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
|
2021-10-21 18:51:36 +00:00
|
|
|
index 6520b9b7e90aa7a5e007b592294c761ed416e8d8..1c7df171237f441ae13a8b8b0d681d496ee0cc8a 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
|
2021-10-21 18:51:36 +00:00
|
|
|
@@ -6497,6 +6497,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
|
2021-10-21 18:51:36 +00:00
|
|
|
index e7e2e3d3163bbd4ab865ae674f450465f9e84ec3..12ac864159be77519ce6f6dc69941fe1fbdd9c35 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
|
2021-10-21 18:51:36 +00:00
|
|
|
@@ -3749,6 +3749,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(
|
|
|
|
partition_id, session_storage_namespace);
|
|
|
|
|
2021-10-21 18:51:36 +00:00
|
|
|
@@ -3791,12 +3799,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
|
2021-10-21 18:51:36 +00:00
|
|
|
index 268a2395423ebcd1eded3d8ead5f7775cd5895be..c0cad20dc8273576dea2a9f3fe0c67be101a2193 100644
|
2018-09-14 05:02:16 +00:00
|
|
|
--- a/content/common/frame.mojom
|
|
|
|
+++ b/content/common/frame.mojom
|
2021-10-21 18:51:36 +00:00
|
|
|
@@ -550,6 +550,10 @@ struct CreateNewWindowParams {
|
2021-09-01 19:55:07 +00:00
|
|
|
|
|
|
|
// Governs how downloads are handled if `target_url` results in a download.
|
|
|
|
blink.mojom.NavigationDownloadPolicy download_policy;
|
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
|
2021-10-21 18:51:36 +00:00
|
|
|
index 248a90c7682001296d623eb80e925f03360a5510..bd15404a10db2f4641763da260a84bb76d3739ab 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
|
2021-10-21 18:51:36 +00:00
|
|
|
@@ -569,6 +569,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
|
2021-10-21 18:51:36 +00:00
|
|
|
index 7dfc30f346a9420be631c466ffa2d8b8adabf556..f0e2a061bb35fd3db26c7d235e1196273036925f 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
|
2021-10-21 18:51:36 +00:00
|
|
|
@@ -168,6 +168,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 {
|
2021-10-21 18:51:36 +00:00
|
|
|
@@ -936,6 +937,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
|
2021-08-24 00:52:17 +00:00
|
|
|
index 4a57554c9e540516af83567183a34384ac722ebf..31c73efb73bb69076abd6b9c4f139072a9f7f603 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
|
2021-06-05 02:03:31 +00:00
|
|
|
@@ -28,6 +28,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
|
2021-08-24 00:52:17 +00:00
|
|
|
index a0da74d5cbe4ab8be84d6f1a92f444e858320745..5936fa4bce09895595ccb294504f5b89c967d8c0 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"
|
2021-08-24 00:52:17 +00:00
|
|
|
@@ -335,6 +336,13 @@ class CONTENT_EXPORT WebContentsDelegate {
|
2021-03-15 18:32:18 +00:00
|
|
|
const StoragePartitionId& partition_id,
|
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
|
2021-09-01 19:55:07 +00:00
|
|
|
index ea22a86dc1a6e5cdb3e3dfa31a929a3dd14b9e61..215b059bb2dfcead6c709c99b39578f8e2216d93 100644
|
2018-09-14 05:02:16 +00:00
|
|
|
--- a/content/renderer/render_view_impl.cc
|
|
|
|
+++ b/content/renderer/render_view_impl.cc
|
2021-08-11 21:04:56 +00:00
|
|
|
@@ -31,6 +31,7 @@
|
2021-02-09 20:16:21 +00:00
|
|
|
#include "third_party/blink/public/platform/impression_conversions.h"
|
2020-10-28 00:33:04 +00:00
|
|
|
#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"
|
2021-08-11 21:04:56 +00:00
|
|
|
@@ -289,6 +290,10 @@ WebView* RenderViewImpl::CreateView(
|
2021-02-09 20:16:21 +00:00
|
|
|
params->impression = blink::ConvertWebImpressionToImpression(*impression);
|
2018-09-14 05:02:16 +00:00
|
|
|
}
|
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
|
|
|
+
|
2021-09-01 19:55:07 +00:00
|
|
|
params->download_policy.ApplyDownloadFramePolicy(
|
|
|
|
/*is_opener_navigation=*/false, request.HasUserGesture(),
|
|
|
|
// `openee_can_access_opener_origin` only matters for opener navigations,
|
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
|
2021-10-06 02:21:00 +00:00
|
|
|
index 520b6f8146361cf8c00079c1cc0f5394f747d405..77f58cc157229eb01ce9a35aa5814f64d6e8f2f2 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
|
2021-10-06 02:21:00 +00:00
|
|
|
@@ -438,6 +438,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
|
2021-10-06 02:21:00 +00:00
|
|
|
index 1580bd13ea123740dc7a8813680a8d2448d49969..5c0809733b366ecff02c5a4b77dac9530eb15fbf 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
|
2021-10-06 02:21:00 +00:00
|
|
|
@@ -80,6 +80,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
|
2021-05-19 23:15:47 +00:00
|
|
|
index 84d32491a56528a84b4395fba1d54cdbb38d522b..09998a83c449ef8cd9f360fbcdcf7edc0bbfa4a9 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
|
|
|
|
2021-05-05 23:26:17 +00:00
|
|
|
#include "third_party/blink/public/platform/web_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.
|
2021-05-19 23:15:47 +00:00
|
|
|
absl::optional<WebImpression> 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
|
2021-10-21 18:51:36 +00:00
|
|
|
index 1cab0b95a9f828791188ca6ad3adb416f864e008..f8ec60fae8eabda4019dd9f6903bfcbf00d423ce 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
|
2021-10-21 18:51:36 +00:00
|
|
|
@@ -2030,6 +2030,7 @@ DOMWindow* LocalDOMWindow::open(v8::Isolate* isolate,
|
2020-04-06 20:09:52 +00:00
|
|
|
|
2021-05-05 23:26:17 +00:00
|
|
|
WebWindowFeatures window_features =
|
|
|
|
GetWindowFeaturesFromString(features, incumbent_window);
|
2020-03-26 18:05:45 +00:00
|
|
|
+ window_features.raw_features = features;
|
2020-04-06 20:09:52 +00:00
|
|
|
|
2020-07-14 01:13:34 +00:00
|
|
|
FrameLoadRequest frame_request(incumbent_window,
|
2020-03-26 18:05:45 +00:00
|
|
|
ResourceRequest(completed_url));
|