Merge pull request #779 from atom/new-window-disposition
Emit "new-window" event for dispositions other than current tab
This commit is contained in:
commit
1fbe05b2d5
11 changed files with 49 additions and 14 deletions
|
@ -90,7 +90,8 @@ bool WebContents::ShouldCreateWebContents(
|
||||||
base::ListValue args;
|
base::ListValue args;
|
||||||
args.AppendString(target_url.spec());
|
args.AppendString(target_url.spec());
|
||||||
args.AppendString(frame_name);
|
args.AppendString(frame_name);
|
||||||
Emit("new-window", args);
|
args.AppendInteger(NEW_FOREGROUND_TAB);
|
||||||
|
Emit("-new-window", args);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,8 +102,14 @@ void WebContents::CloseContents(content::WebContents* source) {
|
||||||
content::WebContents* WebContents::OpenURLFromTab(
|
content::WebContents* WebContents::OpenURLFromTab(
|
||||||
content::WebContents* source,
|
content::WebContents* source,
|
||||||
const content::OpenURLParams& params) {
|
const content::OpenURLParams& params) {
|
||||||
if (params.disposition != CURRENT_TAB)
|
if (params.disposition != CURRENT_TAB) {
|
||||||
|
base::ListValue args;
|
||||||
|
args.AppendString(params.url.spec());
|
||||||
|
args.AppendString("");
|
||||||
|
args.AppendInteger(params.disposition);
|
||||||
|
Emit("-new-window", args);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
content::NavigationController::LoadURLParams load_url_params(params.url);
|
content::NavigationController::LoadURLParams load_url_params(params.url);
|
||||||
load_url_params.referrer = params.referrer;
|
load_url_params.referrer = params.referrer;
|
||||||
|
|
|
@ -85,11 +85,13 @@ void Window::OnPageTitleUpdated(bool* prevent_default,
|
||||||
|
|
||||||
void Window::WillCreatePopupWindow(const base::string16& frame_name,
|
void Window::WillCreatePopupWindow(const base::string16& frame_name,
|
||||||
const GURL& target_url,
|
const GURL& target_url,
|
||||||
const std::string& partition_id) {
|
const std::string& partition_id,
|
||||||
|
WindowOpenDisposition disposition) {
|
||||||
base::ListValue args;
|
base::ListValue args;
|
||||||
args.AppendString(target_url.spec());
|
args.AppendString(target_url.spec());
|
||||||
args.AppendString(frame_name);
|
args.AppendString(frame_name);
|
||||||
Emit("new-window", args);
|
args.AppendInteger(disposition);
|
||||||
|
Emit("-new-window", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::WillCloseWindow(bool* prevent_default) {
|
void Window::WillCloseWindow(bool* prevent_default) {
|
||||||
|
|
|
@ -48,7 +48,8 @@ class Window : public mate::EventEmitter,
|
||||||
const std::string& title) override;
|
const std::string& title) override;
|
||||||
void WillCreatePopupWindow(const base::string16& frame_name,
|
void WillCreatePopupWindow(const base::string16& frame_name,
|
||||||
const GURL& target_url,
|
const GURL& target_url,
|
||||||
const std::string& partition_id) override;
|
const std::string& partition_id,
|
||||||
|
WindowOpenDisposition disposition) 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;
|
||||||
|
|
|
@ -25,7 +25,7 @@ BrowserWindow::_init = ->
|
||||||
enumerable: true
|
enumerable: true
|
||||||
|
|
||||||
# Make new windows requested by links behave like "window.open"
|
# Make new windows requested by links behave like "window.open"
|
||||||
@on 'new-window', (event, url, frameName) =>
|
@on '-new-window', (event, url, frameName) =>
|
||||||
event.sender = @webContents
|
event.sender = @webContents
|
||||||
options = show: true, width: 800, height: 600
|
options = show: true, width: 800, height: 600
|
||||||
ipc.emit 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', event, url, frameName, options
|
ipc.emit 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', event, url, frameName, options
|
||||||
|
|
|
@ -26,6 +26,17 @@ module.exports.wrap = (webContents) ->
|
||||||
webContents.getId = -> "#{@getProcessId()}-#{@getRoutingId()}"
|
webContents.getId = -> "#{@getProcessId()}-#{@getRoutingId()}"
|
||||||
webContents.equal = (other) -> @getId() is other.getId()
|
webContents.equal = (other) -> @getId() is other.getId()
|
||||||
|
|
||||||
|
# Translate |disposition| to string for 'new-window' event.
|
||||||
|
webContents.on '-new-window', (args..., disposition) ->
|
||||||
|
disposition =
|
||||||
|
switch disposition
|
||||||
|
when 2 then 'default'
|
||||||
|
when 4 then 'foreground-tab'
|
||||||
|
when 5 then 'background-tab'
|
||||||
|
when 6, 7 then 'new-window'
|
||||||
|
else 'other'
|
||||||
|
@emit 'new-window', args..., disposition
|
||||||
|
|
||||||
# Tell the rpc server that a render view has been deleted and we need to
|
# Tell the rpc server that a render view has been deleted and we need to
|
||||||
# release all objects owned by it.
|
# release all objects owned by it.
|
||||||
webContents.on 'render-view-deleted', (event, processId, routingId) ->
|
webContents.on 'render-view-deleted', (event, processId, routingId) ->
|
||||||
|
|
|
@ -34,7 +34,8 @@ createGuest = (embedder, url, frameName, options) ->
|
||||||
|
|
||||||
# Routed window.open messages.
|
# Routed window.open messages.
|
||||||
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', (event, args...) ->
|
ipc.on 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', (event, args...) ->
|
||||||
event.sender.emit 'new-window', event, args...
|
[url, frameName, options] = args
|
||||||
|
event.sender.emit '-new-window', event, url, frameName, 7
|
||||||
if event.sender.isGuest() or event.defaultPrevented
|
if event.sender.isGuest() or event.defaultPrevented
|
||||||
event.returnValue = null
|
event.returnValue = null
|
||||||
else
|
else
|
||||||
|
|
|
@ -437,7 +437,8 @@ bool NativeWindow::ShouldCreateWebContents(
|
||||||
observers_,
|
observers_,
|
||||||
WillCreatePopupWindow(frame_name,
|
WillCreatePopupWindow(frame_name,
|
||||||
target_url,
|
target_url,
|
||||||
partition_id));
|
partition_id,
|
||||||
|
NEW_FOREGROUND_TAB));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,8 +449,15 @@ bool NativeWindow::ShouldCreateWebContents(
|
||||||
content::WebContents* NativeWindow::OpenURLFromTab(
|
content::WebContents* NativeWindow::OpenURLFromTab(
|
||||||
content::WebContents* source,
|
content::WebContents* source,
|
||||||
const content::OpenURLParams& params) {
|
const content::OpenURLParams& params) {
|
||||||
if (params.disposition != CURRENT_TAB)
|
if (params.disposition != CURRENT_TAB) {
|
||||||
|
FOR_EACH_OBSERVER(NativeWindowObserver,
|
||||||
|
observers_,
|
||||||
|
WillCreatePopupWindow(base::string16(),
|
||||||
|
params.url,
|
||||||
|
"",
|
||||||
|
params.disposition));
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
content::NavigationController::LoadURLParams load_url_params(params.url);
|
content::NavigationController::LoadURLParams load_url_params(params.url);
|
||||||
load_url_params.referrer = params.referrer;
|
load_url_params.referrer = params.referrer;
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "base/strings/string16.h"
|
#include "base/strings/string16.h"
|
||||||
|
#include "ui/base/window_open_disposition.h"
|
||||||
#include "url/gurl.h"
|
#include "url/gurl.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
@ -23,7 +24,8 @@ class NativeWindowObserver {
|
||||||
// Called when the web page in window wants to create a popup window.
|
// Called when the web page in window wants to create a popup window.
|
||||||
virtual void WillCreatePopupWindow(const base::string16& frame_name,
|
virtual void WillCreatePopupWindow(const base::string16& frame_name,
|
||||||
const GURL& target_url,
|
const GURL& target_url,
|
||||||
const std::string& partition_id) {}
|
const std::string& partition_id,
|
||||||
|
WindowOpenDisposition disposition) {}
|
||||||
|
|
||||||
// Called when the window is gonna closed.
|
// Called when the window is gonna closed.
|
||||||
virtual void WillCloseWindow(bool* prevent_default) {}
|
virtual void WillCloseWindow(bool* prevent_default) {}
|
||||||
|
|
|
@ -10,7 +10,7 @@ WEB_VIEW_EVENTS =
|
||||||
'did-stop-loading': []
|
'did-stop-loading': []
|
||||||
'did-get-redirect-request': ['oldUrl', 'newUrl', 'isMainFrame']
|
'did-get-redirect-request': ['oldUrl', 'newUrl', 'isMainFrame']
|
||||||
'console-message': ['level', 'message', 'line', 'sourceId']
|
'console-message': ['level', 'message', 'line', 'sourceId']
|
||||||
'new-window': ['url', 'frameName']
|
'new-window': ['url', 'frameName', 'disposition']
|
||||||
'close': []
|
'close': []
|
||||||
'crashed': []
|
'crashed': []
|
||||||
'destroyed': []
|
'destroyed': []
|
||||||
|
|
|
@ -551,7 +551,8 @@ Emitted when a redirect was received while requesting a resource.
|
||||||
* `event` Event
|
* `event` Event
|
||||||
* `url` String
|
* `url` String
|
||||||
* `frameName` String
|
* `frameName` String
|
||||||
* `options` Object
|
* `disposition` String - Can be `default`, `foreground-tab`, `background-tab`,
|
||||||
|
`new-window` and `other`
|
||||||
|
|
||||||
Emitted when the page requested to open a new window for `url`. It could be
|
Emitted when the page requested to open a new window for `url`. It could be
|
||||||
requested by `window.open` or an external link like `<a target='_blank'>`.
|
requested by `window.open` or an external link like `<a target='_blank'>`.
|
||||||
|
|
|
@ -250,6 +250,8 @@ webview.addEventListener('console-message', function(e) {
|
||||||
|
|
||||||
* `url` String
|
* `url` String
|
||||||
* `frameName` String
|
* `frameName` String
|
||||||
|
* `disposition` String - Can be `default`, `foreground-tab`, `background-tab`,
|
||||||
|
`new-window` and `other`
|
||||||
|
|
||||||
Fired when the guest page attempts to open a new browser window.
|
Fired when the guest page attempts to open a new browser window.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue