fix_adapt_exclusive_access_for_electron_needs.patch 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Shelley Vohr <[email protected]>
  3. Date: Mon, 25 Oct 2021 21:45:57 +0200
  4. Subject: fix: adapt exclusive_access for electron needs
  5. This patch is necessary in order to properly enable
  6. navigator.keyboard.{(un)?lock}() functionality. We don't have a concept
  7. of PermissionManager nor of a Profile, so this would not affect usage of
  8. the API.
  9. We also need to ensure that NotifyExclusiveTabAccessLost is called
  10. on all platforms in FullscreenController::ExitFullscreenModeInternal()
  11. and not just macOS, since Electron's native window impls report state
  12. change fairly instantly as well, and so pressing escape won't work on
  13. Linux or Windows to un-fullscreen in some circumstances without this
  14. change.
  15. diff --git a/chrome/browser/ui/exclusive_access/fullscreen_controller.cc b/chrome/browser/ui/exclusive_access/fullscreen_controller.cc
  16. index 81d7bb03c97ce4cf4744e7b89f3321132c21ae4e..5ffddaa3a0d4b8b25e8ef03d4eb431f8ea248a9a 100644
  17. --- a/chrome/browser/ui/exclusive_access/fullscreen_controller.cc
  18. +++ b/chrome/browser/ui/exclusive_access/fullscreen_controller.cc
  19. @@ -16,12 +16,16 @@
  20. #include "build/build_config.h"
  21. #include "chrome/browser/app_mode/app_mode_utils.h"
  22. #include "chrome/browser/profiles/profile.h"
  23. +#if 0
  24. #include "chrome/browser/ui/blocked_content/popunder_preventer.h"
  25. +#endif
  26. #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h"
  27. #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h"
  28. #include "chrome/browser/ui/exclusive_access/fullscreen_within_tab_helper.h"
  29. +#if 0
  30. #include "chrome/browser/ui/status_bubble.h"
  31. #include "chrome/browser/ui/tabs/tab_strip_model.h"
  32. +#endif
  33. #include "chrome/common/chrome_switches.h"
  34. #include "content/public/browser/fullscreen_types.h"
  35. #include "content/public/browser/navigation_details.h"
  36. @@ -180,10 +184,12 @@ void FullscreenController::EnterFullscreenModeForTab(
  37. return;
  38. }
  39. +#if 0
  40. if (!popunder_preventer_)
  41. popunder_preventer_ = std::make_unique<PopunderPreventer>(web_contents);
  42. else
  43. popunder_preventer_->WillActivateWebContents(web_contents);
  44. +#endif
  45. // Keep the current state. |SetTabWithExclusiveAccess| may change the return
  46. // value of |IsWindowFullscreenForTabOrPending|.
  47. @@ -240,11 +246,13 @@ void FullscreenController::EnterFullscreenModeForTab(
  48. }
  49. void FullscreenController::ExitFullscreenModeForTab(WebContents* web_contents) {
  50. +#if 0
  51. // Reset the popunder preventer after the window exits content fullscreen.
  52. // This activates any popup windows that were created while fullscreen.
  53. base::ScopedClosureRunner reset_popunder_preventer(
  54. base::BindOnce(&std::unique_ptr<PopunderPreventer>::reset,
  55. base::Unretained(&popunder_preventer_), nullptr));
  56. +#endif
  57. if (MaybeToggleFullscreenWithinTab(web_contents, false)) {
  58. // During tab capture of fullscreen-within-tab views, the browser window
  59. @@ -302,12 +310,14 @@ void FullscreenController::ExitFullscreenModeForTab(WebContents* web_contents) {
  60. void FullscreenController::FullscreenTabOpeningPopup(
  61. content::WebContents* opener,
  62. content::WebContents* popup) {
  63. +#if 0
  64. if (!popunder_preventer_) {
  65. return;
  66. }
  67. DCHECK_EQ(exclusive_access_tab(), opener);
  68. popunder_preventer_->AddPotentialPopunder(popup);
  69. +#endif
  70. }
  71. void FullscreenController::OnTabDeactivated(
  72. @@ -488,18 +498,17 @@ void FullscreenController::EnterFullscreenModeInternal(
  73. // Do not enter fullscreen mode if disallowed by pref. This prevents the user
  74. // from manually entering fullscreen mode and also disables kiosk mode on
  75. // desktop platforms.
  76. - if (!exclusive_access_manager()
  77. - ->context()
  78. - ->GetProfile()
  79. - ->GetPrefs()
  80. - ->GetBoolean(prefs::kFullscreenAllowed)) {
  81. + auto* profile = exclusive_access_manager()->context()->GetProfile();
  82. + if (!profile || !profile->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed))
  83. return;
  84. - }
  85. #endif
  86. started_fullscreen_transition_ = true;
  87. toggled_into_fullscreen_ = true;
  88. +#if 0
  89. bool entering_tab_fullscreen = option == TAB && !tab_fullscreen_;
  90. +#endif
  91. GURL url;
  92. +#if 0
  93. if (option == TAB) {
  94. url = GetRequestingOrigin();
  95. tab_fullscreen_ = true;
  96. @@ -532,6 +541,7 @@ void FullscreenController::EnterFullscreenModeInternal(
  97. if (!extension_caused_fullscreen_.is_empty())
  98. url = extension_caused_fullscreen_;
  99. }
  100. +#endif
  101. fullscreen_start_time_ = base::TimeTicks::Now();
  102. if (option == BROWSER)
  103. @@ -551,6 +561,7 @@ void FullscreenController::ExitFullscreenModeInternal() {
  104. if (chrome::IsRunningInAppMode())
  105. return;
  106. +#if 0
  107. // `fullscreen_start_time_` is null if a fullscreen tab moves to a new window.
  108. if (fullscreen_start_time_ && exclusive_access_tab()) {
  109. ukm::SourceId source_id =
  110. @@ -562,15 +573,16 @@ void FullscreenController::ExitFullscreenModeInternal() {
  111. .Record(ukm::UkmRecorder::Get());
  112. fullscreen_start_time_.reset();
  113. }
  114. +#endif
  115. toggled_into_fullscreen_ = false;
  116. started_fullscreen_transition_ = true;
  117. -#if BUILDFLAG(IS_MAC)
  118. - // Mac windows report a state change instantly, and so we must also clear
  119. +
  120. + // Electron native windows report a state change instantly, and so we must also clear
  121. // state_prior_to_tab_fullscreen_ to match them else other logic using
  122. // state_prior_to_tab_fullscreen_ will be incorrect.
  123. NotifyTabExclusiveAccessLost();
  124. -#endif
  125. +
  126. exclusive_access_manager()->context()->ExitFullscreen();
  127. extension_caused_fullscreen_ = GURL();
  128. diff --git a/chrome/browser/ui/exclusive_access/fullscreen_controller.h b/chrome/browser/ui/exclusive_access/fullscreen_controller.h
  129. index 439f0aaceb443e650c82951bd1dffc937d58f2a2..781e02163bf11ac40bd82081465d08f5bb4be448 100644
  130. --- a/chrome/browser/ui/exclusive_access/fullscreen_controller.h
  131. +++ b/chrome/browser/ui/exclusive_access/fullscreen_controller.h
  132. @@ -248,10 +248,12 @@ class FullscreenController : public ExclusiveAccessControllerBase {
  133. // Used in testing to set the state to tab fullscreen.
  134. bool is_tab_fullscreen_for_testing_ = false;
  135. +#if 0
  136. // Tracks related popups that lost activation or were shown without activation
  137. // during content fullscreen sessions. This also activates the popups when
  138. // fullscreen exits, to prevent sites from creating persistent popunders.
  139. std::unique_ptr<PopunderPreventer> popunder_preventer_;
  140. +#endif
  141. base::ObserverList<FullscreenObserver> observer_list_;