OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "chrome/browser/ui/exclusive_access/exclusive_access_controller_manager
.h" |
| 6 |
| 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/fullscreen_controller.h" |
| 11 #include "chrome/browser/ui/exclusive_access/mouse_lock_controller.h" |
| 12 |
| 13 using content::WebContents; |
| 14 |
| 15 ExclusiveAccessControllerManager::ExclusiveAccessControllerManager( |
| 16 Browser* browser) |
| 17 : browser_(browser), window_(browser->window()) { |
| 18 DCHECK(window_); |
| 19 |
| 20 fullscreen_controller_.reset(new FullscreenController(this, browser_)); |
| 21 mouse_lock_controller_.reset(new MouseLockController(this, browser_)); |
| 22 } |
| 23 |
| 24 ExclusiveAccessControllerManager::~ExclusiveAccessControllerManager() { |
| 25 } |
| 26 |
| 27 FullscreenController* |
| 28 ExclusiveAccessControllerManager::GetFullscreenController() { |
| 29 return fullscreen_controller_.get(); |
| 30 } |
| 31 |
| 32 MouseLockController* |
| 33 ExclusiveAccessControllerManager::GetMouseLockController() { |
| 34 return mouse_lock_controller_.get(); |
| 35 } |
| 36 |
| 37 ExclusiveAccessBubbleType |
| 38 ExclusiveAccessControllerManager::GetExclusiveAccessExitBubbleType() const { |
| 39 // In kiosk and exclusive app mode we always want to be fullscreen and do not |
| 40 // want to show exit instructions for browser mode fullscreen. |
| 41 bool app_mode = false; |
| 42 #if !defined(OS_MACOSX) // App mode (kiosk) is not available on Mac yet. |
| 43 app_mode = chrome::IsRunningInAppMode(); |
| 44 #endif |
| 45 |
| 46 if (mouse_lock_controller_->IsMouseLockSilentlyAccepted()) |
| 47 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE; |
| 48 |
| 49 if (!fullscreen_controller_->IsWindowFullscreenForTabOrPending()) { |
| 50 if (mouse_lock_controller_->IsMouseLocked()) |
| 51 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_EXIT_INSTRUCTION; |
| 52 if (mouse_lock_controller_->IsMouseLockRequested()) |
| 53 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_BUTTONS; |
| 54 if (fullscreen_controller_->IsExtensionFullscreenOrPending()) |
| 55 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION; |
| 56 if (fullscreen_controller_->IsControllerInitiatedFullscreen() && !app_mode) |
| 57 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION; |
| 58 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE; |
| 59 } |
| 60 |
| 61 if (fullscreen_controller_->IsUserAcceptedFullscreen()) { |
| 62 if (fullscreen_controller_->IsPrivilegedFullscreenForTab()) |
| 63 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE; |
| 64 if (mouse_lock_controller_->IsMouseLocked()) |
| 65 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION; |
| 66 if (mouse_lock_controller_->IsMouseLockRequested()) |
| 67 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_BUTTONS; |
| 68 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_EXIT_INSTRUCTION; |
| 69 } |
| 70 |
| 71 if (mouse_lock_controller_->IsMouseLockRequested()) |
| 72 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS; |
| 73 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_BUTTONS; |
| 74 } |
| 75 |
| 76 void ExclusiveAccessControllerManager:: |
| 77 UpdateExclusiveAccessExitBubbleContent() { |
| 78 GURL url = GetExclusiveAccessBubbleURL(); |
| 79 ExclusiveAccessBubbleType bubble_type = GetExclusiveAccessExitBubbleType(); |
| 80 |
| 81 // If bubble displays buttons, unlock mouse to allow pressing them. |
| 82 if (exclusive_access_bubble::ShowButtonsForType(bubble_type) && |
| 83 mouse_lock_controller_->IsMouseLocked()) |
| 84 mouse_lock_controller_->UnlockMouse(); |
| 85 |
| 86 browser_->window()->UpdateFullscreenExitBubbleContent(url, bubble_type); |
| 87 } |
| 88 |
| 89 GURL ExclusiveAccessControllerManager::GetExclusiveAccessBubbleURL() const { |
| 90 GURL result = fullscreen_controller_->GetURLForExclusiveAccessBubble(); |
| 91 if (!result.is_valid()) |
| 92 result = mouse_lock_controller_->GetURLForExclusiveAccessBubble(); |
| 93 return result; |
| 94 } |
| 95 |
| 96 void ExclusiveAccessControllerManager::OnTabDeactivated( |
| 97 WebContents* web_contents) { |
| 98 fullscreen_controller_->OnTabDeactivated(web_contents); |
| 99 mouse_lock_controller_->OnTabDeactivated(web_contents); |
| 100 } |
| 101 |
| 102 void ExclusiveAccessControllerManager::OnTabDetachedFromView( |
| 103 WebContents* web_contents) { |
| 104 fullscreen_controller_->OnTabDetachedFromView(web_contents); |
| 105 mouse_lock_controller_->OnTabDetachedFromView(web_contents); |
| 106 } |
| 107 |
| 108 void ExclusiveAccessControllerManager::OnTabClosing(WebContents* web_contents) { |
| 109 fullscreen_controller_->OnTabClosing(web_contents); |
| 110 mouse_lock_controller_->OnTabClosing(web_contents); |
| 111 } |
| 112 |
| 113 bool ExclusiveAccessControllerManager::HandleUserPressedEscape() { |
| 114 bool handled = false; |
| 115 handled = fullscreen_controller_->HandleUserPressedEscape(); |
| 116 handled |= mouse_lock_controller_->HandleUserPressedEscape(); |
| 117 return handled; |
| 118 } |
| 119 |
| 120 void ExclusiveAccessControllerManager::OnAcceptExclusiveAccessPermission() { |
| 121 bool updateBubble = |
| 122 mouse_lock_controller_->OnAcceptExclusiveAccessPermission(); |
| 123 updateBubble |= fullscreen_controller_->OnAcceptExclusiveAccessPermission(); |
| 124 if (updateBubble) |
| 125 UpdateExclusiveAccessExitBubbleContent(); |
| 126 } |
| 127 |
| 128 void ExclusiveAccessControllerManager::OnDenyExclusiveAccessPermission() { |
| 129 bool updateBubble = mouse_lock_controller_->OnDenyExclusiveAccessPermission(); |
| 130 updateBubble |= fullscreen_controller_->OnDenyExclusiveAccessPermission(); |
| 131 if (updateBubble) |
| 132 UpdateExclusiveAccessExitBubbleContent(); |
| 133 } |
OLD | NEW |