fix_move_autopipsettingshelper_behind_branding_buildflag.patch 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: deepak1556 <[email protected]>
  3. Date: Wed, 30 Aug 2023 15:56:53 +0900
  4. Subject: fix: move AutoPipSettingsHelper behind branding buildflag
  5. The class was added in https://chromium-review.googlesource.com/c/chromium/src/+/4688277
  6. which is primarily used for providing an overlay view in a PIP window
  7. to support content settings UI. The support pulls in chrome content settings
  8. and UI code which are not valid in the scope of Electron.
  9. diff --git a/chrome/browser/picture_in_picture/picture_in_picture_window_manager.cc b/chrome/browser/picture_in_picture/picture_in_picture_window_manager.cc
  10. index 297e37c11cc69025843b225a4ba8ae096e304915..6244f27cacbddeed4881463d07a2279083173a5b 100644
  11. --- a/chrome/browser/picture_in_picture/picture_in_picture_window_manager.cc
  12. +++ b/chrome/browser/picture_in_picture/picture_in_picture_window_manager.cc
  13. @@ -21,8 +21,10 @@
  14. #include "ui/gfx/geometry/size.h"
  15. #if !BUILDFLAG(IS_ANDROID)
  16. #include "base/task/sequenced_task_runner.h"
  17. +#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
  18. #include "chrome/browser/picture_in_picture/auto_picture_in_picture_tab_helper.h"
  19. #include "chrome/browser/picture_in_picture/auto_pip_setting_helper.h"
  20. +#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
  21. #include "media/base/media_switches.h"
  22. #include "third_party/blink/public/common/features.h"
  23. #include "ui/views/view.h"
  24. @@ -38,7 +40,7 @@ constexpr gfx::Size kMinWindowSize(240, 52);
  25. // not apply to video Picture-in-Picture windows.
  26. constexpr double kMaxWindowSizeRatio = 0.8;
  27. -#if !BUILDFLAG(IS_ANDROID)
  28. +#if !BUILDFLAG(IS_ANDROID) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
  29. // Returns true if a document picture-in-picture window should be focused upon
  30. // opening it.
  31. bool ShouldFocusPictureInPictureWindow(const NavigateParams& params) {
  32. @@ -170,7 +172,7 @@ bool PictureInPictureWindowManager::ExitPictureInPictureViaWindowUi(
  33. return false;
  34. }
  35. -#if !BUILDFLAG(IS_ANDROID)
  36. +#if !BUILDFLAG(IS_ANDROID) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
  37. if (auto_pip_setting_helper_) {
  38. auto_pip_setting_helper_->OnUserClosedWindow();
  39. }
  40. @@ -353,7 +355,7 @@ gfx::Size PictureInPictureWindowManager::GetMaximumWindowSize(
  41. // static
  42. void PictureInPictureWindowManager::SetWindowParams(NavigateParams& params) {
  43. -#if !BUILDFLAG(IS_ANDROID)
  44. +#if !BUILDFLAG(IS_ANDROID) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
  45. // Always show document picture-in-picture in a new window. When this is
  46. // not opened via the AutoPictureInPictureTabHelper, focus the window.
  47. params.window_action = ShouldFocusPictureInPictureWindow(params)
  48. @@ -376,7 +378,7 @@ void PictureInPictureWindowManager::CloseWindowInternal() {
  49. video_web_contents_observer_.reset();
  50. pip_window_controller_->Close(false /* should_pause_video */);
  51. pip_window_controller_ = nullptr;
  52. -#if !BUILDFLAG(IS_ANDROID)
  53. +#if !BUILDFLAG(IS_ANDROID) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
  54. auto_pip_setting_helper_.reset();
  55. #endif // !BUILDFLAG(IS_ANDROID)
  56. }
  57. @@ -387,8 +389,10 @@ void PictureInPictureWindowManager::DocumentWebContentsDestroyed() {
  58. // contents, so we only need to forget the controller here when user closes
  59. // the parent web contents with the PiP window open.
  60. document_web_contents_observer_.reset();
  61. +#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
  62. // `auto_pip_setting_helper_` depends on the opener's WebContents.
  63. auto_pip_setting_helper_.reset();
  64. +#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
  65. if (pip_window_controller_)
  66. pip_window_controller_ = nullptr;
  67. }
  68. @@ -410,6 +414,7 @@ PictureInPictureWindowManager::GetOverlayView(
  69. return nullptr;
  70. }
  71. +#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
  72. // It would be nice to create this in `EnterPictureInPicture*`, but detecting
  73. // auto-pip while pip is in the process of opening doesn't work.
  74. //
  75. @@ -440,6 +445,8 @@ PictureInPictureWindowManager::GetOverlayView(
  76. }
  77. return overlay_view;
  78. +#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
  79. + return nullptr;
  80. }
  81. PictureInPictureOcclusionTracker*
  82. @@ -450,6 +457,7 @@ PictureInPictureWindowManager::GetOcclusionTracker() {
  83. #endif // !BUILDFLAG(IS_ANDROID)
  84. #if !BUILDFLAG(IS_ANDROID)
  85. +#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
  86. void PictureInPictureWindowManager::CreateAutoPipSettingHelperIfNeeded() {
  87. // Because we have to defer creating this until after the tab helper finds out
  88. // about pip, we don't care if there's already a helper. Just use it.
  89. @@ -479,6 +487,7 @@ void PictureInPictureWindowManager::CreateAutoPipSettingHelperIfNeeded() {
  90. web_contents,
  91. base::BindOnce(&PictureInPictureWindowManager::ExitPictureInPictureSoon));
  92. }
  93. +#endif
  94. void PictureInPictureWindowManager::CreateOcclusionTrackerIfNecessary() {
  95. if (occlusion_tracker_) {
  96. diff --git a/chrome/browser/picture_in_picture/picture_in_picture_window_manager.h b/chrome/browser/picture_in_picture/picture_in_picture_window_manager.h
  97. index 5b3deb74d3e1cceebfd86a8f4bacf81a10967ade..8ca4f8d8fd6353177ae203e3c4c0810a11640b7c 100644
  98. --- a/chrome/browser/picture_in_picture/picture_in_picture_window_manager.h
  99. +++ b/chrome/browser/picture_in_picture/picture_in_picture_window_manager.h
  100. @@ -11,6 +11,7 @@
  101. #include "base/memory/singleton.h"
  102. #include "base/observer_list.h"
  103. #include "base/observer_list_types.h"
  104. +#include "build/branding_buildflags.h"
  105. #include "build/build_config.h"
  106. #include "third_party/abseil-cpp/absl/types/optional.h"
  107. #include "third_party/blink/public/mojom/picture_in_picture_window_options/picture_in_picture_window_options.mojom.h"
  108. @@ -32,7 +33,9 @@ class Display;
  109. } // namespace display
  110. #if !BUILDFLAG(IS_ANDROID)
  111. +#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
  112. class AutoPipSettingHelper;
  113. +#endif
  114. class PictureInPictureOcclusionTracker;
  115. namespace views {
  116. @@ -179,10 +182,11 @@ class PictureInPictureWindowManager {
  117. const gfx::Rect& browser_view_overridden_bounds,
  118. views::View* anchor_view,
  119. views::BubbleBorder::Arrow arrow);
  120. -
  121. +#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
  122. AutoPipSettingHelper* get_setting_helper_for_testing() {
  123. return auto_pip_setting_helper_.get();
  124. }
  125. +#endif
  126. // Returns the PictureInPictureOcclusionTracker, which can inform observers
  127. // when a widget has been occluded by a video or document picture-in-picture
  128. @@ -238,8 +242,10 @@ class PictureInPictureWindowManager {
  129. static void ExitPictureInPictureSoon();
  130. #if !BUILDFLAG(IS_ANDROID)
  131. +#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
  132. // Create the settings helper if this is auto-pip and we don't have one.
  133. void CreateAutoPipSettingHelperIfNeeded();
  134. +#endif
  135. // Creates the `occlusion_tracker_` if it does not already exist and should
  136. // exist.
  137. @@ -256,7 +262,9 @@ class PictureInPictureWindowManager {
  138. #if !BUILDFLAG(IS_ANDROID)
  139. std::unique_ptr<DocumentWebContentsObserver> document_web_contents_observer_;
  140. +#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
  141. std::unique_ptr<AutoPipSettingHelper> auto_pip_setting_helper_;
  142. +#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
  143. std::unique_ptr<PictureInPictureOcclusionTracker> occlusion_tracker_;
  144. #endif //! BUILDFLAG(IS_ANDROID)
  145. diff --git a/chrome/browser/ui/views/overlay/video_overlay_window_views.cc b/chrome/browser/ui/views/overlay/video_overlay_window_views.cc
  146. index b3419d2bb60ab0488fc0413843c33b5a926fee09..059754d92621ada9100e739ee6b5db01ae9ea75f 100644
  147. --- a/chrome/browser/ui/views/overlay/video_overlay_window_views.cc
  148. +++ b/chrome/browser/ui/views/overlay/video_overlay_window_views.cc
  149. @@ -314,11 +314,13 @@ std::unique_ptr<VideoOverlayWindowViews> VideoOverlayWindowViews::Create(
  150. }
  151. #endif // BUILDFLAG(IS_WIN)
  152. +#if 0
  153. PictureInPictureOcclusionTracker* tracker =
  154. PictureInPictureWindowManager::GetInstance()->GetOcclusionTracker();
  155. if (tracker) {
  156. tracker->OnPictureInPictureWidgetOpened(overlay_window.get());
  157. }
  158. +#endif
  159. return overlay_window;
  160. }