Emit "new-window" event for dispositions other than CURRENT_TAB

This commit is contained in:
Cheng Zhao 2014-11-04 17:59:15 +08:00
parent 77724345c4
commit 013593ccf8
6 changed files with 29 additions and 9 deletions

View file

@ -90,6 +90,7 @@ 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);
args.AppendInteger(CURRENT_TAB);
Emit("new-window", args); 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) {
return NULL; base::ListValue args;
args.AppendString(params.url.spec());
args.AppendString("");
args.AppendInteger(params.disposition);
Emit("new-window", args);
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;

View file

@ -85,10 +85,12 @@ 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);
args.AppendInteger(disposition);
Emit("new-window", args); Emit("new-window", args);
} }

View file

@ -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;

View file

@ -437,7 +437,8 @@ bool NativeWindow::ShouldCreateWebContents(
observers_, observers_,
WillCreatePopupWindow(frame_name, WillCreatePopupWindow(frame_name,
target_url, target_url,
partition_id)); partition_id,
CURRENT_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) {
return NULL; FOR_EACH_OBSERVER(NativeWindowObserver,
observers_,
WillCreatePopupWindow(base::string16(),
params.url,
"",
params.disposition));
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;

View file

@ -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) {}

View file

@ -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': []