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
|
|
|
|
2018-09-13 22:02:16 -07:00
|
|
|
diff --git a/content/browser/frame_host/render_frame_host_impl.cc b/content/browser/frame_host/render_frame_host_impl.cc
|
2020-05-26 13:06:26 -07:00
|
|
|
index fd47808a5a1e51dcca00ac7daff7107e3dfa17e4..f30eeb4f36c86431df1c965273eb188490db4ac0 100644
|
2018-09-13 22:02:16 -07:00
|
|
|
--- a/content/browser/frame_host/render_frame_host_impl.cc
|
|
|
|
|
+++ b/content/browser/frame_host/render_frame_host_impl.cc
|
2020-05-26 13:06:26 -07:00
|
|
|
@@ -4654,6 +4654,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-05-26 13:06:26 -07:00
|
|
|
index a9c62d7efd00fea602cced369f64fb81c068b8cc..c017455770707877008e2df07e65c391068bdb8c 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-05-26 13:06:26 -07:00
|
|
|
@@ -2955,9 +2955,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-03-26 19:05:45 +01:00
|
|
|
for (auto& observer : observers_) {
|
2018-09-13 22:02:16 -07:00
|
|
|
diff --git a/content/common/frame.mojom b/content/common/frame.mojom
|
2020-05-26 13:06:26 -07:00
|
|
|
index b6113c360f9e033440c3043a128531704778fe9c..9732b9ad4562b503041e19f2763d697e6c191e1c 100644
|
2018-09-13 22:02:16 -07:00
|
|
|
--- a/content/common/frame.mojom
|
|
|
|
|
+++ b/content/common/frame.mojom
|
2020-05-26 13:06:26 -07:00
|
|
|
@@ -302,6 +302,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-05-26 13:06:26 -07:00
|
|
|
index ba197ce381396608ab8603d27752b1bfe30e8e84..3c743a74321d54e36248d7b6201d9fdf5b749af6 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-05-26 13:06:26 -07:00
|
|
|
@@ -524,6 +524,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-05-26 13:06:26 -07:00
|
|
|
index d6c203ab546dde5106383c4d357d52c88965c467..491d6e7260dd329f312916c2f4aaba0aa177cc6a 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-05-26 13:06:26 -07:00
|
|
|
@@ -146,6 +146,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
|
|
|
|
2019-10-28 18:12:35 -04:00
|
|
|
namespace rappor {
|
2020-05-26 13:06:26 -07:00
|
|
|
@@ -845,6 +846,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-05-26 13:06:26 -07:00
|
|
|
index 6017278cc0fa8d029477e7ef46a9c0cacae438be..18161c8f836134e470333381a16425e3347ea867 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-05-26 13:06:26 -07:00
|
|
|
index 7757c7720406aa9915a2a413b939be968c3cd988..7b329848850638941a7d8564dfe3786ae6f489ff 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
|
|
|
|
|
@@ -16,6 +16,7 @@
|
|
|
|
|
#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"
|
|
|
|
|
@@ -331,6 +332,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-05-26 13:06:26 -07:00
|
|
|
index 20ec8fc88cba99266ca9cf5f22f2565a762a97b3..00333d9aa46d643bf65db07cfac7a3a8959a14a3 100644
|
2018-09-13 22:02:16 -07:00
|
|
|
--- a/content/renderer/render_view_impl.cc
|
|
|
|
|
+++ b/content/renderer/render_view_impl.cc
|
2020-03-03 13:35:05 -08:00
|
|
|
@@ -68,6 +68,7 @@
|
2018-09-14 11:03:43 -07:00
|
|
|
#include "content/renderer/ime_event_guard.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-05-26 13:06:26 -07:00
|
|
|
@@ -1250,6 +1251,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 =
|
2019-01-16 23:37:52 +05:30
|
|
|
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-05-26 13:06:26 -07:00
|
|
|
index f963cc714c49c90b66195e84b4fdda9b1f38ad28..c6e10685403a1f6dd3f326b001d9ee5e2e351e67 100644
|
2019-01-16 23:37:52 +05:30
|
|
|
--- 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-05-26 13:06:26 -07:00
|
|
|
@@ -401,6 +401,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) {
|
2019-01-16 23:37:52 +05:30
|
|
|
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-05-26 13:06:26 -07:00
|
|
|
index 45b6bbbd41bbe19a39edb83b6ced844cb4c97244..90b5c696f4cc6b77d1377a628c9d8166c773bb60 100644
|
2019-01-16 23:37:52 +05:30
|
|
|
--- 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-05-26 13:06:26 -07:00
|
|
|
@@ -79,6 +79,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-05-26 13:06:26 -07:00
|
|
|
index 1d5c3315671f0c414572ee0610fe6ac399b6e1e8..ee2c97cd344ea5f6e3aadd34304d290dbf5d2587 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-05-26 13:06:26 -07:00
|
|
|
@@ -1874,6 +1874,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-03-26 19:05:45 +01:00
|
|
|
FrameLoadRequest frame_request(active_document,
|
|
|
|
|
ResourceRequest(completed_url));
|