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
|
2022-11-17 14:59:23 -05:00
|
|
|
index b44b331f03bad11a8433ca7d0a2e03d9c9a355fa..92d18de4b9830c2f1ee43e0c58c1735344425c0d 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
|
2022-11-17 14:59:23 -05:00
|
|
|
@@ -7269,6 +7269,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
|
2022-11-17 14:59:23 -05:00
|
|
|
index a7e56cc23e50930b038be9ecc285e506c783f72a..027c035405567ccb2d45b97a63ac7e2a29c96ac5 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
|
2022-11-17 14:59:23 -05:00
|
|
|
@@ -4032,6 +4032,14 @@ FrameTree* WebContentsImpl::CreateNewWindow(
|
2020-03-26 19:05:45 +01:00
|
|
|
}
|
2020-11-10 09:06:03 -08:00
|
|
|
auto* new_contents_impl = new_contents.get();
|
2020-04-06 13:09:52 -07:00
|
|
|
|
2020-11-10 09:06:03 -08:00
|
|
|
+ // Call this earlier than Chrome to associate the web preferences with the
|
|
|
|
+ // WebContents before the view gets created.
|
|
|
|
+ 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
|
|
|
+ }
|
|
|
|
+
|
|
|
|
new_contents_impl->GetController().SetSessionStorageNamespace(
|
2022-02-25 13:17:35 -05:00
|
|
|
partition_config, session_storage_namespace);
|
2020-11-10 09:06:03 -08:00
|
|
|
|
2022-11-17 14:59:23 -05:00
|
|
|
@@ -4076,12 +4084,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
|
2022-11-17 14:59:23 -05:00
|
|
|
index d4f2e7f78c601ed7ab5514cfa731e04b7597a7b2..9a9a9766b34e00bce4bb5bf211a0809735021304 100644
|
2018-09-13 22:02:16 -07:00
|
|
|
--- a/content/common/frame.mojom
|
|
|
|
+++ b/content/common/frame.mojom
|
2022-11-17 14:59:23 -05:00
|
|
|
@@ -587,6 +587,10 @@ struct CreateNewWindowParams {
|
2021-09-01 15:55:07 -04:00
|
|
|
|
2022-07-13 17:26:16 -04:00
|
|
|
// Additional parameters for creating picture-in-picture windows.
|
|
|
|
blink.mojom.PictureInPictureWindowOptions? pip_options;
|
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
|
2022-11-17 14:59:23 -05:00
|
|
|
index 560e66d4e402c7c114fae8c5bac750cf1029b32c..bd85708729c32381ea982d894a6be26783f8cc3f 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
|
2022-11-17 14:59:23 -05:00
|
|
|
@@ -625,6 +625,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
|
2022-11-17 14:59:23 -05:00
|
|
|
index bdb4632c5653457a1a8e024a6a9c9f5c4d823610..c5797e84287faa8df154e60e5db230598aa6d5ff 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
|
2022-11-17 14:59:23 -05:00
|
|
|
@@ -164,6 +164,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 {
|
2022-11-17 14:59:23 -05:00
|
|
|
@@ -1017,6 +1018,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
|
2022-11-17 14:59:23 -05:00
|
|
|
index 7122abf89f48a931a5abd38de03d3aebb6d0fb09..eec7f60003267f91f856dc347b31ab8d637fc674 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
|
2022-10-03 13:21:00 -07:00
|
|
|
@@ -27,6 +27,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);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
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
|
2022-11-17 14:59:23 -05:00
|
|
|
index e2ce097fb78d853bb7098b1ce7dacfadd6d188d9..a082d41de24f963fe170108e80601946a25fa5f9 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
|
2021-03-16 10:01:00 -04:00
|
|
|
@@ -16,6 +16,7 @@
|
|
|
|
#include "base/memory/scoped_refptr.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"
|
2020-11-13 16:16:56 -08:00
|
|
|
#include "content/public/browser/invalidate_type.h"
|
|
|
|
#include "content/public/browser/media_stream_request.h"
|
2022-10-03 13:21:00 -07:00
|
|
|
@@ -342,6 +343,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
|
2022-11-17 14:59:23 -05:00
|
|
|
index aee69f38859264537ab9326d4682999922afbc14..21b3808c10368e54d7e68acdcd1763465410a854 100644
|
2022-09-07 09:46:37 +02:00
|
|
|
--- a/content/renderer/render_frame_impl.cc
|
|
|
|
+++ b/content/renderer/render_frame_impl.cc
|
2022-11-17 14:59:23 -05:00
|
|
|
@@ -6228,6 +6228,10 @@ WebView* RenderFrameImpl::CreateNewWindow(
|
2022-09-07 09:46:37 +02:00
|
|
|
/*openee_can_access_opener_origin=*/true,
|
|
|
|
!GetWebFrame()->IsAllowedToDownload(), GetWebFrame()->IsAdFrame());
|
2021-02-09 12:16:21 -08:00
|
|
|
|
2020-03-26 19:05:45 +01:00
|
|
|
+ params->raw_features = features.raw_features.Utf8(
|
|
|
|
+ WTF::UTF8ConversionMode::kStrictUTF8ConversionReplacingUnpairedSurrogatesWithFFFD);
|
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
|
2022-11-17 14:59:23 -05:00
|
|
|
index 7881b779d60d2a1cc4deff874c0b740e9e2fa167..d43c29a42a2f9e5d99462e3037b9483081595158 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
|
2022-09-07 09:46:37 +02:00
|
|
|
@@ -482,6 +482,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
|
2022-10-03 13:21:00 -07:00
|
|
|
index 0b77223b1fa7a24599c89621423ad9d66f36c114..848029e3f293d11421598c0e5ecf3593b1720bb3 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
|
2022-07-13 17:26:16 -04:00
|
|
|
@@ -81,6 +81,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
|
2022-06-01 08:12:47 +02:00
|
|
|
index 34570168ccb123f5102dcf8fa6bbf98e7c373ec6..192701e56d258da41b3724292853885e4daf3420 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
|
2021-05-05 16:26:17 -07:00
|
|
|
@@ -34,6 +34,7 @@
|
2021-05-19 16:15:47 -07:00
|
|
|
#include "third_party/abseil-cpp/absl/types/optional.h"
|
2020-04-06 13:09:52 -07:00
|
|
|
|
2022-06-01 08:12:47 +02:00
|
|
|
#include "third_party/blink/public/common/navigation/impression.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
|
|
|
|
2021-05-05 16:26:17 -07:00
|
|
|
@@ -68,6 +69,8 @@ struct WebWindowFeatures {
|
|
|
|
// Represents the attribution source declared by Attribution Reporting related
|
|
|
|
// window features, if any.
|
2022-06-01 08:12:47 +02:00
|
|
|
absl::optional<Impression> impression;
|
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
|
2022-11-17 14:59:23 -05:00
|
|
|
index 35a36f218131621074dc15f674cfd847e2d528ce..b02457eb22f9b43e552ae4aebbfcbfff6abd9f2f 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
|
2022-11-17 14:59:23 -05:00
|
|
|
@@ -2179,6 +2179,8 @@ DOMWindow* LocalDOMWindow::open(v8::Isolate* isolate,
|
2021-05-05 16:26:17 -07:00
|
|
|
WebWindowFeatures window_features =
|
2022-09-07 09:46:37 +02:00
|
|
|
GetWindowFeaturesFromString(features, entered_window, completed_url);
|
2020-04-06 13:09:52 -07:00
|
|
|
|
2022-06-27 15:50:08 -05:00
|
|
|
+ window_features.raw_features = features;
|
|
|
|
+
|
2022-04-12 13:19:14 +02:00
|
|
|
// In fenced frames, we should always use `noopener`.
|
|
|
|
if (GetFrame()->IsInFencedFrameTree()) {
|
2022-06-27 15:50:08 -05:00
|
|
|
window_features.noopener = true;
|