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
|
|
|
|
2018-09-14 05:02:16 +00:00
|
|
|
diff --git a/content/browser/frame_host/render_frame_host_impl.cc b/content/browser/frame_host/render_frame_host_impl.cc
|
2020-08-12 18:33:58 +00:00
|
|
|
index 16c568be438a6d1bf5ed413fedaee03a5b866a6d..910020e4ec7125eaae9e0f42319ced54dd768d91 100644
|
2018-09-14 05:02:16 +00:00
|
|
|
--- a/content/browser/frame_host/render_frame_host_impl.cc
|
|
|
|
+++ b/content/browser/frame_host/render_frame_host_impl.cc
|
2020-08-12 18:33:58 +00:00
|
|
|
@@ -4769,6 +4769,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
|
2020-08-12 18:33:58 +00:00
|
|
|
index b56ff2cbb595ac9c1b88cbd84d39dc9587faaaba..247f6fc26104c24a9d818e3606d76f17f6e4be6b 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
|
2020-08-12 18:33:58 +00:00
|
|
|
@@ -3369,9 +3369,9 @@ RenderFrameHostDelegate* WebContentsImpl::CreateNewWindow(
|
2020-03-26 18:05:45 +00:00
|
|
|
}
|
2020-04-06 20:09:52 +00:00
|
|
|
|
2020-03-26 18:05:45 +00:00
|
|
|
if (delegate_) {
|
|
|
|
- delegate_->WebContentsCreated(this, render_process_id,
|
|
|
|
- opener->GetRoutingID(), params.frame_name,
|
|
|
|
- params.target_url, new_contents_impl);
|
|
|
|
+ delegate_->WebContentsCreatedWithFullParams(this, render_process_id,
|
|
|
|
+ opener->GetRoutingID(),
|
|
|
|
+ params, new_contents_impl);
|
|
|
|
}
|
2020-04-06 20:09:52 +00:00
|
|
|
|
2020-03-26 18:05:45 +00:00
|
|
|
for (auto& observer : observers_) {
|
2018-09-14 05:02:16 +00:00
|
|
|
diff --git a/content/common/frame.mojom b/content/common/frame.mojom
|
2020-08-12 18:33:58 +00:00
|
|
|
index c969ed9b17b915f713d9b82114c7b637c8fd90df..9530a1936b0a801a4c6152dd53ec5105d5d712e0 100644
|
2018-09-14 05:02:16 +00:00
|
|
|
--- a/content/common/frame.mojom
|
|
|
|
+++ b/content/common/frame.mojom
|
2020-08-12 18:33:58 +00:00
|
|
|
@@ -264,6 +264,10 @@ struct CreateNewWindowParams {
|
2020-04-06 20:09:52 +00:00
|
|
|
|
2018-09-14 05:02:16 +00:00
|
|
|
// The window features to use for the new window.
|
|
|
|
blink.mojom.WindowFeatures features;
|
|
|
|
+
|
|
|
|
+ // 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
|
2020-08-12 18:33:58 +00:00
|
|
|
index 479e52d0c08050704f65fbf02779261446a107fe..0e150a89b451e7ae464f1bd5e38c412f58aa8568 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
|
2020-08-12 18:33:58 +00:00
|
|
|
@@ -543,6 +543,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
|
2020-08-12 18:33:58 +00:00
|
|
|
index 5f73f4713eae097b544ba38c4117621d3a1b77e4..170beaff3f579d3fcf9c461f6a41350e8c9439cc 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
|
2020-08-12 18:33:58 +00:00
|
|
|
@@ -149,6 +149,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 {
|
2020-08-12 18:33:58 +00:00
|
|
|
@@ -869,6 +870,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
|
2020-08-12 18:33:58 +00:00
|
|
|
index 5631ce92ac15737d4aff4d08e4a285bc507b6d47..04428e426ff43570deb01edf33400824f9a5206c 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
|
|
|
|
@@ -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
|
2020-08-12 18:33:58 +00:00
|
|
|
index 61ed37a5868fd53f669d40c62542d6271daea91d..c1d7b01d0d63f9f1ba90a32511f69318c9ec10fb 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
|
2020-07-14 01:13:34 +00:00
|
|
|
@@ -17,6 +17,7 @@
|
2020-03-26 18:05:45 +00:00
|
|
|
#include "base/strings/string16.h"
|
|
|
|
#include "build/build_config.h"
|
|
|
|
#include "content/common/content_export.h"
|
|
|
|
+#include "content/common/frame.mojom.h"
|
|
|
|
#include "content/public/browser/bluetooth_chooser.h"
|
|
|
|
#include "content/public/browser/bluetooth_scanning_prompt.h"
|
2020-05-26 20:06:26 +00:00
|
|
|
#include "content/public/browser/eye_dropper.h"
|
2020-07-14 01:13:34 +00:00
|
|
|
@@ -338,6 +339,13 @@ class CONTENT_EXPORT WebContentsDelegate {
|
2020-03-26 18:05:45 +00:00
|
|
|
const std::string& partition_id,
|
|
|
|
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
|
2020-08-12 18:33:58 +00:00
|
|
|
index b34393f42c6c2ba5b39d72d6a40219071bd61ff4..03fc999b46164b44a17537cc574afbeb712abfb0 100644
|
2018-09-14 05:02:16 +00:00
|
|
|
--- a/content/renderer/render_view_impl.cc
|
|
|
|
+++ b/content/renderer/render_view_impl.cc
|
2020-06-22 17:35:10 +00:00
|
|
|
@@ -67,6 +67,7 @@
|
|
|
|
#include "content/renderer/history_serialization.h"
|
2018-09-14 05:02:16 +00:00
|
|
|
#include "content/renderer/internal_document_state_data.h"
|
|
|
|
#include "content/renderer/loader/request_extra_data.h"
|
|
|
|
+#include "content/renderer/loader/web_url_request_util.h"
|
2018-09-21 00:30:26 +00:00
|
|
|
#include "content/renderer/media/audio/audio_device_factory.h"
|
2019-10-28 22:12:35 +00:00
|
|
|
#include "content/renderer/render_frame_impl.h"
|
2019-12-11 00:22:35 +00:00
|
|
|
#include "content/renderer/render_frame_proxy.h"
|
2020-08-12 18:33:58 +00:00
|
|
|
@@ -1215,6 +1216,10 @@ WebView* RenderViewImpl::CreateView(
|
2018-09-14 05:02:16 +00:00
|
|
|
}
|
|
|
|
params->features = ConvertWebWindowFeaturesToMojoWindowFeatures(features);
|
2020-04-06 20:09:52 +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);
|
2018-09-14 05:02:16 +00:00
|
|
|
+
|
|
|
|
// We preserve this information before sending the message since |params| is
|
|
|
|
// moved on send.
|
|
|
|
bool is_background_tab =
|
2019-01-16 18:07:52 +00:00
|
|
|
diff --git a/content/shell/browser/web_test/web_test_content_browser_client.cc b/content/shell/browser/web_test/web_test_content_browser_client.cc
|
2020-08-12 18:33:58 +00:00
|
|
|
index c22aeb8e80440061f33271762b373912ef30cc48..5418efe944e0e897adb754f790ba8182c20f87ec 100644
|
2019-01-16 18:07:52 +00:00
|
|
|
--- a/content/shell/browser/web_test/web_test_content_browser_client.cc
|
|
|
|
+++ b/content/shell/browser/web_test/web_test_content_browser_client.cc
|
2020-08-12 18:33:58 +00:00
|
|
|
@@ -381,6 +381,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) {
|
2019-01-16 18:07:52 +00:00
|
|
|
diff --git a/content/shell/browser/web_test/web_test_content_browser_client.h b/content/shell/browser/web_test/web_test_content_browser_client.h
|
2020-08-12 18:33:58 +00:00
|
|
|
index a79ff68cb0a9fa9f65b780c06df4b62696e34891..70c0073aac1e7b133b847d62ef4d87293ec5956c 100644
|
2019-01-16 18:07:52 +00:00
|
|
|
--- a/content/shell/browser/web_test/web_test_content_browser_client.h
|
|
|
|
+++ b/content/shell/browser/web_test/web_test_content_browser_client.h
|
2020-08-12 18:33:58 +00:00
|
|
|
@@ -77,6 +77,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
|
|
|
|
index 4f735ad0d97eaac9a57dad137e479f8a7ec33a36..0a3c5821962c85609b64b3625fa6b8d658cd9ab2 100644
|
|
|
|
--- a/third_party/blink/public/web/web_window_features.h
|
|
|
|
+++ b/third_party/blink/public/web/web_window_features.h
|
|
|
|
@@ -31,6 +31,8 @@
|
|
|
|
#ifndef THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_WINDOW_FEATURES_H_
|
|
|
|
#define THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_WINDOW_FEATURES_H_
|
2020-04-06 20:09:52 +00:00
|
|
|
|
2020-03-26 18:05:45 +00:00
|
|
|
+#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
|
|
|
|
+
|
|
|
|
namespace blink {
|
2020-04-06 20:09:52 +00:00
|
|
|
|
2020-03-26 18:05:45 +00:00
|
|
|
struct WebWindowFeatures {
|
|
|
|
@@ -60,6 +62,8 @@ struct WebWindowFeatures {
|
|
|
|
bool noreferrer = false;
|
|
|
|
bool background = false;
|
|
|
|
bool persistent = false;
|
|
|
|
+
|
|
|
|
+ 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
|
2020-08-12 18:33:58 +00:00
|
|
|
index f4259f5af3ab508d58b8d351da147e2d71250f07..2943be5715f2436e40049f82d954caedd1b76cc0 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
|
2020-08-12 18:33:58 +00:00
|
|
|
@@ -1915,6 +1915,7 @@ DOMWindow* LocalDOMWindow::open(v8::Isolate* isolate,
|
2020-03-26 18:05:45 +00:00
|
|
|
}
|
2020-04-06 20:09:52 +00:00
|
|
|
|
2020-03-26 18:05:45 +00:00
|
|
|
WebWindowFeatures window_features = GetWindowFeaturesFromString(features);
|
|
|
|
+ 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));
|