| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" | 5 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "chrome/browser/app_mode/app_mode_utils.h" | 9 #include "chrome/browser/app_mode/app_mode_utils.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/browser_window.h" | 11 #include "chrome/browser/ui/browser_window.h" |
| 12 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h" | 12 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h" |
| 13 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" | 13 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" |
| 14 #include "chrome/browser/ui/exclusive_access/mouse_lock_controller.h" | 14 #include "chrome/browser/ui/exclusive_access/mouse_lock_controller.h" |
| 15 #include "chrome/common/chrome_features.h" | 15 #include "chrome/common/chrome_features.h" |
| 16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 17 #include "content/public/browser/native_web_keyboard_event.h" | 17 #include "content/public/browser/native_web_keyboard_event.h" |
| 18 #include "ui/events/keycodes/keyboard_codes.h" | 18 #include "ui/events/keycodes/keyboard_codes.h" |
| 19 | 19 |
| 20 using content::WebContents; | 20 using content::WebContents; |
| 21 | 21 |
| 22 namespace { |
| 23 |
| 24 // Time in milliseconds to hold the Esc key in order to exit full screen. |
| 25 // TODO(dominickn) refactor the way timings/input handling works so this |
| 26 // constant doesn't have to be in this file. |
| 27 const int kHoldEscapeTimeMs = 1500; |
| 28 |
| 29 } |
| 30 |
| 22 ExclusiveAccessManager::ExclusiveAccessManager( | 31 ExclusiveAccessManager::ExclusiveAccessManager( |
| 23 ExclusiveAccessContext* exclusive_access_context) | 32 ExclusiveAccessContext* exclusive_access_context) |
| 24 : exclusive_access_context_(exclusive_access_context), | 33 : exclusive_access_context_(exclusive_access_context), |
| 25 fullscreen_controller_(this), | 34 fullscreen_controller_(this), |
| 26 mouse_lock_controller_(this) { | 35 mouse_lock_controller_(this) { |
| 27 } | 36 } |
| 28 | 37 |
| 29 ExclusiveAccessManager::~ExclusiveAccessManager() { | 38 ExclusiveAccessManager::~ExclusiveAccessManager() { |
| 30 } | 39 } |
| 31 | 40 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 51 if (fullscreen_controller_.IsExtensionFullscreenOrPending()) | 60 if (fullscreen_controller_.IsExtensionFullscreenOrPending()) |
| 52 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION; | 61 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION; |
| 53 if (fullscreen_controller_.IsControllerInitiatedFullscreen() && !app_mode) | 62 if (fullscreen_controller_.IsControllerInitiatedFullscreen() && !app_mode) |
| 54 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION; | 63 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION; |
| 55 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE; | 64 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE; |
| 56 } | 65 } |
| 57 | 66 |
| 58 if (fullscreen_controller_.IsUserAcceptedFullscreen()) { | 67 if (fullscreen_controller_.IsUserAcceptedFullscreen()) { |
| 59 if (fullscreen_controller_.IsPrivilegedFullscreenForTab()) | 68 if (fullscreen_controller_.IsPrivilegedFullscreenForTab()) |
| 60 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE; | 69 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE; |
| 70 if (IsExperimentalKeyboardLockUIEnabled()) |
| 71 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_KEYBOARD_LOCK_EXIT_INSTRUCTION; |
| 61 if (mouse_lock_controller_.IsMouseLocked()) | 72 if (mouse_lock_controller_.IsMouseLocked()) |
| 62 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION; | 73 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION; |
| 63 if (mouse_lock_controller_.IsMouseLockRequested()) | 74 if (mouse_lock_controller_.IsMouseLockRequested()) |
| 64 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_BUTTONS; | 75 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_BUTTONS; |
| 65 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_EXIT_INSTRUCTION; | 76 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_EXIT_INSTRUCTION; |
| 66 } | 77 } |
| 67 | 78 |
| 68 if (mouse_lock_controller_.IsMouseLockRequested()) | 79 if (mouse_lock_controller_.IsMouseLockRequested()) |
| 69 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS; | 80 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS; |
| 70 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_BUTTONS; | 81 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_BUTTONS; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 84 } | 95 } |
| 85 | 96 |
| 86 GURL ExclusiveAccessManager::GetExclusiveAccessBubbleURL() const { | 97 GURL ExclusiveAccessManager::GetExclusiveAccessBubbleURL() const { |
| 87 GURL result = fullscreen_controller_.GetURLForExclusiveAccessBubble(); | 98 GURL result = fullscreen_controller_.GetURLForExclusiveAccessBubble(); |
| 88 if (!result.is_valid()) | 99 if (!result.is_valid()) |
| 89 result = mouse_lock_controller_.GetURLForExclusiveAccessBubble(); | 100 result = mouse_lock_controller_.GetURLForExclusiveAccessBubble(); |
| 90 return result; | 101 return result; |
| 91 } | 102 } |
| 92 | 103 |
| 93 // static | 104 // static |
| 105 bool ExclusiveAccessManager::IsExperimentalKeyboardLockUIEnabled() { |
| 106 return base::FeatureList::IsEnabled(features::kExperimentalKeyboardLockUI); |
| 107 } |
| 108 |
| 109 // static |
| 94 bool ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() { | 110 bool ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() { |
| 95 return base::FeatureList::IsEnabled(features::kSimplifiedFullscreenUI); | 111 return base::FeatureList::IsEnabled(features::kSimplifiedFullscreenUI); |
| 96 } | 112 } |
| 97 | 113 |
| 98 void ExclusiveAccessManager::OnTabDeactivated(WebContents* web_contents) { | 114 void ExclusiveAccessManager::OnTabDeactivated(WebContents* web_contents) { |
| 99 fullscreen_controller_.OnTabDeactivated(web_contents); | 115 fullscreen_controller_.OnTabDeactivated(web_contents); |
| 100 mouse_lock_controller_.OnTabDeactivated(web_contents); | 116 mouse_lock_controller_.OnTabDeactivated(web_contents); |
| 101 } | 117 } |
| 102 | 118 |
| 103 void ExclusiveAccessManager::OnTabDetachedFromView(WebContents* web_contents) { | 119 void ExclusiveAccessManager::OnTabDetachedFromView(WebContents* web_contents) { |
| 104 fullscreen_controller_.OnTabDetachedFromView(web_contents); | 120 fullscreen_controller_.OnTabDetachedFromView(web_contents); |
| 105 mouse_lock_controller_.OnTabDetachedFromView(web_contents); | 121 mouse_lock_controller_.OnTabDetachedFromView(web_contents); |
| 106 } | 122 } |
| 107 | 123 |
| 108 void ExclusiveAccessManager::OnTabClosing(WebContents* web_contents) { | 124 void ExclusiveAccessManager::OnTabClosing(WebContents* web_contents) { |
| 109 fullscreen_controller_.OnTabClosing(web_contents); | 125 fullscreen_controller_.OnTabClosing(web_contents); |
| 110 mouse_lock_controller_.OnTabClosing(web_contents); | 126 mouse_lock_controller_.OnTabClosing(web_contents); |
| 111 } | 127 } |
| 112 | 128 |
| 113 bool ExclusiveAccessManager::HandleUserKeyPress( | 129 bool ExclusiveAccessManager::HandleUserKeyPress( |
| 114 const content::NativeWebKeyboardEvent& event) { | 130 const content::NativeWebKeyboardEvent& event) { |
| 115 if (event.windowsKeyCode != ui::VKEY_ESCAPE) { | 131 if (event.windowsKeyCode != ui::VKEY_ESCAPE) { |
| 116 OnUserInput(); | 132 OnUserInput(); |
| 117 return false; | 133 return false; |
| 118 } | 134 } |
| 119 | 135 |
| 136 if (IsExperimentalKeyboardLockUIEnabled()) { |
| 137 if (event.type == content::NativeWebKeyboardEvent::KeyUp && |
| 138 hold_timer_.IsRunning()) { |
| 139 // Seeing a key up event on Esc with the hold timer running cancels the |
| 140 // timer and doesn't exit. This means the user pressed Esc, but not long |
| 141 // enough to trigger an exit |
| 142 hold_timer_.Stop(); |
| 143 } else if (event.type == content::NativeWebKeyboardEvent::RawKeyDown && |
| 144 !hold_timer_.IsRunning()) { |
| 145 // Seeing a key down event on Esc when the hold timer is stopped starts |
| 146 // the timer. When the timer reaches 0, the callback will trigger an exit |
| 147 // from fullscreen/mouselock. |
| 148 hold_timer_.Start( |
| 149 FROM_HERE, base::TimeDelta::FromMilliseconds(kHoldEscapeTimeMs), |
| 150 base::Bind(&ExclusiveAccessManager::HandleUserHeldEscape, |
| 151 base::Unretained(this))); |
| 152 } |
| 153 // We never handle the keyboard event. |
| 154 return false; |
| 155 } |
| 156 |
| 120 bool handled = false; | 157 bool handled = false; |
| 121 handled = fullscreen_controller_.HandleUserPressedEscape(); | 158 handled = fullscreen_controller_.HandleUserPressedEscape(); |
| 122 handled |= mouse_lock_controller_.HandleUserPressedEscape(); | 159 handled |= mouse_lock_controller_.HandleUserPressedEscape(); |
| 123 return handled; | 160 return handled; |
| 124 } | 161 } |
| 125 | 162 |
| 126 void ExclusiveAccessManager::OnUserInput() { | 163 void ExclusiveAccessManager::OnUserInput() { |
| 127 exclusive_access_context_->OnExclusiveAccessUserInput(); | 164 exclusive_access_context_->OnExclusiveAccessUserInput(); |
| 128 } | 165 } |
| 129 | 166 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 152 // Figure out whether each of fullscreen, mouselock is in effect. | 189 // Figure out whether each of fullscreen, mouselock is in effect. |
| 153 bool fullscreen = false; | 190 bool fullscreen = false; |
| 154 bool mouselock = false; | 191 bool mouselock = false; |
| 155 switch (type) { | 192 switch (type) { |
| 156 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE: | 193 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE: |
| 157 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_BUTTONS: | 194 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_BUTTONS: |
| 158 // None in effect. | 195 // None in effect. |
| 159 break; | 196 break; |
| 160 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_BUTTONS: | 197 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_BUTTONS: |
| 161 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_EXIT_INSTRUCTION: | 198 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_EXIT_INSTRUCTION: |
| 199 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_KEYBOARD_LOCK_EXIT_INSTRUCTION: |
| 162 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION: | 200 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION: |
| 163 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION: | 201 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION: |
| 164 // Only fullscreen in effect. | 202 // Only fullscreen in effect. |
| 165 fullscreen = true; | 203 fullscreen = true; |
| 166 break; | 204 break; |
| 167 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_EXIT_INSTRUCTION: | 205 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_EXIT_INSTRUCTION: |
| 168 // Only mouselock in effect. | 206 // Only mouselock in effect. |
| 169 mouselock = true; | 207 mouselock = true; |
| 170 break; | 208 break; |
| 171 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS: | 209 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS: |
| 172 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION: | 210 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION: |
| 173 // Both in effect. | 211 // Both in effect. |
| 174 fullscreen = true; | 212 fullscreen = true; |
| 175 mouselock = true; | 213 mouselock = true; |
| 176 break; | 214 break; |
| 177 } | 215 } |
| 178 | 216 |
| 179 if (fullscreen) | 217 if (fullscreen) |
| 180 fullscreen_controller_.RecordBubbleReshownUMA(); | 218 fullscreen_controller_.RecordBubbleReshownUMA(); |
| 181 if (mouselock) | 219 if (mouselock) |
| 182 mouse_lock_controller_.RecordBubbleReshownUMA(); | 220 mouse_lock_controller_.RecordBubbleReshownUMA(); |
| 183 } | 221 } |
| 222 |
| 223 void ExclusiveAccessManager::HandleUserHeldEscape() { |
| 224 fullscreen_controller_.HandleUserPressedEscape(); |
| 225 mouse_lock_controller_.HandleUserPressedEscape(); |
| 226 } |
| OLD | NEW |