electron/patches/chromium/can_create_window.patch
Electron Bot 8383c14aba
chore: bump chromium to 7264889ce3aad1568ff3d211c81fe (master) (#27003)
* chore: bump chromium in DEPS to 91c9f44297abe2844f593ec7956e6ce79c81f463

* chore: update chromium patches

* chore: update v8 patches

* build: service_names.mojom has been deleted

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2568681

* chore: add DISPLAY_CAPTURE permission to converter

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2551098

* chore: handle AXPropertyFilter::SCRIPT in accessibility_ui

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2563923

* refactor: web_isolated_world_ids.h has been deleted

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2585255

* refactor: ResourceType has been deprecated / removed in ExtensionsBrowserClient

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2562002

* chore: fix lint

* chore: remove deleted headers

* build: disable gn check for blink header

* fix: refactor X11 event handling

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2577887
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2585750

* chore: update patches

* chore: bump chromium in DEPS to bfd8e7dbd37af8b1bc40d887815edd5a29496fa3

* chore: update patches

* refactor: xeventobserver is now x11:eventobserver

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2585750

* refactor: remove UseWebUIBindingsForURL

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2583590

* chore: DidProcessXEvent has been removed

* chore: bump chromium in DEPS to b13e791d7244a08d9d61dbfa2bb2b6cdf1ff6294

* chore: update patches

* build: change gfx::GetAtom to x11:GetAtom

Refs: d972a0ae4a

* build: change gfx namespace to x11

Ref: d972a0ae4a

* build: change ui namespace to x11

Refs: c38f8571a8:ui/gfx/x/xproto_util.h;dlc=ba9145d0c7f2b10e869e2ba482ca05b75ca35812

* chore: add patch to fix blink prefs fetching during frame swap

* chore: fix lint

* fix: do not make invalid SKImageRep in FrameSubscriber

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2572896

Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com>
2020-12-22 14:14:44 -08:00

234 lines
11 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Cheng Zhao <zcbenz@gmail.com>
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 6c0bb3d6b85d31d4a80a57a7bcee481ed721b158..145c09e1d27a0142c36640001c618081c8e6ecaf 100644
--- a/content/browser/renderer_host/render_frame_host_impl.cc
+++ b/content/browser/renderer_host/render_frame_host_impl.cc
@@ -5220,6 +5220,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 d5309b32ad9fa4e85d6574bbed062c985fa49baa..5289f745a02e3df7157197b515031f9749b101fd 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -3585,6 +3585,14 @@ RenderFrameHostDelegate* WebContentsImpl::CreateNewWindow(
}
auto* new_contents_impl = new_contents.get();
+ // Call this earlier than Chrome to associate the web preferences with the
+ // WebContents before the view gets created.
+ if (delegate_) {
+ delegate_->WebContentsCreatedWithFullParams(this, render_process_id,
+ opener->GetRoutingID(),
+ params, new_contents_impl);
+ }
+
new_contents_impl->GetController().SetSessionStorageNamespace(
partition_id, session_storage_namespace);
@@ -3626,12 +3634,6 @@ RenderFrameHostDelegate* WebContentsImpl::CreateNewWindow(
AddDestructionObserver(new_contents_impl);
}
- if (delegate_) {
- delegate_->WebContentsCreated(this, render_process_id,
- opener->GetRoutingID(), params.frame_name,
- params.target_url, new_contents_impl);
- }
-
observers_.ForEachObserver([&](WebContentsObserver* observer) {
observer->DidOpenRequestedURL(new_contents_impl, opener, params.target_url,
params.referrer.To<Referrer>(),
diff --git a/content/common/frame.mojom b/content/common/frame.mojom
index 68fcf36b593374bb21ef5f6471d43c5b47df6368..c20549d289d82d45c855dd7ae558595f267537e1 100644
--- a/content/common/frame.mojom
+++ b/content/common/frame.mojom
@@ -280,6 +280,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 84f1ea2245477d3a64ad3e550e5ff3b500e4cbfa..05b2d9b76ae5c5f2a39303282a9c5c7326489d3b 100644
--- a/content/public/browser/content_browser_client.cc
+++ b/content/public/browser/content_browser_client.cc
@@ -544,6 +544,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 4bb333f23c05d078bc0894b2a4953b46c36e48bc..bdb9c61af7c5b84c358a8e0282e4c06fcb05fdfe 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 {
@@ -877,6 +878,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 23ef0fe1e0275778bccd1bbae8ec46fa3dc24a7c..41bae2ebe3c6db1fc81a90763f304e90b8a1005c 100644
--- a/content/public/browser/web_contents_delegate.cc
+++ b/content/public/browser/web_contents_delegate.cc
@@ -27,6 +27,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 21d30d1b60ba870a35be87f8d1823ef5e3902a01..73b85693d59f25160df21c3b535869b3d03c3a76 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/eye_dropper.h"
#include "content/public/browser/invalidate_type.h"
#include "content/public/browser/media_stream_request.h"
@@ -337,6 +338,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 95450cc45b57977f75644da65b878a6ab259485b..37f3ddc08388112916d52156d791a758ea7d7d48 100644
--- a/content/renderer/render_view_impl.cc
+++ b/content/renderer/render_view_impl.cc
@@ -27,6 +27,7 @@
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/platform/modules/video_capture/web_video_capture_impl_manager.h"
#include "third_party/blink/public/platform/url_conversion.h"
+#include "third_party/blink/public/platform/web_url_request_util.h"
#include "third_party/blink/public/web/modules/mediastream/web_media_stream_device_observer.h"
#include "third_party/blink/public/web/web_frame_widget.h"
#include "third_party/blink/public/web/web_local_frame.h"
@@ -380,6 +381,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 565e73f6c43fb8e20d31a094768fddda388d3768..a0acffed269faa7c9e3715744fa6c6b099813469 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<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 15262ff3e3a7be037d5eedda3279c8897628e4d8..4e285a97787d9f487b5424b2dfc2b0fff2df53a2 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<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 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 9016c40b451c8f3a43737f24b120e3ffce5f9d04..f55023b59fdc76322d7415501a67331c427b3098 100644
--- a/third_party/blink/renderer/core/frame/local_dom_window.cc
+++ b/third_party/blink/renderer/core/frame/local_dom_window.cc
@@ -1954,6 +1954,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));