electron/patches/chromium/revert_remove_contentrendererclient_shouldfork.patch

122 lines
6 KiB
Diff
Raw Normal View History

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Shelley Vohr <shelley.vohr@gmail.com>
Date: Tue, 4 Feb 2020 08:59:32 -0700
Subject: Revert "Remove ContentRendererClient::ShouldFork."
This reverts the CL at https://chromium-review.googlesource.com/c/chromium/src/+/1812128.
We use it to force a new renderer process for navigations, and need to start a new renderer process
for every navigation to keep Node.js working properly. Once Native Modules in the renderer process
are required to be NAPI or context aware (Electron v11), this patch can be removed.
diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc
index 7dbbe8742ca4f680ac99b5e286f7522e2b91dc14..82fb42b76f8a7dafab79018f1919e55cbe964569 100644
--- a/chrome/renderer/chrome_content_renderer_client.cc
+++ b/chrome/renderer/chrome_content_renderer_client.cc
@@ -1265,6 +1265,25 @@ ChromeContentRendererClient::GetProtocolHandlerSecurityLevel() {
#endif
}
+bool ChromeContentRendererClient::ShouldFork(WebLocalFrame* frame,
+ const GURL& url,
+ const std::string& http_method,
+ bool is_initial_navigation,
+ bool is_server_redirect) {
+ DCHECK(!frame->Parent());
+
+ // If |url| matches one of the prerendered URLs, stop this navigation and try
+ // to swap in the prerendered page on the browser process. If the prerendered
+ // page no longer exists by the time the OpenURL IPC is handled, a normal
+ // navigation is attempted.
+ if (prerender_dispatcher_.get() &&
+ prerender_dispatcher_->IsPrerenderURL(url)) {
+ return true;
+ }
+
+ return false;
+}
+
void ChromeContentRendererClient::WillSendRequest(
WebLocalFrame* frame,
ui::PageTransition transition_type,
diff --git a/chrome/renderer/chrome_content_renderer_client.h b/chrome/renderer/chrome_content_renderer_client.h
index b76ed96d41c174aaf225e35b72d03b9f870b3d70..429f5b3be9ae1bb92200ed44e26085f8db04169d 100644
--- a/chrome/renderer/chrome_content_renderer_client.h
+++ b/chrome/renderer/chrome_content_renderer_client.h
@@ -122,6 +122,11 @@ class ChromeContentRendererClient
base::SingleThreadTaskRunner* compositor_thread_task_runner) override;
bool RunIdleHandlerWhenWidgetsHidden() override;
bool AllowPopup() override;
+ bool ShouldFork(blink::WebLocalFrame* frame,
+ const GURL& url,
+ const std::string& http_method,
+ bool is_initial_navigation,
+ bool is_server_redirect) override;
blink::ProtocolHandlerSecurityLevel GetProtocolHandlerSecurityLevel()
override;
void WillSendRequest(blink::WebLocalFrame* frame,
diff --git a/content/public/renderer/content_renderer_client.cc b/content/public/renderer/content_renderer_client.cc
index 6a4f2e42f18e53e337e18333618803ebeaef2eb2..e475101a596d9b89a5fed27f81e8e46320beba0b 100644
--- a/content/public/renderer/content_renderer_client.cc
+++ b/content/public/renderer/content_renderer_client.cc
@@ -115,6 +115,14 @@ bool ContentRendererClient::HandleNavigation(
}
#endif
+bool ContentRendererClient::ShouldFork(blink::WebLocalFrame* frame,
+ const GURL& url,
+ const std::string& http_method,
+ bool is_initial_navigation,
+ bool is_server_redirect) {
+ return false;
+}
+
void ContentRendererClient::WillSendRequest(
blink::WebLocalFrame* frame,
ui::PageTransition transition_type,
diff --git a/content/public/renderer/content_renderer_client.h b/content/public/renderer/content_renderer_client.h
index c311fd6e4094c56698575c492042644fc5bccf28..1337b1acd88a6e7fbffb23a0ca1f03c53b3a9718 100644
--- a/content/public/renderer/content_renderer_client.h
+++ b/content/public/renderer/content_renderer_client.h
@@ -210,6 +210,13 @@ class CONTENT_EXPORT ContentRendererClient {
bool is_redirect);
#endif
+ // Returns true if we should fork a new process for the given navigation.
+ virtual bool ShouldFork(blink::WebLocalFrame* frame,
+ const GURL& url,
+ const std::string& http_method,
+ bool is_initial_navigation,
+ bool is_server_redirect);
+
// Notifies the embedder that the given frame is requesting the resource at
// |url|. If the function returns a valid |new_url|, the request must be
// updated to use it. The |force_ignore_site_for_cookies| output parameter
diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc
index d4210bec6eb6efb401b64dbd9d196891c7b4e551..1ffa87121d5f368dd1cad844406f8d16e8d9fc43 100644
--- a/content/renderer/render_frame_impl.cc
+++ b/content/renderer/render_frame_impl.cc
@@ -5567,6 +5567,23 @@ void RenderFrameImpl::BeginNavigation(
// we can do a per-frame check here rather than a process-wide check.
bool should_fork = HasWebUIScheme(url) || HasWebUIScheme(old_url) ||
(enabled_bindings_ & kWebUIBindingsPolicyMask);
+
+ if (!should_fork && url.SchemeIs(url::kFileScheme)) {
+ // Fork non-file to file opens (see https://crbug.com/1031119). Note that
+ // this may fork unnecessarily if another tab (hosting a file or not)
+ // targeted this one before its initial navigation, but that shouldn't
+ // cause a problem.
+ should_fork = !old_url.SchemeIs(url::kFileScheme);
+ }
+
+ if (!should_fork) {
+ // Give the embedder a chance.
+ bool is_initial_navigation = render_view_->history_list_length_ == 0;
+ should_fork = GetContentClient()->renderer()->ShouldFork(
+ frame_, url, info->url_request.HttpMethod().Utf8(),
+ is_initial_navigation, false /* is_redirect */);
+ }
+
if (should_fork) {
OpenURL(std::move(info));
return; // Suppress the load here.