fix_adapt_exclusive_access_for_electron_needs.patch 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 458029244ad9db7beace040778117d82d90f4bea..66202201b11de10bf2d781a52640a81f25d04780 100644
  17. --- a/chrome/browser/ui/exclusive_access/fullscreen_controller.cc
  18. +++ b/chrome/browser/ui/exclusive_access/fullscreen_controller.cc
  19. @@ -20,12 +20,16 @@
  20. #include "chrome/browser/browser_process.h"
  21. #include "chrome/browser/history/history_service_factory.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 "components/history/core/browser/history_service.h"
  35. #include "components/history/core/browser/history_types.h"
  36. @@ -271,11 +275,13 @@ 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. }
  45. +#endif
  46. // Keep the current state. |SetTabWithExclusiveAccess| may change the return
  47. // value of |IsWindowFullscreenForTabOrPending|.
  48. @@ -389,12 +395,14 @@ void FullscreenController::ExitFullscreenModeForTab(WebContents* web_contents) {
  49. void FullscreenController::FullscreenTabOpeningPopup(
  50. content::WebContents* opener,
  51. content::WebContents* popup) {
  52. +#if 0
  53. if (!popunder_preventer_) {
  54. return;
  55. }
  56. DCHECK_EQ(exclusive_access_tab(), opener);
  57. popunder_preventer_->AddPotentialPopunder(popup);
  58. +#endif
  59. }
  60. void FullscreenController::OnTabDeactivated(
  61. @@ -484,10 +492,12 @@ void FullscreenController::FullscreenTransitionCompleted() {
  62. #endif // DCHECK_IS_ON()
  63. tab_fullscreen_target_display_id_ = display::kInvalidDisplayId;
  64. started_fullscreen_transition_ = false;
  65. +#if 0
  66. if (!IsTabFullscreen()) {
  67. // Activate any popup windows created while content fullscreen, after exit.
  68. popunder_preventer_.reset();
  69. }
  70. +#endif
  71. }
  72. void FullscreenController::RunOrDeferUntilTransitionIsComplete(
  73. @@ -612,18 +622,17 @@ void FullscreenController::EnterFullscreenModeInternal(
  74. // Do not enter fullscreen mode if disallowed by pref. This prevents the user
  75. // from manually entering fullscreen mode and also disables kiosk mode on
  76. // desktop platforms.
  77. - if (!exclusive_access_manager()
  78. - ->context()
  79. - ->GetProfile()
  80. - ->GetPrefs()
  81. - ->GetBoolean(prefs::kFullscreenAllowed)) {
  82. + auto* profile = exclusive_access_manager()->context()->GetProfile();
  83. + if (!profile || !profile->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed))
  84. return;
  85. - }
  86. #endif
  87. started_fullscreen_transition_ = true;
  88. toggled_into_fullscreen_ = true;
  89. +#if 0
  90. bool entering_tab_fullscreen = option == TAB && !tab_fullscreen_;
  91. +#endif
  92. GURL url;
  93. +#if 0
  94. if (option == TAB) {
  95. url = GetRequestingOrigin();
  96. tab_fullscreen_ = true;
  97. @@ -658,6 +667,7 @@ void FullscreenController::EnterFullscreenModeInternal(
  98. url = extension_caused_fullscreen_;
  99. }
  100. }
  101. +#endif
  102. fullscreen_start_time_ = base::TimeTicks::Now();
  103. if (option == BROWSER) {
  104. @@ -679,6 +689,7 @@ void FullscreenController::ExitFullscreenModeInternal() {
  105. return;
  106. }
  107. +#if 0
  108. // `fullscreen_start_time_` is null if a fullscreen tab moves to a new window.
  109. if (fullscreen_start_time_ && exclusive_access_tab()) {
  110. ukm::SourceId source_id =
  111. @@ -690,15 +701,16 @@ void FullscreenController::ExitFullscreenModeInternal() {
  112. .Record(ukm::UkmRecorder::Get());
  113. fullscreen_start_time_.reset();
  114. }
  115. +#endif
  116. toggled_into_fullscreen_ = false;
  117. started_fullscreen_transition_ = true;
  118. -#if BUILDFLAG(IS_MAC)
  119. - // Mac windows report a state change instantly, and so we must also clear
  120. +
  121. + // Electron native windows report a state change instantly, and so we must also clear
  122. // state_prior_to_tab_fullscreen_ to match them else other logic using
  123. // state_prior_to_tab_fullscreen_ will be incorrect.
  124. NotifyTabExclusiveAccessLost();
  125. -#endif
  126. +
  127. exclusive_access_manager()->context()->ExitFullscreen();
  128. extension_caused_fullscreen_ = GURL();
  129. exclusive_access_manager()->UpdateBubble(base::NullCallback());
  130. @@ -762,8 +774,12 @@ GURL FullscreenController::GetEmbeddingOrigin() const {
  131. void FullscreenController::RecordMetricsOnFullscreenApiRequested(
  132. content::RenderFrameHost* requesting_frame) {
  133. history::HistoryService* service =
  134. + #if 0
  135. HistoryServiceFactory::GetForProfileWithoutCreating(
  136. exclusive_access_manager()->context()->GetProfile());
  137. + #else
  138. + nullptr;
  139. + #endif
  140. if (service) {
  141. // Check if the origin has been visited more than a day ago and whether it's
  142. // on an allowlist, then record those bits of information in a metric.
  143. diff --git a/chrome/browser/ui/exclusive_access/fullscreen_controller.h b/chrome/browser/ui/exclusive_access/fullscreen_controller.h
  144. index 7fdf883310b13e3334ba007580a1a4287d49d592..d7c2bdaa08cae1645bf52f1d9b9d84b1cdb78c66 100644
  145. --- a/chrome/browser/ui/exclusive_access/fullscreen_controller.h
  146. +++ b/chrome/browser/ui/exclusive_access/fullscreen_controller.h
  147. @@ -250,10 +250,12 @@ class FullscreenController : public ExclusiveAccessControllerBase {
  148. // Used in testing to set the state to tab fullscreen.
  149. bool is_tab_fullscreen_for_testing_ = false;
  150. +#if 0
  151. // Tracks related popups that lost activation or were shown without activation
  152. // during content fullscreen sessions. This also activates the popups when
  153. // fullscreen exits, to prevent sites from creating persistent popunders.
  154. std::unique_ptr<PopunderPreventer> popunder_preventer_;
  155. +#endif
  156. base::ObserverList<FullscreenObserver> observer_list_;