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/screen_locker.h" | 5 #include "chrome/browser/chromeos/login/lock/screen_locker.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "chrome/browser/chrome_notification_types.h" | 27 #include "chrome/browser/chrome_notification_types.h" |
28 #include "chrome/browser/chromeos/login/auth/authenticator.h" | 28 #include "chrome/browser/chromeos/login/auth/authenticator.h" |
29 #include "chrome/browser/chromeos/login/auth/extended_authenticator.h" | 29 #include "chrome/browser/chromeos/login/auth/extended_authenticator.h" |
30 #include "chrome/browser/chromeos/login/auth/login_performer.h" | 30 #include "chrome/browser/chromeos/login/auth/login_performer.h" |
31 #include "chrome/browser/chromeos/login/lock/webui_screen_locker.h" | 31 #include "chrome/browser/chromeos/login/lock/webui_screen_locker.h" |
32 #include "chrome/browser/chromeos/login/login_utils.h" | 32 #include "chrome/browser/chromeos/login/login_utils.h" |
33 #include "chrome/browser/chromeos/login/managed/supervised_user_authentication.h
" | 33 #include "chrome/browser/chromeos/login/managed/supervised_user_authentication.h
" |
34 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" | 34 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" |
35 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" | 35 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" |
36 #include "chrome/browser/chromeos/login/users/user_manager.h" | 36 #include "chrome/browser/chromeos/login/users/user_manager.h" |
37 #include "chrome/browser/extensions/api/screenlock_private/screenlock_private_ap
i.h" | |
38 #include "chrome/browser/lifetime/application_lifetime.h" | 37 #include "chrome/browser/lifetime/application_lifetime.h" |
39 #include "chrome/browser/profiles/profile.h" | 38 #include "chrome/browser/profiles/profile.h" |
40 #include "chrome/browser/profiles/profile_manager.h" | 39 #include "chrome/browser/profiles/profile_manager.h" |
41 #include "chrome/browser/signin/signin_manager_factory.h" | 40 #include "chrome/browser/signin/signin_manager_factory.h" |
42 #include "chrome/browser/sync/profile_sync_service.h" | 41 #include "chrome/browser/sync/profile_sync_service.h" |
43 #include "chrome/browser/sync/profile_sync_service_factory.h" | 42 #include "chrome/browser/sync/profile_sync_service_factory.h" |
44 #include "chrome/browser/ui/webui/chromeos/login/screenlock_icon_provider.h" | 43 #include "chrome/browser/ui/webui/chromeos/login/screenlock_icon_provider.h" |
45 #include "chrome/browser/ui/webui/chromeos/login/screenlock_icon_source.h" | 44 #include "chrome/browser/ui/webui/chromeos/login/screenlock_icon_source.h" |
46 #include "chrome/common/chrome_switches.h" | 45 #include "chrome/common/chrome_switches.h" |
47 #include "chromeos/audio/chromeos_sounds.h" | 46 #include "chromeos/audio/chromeos_sounds.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 115 |
117 private: | 116 private: |
118 bool session_started_; | 117 bool session_started_; |
119 content::NotificationRegistrar registrar_; | 118 content::NotificationRegistrar registrar_; |
120 | 119 |
121 DISALLOW_COPY_AND_ASSIGN(ScreenLockObserver); | 120 DISALLOW_COPY_AND_ASSIGN(ScreenLockObserver); |
122 }; | 121 }; |
123 | 122 |
124 ScreenLockObserver* g_screen_lock_observer = NULL; | 123 ScreenLockObserver* g_screen_lock_observer = NULL; |
125 | 124 |
126 // TODO(xiyuan): Get rid of LoginDisplay::AuthType and the mappers below. | |
127 ScreenlockBridge::LockHandler::AuthType ToLockHandlerAuthType( | |
128 LoginDisplay::AuthType auth_type) { | |
129 switch (auth_type) { | |
130 case LoginDisplay::OFFLINE_PASSWORD: | |
131 return ScreenlockBridge::LockHandler::OFFLINE_PASSWORD; | |
132 case LoginDisplay::ONLINE_SIGN_IN: | |
133 return ScreenlockBridge::LockHandler::ONLINE_SIGN_IN; | |
134 case LoginDisplay::NUMERIC_PIN: | |
135 return ScreenlockBridge::LockHandler::NUMERIC_PIN; | |
136 case LoginDisplay::USER_CLICK: | |
137 return ScreenlockBridge::LockHandler::USER_CLICK; | |
138 } | |
139 NOTREACHED(); | |
140 return ScreenlockBridge::LockHandler::OFFLINE_PASSWORD; | |
141 } | |
142 | |
143 LoginDisplay::AuthType FromLockHandlerAuthType( | |
144 ScreenlockBridge::LockHandler::AuthType auth_type) { | |
145 switch (auth_type) { | |
146 case ScreenlockBridge::LockHandler::OFFLINE_PASSWORD: | |
147 return LoginDisplay::OFFLINE_PASSWORD; | |
148 case ScreenlockBridge::LockHandler::ONLINE_SIGN_IN: | |
149 return LoginDisplay::ONLINE_SIGN_IN; | |
150 case ScreenlockBridge::LockHandler::NUMERIC_PIN: | |
151 return LoginDisplay::NUMERIC_PIN; | |
152 case ScreenlockBridge::LockHandler::USER_CLICK: | |
153 return LoginDisplay::USER_CLICK; | |
154 } | |
155 NOTREACHED(); | |
156 return LoginDisplay::OFFLINE_PASSWORD; | |
157 } | |
158 | |
159 } // namespace | 125 } // namespace |
160 | 126 |
161 // static | 127 // static |
162 ScreenLocker* ScreenLocker::screen_locker_ = NULL; | 128 ScreenLocker* ScreenLocker::screen_locker_ = NULL; |
163 | 129 |
164 ////////////////////////////////////////////////////////////////////////////// | 130 ////////////////////////////////////////////////////////////////////////////// |
165 // ScreenLocker, public: | 131 // ScreenLocker, public: |
166 | 132 |
167 ScreenLocker::ScreenLocker(const UserList& users) | 133 ScreenLocker::ScreenLocker(const UserList& users) |
168 : users_(users), | 134 : users_(users), |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 } | 244 } |
279 | 245 |
280 void ScreenLocker::Authenticate(const UserContext& user_context) { | 246 void ScreenLocker::Authenticate(const UserContext& user_context) { |
281 LOG_ASSERT(IsUserLoggedIn(user_context.GetUserID())) | 247 LOG_ASSERT(IsUserLoggedIn(user_context.GetUserID())) |
282 << "Invalid user trying to unlock."; | 248 << "Invalid user trying to unlock."; |
283 | 249 |
284 authentication_start_time_ = base::Time::Now(); | 250 authentication_start_time_ = base::Time::Now(); |
285 delegate_->SetInputEnabled(false); | 251 delegate_->SetInputEnabled(false); |
286 delegate_->OnAuthenticate(); | 252 delegate_->OnAuthenticate(); |
287 | 253 |
288 // Send authentication request to chrome.screenlockPrivate API event router | |
289 // if the authentication type is not the system password. | |
290 LoginDisplay::AuthType auth_type = | |
291 FromLockHandlerAuthType(GetAuthType(user_context.GetUserID())); | |
292 if (auth_type != LoginDisplay::OFFLINE_PASSWORD) { | |
293 const User* unlock_user = FindUnlockUser(user_context.GetUserID()); | |
294 LOG_ASSERT(unlock_user); | |
295 | |
296 Profile* profile = UserManager::Get()->GetProfileByUser(unlock_user); | |
297 extensions::ScreenlockPrivateEventRouter* router = | |
298 extensions::ScreenlockPrivateEventRouter::GetFactoryInstance()->Get( | |
299 profile); | |
300 router->OnAuthAttempted(ToLockHandlerAuthType(auth_type), | |
301 user_context.GetPassword()); | |
302 return; | |
303 } | |
304 | |
305 // Special case: supervised users. Use special authenticator. | 254 // Special case: supervised users. Use special authenticator. |
306 if (const User* user = FindUnlockUser(user_context.GetUserID())) { | 255 if (const User* user = FindUnlockUser(user_context.GetUserID())) { |
307 if (user->GetType() == User::USER_TYPE_LOCALLY_MANAGED) { | 256 if (user->GetType() == User::USER_TYPE_LOCALLY_MANAGED) { |
308 UserContext updated_context = | 257 UserContext updated_context = |
309 UserManager::Get() | 258 UserManager::Get() |
310 ->GetSupervisedUserManager() | 259 ->GetSupervisedUserManager() |
311 ->GetAuthentication() | 260 ->GetAuthentication() |
312 ->TransformPasswordInContext(user_context); | 261 ->TransformPasswordInContext(user_context); |
313 // TODO(antrim) : replace empty closure with explicit method. | 262 // TODO(antrim) : replace empty closure with explicit method. |
314 // http://crbug.com/351268 | 263 // http://crbug.com/351268 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 delegate_->ClearErrors(); | 300 delegate_->ClearErrors(); |
352 content::RecordAction(UserMetricsAction("ScreenLocker_Signout")); | 301 content::RecordAction(UserMetricsAction("ScreenLocker_Signout")); |
353 // We expect that this call will not wait for any user input. | 302 // We expect that this call will not wait for any user input. |
354 // If it changes at some point, we will need to force exit. | 303 // If it changes at some point, we will need to force exit. |
355 chrome::AttemptUserExit(); | 304 chrome::AttemptUserExit(); |
356 | 305 |
357 // Don't hide yet the locker because the chrome screen may become visible | 306 // Don't hide yet the locker because the chrome screen may become visible |
358 // briefly. | 307 // briefly. |
359 } | 308 } |
360 | 309 |
361 void ScreenLocker::ShowBannerMessage(const std::string& message) { | |
362 delegate_->ShowBannerMessage(message); | |
363 } | |
364 | |
365 void ScreenLocker::ShowUserPodButton(const std::string& username, | |
366 const gfx::Image& icon, | |
367 const base::Closure& click_callback) { | |
368 if (!locked_) | |
369 return; | |
370 | |
371 screenlock_icon_provider_->AddIcon(username, icon); | |
372 | |
373 if (!username.empty()) { | |
374 // Append the current time to the URL so the image will not be cached. | |
375 std::string icon_url = | |
376 ScreenlockIconSource::GetIconURLForUser(username) + "?uniq=" + | |
377 base::Int64ToString(base::Time::Now().ToInternalValue()); | |
378 delegate_->ShowUserPodButton(username, icon_url, click_callback); | |
379 } | |
380 } | |
381 | |
382 void ScreenLocker::HideUserPodButton(const std::string& username) { | |
383 if (!locked_) | |
384 return; | |
385 screenlock_icon_provider_->RemoveIcon(username); | |
386 delegate_->HideUserPodButton(username); | |
387 } | |
388 | |
389 void ScreenLocker::EnableInput() { | 310 void ScreenLocker::EnableInput() { |
390 delegate_->SetInputEnabled(true); | 311 delegate_->SetInputEnabled(true); |
391 } | 312 } |
392 | 313 |
393 void ScreenLocker::SetAuthType( | |
394 const std::string& username, | |
395 ScreenlockBridge::LockHandler::AuthType auth_type, | |
396 const std::string& initial_value) { | |
397 if (!locked_) | |
398 return; | |
399 delegate_->SetAuthType( | |
400 username, FromLockHandlerAuthType(auth_type), initial_value); | |
401 } | |
402 | |
403 ScreenlockBridge::LockHandler::AuthType ScreenLocker::GetAuthType( | |
404 const std::string& username) const { | |
405 // Return default authentication type when not locked. | |
406 if (!locked_) | |
407 return ScreenlockBridge::LockHandler::OFFLINE_PASSWORD; | |
408 return ToLockHandlerAuthType(delegate_->GetAuthType(username)); | |
409 } | |
410 | |
411 void ScreenLocker::Unlock(const std::string& user_email) { | |
412 chromeos::ScreenLocker::Hide(); | |
413 } | |
414 | |
415 void ScreenLocker::ShowErrorMessage(int error_msg_id, | 314 void ScreenLocker::ShowErrorMessage(int error_msg_id, |
416 HelpAppLauncher::HelpTopic help_topic_id, | 315 HelpAppLauncher::HelpTopic help_topic_id, |
417 bool sign_out_only) { | 316 bool sign_out_only) { |
418 delegate_->SetInputEnabled(!sign_out_only); | 317 delegate_->SetInputEnabled(!sign_out_only); |
419 delegate_->ShowErrorMessage(error_msg_id, help_topic_id); | 318 delegate_->ShowErrorMessage(error_msg_id, help_topic_id); |
420 } | 319 } |
421 | 320 |
422 void ScreenLocker::SetLoginStatusConsumer( | 321 void ScreenLocker::SetLoginStatusConsumer( |
423 chromeos::LoginStatusConsumer* consumer) { | 322 chromeos::LoginStatusConsumer* consumer) { |
424 login_status_consumer_ = consumer; | 323 login_status_consumer_ = consumer; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 bool state = false; | 448 bool state = false; |
550 VLOG(1) << "Emitting SCREEN_LOCK_STATE_CHANGED with state=" << state; | 449 VLOG(1) << "Emitting SCREEN_LOCK_STATE_CHANGED with state=" << state; |
551 content::NotificationService::current()->Notify( | 450 content::NotificationService::current()->Notify( |
552 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, | 451 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, |
553 content::Source<ScreenLocker>(this), | 452 content::Source<ScreenLocker>(this), |
554 content::Details<bool>(&state)); | 453 content::Details<bool>(&state)); |
555 | 454 |
556 VLOG(1) << "Calling session manager's HandleLockScreenDismissed D-Bus method"; | 455 VLOG(1) << "Calling session manager's HandleLockScreenDismissed D-Bus method"; |
557 DBusThreadManager::Get()->GetSessionManagerClient()-> | 456 DBusThreadManager::Get()->GetSessionManagerClient()-> |
558 NotifyLockScreenDismissed(); | 457 NotifyLockScreenDismissed(); |
559 | |
560 ScreenlockBridge::Get()->SetLockHandler(NULL); | |
561 } | 458 } |
562 | 459 |
563 void ScreenLocker::SetAuthenticator(Authenticator* authenticator) { | 460 void ScreenLocker::SetAuthenticator(Authenticator* authenticator) { |
564 authenticator_ = authenticator; | 461 authenticator_ = authenticator; |
565 } | 462 } |
566 | 463 |
567 void ScreenLocker::ScreenLockReady() { | 464 void ScreenLocker::ScreenLockReady() { |
568 locked_ = true; | 465 locked_ = true; |
569 base::TimeDelta delta = base::Time::Now() - start_time_; | 466 base::TimeDelta delta = base::Time::Now() - start_time_; |
570 VLOG(1) << "ScreenLocker " << this << " is ready after " | 467 VLOG(1) << "ScreenLocker " << this << " is ready after " |
571 << delta.InSecondsF() << " second(s)"; | 468 << delta.InSecondsF() << " second(s)"; |
572 UMA_HISTOGRAM_TIMES("ScreenLocker.ScreenLockTime", delta); | 469 UMA_HISTOGRAM_TIMES("ScreenLocker.ScreenLockTime", delta); |
573 | 470 |
574 VLOG(1) << "Moving desktop background to locked container"; | 471 VLOG(1) << "Moving desktop background to locked container"; |
575 ash::Shell::GetInstance()-> | 472 ash::Shell::GetInstance()-> |
576 desktop_background_controller()->MoveDesktopToLockedContainer(); | 473 desktop_background_controller()->MoveDesktopToLockedContainer(); |
577 | 474 |
578 bool state = true; | 475 bool state = true; |
579 VLOG(1) << "Emitting SCREEN_LOCK_STATE_CHANGED with state=" << state; | 476 VLOG(1) << "Emitting SCREEN_LOCK_STATE_CHANGED with state=" << state; |
580 content::NotificationService::current()->Notify( | 477 content::NotificationService::current()->Notify( |
581 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, | 478 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, |
582 content::Source<ScreenLocker>(this), | 479 content::Source<ScreenLocker>(this), |
583 content::Details<bool>(&state)); | 480 content::Details<bool>(&state)); |
584 VLOG(1) << "Calling session manager's HandleLockScreenShown D-Bus method"; | 481 VLOG(1) << "Calling session manager's HandleLockScreenShown D-Bus method"; |
585 DBusThreadManager::Get()->GetSessionManagerClient()->NotifyLockScreenShown(); | 482 DBusThreadManager::Get()->GetSessionManagerClient()->NotifyLockScreenShown(); |
586 | |
587 ScreenlockBridge::Get()->SetLockHandler(this); | |
588 } | 483 } |
589 | 484 |
590 content::WebUI* ScreenLocker::GetAssociatedWebUI() { | 485 content::WebUI* ScreenLocker::GetAssociatedWebUI() { |
591 return delegate_->GetAssociatedWebUI(); | 486 return delegate_->GetAssociatedWebUI(); |
592 } | 487 } |
593 | 488 |
594 bool ScreenLocker::IsUserLoggedIn(const std::string& username) { | 489 bool ScreenLocker::IsUserLoggedIn(const std::string& username) { |
595 for (UserList::const_iterator it = users_.begin(); it != users_.end(); ++it) { | 490 for (UserList::const_iterator it = users_.begin(); it != users_.end(); ++it) { |
596 if ((*it)->email() == username) | 491 if ((*it)->email() == username) |
597 return true; | 492 return true; |
598 } | 493 } |
599 return false; | 494 return false; |
600 } | 495 } |
601 | 496 |
602 } // namespace chromeos | 497 } // namespace chromeos |
OLD | NEW |