fix_adapt_exclusive_access_for_electron_needs.patch 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 31f9403bf89095f8694aecc855c24d81be9261e7..1e82eaa7b45e1a1b04b132d752ae8252ee55ad1f 100644
  17. --- a/chrome/browser/ui/exclusive_access/fullscreen_controller.cc
  18. +++ b/chrome/browser/ui/exclusive_access/fullscreen_controller.cc
  19. @@ -17,12 +17,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/navigation_details.h"
  35. #include "content/public/browser/navigation_entry.h"
  36. @@ -181,6 +185,7 @@ void FullscreenController::EnterFullscreenModeForTab(
  37. return;
  38. }
  39. +#if 0
  40. if (base::FeatureList::IsEnabled(
  41. blink::features::kWindowPlacementFullscreenCompanionWindow)) {
  42. if (!popunder_preventer_)
  43. @@ -188,6 +193,7 @@ void FullscreenController::EnterFullscreenModeForTab(
  44. else
  45. popunder_preventer_->WillActivateWebContents(web_contents);
  46. }
  47. +#endif
  48. // Keep the current state. |SetTabWithExclusiveAccess| may change the return
  49. // value of |IsWindowFullscreenForTabOrPending|.
  50. @@ -237,11 +243,13 @@ void FullscreenController::EnterFullscreenModeForTab(
  51. }
  52. void FullscreenController::ExitFullscreenModeForTab(WebContents* web_contents) {
  53. +#if 0
  54. // Reset the popunder preventer after the window exits content fullscreen.
  55. // This activates any popup windows that were created while fullscreen.
  56. base::ScopedClosureRunner reset_popunder_preventer(
  57. base::BindOnce(&std::unique_ptr<PopunderPreventer>::reset,
  58. base::Unretained(&popunder_preventer_), nullptr));
  59. +#endif
  60. if (MaybeToggleFullscreenWithinTab(web_contents, false)) {
  61. // During tab capture of fullscreen-within-tab views, the browser window
  62. @@ -299,11 +307,13 @@ void FullscreenController::ExitFullscreenModeForTab(WebContents* web_contents) {
  63. void FullscreenController::FullscreenTabOpeningPopup(
  64. content::WebContents* opener,
  65. content::WebContents* popup) {
  66. +#if 0
  67. DCHECK(base::FeatureList::IsEnabled(
  68. blink::features::kWindowPlacementFullscreenCompanionWindow));
  69. DCHECK_EQ(exclusive_access_tab(), opener);
  70. DCHECK(popunder_preventer_);
  71. popunder_preventer_->AddPotentialPopunder(popup);
  72. +#endif
  73. }
  74. void FullscreenController::OnTabDeactivated(
  75. @@ -472,18 +482,17 @@ void FullscreenController::EnterFullscreenModeInternal(
  76. // Do not enter fullscreen mode if disallowed by pref. This prevents the user
  77. // from manually entering fullscreen mode and also disables kiosk mode on
  78. // desktop platforms.
  79. - if (!exclusive_access_manager()
  80. - ->context()
  81. - ->GetProfile()
  82. - ->GetPrefs()
  83. - ->GetBoolean(prefs::kFullscreenAllowed)) {
  84. + auto* profile = exclusive_access_manager()->context()->GetProfile();
  85. + if (!profile || !profile->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed))
  86. return;
  87. - }
  88. #endif
  89. started_fullscreen_transition_ = true;
  90. toggled_into_fullscreen_ = true;
  91. +#if 0
  92. bool entering_tab_fullscreen = option == TAB && !tab_fullscreen_;
  93. +#endif
  94. GURL url;
  95. +#if 0
  96. if (option == TAB) {
  97. url = GetRequestingOrigin();
  98. tab_fullscreen_ = true;
  99. @@ -516,6 +525,7 @@ void FullscreenController::EnterFullscreenModeInternal(
  100. if (!extension_caused_fullscreen_.is_empty())
  101. url = extension_caused_fullscreen_;
  102. }
  103. +#endif
  104. if (option == BROWSER)
  105. base::RecordAction(base::UserMetricsAction("ToggleFullscreen"));
  106. @@ -543,12 +553,12 @@ void FullscreenController::ExitFullscreenModeInternal() {
  107. RecordExitingUMA();
  108. toggled_into_fullscreen_ = false;
  109. started_fullscreen_transition_ = true;
  110. -#if BUILDFLAG(IS_MAC)
  111. - // Mac windows report a state change instantly, and so we must also clear
  112. +
  113. + // Electron native windows report a state change instantly, and so we must also clear
  114. // state_prior_to_tab_fullscreen_ to match them else other logic using
  115. // state_prior_to_tab_fullscreen_ will be incorrect.
  116. NotifyTabExclusiveAccessLost();
  117. -#endif
  118. +
  119. exclusive_access_manager()->context()->ExitFullscreen();
  120. extension_caused_fullscreen_ = GURL();
  121. diff --git a/chrome/browser/ui/exclusive_access/fullscreen_controller.h b/chrome/browser/ui/exclusive_access/fullscreen_controller.h
  122. index a31c0b1a17d4cda765a4511923686b7f44d10e81..0b0a015f0500432273bf0e7f7231987cdd11b440 100644
  123. --- a/chrome/browser/ui/exclusive_access/fullscreen_controller.h
  124. +++ b/chrome/browser/ui/exclusive_access/fullscreen_controller.h
  125. @@ -247,10 +247,12 @@ class FullscreenController : public ExclusiveAccessControllerBase {
  126. // Used in testing to set the state to tab fullscreen.
  127. bool is_tab_fullscreen_for_testing_ = false;
  128. +#if 0
  129. // Tracks related popups that lost activation or were shown without activation
  130. // during content fullscreen sessions. This also activates the popups when
  131. // fullscreen exits, to prevent sites from creating persisent popunders.
  132. std::unique_ptr<PopunderPreventer> popunder_preventer_;
  133. +#endif
  134. base::ObserverList<FullscreenObserver> observer_list_;