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/renderer_host/render_frame_host_impl.cc b/content/browser/renderer_host/render_frame_host_impl.cc index 8cdf087a3db51c3994d886d4abe31fd866cecb20..90cf2f632a222846acfb306c25a826c618ba22d0 100644 --- a/content/browser/renderer_host/render_frame_host_impl.cc +++ b/content/browser/renderer_host/render_frame_host_impl.cc @@ -4982,6 +4982,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->raw_features, params->body, effective_transient_activation_state, params->opener_suppressed, &no_javascript_access); diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc index 722e2bfc385381d1970435d96de817f32db8f0b2..77686b665c4eeb6f40ed7b417aeb236a28673aaf 100644 --- a/content/browser/web_contents/web_contents_impl.cc +++ b/content/browser/web_contents/web_contents_impl.cc @@ -3702,9 +3702,9 @@ RenderFrameHostDelegate* WebContentsImpl::CreateNewWindow( } if (delegate_) { - delegate_->WebContentsCreated(this, render_process_id, - opener->GetRoutingID(), params.frame_name, - params.target_url, new_contents_impl); + delegate_->WebContentsCreatedWithFullParams(this, render_process_id, + opener->GetRoutingID(), + params, new_contents_impl); } observers_.ForEachObserver([&](WebContentsObserver* observer) { diff --git a/content/common/frame.mojom b/content/common/frame.mojom index 6f122e199f208a03bef37e6a6194b2a40b483ea2..cc6a739f8a31945fe58eb97c7beb3fef4370047a 100644 --- a/content/common/frame.mojom +++ b/content/common/frame.mojom @@ -285,6 +285,10 @@ struct CreateNewWindowParams { // The window features to use for the new window. blink.mojom.WindowFeatures features; + + // Extra fields added by Electron. + string raw_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 c5620c9aad06eb3083420d75327df6927b890e82..fc2fb1b9b20cee93796641de85d59b6d794b9a8e 100644 --- a/content/public/browser/content_browser_client.cc +++ b/content/public/browser/content_browser_client.cc @@ -545,6 +545,8 @@ bool ContentBrowserClient::CanCreateWindow( const std::string& frame_name, WindowOpenDisposition disposition, const blink::mojom::WindowFeatures& features, + const std::string& raw_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 56e30e001f5b4a4b0f21638931c48abaa125a863..17bc01e41820cf449d7228f0c5c9a2aa56374e88 100644 --- a/content/public/browser/content_browser_client.h +++ b/content/public/browser/content_browser_client.h @@ -153,6 +153,7 @@ class NetworkService; class TrustedURLLoaderHeaderClient; } // namespace mojom struct ResourceRequest; +class ResourceRequestBody; } // namespace network namespace sandbox { @@ -865,6 +866,8 @@ class CONTENT_EXPORT ContentBrowserClient { const std::string& frame_name, WindowOpenDisposition disposition, const blink::mojom::WindowFeatures& features, + const std::string& raw_features, + const scoped_refptr& body, bool user_gesture, bool opener_suppressed, bool* no_javascript_access); diff --git a/content/public/browser/web_contents_delegate.cc b/content/public/browser/web_contents_delegate.cc index 12ce66464a416262767c126d0600fed60f5b106a..f60cf6064fdf279b26f0d11125e2ffa5bbb36c78 100644 --- a/content/public/browser/web_contents_delegate.cc +++ b/content/public/browser/web_contents_delegate.cc @@ -26,6 +26,17 @@ namespace content { WebContentsDelegate::WebContentsDelegate() = default; +void WebContentsDelegate::WebContentsCreatedWithFullParams( + WebContents* source_contents, + int opener_render_process_id, + int opener_render_frame_id, + const mojom::CreateNewWindowParams& params, + WebContents* new_contents) { + WebContentsCreated(source_contents, opener_render_process_id, + opener_render_frame_id, params.frame_name, + params.target_url, new_contents); +} + WebContents* WebContentsDelegate::OpenURLFromTab(WebContents* source, const OpenURLParams& params) { return nullptr; diff --git a/content/public/browser/web_contents_delegate.h b/content/public/browser/web_contents_delegate.h index ee6b87d40496591935cef789bab9c1de8e60cee9..dd7f018be164b250f0b2408ce309219d61c50caa 100644 --- a/content/public/browser/web_contents_delegate.h +++ b/content/public/browser/web_contents_delegate.h @@ -17,6 +17,7 @@ #include "base/strings/string16.h" #include "build/build_config.h" #include "content/common/content_export.h" +#include "content/common/frame.mojom.h" #include "content/public/browser/bluetooth_chooser.h" #include "content/public/browser/bluetooth_scanning_prompt.h" #include "content/public/browser/eye_dropper.h" @@ -338,6 +339,13 @@ class CONTENT_EXPORT WebContentsDelegate { const std::string& partition_id, SessionStorageNamespace* session_storage_namespace); + virtual void WebContentsCreatedWithFullParams( + WebContents* source_contents, + int opener_render_process_id, + int opener_render_frame_id, + const mojom::CreateNewWindowParams& params, + WebContents* new_contents); + // Notifies the delegate about the creation of a new WebContents. This // typically happens when popups are created. virtual void WebContentsCreated(WebContents* source_contents, diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index c8b9d26590ae0114e592a637b7873606ef2713ac..a39f2daf5a411eaa70326dc94d902d53405c1c6c 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -65,6 +65,7 @@ #include "content/renderer/history_serialization.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/render_frame_impl.h" #include "content/renderer/render_frame_proxy.h" #include "content/renderer/render_process.h" @@ -635,6 +636,10 @@ WebView* RenderViewImpl::CreateView( } params->features = ConvertWebWindowFeaturesToMojoWindowFeatures(features); + params->raw_features = features.raw_features.Utf8( + WTF::UTF8ConversionMode::kStrictUTF8ConversionReplacingUnpairedSurrogatesWithFFFD); + 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/web_test/browser/web_test_content_browser_client.cc b/content/web_test/browser/web_test_content_browser_client.cc index f0c53c0945d76ce4482ce4c24acb75c3eccb59e9..458919350048f02d07695bef1c4d4e41b0ce043e 100644 --- a/content/web_test/browser/web_test_content_browser_client.cc +++ b/content/web_test/browser/web_test_content_browser_client.cc @@ -377,6 +377,8 @@ bool WebTestContentBrowserClient::CanCreateWindow( const std::string& frame_name, WindowOpenDisposition disposition, const blink::mojom::WindowFeatures& features, + const std::string& raw_features, + const scoped_refptr& body, bool user_gesture, bool opener_suppressed, bool* no_javascript_access) { diff --git a/content/web_test/browser/web_test_content_browser_client.h b/content/web_test/browser/web_test_content_browser_client.h index b96c23ec09111b29f9b9349a6324076d26f900bc..d42a00e59cde5195195096237f25eca5d4186797 100644 --- a/content/web_test/browser/web_test_content_browser_client.h +++ b/content/web_test/browser/web_test_content_browser_client.h @@ -83,6 +83,8 @@ class WebTestContentBrowserClient : public ShellContentBrowserClient { const std::string& frame_name, WindowOpenDisposition disposition, const blink::mojom::WindowFeatures& features, + const std::string& raw_features, + const scoped_refptr& body, bool user_gesture, bool opener_suppressed, bool* no_javascript_access) override; diff --git a/third_party/blink/public/web/web_window_features.h b/third_party/blink/public/web/web_window_features.h index 4f735ad0d97eaac9a57dad137e479f8a7ec33a36..0a3c5821962c85609b64b3625fa6b8d658cd9ab2 100644 --- a/third_party/blink/public/web/web_window_features.h +++ b/third_party/blink/public/web/web_window_features.h @@ -31,6 +31,8 @@ #ifndef THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_WINDOW_FEATURES_H_ #define THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_WINDOW_FEATURES_H_ +#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" + namespace blink { struct WebWindowFeatures { @@ -60,6 +62,8 @@ struct WebWindowFeatures { bool noreferrer = false; bool background = false; bool persistent = false; + + String raw_features; }; } // namespace blink diff --git a/third_party/blink/renderer/core/frame/local_dom_window.cc b/third_party/blink/renderer/core/frame/local_dom_window.cc index 908aa4dba7470d9bdf6c57ecee04a107e23f93a3..737c597812fb275829630553de28f37c849f099a 100644 --- a/third_party/blink/renderer/core/frame/local_dom_window.cc +++ b/third_party/blink/renderer/core/frame/local_dom_window.cc @@ -1971,6 +1971,7 @@ DOMWindow* LocalDOMWindow::open(v8::Isolate* isolate, } WebWindowFeatures window_features = GetWindowFeaturesFromString(features); + window_features.raw_features = features; FrameLoadRequest frame_request(incumbent_window, ResourceRequest(completed_url));