revert_remove_contentrendererclient_shouldfork.patch 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Shelley Vohr <[email protected]>
  3. Date: Tue, 4 Feb 2020 08:59:32 -0700
  4. Subject: Revert "Remove ContentRendererClient::ShouldFork."
  5. This reverts the CL at https://chromium-review.googlesource.com/c/chromium/src/+/1812128.
  6. We use it to force a new renderer process for navigations, and need to start a new renderer process
  7. for every navigation to keep Node.js working properly. Once Native Modules in the renderer process
  8. are required to be NAPI or context aware (Electron v11), this patch can be removed.
  9. diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc
  10. index ceb29f83a9dc17218830f401d472fef5835b67e5..be88b6ab2ac9d7fe2b0e7e3579a2c7ba763b5dee 100644
  11. --- a/chrome/renderer/chrome_content_renderer_client.cc
  12. +++ b/chrome/renderer/chrome_content_renderer_client.cc
  13. @@ -1281,6 +1281,24 @@ ChromeContentRendererClient::GetProtocolHandlerSecurityLevel() {
  14. #endif
  15. }
  16. +bool ChromeContentRendererClient::ShouldFork(WebLocalFrame* frame,
  17. + const GURL& url,
  18. + const std::string& http_method,
  19. + bool is_server_redirect) {
  20. + DCHECK(!frame->Parent());
  21. +
  22. + // If |url| matches one of the prerendered URLs, stop this navigation and try
  23. + // to swap in the prerendered page on the browser process. If the prerendered
  24. + // page no longer exists by the time the OpenURL IPC is handled, a normal
  25. + // navigation is attempted.
  26. + if (prerender_dispatcher_.get() &&
  27. + prerender_dispatcher_->IsPrerenderURL(url)) {
  28. + return true;
  29. + }
  30. +
  31. + return false;
  32. +}
  33. +
  34. void ChromeContentRendererClient::WillSendRequest(
  35. WebLocalFrame* frame,
  36. ui::PageTransition transition_type,
  37. diff --git a/chrome/renderer/chrome_content_renderer_client.h b/chrome/renderer/chrome_content_renderer_client.h
  38. index 4fb3926576c80881a9230bb91bfe7655fec12df1..0f7f3773cf5efcf55cbf001885083f393529911b 100644
  39. --- a/chrome/renderer/chrome_content_renderer_client.h
  40. +++ b/chrome/renderer/chrome_content_renderer_client.h
  41. @@ -121,6 +121,10 @@ class ChromeContentRendererClient
  42. base::SingleThreadTaskRunner* compositor_thread_task_runner) override;
  43. bool RunIdleHandlerWhenWidgetsHidden() override;
  44. bool AllowPopup() override;
  45. + bool ShouldFork(blink::WebLocalFrame* frame,
  46. + const GURL& url,
  47. + const std::string& http_method,
  48. + bool is_server_redirect) override;
  49. blink::ProtocolHandlerSecurityLevel GetProtocolHandlerSecurityLevel()
  50. override;
  51. void WillSendRequest(blink::WebLocalFrame* frame,
  52. diff --git a/content/public/renderer/content_renderer_client.cc b/content/public/renderer/content_renderer_client.cc
  53. index 9745f3208baaf1654c8386c11067958c0e47fd28..f441e4b65835343d385c2377be70d71e7e9c9fca 100644
  54. --- a/content/public/renderer/content_renderer_client.cc
  55. +++ b/content/public/renderer/content_renderer_client.cc
  56. @@ -117,6 +117,13 @@ bool ContentRendererClient::HandleNavigation(
  57. }
  58. #endif
  59. +bool ContentRendererClient::ShouldFork(blink::WebLocalFrame* frame,
  60. + const GURL& url,
  61. + const std::string& http_method,
  62. + bool is_server_redirect) {
  63. + return false;
  64. +}
  65. +
  66. void ContentRendererClient::WillSendRequest(
  67. blink::WebLocalFrame* frame,
  68. ui::PageTransition transition_type,
  69. diff --git a/content/public/renderer/content_renderer_client.h b/content/public/renderer/content_renderer_client.h
  70. index f259835ef4cabb8923f8b0fe9b3f6ae8f2b2b79f..a538b9ebcfa232b90fc7713e6569608a16c57ed3 100644
  71. --- a/content/public/renderer/content_renderer_client.h
  72. +++ b/content/public/renderer/content_renderer_client.h
  73. @@ -207,6 +207,12 @@ class CONTENT_EXPORT ContentRendererClient {
  74. bool is_redirect);
  75. #endif
  76. + // Returns true if we should fork a new process for the given navigation.
  77. + virtual bool ShouldFork(blink::WebLocalFrame* frame,
  78. + const GURL& url,
  79. + const std::string& http_method,
  80. + bool is_server_redirect);
  81. +
  82. // Notifies the embedder that the given frame is requesting the resource at
  83. // |url|. If the function returns a valid |new_url|, the request must be
  84. // updated to use it.
  85. diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc
  86. index 8999d6bbb3acc55dbedc2b36cca03862614f139f..3e1eb1d3a54566627c33a268a5ff8e3500c58616 100644
  87. --- a/content/renderer/render_frame_impl.cc
  88. +++ b/content/renderer/render_frame_impl.cc
  89. @@ -5321,6 +5321,22 @@ void RenderFrameImpl::BeginNavigation(
  90. // we can do a per-frame check here rather than a process-wide check.
  91. bool should_fork = HasWebUIScheme(url) || HasWebUIScheme(old_url) ||
  92. (enabled_bindings_ & kWebUIBindingsPolicyMask);
  93. +
  94. + if (!should_fork && url.SchemeIs(url::kFileScheme)) {
  95. + // Fork non-file to file opens (see https://crbug.com/1031119). Note that
  96. + // this may fork unnecessarily if another tab (hosting a file or not)
  97. + // targeted this one before its initial navigation, but that shouldn't
  98. + // cause a problem.
  99. + should_fork = !old_url.SchemeIs(url::kFileScheme);
  100. + }
  101. +
  102. + if (!should_fork) {
  103. + // Give the embedder a chance.
  104. + should_fork = GetContentClient()->renderer()->ShouldFork(
  105. + frame_, url, info->url_request.HttpMethod().Utf8(),
  106. + false /* is_redirect */);
  107. + }
  108. +
  109. if (should_fork) {
  110. OpenURL(std::move(info));
  111. return; // Suppress the load here.