Route window.open to "new-window" event

This commit is contained in:
Cheng Zhao 2014-10-27 18:52:55 +08:00
parent 94818aef26
commit 389e56ce36
5 changed files with 41 additions and 24 deletions

View file

@ -82,6 +82,15 @@ void Window::OnPageTitleUpdated(bool* prevent_default,
*prevent_default = Emit("page-title-updated", args);
}
void Window::WillCreatePopupWindow(const base::string16& frame_name,
const GURL& target_url,
const std::string& partition_id) {
base::ListValue args;
args.AppendString(target_url.spec());
args.AppendString(frame_name);
Emit("new-window", args);
}
void Window::WillCloseWindow(bool* prevent_default) {
*prevent_default = Emit("close");
}

View file

@ -45,6 +45,9 @@ class Window : public mate::EventEmitter,
// Implementations of NativeWindowObserver:
void OnPageTitleUpdated(bool* prevent_default,
const std::string& title) override;
void WillCreatePopupWindow(const base::string16& frame_name,
const GURL& target_url,
const std::string& partition_id) override;
void WillCloseWindow(bool* prevent_default) override;
void OnWindowClosed() override;
void OnWindowBlur() override;

View file

@ -23,6 +23,10 @@ BrowserWindow::_init = ->
value: BrowserWindow.windows.add(this)
enumerable: true
# Route the "new-window" event to webContents.
@on 'new-window', (args...) =>
@webContents?.emit 'new-window', args...
# Remove the window from weak map immediately when it's destroyed, since we
# could be iterating windows before GC happened.
@once 'closed', =>

View file

@ -2,6 +2,10 @@ EventEmitter = require('events').EventEmitter
binding = process.atomBinding 'web_contents'
ipc = require 'ipc'
# Routed window.open messages.
ipc.on 'ATOM_SHELL_WEB_CONTENTS_WINDOW_OPEN', (event, url, name, features) ->
event.sender.emit 'new-window', url, name, features
module.exports.wrap = (webContents) ->
return null unless webContents.isAlive()