From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Shelley Vohr <shelley.vohr@gmail.com>
Date: Mon, 25 Oct 2021 21:45:57 +0200
Subject: fix: patch out permissions checks in exclusive_access

This patch is necessary in order to properly enable
navigator.keyboard.{(un)?lock}() functionality. We don't have a concept
of PermissionManager nor of a Profile, so this would not affect usage of
the API.

We might consider potentially using our own permissions handler,
but it's not strictly necessary for this API to work to spec.

Profile check has been upstreamed at https://chromium-review.googlesource.com/c/chromium/src/+/3247196

diff --git a/chrome/browser/ui/exclusive_access/fullscreen_controller.cc b/chrome/browser/ui/exclusive_access/fullscreen_controller.cc
index 41cd193087f8d4f246993e96da96ea0523ab50ed..96cd17afad81037ce94ca3ea3583ebbbdd7f157b 100644
--- a/chrome/browser/ui/exclusive_access/fullscreen_controller.cc
+++ b/chrome/browser/ui/exclusive_access/fullscreen_controller.cc
@@ -16,12 +16,16 @@
 #include "build/build_config.h"
 #include "chrome/browser/app_mode/app_mode_utils.h"
 #include "chrome/browser/profiles/profile.h"
+#if 0
 #include "chrome/browser/ui/blocked_content/popunder_preventer.h"
+#endif
 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h"
 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h"
 #include "chrome/browser/ui/exclusive_access/fullscreen_within_tab_helper.h"
+#if 0
 #include "chrome/browser/ui/status_bubble.h"
 #include "chrome/browser/ui/tabs/tab_strip_model.h"
+#endif
 #include "chrome/common/chrome_switches.h"
 #include "content/public/browser/navigation_details.h"
 #include "content/public/browser/navigation_entry.h"
@@ -159,6 +163,7 @@ void FullscreenController::EnterFullscreenModeForTab(
     return;
   }
 
+#if 0
   if (base::FeatureList::IsEnabled(
           blink::features::kWindowPlacementFullscreenCompanionWindow)) {
     if (!popunder_preventer_)
@@ -166,6 +171,7 @@ void FullscreenController::EnterFullscreenModeForTab(
     else
       popunder_preventer_->WillActivateWebContents(web_contents);
   }
+#endif
 
   // Keep the current state. |SetTabWithExclusiveAccess| may change the return
   // value of |IsWindowFullscreenForTabOrPending|.
@@ -218,7 +224,9 @@ void FullscreenController::EnterFullscreenModeForTab(
 }
 
 void FullscreenController::ExitFullscreenModeForTab(WebContents* web_contents) {
+#if 0
   popunder_preventer_.reset();
+#endif
 
   if (MaybeToggleFullscreenWithinTab(web_contents, false)) {
     // During tab capture of fullscreen-within-tab views, the browser window
@@ -263,11 +271,13 @@ void FullscreenController::ExitFullscreenModeForTab(WebContents* web_contents) {
 void FullscreenController::FullscreenTabOpeningPopup(
     content::WebContents* opener,
     content::WebContents* popup) {
+#if 0
   DCHECK(base::FeatureList::IsEnabled(
       blink::features::kWindowPlacementFullscreenCompanionWindow));
   DCHECK_EQ(exclusive_access_tab(), opener);
   DCHECK(popunder_preventer_);
   popunder_preventer_->AddPotentialPopunder(popup);
+#endif
 }
 
 void FullscreenController::OnTabDeactivated(
@@ -417,13 +427,9 @@ void FullscreenController::EnterFullscreenModeInternal(
   // Do not enter fullscreen mode if disallowed by pref. This prevents the user
   // from manually entering fullscreen mode and also disables kiosk mode on
   // desktop platforms.
-  if (!exclusive_access_manager()
-           ->context()
-           ->GetProfile()
-           ->GetPrefs()
-           ->GetBoolean(prefs::kFullscreenAllowed)) {
+  auto* profile = exclusive_access_manager()->context()->GetProfile();
+  if (!profile || !profile->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed))
     return;
-  }
 #endif
 
   toggled_into_fullscreen_ = true;
@@ -436,6 +442,7 @@ void FullscreenController::EnterFullscreenModeInternal(
       url = extension_caused_fullscreen_;
   }
 
+#if 0
   if (display_id != display::kInvalidDisplayId) {
     // Check, but do not prompt, for permission to request a specific screen.
     // Sites generally need permission to get the display id in the first place.
@@ -449,6 +456,7 @@ void FullscreenController::EnterFullscreenModeInternal(
       display_id = display::kInvalidDisplayId;
     }
   }
+#endif
 
   if (option == BROWSER)
     base::RecordAction(base::UserMetricsAction("ToggleFullscreen"));
diff --git a/chrome/browser/ui/exclusive_access/fullscreen_controller.h b/chrome/browser/ui/exclusive_access/fullscreen_controller.h
index 7bd40f52ef5f6b04a7ea114ec4d18c8a98ec6d42..fb04fed5cc1e2e255c9e67c180fababe1fbb3fe0 100644
--- a/chrome/browser/ui/exclusive_access/fullscreen_controller.h
+++ b/chrome/browser/ui/exclusive_access/fullscreen_controller.h
@@ -222,10 +222,12 @@ class FullscreenController : public ExclusiveAccessControllerBase {
   // Used in testing to set the state to tab fullscreen.
   bool is_tab_fullscreen_for_testing_ = false;
 
+#if 0
   // Tracks related popups that lost activation or were shown without activation
   // during content fullscreen sessions. This also activates the popups when
   // fullscreen exits, to prevent sites from creating persisent popunders.
   std::unique_ptr<PopunderPreventer> popunder_preventer_;
+#endif
 
   base::ObserverList<FullscreenObserver> observer_list_;
 
