feat_allow_disabling_blink_scheduler_throttling_per_renderview.patch 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 195b0f2da8a08f59566bb6306ccbec94b684d613..8d04d13574374a2cf2b09c2dd30b6b9f07b4ac84 100644
  8. --- a/content/browser/renderer_host/render_view_host_impl.cc
  9. +++ b/content/browser/renderer_host/render_view_host_impl.cc
  10. @@ -433,6 +433,10 @@ void RenderViewHostImpl::SetBackgroundOpaque(bool opaque) {
  11. Send(new ViewMsg_SetBackgroundOpaque(GetRoutingID(), 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 4311c3406cc8a3e2af505df182c890e4de6e5ea3..15daed8fd4071926c9fa7bf3aa00789b0dae0928 100644
  22. --- a/content/browser/renderer_host/render_view_host_impl.h
  23. +++ b/content/browser/renderer_host/render_view_host_impl.h
  24. @@ -108,6 +108,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 accb317ce091177766a8c49054b3e274b57871d8..8e0c40cbb98e02849c4c9dffc714eb48fbb40d57 100644
  34. --- a/content/common/view_messages.h
  35. +++ b/content/common/view_messages.h
  36. @@ -109,6 +109,9 @@ IPC_STRUCT_TRAITS_END()
  37. // Make the RenderWidget background transparent or opaque.
  38. IPC_MESSAGE_ROUTED1(ViewMsg_SetBackgroundOpaque, bool /* opaque */)
  39. +// Whether to enable the Renderer scheduler background throttling.
  40. +IPC_MESSAGE_ROUTED1(ViewMsg_SetSchedulerThrottling, bool /* allowed */)
  41. +
  42. // This passes a set of webkit preferences down to the renderer.
  43. IPC_MESSAGE_ROUTED1(ViewMsg_UpdateWebPreferences,
  44. content::WebPreferences)
  45. diff --git a/content/public/browser/render_view_host.h b/content/public/browser/render_view_host.h
  46. index 95679ab2915ad496ca0018aa13874b84eb11d7fd..c278e0fc072409677beafc7f252ebcf6002f16d4 100644
  47. --- a/content/public/browser/render_view_host.h
  48. +++ b/content/public/browser/render_view_host.h
  49. @@ -99,6 +99,9 @@ class CONTENT_EXPORT RenderViewHost : public IPC::Sender {
  50. // started.
  51. virtual void NotifyMoveOrResizeStarted() = 0;
  52. + // Disable/Enable scheduler throttling.
  53. + virtual void SetSchedulerThrottling(bool allowed) = 0;
  54. +
  55. // TODO(mustaq): Replace "Webkit" from the following three method names.
  56. //
  57. // Returns the current WebKit preferences. Note: WebPreferences is cached, so
  58. diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc
  59. index 37ac96bb7d42fe4caeb31861875219079d986982..d4b3d0f71ea6bc6aa9b927f32ee09eb9732c46c7 100644
  60. --- a/content/renderer/render_view_impl.cc
  61. +++ b/content/renderer/render_view_impl.cc
  62. @@ -1210,6 +1210,8 @@ bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
  63. IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message)
  64. IPC_MESSAGE_HANDLER(ViewMsg_SetPageScale, OnSetPageScale)
  65. IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
  66. + IPC_MESSAGE_HANDLER(ViewMsg_SetSchedulerThrottling,
  67. + OnSetSchedulerThrottling)
  68. IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
  69. IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
  70. IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
  71. @@ -1800,6 +1802,12 @@ void RenderViewImpl::OnSetPageScale(float page_scale_factor) {
  72. webview()->SetPageScaleFactor(page_scale_factor);
  73. }
  74. +void RenderViewImpl::OnSetSchedulerThrottling(bool allowed) {
  75. + if (!webview())
  76. + return;
  77. + webview()->SetSchedulerThrottling(allowed);
  78. +}
  79. +
  80. void RenderViewImpl::ApplyPageVisibilityState(
  81. PageVisibilityState visibility_state,
  82. bool initial_setting) {
  83. diff --git a/content/renderer/render_view_impl.h b/content/renderer/render_view_impl.h
  84. index a6768059fb7e91115f4659f236f096d264977408..a5954b581e06f78d364f4525f1550f7f13c836ec 100644
  85. --- a/content/renderer/render_view_impl.h
  86. +++ b/content/renderer/render_view_impl.h
  87. @@ -452,6 +452,7 @@ class CONTENT_EXPORT RenderViewImpl : public blink::WebViewClient,
  88. void OnSetInitialFocus(bool reverse);
  89. void OnSetRendererPrefs(
  90. const blink::mojom::RendererPreferences& renderer_prefs);
  91. + void OnSetSchedulerThrottling(bool allowed);
  92. void OnSuppressDialogsUntilSwapOut();
  93. void OnUpdateTargetURLAck();
  94. void OnUpdateWebPreferences(const WebPreferences& prefs);
  95. diff --git a/third_party/blink/public/web/web_view.h b/third_party/blink/public/web/web_view.h
  96. index dc04ef3eb3a1a56d932a22ffce7b71bb60786f7a..3e7d605d7a0f884299e441d954877c03436aa618 100644
  97. --- a/third_party/blink/public/web/web_view.h
  98. +++ b/third_party/blink/public/web/web_view.h
  99. @@ -399,6 +399,7 @@ class WebView {
  100. // Scheduling -----------------------------------------------------------
  101. virtual PageScheduler* Scheduler() const = 0;
  102. + virtual void SetSchedulerThrottling(bool allowed) = 0;
  103. // Visibility -----------------------------------------------------------
  104. diff --git a/third_party/blink/renderer/core/exported/web_view_impl.cc b/third_party/blink/renderer/core/exported/web_view_impl.cc
  105. index 34ff617acbd75b2d431aef194cceff651aadc24f..b681d16f2bf1aa9151d455f1a6d9ebb55adeae7b 100644
  106. --- a/third_party/blink/renderer/core/exported/web_view_impl.cc
  107. +++ b/third_party/blink/renderer/core/exported/web_view_impl.cc
  108. @@ -3326,12 +3326,20 @@ PageScheduler* WebViewImpl::Scheduler() const {
  109. return GetPage()->GetPageScheduler();
  110. }
  111. +void WebViewImpl::SetSchedulerThrottling(bool allowed) {
  112. + DCHECK(GetPage());
  113. + scheduler_throttling_allowed_ = allowed;
  114. + GetPage()->GetPageScheduler()->SetPageVisible(allowed ?
  115. + (GetVisibilityState() == PageVisibilityState::kVisible) : true);
  116. +}
  117. +
  118. void WebViewImpl::SetVisibilityState(PageVisibilityState visibility_state,
  119. bool is_initial_state) {
  120. DCHECK(GetPage());
  121. GetPage()->SetVisibilityState(visibility_state, is_initial_state);
  122. - GetPage()->GetPageScheduler()->SetPageVisible(visibility_state ==
  123. - PageVisibilityState::kVisible);
  124. + GetPage()->GetPageScheduler()->SetPageVisible(
  125. + scheduler_throttling_allowed_ ?
  126. + (visibility_state == PageVisibilityState::kVisible) : true);
  127. }
  128. PageVisibilityState WebViewImpl::GetVisibilityState() {
  129. diff --git a/third_party/blink/renderer/core/exported/web_view_impl.h b/third_party/blink/renderer/core/exported/web_view_impl.h
  130. index 3154dbd08dc8aa0386c6259afdec084570822a9e..b9f6ed110e4527a9a05074c31cc89982edaae4f2 100644
  131. --- a/third_party/blink/renderer/core/exported/web_view_impl.h
  132. +++ b/third_party/blink/renderer/core/exported/web_view_impl.h
  133. @@ -306,6 +306,7 @@ class CORE_EXPORT WebViewImpl final : public WebView,
  134. LocalDOMWindow* PagePopupWindow() const;
  135. PageScheduler* Scheduler() const override;
  136. + void SetSchedulerThrottling(bool allowed) override;
  137. void SetVisibilityState(PageVisibilityState visibility_state,
  138. bool is_initial_state) override;
  139. PageVisibilityState GetVisibilityState() override;
  140. @@ -680,6 +681,8 @@ class CORE_EXPORT WebViewImpl final : public WebView,
  141. // WebViewImpl::Close while handling an input event.
  142. bool debug_inside_input_handling_ = false;
  143. + bool scheduler_throttling_allowed_ = true;
  144. +
  145. FloatSize elastic_overscroll_;
  146. Persistent<EventListener> popup_mouse_wheel_event_listener_;