Merge pull request #931 from atom/will-navigate
Add "will-navigate" event
This commit is contained in:
commit
c01e3cf9aa
9 changed files with 61 additions and 5 deletions
|
@ -111,9 +111,15 @@ content::WebContents* WebContents::OpenURLFromTab(
|
|||
args.AppendString("");
|
||||
args.AppendInteger(params.disposition);
|
||||
Emit("-new-window", args);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Give user a chance to cancel navigation.
|
||||
base::ListValue args;
|
||||
args.AppendString(params.url.spec());
|
||||
if (Emit("will-navigate", args))
|
||||
return nullptr;
|
||||
|
||||
content::NavigationController::LoadURLParams load_url_params(params.url);
|
||||
load_url_params.referrer = params.referrer;
|
||||
load_url_params.transition_type = params.transition;
|
||||
|
|
|
@ -92,6 +92,12 @@ void Window::WillCreatePopupWindow(const base::string16& frame_name,
|
|||
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) {
|
||||
*prevent_default = Emit("close");
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ class Window : public mate::EventEmitter,
|
|||
const GURL& target_url,
|
||||
const std::string& partition_id,
|
||||
WindowOpenDisposition disposition) override;
|
||||
void WillNavigate(bool* prevent_default, const GURL& url) override;
|
||||
void WillCloseWindow(bool* prevent_default) override;
|
||||
void OnWindowClosed() override;
|
||||
void OnWindowBlur() override;
|
||||
|
|
|
@ -30,6 +30,10 @@ BrowserWindow::_init = ->
|
|||
options = show: true, width: 800, height: 600
|
||||
ipc.emit 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', event, url, frameName, options
|
||||
|
||||
# Redirect "will-navigate" to webContents.
|
||||
@on '-will-navigate', (event, url) =>
|
||||
@webContents.emit 'will-navigate', event, url
|
||||
|
||||
# Remove the window from weak map immediately when it's destroyed, since we
|
||||
# could be iterating windows before GC happened.
|
||||
@once 'closed', =>
|
||||
|
|
|
@ -169,7 +169,7 @@ NativeWindow* NativeWindow::FromRenderView(int process_id, int routing_id) {
|
|||
return window;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void NativeWindow::InitFromOptions(const mate::Dictionary& options) {
|
||||
|
@ -370,13 +370,13 @@ void NativeWindow::CloseWebContents() {
|
|||
|
||||
content::WebContents* NativeWindow::GetWebContents() const {
|
||||
if (!inspectable_web_contents_)
|
||||
return NULL;
|
||||
return nullptr;
|
||||
return inspectable_web_contents()->GetWebContents();
|
||||
}
|
||||
|
||||
content::WebContents* NativeWindow::GetDevToolsWebContents() const {
|
||||
if (!inspectable_web_contents_)
|
||||
return NULL;
|
||||
return nullptr;
|
||||
return inspectable_web_contents()->devtools_web_contents();
|
||||
}
|
||||
|
||||
|
@ -524,9 +524,17 @@ content::WebContents* NativeWindow::OpenURLFromTab(
|
|||
params.url,
|
||||
"",
|
||||
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);
|
||||
load_url_params.referrer = params.referrer;
|
||||
load_url_params.transition_type = params.transition;
|
||||
|
|
|
@ -27,6 +27,9 @@ class NativeWindowObserver {
|
|||
const std::string& partition_id,
|
||||
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.
|
||||
virtual void WillCloseWindow(bool* prevent_default) {}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue