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/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/wm/lock_state_controller.h" | 8 #include "ash/wm/lock_state_controller.h" |
9 #include "ash/wm/lock_state_observer.h" | 9 #include "ash/wm/lock_state_observer.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 15 matching lines...) Loading... |
26 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
27 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
28 #include "content/public/browser/notification_types.h" | 28 #include "content/public/browser/notification_types.h" |
29 #include "content/public/browser/render_widget_host_view.h" | 29 #include "content/public/browser/render_widget_host_view.h" |
30 #include "content/public/browser/web_ui.h" | 30 #include "content/public/browser/web_ui.h" |
31 #include "ui/aura/client/capture_client.h" | 31 #include "ui/aura/client/capture_client.h" |
32 #include "ui/aura/window_event_dispatcher.h" | 32 #include "ui/aura/window_event_dispatcher.h" |
33 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
34 #include "ui/base/x/x11_util.h" | 34 #include "ui/base/x/x11_util.h" |
35 #include "ui/gfx/screen.h" | 35 #include "ui/gfx/screen.h" |
| 36 #include "ui/keyboard/keyboard_controller.h" |
| 37 #include "ui/keyboard/keyboard_util.h" |
36 #include "ui/views/controls/webview/webview.h" | 38 #include "ui/views/controls/webview/webview.h" |
37 | 39 |
38 namespace { | 40 namespace { |
39 | 41 |
40 // URL which corresponds to the login WebUI. | 42 // URL which corresponds to the login WebUI. |
41 const char kLoginURL[] = "chrome://oobe/lock"; | 43 const char kLoginURL[] = "chrome://oobe/lock"; |
42 | 44 |
| 45 // Disables virtual keyboard overscroll. Login UI will scroll user pods |
| 46 // into view on JS side when virtual keyboard is shown. |
| 47 void DisableKeyboardOverscroll() { |
| 48 keyboard::SetKeyboardOverscrollOverride( |
| 49 keyboard::KEYBOARD_OVERSCROLL_OVERRIDE_DISABLED); |
| 50 } |
| 51 |
| 52 void ResetKeyboardOverscrollOverride() { |
| 53 keyboard::SetKeyboardOverscrollOverride( |
| 54 keyboard::KEYBOARD_OVERSCROLL_OVERRIDE_NONE); |
| 55 } |
| 56 |
43 } // namespace | 57 } // namespace |
44 | 58 |
45 namespace chromeos { | 59 namespace chromeos { |
46 | 60 |
47 //////////////////////////////////////////////////////////////////////////////// | 61 //////////////////////////////////////////////////////////////////////////////// |
48 // WebUIScreenLocker implementation. | 62 // WebUIScreenLocker implementation. |
49 | 63 |
50 WebUIScreenLocker::WebUIScreenLocker(ScreenLocker* screen_locker) | 64 WebUIScreenLocker::WebUIScreenLocker(ScreenLocker* screen_locker) |
51 : ScreenLockerDelegate(screen_locker), | 65 : ScreenLockerDelegate(screen_locker), |
52 lock_ready_(false), | 66 lock_ready_(false), |
53 webui_ready_(false), | 67 webui_ready_(false), |
54 network_state_helper_(new login::NetworkStateHelper), | 68 network_state_helper_(new login::NetworkStateHelper), |
| 69 is_observing_keyboard_(false), |
55 weak_factory_(this) { | 70 weak_factory_(this) { |
56 set_should_emit_login_prompt_visible(false); | 71 set_should_emit_login_prompt_visible(false); |
57 ash::Shell::GetInstance()->lock_state_controller()->AddObserver(this); | 72 ash::Shell::GetInstance()->lock_state_controller()->AddObserver(this); |
58 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); | 73 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); |
| 74 |
| 75 if (keyboard::KeyboardController::GetInstance()) { |
| 76 keyboard::KeyboardController::GetInstance()->AddObserver(this); |
| 77 is_observing_keyboard_ = true; |
| 78 } |
| 79 |
| 80 ash::Shell::GetInstance()->delegate()->AddVirtualKeyboardStateObserver(this); |
59 } | 81 } |
60 | 82 |
61 void WebUIScreenLocker::LockScreen() { | 83 void WebUIScreenLocker::LockScreen() { |
62 gfx::Rect bounds(ash::Shell::GetScreen()->GetPrimaryDisplay().bounds()); | 84 gfx::Rect bounds(ash::Shell::GetScreen()->GetPrimaryDisplay().bounds()); |
63 | 85 |
64 lock_time_ = base::TimeTicks::Now(); | 86 lock_time_ = base::TimeTicks::Now(); |
65 LockWindow* lock_window = LockWindow::Create(); | 87 LockWindow* lock_window = LockWindow::Create(); |
66 lock_window->set_observer(this); | 88 lock_window->set_observer(this); |
67 lock_window_ = lock_window->GetWidget(); | 89 lock_window_ = lock_window->GetWidget(); |
68 lock_window_->AddObserver(this); | 90 lock_window_->AddObserver(this); |
69 WebUILoginView::Init(); | 91 WebUILoginView::Init(); |
70 lock_window_->SetContentsView(this); | 92 lock_window_->SetContentsView(this); |
71 lock_window_->Show(); | 93 lock_window_->Show(); |
72 LoadURL(GURL(kLoginURL)); | 94 LoadURL(GURL(kLoginURL)); |
73 lock_window->Grab(); | 95 lock_window->Grab(); |
74 | 96 |
75 login_display_.reset(new WebUILoginDisplay(this)); | 97 login_display_.reset(new WebUILoginDisplay(this)); |
76 login_display_->set_background_bounds(bounds); | 98 login_display_->set_background_bounds(bounds); |
77 login_display_->set_parent_window(GetNativeWindow()); | 99 login_display_->set_parent_window(GetNativeWindow()); |
78 login_display_->Init(screen_locker()->users(), false, true, false); | 100 login_display_->Init(screen_locker()->users(), false, true, false); |
79 | 101 |
80 static_cast<OobeUI*>(GetWebUI()->GetController())->ShowSigninScreen( | 102 GetOobeUI()->ShowSigninScreen( |
81 LoginScreenContext(), login_display_.get(), login_display_.get()); | 103 LoginScreenContext(), login_display_.get(), login_display_.get()); |
82 | 104 |
83 registrar_.Add(this, | 105 registrar_.Add(this, |
84 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, | 106 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, |
85 content::NotificationService::AllSources()); | 107 content::NotificationService::AllSources()); |
| 108 |
| 109 if (login::LockScrollIntoViewEnabled()) |
| 110 DisableKeyboardOverscroll(); |
86 } | 111 } |
87 | 112 |
88 void WebUIScreenLocker::ScreenLockReady() { | 113 void WebUIScreenLocker::ScreenLockReady() { |
89 UMA_HISTOGRAM_TIMES("LockScreen.LockReady", | 114 UMA_HISTOGRAM_TIMES("LockScreen.LockReady", |
90 base::TimeTicks::Now() - lock_time_); | 115 base::TimeTicks::Now() - lock_time_); |
91 ScreenLockerDelegate::ScreenLockReady(); | 116 ScreenLockerDelegate::ScreenLockReady(); |
92 SetInputEnabled(true); | 117 SetInputEnabled(true); |
93 } | 118 } |
94 | 119 |
95 void WebUIScreenLocker::OnAuthenticate() { | 120 void WebUIScreenLocker::OnAuthenticate() { |
(...skipping 42 matching lines...) Loading... |
138 if (lock_window_) { | 163 if (lock_window_) { |
139 lock_window_->RemoveObserver(this); | 164 lock_window_->RemoveObserver(this); |
140 lock_window_->Close(); | 165 lock_window_->Close(); |
141 } | 166 } |
142 // If LockScreen() was called, we need to clear the signin screen handler | 167 // If LockScreen() was called, we need to clear the signin screen handler |
143 // delegate set in ShowSigninScreen so that it no longer points to us. | 168 // delegate set in ShowSigninScreen so that it no longer points to us. |
144 if (login_display_.get()) { | 169 if (login_display_.get()) { |
145 static_cast<OobeUI*>(GetWebUI()->GetController())-> | 170 static_cast<OobeUI*>(GetWebUI()->GetController())-> |
146 ResetSigninScreenHandlerDelegate(); | 171 ResetSigninScreenHandlerDelegate(); |
147 } | 172 } |
| 173 |
| 174 if (keyboard::KeyboardController::GetInstance() && is_observing_keyboard_) { |
| 175 keyboard::KeyboardController::GetInstance()->RemoveObserver(this); |
| 176 is_observing_keyboard_ = false; |
| 177 } |
| 178 |
| 179 ash::Shell::GetInstance()->delegate()-> |
| 180 RemoveVirtualKeyboardStateObserver(this); |
| 181 |
| 182 if (login::LockScrollIntoViewEnabled()) |
| 183 ResetKeyboardOverscrollOverride(); |
148 } | 184 } |
149 | 185 |
150 void WebUIScreenLocker::OnLockWebUIReady() { | 186 void WebUIScreenLocker::OnLockWebUIReady() { |
151 VLOG(1) << "WebUI ready; lock window is " | 187 VLOG(1) << "WebUI ready; lock window is " |
152 << (lock_ready_ ? "too" : "not"); | 188 << (lock_ready_ ? "too" : "not"); |
153 webui_ready_ = true; | 189 webui_ready_ = true; |
154 if (lock_ready_) | 190 if (lock_ready_) |
155 ScreenLockReady(); | 191 ScreenLockReady(); |
156 } | 192 } |
157 | 193 |
158 void WebUIScreenLocker::OnLockBackgroundDisplayed() { | 194 void WebUIScreenLocker::OnLockBackgroundDisplayed() { |
159 UMA_HISTOGRAM_TIMES("LockScreen.BackgroundReady", | 195 UMA_HISTOGRAM_TIMES("LockScreen.BackgroundReady", |
160 base::TimeTicks::Now() - lock_time_); | 196 base::TimeTicks::Now() - lock_time_); |
161 } | 197 } |
162 | 198 |
| 199 OobeUI* WebUIScreenLocker::GetOobeUI() { |
| 200 return static_cast<OobeUI*>(GetWebUI()->GetController()); |
| 201 } |
| 202 |
163 //////////////////////////////////////////////////////////////////////////////// | 203 //////////////////////////////////////////////////////////////////////////////// |
164 // WebUIScreenLocker, content::NotificationObserver implementation: | 204 // WebUIScreenLocker, content::NotificationObserver implementation: |
165 | 205 |
166 void WebUIScreenLocker::Observe( | 206 void WebUIScreenLocker::Observe( |
167 int type, | 207 int type, |
168 const content::NotificationSource& source, | 208 const content::NotificationSource& source, |
169 const content::NotificationDetails& details) { | 209 const content::NotificationDetails& details) { |
170 switch (type) { | 210 switch (type) { |
171 case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED: { | 211 case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED: { |
172 const User& user = *content::Details<User>(details).ptr(); | 212 const User& user = *content::Details<User>(details).ptr(); |
(...skipping 142 matching lines...) Loading... |
315 } | 355 } |
316 | 356 |
317 void WebUIScreenLocker::RenderProcessGone(base::TerminationStatus status) { | 357 void WebUIScreenLocker::RenderProcessGone(base::TerminationStatus status) { |
318 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID && | 358 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID && |
319 status != base::TERMINATION_STATUS_NORMAL_TERMINATION) { | 359 status != base::TERMINATION_STATUS_NORMAL_TERMINATION) { |
320 LOG(ERROR) << "Renderer crash on lock screen"; | 360 LOG(ERROR) << "Renderer crash on lock screen"; |
321 Signout(); | 361 Signout(); |
322 } | 362 } |
323 } | 363 } |
324 | 364 |
| 365 //////////////////////////////////////////////////////////////////////////////// |
| 366 // ash::KeyboardStateObserver overrides. |
| 367 |
| 368 void WebUIScreenLocker::OnVirtualKeyboardStateChanged(bool activated) { |
| 369 if (keyboard::KeyboardController::GetInstance()) { |
| 370 if (activated) { |
| 371 if (!is_observing_keyboard_) { |
| 372 keyboard::KeyboardController::GetInstance()->AddObserver(this); |
| 373 is_observing_keyboard_ = true; |
| 374 } |
| 375 } else { |
| 376 keyboard::KeyboardController::GetInstance()->RemoveObserver(this); |
| 377 is_observing_keyboard_ = false; |
| 378 } |
| 379 } |
| 380 } |
| 381 |
| 382 //////////////////////////////////////////////////////////////////////////////// |
| 383 // keyboard::KeyboardControllerObserver overrides. |
| 384 |
| 385 void WebUIScreenLocker::OnKeyboardBoundsChanging( |
| 386 const gfx::Rect& new_bounds) { |
| 387 if (new_bounds.IsEmpty() && !keyboard_bounds_.IsEmpty()) { |
| 388 // Keyboard has been hidden. |
| 389 if (GetOobeUI()) { |
| 390 GetOobeUI()->GetCoreOobeActor()->ShowControlBar(true); |
| 391 if (login::LockScrollIntoViewEnabled()) |
| 392 GetOobeUI()->GetCoreOobeActor()->SetKeyboardState(false, new_bounds); |
| 393 } |
| 394 } else if (!new_bounds.IsEmpty() && keyboard_bounds_.IsEmpty()) { |
| 395 // Keyboard has been shown. |
| 396 if (GetOobeUI()) { |
| 397 GetOobeUI()->GetCoreOobeActor()->ShowControlBar(false); |
| 398 if (login::LockScrollIntoViewEnabled()) |
| 399 GetOobeUI()->GetCoreOobeActor()->SetKeyboardState(true, new_bounds); |
| 400 } |
| 401 } |
| 402 |
| 403 keyboard_bounds_ = new_bounds; |
| 404 } |
| 405 |
325 } // namespace chromeos | 406 } // namespace chromeos |
OLD | NEW |