From: Cheng Zhao Date: Mon, 27 Oct 2014 08:56:28 +0000 (+0800) Subject: Prevent creating popup window from inside WebContents X-Git-Tag: v0.19.0~1^2~15 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=fb864a8f23ceececbb08959adde0b2ccaef35107;p=electron.git Prevent creating popup window from inside WebContents --- diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 71eb6511..e55afe42 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -423,6 +423,22 @@ void NativeWindow::NotifyWindowFocus() { FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowFocus()); } +bool NativeWindow::ShouldCreateWebContents( + content::WebContents* web_contents, + int route_id, + WindowContainerType window_container_type, + const base::string16& frame_name, + const GURL& target_url, + const std::string& partition_id, + content::SessionStorageNamespace* session_storage_namespace) { + FOR_EACH_OBSERVER(NativeWindowObserver, + observers_, + WillCreatePopupWindow(frame_name, + target_url, + partition_id)); + return false; +} + // In atom-shell all reloads and navigations started by renderer process would // be redirected to this method, so we can have precise control of how we // would open the url (in our case, is to restart the renderer process). See diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 5fc4766f..ffccccc9 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -214,6 +214,14 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, const std::vector& regions) = 0; // Implementations of content::WebContentsDelegate. + bool ShouldCreateWebContents( + content::WebContents* web_contents, + int route_id, + WindowContainerType window_container_type, + const base::string16& frame_name, + const GURL& target_url, + const std::string& partition_id, + content::SessionStorageNamespace* session_storage_namespace) override; content::WebContents* OpenURLFromTab( content::WebContents* source, const content::OpenURLParams& params) override; diff --git a/atom/browser/native_window_observer.h b/atom/browser/native_window_observer.h index 33a1505a..522fa941 100644 --- a/atom/browser/native_window_observer.h +++ b/atom/browser/native_window_observer.h @@ -7,6 +7,9 @@ #include +#include "base/strings/string16.h" +#include "url/gurl.h" + namespace atom { class NativeWindowObserver { @@ -17,6 +20,11 @@ class NativeWindowObserver { virtual void OnPageTitleUpdated(bool* prevent_default, const std::string& title) {} + // Called when the web page in window wants to create a popup window. + virtual void WillCreatePopupWindow(const base::string16& frame_name, + const GURL& target_url, + const std::string& partition_id) {} + // Called when the window is gonna closed. virtual void WillCloseWindow(bool* prevent_default) {}