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 seconds required to hold the Esc key in order to exit full screen. | |
| 25 const double kDurationToHoldEscapeToExitFullscreen = 1.5; | |
|
Matt Giuca
2016/03/21 00:36:07
I think this should be in c/b/u/exclusive_access/e
dominickn
2016/03/21 21:58:04
That means a) pulling in exclusive_access_bubble.h
msw
2016/03/23 07:20:54
nit: add a todo if you think it should be moved
| |
| 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 (IsExperimentalFullscreenUIEnabled()) | |
| 70 return | |
| 71 EXCLUSIVE_ACCESS_BUBBLE_TYPE_EXPERIMENTAL_FULLSCREEN_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::IsExperimentalFullscreenUIEnabled() { | |
| 106 return base::FeatureList::IsEnabled(features::kExperimentalFullscreenUI); | |
| 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 (IsExperimentalFullscreenUIEnabled()) { |
| 116 OnUserInput(); | 132 if (event.windowsKeyCode != ui::VKEY_ESCAPE) { |
|
Matt Giuca
2016/03/21 00:36:07
This block got duplicated. It's the same for both
dominickn
2016/03/21 21:58:04
Good point, thanks
| |
| 133 OnUserInput(); | |
| 134 } else if (event.type == content::NativeWebKeyboardEvent::KeyUp && | |
| 135 hold_timer_.IsRunning()) { | |
| 136 // Seeing a key up event on Esc with the hold timer running cancels the | |
| 137 // timer and doesn't exit. This means the user pressed Esc, but not long | |
| 138 // enough to trigger an exit | |
| 139 hold_timer_.Stop(); | |
| 140 } else if (event.type == content::NativeWebKeyboardEvent::RawKeyDown && | |
| 141 !hold_timer_.IsRunning()) { | |
| 142 // Seeing a key down event on Esc when the hold timer is stopped starts | |
| 143 // the timer. When the timer reaches 0, the callback will trigger an exit | |
| 144 // from fullscreen/mouselock. | |
| 145 hold_timer_.Start( | |
| 146 FROM_HERE, | |
| 147 base::TimeDelta::FromSeconds(kDurationToHoldEscapeToExitFullscreen), | |
|
Matt Giuca
2016/03/21 00:36:07
FromSeconds takes an int, so this will round down
dominickn
2016/03/21 21:58:04
FromMillseeconds, done
| |
| 148 base::Bind(&ExclusiveAccessManager::HandleUserHeldEscape, | |
| 149 base::Unretained(this))); | |
| 150 } | |
| 151 // We never handle the keyboard event. | |
| 117 return false; | 152 return false; |
| 153 } else { | |
| 154 if (event.windowsKeyCode != ui::VKEY_ESCAPE) { | |
| 155 OnUserInput(); | |
| 156 return false; | |
| 157 } | |
| 158 | |
| 159 bool handled = false; | |
| 160 handled = fullscreen_controller_.HandleUserPressedEscape(); | |
| 161 handled |= mouse_lock_controller_.HandleUserPressedEscape(); | |
| 162 return handled; | |
| 118 } | 163 } |
| 119 | |
| 120 bool handled = false; | |
| 121 handled = fullscreen_controller_.HandleUserPressedEscape(); | |
| 122 handled |= mouse_lock_controller_.HandleUserPressedEscape(); | |
| 123 return handled; | |
| 124 } | 164 } |
| 125 | 165 |
| 126 void ExclusiveAccessManager::OnUserInput() { | 166 void ExclusiveAccessManager::OnUserInput() { |
| 127 exclusive_access_context_->OnExclusiveAccessUserInput(); | 167 exclusive_access_context_->OnExclusiveAccessUserInput(); |
| 128 } | 168 } |
| 129 | 169 |
| 130 void ExclusiveAccessManager::OnAcceptExclusiveAccessPermission() { | 170 void ExclusiveAccessManager::OnAcceptExclusiveAccessPermission() { |
| 131 bool updateBubble = | 171 bool updateBubble = |
| 132 mouse_lock_controller_.OnAcceptExclusiveAccessPermission(); | 172 mouse_lock_controller_.OnAcceptExclusiveAccessPermission(); |
| 133 updateBubble |= fullscreen_controller_.OnAcceptExclusiveAccessPermission(); | 173 updateBubble |= fullscreen_controller_.OnAcceptExclusiveAccessPermission(); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 152 // Figure out whether each of fullscreen, mouselock is in effect. | 192 // Figure out whether each of fullscreen, mouselock is in effect. |
| 153 bool fullscreen = false; | 193 bool fullscreen = false; |
| 154 bool mouselock = false; | 194 bool mouselock = false; |
| 155 switch (type) { | 195 switch (type) { |
| 156 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE: | 196 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE: |
| 157 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_BUTTONS: | 197 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_BUTTONS: |
| 158 // None in effect. | 198 // None in effect. |
| 159 break; | 199 break; |
| 160 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_BUTTONS: | 200 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_BUTTONS: |
| 161 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_EXIT_INSTRUCTION: | 201 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_EXIT_INSTRUCTION: |
| 202 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_EXPERIMENTAL_FULLSCREEN_EXIT_INSTRUCTION: | |
| 162 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION: | 203 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION: |
| 163 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION: | 204 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_EXTENSION_FULLSCREEN_EXIT_INSTRUCTION: |
| 164 // Only fullscreen in effect. | 205 // Only fullscreen in effect. |
| 165 fullscreen = true; | 206 fullscreen = true; |
| 166 break; | 207 break; |
| 167 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_EXIT_INSTRUCTION: | 208 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_EXIT_INSTRUCTION: |
| 168 // Only mouselock in effect. | 209 // Only mouselock in effect. |
| 169 mouselock = true; | 210 mouselock = true; |
| 170 break; | 211 break; |
| 171 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS: | 212 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS: |
| 172 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION: | 213 case EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION: |
| 173 // Both in effect. | 214 // Both in effect. |
| 174 fullscreen = true; | 215 fullscreen = true; |
| 175 mouselock = true; | 216 mouselock = true; |
| 176 break; | 217 break; |
| 177 } | 218 } |
| 178 | 219 |
| 179 if (fullscreen) | 220 if (fullscreen) |
| 180 fullscreen_controller_.RecordBubbleReshownUMA(); | 221 fullscreen_controller_.RecordBubbleReshownUMA(); |
| 181 if (mouselock) | 222 if (mouselock) |
| 182 mouse_lock_controller_.RecordBubbleReshownUMA(); | 223 mouse_lock_controller_.RecordBubbleReshownUMA(); |
| 183 } | 224 } |
| 225 | |
| 226 void ExclusiveAccessManager::HandleUserHeldEscape() { | |
| 227 fullscreen_controller_.HandleUserPressedEscape(); | |
| 228 mouse_lock_controller_.HandleUserPressedEscape(); | |
| 229 } | |
| OLD | NEW |