Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement window.open in pure js #146

Merged
merged 6 commits into from Dec 27, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions browser/api/atom_api_event_emitter.cc
Expand Up @@ -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) {
Expand Down
12 changes: 7 additions & 5 deletions browser/api/atom_api_window.cc
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
18 changes: 0 additions & 18 deletions browser/native_window.cc
Expand Up @@ -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);
Expand Down
5 changes: 0 additions & 5 deletions browser/native_window.h
Expand Up @@ -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,
Expand Down
24 changes: 24 additions & 0 deletions renderer/lib/init.coffee
Expand Up @@ -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
8 changes: 8 additions & 0 deletions spec/chromium-spec.coffee
@@ -1,3 +1,5 @@
assert = require 'assert'

describe 'chromium feature', ->
describe 'heap snapshot', ->
it 'does not crash', ->
Expand All @@ -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()