2018-10-24 18:24:11 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2018-09-21 00:30:26 +00:00
|
|
|
From: Cheng Zhao <zcbenz@gmail.com>
|
|
|
|
Date: Thu, 20 Sep 2018 17:45:32 -0700
|
|
|
|
Subject: can_create_window.patch
|
|
|
|
|
2019-12-13 17:18:45 +00: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-21 00:30:26 +00:00
|
|
|
|
2020-09-21 08:00:36 +00:00
|
|
|
diff --git a/content/browser/renderer_host/render_frame_host_impl.cc b/content/browser/renderer_host/render_frame_host_impl.cc
|
2022-08-17 18:35:53 +00:00
|
|
|
index 9fe7a9c021c8d29359f072e04665a55858048be6..115dab63efa4b90f37609a9a0a363ad75a0ff582 100644
|
2020-09-21 08:00:36 +00:00
|
|
|
--- a/content/browser/renderer_host/render_frame_host_impl.cc
|
|
|
|
+++ b/content/browser/renderer_host/render_frame_host_impl.cc
|
2022-08-17 18:35:53 +00:00
|
|
|
@@ -7298,6 +7298,7 @@ void RenderFrameHostImpl::CreateNewWindow(
|
2019-01-16 18:07:52 +00:00
|
|
|
last_committed_origin_, params->window_container_type,
|
2019-01-08 23:59:47 +00:00
|
|
|
params->target_url, params->referrer.To<Referrer>(),
|
|
|
|
params->frame_name, params->disposition, *params->features,
|
2020-03-26 18:05:45 +00:00
|
|
|
+ params->raw_features, params->body,
|
2018-09-21 00:30:26 +00:00
|
|
|
effective_transient_activation_state, params->opener_suppressed,
|
|
|
|
&no_javascript_access);
|
2020-04-06 20:09:52 +00:00
|
|
|
|
2020-03-26 18:05:45 +00:00
|
|
|
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
|
2022-08-17 18:35:53 +00:00
|
|
|
index 276ae812cfb35f4fe6000a87b38c2155f37b12d3..9a0edcadef1bc60b035ca67df5082a7d06dd4436 100644
|
2020-03-26 18:05:45 +00:00
|
|
|
--- a/content/browser/web_contents/web_contents_impl.cc
|
|
|
|
+++ b/content/browser/web_contents/web_contents_impl.cc
|
2022-08-17 18:35:53 +00:00
|
|
|
@@ -3996,6 +3996,14 @@ FrameTree* WebContentsImpl::CreateNewWindow(
|
2020-03-26 18:05:45 +00:00
|
|
|
}
|
2020-11-10 17:06:03 +00:00
|
|
|
auto* new_contents_impl = new_contents.get();
|
2020-04-06 20:09:52 +00:00
|
|
|
|
2020-11-10 17:06:03 +00:00
|
|
|
+ // Call this earlier than Chrome to associate the web preferences with the
|
|
|
|
+ // WebContents before the view gets created.
|
|
|
|
+ if (delegate_) {
|
2020-03-26 18:05:45 +00:00
|
|
|
+ delegate_->WebContentsCreatedWithFullParams(this, render_process_id,
|
|
|
|
+ opener->GetRoutingID(),
|
|
|
|
+ params, new_contents_impl);
|
2020-11-10 17:06:03 +00:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
new_contents_impl->GetController().SetSessionStorageNamespace(
|
2022-02-25 18:17:35 +00:00
|
|
|
partition_config, session_storage_namespace);
|
2020-11-10 17:06:03 +00:00
|
|
|
|
2022-08-17 18:35:53 +00:00
|
|
|
@@ -4040,12 +4048,6 @@ FrameTree* WebContentsImpl::CreateNewWindow(
|
2021-03-04 17:27:05 +00:00
|
|
|
AddWebContentsDestructionObserver(new_contents_impl);
|
2020-03-26 18:05:45 +00:00
|
|
|
}
|
2020-04-06 20:09:52 +00:00
|
|
|
|
2020-11-10 17:06:03 +00:00
|
|
|
- if (delegate_) {
|
|
|
|
- delegate_->WebContentsCreated(this, render_process_id,
|
|
|
|
- opener->GetRoutingID(), params.frame_name,
|
|
|
|
- params.target_url, new_contents_impl);
|
|
|
|
- }
|
|
|
|
-
|
2021-02-09 20:16:21 +00:00
|
|
|
observers_.NotifyObservers(&WebContentsObserver::DidOpenRequestedURL,
|
|
|
|
new_contents_impl, opener, params.target_url,
|
|
|
|
params.referrer.To<Referrer>(), params.disposition,
|
2018-09-14 05:02:16 +00:00
|
|
|
diff --git a/content/common/frame.mojom b/content/common/frame.mojom
|
2022-08-17 18:35:53 +00:00
|
|
|
index fc7e18c294993f1fa8cef88782ae3f4ba60e4d54..c41545fc79a6a45c82aa39ff21e790bdcd7b8f01 100644
|
2018-09-14 05:02:16 +00:00
|
|
|
--- a/content/common/frame.mojom
|
|
|
|
+++ b/content/common/frame.mojom
|
2022-08-17 18:35:53 +00:00
|
|
|
@@ -571,6 +571,10 @@ struct CreateNewWindowParams {
|
2021-09-01 19:55:07 +00:00
|
|
|
|
2022-07-13 21:26:16 +00:00
|
|
|
// Additional parameters for creating picture-in-picture windows.
|
|
|
|
blink.mojom.PictureInPictureWindowOptions? pip_options;
|
2018-09-14 05:02:16 +00:00
|
|
|
+
|
|
|
|
+ // Extra fields added by Electron.
|
2020-03-26 18:05:45 +00:00
|
|
|
+ string raw_features;
|
2019-01-24 14:52:14 +00:00
|
|
|
+ network.mojom.URLRequestBody? body;
|
2018-09-14 05:02:16 +00:00
|
|
|
};
|
2020-04-06 20:09:52 +00:00
|
|
|
|
2018-09-14 05:02:16 +00: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-08-17 18:35:53 +00:00
|
|
|
index 82a07cfb29870615a18a1718e5b6c0b2a42443ef..ba6e21fb83b4c58716b776c1a018c36f14902e6f 100644
|
2018-09-14 05:02:16 +00:00
|
|
|
--- a/content/public/browser/content_browser_client.cc
|
|
|
|
+++ b/content/public/browser/content_browser_client.cc
|
2022-08-17 18:35:53 +00:00
|
|
|
@@ -610,6 +610,8 @@ bool ContentBrowserClient::CanCreateWindow(
|
2018-09-14 05:02:16 +00:00
|
|
|
const std::string& frame_name,
|
|
|
|
WindowOpenDisposition disposition,
|
|
|
|
const blink::mojom::WindowFeatures& features,
|
2020-03-26 18:05:45 +00:00
|
|
|
+ const std::string& raw_features,
|
2018-09-14 05:02:16 +00: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-08-17 18:35:53 +00:00
|
|
|
index 2f475430b85cf6029f0066f30069294847d05bd1..f399bc59be5705542b34185e7fe7202a029c40ea 100644
|
2018-09-14 05:02:16 +00:00
|
|
|
--- a/content/public/browser/content_browser_client.h
|
|
|
|
+++ b/content/public/browser/content_browser_client.h
|
2022-08-17 18:35:53 +00:00
|
|
|
@@ -164,6 +164,7 @@ class NetworkService;
|
2019-10-28 22:12:35 +00:00
|
|
|
class TrustedURLLoaderHeaderClient;
|
|
|
|
} // namespace mojom
|
|
|
|
struct ResourceRequest;
|
2018-09-14 05:02:16 +00:00
|
|
|
+class ResourceRequestBody;
|
2019-10-28 22:12:35 +00:00
|
|
|
} // namespace network
|
2020-04-06 20:09:52 +00:00
|
|
|
|
2020-06-22 17:35:10 +00:00
|
|
|
namespace sandbox {
|
2022-08-17 18:35:53 +00:00
|
|
|
@@ -991,6 +992,8 @@ class CONTENT_EXPORT ContentBrowserClient {
|
2018-09-14 05:02:16 +00:00
|
|
|
const std::string& frame_name,
|
|
|
|
WindowOpenDisposition disposition,
|
|
|
|
const blink::mojom::WindowFeatures& features,
|
2020-03-26 18:05:45 +00:00
|
|
|
+ const std::string& raw_features,
|
2018-09-14 05:02:16 +00:00
|
|
|
+ const scoped_refptr<network::ResourceRequestBody>& body,
|
|
|
|
bool user_gesture,
|
|
|
|
bool opener_suppressed,
|
|
|
|
bool* no_javascript_access);
|
2020-03-26 18:05:45 +00:00
|
|
|
diff --git a/content/public/browser/web_contents_delegate.cc b/content/public/browser/web_contents_delegate.cc
|
2022-08-17 18:35:53 +00:00
|
|
|
index 74847a4fbd4d0d897ce6aecd1b39e30bc226f8f4..3ddcc2d403a68fdc2b4b0246899cd9507ecc6195 100644
|
2020-03-26 18:05:45 +00:00
|
|
|
--- a/content/public/browser/web_contents_delegate.cc
|
|
|
|
+++ b/content/public/browser/web_contents_delegate.cc
|
2022-02-25 18:17:35 +00:00
|
|
|
@@ -26,6 +26,17 @@ namespace content {
|
2020-04-06 20:09:52 +00:00
|
|
|
|
2020-03-26 18:05:45 +00:00
|
|
|
WebContentsDelegate::WebContentsDelegate() = default;
|
2020-04-06 20:09:52 +00:00
|
|
|
|
2020-03-26 18:05:45 +00: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-08-17 18:35:53 +00:00
|
|
|
index 0274e3bb5cc62ce2c52be68a50b57c339fc5bba7..1ea3e1fdf067ea54ce54d31f494ac2bf42b2de3f 100644
|
2020-03-26 18:05:45 +00:00
|
|
|
--- a/content/public/browser/web_contents_delegate.h
|
|
|
|
+++ b/content/public/browser/web_contents_delegate.h
|
2021-03-16 14:01:00 +00:00
|
|
|
@@ -16,6 +16,7 @@
|
|
|
|
#include "base/memory/scoped_refptr.h"
|
2020-03-26 18:05:45 +00:00
|
|
|
#include "build/build_config.h"
|
|
|
|
#include "content/common/content_export.h"
|
|
|
|
+#include "content/common/frame.mojom.h"
|
2020-05-26 20:06:26 +00:00
|
|
|
#include "content/public/browser/eye_dropper.h"
|
2020-11-14 00:16:56 +00:00
|
|
|
#include "content/public/browser/invalidate_type.h"
|
|
|
|
#include "content/public/browser/media_stream_request.h"
|
2022-03-30 18:08:58 +00:00
|
|
|
@@ -338,6 +339,13 @@ class CONTENT_EXPORT WebContentsDelegate {
|
2022-02-25 18:17:35 +00:00
|
|
|
const StoragePartitionConfig& partition_config,
|
2020-03-26 18:05:45 +00:00
|
|
|
SessionStorageNamespace* session_storage_namespace);
|
2020-04-06 20:09:52 +00:00
|
|
|
|
2020-03-26 18:05:45 +00: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,
|
2018-09-14 05:02:16 +00:00
|
|
|
diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc
|
2022-08-17 18:35:53 +00:00
|
|
|
index f9a857f270bad274fc952655efd7a9a32fbd7fb1..80cad3267721dc7bf78f5b75f99cda2a0d1d2016 100644
|
2018-09-14 05:02:16 +00:00
|
|
|
--- a/content/renderer/render_view_impl.cc
|
|
|
|
+++ b/content/renderer/render_view_impl.cc
|
2022-08-17 18:35:53 +00:00
|
|
|
@@ -297,6 +297,10 @@ WebView* RenderViewImpl::CreateView(
|
2022-06-01 06:12:47 +00:00
|
|
|
/*openee_can_access_opener_origin=*/true, !creator->IsAllowedToDownload(),
|
2022-08-17 18:35:53 +00:00
|
|
|
creator->IsAdFrame());
|
2021-02-09 20:16:21 +00:00
|
|
|
|
2020-03-26 18:05:45 +00:00
|
|
|
+ params->raw_features = features.raw_features.Utf8(
|
|
|
|
+ WTF::UTF8ConversionMode::kStrictUTF8ConversionReplacingUnpairedSurrogatesWithFFFD);
|
2019-01-24 14:52:14 +00:00
|
|
|
+ params->body = GetRequestBodyForWebURLRequest(request);
|
2021-02-09 20:16:21 +00:00
|
|
|
+
|
2022-06-01 06:12:47 +00:00
|
|
|
// We preserve this information before sending the message since |params| is
|
|
|
|
// moved on send.
|
|
|
|
bool is_background_tab =
|
2020-09-21 08:00:36 +00: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-08-17 18:35:53 +00:00
|
|
|
index 6abdcf70bdeeb3a34d01c3b00e5f629373eef76b..537f71cbf3cc1112100a199a15b77a535efd8a4e 100644
|
2020-09-21 08:00:36 +00:00
|
|
|
--- a/content/web_test/browser/web_test_content_browser_client.cc
|
|
|
|
+++ b/content/web_test/browser/web_test_content_browser_client.cc
|
2022-07-13 21:26:16 +00:00
|
|
|
@@ -440,6 +440,8 @@ bool WebTestContentBrowserClient::CanCreateWindow(
|
2018-09-14 05:02:16 +00:00
|
|
|
const std::string& frame_name,
|
|
|
|
WindowOpenDisposition disposition,
|
|
|
|
const blink::mojom::WindowFeatures& features,
|
2020-03-26 18:05:45 +00:00
|
|
|
+ const std::string& raw_features,
|
2018-09-14 05:02:16 +00:00
|
|
|
+ const scoped_refptr<network::ResourceRequestBody>& body,
|
|
|
|
bool user_gesture,
|
|
|
|
bool opener_suppressed,
|
|
|
|
bool* no_javascript_access) {
|
2020-09-21 08:00:36 +00: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-07-13 21:26:16 +00:00
|
|
|
index 4805dd035772fcaea60a1a91eb9911d5c0ce93a9..3b752ea509149f04fd6d10f6977bd29791f6a5d6 100644
|
2020-09-21 08:00:36 +00: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 21:26:16 +00:00
|
|
|
@@ -81,6 +81,8 @@ class WebTestContentBrowserClient : public ShellContentBrowserClient {
|
2018-09-14 05:02:16 +00:00
|
|
|
const std::string& frame_name,
|
|
|
|
WindowOpenDisposition disposition,
|
|
|
|
const blink::mojom::WindowFeatures& features,
|
2020-03-26 18:05:45 +00:00
|
|
|
+ const std::string& raw_features,
|
2018-09-14 05:02:16 +00:00
|
|
|
+ const scoped_refptr<network::ResourceRequestBody>& body,
|
|
|
|
bool user_gesture,
|
|
|
|
bool opener_suppressed,
|
|
|
|
bool* no_javascript_access) override;
|
2020-03-26 18:05:45 +00: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 06:12:47 +00:00
|
|
|
index 34570168ccb123f5102dcf8fa6bbf98e7c373ec6..192701e56d258da41b3724292853885e4daf3420 100644
|
2020-03-26 18:05:45 +00:00
|
|
|
--- a/third_party/blink/public/web/web_window_features.h
|
|
|
|
+++ b/third_party/blink/public/web/web_window_features.h
|
2021-05-05 23:26:17 +00:00
|
|
|
@@ -34,6 +34,7 @@
|
2021-05-19 23:15:47 +00:00
|
|
|
#include "third_party/abseil-cpp/absl/types/optional.h"
|
2020-04-06 20:09:52 +00:00
|
|
|
|
2022-06-01 06:12:47 +00:00
|
|
|
#include "third_party/blink/public/common/navigation/impression.h"
|
2020-03-26 18:05:45 +00:00
|
|
|
+#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
|
2021-05-05 23:26:17 +00:00
|
|
|
|
2020-03-26 18:05:45 +00:00
|
|
|
namespace blink {
|
2020-04-06 20:09:52 +00:00
|
|
|
|
2021-05-05 23:26:17 +00:00
|
|
|
@@ -68,6 +69,8 @@ struct WebWindowFeatures {
|
|
|
|
// Represents the attribution source declared by Attribution Reporting related
|
|
|
|
// window features, if any.
|
2022-06-01 06:12:47 +00:00
|
|
|
absl::optional<Impression> impression;
|
2020-03-26 18:05:45 +00:00
|
|
|
+
|
|
|
|
+ String raw_features;
|
|
|
|
};
|
2020-04-06 20:09:52 +00:00
|
|
|
|
2020-03-26 18:05:45 +00: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-08-17 18:35:53 +00:00
|
|
|
index cc39235616f0249c8a979a870885aec2d0e04cc4..77e6bbe18556279a98b5453d4ba1c3eb5b850287 100644
|
2020-03-26 18:05:45 +00:00
|
|
|
--- a/third_party/blink/renderer/core/frame/local_dom_window.cc
|
|
|
|
+++ b/third_party/blink/renderer/core/frame/local_dom_window.cc
|
2022-08-17 18:35:53 +00:00
|
|
|
@@ -2090,6 +2090,8 @@ DOMWindow* LocalDOMWindow::open(v8::Isolate* isolate,
|
2021-05-05 23:26:17 +00:00
|
|
|
WebWindowFeatures window_features =
|
2022-06-27 20:50:08 +00:00
|
|
|
GetWindowFeaturesFromString(features, entered_window);
|
2020-04-06 20:09:52 +00:00
|
|
|
|
2022-06-27 20:50:08 +00:00
|
|
|
+ window_features.raw_features = features;
|
|
|
|
+
|
2022-04-12 11:19:14 +00:00
|
|
|
// In fenced frames, we should always use `noopener`.
|
|
|
|
if (GetFrame()->IsInFencedFrameTree()) {
|
2022-06-27 20:50:08 +00:00
|
|
|
window_features.noopener = true;
|