2018-10-24 11:24:11 -07:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2018-09-20 17:30:26 -07:00
|
|
|
From: Cheng Zhao <zcbenz@gmail.com>
|
|
|
|
Date: Thu, 20 Sep 2018 17:45:32 -0700
|
|
|
|
Subject: can_create_window.patch
|
|
|
|
|
2019-12-13 09:18:45 -08:00
|
|
|
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.
|
2018-09-20 17:30:26 -07:00
|
|
|
|
2020-09-21 01:00:36 -07:00
|
|
|
diff --git a/content/browser/renderer_host/render_frame_host_impl.cc b/content/browser/renderer_host/render_frame_host_impl.cc
|
2025-07-15 12:05:29 -04:00
|
|
|
index 63b6d11a3752cf7eea37e477ae438a4375e6ac4f..b0de3dc68c75388591e54cc3c1d8e8c7a56a8773 100644
|
2020-09-21 01:00:36 -07:00
|
|
|
--- a/content/browser/renderer_host/render_frame_host_impl.cc
|
|
|
|
+++ b/content/browser/renderer_host/render_frame_host_impl.cc
|
2025-07-15 12:05:29 -04:00
|
|
|
@@ -9757,6 +9757,7 @@ void RenderFrameHostImpl::CreateNewWindow(
|
2019-01-16 23:37:52 +05:30
|
|
|
last_committed_origin_, params->window_container_type,
|
2019-01-08 15:59:47 -08:00
|
|
|
params->target_url, params->referrer.To<Referrer>(),
|
|
|
|
params->frame_name, params->disposition, *params->features,
|
2020-03-26 19:05:45 +01:00
|
|
|
+ params->raw_features, params->body,
|
2018-09-20 17:30:26 -07:00
|
|
|
effective_transient_activation_state, params->opener_suppressed,
|
|
|
|
&no_javascript_access);
|
2020-04-06 13:09:52 -07:00
|
|
|
|
2020-03-26 19:05:45 +01:00
|
|
|
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
|
2025-07-15 12:05:29 -04:00
|
|
|
index f4cb3ab03bba197652e000a1cdfd8593d526b5cc..133718bc2e270ac7ed02ef4a7f17bf4efb773d5c 100644
|
2020-03-26 19:05:45 +01:00
|
|
|
--- a/content/browser/web_contents/web_contents_impl.cc
|
|
|
|
+++ b/content/browser/web_contents/web_contents_impl.cc
|
2025-07-15 12:05:29 -04:00
|
|
|
@@ -5287,6 +5287,12 @@ FrameTree* WebContentsImpl::CreateNewWindow(
|
2025-05-13 14:51:20 -04:00
|
|
|
// Sets the newly created WebContents WindowOpenDisposition.
|
|
|
|
new_contents_impl->original_window_open_disposition_ = params.disposition;
|
2020-04-06 13:09:52 -07:00
|
|
|
|
2020-11-10 09:06:03 -08:00
|
|
|
+ if (delegate_) {
|
2020-03-26 19:05:45 +01:00
|
|
|
+ delegate_->WebContentsCreatedWithFullParams(this, render_process_id,
|
|
|
|
+ opener->GetRoutingID(),
|
|
|
|
+ params, new_contents_impl);
|
2020-11-10 09:06:03 -08:00
|
|
|
+ }
|
|
|
|
+
|
2022-12-05 17:59:19 -05:00
|
|
|
// 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
|
2025-07-15 12:05:29 -04:00
|
|
|
@@ -5328,12 +5334,6 @@ FrameTree* WebContentsImpl::CreateNewWindow(
|
2021-03-04 09:27:05 -08:00
|
|
|
AddWebContentsDestructionObserver(new_contents_impl);
|
2020-03-26 19:05:45 +01:00
|
|
|
}
|
2020-04-06 13:09:52 -07:00
|
|
|
|
2020-11-10 09:06:03 -08:00
|
|
|
- if (delegate_) {
|
|
|
|
- delegate_->WebContentsCreated(this, render_process_id,
|
|
|
|
- opener->GetRoutingID(), params.frame_name,
|
|
|
|
- params.target_url, new_contents_impl);
|
|
|
|
- }
|
|
|
|
-
|
2021-02-09 12:16:21 -08:00
|
|
|
observers_.NotifyObservers(&WebContentsObserver::DidOpenRequestedURL,
|
|
|
|
new_contents_impl, opener, params.target_url,
|
|
|
|
params.referrer.To<Referrer>(), params.disposition,
|
2018-09-13 22:02:16 -07:00
|
|
|
diff --git a/content/common/frame.mojom b/content/common/frame.mojom
|
2025-07-15 12:05:29 -04:00
|
|
|
index 0dfcbbd0e3274d01d938f843530b61a52028771d..14007f8b9c30a72b8303eccd1891a7fd409cc7ad 100644
|
2018-09-13 22:02:16 -07:00
|
|
|
--- a/content/common/frame.mojom
|
|
|
|
+++ b/content/common/frame.mojom
|
2025-05-13 14:51:20 -04:00
|
|
|
@@ -653,6 +653,10 @@ struct CreateNewWindowParams {
|
2025-03-18 19:20:54 -04:00
|
|
|
pending_associated_remote<blink.mojom.Widget> widget;
|
|
|
|
pending_associated_receiver<blink.mojom.FrameWidgetHost> frame_widget_host;
|
|
|
|
pending_associated_remote<blink.mojom.FrameWidget> frame_widget;
|
2018-09-13 22:02:16 -07:00
|
|
|
+
|
|
|
|
+ // Extra fields added by Electron.
|
2020-03-26 19:05:45 +01:00
|
|
|
+ string raw_features;
|
2019-01-24 20:22:14 +05:30
|
|
|
+ network.mojom.URLRequestBody? body;
|
2018-09-13 22:02:16 -07:00
|
|
|
};
|
2020-04-06 13:09:52 -07:00
|
|
|
|
2018-09-13 22:02:16 -07:00
|
|
|
// 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
|
2025-07-15 12:05:29 -04:00
|
|
|
index 8b21f2ba284ece1d6b339cf10dfe9181fae9b1d7..a1f71d06e8f205d651c5a3f8a3f1af3e774d6800 100644
|
2018-09-13 22:02:16 -07:00
|
|
|
--- a/content/public/browser/content_browser_client.cc
|
|
|
|
+++ b/content/public/browser/content_browser_client.cc
|
2025-07-15 12:05:29 -04:00
|
|
|
@@ -858,6 +858,8 @@ bool ContentBrowserClient::CanCreateWindow(
|
2018-09-13 22:02:16 -07:00
|
|
|
const std::string& frame_name,
|
|
|
|
WindowOpenDisposition disposition,
|
|
|
|
const blink::mojom::WindowFeatures& features,
|
2020-03-26 19:05:45 +01:00
|
|
|
+ const std::string& raw_features,
|
2018-09-13 22:02:16 -07:00
|
|
|
+ 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
|
2025-07-15 12:05:29 -04:00
|
|
|
index 3244924132a833c7c712aa46f96e990cacf42eca..96f343fa47565d6f88925548b1f1c7f9b5c8736c 100644
|
2018-09-13 22:02:16 -07:00
|
|
|
--- a/content/public/browser/content_browser_client.h
|
|
|
|
+++ b/content/public/browser/content_browser_client.h
|
2025-07-15 12:05:29 -04:00
|
|
|
@@ -199,6 +199,7 @@ class NetworkService;
|
2019-10-28 18:12:35 -04:00
|
|
|
class TrustedURLLoaderHeaderClient;
|
|
|
|
} // namespace mojom
|
|
|
|
struct ResourceRequest;
|
2018-09-13 22:02:16 -07:00
|
|
|
+class ResourceRequestBody;
|
2019-10-28 18:12:35 -04:00
|
|
|
} // namespace network
|
2020-04-06 13:09:52 -07:00
|
|
|
|
2020-06-22 10:35:10 -07:00
|
|
|
namespace sandbox {
|
2025-07-15 12:05:29 -04:00
|
|
|
@@ -1425,6 +1426,8 @@ class CONTENT_EXPORT ContentBrowserClient {
|
2018-09-13 22:02:16 -07:00
|
|
|
const std::string& frame_name,
|
|
|
|
WindowOpenDisposition disposition,
|
|
|
|
const blink::mojom::WindowFeatures& features,
|
2020-03-26 19:05:45 +01:00
|
|
|
+ const std::string& raw_features,
|
2018-09-13 22:02:16 -07:00
|
|
|
+ const scoped_refptr<network::ResourceRequestBody>& body,
|
|
|
|
bool user_gesture,
|
|
|
|
bool opener_suppressed,
|
|
|
|
bool* no_javascript_access);
|
2020-03-26 19:05:45 +01:00
|
|
|
diff --git a/content/public/browser/web_contents_delegate.cc b/content/public/browser/web_contents_delegate.cc
|
2025-06-30 12:29:54 -04:00
|
|
|
index ca92e2ddf78d8f386b5ab23a09876d3b44e21334..33be50ce93dd998df5244f9ade391943f06978ad 100644
|
2020-03-26 19:05:45 +01:00
|
|
|
--- a/content/public/browser/web_contents_delegate.cc
|
|
|
|
+++ b/content/public/browser/web_contents_delegate.cc
|
2025-02-14 11:05:01 +01:00
|
|
|
@@ -32,6 +32,17 @@ namespace content {
|
2020-04-06 13:09:52 -07:00
|
|
|
|
2020-03-26 19:05:45 +01:00
|
|
|
WebContentsDelegate::WebContentsDelegate() = default;
|
2020-04-06 13:09:52 -07:00
|
|
|
|
2020-03-26 19:05:45 +01:00
|
|
|
+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);
|
|
|
|
+}
|
|
|
|
+
|
2024-04-15 18:10:32 -04:00
|
|
|
WebContents* WebContentsDelegate::OpenURLFromTab(
|
|
|
|
WebContents* source,
|
|
|
|
const OpenURLParams& params,
|
2020-03-26 19:05:45 +01:00
|
|
|
diff --git a/content/public/browser/web_contents_delegate.h b/content/public/browser/web_contents_delegate.h
|
2025-07-15 12:05:29 -04:00
|
|
|
index 4c687a84d14d5fa8cd5e376580b594ed0d116ef5..1a71f8020ba4de7bd4966bb02563155237659c32 100644
|
2020-03-26 19:05:45 +01:00
|
|
|
--- a/content/public/browser/web_contents_delegate.h
|
|
|
|
+++ b/content/public/browser/web_contents_delegate.h
|
2024-11-14 18:18:11 +01:00
|
|
|
@@ -18,6 +18,7 @@
|
|
|
|
#include "base/types/expected.h"
|
2020-03-26 19:05:45 +01:00
|
|
|
#include "build/build_config.h"
|
|
|
|
#include "content/common/content_export.h"
|
|
|
|
+#include "content/common/frame.mojom.h"
|
2020-05-26 13:06:26 -07:00
|
|
|
#include "content/public/browser/eye_dropper.h"
|
2023-03-10 10:07:42 -06:00
|
|
|
#include "content/public/browser/fullscreen_types.h"
|
2025-01-23 23:07:43 -05:00
|
|
|
#include "content/public/browser/invalidate_type.h"
|
2025-07-15 12:05:29 -04:00
|
|
|
@@ -383,6 +384,13 @@ class CONTENT_EXPORT WebContentsDelegate {
|
2022-02-25 13:17:35 -05:00
|
|
|
const StoragePartitionConfig& partition_config,
|
2020-03-26 19:05:45 +01:00
|
|
|
SessionStorageNamespace* session_storage_namespace);
|
2020-04-06 13:09:52 -07:00
|
|
|
|
2020-03-26 19:05:45 +01:00
|
|
|
+ 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,
|
2022-09-07 09:46:37 +02:00
|
|
|
diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc
|
2025-07-15 12:05:29 -04:00
|
|
|
index 414af5f3574d3fa7c45a5b809cd99d19e5202160..b74623455d53d109a97e6c767f56a9beeb0e87e5 100644
|
2022-09-07 09:46:37 +02:00
|
|
|
--- a/content/renderer/render_frame_impl.cc
|
|
|
|
+++ b/content/renderer/render_frame_impl.cc
|
2025-07-15 12:05:29 -04:00
|
|
|
@@ -6756,6 +6756,10 @@ WebView* RenderFrameImpl::CreateNewWindow(
|
2023-07-19 00:26:27 +02:00
|
|
|
request.HasUserGesture(), GetWebFrame()->IsAdFrame(),
|
|
|
|
GetWebFrame()->IsAdScriptInStack());
|
2021-02-09 12:16:21 -08:00
|
|
|
|
2020-03-26 19:05:45 +01:00
|
|
|
+ params->raw_features = features.raw_features.Utf8(
|
2025-07-15 12:05:29 -04:00
|
|
|
+ blink::Utf8ConversionMode::kStrictReplacingErrors);
|
2019-01-24 20:22:14 +05:30
|
|
|
+ params->body = GetRequestBodyForWebURLRequest(request);
|
2021-02-09 12:16:21 -08:00
|
|
|
+
|
2022-06-01 08:12:47 +02:00
|
|
|
// We preserve this information before sending the message since |params| is
|
|
|
|
// moved on send.
|
|
|
|
bool is_background_tab =
|
2020-09-21 01:00:36 -07:00
|
|
|
diff --git a/content/web_test/browser/web_test_content_browser_client.cc b/content/web_test/browser/web_test_content_browser_client.cc
|
2025-07-15 12:05:29 -04:00
|
|
|
index 66a10226b043a490295e518230c20bba0ed71d6c..14b78014d93ce459789fd497dfcfb71e2cc769bd 100644
|
2020-09-21 01:00:36 -07:00
|
|
|
--- a/content/web_test/browser/web_test_content_browser_client.cc
|
|
|
|
+++ b/content/web_test/browser/web_test_content_browser_client.cc
|
2025-06-30 12:29:54 -04:00
|
|
|
@@ -537,6 +537,8 @@ bool WebTestContentBrowserClient::CanCreateWindow(
|
2018-09-13 22:02:16 -07:00
|
|
|
const std::string& frame_name,
|
|
|
|
WindowOpenDisposition disposition,
|
|
|
|
const blink::mojom::WindowFeatures& features,
|
2020-03-26 19:05:45 +01:00
|
|
|
+ const std::string& raw_features,
|
2018-09-13 22:02:16 -07:00
|
|
|
+ const scoped_refptr<network::ResourceRequestBody>& body,
|
|
|
|
bool user_gesture,
|
|
|
|
bool opener_suppressed,
|
|
|
|
bool* no_javascript_access) {
|
2020-09-21 01:00:36 -07:00
|
|
|
diff --git a/content/web_test/browser/web_test_content_browser_client.h b/content/web_test/browser/web_test_content_browser_client.h
|
2025-07-15 12:05:29 -04:00
|
|
|
index 790f004d2a3a9ae5a3588fda097732a5daac0c75..83fcc9418b89b669863e730f2049a1d836eef260 100644
|
2020-09-21 01:00:36 -07:00
|
|
|
--- a/content/web_test/browser/web_test_content_browser_client.h
|
|
|
|
+++ b/content/web_test/browser/web_test_content_browser_client.h
|
2025-07-15 12:05:29 -04:00
|
|
|
@@ -98,6 +98,8 @@ class WebTestContentBrowserClient : public ShellContentBrowserClient {
|
2018-09-13 22:02:16 -07:00
|
|
|
const std::string& frame_name,
|
|
|
|
WindowOpenDisposition disposition,
|
|
|
|
const blink::mojom::WindowFeatures& features,
|
2020-03-26 19:05:45 +01:00
|
|
|
+ const std::string& raw_features,
|
2018-09-13 22:02:16 -07:00
|
|
|
+ const scoped_refptr<network::ResourceRequestBody>& body,
|
|
|
|
bool user_gesture,
|
|
|
|
bool opener_suppressed,
|
|
|
|
bool* no_javascript_access) override;
|
2020-03-26 19:05:45 +01:00
|
|
|
diff --git a/third_party/blink/public/web/web_window_features.h b/third_party/blink/public/web/web_window_features.h
|
2025-02-06 15:30:54 -05:00
|
|
|
index 82e9d3dfb5f7da76d89fe15ae61d379fa46e177d..fd035512099a54dff6cc951a2226c23a252a90e2 100644
|
2020-03-26 19:05:45 +01:00
|
|
|
--- a/third_party/blink/public/web/web_window_features.h
|
|
|
|
+++ b/third_party/blink/public/web/web_window_features.h
|
2024-02-14 12:33:32 -05:00
|
|
|
@@ -35,6 +35,7 @@
|
2025-02-06 15:30:54 -05:00
|
|
|
#include <vector>
|
2024-02-14 12:33:32 -05:00
|
|
|
|
2023-04-12 18:10:31 -07:00
|
|
|
#include "third_party/blink/public/platform/web_string.h"
|
2020-03-26 19:05:45 +01:00
|
|
|
+#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
|
2021-05-05 16:26:17 -07:00
|
|
|
|
2020-03-26 19:05:45 +01:00
|
|
|
namespace blink {
|
2020-04-06 13:09:52 -07:00
|
|
|
|
2024-08-19 14:52:53 -04:00
|
|
|
@@ -74,6 +75,8 @@ struct WebWindowFeatures {
|
2023-05-10 10:47:48 -04:00
|
|
|
// TODO(apaseltiner): Investigate moving this field to a non-public struct
|
|
|
|
// since it is only needed within //third_party/blink.
|
2025-02-06 15:30:54 -05:00
|
|
|
std::optional<std::vector<WebString>> attribution_srcs;
|
2020-03-26 19:05:45 +01:00
|
|
|
+
|
|
|
|
+ String raw_features;
|
|
|
|
};
|
2020-04-06 13:09:52 -07:00
|
|
|
|
2020-03-26 19:05:45 +01:00
|
|
|
} // 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
|
2025-07-15 12:05:29 -04:00
|
|
|
index 03277987be8d0799b8ae61b6714bc71f74adb5f0..12e6ca5e45c16a76c0bac3674e74def93f0a0593 100644
|
2020-03-26 19:05:45 +01:00
|
|
|
--- a/third_party/blink/renderer/core/frame/local_dom_window.cc
|
|
|
|
+++ b/third_party/blink/renderer/core/frame/local_dom_window.cc
|
2025-06-16 12:46:06 -05:00
|
|
|
@@ -2317,6 +2317,8 @@ DOMWindow* LocalDOMWindow::open(v8::Isolate* isolate,
|
2021-05-05 16:26:17 -07:00
|
|
|
WebWindowFeatures window_features =
|
2023-04-12 18:10:31 -07:00
|
|
|
GetWindowFeaturesFromString(features, entered_window);
|
2024-08-22 13:16:40 -05:00
|
|
|
|
2024-08-26 15:09:33 -04:00
|
|
|
+ window_features.raw_features = features;
|
|
|
|
+
|
2024-09-17 18:12:11 -07:00
|
|
|
if (window_features.is_partitioned_popin) {
|
|
|
|
UseCounter::Count(*entered_window,
|
|
|
|
WebFeature::kPartitionedPopin_OpenAttempt);
|