]> khamidou — GitHub mirrors - electron.git/commitdiff
Prevent creating popup window from inside WebContents
authorCheng Zhao <zcbenz@gmail.com>
Mon, 27 Oct 2014 08:56:28 +0000 (16:56 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 27 Oct 2014 08:56:28 +0000 (16:56 +0800)
atom/browser/native_window.cc
atom/browser/native_window.h
atom/browser/native_window_observer.h

index 71eb65112d1aae4168c800d336eabefa2620d479..e55afe42d20a6c5cdcdb96aa30b91b86d9b8fde6 100644 (file)
@@ -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
index 5fc4766fa706150683747fdb10aca81ff18d38fd..ffccccc9b2c7a9edb294f962c4a01a2d8507ef57 100644 (file)
@@ -214,6 +214,14 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
       const std::vector<DraggableRegion>& 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;
index 33a1505a99b3420b7e701b7380dd3d21373ea0d7..522fa9414241f24ef77205afd7aa578d138d4f73 100644 (file)
@@ -7,6 +7,9 @@
 
 #include <string>
 
+#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) {}