Merge pull request #146 from atom/window-open

Implement window.open in pure js
This commit is contained in:
Cheng Zhao 2013-12-26 23:54:19 -08:00
commit f6c3a69595
6 changed files with 43 additions and 28 deletions

View file

@ -21,6 +21,10 @@ EventEmitter::EventEmitter(v8::Handle<v8::Object> wrapper) {
}
EventEmitter::~EventEmitter() {
// Clear the aligned pointer, it should have been done by ObjectWrap but
// somehow node v0.11.x changed this behaviour.
v8::HandleScope handle_scope(node_isolate);
handle()->SetAlignedPointerInInternalField(0, NULL);
}
bool EventEmitter::Emit(const std::string& name) {

View file

@ -4,6 +4,7 @@
#include "browser/api/atom_api_window.h"
#include "base/bind.h"
#include "base/process/kill.h"
#include "browser/native_window.h"
#include "common/v8/native_type_conversions.h"
@ -127,11 +128,12 @@ void Window::Destroy(const v8::FunctionCallbackInfo<v8::Value>& args) {
base::ProcessHandle handle = self->window_->GetRenderProcessHandle();
delete self;
// Check if the render process is terminated, it could happen that the render
// became a zombie.
if (!base::WaitForSingleProcess(handle,
base::TimeDelta::FromMilliseconds(500)))
base::KillProcess(handle, 0, true);
// Make sure the renderer process is terminated, it could happen that the
// renderer process became a zombie.
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::Bind(base::IgnoreResult(base::KillProcess), 0, false, handle),
base::TimeDelta::FromMilliseconds(5000));
}
// static

View file

@ -280,24 +280,6 @@ void NativeWindow::NotifyWindowBlur() {
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowBlur());
}
// Window opened by window.open.
void NativeWindow::WebContentsCreated(
content::WebContents* source_contents,
int64 source_frame_id,
const string16& frame_name,
const GURL& target_url,
content::WebContents* new_contents) {
LOG(WARNING) << "Please use node-style Window API to create window, "
"using window.open has very strict constrains.";
scoped_ptr<base::DictionaryValue> options(new base::DictionaryValue);
options->SetInteger(switches::kWidth, 800);
options->SetInteger(switches::kHeight, 600);
NativeWindow* window = Create(new_contents, options.get());
window->InitFromOptions(options.get());
}
content::JavaScriptDialogManager* NativeWindow::GetJavaScriptDialogManager() {
if (!dialog_manager_)
dialog_manager_.reset(new AtomJavaScriptDialogManager);

View file

@ -157,11 +157,6 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
const std::vector<DraggableRegion>& regions) = 0;
// Implementations of content::WebContentsDelegate.
virtual void WebContentsCreated(content::WebContents* source_contents,
int64 source_frame_id,
const string16& frame_name,
const GURL& target_url,
content::WebContents* new_contents) OVERRIDE;
virtual content::JavaScriptDialogManager*
GetJavaScriptDialogManager() OVERRIDE;
virtual void BeforeUnloadFired(content::WebContents* tab,

View file

@ -59,3 +59,27 @@ window.onerror = (error) ->
true
else
false
# Override default window.open.
window.open = (url, name, features) ->
options = {}
for feature in features.split ','
[name, value] = feature.split '='
options[name] =
if value is 'yes'
true
else if value is 'no'
false
else
value
options.x ?= options.left
options.y ?= options.top
options.title ?= name
options.width ?= 800
options.height ?= 600
BrowserWindow = require('remote').require 'browser-window'
browser = new BrowserWindow options
browser.loadUrl url
browser

View file

@ -1,3 +1,5 @@
assert = require 'assert'
describe 'chromium feature', ->
describe 'heap snapshot', ->
it 'does not crash', ->
@ -13,3 +15,9 @@ describe 'chromium feature', ->
navigator.webkitGetUserMedia audio: true, video: false,
-> done()
-> done()
describe 'window.open', ->
it 'returns a BrowserWindow object', ->
b = window.open 'about:blank', 'test', 'show=no'
assert.equal b.constructor.name, 'BrowserWindow'
b.destroy()