Route window.open to "new-window" event
This commit is contained in:
parent
94818aef26
commit
389e56ce36
5 changed files with 41 additions and 24 deletions
|
@ -82,6 +82,15 @@ void Window::OnPageTitleUpdated(bool* prevent_default,
|
||||||
*prevent_default = Emit("page-title-updated", args);
|
*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) {
|
void Window::WillCloseWindow(bool* prevent_default) {
|
||||||
*prevent_default = Emit("close");
|
*prevent_default = Emit("close");
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,9 @@ class Window : public mate::EventEmitter,
|
||||||
// Implementations of NativeWindowObserver:
|
// Implementations of NativeWindowObserver:
|
||||||
void OnPageTitleUpdated(bool* prevent_default,
|
void OnPageTitleUpdated(bool* prevent_default,
|
||||||
const std::string& title) override;
|
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 WillCloseWindow(bool* prevent_default) override;
|
||||||
void OnWindowClosed() override;
|
void OnWindowClosed() override;
|
||||||
void OnWindowBlur() override;
|
void OnWindowBlur() override;
|
||||||
|
|
|
@ -23,6 +23,10 @@ BrowserWindow::_init = ->
|
||||||
value: BrowserWindow.windows.add(this)
|
value: BrowserWindow.windows.add(this)
|
||||||
enumerable: true
|
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
|
# Remove the window from weak map immediately when it's destroyed, since we
|
||||||
# could be iterating windows before GC happened.
|
# could be iterating windows before GC happened.
|
||||||
@once 'closed', =>
|
@once 'closed', =>
|
||||||
|
|
|
@ -2,6 +2,10 @@ EventEmitter = require('events').EventEmitter
|
||||||
binding = process.atomBinding 'web_contents'
|
binding = process.atomBinding 'web_contents'
|
||||||
ipc = require 'ipc'
|
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) ->
|
module.exports.wrap = (webContents) ->
|
||||||
return null unless webContents.isAlive()
|
return null unless webContents.isAlive()
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
process = global.process
|
process = global.process
|
||||||
|
ipc = require 'ipc'
|
||||||
remote = require 'remote'
|
remote = require 'remote'
|
||||||
|
|
||||||
unless process.guestInstanceId?
|
if process.guestInstanceId?
|
||||||
# Override default window.close, see:
|
# Override default window.close.
|
||||||
window.close = ->
|
window.close = ->
|
||||||
remote.getCurrentWindow().close()
|
remote.getCurrentWindow().close()
|
||||||
|
|
||||||
# Override default window.open.
|
# Make the browser window or guest view emit "new-window" event.
|
||||||
window.open = (url, name, features) ->
|
window.open = (url, name='', features='') ->
|
||||||
options = {}
|
options = {}
|
||||||
for feature in features.split ','
|
for feature in features.split ','
|
||||||
[name, value] = feature.split '='
|
[name, value] = feature.split '='
|
||||||
|
@ -18,17 +19,13 @@ unless process.guestInstanceId?
|
||||||
false
|
false
|
||||||
else
|
else
|
||||||
value
|
value
|
||||||
|
|
||||||
options.x ?= options.left
|
options.x ?= options.left
|
||||||
options.y ?= options.top
|
options.y ?= options.top
|
||||||
options.title ?= name
|
options.title ?= name
|
||||||
options.width ?= 800
|
options.width ?= 800
|
||||||
options.height ?= 600
|
options.height ?= 600
|
||||||
|
|
||||||
BrowserWindow = require('remote').require 'browser-window'
|
ipc.send 'ATOM_SHELL_WEB_CONTENTS_WINDOW_OPEN', url, name, features
|
||||||
browser = new BrowserWindow options
|
|
||||||
browser.loadUrl url
|
|
||||||
browser
|
|
||||||
|
|
||||||
# Use the dialog API to implement alert().
|
# Use the dialog API to implement alert().
|
||||||
window.alert = (message, title='') ->
|
window.alert = (message, title='') ->
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue