allow_disabling_blink_scheduler_throttling_per_renderview.patch 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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/render_view_host_impl.cc b/content/browser/renderer_host/render_view_host_impl.cc
  7. index 8a8f88c0beed2afda87543b8933bde342ecb0588..2ed68bd47ccadea20acad67d6a106e257e2c7cd0 100644
  8. --- a/content/browser/renderer_host/render_view_host_impl.cc
  9. +++ b/content/browser/renderer_host/render_view_host_impl.cc
  10. @@ -716,6 +716,11 @@ void RenderViewHostImpl::SetBackgroundOpaque(bool opaque) {
  11. GetWidget()->GetAssociatedFrameWidget()->SetBackgroundOpaque(opaque);
  12. }
  13. +void RenderViewHostImpl::SetSchedulerThrottling(bool allowed) {
  14. + if (auto& broadcast = GetAssociatedPageBroadcast())
  15. + broadcast->SetSchedulerThrottling(allowed);
  16. +}
  17. +
  18. bool RenderViewHostImpl::IsMainFrameActive() {
  19. return is_active();
  20. }
  21. diff --git a/content/browser/renderer_host/render_view_host_impl.h b/content/browser/renderer_host/render_view_host_impl.h
  22. index d44652650891eff7cd6111bc6d6454a009942cb6..16522609163ba6bc422fc30a8d145a25877c407e 100644
  23. --- a/content/browser/renderer_host/render_view_host_impl.h
  24. +++ b/content/browser/renderer_host/render_view_host_impl.h
  25. @@ -140,6 +140,7 @@ class CONTENT_EXPORT RenderViewHostImpl
  26. void EnablePreferredSizeMode() override;
  27. void WriteIntoTrace(perfetto::TracedProto<TraceProto> context) const override;
  28. + void SetSchedulerThrottling(bool allowed) override;
  29. void SendWebPreferencesToRenderer();
  30. void SendRendererPreferencesToRenderer(
  31. const blink::RendererPreferences& preferences);
  32. diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc
  33. index 9b7814890a4f513e8b9e07fbac370a40af6dac15..ee2b3bc3aabf7f5a8e3d2ad57675537f21aafaa6 100644
  34. --- a/content/browser/renderer_host/render_widget_host_view_aura.cc
  35. +++ b/content/browser/renderer_host/render_widget_host_view_aura.cc
  36. @@ -562,8 +562,8 @@ void RenderWidgetHostViewAura::ShowImpl(PageVisibilityState page_visibility) {
  37. // OnShowWithPageVisibility will not call NotifyHostAndDelegateOnWasShown,
  38. // which updates `visibility_`, unless the host is hidden. Make sure no update
  39. // is needed.
  40. - DCHECK(host_->is_hidden() || visibility_ == Visibility::VISIBLE);
  41. - OnShowWithPageVisibility(page_visibility);
  42. + if (host_->is_hidden() || visibility_ == Visibility::VISIBLE)
  43. + OnShowWithPageVisibility(page_visibility);
  44. }
  45. void RenderWidgetHostViewAura::NotifyHostAndDelegateOnWasShown(
  46. diff --git a/content/public/browser/render_view_host.h b/content/public/browser/render_view_host.h
  47. index 9979c25ecd57e68331b628a518368635db5c2027..f65bfbbb663a5bb0511ffa389d3163e0fdeb4d1f 100644
  48. --- a/content/public/browser/render_view_host.h
  49. +++ b/content/public/browser/render_view_host.h
  50. @@ -76,6 +76,9 @@ class CONTENT_EXPORT RenderViewHost {
  51. virtual void WriteIntoTrace(
  52. perfetto::TracedProto<TraceProto> context) const = 0;
  53. + // Disable/Enable scheduler throttling.
  54. + virtual void SetSchedulerThrottling(bool allowed) {}
  55. +
  56. private:
  57. // This interface should only be implemented inside content.
  58. friend class RenderViewHostImpl;
  59. diff --git a/content/test/test_page_broadcast.h b/content/test/test_page_broadcast.h
  60. index 73c0f64aa84061381a98ba60906835258f881468..41bdf7e231eca4617dbe53737a3925039bf77c4f 100644
  61. --- a/content/test/test_page_broadcast.h
  62. +++ b/content/test/test_page_broadcast.h
  63. @@ -45,6 +45,7 @@ class TestPageBroadcast : public blink::mojom::PageBroadcast {
  64. override;
  65. void UpdatePageBrowsingContextGroup(const blink::BrowsingContextGroupInfo&
  66. browsing_context_group_info) override;
  67. + void SetSchedulerThrottling(bool allowed) override {}
  68. mojo::AssociatedReceiver<blink::mojom::PageBroadcast> receiver_;
  69. };
  70. diff --git a/third_party/blink/public/mojom/page/page.mojom b/third_party/blink/public/mojom/page/page.mojom
  71. index d3877e946b1d65eba5bb45efe786fbcc7925ca6e..73bd5056baf7e4278b7260e550e2b8516be72f20 100644
  72. --- a/third_party/blink/public/mojom/page/page.mojom
  73. +++ b/third_party/blink/public/mojom/page/page.mojom
  74. @@ -155,4 +155,7 @@ interface PageBroadcast {
  75. // in `browsing_context_group_info`.
  76. UpdatePageBrowsingContextGroup(
  77. blink.mojom.BrowsingContextGroupInfo browsing_context_group_info);
  78. +
  79. + // Whether to enable the Renderer scheduler background throttling.
  80. + SetSchedulerThrottling(bool allowed);
  81. };
  82. diff --git a/third_party/blink/public/web/web_view.h b/third_party/blink/public/web/web_view.h
  83. index 8a18ecf567cd3a6a2fb1627083a5544a93198bf4..6bb4074e033e045de164bc776f75f152ea7be16f 100644
  84. --- a/third_party/blink/public/web/web_view.h
  85. +++ b/third_party/blink/public/web/web_view.h
  86. @@ -371,6 +371,7 @@ class BLINK_EXPORT WebView {
  87. // Scheduling -----------------------------------------------------------
  88. virtual PageScheduler* Scheduler() const = 0;
  89. + virtual void SetSchedulerThrottling(bool allowed) {}
  90. // Visibility -----------------------------------------------------------
  91. diff --git a/third_party/blink/renderer/core/exported/web_view_impl.cc b/third_party/blink/renderer/core/exported/web_view_impl.cc
  92. index 1043f13dd1d47ba58e2cf5311d2ed2387ba97b14..fd48c793a0d447a4a6777f94c5b580fdf9b5b2d9 100644
  93. --- a/third_party/blink/renderer/core/exported/web_view_impl.cc
  94. +++ b/third_party/blink/renderer/core/exported/web_view_impl.cc
  95. @@ -2407,6 +2407,10 @@ void WebViewImpl::SetPageLifecycleStateInternal(
  96. TRACE_EVENT2("navigation", "WebViewImpl::SetPageLifecycleStateInternal",
  97. "old_state", old_state, "new_state", new_state);
  98. + // If backgroundThrottling is disabled, the page is always visible.
  99. + if (!scheduler_throttling_allowed_)
  100. + new_state->visibility = mojom::blink::PageVisibilityState::kVisible;
  101. +
  102. bool storing_in_bfcache = new_state->is_in_back_forward_cache &&
  103. !old_state->is_in_back_forward_cache;
  104. bool restoring_from_bfcache = !new_state->is_in_back_forward_cache &&
  105. @@ -3875,20 +3879,34 @@ PageScheduler* WebViewImpl::Scheduler() const {
  106. return GetPage()->GetPageScheduler();
  107. }
  108. +void WebViewImpl::SetSchedulerThrottling(bool allowed) {
  109. + DCHECK(GetPage());
  110. + scheduler_throttling_allowed_ = allowed;
  111. + GetPage()->GetPageScheduler()->SetPageVisible(allowed ?
  112. + (GetVisibilityState() == mojom::blink::PageVisibilityState::kVisible) : true);
  113. +}
  114. +
  115. void WebViewImpl::SetVisibilityState(
  116. mojom::blink::PageVisibilityState visibility_state,
  117. bool is_initial_state) {
  118. DCHECK(GetPage());
  119. - GetPage()->SetVisibilityState(visibility_state, is_initial_state);
  120. - // Do not throttle if the page should be painting.
  121. - GetPage()->GetPageScheduler()->SetPageVisible(
  122. - visibility_state == mojom::blink::PageVisibilityState::kVisible ||
  123. - visibility_state ==
  124. - mojom::blink::PageVisibilityState::kHiddenButPainting);
  125. - // Notify observers of the change.
  126. - if (!is_initial_state) {
  127. - for (auto& observer : observers_)
  128. - observer.OnPageVisibilityChanged(visibility_state);
  129. +
  130. + // If backgroundThrottling is disabled, the page is always visible.
  131. + if (!scheduler_throttling_allowed_) {
  132. + GetPage()->SetVisibilityState(mojom::blink::PageVisibilityState::kVisible, is_initial_state);
  133. + GetPage()->GetPageScheduler()->SetPageVisible(true);
  134. + } else {
  135. + bool is_visible =
  136. + (visibility_state == mojom::blink::PageVisibilityState::kVisible ||
  137. + visibility_state ==
  138. + mojom::blink::PageVisibilityState::kHiddenButPainting);
  139. + GetPage()->SetVisibilityState(visibility_state, is_initial_state);
  140. + GetPage()->GetPageScheduler()->SetPageVisible(is_visible);
  141. + // Notify observers of the change.
  142. + if (!is_initial_state) {
  143. + for (auto& observer : observers_)
  144. + observer.OnPageVisibilityChanged(visibility_state);
  145. + }
  146. }
  147. }
  148. diff --git a/third_party/blink/renderer/core/exported/web_view_impl.h b/third_party/blink/renderer/core/exported/web_view_impl.h
  149. index 6a180620e00c77d0f4be346d1296f62feb714abb..c0ccf14faa52ab190c5848e8e9b597bcf637d4c0 100644
  150. --- a/third_party/blink/renderer/core/exported/web_view_impl.h
  151. +++ b/third_party/blink/renderer/core/exported/web_view_impl.h
  152. @@ -445,6 +445,7 @@ class CORE_EXPORT WebViewImpl final : public WebView,
  153. LocalDOMWindow* PagePopupWindow() const;
  154. PageScheduler* Scheduler() const override;
  155. + void SetSchedulerThrottling(bool allowed) override;
  156. void SetVisibilityState(mojom::blink::PageVisibilityState visibility_state,
  157. bool is_initial_state) override;
  158. mojom::blink::PageVisibilityState GetVisibilityState() override;
  159. @@ -909,6 +910,8 @@ class CORE_EXPORT WebViewImpl final : public WebView,
  160. // If true, we send IPC messages when |preferred_size_| changes.
  161. bool send_preferred_size_changes_ = false;
  162. + bool scheduler_throttling_allowed_ = true;
  163. +
  164. // Whether the preferred size may have changed and |UpdatePreferredSize| needs
  165. // to be called.
  166. bool needs_preferred_size_update_ = true;