feat_allow_disabling_blink_scheduler_throttling_per_renderview.patch 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: deepak1556 <[email protected]>
  3. Date: Fri, 29 Nov 2019 16:08:14 -0800
  4. Subject: feat: 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 9a2cc0f076406d68910eeb5351e3869287515fcb..bde2f593f55edc677d44f4ae037042fe10661679 100644
  8. --- a/content/browser/renderer_host/render_view_host_impl.cc
  9. +++ b/content/browser/renderer_host/render_view_host_impl.cc
  10. @@ -512,6 +512,10 @@ void RenderViewHostImpl::SetBackgroundOpaque(bool opaque) {
  11. GetWidget()->GetAssociatedFrameWidget()->SetBackgroundOpaque(opaque);
  12. }
  13. +void RenderViewHostImpl::SetSchedulerThrottling(bool allowed) {
  14. + Send(new ViewMsg_SetSchedulerThrottling(GetRoutingID(), allowed));
  15. +}
  16. +
  17. bool RenderViewHostImpl::IsMainFrameActive() {
  18. return is_active();
  19. }
  20. diff --git a/content/browser/renderer_host/render_view_host_impl.h b/content/browser/renderer_host/render_view_host_impl.h
  21. index af15805b34d2cc038e73654017d4c0921e3fc321..3489f03bac1283efb6a27f5b959a72a8e5d0cb14 100644
  22. --- a/content/browser/renderer_host/render_view_host_impl.h
  23. +++ b/content/browser/renderer_host/render_view_host_impl.h
  24. @@ -110,6 +110,7 @@ class CONTENT_EXPORT RenderViewHostImpl
  25. SiteInstanceImpl* GetSiteInstance() override;
  26. bool IsRenderViewLive() override;
  27. void NotifyMoveOrResizeStarted() override;
  28. + void SetSchedulerThrottling(bool allowed) override;
  29. WebPreferences GetWebkitPreferences() override;
  30. void UpdateWebkitPreferences(const WebPreferences& prefs) override;
  31. void OnWebkitPreferencesChanged() override;
  32. diff --git a/content/common/view_messages.h b/content/common/view_messages.h
  33. index 19fa7ac26926231b01fe19f7adf62dd0e08edb1b..d4d3b97811a656d40884d7e4b872fdf72dfb11fa 100644
  34. --- a/content/common/view_messages.h
  35. +++ b/content/common/view_messages.h
  36. @@ -94,6 +94,9 @@ IPC_STRUCT_TRAITS_END()
  37. // Messages sent from the browser to the renderer.
  38. +// Whether to enable the Renderer scheduler background throttling.
  39. +IPC_MESSAGE_ROUTED1(ViewMsg_SetSchedulerThrottling, bool /* allowed */)
  40. +
  41. // This passes a set of webkit preferences down to the renderer.
  42. IPC_MESSAGE_ROUTED1(ViewMsg_UpdateWebPreferences,
  43. content::WebPreferences)
  44. diff --git a/content/public/browser/render_view_host.h b/content/public/browser/render_view_host.h
  45. index dfd856eb481114fea9da3e26b4080c9a8473acf6..604a95a0427705eca523e91b08a136f806da68f0 100644
  46. --- a/content/public/browser/render_view_host.h
  47. +++ b/content/public/browser/render_view_host.h
  48. @@ -96,6 +96,9 @@ class CONTENT_EXPORT RenderViewHost : public IPC::Sender {
  49. // started.
  50. virtual void NotifyMoveOrResizeStarted() = 0;
  51. + // Disable/Enable scheduler throttling.
  52. + virtual void SetSchedulerThrottling(bool allowed) = 0;
  53. +
  54. // TODO(mustaq): Replace "Webkit" from the following three method names.
  55. //
  56. // Returns the current WebKit preferences. Note: WebPreferences is cached, so
  57. diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc
  58. index 57447f4529917692155d1861c7658156978fa0be..2eaf980889ef9053e728dc09e76f1fcd889153b8 100644
  59. --- a/content/renderer/render_view_impl.cc
  60. +++ b/content/renderer/render_view_impl.cc
  61. @@ -1173,6 +1173,8 @@ bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
  62. bool handled = true;
  63. IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message)
  64. + IPC_MESSAGE_HANDLER(ViewMsg_SetSchedulerThrottling,
  65. + OnSetSchedulerThrottling)
  66. IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
  67. IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
  68. IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
  69. @@ -1669,6 +1671,12 @@ bool RenderViewImpl::GetContentStateImmediately() {
  70. return send_content_state_immediately_;
  71. }
  72. +void RenderViewImpl::OnSetSchedulerThrottling(bool allowed) {
  73. + if (!GetWebView())
  74. + return;
  75. + GetWebView()->SetSchedulerThrottling(allowed);
  76. +}
  77. +
  78. void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
  79. webkit_preferences_ = prefs;
  80. ApplyWebPreferences(webkit_preferences_, GetWebView());
  81. diff --git a/content/renderer/render_view_impl.h b/content/renderer/render_view_impl.h
  82. index 79ffb7a4a0ecef7c2e0583ca06a42c7bf6146bcc..ccb6f98da708fba99579623d92f9e40607e94dda 100644
  83. --- a/content/renderer/render_view_impl.h
  84. +++ b/content/renderer/render_view_impl.h
  85. @@ -391,6 +391,7 @@ class CONTENT_EXPORT RenderViewImpl : public blink::WebViewClient,
  86. void OnSetHistoryOffsetAndLength(int history_offset, int history_length);
  87. void OnSetRendererPrefs(
  88. const blink::mojom::RendererPreferences& renderer_prefs);
  89. + void OnSetSchedulerThrottling(bool allowed);
  90. void OnSuppressDialogsUntilSwapOut();
  91. void OnUpdateTargetURLAck();
  92. void OnUpdateWebPreferences(const WebPreferences& prefs);
  93. diff --git a/third_party/blink/public/web/web_view.h b/third_party/blink/public/web/web_view.h
  94. index baa1cec07522a23221b146165a638d3f679f9817..50f0c46c8fcbb4ee8ebb316f859f84d02d93ceda 100644
  95. --- a/third_party/blink/public/web/web_view.h
  96. +++ b/third_party/blink/public/web/web_view.h
  97. @@ -393,6 +393,7 @@ class WebView {
  98. // Scheduling -----------------------------------------------------------
  99. virtual PageScheduler* Scheduler() const = 0;
  100. + virtual void SetSchedulerThrottling(bool allowed) = 0;
  101. // Visibility -----------------------------------------------------------
  102. diff --git a/third_party/blink/renderer/core/exported/web_view_impl.cc b/third_party/blink/renderer/core/exported/web_view_impl.cc
  103. index 94fb9863a6da4c049e45ec5966ef79d9c8e42b75..063d88779ad2ca7c4c723e2872c28d93401fcec3 100644
  104. --- a/third_party/blink/renderer/core/exported/web_view_impl.cc
  105. +++ b/third_party/blink/renderer/core/exported/web_view_impl.cc
  106. @@ -3366,6 +3366,13 @@ PageScheduler* WebViewImpl::Scheduler() const {
  107. return GetPage()->GetPageScheduler();
  108. }
  109. +void WebViewImpl::SetSchedulerThrottling(bool allowed) {
  110. + DCHECK(GetPage());
  111. + scheduler_throttling_allowed_ = allowed;
  112. + GetPage()->GetPageScheduler()->SetPageVisible(allowed ?
  113. + (GetVisibilityState() == mojom::blink::PageVisibilityState::kVisible) : true);
  114. +}
  115. +
  116. void WebViewImpl::SetVisibilityState(
  117. mojom::blink::PageVisibilityState visibility_state,
  118. bool is_initial_state) {
  119. @@ -3376,7 +3383,8 @@ void WebViewImpl::SetVisibilityState(
  120. }
  121. GetPage()->SetVisibilityState(visibility_state, is_initial_state);
  122. GetPage()->GetPageScheduler()->SetPageVisible(
  123. - visibility_state == mojom::blink::PageVisibilityState::kVisible);
  124. + scheduler_throttling_allowed_ ?
  125. + (visibility_state ==mojom::blink::PageVisibilityState::kVisible) : true);
  126. }
  127. mojom::blink::PageVisibilityState WebViewImpl::GetVisibilityState() {
  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 e2124434e0d8ba3416179534ababca9d3b7f1708..3881e7a9f6fb25cbec37ddce6f87bf25b0d4a400 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. @@ -329,6 +329,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. @@ -681,6 +682,8 @@ class CORE_EXPORT WebViewImpl final : public WebView,
  140. // WebViewImpl::Close while handling an input event.
  141. bool debug_inside_input_handling_ = false;
  142. + bool scheduler_throttling_allowed_ = true;
  143. +
  144. FloatSize elastic_overscroll_;
  145. // If true, we send IPC messages when |preferred_size_| changes.