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