revert_remove_contentrendererclient_shouldfork.patch 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 79d62d4dd739fbe51fedaf1b38e83669d625d7fc..f728b88778b7c9137833fece9615856a60fb399c 100644
  11. --- a/chrome/renderer/chrome_content_renderer_client.cc
  12. +++ b/chrome/renderer/chrome_content_renderer_client.cc
  13. @@ -1296,6 +1296,25 @@ bool ChromeContentRendererClient::AllowPopup() {
  14. #endif
  15. }
  16. +bool ChromeContentRendererClient::ShouldFork(WebLocalFrame* frame,
  17. + const GURL& url,
  18. + const std::string& http_method,
  19. + bool is_initial_navigation,
  20. + bool is_server_redirect) {
  21. + DCHECK(!frame->Parent());
  22. +
  23. + // If |url| matches one of the prerendered URLs, stop this navigation and try
  24. + // to swap in the prerendered page on the browser process. If the prerendered
  25. + // page no longer exists by the time the OpenURL IPC is handled, a normal
  26. + // navigation is attempted.
  27. + if (prerender_dispatcher_.get() &&
  28. + prerender_dispatcher_->IsPrerenderURL(url)) {
  29. + return true;
  30. + }
  31. +
  32. + return false;
  33. +}
  34. +
  35. void ChromeContentRendererClient::WillSendRequest(
  36. WebLocalFrame* frame,
  37. ui::PageTransition transition_type,
  38. diff --git a/chrome/renderer/chrome_content_renderer_client.h b/chrome/renderer/chrome_content_renderer_client.h
  39. index 416b7a8f3ba1b6941761c1df4ea108219c415489..2733d0dbbc10c5465a319b080d9b079258ba896d 100644
  40. --- a/chrome/renderer/chrome_content_renderer_client.h
  41. +++ b/chrome/renderer/chrome_content_renderer_client.h
  42. @@ -127,6 +127,11 @@ class ChromeContentRendererClient
  43. base::SingleThreadTaskRunner* compositor_thread_task_runner) override;
  44. bool RunIdleHandlerWhenWidgetsHidden() override;
  45. bool AllowPopup() override;
  46. + bool ShouldFork(blink::WebLocalFrame* frame,
  47. + const GURL& url,
  48. + const std::string& http_method,
  49. + bool is_initial_navigation,
  50. + bool is_server_redirect) override;
  51. void WillSendRequest(blink::WebLocalFrame* frame,
  52. ui::PageTransition transition_type,
  53. const blink::WebURL& url,
  54. diff --git a/content/public/renderer/content_renderer_client.cc b/content/public/renderer/content_renderer_client.cc
  55. index ea6d8e6357233f519c3cf41a96d8453993a9ce71..c513aff3e1c3da45e45954bc0beb80469de6a450 100644
  56. --- a/content/public/renderer/content_renderer_client.cc
  57. +++ b/content/public/renderer/content_renderer_client.cc
  58. @@ -114,6 +114,14 @@ bool ContentRendererClient::HandleNavigation(
  59. }
  60. #endif
  61. +bool ContentRendererClient::ShouldFork(blink::WebLocalFrame* frame,
  62. + const GURL& url,
  63. + const std::string& http_method,
  64. + bool is_initial_navigation,
  65. + bool is_server_redirect) {
  66. + return false;
  67. +}
  68. +
  69. void ContentRendererClient::WillSendRequest(
  70. blink::WebLocalFrame* frame,
  71. ui::PageTransition transition_type,
  72. diff --git a/content/public/renderer/content_renderer_client.h b/content/public/renderer/content_renderer_client.h
  73. index 9d321040de33acac09e83cc582f685740f425009..8f328979cc232c4f81a7f040e2424273a8248015 100644
  74. --- a/content/public/renderer/content_renderer_client.h
  75. +++ b/content/public/renderer/content_renderer_client.h
  76. @@ -228,6 +228,13 @@ class CONTENT_EXPORT ContentRendererClient {
  77. bool is_redirect);
  78. #endif
  79. + // Returns true if we should fork a new process for the given navigation.
  80. + virtual bool ShouldFork(blink::WebLocalFrame* frame,
  81. + const GURL& url,
  82. + const std::string& http_method,
  83. + bool is_initial_navigation,
  84. + bool is_server_redirect);
  85. +
  86. // Notifies the embedder that the given frame is requesting the resource at
  87. // |url|. If the function returns a valid |new_url|, the request must be
  88. // updated to use it. The |force_ignore_site_for_cookies| output parameter
  89. diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc
  90. index a5a95523e16fd35018f9646ae4a4d51e5ca626c0..4133bb215a66be974e5dfc0f3e0c89614bb58523 100644
  91. --- a/content/renderer/render_frame_impl.cc
  92. +++ b/content/renderer/render_frame_impl.cc
  93. @@ -5478,6 +5478,23 @@ void RenderFrameImpl::BeginNavigation(
  94. // we can do a per-frame check here rather than a process-wide check.
  95. bool should_fork = HasWebUIScheme(url) || HasWebUIScheme(old_url) ||
  96. (enabled_bindings_ & kWebUIBindingsPolicyMask);
  97. +
  98. + if (!should_fork && url.SchemeIs(url::kFileScheme)) {
  99. + // Fork non-file to file opens (see https://crbug.com/1031119). Note that
  100. + // this may fork unnecessarily if another tab (hosting a file or not)
  101. + // targeted this one before its initial navigation, but that shouldn't
  102. + // cause a problem.
  103. + should_fork = !old_url.SchemeIs(url::kFileScheme);
  104. + }
  105. +
  106. + if (!should_fork) {
  107. + // Give the embedder a chance.
  108. + bool is_initial_navigation = render_view_->history_list_length_ == 0;
  109. + should_fork = GetContentClient()->renderer()->ShouldFork(
  110. + frame_, url, info->url_request.HttpMethod().Utf8(),
  111. + is_initial_navigation, false /* is_redirect */);
  112. + }
  113. +
  114. if (should_fork) {
  115. OpenURL(std::move(info));
  116. return; // Suppress the load here.