Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / exclusive_access / exclusive_access_manager.cc
blob88dba13825ba954e3f51320903903e6f9ba0dca5
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h"
7 #include "base/command_line.h"
8 #include "chrome/browser/app_mode/app_mode_utils.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_window.h"
11 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h"
12 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
13 #include "chrome/browser/ui/exclusive_access/mouse_lock_controller.h"
14 #include "chrome/common/chrome_switches.h"
16 using content::WebContents;
18 ExclusiveAccessManager::ExclusiveAccessManager(
19 ExclusiveAccessContext* exclusive_access_context)
20 : exclusive_access_context_(exclusive_access_context),
21 fullscreen_controller_(this),
22 mouse_lock_controller_(this) {
25 ExclusiveAccessManager::~ExclusiveAccessManager() {
28 ExclusiveAccessBubbleType
29 ExclusiveAccessManager::GetExclusiveAccessExitBubbleType() const {
30 // In kiosk and exclusive app mode we always want to be fullscreen and do not
31 // want to show exit instructions for browser mode fullscreen.
32 bool app_mode = false;
33 #if !defined(OS_MACOSX) // App mode (kiosk) is not available on Mac yet.
34 app_mode = chrome::IsRunningInAppMode();
35 #endif
37 if (mouse_lock_controller_.IsMouseLockSilentlyAccepted() &&
38 (!fullscreen_controller_.IsWindowFullscreenForTabOrPending() ||
39 fullscreen_controller_.IsUserAcceptedFullscreen()))
40 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE;
42 if (!fullscreen_controller_.IsWindowFullscreenForTabOrPending()) {
43 if (mouse_lock_controller_.IsMouseLocked())
44 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_EXIT_INSTRUCTION;
45 if (mouse_lock_controller_.IsMouseLockRequested())
46 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_BUTTONS;
47 if (fullscreen_controller_.IsExtensionFullscreenOrPending())
48 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION;
49 if (fullscreen_controller_.IsControllerInitiatedFullscreen() && !app_mode)
50 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION;
51 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE;
54 if (fullscreen_controller_.IsUserAcceptedFullscreen()) {
55 if (fullscreen_controller_.IsPrivilegedFullscreenForTab())
56 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE;
57 if (mouse_lock_controller_.IsMouseLocked())
58 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION;
59 if (mouse_lock_controller_.IsMouseLockRequested())
60 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_BUTTONS;
61 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_EXIT_INSTRUCTION;
64 if (mouse_lock_controller_.IsMouseLockRequested())
65 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS;
66 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_BUTTONS;
69 void ExclusiveAccessManager::UpdateExclusiveAccessExitBubbleContent() {
70 GURL url = GetExclusiveAccessBubbleURL();
71 ExclusiveAccessBubbleType bubble_type = GetExclusiveAccessExitBubbleType();
73 // If bubble displays buttons, unlock mouse to allow pressing them.
74 if (exclusive_access_bubble::ShowButtonsForType(bubble_type) &&
75 mouse_lock_controller_.IsMouseLocked())
76 mouse_lock_controller_.UnlockMouse();
78 exclusive_access_context_->UpdateExclusiveAccessExitBubbleContent(
79 url, bubble_type);
82 GURL ExclusiveAccessManager::GetExclusiveAccessBubbleURL() const {
83 GURL result = fullscreen_controller_.GetURLForExclusiveAccessBubble();
84 if (!result.is_valid())
85 result = mouse_lock_controller_.GetURLForExclusiveAccessBubble();
86 return result;
89 // static
90 bool ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() {
91 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
92 switches::kEnableSimplifiedFullscreenUI)) {
93 return true;
96 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
97 switches::kDisableSimplifiedFullscreenUI)) {
98 return false;
101 return false;
104 void ExclusiveAccessManager::OnTabDeactivated(WebContents* web_contents) {
105 fullscreen_controller_.OnTabDeactivated(web_contents);
106 mouse_lock_controller_.OnTabDeactivated(web_contents);
109 void ExclusiveAccessManager::OnTabDetachedFromView(WebContents* web_contents) {
110 fullscreen_controller_.OnTabDetachedFromView(web_contents);
111 mouse_lock_controller_.OnTabDetachedFromView(web_contents);
114 void ExclusiveAccessManager::OnTabClosing(WebContents* web_contents) {
115 fullscreen_controller_.OnTabClosing(web_contents);
116 mouse_lock_controller_.OnTabClosing(web_contents);
119 bool ExclusiveAccessManager::HandleUserPressedEscape() {
120 bool handled = false;
121 handled = fullscreen_controller_.HandleUserPressedEscape();
122 handled |= mouse_lock_controller_.HandleUserPressedEscape();
123 return handled;
126 void ExclusiveAccessManager::OnAcceptExclusiveAccessPermission() {
127 bool updateBubble =
128 mouse_lock_controller_.OnAcceptExclusiveAccessPermission();
129 updateBubble |= fullscreen_controller_.OnAcceptExclusiveAccessPermission();
130 if (updateBubble)
131 UpdateExclusiveAccessExitBubbleContent();
134 void ExclusiveAccessManager::OnDenyExclusiveAccessPermission() {
135 bool updateBubble = mouse_lock_controller_.OnDenyExclusiveAccessPermission();
136 updateBubble |= fullscreen_controller_.OnDenyExclusiveAccessPermission();
137 if (updateBubble)
138 UpdateExclusiveAccessExitBubbleContent();
141 void ExclusiveAccessManager::ExitExclusiveAccess() {
142 fullscreen_controller_.ExitExclusiveAccessToPreviousState();
143 mouse_lock_controller_.LostMouseLock();