Add "will-navigate" event for BrowserWindow
This commit is contained in:
parent
5142b7858b
commit
fd596d4a65
4 changed files with 22 additions and 4 deletions
|
@ -92,6 +92,12 @@ void Window::WillCreatePopupWindow(const base::string16& frame_name,
|
||||||
Emit("-new-window", args);
|
Emit("-new-window", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::WillNavigate(bool* prevent_default, const GURL& url) {
|
||||||
|
base::ListValue args;
|
||||||
|
args.AppendString(url.spec());
|
||||||
|
*prevent_default = Emit("will-navigate", args);
|
||||||
|
}
|
||||||
|
|
||||||
void Window::WillCloseWindow(bool* prevent_default) {
|
void Window::WillCloseWindow(bool* prevent_default) {
|
||||||
*prevent_default = Emit("close");
|
*prevent_default = Emit("close");
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@ class Window : public mate::EventEmitter,
|
||||||
const GURL& target_url,
|
const GURL& target_url,
|
||||||
const std::string& partition_id,
|
const std::string& partition_id,
|
||||||
WindowOpenDisposition disposition) override;
|
WindowOpenDisposition disposition) override;
|
||||||
|
void WillNavigate(bool* prevent_default, const GURL& url) 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;
|
||||||
|
|
|
@ -169,7 +169,7 @@ NativeWindow* NativeWindow::FromRenderView(int process_id, int routing_id) {
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindow::InitFromOptions(const mate::Dictionary& options) {
|
void NativeWindow::InitFromOptions(const mate::Dictionary& options) {
|
||||||
|
@ -370,13 +370,13 @@ void NativeWindow::CloseWebContents() {
|
||||||
|
|
||||||
content::WebContents* NativeWindow::GetWebContents() const {
|
content::WebContents* NativeWindow::GetWebContents() const {
|
||||||
if (!inspectable_web_contents_)
|
if (!inspectable_web_contents_)
|
||||||
return NULL;
|
return nullptr;
|
||||||
return inspectable_web_contents()->GetWebContents();
|
return inspectable_web_contents()->GetWebContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
content::WebContents* NativeWindow::GetDevToolsWebContents() const {
|
content::WebContents* NativeWindow::GetDevToolsWebContents() const {
|
||||||
if (!inspectable_web_contents_)
|
if (!inspectable_web_contents_)
|
||||||
return NULL;
|
return nullptr;
|
||||||
return inspectable_web_contents()->devtools_web_contents();
|
return inspectable_web_contents()->devtools_web_contents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -524,9 +524,17 @@ content::WebContents* NativeWindow::OpenURLFromTab(
|
||||||
params.url,
|
params.url,
|
||||||
"",
|
"",
|
||||||
params.disposition));
|
params.disposition));
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Give user a chance to prevent navigation.
|
||||||
|
bool prevent_default = false;
|
||||||
|
FOR_EACH_OBSERVER(NativeWindowObserver,
|
||||||
|
observers_,
|
||||||
|
WillNavigate(&prevent_default, params.url));
|
||||||
|
if (prevent_default)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
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;
|
||||||
load_url_params.transition_type = params.transition;
|
load_url_params.transition_type = params.transition;
|
||||||
|
|
|
@ -27,6 +27,9 @@ class NativeWindowObserver {
|
||||||
const std::string& partition_id,
|
const std::string& partition_id,
|
||||||
WindowOpenDisposition disposition) {}
|
WindowOpenDisposition disposition) {}
|
||||||
|
|
||||||
|
// Called when user is starting an navigation in web page.
|
||||||
|
virtual void WillNavigate(bool* prevent_default, const GURL& url) {}
|
||||||
|
|
||||||
// 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) {}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue