feat_allow_disabling_blink_scheduler_throttling_per_renderview.patch 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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: 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 00644aa7553c815753b5f47d4489614657cc770f..1050e3fca362fd898f150c0f15d7a92dcdd95cae 100644
  8. --- a/content/browser/renderer_host/render_view_host_impl.cc
  9. +++ b/content/browser/renderer_host/render_view_host_impl.cc
  10. @@ -609,6 +609,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 b9b5b0984f5313b1e90999cde027b2e987e3bef8..12c99cf6ff021aa43cf32f9eb3021af6463fc742 100644
  23. --- a/content/browser/renderer_host/render_view_host_impl.h
  24. +++ b/content/browser/renderer_host/render_view_host_impl.h
  25. @@ -135,6 +135,7 @@ class CONTENT_EXPORT RenderViewHostImpl
  26. bool IsRenderViewLive() override;
  27. void WriteIntoTracedValue(perfetto::TracedValue context) override;
  28. + void SetSchedulerThrottling(bool allowed) override;
  29. void SendWebPreferencesToRenderer();
  30. void SendRendererPreferencesToRenderer(
  31. const blink::RendererPreferences& preferences);
  32. diff --git a/content/public/browser/render_view_host.h b/content/public/browser/render_view_host.h
  33. index 59b281ca58f7ea8cf20f809a85fffef4fd3c9eec..e27942ee8a436d80d2f441925b751e7bd3cf7132 100644
  34. --- a/content/public/browser/render_view_host.h
  35. +++ b/content/public/browser/render_view_host.h
  36. @@ -91,6 +91,9 @@ class CONTENT_EXPORT RenderViewHost {
  37. // Write a representation of this object into a trace.
  38. virtual void WriteIntoTracedValue(perfetto::TracedValue context) = 0;
  39. + // Disable/Enable scheduler throttling.
  40. + virtual void SetSchedulerThrottling(bool allowed) = 0;
  41. +
  42. private:
  43. // This interface should only be implemented inside content.
  44. friend class RenderViewHostImpl;
  45. diff --git a/content/renderer/render_view_impl.h b/content/renderer/render_view_impl.h
  46. index 1d8ffde83fa97ff516e2cbc2add520da7b955750..4db10afe645a36ccac56d9afda95fd1fb3eaadf7 100644
  47. --- a/content/renderer/render_view_impl.h
  48. +++ b/content/renderer/render_view_impl.h
  49. @@ -211,6 +211,8 @@ class CONTENT_EXPORT RenderViewImpl : public blink::WebViewClient,
  50. static WindowOpenDisposition NavigationPolicyToDisposition(
  51. blink::WebNavigationPolicy policy);
  52. + void OnSetSchedulerThrottling(bool allowed);
  53. +
  54. // Misc private functions ----------------------------------------------------
  55. #if defined(OS_ANDROID)
  56. diff --git a/third_party/blink/public/mojom/page/page.mojom b/third_party/blink/public/mojom/page/page.mojom
  57. index e122d4ffb857023841dabcb6fed352d7586d8344..3c7cd1cb8b204024a0835150302ee8896e01ee45 100644
  58. --- a/third_party/blink/public/mojom/page/page.mojom
  59. +++ b/third_party/blink/public/mojom/page/page.mojom
  60. @@ -73,4 +73,7 @@ interface PageBroadcast {
  61. // Set history offset and length.
  62. SetHistoryOffsetAndLength(int32 offset, int32 length);
  63. +
  64. + // Whether to enable the Renderer scheduler background throttling.
  65. + SetSchedulerThrottling(bool allowed);
  66. };
  67. diff --git a/third_party/blink/public/web/web_view.h b/third_party/blink/public/web/web_view.h
  68. index 209067240ccce0458882ad008363cdb996dd1a80..eaacca18d1488b3a2f7445bb44949ccb9e8e3453 100644
  69. --- a/third_party/blink/public/web/web_view.h
  70. +++ b/third_party/blink/public/web/web_view.h
  71. @@ -348,6 +348,7 @@ class WebView {
  72. // Scheduling -----------------------------------------------------------
  73. virtual PageScheduler* Scheduler() const = 0;
  74. + virtual void SetSchedulerThrottling(bool allowed) = 0;
  75. // Visibility -----------------------------------------------------------
  76. diff --git a/third_party/blink/renderer/core/exported/web_view_impl.cc b/third_party/blink/renderer/core/exported/web_view_impl.cc
  77. index 4b7adb536a285501bb8dbeccd6bbb813cdf903c6..d7ada5c44ba02449ab11d4cb5a6f201ea6adf9f6 100644
  78. --- a/third_party/blink/renderer/core/exported/web_view_impl.cc
  79. +++ b/third_party/blink/renderer/core/exported/web_view_impl.cc
  80. @@ -3551,6 +3551,13 @@ PageScheduler* WebViewImpl::Scheduler() const {
  81. return GetPage()->GetPageScheduler();
  82. }
  83. +void WebViewImpl::SetSchedulerThrottling(bool allowed) {
  84. + DCHECK(GetPage());
  85. + scheduler_throttling_allowed_ = allowed;
  86. + GetPage()->GetPageScheduler()->SetPageVisible(allowed ?
  87. + (GetVisibilityState() == mojom::blink::PageVisibilityState::kVisible) : true);
  88. +}
  89. +
  90. void WebViewImpl::SetVisibilityState(
  91. mojom::blink::PageVisibilityState visibility_state,
  92. bool is_initial_state) {
  93. @@ -3563,7 +3570,8 @@ void WebViewImpl::SetVisibilityState(
  94. }
  95. GetPage()->SetVisibilityState(visibility_state, is_initial_state);
  96. GetPage()->GetPageScheduler()->SetPageVisible(
  97. - visibility_state == mojom::blink::PageVisibilityState::kVisible);
  98. + scheduler_throttling_allowed_ ?
  99. + (visibility_state == mojom::blink::PageVisibilityState::kVisible) : true);
  100. }
  101. mojom::blink::PageVisibilityState WebViewImpl::GetVisibilityState() {
  102. diff --git a/third_party/blink/renderer/core/exported/web_view_impl.h b/third_party/blink/renderer/core/exported/web_view_impl.h
  103. index ace66b559cdc53c81b6b303a18a0c425e9a74789..5c4b0110e67b51877405fd49b497404201ce9dbc 100644
  104. --- a/third_party/blink/renderer/core/exported/web_view_impl.h
  105. +++ b/third_party/blink/renderer/core/exported/web_view_impl.h
  106. @@ -391,6 +391,7 @@ class CORE_EXPORT WebViewImpl final : public WebView,
  107. LocalDOMWindow* PagePopupWindow() const;
  108. PageScheduler* Scheduler() const override;
  109. + void SetSchedulerThrottling(bool allowed) override;
  110. void SetVisibilityState(mojom::blink::PageVisibilityState visibility_state,
  111. bool is_initial_state) override;
  112. mojom::blink::PageVisibilityState GetVisibilityState() override;
  113. @@ -800,11 +801,18 @@ class CORE_EXPORT WebViewImpl final : public WebView,
  114. float zoom_factor_override_ = 0.f;
  115. + // TODO(bokan): Temporary debugging added to diagnose
  116. + // https://crbug.com/992315. Somehow we're synchronously calling
  117. + // WebViewImpl::Close while handling an input event.
  118. + bool debug_inside_input_handling_ = false;
  119. +
  120. FloatSize elastic_overscroll_;
  121. // If true, we send IPC messages when |preferred_size_| changes.
  122. bool send_preferred_size_changes_ = false;
  123. + bool scheduler_throttling_allowed_ = true;
  124. +
  125. // Whether the preferred size may have changed and |UpdatePreferredSize| needs
  126. // to be called.
  127. bool needs_preferred_size_update_ = true;