fix_adapt_exclusive_access_for_electron_needs.patch 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 176f02f0abb4220564caa1d794faabc5b22bd8bc..4b08918cef83a84076e452b41302588efdfb0619 100644
  17. --- a/chrome/browser/ui/exclusive_access/fullscreen_controller.cc
  18. +++ b/chrome/browser/ui/exclusive_access/fullscreen_controller.cc
  19. @@ -21,12 +21,16 @@
  20. #include "chrome/browser/history/history_service_factory.h"
  21. #include "chrome/browser/profiles/profile.h"
  22. #include "chrome/browser/safe_browsing/safe_browsing_service.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. @@ -259,10 +263,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. @@ -374,12 +380,14 @@ void FullscreenController::ExitFullscreenModeForTab(WebContents* web_contents) {
  48. void FullscreenController::FullscreenTabOpeningPopup(
  49. content::WebContents* opener,
  50. content::WebContents* popup) {
  51. +#if 0
  52. if (!popunder_preventer_) {
  53. return;
  54. }
  55. DCHECK_EQ(exclusive_access_tab(), opener);
  56. popunder_preventer_->AddPotentialPopunder(popup);
  57. +#endif
  58. }
  59. void FullscreenController::OnTabDeactivated(
  60. @@ -465,10 +473,12 @@ void FullscreenController::FullscreenTransitionCompleted() {
  61. #endif // DCHECK_IS_ON()
  62. tab_fullscreen_target_display_id_ = display::kInvalidDisplayId;
  63. started_fullscreen_transition_ = false;
  64. +#if 0
  65. if (!IsTabFullscreen()) {
  66. // Activate any popup windows created while content fullscreen, after exit.
  67. popunder_preventer_.reset();
  68. }
  69. +#endif
  70. }
  71. void FullscreenController::RunOrDeferUntilTransitionIsComplete(
  72. @@ -576,18 +586,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. @@ -620,6 +629,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. @@ -640,6 +650,7 @@ void FullscreenController::ExitFullscreenModeInternal() {
  104. return;
  105. }
  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. @@ -651,15 +662,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. exclusive_access_manager()->UpdateBubble(base::NullCallback());
  129. @@ -721,8 +733,12 @@ GURL FullscreenController::GetEmbeddingOrigin() const {
  130. void FullscreenController::RecordMetricsOnFullscreenApiRequested(
  131. content::RenderFrameHost* requesting_frame) {
  132. history::HistoryService* service =
  133. + #if 0
  134. HistoryServiceFactory::GetForProfileWithoutCreating(
  135. exclusive_access_manager()->context()->GetProfile());
  136. + #else
  137. + nullptr;
  138. + #endif
  139. if (service) {
  140. // Check if the origin has been visited more than a day ago and whether it's
  141. // on an allowlist, then record those bits of information in a metric.
  142. diff --git a/chrome/browser/ui/exclusive_access/fullscreen_controller.h b/chrome/browser/ui/exclusive_access/fullscreen_controller.h
  143. index 97003f03b69c9435ee1f79e42476003b63b8a66d..859b9d21985c14c9e9f95c65edfbd89e13ef16e7 100644
  144. --- a/chrome/browser/ui/exclusive_access/fullscreen_controller.h
  145. +++ b/chrome/browser/ui/exclusive_access/fullscreen_controller.h
  146. @@ -250,10 +250,12 @@ class FullscreenController : public ExclusiveAccessControllerBase {
  147. // Used in testing to set the state to tab fullscreen.
  148. bool is_tab_fullscreen_for_testing_ = false;
  149. +#if 0
  150. // Tracks related popups that lost activation or were shown without activation
  151. // during content fullscreen sessions. This also activates the popups when
  152. // fullscreen exits, to prevent sites from creating persistent popunders.
  153. std::unique_ptr<PopunderPreventer> popunder_preventer_;
  154. +#endif
  155. base::ObserverList<FullscreenObserver> observer_list_;