allow_disabling_blink_scheduler_throttling_per_renderview.patch 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: deepak1556 <[email protected]>
  3. Date: Mon, 18 May 2020 11:12:26 -0700
  4. Subject: allow disabling blink scheduler throttling per RenderView
  5. This allows us to disable throttling for hidden windows.
  6. diff --git a/content/browser/renderer_host/navigation_controller_impl_unittest.cc b/content/browser/renderer_host/navigation_controller_impl_unittest.cc
  7. index b5934f99861b11afe1b695ac25886ee0d059d0ab..419f823a094c1b163d7a5b441f1b034c0dada66b 100644
  8. --- a/content/browser/renderer_host/navigation_controller_impl_unittest.cc
  9. +++ b/content/browser/renderer_host/navigation_controller_impl_unittest.cc
  10. @@ -163,6 +163,12 @@ class MockPageBroadcast : public blink::mojom::PageBroadcast {
  11. (network::mojom::AttributionSupport support),
  12. (override));
  13. + MOCK_METHOD(
  14. + void,
  15. + SetSchedulerThrottling,
  16. + (bool allowed),
  17. + (override));
  18. +
  19. mojo::PendingAssociatedRemote<blink::mojom::PageBroadcast> GetRemote() {
  20. return receiver_.BindNewEndpointAndPassDedicatedRemote();
  21. }
  22. diff --git a/content/browser/renderer_host/render_view_host_impl.cc b/content/browser/renderer_host/render_view_host_impl.cc
  23. index c398dc84de605c7feef92fda30b25297a12273b0..747d5d9e09c4c002a5f38483ef0022d263cddbe6 100644
  24. --- a/content/browser/renderer_host/render_view_host_impl.cc
  25. +++ b/content/browser/renderer_host/render_view_host_impl.cc
  26. @@ -737,6 +737,11 @@ void RenderViewHostImpl::SetBackgroundOpaque(bool opaque) {
  27. GetWidget()->GetAssociatedFrameWidget()->SetBackgroundOpaque(opaque);
  28. }
  29. +void RenderViewHostImpl::SetSchedulerThrottling(bool allowed) {
  30. + if (auto& broadcast = GetAssociatedPageBroadcast())
  31. + broadcast->SetSchedulerThrottling(allowed);
  32. +}
  33. +
  34. bool RenderViewHostImpl::IsMainFrameActive() {
  35. return is_active();
  36. }
  37. diff --git a/content/browser/renderer_host/render_view_host_impl.h b/content/browser/renderer_host/render_view_host_impl.h
  38. index 779e90581cdfb2d1bdd904da038f7537d0477f5a..c85620ac2f30998d1b67f159e50ee72221bf0dad 100644
  39. --- a/content/browser/renderer_host/render_view_host_impl.h
  40. +++ b/content/browser/renderer_host/render_view_host_impl.h
  41. @@ -139,6 +139,7 @@ class CONTENT_EXPORT RenderViewHostImpl
  42. void EnablePreferredSizeMode() override;
  43. void WriteIntoTrace(perfetto::TracedProto<TraceProto> context) const override;
  44. + void SetSchedulerThrottling(bool allowed) override;
  45. void SendWebPreferencesToRenderer();
  46. void SendRendererPreferencesToRenderer(
  47. const blink::RendererPreferences& preferences);
  48. diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc
  49. index d1336997fbb2b4eae4e36f4266663d296b19d076..dcafa7c3ecf417ff1d79dff43b6f1a73cdd2da48 100644
  50. --- a/content/browser/renderer_host/render_widget_host_view_aura.cc
  51. +++ b/content/browser/renderer_host/render_widget_host_view_aura.cc
  52. @@ -579,8 +579,8 @@ void RenderWidgetHostViewAura::ShowImpl(PageVisibilityState page_visibility) {
  53. // OnShowWithPageVisibility will not call NotifyHostAndDelegateOnWasShown,
  54. // which updates `visibility_`, unless the host is hidden. Make sure no update
  55. // is needed.
  56. - CHECK(host_->is_hidden() || visibility_ == Visibility::VISIBLE);
  57. - OnShowWithPageVisibility(page_visibility);
  58. + if (host_->is_hidden() || visibility_ == Visibility::VISIBLE)
  59. + OnShowWithPageVisibility(page_visibility);
  60. }
  61. void RenderWidgetHostViewAura::EnsurePlatformVisibility(
  62. diff --git a/content/public/browser/render_view_host.h b/content/public/browser/render_view_host.h
  63. index 20ca763ff7f55e8176b77349b41917b11e051ae6..a50c122064b5f0092f57e3d508fb19389b72203b 100644
  64. --- a/content/public/browser/render_view_host.h
  65. +++ b/content/public/browser/render_view_host.h
  66. @@ -75,6 +75,9 @@ class CONTENT_EXPORT RenderViewHost {
  67. virtual void WriteIntoTrace(
  68. perfetto::TracedProto<TraceProto> context) const = 0;
  69. + // Disable/Enable scheduler throttling.
  70. + virtual void SetSchedulerThrottling(bool allowed) {}
  71. +
  72. private:
  73. // This interface should only be implemented inside content.
  74. friend class RenderViewHostImpl;
  75. diff --git a/content/test/test_page_broadcast.h b/content/test/test_page_broadcast.h
  76. index 603798ae0d45836f1bf3e6608761ce1467303310..2d8caa06e418f123d7565b96d40c66fb51617a6d 100644
  77. --- a/content/test/test_page_broadcast.h
  78. +++ b/content/test/test_page_broadcast.h
  79. @@ -50,6 +50,7 @@ class TestPageBroadcast : public blink::mojom::PageBroadcast {
  80. network::mojom::AttributionSupport support) override;
  81. void UpdateColorProviders(
  82. const blink::ColorProviderColorMaps& color_provider_colors) override;
  83. + void SetSchedulerThrottling(bool allowed) override {}
  84. mojo::AssociatedReceiver<blink::mojom::PageBroadcast> receiver_;
  85. };
  86. diff --git a/third_party/blink/public/mojom/page/page.mojom b/third_party/blink/public/mojom/page/page.mojom
  87. index c980f3f76a37a4207bb54f18fbcdb8d0950c8856..91a9dfe56fbbcd1cc873add438947dd29c7e6646 100644
  88. --- a/third_party/blink/public/mojom/page/page.mojom
  89. +++ b/third_party/blink/public/mojom/page/page.mojom
  90. @@ -173,4 +173,7 @@ interface PageBroadcast {
  91. // 2. The ColorProvider associated with the WebContents changes as a result
  92. // of theme changes.
  93. UpdateColorProviders(ColorProviderColorMaps color_provider_colors);
  94. +
  95. + // Whether to enable the Renderer scheduler background throttling.
  96. + SetSchedulerThrottling(bool allowed);
  97. };
  98. diff --git a/third_party/blink/public/web/web_view.h b/third_party/blink/public/web/web_view.h
  99. index 4220a0aebf4a2ce3d62f76c441b6ec1b5e11ffa1..6ea17602d2b186b81cf7dc69750bd302ff717aea 100644
  100. --- a/third_party/blink/public/web/web_view.h
  101. +++ b/third_party/blink/public/web/web_view.h
  102. @@ -362,6 +362,7 @@ class BLINK_EXPORT WebView {
  103. // Scheduling -----------------------------------------------------------
  104. virtual PageScheduler* Scheduler() const = 0;
  105. + virtual void SetSchedulerThrottling(bool allowed) {}
  106. // Visibility -----------------------------------------------------------
  107. diff --git a/third_party/blink/renderer/core/exported/web_view_impl.cc b/third_party/blink/renderer/core/exported/web_view_impl.cc
  108. index 36bd7ee7ed789981d3e6733d5f869430a1112a6f..831b3b1ee47a88b6b02a2256682e4a9b1cbeda3c 100644
  109. --- a/third_party/blink/renderer/core/exported/web_view_impl.cc
  110. +++ b/third_party/blink/renderer/core/exported/web_view_impl.cc
  111. @@ -2461,6 +2461,10 @@ void WebViewImpl::SetPageLifecycleStateInternal(
  112. TRACE_EVENT2("navigation", "WebViewImpl::SetPageLifecycleStateInternal",
  113. "old_state", old_state, "new_state", new_state);
  114. + // If backgroundThrottling is disabled, the page is always visible.
  115. + if (!scheduler_throttling_allowed_)
  116. + new_state->visibility = mojom::blink::PageVisibilityState::kVisible;
  117. +
  118. bool storing_in_bfcache = new_state->is_in_back_forward_cache &&
  119. !old_state->is_in_back_forward_cache;
  120. bool restoring_from_bfcache = !new_state->is_in_back_forward_cache &&
  121. @@ -3974,10 +3978,23 @@ PageScheduler* WebViewImpl::Scheduler() const {
  122. return GetPage()->GetPageScheduler();
  123. }
  124. +void WebViewImpl::SetSchedulerThrottling(bool allowed) {
  125. + DCHECK(GetPage());
  126. + scheduler_throttling_allowed_ = allowed;
  127. + GetPage()->GetPageScheduler()->SetPageVisible(!allowed || GetVisibilityState() == mojom::blink::PageVisibilityState::kVisible);
  128. +}
  129. +
  130. void WebViewImpl::SetVisibilityState(
  131. mojom::blink::PageVisibilityState visibility_state,
  132. bool is_initial_state) {
  133. DCHECK(GetPage());
  134. +
  135. + if (!scheduler_throttling_allowed_) {
  136. + GetPage()->SetVisibilityState(mojom::blink::PageVisibilityState::kVisible, is_initial_state);
  137. + GetPage()->GetPageScheduler()->SetPageVisible(true);
  138. + return;
  139. + }
  140. +
  141. GetPage()->SetVisibilityState(visibility_state, is_initial_state);
  142. // Do not throttle if the page should be painting.
  143. bool is_visible =
  144. diff --git a/third_party/blink/renderer/core/exported/web_view_impl.h b/third_party/blink/renderer/core/exported/web_view_impl.h
  145. index 764d48e8fc89fa0b95e01881c2f5462e385ed8d5..c0e99aec75858ec00a57d4b4484cbc719dbdda88 100644
  146. --- a/third_party/blink/renderer/core/exported/web_view_impl.h
  147. +++ b/third_party/blink/renderer/core/exported/web_view_impl.h
  148. @@ -449,6 +449,7 @@ class CORE_EXPORT WebViewImpl final : public WebView,
  149. LocalDOMWindow* PagePopupWindow() const;
  150. PageScheduler* Scheduler() const override;
  151. + void SetSchedulerThrottling(bool allowed) override;
  152. void SetVisibilityState(mojom::blink::PageVisibilityState visibility_state,
  153. bool is_initial_state) override;
  154. mojom::blink::PageVisibilityState GetVisibilityState() override;
  155. @@ -930,6 +931,8 @@ class CORE_EXPORT WebViewImpl final : public WebView,
  156. // If true, we send IPC messages when |preferred_size_| changes.
  157. bool send_preferred_size_changes_ = false;
  158. + bool scheduler_throttling_allowed_ = true;
  159. +
  160. // Whether the preferred size may have changed and |UpdatePreferredSize| needs
  161. // to be called.
  162. bool needs_preferred_size_update_ = true;