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 47749c430a71c3060c3e258ce1671bf6b03fa8c8..f2aedf5321a13742c6e3c2c4b7492b236a2d726c 100644 --- a/content/browser/frame_host/render_frame_host_impl.cc +++ b/content/browser/frame_host/render_frame_host_impl.cc @@ -4305,6 +4305,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 00d9c34304266b49e3f9703ef1aea6524d026ed5..44bb5868b8c3699230d74de0f0903af572d000fc 100644 --- a/content/common/frame.mojom +++ b/content/common/frame.mojom @@ -303,6 +303,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 702cd0792df47809d9278dd3af40e0e70494e229..75cd0ad7a8dc1efd89683d8da192050659c5016f 100644 --- a/content/public/browser/content_browser_client.cc +++ b/content/public/browser/content_browser_client.cc @@ -508,6 +508,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 ed0460f7e3c9e2149eed89f7d35a4bb457f6b29f..5fc3d0e31927b618d04024fcc42b2061580a4f22 100644 --- a/content/public/browser/content_browser_client.h +++ b/content/public/browser/content_browser_client.h @@ -143,6 +143,7 @@ class NetworkService; class TrustedURLLoaderHeaderClient; } // namespace mojom struct ResourceRequest; +class ResourceRequestBody; } // namespace network namespace rappor { @@ -825,6 +826,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 b3388258feb1d9fd791a975b08a382addd06af3a..98855151d1f07177a20b0f6079f2f48826d215ca 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -68,6 +68,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" @@ -1255,6 +1256,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 bf7c4bf0b76a89b1ecee6edc11fcfd06fe679968..79b2ba79653a251d3a4c3a54adbcd5c10c460b19 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 @@ -333,6 +333,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 aaf3b8fed16bc2959941effaffd3aec87017ca59..1ea96df464f61c963a6d9aa224b9607e4221daa6 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 @@ -71,6 +71,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;