Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(691)

Side by Side Diff: chrome/browser/chromeos/login/lock/webui_screen_locker.cc

Issue 2553863002: cros: Preload and reuse the lock screen across lock sessions (Closed)
Patch Set: Rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
13 #include "base/values.h" 14 #include "base/values.h"
14 #include "chrome/browser/browser_shutdown.h" 15 #include "chrome/browser/browser_shutdown.h"
15 #include "chrome/browser/chrome_notification_types.h" 16 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/chromeos/accessibility/accessibility_util.h" 17 #include "chrome/browser/chromeos/accessibility/accessibility_util.h"
17 #include "chrome/browser/chromeos/login/helper.h" 18 #include "chrome/browser/chromeos/login/helper.h"
18 #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"
21 #include "chrome/browser/chromeos/login/ui/shared_web_view_factory.h"
22 #include "chrome/browser/chromeos/login/ui/web_view_handle.h"
19 #include "chrome/browser/chromeos/login/ui/webui_login_display.h" 23 #include "chrome/browser/chromeos/login/ui/webui_login_display.h"
24 #include "chrome/browser/chromeos/profiles/profile_helper.h"
20 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" 25 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
21 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" 26 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
27 #include "chrome/common/chrome_features.h"
28 #include "chrome/common/pref_names.h"
22 #include "chrome/common/url_constants.h" 29 #include "chrome/common/url_constants.h"
30 #include "chrome/grit/generated_resources.h"
23 #include "chromeos/dbus/dbus_thread_manager.h" 31 #include "chromeos/dbus/dbus_thread_manager.h"
32 #include "components/prefs/pref_service.h"
24 #include "components/user_manager/user.h" 33 #include "components/user_manager/user.h"
25 #include "content/public/browser/browser_thread.h" 34 #include "content/public/browser/browser_thread.h"
26 #include "content/public/browser/notification_service.h" 35 #include "content/public/browser/notification_service.h"
27 #include "content/public/browser/notification_types.h" 36 #include "content/public/browser/notification_types.h"
28 #include "content/public/browser/render_widget_host_view.h" 37 #include "content/public/browser/render_widget_host_view.h"
38 #include "content/public/browser/web_contents.h"
29 #include "content/public/browser/web_ui.h" 39 #include "content/public/browser/web_ui.h"
30 #include "ui/aura/client/capture_client.h" 40 #include "ui/aura/client/capture_client.h"
31 #include "ui/aura/window_event_dispatcher.h" 41 #include "ui/aura/window_event_dispatcher.h"
42 #include "ui/base/l10n/l10n_util.h"
32 #include "ui/base/x/x11_util.h" 43 #include "ui/base/x/x11_util.h"
33 #include "ui/display/display.h" 44 #include "ui/display/display.h"
34 #include "ui/display/screen.h" 45 #include "ui/display/screen.h"
35 #include "ui/keyboard/keyboard_controller.h" 46 #include "ui/keyboard/keyboard_controller.h"
36 #include "ui/keyboard/keyboard_util.h" 47 #include "ui/keyboard/keyboard_util.h"
37 #include "ui/views/controls/webview/webview.h" 48 #include "ui/views/controls/webview/webview.h"
38 49
39 namespace { 50 namespace {
40 51
41 // URL which corresponds to the login WebUI. 52 // URL which corresponds to the login WebUI.
42 const char kLoginURL[] = "chrome://oobe/lock"; 53 const char kLoginURL[] = "chrome://oobe/lock";
43 54
44 // Disables virtual keyboard overscroll. Login UI will scroll user pods 55 // Disables virtual keyboard overscroll. Login UI will scroll user pods
45 // into view on JS side when virtual keyboard is shown. 56 // into view on JS side when virtual keyboard is shown.
46 void DisableKeyboardOverscroll() { 57 void DisableKeyboardOverscroll() {
47 keyboard::SetKeyboardOverscrollOverride( 58 keyboard::SetKeyboardOverscrollOverride(
48 keyboard::KEYBOARD_OVERSCROLL_OVERRIDE_DISABLED); 59 keyboard::KEYBOARD_OVERSCROLL_OVERRIDE_DISABLED);
49 } 60 }
50 61
51 void ResetKeyboardOverscrollOverride() { 62 void ResetKeyboardOverscrollOverride() {
52 keyboard::SetKeyboardOverscrollOverride( 63 keyboard::SetKeyboardOverscrollOverride(
53 keyboard::KEYBOARD_OVERSCROLL_OVERRIDE_NONE); 64 keyboard::KEYBOARD_OVERSCROLL_OVERRIDE_NONE);
54 } 65 }
55 66
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
56 } // namespace 77 } // namespace
57 78
58 namespace chromeos { 79 namespace chromeos {
59 80
81 // static
82 bool WebUIScreenLocker::ShouldShareLockScreen() {
83 Profile* profile = ProfileHelper::Get()->GetProfileByUser(
84 user_manager::UserManager::Get()->GetActiveUser());
85
86 // We only want to share the lock screen if the user is likely to see the lock
87 // screen (since caching the lock screen uses memory). Without preloading,
88 // showing the lock screen can take so long we will timeout and crash the
89 // browser process (which currently takes down all of Chrome). See
90 // crbug.com/452599 for more context.
91 //
92 // prefs::kEnableAutoScreenLock controls if the lock screen is shown on
93 // suspend, so that is our primary hueristic.
94
95 // Note that |profile| can be null in tests.
96 return base::FeatureList::IsEnabled(features::kSharedLockScreen) && profile &&
97 profile->GetPrefs()->GetBoolean(prefs::kEnableAutoScreenLock);
98 }
99
100 // static
101 void WebUIScreenLocker::Preload() {
102 DCHECK(ShouldShareLockScreen());
103 VLOG(1) << "Preloading lock screen";
104
105 SharedWebView* shared_web_view =
106 SharedWebViewFactory::GetForProfile(ProfileHelper::GetSigninProfile());
107
108 scoped_refptr<WebViewHandle> web_view_handle;
109 if (!shared_web_view->Get(GURL(kLoginURL), &web_view_handle)) {
110 web_view_handle->web_view()->LoadInitialURL(GURL(kLoginURL));
111 InitializeWebView(
112 web_view_handle->web_view(),
113 l10n_util::GetStringUTF16(IDS_LOCK_SCREEN_TASK_MANAGER_NAME));
114 }
115 }
116
60 //////////////////////////////////////////////////////////////////////////////// 117 ////////////////////////////////////////////////////////////////////////////////
61 // WebUIScreenLocker implementation. 118 // WebUIScreenLocker implementation.
62 119
63 WebUIScreenLocker::WebUIScreenLocker(ScreenLocker* screen_locker) 120 WebUIScreenLocker::WebUIScreenLocker(ScreenLocker* screen_locker)
64 : WebUILoginView(WebViewSettings()), 121 : WebUILoginView(BuildSettings()),
65 screen_locker_(screen_locker), 122 screen_locker_(screen_locker),
66 network_state_helper_(new login::NetworkStateHelper), 123 network_state_helper_(new login::NetworkStateHelper),
67 weak_factory_(this) { 124 weak_factory_(this) {
68 set_should_emit_login_prompt_visible(false); 125 set_should_emit_login_prompt_visible(false);
69 ash::WmShell::Get()->AddLockStateObserver(this); 126 ash::WmShell::Get()->AddLockStateObserver(this);
70 ash::WmShell::Get()->AddShellObserver(this); 127 ash::WmShell::Get()->AddShellObserver(this);
71 display::Screen::GetScreen()->AddObserver(this); 128 display::Screen::GetScreen()->AddObserver(this);
72 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); 129 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this);
73 130
74 if (keyboard::KeyboardController::GetInstance()) { 131 if (keyboard::KeyboardController::GetInstance()) {
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 } 450 }
394 451
395 if (GetOobeUI()) { 452 if (GetOobeUI()) {
396 const gfx::Size& size = primary_display.size(); 453 const gfx::Size& size = primary_display.size();
397 GetOobeUI()->GetCoreOobeActor()->SetClientAreaSize(size.width(), 454 GetOobeUI()->GetCoreOobeActor()->SetClientAreaSize(size.width(),
398 size.height()); 455 size.height());
399 } 456 }
400 } 457 }
401 458
402 } // namespace chromeos 459 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698