From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 20 Sep 2018 17:45:32 -0700 Subject: can_create_window.patch This adds a hook to the window creation flow so that Electron can intercede and potentially prevent a window from being created. TODO(loc): this patch is currently broken. diff --git a/content/browser/frame_host/render_frame_host_impl.cc b/content/browser/frame_host/render_frame_host_impl.cc index b7ed7e9f59b7cde06aa468e1fec708c791327a57..14b3d4603b8143ea2660c0fad5ab8e8547f2854a 100644 --- a/content/browser/frame_host/render_frame_host_impl.cc +++ b/content/browser/frame_host/render_frame_host_impl.cc @@ -4397,6 +4397,7 @@ void RenderFrameHostImpl::CreateNewWindow( last_committed_origin_, params->window_container_type, params->target_url, params->referrer.To(), params->frame_name, params->disposition, *params->features, + params->additional_features, params->body, effective_transient_activation_state, params->opener_suppressed, &no_javascript_access); diff --git a/content/common/frame.mojom b/content/common/frame.mojom index 46d534b72813c8fb6dfa2ad42f2d81b983cfdf90..9c492e3c2ebd4f6e89ee883d08522145594a8e01 100644 --- a/content/common/frame.mojom +++ b/content/common/frame.mojom @@ -302,6 +302,10 @@ struct CreateNewWindowParams { // The window features to use for the new window. blink.mojom.WindowFeatures features; + + // Extra fields added by Electron. + array additional_features; + network.mojom.URLRequestBody? body; }; // Operation result when the renderer asks the browser to create a new window. diff --git a/content/public/browser/content_browser_client.cc b/content/public/browser/content_browser_client.cc index 602008278edca8b34ba02e5c5d236ab9342b3cc0..76261e6b09094527327e068e183d3d3b2665467b 100644 --- a/content/public/browser/content_browser_client.cc +++ b/content/public/browser/content_browser_client.cc @@ -510,6 +510,8 @@ bool ContentBrowserClient::CanCreateWindow( const std::string& frame_name, WindowOpenDisposition disposition, const blink::mojom::WindowFeatures& features, + const std::vector& additional_features, + const scoped_refptr& body, bool user_gesture, bool opener_suppressed, bool* no_javascript_access) { diff --git a/content/public/browser/content_browser_client.h b/content/public/browser/content_browser_client.h index c2af7b3b2b38997b083bc860e4abca63a53d73e4..2196584c127c8a3f80bfe55aaff3187372c19b1e 100644 --- a/content/public/browser/content_browser_client.h +++ b/content/public/browser/content_browser_client.h @@ -135,6 +135,7 @@ class NetworkService; class TrustedURLLoaderHeaderClient; } // namespace mojom struct ResourceRequest; +class ResourceRequestBody; } // namespace network namespace rappor { @@ -823,6 +824,8 @@ class CONTENT_EXPORT ContentBrowserClient { const std::string& frame_name, WindowOpenDisposition disposition, const blink::mojom::WindowFeatures& features, + const std::vector& additional_features, + const scoped_refptr& body, bool user_gesture, bool opener_suppressed, bool* no_javascript_access); diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index 2c43fe2096f9c76b6ca757dcd2d53eb596bca2c1..f815739a06a60e050003d2819ddab82be2abf3a6 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -70,6 +70,7 @@ #include "content/renderer/ime_event_guard.h" #include "content/renderer/internal_document_state_data.h" #include "content/renderer/loader/request_extra_data.h" +#include "content/renderer/loader/web_url_request_util.h" #include "content/renderer/media/audio/audio_device_factory.h" #include "content/renderer/render_frame_impl.h" #include "content/renderer/render_frame_proxy.h" @@ -1333,6 +1334,8 @@ WebView* RenderViewImpl::CreateView( } params->features = ConvertWebWindowFeaturesToMojoWindowFeatures(features); + params->body = GetRequestBodyForWebURLRequest(request); + // We preserve this information before sending the message since |params| is // moved on send. bool is_background_tab = diff --git a/content/shell/browser/web_test/web_test_content_browser_client.cc b/content/shell/browser/web_test/web_test_content_browser_client.cc index 5908c91e81f94575ec772fa86833fe1effe07c99..ac05f23929d1223646d6bc1956a581c48ee1f844 100644 --- a/content/shell/browser/web_test/web_test_content_browser_client.cc +++ b/content/shell/browser/web_test/web_test_content_browser_client.cc @@ -331,6 +331,8 @@ bool WebTestContentBrowserClient::CanCreateWindow( const std::string& frame_name, WindowOpenDisposition disposition, const blink::mojom::WindowFeatures& features, + const std::vector& additional_features, + const scoped_refptr& body, bool user_gesture, bool opener_suppressed, bool* no_javascript_access) { diff --git a/content/shell/browser/web_test/web_test_content_browser_client.h b/content/shell/browser/web_test/web_test_content_browser_client.h index 63252a3503176be335510c0bbeaed2a39929930d..45fab07bdc9d11df755cb172f7314e6f131f31df 100644 --- a/content/shell/browser/web_test/web_test_content_browser_client.h +++ b/content/shell/browser/web_test/web_test_content_browser_client.h @@ -69,6 +69,8 @@ class WebTestContentBrowserClient : public ShellContentBrowserClient { const std::string& frame_name, WindowOpenDisposition disposition, const blink::mojom::WindowFeatures& features, + const std::vector& additional_features, + const scoped_refptr& body, bool user_gesture, bool opener_suppressed, bool* no_javascript_access) override;