From: Cheng Zhao Date: Sat, 25 Oct 2014 05:21:09 +0000 (+0800) Subject: Add 'new-window' event for X-Git-Tag: v0.19.0~3^2~13 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=194ed3884c7e82418676dc718d76857560aad75d;p=electron.git Add 'new-window' event for --- diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 3b80e3b5..5487234e 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -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 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() { diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 4a104f3f..1604d7db 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -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, diff --git a/atom/browser/lib/guest-view-manager.coffee b/atom/browser/lib/guest-view-manager.coffee index 94c2bbd2..f827b3af 100644 --- a/atom/browser/lib/guest-view-manager.coffee +++ b/atom/browser/lib/guest-view-manager.coffee @@ -10,6 +10,7 @@ supportedWebViewEvents = [ 'did-stop-loading' 'did-get-redirect-request' 'console-message' + 'new-window' 'close' 'crashed' 'destroyed' diff --git a/atom/renderer/lib/guest-view-internal.coffee b/atom/renderer/lib/guest-view-internal.coffee index 8dc27151..9d09cc3d 100644 --- a/atom/renderer/lib/guest-view-internal.coffee +++ b/atom/renderer/lib/guest-view-internal.coffee @@ -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': []