| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chromeos/login/lock/webui_screen_locker.h" | 5 #include "chrome/browser/chromeos/login/lock/webui_screen_locker.h" |
| 6 | 6 |
| 7 #include "ash/common/wm_shell.h" | 7 #include "ash/common/wm_shell.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/system/chromeos/power/power_event_observer.h" | 9 #include "ash/system/chromeos/power/power_event_observer.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/feature_list.h" | 11 #include "base/feature_list.h" |
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/browser_shutdown.h" | 15 #include "chrome/browser/browser_shutdown.h" |
| 16 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
| 17 #include "chrome/browser/chromeos/accessibility/accessibility_util.h" | 17 #include "chrome/browser/chromeos/accessibility/accessibility_util.h" |
| 18 #include "chrome/browser/chromeos/login/helper.h" | 18 #include "chrome/browser/chromeos/login/helper.h" |
| 19 #include "chrome/browser/chromeos/login/lock/screen_locker.h" | 19 #include "chrome/browser/chromeos/login/lock/screen_locker.h" |
| 20 #include "chrome/browser/chromeos/login/ui/shared_web_view.h" | 20 #include "chrome/browser/chromeos/login/ui/preloaded_web_view.h" |
| 21 #include "chrome/browser/chromeos/login/ui/shared_web_view_factory.h" | 21 #include "chrome/browser/chromeos/login/ui/preloaded_web_view_factory.h" |
| 22 #include "chrome/browser/chromeos/login/ui/web_view_handle.h" | |
| 23 #include "chrome/browser/chromeos/login/ui/webui_login_display.h" | 22 #include "chrome/browser/chromeos/login/ui/webui_login_display.h" |
| 24 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 23 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 25 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" | 24 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" |
| 26 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" | 25 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" |
| 27 #include "chrome/common/chrome_features.h" | 26 #include "chrome/common/chrome_features.h" |
| 28 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 29 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
| 30 #include "chrome/grit/generated_resources.h" | 29 #include "chrome/grit/generated_resources.h" |
| 31 #include "chromeos/dbus/dbus_thread_manager.h" | 30 #include "chromeos/dbus/dbus_thread_manager.h" |
| 32 #include "components/prefs/pref_service.h" | 31 #include "components/prefs/pref_service.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 57 void DisableKeyboardOverscroll() { | 56 void DisableKeyboardOverscroll() { |
| 58 keyboard::SetKeyboardOverscrollOverride( | 57 keyboard::SetKeyboardOverscrollOverride( |
| 59 keyboard::KEYBOARD_OVERSCROLL_OVERRIDE_DISABLED); | 58 keyboard::KEYBOARD_OVERSCROLL_OVERRIDE_DISABLED); |
| 60 } | 59 } |
| 61 | 60 |
| 62 void ResetKeyboardOverscrollOverride() { | 61 void ResetKeyboardOverscrollOverride() { |
| 63 keyboard::SetKeyboardOverscrollOverride( | 62 keyboard::SetKeyboardOverscrollOverride( |
| 64 keyboard::KEYBOARD_OVERSCROLL_OVERRIDE_NONE); | 63 keyboard::KEYBOARD_OVERSCROLL_OVERRIDE_NONE); |
| 65 } | 64 } |
| 66 | 65 |
| 67 chromeos::WebUILoginView::WebViewSettings BuildSettings() { | |
| 68 chromeos::WebUILoginView::WebViewSettings settings; | |
| 69 if (chromeos::WebUIScreenLocker::ShouldShareLockScreen()) { | |
| 70 settings.preloaded_url = GURL(kLoginURL); | |
| 71 settings.web_view_title = | |
| 72 l10n_util::GetStringUTF16(IDS_LOCK_SCREEN_TASK_MANAGER_NAME); | |
| 73 } | |
| 74 return settings; | |
| 75 } | |
| 76 | |
| 77 } // namespace | 66 } // namespace |
| 78 | 67 |
| 79 namespace chromeos { | 68 namespace chromeos { |
| 80 | 69 |
| 81 // static | 70 // static |
| 82 bool WebUIScreenLocker::ShouldShareLockScreen() { | 71 void WebUIScreenLocker::RequestPreload() { |
| 72 if (!ShouldPreloadLockScreen()) |
| 73 return; |
| 74 |
| 75 VLOG(1) << "Preloading lock screen"; |
| 76 PreloadedWebView* preloaded_web_view = |
| 77 PreloadedWebViewFactory::GetForProfile(ProfileHelper::GetSigninProfile()); |
| 78 preloaded_web_view->PreloadOnIdle( |
| 79 base::BindOnce(&WebUIScreenLocker::DoPreload)); |
| 80 } |
| 81 |
| 82 // static |
| 83 bool WebUIScreenLocker::ShouldPreloadLockScreen() { |
| 83 Profile* profile = ProfileHelper::Get()->GetProfileByUser( | 84 Profile* profile = ProfileHelper::Get()->GetProfileByUser( |
| 84 user_manager::UserManager::Get()->GetActiveUser()); | 85 user_manager::UserManager::Get()->GetActiveUser()); |
| 85 | 86 |
| 86 // We only want to share the lock screen if the user is likely to see the lock | 87 // We only want to preload the lock screen if the user is likely to see the |
| 87 // screen (since caching the lock screen uses memory). Without preloading, | 88 // lock screen (since caching the lock screen uses memory). Without |
| 88 // showing the lock screen can take so long we will timeout and crash the | 89 // preloading, showing the lock screen can take so long we will timeout and |
| 89 // browser process (which currently takes down all of Chrome). See | 90 // crash the browser process (which currently takes down all of Chrome). See |
| 90 // crbug.com/452599 for more context. | 91 // crbug.com/452599 for more context. |
| 91 // | 92 // |
| 92 // prefs::kEnableAutoScreenLock controls if the lock screen is shown on | 93 // prefs::kEnableAutoScreenLock controls if the lock screen is shown on |
| 93 // suspend, so that is our primary hueristic. | 94 // suspend, so that is our primary hueristic. |
| 94 | 95 |
| 95 // Note that |profile| can be null in tests. | 96 // Note that |profile| can be null in tests. |
| 96 return base::FeatureList::IsEnabled(features::kSharedLockScreen) && profile && | 97 return base::FeatureList::IsEnabled(features::kPreloadLockScreen) && |
| 98 profile && |
| 97 profile->GetPrefs()->GetBoolean(prefs::kEnableAutoScreenLock); | 99 profile->GetPrefs()->GetBoolean(prefs::kEnableAutoScreenLock); |
| 98 } | 100 } |
| 99 | 101 |
| 100 // static | 102 // static |
| 101 void WebUIScreenLocker::Preload() { | 103 std::unique_ptr<views::WebView> WebUIScreenLocker::DoPreload(Profile* profile) { |
| 102 DCHECK(ShouldShareLockScreen()); | 104 auto web_view = base::MakeUnique<views::WebView>(profile); |
| 103 VLOG(1) << "Preloading lock screen"; | 105 web_view->set_owned_by_client(); |
| 104 | 106 web_view->LoadInitialURL(GURL(kLoginURL)); |
| 105 SharedWebView* shared_web_view = | 107 InitializeWebView(web_view.get(), l10n_util::GetStringUTF16( |
| 106 SharedWebViewFactory::GetForProfile(ProfileHelper::GetSigninProfile()); | 108 IDS_LOCK_SCREEN_TASK_MANAGER_NAME)); |
| 107 | 109 return web_view; |
| 108 scoped_refptr<WebViewHandle> web_view_handle; | |
| 109 if (!shared_web_view->has_web_view() && | |
| 110 !shared_web_view->Get(GURL(kLoginURL), &web_view_handle)) { | |
| 111 web_view_handle->web_view()->LoadInitialURL(GURL(kLoginURL)); | |
| 112 InitializeWebView( | |
| 113 web_view_handle->web_view(), | |
| 114 l10n_util::GetStringUTF16(IDS_LOCK_SCREEN_TASK_MANAGER_NAME)); | |
| 115 } | |
| 116 } | 110 } |
| 117 | 111 |
| 118 //////////////////////////////////////////////////////////////////////////////// | 112 //////////////////////////////////////////////////////////////////////////////// |
| 119 // WebUIScreenLocker implementation. | 113 // WebUIScreenLocker implementation. |
| 120 | 114 |
| 121 WebUIScreenLocker::WebUIScreenLocker(ScreenLocker* screen_locker) | 115 WebUIScreenLocker::WebUIScreenLocker(ScreenLocker* screen_locker) |
| 122 : WebUILoginView(BuildSettings()), | 116 : WebUILoginView(BuildConfigSettings()), |
| 123 screen_locker_(screen_locker), | 117 screen_locker_(screen_locker), |
| 124 network_state_helper_(new login::NetworkStateHelper), | 118 network_state_helper_(new login::NetworkStateHelper), |
| 125 weak_factory_(this) { | 119 weak_factory_(this) { |
| 126 set_should_emit_login_prompt_visible(false); | 120 set_should_emit_login_prompt_visible(false); |
| 127 ash::WmShell::Get()->AddLockStateObserver(this); | 121 ash::WmShell::Get()->AddLockStateObserver(this); |
| 128 ash::WmShell::Get()->AddShellObserver(this); | 122 ash::WmShell::Get()->AddShellObserver(this); |
| 129 display::Screen::GetScreen()->AddObserver(this); | 123 display::Screen::GetScreen()->AddObserver(this); |
| 130 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); | 124 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); |
| 131 | 125 |
| 132 if (keyboard::KeyboardController::GetInstance()) { | 126 if (keyboard::KeyboardController::GetInstance()) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 149 // delegate set in ShowSigninScreen so that it no longer points to us. | 143 // delegate set in ShowSigninScreen so that it no longer points to us. |
| 150 if (login_display_.get() && GetOobeUI()) | 144 if (login_display_.get() && GetOobeUI()) |
| 151 GetOobeUI()->ResetSigninScreenHandlerDelegate(); | 145 GetOobeUI()->ResetSigninScreenHandlerDelegate(); |
| 152 | 146 |
| 153 if (keyboard::KeyboardController::GetInstance() && is_observing_keyboard_) { | 147 if (keyboard::KeyboardController::GetInstance() && is_observing_keyboard_) { |
| 154 keyboard::KeyboardController::GetInstance()->RemoveObserver(this); | 148 keyboard::KeyboardController::GetInstance()->RemoveObserver(this); |
| 155 is_observing_keyboard_ = false; | 149 is_observing_keyboard_ = false; |
| 156 } | 150 } |
| 157 | 151 |
| 158 ResetKeyboardOverscrollOverride(); | 152 ResetKeyboardOverscrollOverride(); |
| 153 |
| 154 RequestPreload(); |
| 159 } | 155 } |
| 160 | 156 |
| 161 void WebUIScreenLocker::LockScreen() { | 157 void WebUIScreenLocker::LockScreen() { |
| 162 gfx::Rect bounds = display::Screen::GetScreen()->GetPrimaryDisplay().bounds(); | 158 gfx::Rect bounds = display::Screen::GetScreen()->GetPrimaryDisplay().bounds(); |
| 163 | 159 |
| 164 lock_time_ = base::TimeTicks::Now(); | 160 lock_time_ = base::TimeTicks::Now(); |
| 165 lock_window_ = new LockWindow(this); | 161 lock_window_ = new LockWindow(this); |
| 166 lock_window_->AddObserver(this); | 162 lock_window_->AddObserver(this); |
| 167 | 163 |
| 168 Init(); | 164 Init(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 "cr.ui.Oobe.forceLockedUserPodFocus"); | 231 "cr.ui.Oobe.forceLockedUserPodFocus"); |
| 236 } | 232 } |
| 237 | 233 |
| 238 void WebUIScreenLocker::ResetAndFocusUserPod() { | 234 void WebUIScreenLocker::ResetAndFocusUserPod() { |
| 239 if (!webui_ready_) | 235 if (!webui_ready_) |
| 240 return; | 236 return; |
| 241 GetWebUI()->CallJavascriptFunctionUnsafe("cr.ui.Oobe.clearUserPodPassword"); | 237 GetWebUI()->CallJavascriptFunctionUnsafe("cr.ui.Oobe.clearUserPodPassword"); |
| 242 FocusUserPod(); | 238 FocusUserPod(); |
| 243 } | 239 } |
| 244 | 240 |
| 241 WebUILoginView::WebViewSettings WebUIScreenLocker::BuildConfigSettings() { |
| 242 chromeos::WebUILoginView::WebViewSettings settings; |
| 243 if (chromeos::WebUIScreenLocker::ShouldPreloadLockScreen()) { |
| 244 settings.check_for_preload = true; |
| 245 settings.web_view_title = |
| 246 l10n_util::GetStringUTF16(IDS_LOCK_SCREEN_TASK_MANAGER_NAME); |
| 247 } |
| 248 return settings; |
| 249 } |
| 250 |
| 245 void WebUIScreenLocker::OnLockWebUIReady() { | 251 void WebUIScreenLocker::OnLockWebUIReady() { |
| 246 VLOG(1) << "WebUI ready; lock window is " | 252 VLOG(1) << "WebUI ready; lock window is " |
| 247 << (lock_ready_ ? "too" : "not"); | 253 << (lock_ready_ ? "too" : "not"); |
| 248 webui_ready_ = true; | 254 webui_ready_ = true; |
| 249 if (lock_ready_) | 255 if (lock_ready_) |
| 250 ScreenLockReady(); | 256 ScreenLockReady(); |
| 251 } | 257 } |
| 252 | 258 |
| 253 void WebUIScreenLocker::OnLockBackgroundDisplayed() { | 259 void WebUIScreenLocker::OnLockBackgroundDisplayed() { |
| 254 UMA_HISTOGRAM_TIMES("LockScreen.BackgroundReady", | 260 UMA_HISTOGRAM_TIMES("LockScreen.BackgroundReady", |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 } | 457 } |
| 452 | 458 |
| 453 if (GetOobeUI()) { | 459 if (GetOobeUI()) { |
| 454 const gfx::Size& size = primary_display.size(); | 460 const gfx::Size& size = primary_display.size(); |
| 455 GetOobeUI()->GetCoreOobeActor()->SetClientAreaSize(size.width(), | 461 GetOobeUI()->GetCoreOobeActor()->SetClientAreaSize(size.width(), |
| 456 size.height()); | 462 size.height()); |
| 457 } | 463 } |
| 458 } | 464 } |
| 459 | 465 |
| 460 } // namespace chromeos | 466 } // namespace chromeos |
| OLD | NEW |