allow_disabling_blink_scheduler_throttling_per_renderview.patch 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 093bed2d057df4b12ae01b8edc11c7924233b0c5..43a24c45bc5adf1bb6a3eb00c3b3ad64e663522f 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 2d5431caee0b44828ae35a861cda8b15b587123f..5db98459e35767aee91c9b901c10f2f59ac1456b 100644
  23. --- a/content/browser/renderer_host/render_view_host_impl.h
  24. +++ b/content/browser/renderer_host/render_view_host_impl.h
  25. @@ -139,6 +139,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 2b7a01cd1e7637031bbd28ba32f332f9f97456f1..9840d0e1308bc6e4589f32f6eac5e27f353895dd 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. @@ -564,8 +564,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 b2204672b2dde14ce91a0c67e8a5b5ebede55aa9..0f9bed79ba572a5fffb4f39e2ffc6f58970ee7cb 100644
  61. --- a/content/test/test_page_broadcast.h
  62. +++ b/content/test/test_page_broadcast.h
  63. @@ -47,6 +47,7 @@ class TestPageBroadcast : public blink::mojom::PageBroadcast {
  64. browsing_context_group_info) override;
  65. void SetPageAttributionSupport(
  66. network::mojom::AttributionSupport support) 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 1270218d71d365b3b33188ba803026e9a24f51dc..78fe7a385eb8781787c5288a9eb790df05afa088 100644
  72. --- a/third_party/blink/public/mojom/page/page.mojom
  73. +++ b/third_party/blink/public/mojom/page/page.mojom
  74. @@ -162,4 +162,7 @@ interface PageBroadcast {
  75. // supported/unsupported or when attribution is enabled/disabled for
  76. // Android WebView.
  77. SetPageAttributionSupport(network.mojom.AttributionSupport support);
  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 e89d7153d66d15e6e9a2a6980aaec5c671dfd0f3..c77228f8aa6ada81bcafc2622d784bb3f85cca30 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 9f211819ae0b54718c89ecb777fbf469fa4ebe4d..d9b1a87fb6c7dca120c1a7d25eeda1135f4a3831 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. @@ -2395,6 +2395,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. @@ -3885,10 +3889,23 @@ 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 || GetVisibilityState() == mojom::blink::PageVisibilityState::kVisible);
  112. +}
  113. +
  114. void WebViewImpl::SetVisibilityState(
  115. mojom::blink::PageVisibilityState visibility_state,
  116. bool is_initial_state) {
  117. DCHECK(GetPage());
  118. +
  119. + if (!scheduler_throttling_allowed_) {
  120. + GetPage()->SetVisibilityState(mojom::blink::PageVisibilityState::kVisible, is_initial_state);
  121. + GetPage()->GetPageScheduler()->SetPageVisible(true);
  122. + return;
  123. + }
  124. +
  125. GetPage()->SetVisibilityState(visibility_state, is_initial_state);
  126. // Do not throttle if the page should be painting.
  127. bool is_visible =
  128. diff --git a/third_party/blink/renderer/core/exported/web_view_impl.h b/third_party/blink/renderer/core/exported/web_view_impl.h
  129. index 90359a1f1aafadc7bb4e8776c9b609a7485072f6..b66744a6557152b69a3c769f8dfb5b0221d67a01 100644
  130. --- a/third_party/blink/renderer/core/exported/web_view_impl.h
  131. +++ b/third_party/blink/renderer/core/exported/web_view_impl.h
  132. @@ -447,6 +447,7 @@ class CORE_EXPORT WebViewImpl final : public WebView,
  133. LocalDOMWindow* PagePopupWindow() const;
  134. PageScheduler* Scheduler() const override;
  135. + void SetSchedulerThrottling(bool allowed) override;
  136. void SetVisibilityState(mojom::blink::PageVisibilityState visibility_state,
  137. bool is_initial_state) override;
  138. mojom::blink::PageVisibilityState GetVisibilityState() override;
  139. @@ -914,6 +915,8 @@ class CORE_EXPORT WebViewImpl final : public WebView,
  140. // If true, we send IPC messages when |preferred_size_| changes.
  141. bool send_preferred_size_changes_ = false;
  142. + bool scheduler_throttling_allowed_ = true;
  143. +
  144. // Whether the preferred size may have changed and |UpdatePreferredSize| needs
  145. // to be called.
  146. bool needs_preferred_size_update_ = true;