Chromium Code Reviews| 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), |
| 36 hold_timer_() { | |
|
msw
2016/03/23 17:07:32
nit: this explicit call to the default ctor should
dominickn
2016/03/23 23:36:22
Done.
| |
| 27 } | 37 } |
| 28 | 38 |
| 29 ExclusiveAccessManager::~ExclusiveAccessManager() { | 39 ExclusiveAccessManager::~ExclusiveAccessManager() { |
| 30 } | 40 } |
| 31 | 41 |
| 32 ExclusiveAccessBubbleType | 42 ExclusiveAccessBubbleType |
| 33 ExclusiveAccessManager::GetExclusiveAccessExitBubbleType() const { | 43 ExclusiveAccessManager::GetExclusiveAccessExitBubbleType() const { |
| 34 // In kiosk and exclusive app mode we always want to be fullscreen and do not | 44 // In kiosk and exclusive app mode we always want to be fullscreen and do not |
| 35 // want to show exit instructions for browser mode fullscreen. | 45 // want to show exit instructions for browser mode fullscreen. |
| 36 bool app_mode = false; | 46 bool app_mode = false; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 51 if (fullscreen_controller_.IsExtensionFullscreenOrPending()) | 61 if (fullscreen_controller_.IsExtensionFullscreenOrPending()) |
| 52 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION; | 62 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION; |
| 53 if (fullscreen_controller_.IsControllerInitiatedFullscreen() && !app_mode) | 63 if (fullscreen_controller_.IsControllerInitiatedFullscreen() && !app_mode) |
| 54 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION; | 64 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION; |
| 55 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE; | 65 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE; |
| 56 } | 66 } |
| 57 | 67 |
| 58 if (fullscreen_controller_.IsUserAcceptedFullscreen()) { | 68 if (fullscreen_controller_.IsUserAcceptedFullscreen()) { |
| 59 if (fullscreen_controller_.IsPrivilegedFullscreenForTab()) | 69 if (fullscreen_controller_.IsPrivilegedFullscreenForTab()) |
| 60 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE; | 70 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE; |
| 71 if (IsExperimentalKeyboardLockUIEnabled()) | |
| 72 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_KEYBOARD_LOCK_EXIT_INSTRUCTION; | |
| 61 if (mouse_lock_controller_.IsMouseLocked()) | 73 if (mouse_lock_controller_.IsMouseLocked()) |
| 62 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION; | 74 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION; |
| 63 if (mouse_lock_controller_.IsMouseLockRequested()) | 75 if (mouse_lock_controller_.IsMouseLockRequested()) |
| 64 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_BUTTONS; | 76 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_BUTTONS; |
| 65 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_EXIT_INSTRUCTION; | 77 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_EXIT_INSTRUCTION; |
| 66 } | 78 } |
| 67 | 79 |
| 68 if (mouse_lock_controller_.IsMouseLockRequested()) | 80 if (mouse_lock_controller_.IsMouseLockRequested()) |
| 69 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS; | 81 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS; |
| 70 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_BUTTONS; | 82 return EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_BUTTONS; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 84 } | 96 } |
| 85 | 97 |
| 86 GURL ExclusiveAccessManager::GetExclusiveAccessBubbleURL() const { | 98 GURL ExclusiveAccessManager::GetExclusiveAccessBubbleURL() const { |
| 87 GURL result = fullscreen_controller_.GetURLForExclusiveAccessBubble(); | 99 GURL result = fullscreen_controller_.GetURLForExclusiveAccessBubble(); |
| 88 if (!result.is_valid()) | 100 if (!result.is_valid()) |
| 89 result = mouse_lock_controller_.GetURLForExclusiveAccessBubble(); | 101 result = mouse_lock_controller_.GetURLForExclusiveAccessBubble(); |
| 90 return result; | 102 return result; |
| 91 } | 103 } |
| 92 | 104 |
| 93 // static | 105 // static |
| 106 bool ExclusiveAccessManager::IsExperimentalKeyboardLockUIEnabled() { | |
| 107 return base::FeatureList::IsEnabled(features::kExperimentalKeyboardLockUI); | |
| 108 } | |
| 109 | |
| 110 // static | |
| 94 bool ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() { | 111 bool ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled() { |
| 95 return base::FeatureList::IsEnabled(features::kSimplifiedFullscreenUI); | 112 return base::FeatureList::IsEnabled(features::kSimplifiedFullscreenUI); |
| 96 } | 113 } |
| 97 | 114 |
| 98 void ExclusiveAccessManager::OnTabDeactivated(WebContents* web_contents) { | 115 void ExclusiveAccessManager::OnTabDeactivated(WebContents* web_contents) { |
| 99 fullscreen_controller_.OnTabDeactivated(web_contents); | 116 fullscreen_controller_.OnTabDeactivated(web_contents); |
| 100 mouse_lock_controller_.OnTabDeactivated(web_contents); | 117 mouse_lock_controller_.OnTabDeactivated(web_contents); |
| 101 } | 118 } |
| 102 | 119 |
| 103 void ExclusiveAccessManager::OnTabDetachedFromView(WebContents* web_contents) { | 120 void ExclusiveAccessManager::OnTabDetachedFromView(WebContents* web_contents) { |
| 104 fullscreen_controller_.OnTabDetachedFromView(web_contents); | 121 fullscreen_controller_.OnTabDetachedFromView(web_contents); |
| 105 mouse_lock_controller_.OnTabDetachedFromView(web_contents); | 122 mouse_lock_controller_.OnTabDetachedFromView(web_contents); |
| 106 } | 123 } |
| 107 | 124 |
| 108 void ExclusiveAccessManager::OnTabClosing(WebContents* web_contents) { | 125 void ExclusiveAccessManager::OnTabClosing(WebContents* web_contents) { |
| 109 fullscreen_controller_.OnTabClosing(web_contents); | 126 fullscreen_controller_.OnTabClosing(web_contents); |
| 110 mouse_lock_controller_.OnTabClosing(web_contents); | 127 mouse_lock_controller_.OnTabClosing(web_contents); |
| 111 } | 128 } |
| 112 | 129 |
| 113 bool ExclusiveAccessManager::HandleUserKeyPress( | 130 bool ExclusiveAccessManager::HandleUserKeyPress( |
| 114 const content::NativeWebKeyboardEvent& event) { | 131 const content::NativeWebKeyboardEvent& event) { |
| 115 if (event.windowsKeyCode != ui::VKEY_ESCAPE) { | 132 if (event.windowsKeyCode != ui::VKEY_ESCAPE) { |
| 116 OnUserInput(); | 133 OnUserInput(); |
| 117 return false; | 134 return false; |
| 118 } | 135 } |
| 119 | 136 |
| 137 if (IsExperimentalKeyboardLockUIEnabled()) { | |
| 138 if (event.type == content::NativeWebKeyboardEvent::KeyUp && | |
| 139 hold_timer_.IsRunning()) { | |
| 140 // Seeing a key up event on Esc with the hold timer running cancels the | |
| 141 // timer and doesn't exit. This means the user pressed Esc, but not long | |
| 142 // enough to trigger an exit | |
| 143 hold_timer_.Stop(); | |
| 144 } else if (event.type == content::NativeWebKeyboardEvent::RawKeyDown && | |
| 145 !hold_timer_.IsRunning()) { | |
| 146 // Seeing a key down event on Esc when the hold timer is stopped starts | |
| 147 // the timer. When the timer reaches 0, the callback will trigger an exit | |
| 148 // from fullscreen/mouselock. | |
| 149 hold_timer_.Start( | |
| 150 FROM_HERE, base::TimeDelta::FromMilliseconds(kHoldEscapeTimeMs), | |
| 151 base::Bind(&ExclusiveAccessManager::HandleUserHeldEscape, | |
| 152 base::Unretained(this))); | |
| 153 } | |
| 154 // We never handle the keyboard event. | |
| 155 return false; | |
| 156 } | |
| 157 | |
| 120 bool handled = false; | 158 bool handled = false; |
| 121 handled = fullscreen_controller_.HandleUserPressedEscape(); | 159 handled = fullscreen_controller_.HandleUserPressedEscape(); |
| 122 handled |= mouse_lock_controller_.HandleUserPressedEscape(); | 160 handled |= mouse_lock_controller_.HandleUserPressedEscape(); |
| 123 return handled; | 161 return handled; |
| 124 } | 162 } |
| 125 | 163 |
| 126 void ExclusiveAccessManager::OnUserInput() { | 164 void ExclusiveAccessManager::OnUserInput() { |
| 127 exclusive_access_context_->OnExclusiveAccessUserInput(); | 165 exclusive_access_context_->OnExclusiveAccessUserInput(); |
| 128 } | 166 } |
| 129 | 167 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 152 // Figure out whether each of fullscreen, mouselock is in effect. | 190 // Figure out whether each of fullscreen, mouselock is in effect. |
| 153 bool fullscreen = false; | 191 bool fullscreen = false; |
| 154 bool mouselock = false; | 192 bool mouselock = false; |
| 155 switch (type) { | 193 switch (type) { |
| 156 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE: | 194 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE: |
| 157 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_BUTTONS: | 195 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_BUTTONS: |
| 158 // None in effect. | 196 // None in effect. |
| 159 break; | 197 break; |
| 160 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_BUTTONS: | 198 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_BUTTONS: |
| 161 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_EXIT_INSTRUCTION: | 199 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_EXIT_INSTRUCTION: |
| 200 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_KEYBOARD_LOCK_EXIT_INSTRUCTION: | |
| 162 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION: | 201 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION: |
| 163 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION: | 202 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION: |
| 164 // Only fullscreen in effect. | 203 // Only fullscreen in effect. |
| 165 fullscreen = true; | 204 fullscreen = true; |
| 166 break; | 205 break; |
| 167 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_EXIT_INSTRUCTION: | 206 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_EXIT_INSTRUCTION: |
| 168 // Only mouselock in effect. | 207 // Only mouselock in effect. |
| 169 mouselock = true; | 208 mouselock = true; |
| 170 break; | 209 break; |
| 171 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS: | 210 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS: |
| 172 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION: | 211 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION: |
| 173 // Both in effect. | 212 // Both in effect. |
| 174 fullscreen = true; | 213 fullscreen = true; |
| 175 mouselock = true; | 214 mouselock = true; |
| 176 break; | 215 break; |
| 177 } | 216 } |
| 178 | 217 |
| 179 if (fullscreen) | 218 if (fullscreen) |
| 180 fullscreen_controller_.RecordBubbleReshownUMA(); | 219 fullscreen_controller_.RecordBubbleReshownUMA(); |
| 181 if (mouselock) | 220 if (mouselock) |
| 182 mouse_lock_controller_.RecordBubbleReshownUMA(); | 221 mouse_lock_controller_.RecordBubbleReshownUMA(); |
| 183 } | 222 } |
| 223 | |
| 224 void ExclusiveAccessManager::HandleUserHeldEscape() { | |
| 225 fullscreen_controller_.HandleUserPressedEscape(); | |
| 226 mouse_lock_controller_.HandleUserPressedEscape(); | |
| 227 } | |
| OLD | NEW |