1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_EXCLUSIVE_ACCESS_EXCLUSIVE_ACCESS_MANAGER_H_
#define CHROME_BROWSER_UI_EXCLUSIVE_ACCESS_EXCLUSIVE_ACCESS_MANAGER_H_
#include "base/memory/raw_ptr.h"
#include "chrome/browser/ui/exclusive_access/exclusive_access_bubble_type.h"
#include "chrome/browser/ui/exclusive_access/exclusive_access_permission_manager.h"
#include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
#include "chrome/browser/ui/exclusive_access/keyboard_lock_controller.h"
#include "chrome/browser/ui/exclusive_access/pointer_lock_controller.h"
#include "components/input/native_web_keyboard_event.h"
#include "url/origin.h"
class ExclusiveAccessContext;
namespace content {
class WebContents;
} // namespace content
// This class combines the different exclusive access modes (like fullscreen and
// pointer lock) which are each handled by respective controller. It also
// updates the exit bubble to reflect the combined state.
class ExclusiveAccessManager {
public:
explicit ExclusiveAccessManager(
ExclusiveAccessContext* exclusive_access_context);
ExclusiveAccessManager(const ExclusiveAccessManager&) = delete;
ExclusiveAccessManager& operator=(const ExclusiveAccessManager&) = delete;
~ExclusiveAccessManager();
FullscreenController* fullscreen_controller() {
return &fullscreen_controller_;
}
KeyboardLockController* keyboard_lock_controller() {
return &keyboard_lock_controller_;
}
PointerLockController* pointer_lock_controller() {
return &pointer_lock_controller_;
}
ExclusiveAccessContext* context() const { return exclusive_access_context_; }
ExclusiveAccessBubbleType GetExclusiveAccessExitBubbleType() const;
// Asks the ExclusiveAccessContext to show, hide, or update the bubble.
// `first_hide_callback` is called when the bubble is stifled or first hidden.
// `force_update` will reshow the bubble even if there are no content changes.
void UpdateBubble(ExclusiveAccessBubbleHideCallback first_hide_callback,
bool force_update = false);
url::Origin GetExclusiveAccessBubbleOrigin() const;
// Records the keyboard/pointer lock state in a histogram. These should be
// called when the user enters fullscreen through the Fullscreen API or the
// browesr UI, respectively.
void RecordLockStateOnEnteringApiFullscreen() const;
void RecordLockStateOnEnteringBrowserFullscreen() const;
// Callbacks ////////////////////////////////////////////////////////////////
// Called by Browser::TabDeactivated.
void OnTabDeactivated(content::WebContents* web_contents);
// Called by Browser::ActiveTabChanged.
void OnTabDetachedFromView(content::WebContents* web_contents);
// Called by Browser::TabClosingAt.
void OnTabClosing(content::WebContents* web_contents);
// Called by Browser::PreHandleKeyboardEvent.
bool HandleUserKeyEvent(const input::NativeWebKeyboardEvent& event);
// Called by Browser::ContentsMouseEvent.
void OnUserInput();
// Called by platform ExclusiveAccessExitBubble.
void ExitExclusiveAccess();
base::flat_set<raw_ptr<ExclusiveAccessControllerBase>>&
exclusive_access_controllers_for_test() {
return exclusive_access_controllers_;
}
ExclusiveAccessPermissionManager& permission_manager() {
return permission_manager_;
}
const base::OneShotTimer& esc_key_hold_timer_for_test() {
return esc_key_hold_timer_;
}
private:
void HandleUserHeldEscape();
void RecordLockStateOnEnteringFullscreen(const char histogram_name[]) const;
// The timer starts on Esc key down event and stops on Esc key up event. It
// invokes `HandleUserHeldEscape()` when the timer is fired.
base::OneShotTimer esc_key_hold_timer_;
// The timer starts and stops at the same time as `esc_key_hold_timer_` but is
// fired after a shorter delay.
base::OneShotTimer show_exit_bubble_timer_;
const raw_ptr<ExclusiveAccessContext> exclusive_access_context_;
FullscreenController fullscreen_controller_;
KeyboardLockController keyboard_lock_controller_;
PointerLockController pointer_lock_controller_;
base::flat_set<raw_ptr<ExclusiveAccessControllerBase>>
exclusive_access_controllers_;
ExclusiveAccessPermissionManager permission_manager_;
};
#endif // CHROME_BROWSER_UI_EXCLUSIVE_ACCESS_EXCLUSIVE_ACCESS_MANAGER_H_
|