]> khamidou — GitHub mirrors - electron.git/commitdiff
Add 'new-window' event for <webview>
authorCheng Zhao <zcbenz@gmail.com>
Sat, 25 Oct 2014 05:21:09 +0000 (13:21 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Sat, 25 Oct 2014 05:21:09 +0000 (13:21 +0800)
atom/browser/api/atom_api_web_contents.cc
atom/browser/api/atom_api_web_contents.h
atom/browser/lib/guest-view-manager.coffee
atom/renderer/lib/guest-view-internal.coffee

index 3b80e3b5462bbb9f8708dcdeea7f27213260f126..5487234eb14b98dfd31d1b2c7b3fca3bbde4f859 100644 (file)
@@ -78,6 +78,21 @@ bool WebContents::AddMessageToConsole(content::WebContents* source,
   return true;
 }
 
+bool WebContents::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) {
+  base::ListValue args;
+  args.AppendString(target_url.spec());
+  args.AppendString(partition_id);
+  Emit("new-window", args);
+  return false;
+}
+
 void WebContents::CloseContents(content::WebContents* source) {
   Emit("close");
 }
@@ -210,14 +225,8 @@ void WebContents::WillAttach(content::WebContents* embedder_web_contents,
 
 content::WebContents* WebContents::CreateNewGuestWindow(
     const content::WebContents::CreateParams& create_params) {
-  auto web_contents = content::WebContents::Create(create_params);
-  // TODO Currently we just retain the web_contents on V8's heap, which will be
-  // garbage collected later, we should provide a way to let users make use of
-  // this WebContents.
-  mate::Handle<WebContents> managed = CreateFrom(
-      v8::Isolate::GetCurrent(), web_contents);
-  managed->storage_.reset(web_contents);
-  return web_contents;
+  NOTREACHED() << "Should not create new window from guest";
+  return nullptr;
 }
 
 void WebContents::DidAttach() {
index 4a104f3fda85d072f6af6e1af3b0400fb31b8edd..1604d7db3315c992b8abae25b30e50d90a66f5cc 100644 (file)
@@ -93,6 +93,14 @@ class WebContents : public mate::EventEmitter,
                            const base::string16& message,
                            int32 line_no,
                            const base::string16& source_id) override;
+  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;
   void CloseContents(content::WebContents* source) override;
   content::WebContents* OpenURLFromTab(
       content::WebContents* source,
index 94c2bbd23c7b48307e8f36dcaa32a3e4162939a4..f827b3afae2295a7f09bc7bbc186d11bb89d9fec 100644 (file)
@@ -10,6 +10,7 @@ supportedWebViewEvents = [
   'did-stop-loading'
   'did-get-redirect-request'
   'console-message'
+  'new-window'
   'close'
   'crashed'
   'destroyed'
index 8dc271515fa5e0750f74b6cb1bbfbdefc7121f92..9d09cc3da0eb07f6f81aa4c2b542fcc3b3da25f2 100644 (file)
@@ -10,6 +10,7 @@ WEB_VIEW_EVENTS =
   'did-stop-loading': []
   'did-get-redirect-request': ['oldUrl', 'newUrl', 'isMainFrame']
   'console-message': ['level', 'message', 'line', 'sourceId']
+  'new-window': ['url', 'partitionId']
   'close': []
   'crashed': []
   'destroyed': []