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-08-11 21:04:56 +00:00
|
|
|
index c58f10aadf159d30531b6d3ad53cc735ca3868d0..8b7cc22096230163a1c1212c37b65b24add07474 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-08-11 21:04:56 +00:00
|
|
|
@@ -6266,6 +6266,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-08-11 21:04:56 +00:00
|
|
|
index a55a44e2a72f3245211fe6afe8fb827c06da8a2e..fb42b663cf63c38de27c7da98630951be77c3ee1 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-08-11 21:04:56 +00:00
|
|
|
@@ -3735,6 +3735,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-08-11 21:04:56 +00:00
|
|
|
@@ -3777,12 +3785,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-07-26 16:02:16 +00:00
|
|
|
index 192a5084eac3e9426ac8ddc4984b572d55c7a88a..63f53ff39240ea59a03f1a6f9d032444b0e4214d 100644
|
2018-09-14 05:02:16 +00:00
|
|
|
--- a/content/common/frame.mojom
|
|
|
|
+++ b/content/common/frame.mojom
|
2021-07-26 16:02:16 +00:00
|
|
|
@@ -523,6 +523,10 @@ struct CreateNewWindowParams {
|
2021-01-12 23:31:23 +00:00
|
|
|
// The impression associated with the navigation in the new window, if
|
|
|
|
// one is specified.
|
2021-07-06 12:17:13 +00:00
|
|
|
blink.mojom.Impression? impression;
|
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-07-26 16:02:16 +00:00
|
|
|
index b5022114e4e196f8fc038b4a2079356596696bc0..9a16e8a4d35552712f154dc03df0564d169c377c 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-07-26 16:02:16 +00:00
|
|
|
@@ -563,6 +563,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-07-26 16:02:16 +00:00
|
|
|
index aae2616d650761fbb1482f63fff6794ceea69cb7..7628a3f9ecc95dd2eb6580fbf1a7c6fe57bb5a1c 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-07-26 16:02:16 +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 {
|
2021-07-26 16:02:16 +00:00
|
|
|
@@ -927,6 +928,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-07-26 16:02:16 +00:00
|
|
|
index a5b63a551ee8efba5f9ff666e8c27dc59558d703..ba12175d4458a7134eeb2080b3762b386fa05511 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-07-26 16:02:16 +00:00
|
|
|
index 78d340f66b5573fd9039956c9aa9f54a206055cd..a5c1cd18896881066cc4a8954092ab859e4768c1 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-06-29 20:02:27 +00:00
|
|
|
@@ -338,6 +339,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-08-11 21:04:56 +00:00
|
|
|
index afec7767d905488a51b2dbba031b8a85d6d0138a..57f970d15bf03f817680982fa8605c333485804b 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
|
|
|
+
|
2018-09-14 05:02:16 +00:00
|
|
|
// We preserve this information before sending the message since |params| is
|
|
|
|
// moved on send.
|
2021-02-09 20:16:21 +00:00
|
|
|
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
|
2021-07-26 16:02:16 +00:00
|
|
|
index c6872573086e628a894f482877db2d417552c6a1..5e67b6a59c3e3d6881f738985ab947a2d7902f0a 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-07-26 16:02:16 +00:00
|
|
|
@@ -450,6 +450,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-07-26 16:02:16 +00:00
|
|
|
index 427656a1a01a9305459a8f1d6616fd0666413b39..c8e296286cdd148348932d2bdfa4d064f8cbe36d 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
|
|
|
|
@@ -83,6 +83,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-07-26 16:02:16 +00:00
|
|
|
index 071399cc4e72a01e9973fe1dbab63e388ee3e09d..d97f53b51113222ed15d607a0796cf19e785eb45 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-07-26 16:02:16 +00:00
|
|
|
@@ -1999,6 +1999,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));
|