123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
- From: Cheng Zhao <[email protected]>
- 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 8aa5ad8401d047197694b0aa908cd48abb479c25..0d2f09549829a55099b60cfc8915a28fbcb9b3d5 100644
- --- a/content/browser/renderer_host/render_frame_host_impl.cc
- +++ b/content/browser/renderer_host/render_frame_host_impl.cc
- @@ -8270,6 +8270,7 @@ void RenderFrameHostImpl::CreateNewWindow(
- last_committed_origin_, params->window_container_type,
- params->target_url, params->referrer.To<Referrer>(),
- 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 d57a64e5b15512bdd9c7c99c5d5ee66cf833640f..161d0c99eb1da6af69a5dcf6bbb6f753e3397b5b 100644
- --- a/content/browser/web_contents/web_contents_impl.cc
- +++ b/content/browser/web_contents/web_contents_impl.cc
- @@ -4492,6 +4492,12 @@ FrameTree* WebContentsImpl::CreateNewWindow(
-
- auto* new_contents_impl = new_contents.get();
-
- + if (delegate_) {
- + delegate_->WebContentsCreatedWithFullParams(this, render_process_id,
- + opener->GetRoutingID(),
- + params, new_contents_impl);
- + }
- +
- // If the new frame has a name, make sure any SiteInstances that can find
- // this named frame have proxies for it. Must be called after
- // SetSessionStorageNamespace, since this calls CreateRenderView, which uses
- @@ -4533,12 +4539,6 @@ FrameTree* WebContentsImpl::CreateNewWindow(
- AddWebContentsDestructionObserver(new_contents_impl);
- }
-
- - if (delegate_) {
- - delegate_->WebContentsCreated(this, render_process_id,
- - opener->GetRoutingID(), params.frame_name,
- - params.target_url, new_contents_impl);
- - }
- -
- observers_.NotifyObservers(&WebContentsObserver::DidOpenRequestedURL,
- new_contents_impl, opener, params.target_url,
- params.referrer.To<Referrer>(), params.disposition,
- diff --git a/content/common/frame.mojom b/content/common/frame.mojom
- index 40c14e1757dee4fda9aa79f3a52532f8ab737a97..2c833d683b737bd6b24d2ec10d97b46d2c9fcdb0 100644
- --- a/content/common/frame.mojom
- +++ b/content/common/frame.mojom
- @@ -598,6 +598,10 @@ struct CreateNewWindowParams {
- // The navigation initiator's user activation and ad status.
- blink.mojom.NavigationInitiatorActivationAndAdStatus
- initiator_activation_and_ad_status;
- +
- + // 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 39b5ff0122f950990ab1cdd7b686fb4429e97a8a..f602a3fac375bcd18a6db25d163efb40de485cd0 100644
- --- a/content/public/browser/content_browser_client.cc
- +++ b/content/public/browser/content_browser_client.cc
- @@ -716,6 +716,8 @@ bool ContentBrowserClient::CanCreateWindow(
- const std::string& frame_name,
- WindowOpenDisposition disposition,
- const blink::mojom::WindowFeatures& features,
- + const std::string& raw_features,
- + const scoped_refptr<network::ResourceRequestBody>& 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 e479adacb16343891c2782973fa9ba8c1925b275..9bef261091b60fcf1b79b224612180f307f8f0c6 100644
- --- a/content/public/browser/content_browser_client.h
- +++ b/content/public/browser/content_browser_client.h
- @@ -177,6 +177,7 @@ class NetworkService;
- class TrustedURLLoaderHeaderClient;
- } // namespace mojom
- struct ResourceRequest;
- +class ResourceRequestBody;
- } // namespace network
-
- namespace sandbox {
- @@ -1153,6 +1154,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<network::ResourceRequestBody>& 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 9f38850f8efe3d9a29a7be6528129b48cf707a80..35c378f2ecedec3fc799189ecb70139ea090a5c2 100644
- --- a/content/public/browser/web_contents_delegate.cc
- +++ b/content/public/browser/web_contents_delegate.cc
- @@ -30,6 +30,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 9fc7ad92817cc7fea982492b08da6e91ec4b8274..2885b140bb3a7e544d6ab7431090252e29e20ea5 100644
- --- a/content/public/browser/web_contents_delegate.h
- +++ b/content/public/browser/web_contents_delegate.h
- @@ -16,6 +16,7 @@
- #include "base/memory/scoped_refptr.h"
- #include "build/build_config.h"
- #include "content/common/content_export.h"
- +#include "content/common/frame.mojom.h"
- #include "content/public/browser/eye_dropper.h"
- #include "content/public/browser/fullscreen_types.h"
- #include "content/public/browser/invalidate_type.h"
- @@ -345,6 +346,13 @@ class CONTENT_EXPORT WebContentsDelegate {
- const StoragePartitionConfig& partition_config,
- 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_frame_impl.cc b/content/renderer/render_frame_impl.cc
- index d7c6222c977058f230d5e6153b1df13e127a9939..47562a65e99b1bdbeca57f1ba69822df768c0291 100644
- --- a/content/renderer/render_frame_impl.cc
- +++ b/content/renderer/render_frame_impl.cc
- @@ -6507,6 +6507,10 @@ WebView* RenderFrameImpl::CreateNewWindow(
- request.HasUserGesture(), GetWebFrame()->IsAdFrame(),
- GetWebFrame()->IsAdScriptInStack());
-
- + 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 51de81df6cb5126a750dab43322f8fc1fc484d80..9cb924a1969eef8d3940cc261e286e10c6d84d5c 100644
- --- a/content/web_test/browser/web_test_content_browser_client.cc
- +++ b/content/web_test/browser/web_test_content_browser_client.cc
- @@ -512,6 +512,8 @@ bool WebTestContentBrowserClient::CanCreateWindow(
- const std::string& frame_name,
- WindowOpenDisposition disposition,
- const blink::mojom::WindowFeatures& features,
- + const std::string& raw_features,
- + const scoped_refptr<network::ResourceRequestBody>& 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 4869a7502ed31ad6101bd89f899325ffef427c0e..954037dc4fdc21b922debb7a123f1e93e788a908 100644
- --- a/content/web_test/browser/web_test_content_browser_client.h
- +++ b/content/web_test/browser/web_test_content_browser_client.h
- @@ -86,6 +86,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<network::ResourceRequestBody>& 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 bef5a989bac50c177f15f52fe87ac3790d553e85..65dcd2e3b51929400c8bfb6a98a4fb59bb6a3d6b 100644
- --- a/third_party/blink/public/web/web_window_features.h
- +++ b/third_party/blink/public/web/web_window_features.h
- @@ -34,6 +34,7 @@
- #include "third_party/abseil-cpp/absl/types/optional.h"
- #include "third_party/blink/public/platform/web_string.h"
- #include "third_party/blink/public/platform/web_vector.h"
- +#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
-
- namespace blink {
-
- @@ -73,6 +74,8 @@ struct WebWindowFeatures {
- // TODO(apaseltiner): Investigate moving this field to a non-public struct
- // since it is only needed within //third_party/blink.
- absl::optional<WebVector<WebString>> attribution_srcs;
- +
- + 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 7405d410af1859db405f3cc7a2169f3aab597631..bb27d4350590bc7712a271567e1457e6551c7f7d 100644
- --- a/third_party/blink/renderer/core/frame/local_dom_window.cc
- +++ b/third_party/blink/renderer/core/frame/local_dom_window.cc
- @@ -2175,6 +2175,8 @@ DOMWindow* LocalDOMWindow::open(v8::Isolate* isolate,
- WebWindowFeatures window_features =
- GetWindowFeaturesFromString(features, entered_window);
-
- + window_features.raw_features = features;
- +
- // In fenced frames, we should always use `noopener`.
- if (GetFrame()->IsInFencedFrameTree()) {
- window_features.noopener = true;
|