2018-10-24 11:24:11 -07:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2018-09-20 17:30:26 -07:00
|
|
|
From: Cheng Zhao <zcbenz@gmail.com>
|
|
|
|
Date: Thu, 20 Sep 2018 17:45:32 -0700
|
|
|
|
Subject: can_create_window.patch
|
|
|
|
|
2019-12-13 09:18:45 -08: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-20 17:30:26 -07:00
|
|
|
|
2020-09-21 01:00:36 -07:00
|
|
|
diff --git a/content/browser/renderer_host/render_frame_host_impl.cc b/content/browser/renderer_host/render_frame_host_impl.cc
|
|
|
|
index c7f2d8e31eba60686016d2c2d7b565f6d8943df9..7ab29a65a8081cfcbd12e4bd77aa9133965497e0 100644
|
|
|
|
--- a/content/browser/renderer_host/render_frame_host_impl.cc
|
|
|
|
+++ b/content/browser/renderer_host/render_frame_host_impl.cc
|
|
|
|
@@ -4872,6 +4872,7 @@ void RenderFrameHostImpl::CreateNewWindow(
|
2019-01-16 23:37:52 +05:30
|
|
|
last_committed_origin_, params->window_container_type,
|
2019-01-08 15:59:47 -08:00
|
|
|
params->target_url, params->referrer.To<Referrer>(),
|
|
|
|
params->frame_name, params->disposition, *params->features,
|
2020-03-26 19:05:45 +01:00
|
|
|
+ params->raw_features, params->body,
|
2018-09-20 17:30:26 -07:00
|
|
|
effective_transient_activation_state, params->opener_suppressed,
|
|
|
|
&no_javascript_access);
|
2020-04-06 13:09:52 -07:00
|
|
|
|
2020-03-26 19:05:45 +01:00
|
|
|
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
|
2020-09-21 01:00:36 -07:00
|
|
|
index d13b9cd849c531fea59e8d7e46bd1b006b6f5659..93065a4d6e41498b0f358935cecf7ecedaf0d829 100644
|
2020-03-26 19:05:45 +01:00
|
|
|
--- a/content/browser/web_contents/web_contents_impl.cc
|
|
|
|
+++ b/content/browser/web_contents/web_contents_impl.cc
|
2020-09-21 01:00:36 -07:00
|
|
|
@@ -3695,9 +3695,9 @@ RenderFrameHostDelegate* WebContentsImpl::CreateNewWindow(
|
2020-03-26 19:05:45 +01:00
|
|
|
}
|
2020-04-06 13:09:52 -07:00
|
|
|
|
2020-03-26 19:05:45 +01: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 13:09:52 -07:00
|
|
|
|
2020-08-14 18:51:28 -07:00
|
|
|
observers_.ForEachObserver([&](WebContentsObserver* observer) {
|
2018-09-13 22:02:16 -07:00
|
|
|
diff --git a/content/common/frame.mojom b/content/common/frame.mojom
|
2020-08-12 11:33:58 -07:00
|
|
|
index c969ed9b17b915f713d9b82114c7b637c8fd90df..9530a1936b0a801a4c6152dd53ec5105d5d712e0 100644
|
2018-09-13 22:02:16 -07:00
|
|
|
--- a/content/common/frame.mojom
|
|
|
|
+++ b/content/common/frame.mojom
|
2020-08-12 11:33:58 -07:00
|
|
|
@@ -264,6 +264,10 @@ struct CreateNewWindowParams {
|
2020-04-06 13:09:52 -07:00
|
|
|
|
2018-09-13 22:02:16 -07:00
|
|
|
// The window features to use for the new window.
|
|
|
|
blink.mojom.WindowFeatures features;
|
|
|
|
+
|
|
|
|
+ // Extra fields added by Electron.
|
2020-03-26 19:05:45 +01:00
|
|
|
+ string raw_features;
|
2019-01-24 20:22:14 +05:30
|
|
|
+ network.mojom.URLRequestBody? body;
|
2018-09-13 22:02:16 -07:00
|
|
|
};
|
2020-04-06 13:09:52 -07:00
|
|
|
|
2018-09-13 22:02:16 -07: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-09-21 01:00:36 -07:00
|
|
|
index 2d2bfc7e50d9b3e117ffb1dcf433fb6a809923a1..ca22e2dbdfbd4b4c3bf60464cbdcd2104cbe5a7e 100644
|
2018-09-13 22:02:16 -07:00
|
|
|
--- a/content/public/browser/content_browser_client.cc
|
|
|
|
+++ b/content/public/browser/content_browser_client.cc
|
2020-09-21 01:00:36 -07:00
|
|
|
@@ -544,6 +544,8 @@ bool ContentBrowserClient::CanCreateWindow(
|
2018-09-13 22:02:16 -07:00
|
|
|
const std::string& frame_name,
|
|
|
|
WindowOpenDisposition disposition,
|
|
|
|
const blink::mojom::WindowFeatures& features,
|
2020-03-26 19:05:45 +01:00
|
|
|
+ const std::string& raw_features,
|
2018-09-13 22:02:16 -07: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-09-21 01:00:36 -07:00
|
|
|
index 718fc096bd1087ef89d599f572abe20d4173a41c..bd81fcd224d4cad545265be2dd1fa4a65b3248eb 100644
|
2018-09-13 22:02:16 -07:00
|
|
|
--- a/content/public/browser/content_browser_client.h
|
|
|
|
+++ b/content/public/browser/content_browser_client.h
|
2020-09-21 01:00:36 -07:00
|
|
|
@@ -153,6 +153,7 @@ class NetworkService;
|
2019-10-28 18:12:35 -04:00
|
|
|
class TrustedURLLoaderHeaderClient;
|
|
|
|
} // namespace mojom
|
|
|
|
struct ResourceRequest;
|
2018-09-13 22:02:16 -07:00
|
|
|
+class ResourceRequestBody;
|
2019-10-28 18:12:35 -04:00
|
|
|
} // namespace network
|
2020-04-06 13:09:52 -07:00
|
|
|
|
2020-06-22 10:35:10 -07:00
|
|
|
namespace sandbox {
|
2020-09-21 01:00:36 -07:00
|
|
|
@@ -872,6 +873,8 @@ class CONTENT_EXPORT ContentBrowserClient {
|
2018-09-13 22:02:16 -07:00
|
|
|
const std::string& frame_name,
|
|
|
|
WindowOpenDisposition disposition,
|
|
|
|
const blink::mojom::WindowFeatures& features,
|
2020-03-26 19:05:45 +01:00
|
|
|
+ const std::string& raw_features,
|
2018-09-13 22:02:16 -07:00
|
|
|
+ const scoped_refptr<network::ResourceRequestBody>& body,
|
|
|
|
bool user_gesture,
|
|
|
|
bool opener_suppressed,
|
|
|
|
bool* no_javascript_access);
|
2020-03-26 19:05:45 +01:00
|
|
|
diff --git a/content/public/browser/web_contents_delegate.cc b/content/public/browser/web_contents_delegate.cc
|
2020-09-21 01:00:36 -07:00
|
|
|
index 7ac50fbbe16b057d7263c7850a62b01d3dfae095..90d315d815bb269ee47cef7fb5e0b0e2edd578c4 100644
|
2020-03-26 19:05:45 +01: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 13:09:52 -07:00
|
|
|
|
2020-03-26 19:05:45 +01:00
|
|
|
WebContentsDelegate::WebContentsDelegate() = default;
|
2020-04-06 13:09:52 -07:00
|
|
|
|
2020-03-26 19:05:45 +01: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-09-21 01:00:36 -07:00
|
|
|
index a10c5caf5a4b7a30b7338c8b10ffa038e13dfd6a..938b6e622b52a05e6b7d626c4824e76121d807c5 100644
|
2020-03-26 19:05:45 +01:00
|
|
|
--- a/content/public/browser/web_contents_delegate.h
|
|
|
|
+++ b/content/public/browser/web_contents_delegate.h
|
2020-07-13 18:13:34 -07:00
|
|
|
@@ -17,6 +17,7 @@
|
2020-03-26 19:05:45 +01: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 13:06:26 -07:00
|
|
|
#include "content/public/browser/eye_dropper.h"
|
2020-07-13 18:13:34 -07:00
|
|
|
@@ -338,6 +339,13 @@ class CONTENT_EXPORT WebContentsDelegate {
|
2020-03-26 19:05:45 +01:00
|
|
|
const std::string& partition_id,
|
|
|
|
SessionStorageNamespace* session_storage_namespace);
|
2020-04-06 13:09:52 -07:00
|
|
|
|
2020-03-26 19:05:45 +01: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-13 22:02:16 -07:00
|
|
|
diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc
|
2020-09-21 01:00:36 -07:00
|
|
|
index fb0f9eb912782251ca610669e99285bc5df00fcc..425dde974830bf8a669d799da1e695734ebe46aa 100644
|
2018-09-13 22:02:16 -07:00
|
|
|
--- a/content/renderer/render_view_impl.cc
|
|
|
|
+++ b/content/renderer/render_view_impl.cc
|
2020-09-21 01:00:36 -07:00
|
|
|
@@ -65,6 +65,7 @@
|
2020-06-22 10:35:10 -07:00
|
|
|
#include "content/renderer/history_serialization.h"
|
2018-09-13 22:02:16 -07: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-20 17:30:26 -07:00
|
|
|
#include "content/renderer/media/audio/audio_device_factory.h"
|
2019-10-28 18:12:35 -04:00
|
|
|
#include "content/renderer/render_frame_impl.h"
|
2019-12-10 16:22:35 -08:00
|
|
|
#include "content/renderer/render_frame_proxy.h"
|
2020-09-21 01:00:36 -07:00
|
|
|
@@ -644,6 +645,10 @@ WebView* RenderViewImpl::CreateView(
|
2018-09-13 22:02:16 -07:00
|
|
|
}
|
|
|
|
params->features = ConvertWebWindowFeaturesToMojoWindowFeatures(features);
|
2020-04-06 13:09:52 -07:00
|
|
|
|
2020-03-26 19:05:45 +01:00
|
|
|
+ params->raw_features = features.raw_features.Utf8(
|
|
|
|
+ WTF::UTF8ConversionMode::kStrictUTF8ConversionReplacingUnpairedSurrogatesWithFFFD);
|
2019-01-24 20:22:14 +05:30
|
|
|
+ params->body = GetRequestBodyForWebURLRequest(request);
|
2018-09-13 22:02:16 -07:00
|
|
|
+
|
|
|
|
// We preserve this information before sending the message since |params| is
|
|
|
|
// moved on send.
|
|
|
|
bool is_background_tab =
|
2020-09-21 01:00:36 -07: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
|
|
|
|
index 53e938ec4b6515cabea5b7da8c5c9e7168f2d2ee..2e20931edeeca271f620128f5abd1ed4ddf75e1e 100644
|
|
|
|
--- a/content/web_test/browser/web_test_content_browser_client.cc
|
|
|
|
+++ b/content/web_test/browser/web_test_content_browser_client.cc
|
|
|
|
@@ -377,6 +377,8 @@ bool WebTestContentBrowserClient::CanCreateWindow(
|
2018-09-13 22:02:16 -07:00
|
|
|
const std::string& frame_name,
|
|
|
|
WindowOpenDisposition disposition,
|
|
|
|
const blink::mojom::WindowFeatures& features,
|
2020-03-26 19:05:45 +01:00
|
|
|
+ const std::string& raw_features,
|
2018-09-13 22:02:16 -07:00
|
|
|
+ const scoped_refptr<network::ResourceRequestBody>& body,
|
|
|
|
bool user_gesture,
|
|
|
|
bool opener_suppressed,
|
|
|
|
bool* no_javascript_access) {
|
2020-09-21 01:00:36 -07: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
|
|
|
|
index b96c23ec09111b29f9b9349a6324076d26f900bc..d42a00e59cde5195195096237f25eca5d4186797 100644
|
|
|
|
--- 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-13 22:02:16 -07:00
|
|
|
const std::string& frame_name,
|
|
|
|
WindowOpenDisposition disposition,
|
|
|
|
const blink::mojom::WindowFeatures& features,
|
2020-03-26 19:05:45 +01:00
|
|
|
+ const std::string& raw_features,
|
2018-09-13 22:02:16 -07:00
|
|
|
+ const scoped_refptr<network::ResourceRequestBody>& body,
|
|
|
|
bool user_gesture,
|
|
|
|
bool opener_suppressed,
|
|
|
|
bool* no_javascript_access) override;
|
2020-03-26 19:05:45 +01: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 13:09:52 -07:00
|
|
|
|
2020-03-26 19:05:45 +01:00
|
|
|
+#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
|
|
|
|
+
|
|
|
|
namespace blink {
|
2020-04-06 13:09:52 -07:00
|
|
|
|
2020-03-26 19:05:45 +01:00
|
|
|
struct WebWindowFeatures {
|
|
|
|
@@ -60,6 +62,8 @@ struct WebWindowFeatures {
|
|
|
|
bool noreferrer = false;
|
|
|
|
bool background = false;
|
|
|
|
bool persistent = false;
|
|
|
|
+
|
|
|
|
+ String raw_features;
|
|
|
|
};
|
2020-04-06 13:09:52 -07:00
|
|
|
|
2020-03-26 19:05:45 +01: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-09-21 01:00:36 -07:00
|
|
|
index b2c724001af583b1497afab4176ffb02feca05e5..d12a6b4db191ca4e757837e39b8a8d6c024c35f4 100644
|
2020-03-26 19:05:45 +01:00
|
|
|
--- a/third_party/blink/renderer/core/frame/local_dom_window.cc
|
|
|
|
+++ b/third_party/blink/renderer/core/frame/local_dom_window.cc
|
2020-09-21 01:00:36 -07:00
|
|
|
@@ -1949,6 +1949,7 @@ DOMWindow* LocalDOMWindow::open(v8::Isolate* isolate,
|
2020-03-26 19:05:45 +01:00
|
|
|
}
|
2020-04-06 13:09:52 -07:00
|
|
|
|
2020-03-26 19:05:45 +01:00
|
|
|
WebWindowFeatures window_features = GetWindowFeaturesFromString(features);
|
|
|
|
+ window_features.raw_features = features;
|
2020-04-06 13:09:52 -07:00
|
|
|
|
2020-07-13 18:13:34 -07:00
|
|
|
FrameLoadRequest frame_request(incumbent_window,
|
2020-03-26 19:05:45 +01:00
|
|
|
ResourceRequest(completed_url));
|