0b85fdf26c
Co-authored-by: Jeremy Rose <jeremya@chromium.org>
234 lines
11 KiB
Diff
234 lines
11 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Cheng Zhao <zcbenz@gmail.com>
|
|
Date: Thu, 20 Sep 2018 17:45:32 -0700
|
|
Subject: can_create_window.patch
|
|
|
|
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.
|
|
|
|
diff --git a/content/browser/renderer_host/render_frame_host_impl.cc b/content/browser/renderer_host/render_frame_host_impl.cc
|
|
index 365d0d8cf45c664160048a7a9606907cb5414292..dd52048e922904826c5b31d13f17dfc954dff6d3 100644
|
|
--- a/content/browser/renderer_host/render_frame_host_impl.cc
|
|
+++ b/content/browser/renderer_host/render_frame_host_impl.cc
|
|
@@ -5030,6 +5030,7 @@ void RenderFrameHostImpl::CreateNewWindow(
|
|
last_committed_origin_, params->window_container_type,
|
|
params->target_url, params->referrer.To<Referrer>(),
|
|
params->frame_name, params->disposition, *params->features,
|
|
+ params->raw_features, params->body,
|
|
effective_transient_activation_state, params->opener_suppressed,
|
|
&no_javascript_access);
|
|
|
|
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
|
|
index 962cd0fb5a428530cd9e2f8e689f2d09bc95ce1b..ea458219bd182bd9ff21b203c282e7d0738049dd 100644
|
|
--- a/content/browser/web_contents/web_contents_impl.cc
|
|
+++ b/content/browser/web_contents/web_contents_impl.cc
|
|
@@ -3582,6 +3582,14 @@ RenderFrameHostDelegate* WebContentsImpl::CreateNewWindow(
|
|
}
|
|
auto* new_contents_impl = new_contents.get();
|
|
|
|
+ // Call this earlier than Chrome to associate the web preferences with the
|
|
+ // WebContents before the view gets created.
|
|
+ if (delegate_) {
|
|
+ delegate_->WebContentsCreatedWithFullParams(this, render_process_id,
|
|
+ opener->GetRoutingID(),
|
|
+ params, new_contents_impl);
|
|
+ }
|
|
+
|
|
new_contents_impl->GetController().SetSessionStorageNamespace(
|
|
partition_id, session_storage_namespace);
|
|
|
|
@@ -3623,12 +3631,6 @@ RenderFrameHostDelegate* WebContentsImpl::CreateNewWindow(
|
|
AddDestructionObserver(new_contents_impl);
|
|
}
|
|
|
|
- if (delegate_) {
|
|
- delegate_->WebContentsCreated(this, render_process_id,
|
|
- opener->GetRoutingID(), params.frame_name,
|
|
- params.target_url, new_contents_impl);
|
|
- }
|
|
-
|
|
observers_.ForEachObserver([&](WebContentsObserver* observer) {
|
|
observer->DidOpenRequestedURL(new_contents_impl, opener, params.target_url,
|
|
params.referrer.To<Referrer>(),
|
|
diff --git a/content/common/frame.mojom b/content/common/frame.mojom
|
|
index 703c4611691b72380423576eebdadcd23e6ae913..2be0f93b7ea3791bb776158795a44aa7422e19ac 100644
|
|
--- a/content/common/frame.mojom
|
|
+++ b/content/common/frame.mojom
|
|
@@ -289,6 +289,10 @@ struct CreateNewWindowParams {
|
|
|
|
// The window features to use for the new window.
|
|
blink.mojom.WindowFeatures features;
|
|
+
|
|
+ // Extra fields added by Electron.
|
|
+ string raw_features;
|
|
+ network.mojom.URLRequestBody? body;
|
|
};
|
|
|
|
// 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
|
|
index df7dd27659ab16f81b5960610eb883e5dd1df7f4..c180b0ab0081631acfc675dacd2df92d8838ef02 100644
|
|
--- a/content/public/browser/content_browser_client.cc
|
|
+++ b/content/public/browser/content_browser_client.cc
|
|
@@ -543,6 +543,8 @@ bool ContentBrowserClient::CanCreateWindow(
|
|
const std::string& frame_name,
|
|
WindowOpenDisposition disposition,
|
|
const blink::mojom::WindowFeatures& features,
|
|
+ const std::string& raw_features,
|
|
+ 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
|
|
index 0f1befe8b66a32e079f087bdbb3cd072162faa1a..dfee3e388a9097c511d47cf09756dc37c5b63cda 100644
|
|
--- a/content/public/browser/content_browser_client.h
|
|
+++ b/content/public/browser/content_browser_client.h
|
|
@@ -153,6 +153,7 @@ class NetworkService;
|
|
class TrustedURLLoaderHeaderClient;
|
|
} // namespace mojom
|
|
struct ResourceRequest;
|
|
+class ResourceRequestBody;
|
|
} // namespace network
|
|
|
|
namespace sandbox {
|
|
@@ -864,6 +865,8 @@ class CONTENT_EXPORT ContentBrowserClient {
|
|
const std::string& frame_name,
|
|
WindowOpenDisposition disposition,
|
|
const blink::mojom::WindowFeatures& features,
|
|
+ const std::string& raw_features,
|
|
+ const scoped_refptr<network::ResourceRequestBody>& body,
|
|
bool user_gesture,
|
|
bool opener_suppressed,
|
|
bool* no_javascript_access);
|
|
diff --git a/content/public/browser/web_contents_delegate.cc b/content/public/browser/web_contents_delegate.cc
|
|
index 331be91414da82a8311b55c7568a4c6f5c5a6977..b0513d20bd48fe8ffe8398b5387e13545749c508 100644
|
|
--- a/content/public/browser/web_contents_delegate.cc
|
|
+++ b/content/public/browser/web_contents_delegate.cc
|
|
@@ -26,6 +26,17 @@ namespace content {
|
|
|
|
WebContentsDelegate::WebContentsDelegate() = default;
|
|
|
|
+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
|
|
index 5f8ccea8e3a48057bdb0180ae5a9b499be4e710a..94f576a6d52731f92c65adb958be5ca0a3391d4c 100644
|
|
--- a/content/public/browser/web_contents_delegate.h
|
|
+++ b/content/public/browser/web_contents_delegate.h
|
|
@@ -17,6 +17,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"
|
|
#include "content/public/browser/eye_dropper.h"
|
|
@@ -338,6 +339,13 @@ class CONTENT_EXPORT WebContentsDelegate {
|
|
const std::string& partition_id,
|
|
SessionStorageNamespace* session_storage_namespace);
|
|
|
|
+ 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,
|
|
diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc
|
|
index 253d22d0f171fc4897e8ae3c01c053ea24ce1d26..3569e6f3940d71c09720ada159f54e524e247f43 100644
|
|
--- a/content/renderer/render_view_impl.cc
|
|
+++ b/content/renderer/render_view_impl.cc
|
|
@@ -27,6 +27,7 @@
|
|
#include "content/renderer/render_thread_impl.h"
|
|
#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"
|
|
@@ -406,6 +407,10 @@ WebView* RenderViewImpl::CreateView(
|
|
}
|
|
params->features = ConvertWebWindowFeaturesToMojoWindowFeatures(features);
|
|
|
|
+ params->raw_features = features.raw_features.Utf8(
|
|
+ WTF::UTF8ConversionMode::kStrictUTF8ConversionReplacingUnpairedSurrogatesWithFFFD);
|
|
+ params->body = GetRequestBodyForWebURLRequest(request);
|
|
+
|
|
// We preserve this information before sending the message since |params| is
|
|
// moved on send.
|
|
bool is_background_tab =
|
|
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 6f5ae5bf1938133933f8055824e554a57470bbb9..7391fac052218c660cb122181e16ef84dc1a2e74 100644
|
|
--- a/content/web_test/browser/web_test_content_browser_client.cc
|
|
+++ b/content/web_test/browser/web_test_content_browser_client.cc
|
|
@@ -378,6 +378,8 @@ bool WebTestContentBrowserClient::CanCreateWindow(
|
|
const std::string& frame_name,
|
|
WindowOpenDisposition disposition,
|
|
const blink::mojom::WindowFeatures& features,
|
|
+ const std::string& raw_features,
|
|
+ const scoped_refptr<network::ResourceRequestBody>& body,
|
|
bool user_gesture,
|
|
bool opener_suppressed,
|
|
bool* no_javascript_access) {
|
|
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 15262ff3e3a7be037d5eedda3279c8897628e4d8..4e285a97787d9f487b5424b2dfc2b0fff2df53a2 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 {
|
|
const std::string& frame_name,
|
|
WindowOpenDisposition disposition,
|
|
const blink::mojom::WindowFeatures& features,
|
|
+ const std::string& raw_features,
|
|
+ const scoped_refptr<network::ResourceRequestBody>& body,
|
|
bool user_gesture,
|
|
bool opener_suppressed,
|
|
bool* no_javascript_access) override;
|
|
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_
|
|
|
|
+#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
|
|
+
|
|
namespace blink {
|
|
|
|
struct WebWindowFeatures {
|
|
@@ -60,6 +62,8 @@ struct WebWindowFeatures {
|
|
bool noreferrer = false;
|
|
bool background = false;
|
|
bool persistent = false;
|
|
+
|
|
+ String raw_features;
|
|
};
|
|
|
|
} // 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
|
|
index 2940caafb9f4d5ab3fc493dc15652e232468e3f4..4741ecfb249ccb7e88d3d8c4cf18b878f9b2b58d 100644
|
|
--- a/third_party/blink/renderer/core/frame/local_dom_window.cc
|
|
+++ b/third_party/blink/renderer/core/frame/local_dom_window.cc
|
|
@@ -1961,6 +1961,7 @@ DOMWindow* LocalDOMWindow::open(v8::Isolate* isolate,
|
|
}
|
|
|
|
WebWindowFeatures window_features = GetWindowFeaturesFromString(features);
|
|
+ window_features.raw_features = features;
|
|
|
|
FrameLoadRequest frame_request(incumbent_window,
|
|
ResourceRequest(completed_url));
|