fix_adapt_exclusive_access_for_electron_needs.patch 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 3d9ccff4a6a70e97d90f461a92c204af9a8e0a4f..e2a5a1751a6496a0ed7854737056564c2046d436 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. @@ -177,10 +181,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. @@ -237,11 +243,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. @@ -299,12 +307,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. DCHECK_EQ(exclusive_access_tab(), opener);
  66. popunder_preventer_->AddPotentialPopunder(popup);
  67. } else {
  68. DCHECK(IsFullscreenWithinTab(opener));
  69. }
  70. +#endif
  71. }
  72. void FullscreenController::OnTabDeactivated(
  73. @@ -474,18 +484,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. @@ -518,6 +527,7 @@ void FullscreenController::EnterFullscreenModeInternal(
  98. if (!extension_caused_fullscreen_.is_empty())
  99. url = extension_caused_fullscreen_;
  100. }
  101. +#endif
  102. if (option == BROWSER)
  103. base::RecordAction(base::UserMetricsAction("ToggleFullscreen"));
  104. @@ -538,12 +548,12 @@ void FullscreenController::ExitFullscreenModeInternal() {
  105. toggled_into_fullscreen_ = false;
  106. started_fullscreen_transition_ = true;
  107. -#if BUILDFLAG(IS_MAC)
  108. - // Mac windows report a state change instantly, and so we must also clear
  109. +
  110. + // Electron native windows report a state change instantly, and so we must also clear
  111. // state_prior_to_tab_fullscreen_ to match them else other logic using
  112. // state_prior_to_tab_fullscreen_ will be incorrect.
  113. NotifyTabExclusiveAccessLost();
  114. -#endif
  115. +
  116. exclusive_access_manager()->context()->ExitFullscreen();
  117. extension_caused_fullscreen_ = GURL();
  118. diff --git a/chrome/browser/ui/exclusive_access/fullscreen_controller.h b/chrome/browser/ui/exclusive_access/fullscreen_controller.h
  119. index 8e78c52e83e6fc96e97d45970cff12b062d63ad8..6c9c4b439101ca4870c1d682e1b899fb82f836a8 100644
  120. --- a/chrome/browser/ui/exclusive_access/fullscreen_controller.h
  121. +++ b/chrome/browser/ui/exclusive_access/fullscreen_controller.h
  122. @@ -243,10 +243,12 @@ class FullscreenController : public ExclusiveAccessControllerBase {
  123. // Used in testing to set the state to tab fullscreen.
  124. bool is_tab_fullscreen_for_testing_ = false;
  125. +#if 0
  126. // Tracks related popups that lost activation or were shown without activation
  127. // during content fullscreen sessions. This also activates the popups when
  128. // fullscreen exits, to prevent sites from creating persisent popunders.
  129. std::unique_ptr<PopunderPreventer> popunder_preventer_;
  130. +#endif
  131. base::ObserverList<FullscreenObserver> observer_list_;