Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / ui / exclusive_access / exclusive_access_manager.cc
blobe252a394a14003e4199fe14dda137b27a46aa412
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 "chrome/browser/app_mode/app_mode_utils.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_window.h"
10 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h"
11 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
12 #include "chrome/browser/ui/exclusive_access/mouse_lock_controller.h"
14 using content::WebContents;
16 ExclusiveAccessManager::ExclusiveAccessManager(
17 ExclusiveAccessContext* exclusive_access_context)
18 : exclusive_access_context_(exclusive_access_context),
19 fullscreen_controller_(this),
20 mouse_lock_controller_(this) {
23 ExclusiveAccessManager::~ExclusiveAccessManager() {
26 ExclusiveAccessBubbleType
27 ExclusiveAccessManager::GetExclusiveAccessExitBubbleType() const {
28 // In kiosk and exclusive app mode we always want to be fullscreen and do not
29 // want to show exit instructions for browser mode fullscreen.
30 bool app_mode = false;
31 #if !defined(OS_MACOSX) // App mode (kiosk) is not available on Mac yet.
32 app_mode = chrome::IsRunningInAppMode();
33 #endif
35 if (mouse_lock_controller_.IsMouseLockSilentlyAccepted() &&
36 (!fullscreen_controller_.IsWindowFullscreenForTabOrPending() ||
37 fullscreen_controller_.IsUserAcceptedFullscreen()))
38 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE;
40 if (!fullscreen_controller_.IsWindowFullscreenForTabOrPending()) {
41 if (mouse_lock_controller_.IsMouseLocked())
42 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_EXIT_INSTRUCTION;
43 if (mouse_lock_controller_.IsMouseLockRequested())
44 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_BUTTONS;
45 if (fullscreen_controller_.IsExtensionFullscreenOrPending())
46 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION;
47 if (fullscreen_controller_.IsControllerInitiatedFullscreen() && !app_mode)
48 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION;
49 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE;
52 if (fullscreen_controller_.IsUserAcceptedFullscreen()) {
53 if (fullscreen_controller_.IsPrivilegedFullscreenForTab())
54 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE;
55 if (mouse_lock_controller_.IsMouseLocked())
56 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION;
57 if (mouse_lock_controller_.IsMouseLockRequested())
58 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_BUTTONS;
59 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_EXIT_INSTRUCTION;
62 if (mouse_lock_controller_.IsMouseLockRequested())
63 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS;
64 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_BUTTONS;
67 void ExclusiveAccessManager::UpdateExclusiveAccessExitBubbleContent() {
68 GURL url = GetExclusiveAccessBubbleURL();
69 ExclusiveAccessBubbleType bubble_type = GetExclusiveAccessExitBubbleType();
71 // If bubble displays buttons, unlock mouse to allow pressing them.
72 if (exclusive_access_bubble::ShowButtonsForType(bubble_type) &&
73 mouse_lock_controller_.IsMouseLocked())
74 mouse_lock_controller_.UnlockMouse();
76 exclusive_access_context_->UpdateExclusiveAccessExitBubbleContent(
77 url, bubble_type);
80 GURL ExclusiveAccessManager::GetExclusiveAccessBubbleURL() const {
81 GURL result = fullscreen_controller_.GetURLForExclusiveAccessBubble();
82 if (!result.is_valid())
83 result = mouse_lock_controller_.GetURLForExclusiveAccessBubble();
84 return result;
87 void ExclusiveAccessManager::OnTabDeactivated(WebContents* web_contents) {
88 fullscreen_controller_.OnTabDeactivated(web_contents);
89 mouse_lock_controller_.OnTabDeactivated(web_contents);
92 void ExclusiveAccessManager::OnTabDetachedFromView(WebContents* web_contents) {
93 fullscreen_controller_.OnTabDetachedFromView(web_contents);
94 mouse_lock_controller_.OnTabDetachedFromView(web_contents);
97 void ExclusiveAccessManager::OnTabClosing(WebContents* web_contents) {
98 fullscreen_controller_.OnTabClosing(web_contents);
99 mouse_lock_controller_.OnTabClosing(web_contents);
102 bool ExclusiveAccessManager::HandleUserPressedEscape() {
103 bool handled = false;
104 handled = fullscreen_controller_.HandleUserPressedEscape();
105 handled |= mouse_lock_controller_.HandleUserPressedEscape();
106 return handled;
109 void ExclusiveAccessManager::OnAcceptExclusiveAccessPermission() {
110 bool updateBubble =
111 mouse_lock_controller_.OnAcceptExclusiveAccessPermission();
112 updateBubble |= fullscreen_controller_.OnAcceptExclusiveAccessPermission();
113 if (updateBubble)
114 UpdateExclusiveAccessExitBubbleContent();
117 void ExclusiveAccessManager::OnDenyExclusiveAccessPermission() {
118 bool updateBubble = mouse_lock_controller_.OnDenyExclusiveAccessPermission();
119 updateBubble |= fullscreen_controller_.OnDenyExclusiveAccessPermission();
120 if (updateBubble)
121 UpdateExclusiveAccessExitBubbleContent();
124 void ExclusiveAccessManager::ExitExclusiveAccess() {
125 fullscreen_controller_.ExitExclusiveAccessToPreviousState();
126 mouse_lock_controller_.LostMouseLock();