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-01-10 10:52:34 -06:00
|
|
|
index ea77770f7412bc4507897d6edf423966b2111eb4..88396edf058aaf6f18ae8cf09cb7175de5ae8d1c 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-01-10 10:52:34 -06:00
|
|
|
@@ -9244,6 +9244,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-01-10 10:52:34 -06:00
|
|
|
index e131c77f42a7f5183319ff41ec57118981fe76f7..9175a4958c80451dc80205d10856cac40785140e 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-01-10 10:52:34 -06:00
|
|
|
@@ -4947,6 +4947,12 @@ FrameTree* WebContentsImpl::CreateNewWindow(
|
2024-09-17 18:12:11 -07:00
|
|
|
SetPartitionedPopinOpenerOnNewWindowIfNeeded(new_contents_impl, params,
|
|
|
|
opener);
|
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-01-10 10:52:34 -06:00
|
|
|
@@ -4988,12 +4994,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-01-10 10:52:34 -06:00
|
|
|
index 91dcf6c9c4a2d840fb50cb329fe3ef1bba9103c3..cbc887a3034605a93468e73a310e9ca6838b32d8 100644
|
2018-09-13 22:02:16 -07:00
|
|
|
--- a/content/common/frame.mojom
|
|
|
|
+++ b/content/common/frame.mojom
|
2025-01-10 10:52:34 -06:00
|
|
|
@@ -621,6 +621,10 @@ struct CreateNewWindowParams {
|
2023-01-05 21:35:34 -05:00
|
|
|
// The navigation initiator's user activation and ad status.
|
|
|
|
blink.mojom.NavigationInitiatorActivationAndAdStatus
|
|
|
|
initiator_activation_and_ad_status;
|
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-01-10 10:52:34 -06:00
|
|
|
index a344bce909add234e5757ddd08d2fafa5e732a42..de3b79ada34d261ab452efd1934bb3ea4fb74c03 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-01-10 10:52:34 -06:00
|
|
|
@@ -790,6 +790,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-01-10 10:52:34 -06:00
|
|
|
index f3cf5f2d45503b683488c3b39708057749fccdfd..87388bf398413d963a4902bfbd43e6509982fb33 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-01-10 10:52:34 -06:00
|
|
|
@@ -201,6 +201,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-01-10 10:52:34 -06:00
|
|
|
@@ -1347,6 +1348,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-01-10 10:52:34 -06:00
|
|
|
index 2f27fcb0b320d1dcfeb398d34770a9a48ea49915..4d2c03d7102d1217d1b436bf17fa9f293239b049 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
|
2024-09-25 06:19:39 -05:00
|
|
|
@@ -31,6 +31,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-01-10 10:52:34 -06:00
|
|
|
index 0bab4dd08a28dd572c9cac00c337672af6aee352..d17b95b6b0c9842b6db3d4696525984fbbcc8ddd 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"
|
2024-08-12 10:28:33 +02:00
|
|
|
#include "content/public/browser/back_forward_transition_animation_manager.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-10 10:52:34 -06:00
|
|
|
@@ -366,6 +367,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-01-10 10:52:34 -06:00
|
|
|
index 7431b6773d9f0a38f30c00fbff2fa45076beedc9..2f3190e81c665cdfbf75ffee9bf09c5936b4a760 100644
|
2022-09-07 09:46:37 +02:00
|
|
|
--- a/content/renderer/render_frame_impl.cc
|
|
|
|
+++ b/content/renderer/render_frame_impl.cc
|
2025-01-10 10:52:34 -06:00
|
|
|
@@ -6863,6 +6863,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(
|
2024-12-10 13:16:07 -06:00
|
|
|
+ WTF::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-01-10 10:52:34 -06:00
|
|
|
index 5d4101558a3672b747f8f62d4ffaa84416df06a7..204664c08f14bcaf45e287a18fad4aea24a7fa72 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-01-10 10:52:34 -06:00
|
|
|
@@ -523,6 +523,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
|
2024-12-10 13:16:07 -06:00
|
|
|
index 3a6f32f6412b914d24632a1c25d401de7a8ffbf0..0442c6243dbb38b2723e5e803bb403a157df3bcd 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
|
2024-07-29 09:37:35 -04:00
|
|
|
@@ -92,6 +92,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
|
2024-08-19 14:52:53 -04:00
|
|
|
index c576ace24e81cc877aa2595d40e0a13a7af9f6a2..210fb97d44c19c29af424cc7b9cb31690cfcc565 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 @@
|
|
|
|
|
2023-04-12 18:10:31 -07:00
|
|
|
#include "third_party/blink/public/platform/web_string.h"
|
2023-05-10 10:47:48 -04:00
|
|
|
#include "third_party/blink/public/platform/web_vector.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.
|
2024-02-14 12:33:32 -05:00
|
|
|
std::optional<WebVector<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-01-10 10:52:34 -06:00
|
|
|
index 3287ea39797ceca64947f9d69f6bcb6dcb8de56e..f7b31e1cfd29c2c5385b33024448d46ac8d79bd3 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-01-10 10:52:34 -06:00
|
|
|
@@ -2226,6 +2226,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);
|