From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Shelley Vohr 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 ceb29f83a9dc17218830f401d472fef5835b67e5..be88b6ab2ac9d7fe2b0e7e3579a2c7ba763b5dee 100644 --- a/chrome/renderer/chrome_content_renderer_client.cc +++ b/chrome/renderer/chrome_content_renderer_client.cc @@ -1281,6 +1281,24 @@ ChromeContentRendererClient::GetProtocolHandlerSecurityLevel() { #endif } +bool ChromeContentRendererClient::ShouldFork(WebLocalFrame* frame, + const GURL& url, + const std::string& http_method, + 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 4fb3926576c80881a9230bb91bfe7655fec12df1..0f7f3773cf5efcf55cbf001885083f393529911b 100644 --- a/chrome/renderer/chrome_content_renderer_client.h +++ b/chrome/renderer/chrome_content_renderer_client.h @@ -121,6 +121,10 @@ 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_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 9745f3208baaf1654c8386c11067958c0e47fd28..f441e4b65835343d385c2377be70d71e7e9c9fca 100644 --- a/content/public/renderer/content_renderer_client.cc +++ b/content/public/renderer/content_renderer_client.cc @@ -117,6 +117,13 @@ bool ContentRendererClient::HandleNavigation( } #endif +bool ContentRendererClient::ShouldFork(blink::WebLocalFrame* frame, + const GURL& url, + const std::string& http_method, + 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 f259835ef4cabb8923f8b0fe9b3f6ae8f2b2b79f..a538b9ebcfa232b90fc7713e6569608a16c57ed3 100644 --- a/content/public/renderer/content_renderer_client.h +++ b/content/public/renderer/content_renderer_client.h @@ -207,6 +207,12 @@ 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_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. diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc index b04ffbc51f260e63c4217c060e87062eb301ead5..6256e5ad6d87612ef89cf86ea5661318a95335bd 100644 --- a/content/renderer/render_frame_impl.cc +++ b/content/renderer/render_frame_impl.cc @@ -5317,6 +5317,22 @@ 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. + should_fork = GetContentClient()->renderer()->ShouldFork( + frame_, url, info->url_request.HttpMethod().Utf8(), + false /* is_redirect */); + } + if (should_fork) { OpenURL(std::move(info)); return; // Suppress the load here.