| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/screen_locker.h" | 5 #include "chrome/browser/chromeos/login/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/authenticator.h" | 28 #include "chrome/browser/chromeos/login/authenticator.h" |
| 29 #include "chrome/browser/chromeos/login/extended_authenticator.h" | 29 #include "chrome/browser/chromeos/login/extended_authenticator.h" |
| 30 #include "chrome/browser/chromeos/login/login_performer.h" | 30 #include "chrome/browser/chromeos/login/login_performer.h" |
| 31 #include "chrome/browser/chromeos/login/login_utils.h" | 31 #include "chrome/browser/chromeos/login/login_utils.h" |
| 32 #include "chrome/browser/chromeos/login/managed/supervised_user_authentication.h
" | 32 #include "chrome/browser/chromeos/login/managed/supervised_user_authentication.h
" |
| 33 #include "chrome/browser/chromeos/login/supervised_user_manager.h" | 33 #include "chrome/browser/chromeos/login/supervised_user_manager.h" |
| 34 #include "chrome/browser/chromeos/login/user_adding_screen.h" | 34 #include "chrome/browser/chromeos/login/user_adding_screen.h" |
| 35 #include "chrome/browser/chromeos/login/user_manager.h" | 35 #include "chrome/browser/chromeos/login/user_manager.h" |
| 36 #include "chrome/browser/chromeos/login/webui_screen_locker.h" | 36 #include "chrome/browser/chromeos/login/webui_screen_locker.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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 } | 249 } |
| 284 | 250 |
| 285 void ScreenLocker::Authenticate(const UserContext& user_context) { | 251 void ScreenLocker::Authenticate(const UserContext& user_context) { |
| 286 LOG_ASSERT(IsUserLoggedIn(user_context.GetUserID())) | 252 LOG_ASSERT(IsUserLoggedIn(user_context.GetUserID())) |
| 287 << "Invalid user trying to unlock."; | 253 << "Invalid user trying to unlock."; |
| 288 | 254 |
| 289 authentication_start_time_ = base::Time::Now(); | 255 authentication_start_time_ = base::Time::Now(); |
| 290 delegate_->SetInputEnabled(false); | 256 delegate_->SetInputEnabled(false); |
| 291 delegate_->OnAuthenticate(); | 257 delegate_->OnAuthenticate(); |
| 292 | 258 |
| 293 // Send authentication request to chrome.screenlockPrivate API event router | |
| 294 // if the authentication type is not the system password. | |
| 295 LoginDisplay::AuthType auth_type = | |
| 296 FromLockHandlerAuthType(GetAuthType(user_context.GetUserID())); | |
| 297 if (auth_type != LoginDisplay::OFFLINE_PASSWORD) { | |
| 298 const User* unlock_user = FindUnlockUser(user_context.GetUserID()); | |
| 299 LOG_ASSERT(unlock_user); | |
| 300 | |
| 301 Profile* profile = UserManager::Get()->GetProfileByUser(unlock_user); | |
| 302 extensions::ScreenlockPrivateEventRouter* router = | |
| 303 extensions::ScreenlockPrivateEventRouter::GetFactoryInstance()->Get( | |
| 304 profile); | |
| 305 router->OnAuthAttempted(ToLockHandlerAuthType(auth_type), | |
| 306 user_context.GetPassword()); | |
| 307 return; | |
| 308 } | |
| 309 | |
| 310 // Special case: supervised users. Use special authenticator. | 259 // Special case: supervised users. Use special authenticator. |
| 311 if (const User* user = FindUnlockUser(user_context.GetUserID())) { | 260 if (const User* user = FindUnlockUser(user_context.GetUserID())) { |
| 312 if (user->GetType() == User::USER_TYPE_LOCALLY_MANAGED) { | 261 if (user->GetType() == User::USER_TYPE_LOCALLY_MANAGED) { |
| 313 UserContext updated_context = | 262 UserContext updated_context = |
| 314 UserManager::Get() | 263 UserManager::Get() |
| 315 ->GetSupervisedUserManager() | 264 ->GetSupervisedUserManager() |
| 316 ->GetAuthentication() | 265 ->GetAuthentication() |
| 317 ->TransformPasswordInContext(user_context); | 266 ->TransformPasswordInContext(user_context); |
| 318 // TODO(antrim) : replace empty closure with explicit method. | 267 // TODO(antrim) : replace empty closure with explicit method. |
| 319 // http://crbug.com/351268 | 268 // http://crbug.com/351268 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 delegate_->ClearErrors(); | 305 delegate_->ClearErrors(); |
| 357 content::RecordAction(UserMetricsAction("ScreenLocker_Signout")); | 306 content::RecordAction(UserMetricsAction("ScreenLocker_Signout")); |
| 358 // We expect that this call will not wait for any user input. | 307 // We expect that this call will not wait for any user input. |
| 359 // If it changes at some point, we will need to force exit. | 308 // If it changes at some point, we will need to force exit. |
| 360 chrome::AttemptUserExit(); | 309 chrome::AttemptUserExit(); |
| 361 | 310 |
| 362 // Don't hide yet the locker because the chrome screen may become visible | 311 // Don't hide yet the locker because the chrome screen may become visible |
| 363 // briefly. | 312 // briefly. |
| 364 } | 313 } |
| 365 | 314 |
| 366 void ScreenLocker::ShowBannerMessage(const std::string& message) { | |
| 367 delegate_->ShowBannerMessage(message); | |
| 368 } | |
| 369 | |
| 370 void ScreenLocker::ShowUserPodButton(const std::string& username, | |
| 371 const gfx::Image& icon, | |
| 372 const base::Closure& click_callback) { | |
| 373 if (!locked_) | |
| 374 return; | |
| 375 | |
| 376 screenlock_icon_provider_->AddIcon(username, icon); | |
| 377 | |
| 378 if (!username.empty()) { | |
| 379 // Append the current time to the URL so the image will not be cached. | |
| 380 std::string icon_url = | |
| 381 ScreenlockIconSource::GetIconURLForUser(username) + "?uniq=" + | |
| 382 base::Int64ToString(base::Time::Now().ToInternalValue()); | |
| 383 delegate_->ShowUserPodButton(username, icon_url, click_callback); | |
| 384 } | |
| 385 } | |
| 386 | |
| 387 void ScreenLocker::HideUserPodButton(const std::string& username) { | |
| 388 if (!locked_) | |
| 389 return; | |
| 390 screenlock_icon_provider_->RemoveIcon(username); | |
| 391 delegate_->HideUserPodButton(username); | |
| 392 } | |
| 393 | |
| 394 void ScreenLocker::EnableInput() { | 315 void ScreenLocker::EnableInput() { |
| 395 delegate_->SetInputEnabled(true); | 316 delegate_->SetInputEnabled(true); |
| 396 } | 317 } |
| 397 | 318 |
| 398 void ScreenLocker::SetAuthType( | |
| 399 const std::string& username, | |
| 400 ScreenlockBridge::LockHandler::AuthType auth_type, | |
| 401 const std::string& initial_value) { | |
| 402 if (!locked_) | |
| 403 return; | |
| 404 delegate_->SetAuthType( | |
| 405 username, FromLockHandlerAuthType(auth_type), initial_value); | |
| 406 } | |
| 407 | |
| 408 ScreenlockBridge::LockHandler::AuthType ScreenLocker::GetAuthType( | |
| 409 const std::string& username) const { | |
| 410 // Return default authentication type when not locked. | |
| 411 if (!locked_) | |
| 412 return ScreenlockBridge::LockHandler::OFFLINE_PASSWORD; | |
| 413 return ToLockHandlerAuthType(delegate_->GetAuthType(username)); | |
| 414 } | |
| 415 | |
| 416 void ScreenLocker::Unlock(const std::string& user_email) { | |
| 417 chromeos::ScreenLocker::Hide(); | |
| 418 } | |
| 419 | |
| 420 void ScreenLocker::ShowErrorMessage(int error_msg_id, | 319 void ScreenLocker::ShowErrorMessage(int error_msg_id, |
| 421 HelpAppLauncher::HelpTopic help_topic_id, | 320 HelpAppLauncher::HelpTopic help_topic_id, |
| 422 bool sign_out_only) { | 321 bool sign_out_only) { |
| 423 delegate_->SetInputEnabled(!sign_out_only); | 322 delegate_->SetInputEnabled(!sign_out_only); |
| 424 delegate_->ShowErrorMessage(error_msg_id, help_topic_id); | 323 delegate_->ShowErrorMessage(error_msg_id, help_topic_id); |
| 425 } | 324 } |
| 426 | 325 |
| 427 void ScreenLocker::SetLoginStatusConsumer( | 326 void ScreenLocker::SetLoginStatusConsumer( |
| 428 chromeos::LoginStatusConsumer* consumer) { | 327 chromeos::LoginStatusConsumer* consumer) { |
| 429 login_status_consumer_ = consumer; | 328 login_status_consumer_ = consumer; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 bool state = false; | 453 bool state = false; |
| 555 VLOG(1) << "Emitting SCREEN_LOCK_STATE_CHANGED with state=" << state; | 454 VLOG(1) << "Emitting SCREEN_LOCK_STATE_CHANGED with state=" << state; |
| 556 content::NotificationService::current()->Notify( | 455 content::NotificationService::current()->Notify( |
| 557 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, | 456 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, |
| 558 content::Source<ScreenLocker>(this), | 457 content::Source<ScreenLocker>(this), |
| 559 content::Details<bool>(&state)); | 458 content::Details<bool>(&state)); |
| 560 | 459 |
| 561 VLOG(1) << "Calling session manager's HandleLockScreenDismissed D-Bus method"; | 460 VLOG(1) << "Calling session manager's HandleLockScreenDismissed D-Bus method"; |
| 562 DBusThreadManager::Get()->GetSessionManagerClient()-> | 461 DBusThreadManager::Get()->GetSessionManagerClient()-> |
| 563 NotifyLockScreenDismissed(); | 462 NotifyLockScreenDismissed(); |
| 564 | |
| 565 ScreenlockBridge::Get()->SetLockHandler(NULL); | |
| 566 } | 463 } |
| 567 | 464 |
| 568 void ScreenLocker::SetAuthenticator(Authenticator* authenticator) { | 465 void ScreenLocker::SetAuthenticator(Authenticator* authenticator) { |
| 569 authenticator_ = authenticator; | 466 authenticator_ = authenticator; |
| 570 } | 467 } |
| 571 | 468 |
| 572 void ScreenLocker::ScreenLockReady() { | 469 void ScreenLocker::ScreenLockReady() { |
| 573 locked_ = true; | 470 locked_ = true; |
| 574 base::TimeDelta delta = base::Time::Now() - start_time_; | 471 base::TimeDelta delta = base::Time::Now() - start_time_; |
| 575 VLOG(1) << "ScreenLocker " << this << " is ready after " | 472 VLOG(1) << "ScreenLocker " << this << " is ready after " |
| 576 << delta.InSecondsF() << " second(s)"; | 473 << delta.InSecondsF() << " second(s)"; |
| 577 UMA_HISTOGRAM_TIMES("ScreenLocker.ScreenLockTime", delta); | 474 UMA_HISTOGRAM_TIMES("ScreenLocker.ScreenLockTime", delta); |
| 578 | 475 |
| 579 VLOG(1) << "Moving desktop background to locked container"; | 476 VLOG(1) << "Moving desktop background to locked container"; |
| 580 ash::Shell::GetInstance()-> | 477 ash::Shell::GetInstance()-> |
| 581 desktop_background_controller()->MoveDesktopToLockedContainer(); | 478 desktop_background_controller()->MoveDesktopToLockedContainer(); |
| 582 | 479 |
| 583 bool state = true; | 480 bool state = true; |
| 584 VLOG(1) << "Emitting SCREEN_LOCK_STATE_CHANGED with state=" << state; | 481 VLOG(1) << "Emitting SCREEN_LOCK_STATE_CHANGED with state=" << state; |
| 585 content::NotificationService::current()->Notify( | 482 content::NotificationService::current()->Notify( |
| 586 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, | 483 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, |
| 587 content::Source<ScreenLocker>(this), | 484 content::Source<ScreenLocker>(this), |
| 588 content::Details<bool>(&state)); | 485 content::Details<bool>(&state)); |
| 589 VLOG(1) << "Calling session manager's HandleLockScreenShown D-Bus method"; | 486 VLOG(1) << "Calling session manager's HandleLockScreenShown D-Bus method"; |
| 590 DBusThreadManager::Get()->GetSessionManagerClient()->NotifyLockScreenShown(); | 487 DBusThreadManager::Get()->GetSessionManagerClient()->NotifyLockScreenShown(); |
| 591 | |
| 592 ScreenlockBridge::Get()->SetLockHandler(this); | |
| 593 } | 488 } |
| 594 | 489 |
| 595 content::WebUI* ScreenLocker::GetAssociatedWebUI() { | 490 content::WebUI* ScreenLocker::GetAssociatedWebUI() { |
| 596 return delegate_->GetAssociatedWebUI(); | 491 return delegate_->GetAssociatedWebUI(); |
| 597 } | 492 } |
| 598 | 493 |
| 599 bool ScreenLocker::IsUserLoggedIn(const std::string& username) { | 494 bool ScreenLocker::IsUserLoggedIn(const std::string& username) { |
| 600 for (UserList::const_iterator it = users_.begin(); it != users_.end(); ++it) { | 495 for (UserList::const_iterator it = users_.begin(); it != users_.end(); ++it) { |
| 601 if ((*it)->email() == username) | 496 if ((*it)->email() == username) |
| 602 return true; | 497 return true; |
| 603 } | 498 } |
| 604 return false; | 499 return false; |
| 605 } | 500 } |
| 606 | 501 |
| 607 } // namespace chromeos | 502 } // namespace chromeos |
| OLD | NEW |