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
|
2023-04-12 11:37:48 +00:00
|
|
|
index 43c31d210e70f28d5da8b05d0348bc8bf762ecf9..8becad9c30cfb15fda735ced3dbbe7ab81949b91 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
|
2023-04-12 11:37:48 +00:00
|
|
|
@@ -7702,6 +7702,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
|
2023-04-12 11:37:48 +00:00
|
|
|
index d645d91310408a2f04e0ee92cae9e9b387cdf845..aa75360ee5fc3dc6b4a0c5fcf864c9488635f563 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
|
2023-04-12 11:37:48 +00:00
|
|
|
@@ -4160,6 +4160,12 @@ FrameTree* WebContentsImpl::CreateNewWindow(
|
2022-12-05 22:59:19 +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
|
|
|
+ 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
|
|
|
+ }
|
|
|
|
+
|
2022-12-05 22:59:19 +00: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
|
2023-04-12 11:37:48 +00:00
|
|
|
@@ -4201,12 +4207,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
|
2023-04-12 11:37:48 +00:00
|
|
|
index 12f4a2066a2a31e9852216c0cb3344095c7b0e39..588ca46227c58f9596317d6d4d05d0b3c76cbc06 100644
|
2018-09-14 05:02:16 +00:00
|
|
|
--- a/content/common/frame.mojom
|
|
|
|
+++ b/content/common/frame.mojom
|
2023-04-12 11:37:48 +00:00
|
|
|
@@ -593,6 +593,10 @@ struct CreateNewWindowParams {
|
2023-01-06 02:35:34 +00:00
|
|
|
// The navigation initiator's user activation and ad status.
|
|
|
|
blink.mojom.NavigationInitiatorActivationAndAdStatus
|
|
|
|
initiator_activation_and_ad_status;
|
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
|
2023-04-12 11:37:48 +00:00
|
|
|
index b789b7b1bbe4ef23df29da44883f69195dc784fd..772bd32d27f1c54410f2f0ce2784616b4dc49ef9 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
|
2023-04-12 11:37:48 +00:00
|
|
|
@@ -640,6 +640,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
|
2023-04-12 11:37:48 +00:00
|
|
|
index 57ffe3e1603c24abcb8df1ec2a8192160afb07e3..0a65089a09c7d7d157d1facdfa4efd289e77edbb 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
|
2023-04-12 11:37:48 +00:00
|
|
|
@@ -165,6 +165,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 {
|
2023-04-12 11:37:48 +00:00
|
|
|
@@ -1038,6 +1039,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
|
2023-03-10 16:07:42 +00:00
|
|
|
index 885899b151520e0173a5ca68c2613b1333cadddf..5b53ee691c0a07ed1655139ca2d90341b5fa55a3 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
|
2023-03-10 16:07:42 +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
|
2023-03-10 16:07:42 +00:00
|
|
|
index 5da6f93293bc5ddae88c17ac2dd8d7037ba8e8f3..76d699790fb7d92587293b14332f696dc5460322 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"
|
2023-03-10 16:07:42 +00:00
|
|
|
#include "content/public/browser/fullscreen_types.h"
|
2020-11-14 00:16:56 +00:00
|
|
|
#include "content/public/browser/invalidate_type.h"
|
2023-03-10 16:07:42 +00:00
|
|
|
@@ -343,6 +344,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,
|
2022-09-07 07:46:37 +00:00
|
|
|
diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc
|
2023-04-12 11:37:48 +00:00
|
|
|
index 0a0aa8f85c5c818fffc310f4d05a6886f7d6272b..f45f542fa3131036624686cd33a90097e6400ff5 100644
|
2022-09-07 07:46:37 +00:00
|
|
|
--- a/content/renderer/render_frame_impl.cc
|
|
|
|
+++ b/content/renderer/render_frame_impl.cc
|
2023-04-12 11:37:48 +00:00
|
|
|
@@ -6318,6 +6318,10 @@ WebView* RenderFrameImpl::CreateNewWindow(
|
2023-01-06 02:35:34 +00:00
|
|
|
blink::GetNavigationInitiatorActivationAndAdStatus(
|
|
|
|
request.HasUserGesture(), GetWebFrame()->IsAdScriptInStack());
|
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
|
2023-03-10 16:07:42 +00:00
|
|
|
index 48a07780e61463b7e70e2a511bc6f81bd6fbdbf3..465cfb29380df203de7bcf2d27617b604097118a 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
|
2023-03-10 16:07:42 +00:00
|
|
|
@@ -499,6 +499,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
|
2023-03-10 16:07:42 +00:00
|
|
|
index 22254206063abe36739e1c0e7c065223ab6807d2..7f5d89f8dc8b46ac1338e73b0394872569d803b8 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-12-05 22:59:19 +00:00
|
|
|
@@ -84,6 +84,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
|
2023-03-31 02:03:58 +00:00
|
|
|
index 19e505a2d434dfd219b12304238e3b654eb8395f..314d1e63c55fae58e9f7ad0ce10045d3133f4882 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
|
|
|
|
2023-03-31 02:03:58 +00:00
|
|
|
@@ -68,6 +69,8 @@ struct WebWindowFeatures {
|
2021-05-05 23:26:17 +00:00
|
|
|
// 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
|
2023-04-04 13:42:56 +00:00
|
|
|
index 6e4235ff40d88880e5928cbca2a593264d6da527..814781746df6fd0b2cedc2f3aa77759aa1c7a868 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
|
2023-04-03 16:56:57 +00:00
|
|
|
@@ -2212,6 +2212,8 @@ DOMWindow* LocalDOMWindow::open(v8::Isolate* isolate,
|
2021-05-05 23:26:17 +00:00
|
|
|
WebWindowFeatures window_features =
|
2022-09-07 07:46:37 +00:00
|
|
|
GetWindowFeaturesFromString(features, entered_window, completed_url);
|
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;
|