Chromium Code Reviews| 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 20 matching lines...) Expand all Loading... | |
| 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" | 37 #include "chrome/browser/extensions/api/screenlock_private/screenlock_private_ap i.h" |
| 38 #include "chrome/browser/lifetime/application_lifetime.h" | 38 #include "chrome/browser/lifetime/application_lifetime.h" |
| 39 #include "chrome/browser/profiles/profile.h" | 39 #include "chrome/browser/profiles/profile.h" |
| 40 #include "chrome/browser/profiles/profile_manager.h" | 40 #include "chrome/browser/profiles/profile_manager.h" |
| 41 #include "chrome/browser/signin/screenlock_bridge.h" | |
| 41 #include "chrome/browser/signin/signin_manager_factory.h" | 42 #include "chrome/browser/signin/signin_manager_factory.h" |
| 42 #include "chrome/browser/sync/profile_sync_service.h" | 43 #include "chrome/browser/sync/profile_sync_service.h" |
| 43 #include "chrome/browser/sync/profile_sync_service_factory.h" | 44 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 44 #include "chrome/browser/ui/webui/chromeos/login/screenlock_icon_provider.h" | 45 #include "chrome/browser/ui/webui/chromeos/login/screenlock_icon_provider.h" |
| 45 #include "chrome/browser/ui/webui/chromeos/login/screenlock_icon_source.h" | 46 #include "chrome/browser/ui/webui/chromeos/login/screenlock_icon_source.h" |
| 46 #include "chrome/common/chrome_switches.h" | 47 #include "chrome/common/chrome_switches.h" |
| 47 #include "chromeos/audio/chromeos_sounds.h" | 48 #include "chromeos/audio/chromeos_sounds.h" |
| 48 #include "chromeos/dbus/dbus_thread_manager.h" | 49 #include "chromeos/dbus/dbus_thread_manager.h" |
| 49 #include "chromeos/dbus/session_manager_client.h" | 50 #include "chromeos/dbus/session_manager_client.h" |
| 50 #include "components/signin/core/browser/signin_manager.h" | 51 #include "components/signin/core/browser/signin_manager.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 | 117 |
| 117 private: | 118 private: |
| 118 bool session_started_; | 119 bool session_started_; |
| 119 content::NotificationRegistrar registrar_; | 120 content::NotificationRegistrar registrar_; |
| 120 | 121 |
| 121 DISALLOW_COPY_AND_ASSIGN(ScreenLockObserver); | 122 DISALLOW_COPY_AND_ASSIGN(ScreenLockObserver); |
| 122 }; | 123 }; |
| 123 | 124 |
| 124 ScreenLockObserver* g_screen_lock_observer = NULL; | 125 ScreenLockObserver* g_screen_lock_observer = NULL; |
| 125 | 126 |
| 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 | 127 } // namespace |
| 160 | 128 |
| 161 // static | 129 // static |
| 162 ScreenLocker* ScreenLocker::screen_locker_ = NULL; | 130 ScreenLocker* ScreenLocker::screen_locker_ = NULL; |
| 163 | 131 |
| 164 ////////////////////////////////////////////////////////////////////////////// | 132 ////////////////////////////////////////////////////////////////////////////// |
| 165 // ScreenLocker, public: | 133 // ScreenLocker, public: |
| 166 | 134 |
| 167 ScreenLocker::ScreenLocker(const UserList& users) | 135 ScreenLocker::ScreenLocker(const UserList& users) |
| 168 : users_(users), | 136 : users_(users), |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 void ScreenLocker::Authenticate(const UserContext& user_context) { | 253 void ScreenLocker::Authenticate(const UserContext& user_context) { |
| 286 LOG_ASSERT(IsUserLoggedIn(user_context.GetUserID())) | 254 LOG_ASSERT(IsUserLoggedIn(user_context.GetUserID())) |
| 287 << "Invalid user trying to unlock."; | 255 << "Invalid user trying to unlock."; |
| 288 | 256 |
| 289 authentication_start_time_ = base::Time::Now(); | 257 authentication_start_time_ = base::Time::Now(); |
| 290 delegate_->SetInputEnabled(false); | 258 delegate_->SetInputEnabled(false); |
| 291 delegate_->OnAuthenticate(); | 259 delegate_->OnAuthenticate(); |
| 292 | 260 |
| 293 // Send authentication request to chrome.screenlockPrivate API event router | 261 // Send authentication request to chrome.screenlockPrivate API event router |
| 294 // if the authentication type is not the system password. | 262 // if the authentication type is not the system password. |
| 295 LoginDisplay::AuthType auth_type = | 263 ScreenlockBridge::LockHandler::AuthType auth_type = |
| 296 FromLockHandlerAuthType(GetAuthType(user_context.GetUserID())); | 264 ScreenlockBridge::Get()->lock_handler()->GetAuthType( |
| 297 if (auth_type != LoginDisplay::OFFLINE_PASSWORD) { | 265 user_context.GetUserID()); |
| 266 if (auth_type != ScreenlockBridge::LockHandler::OFFLINE_PASSWORD) { | |
|
Tim Song
2014/05/16 18:38:47
Does it still make sense to wire up the OnAuthAtte
xiyuan
2014/05/16 23:00:56
Done.
| |
| 298 const User* unlock_user = FindUnlockUser(user_context.GetUserID()); | 267 const User* unlock_user = FindUnlockUser(user_context.GetUserID()); |
| 299 LOG_ASSERT(unlock_user); | 268 LOG_ASSERT(unlock_user); |
| 300 | 269 |
| 301 Profile* profile = UserManager::Get()->GetProfileByUser(unlock_user); | 270 Profile* profile = UserManager::Get()->GetProfileByUser(unlock_user); |
| 302 extensions::ScreenlockPrivateEventRouter* router = | 271 extensions::ScreenlockPrivateEventRouter* router = |
| 303 extensions::ScreenlockPrivateEventRouter::GetFactoryInstance()->Get( | 272 extensions::ScreenlockPrivateEventRouter::GetFactoryInstance()->Get( |
| 304 profile); | 273 profile); |
| 305 router->OnAuthAttempted(ToLockHandlerAuthType(auth_type), | 274 router->OnAuthAttempted(auth_type, |
| 306 user_context.GetPassword()); | 275 user_context.GetPassword()); |
| 307 return; | 276 return; |
| 308 } | 277 } |
| 309 | 278 |
| 310 // Special case: supervised users. Use special authenticator. | 279 // Special case: supervised users. Use special authenticator. |
| 311 if (const User* user = FindUnlockUser(user_context.GetUserID())) { | 280 if (const User* user = FindUnlockUser(user_context.GetUserID())) { |
| 312 if (user->GetType() == User::USER_TYPE_LOCALLY_MANAGED) { | 281 if (user->GetType() == User::USER_TYPE_LOCALLY_MANAGED) { |
| 313 UserContext updated_context = | 282 UserContext updated_context = |
| 314 UserManager::Get() | 283 UserManager::Get() |
| 315 ->GetSupervisedUserManager() | 284 ->GetSupervisedUserManager() |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 delegate_->ClearErrors(); | 325 delegate_->ClearErrors(); |
| 357 content::RecordAction(UserMetricsAction("ScreenLocker_Signout")); | 326 content::RecordAction(UserMetricsAction("ScreenLocker_Signout")); |
| 358 // We expect that this call will not wait for any user input. | 327 // 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. | 328 // If it changes at some point, we will need to force exit. |
| 360 chrome::AttemptUserExit(); | 329 chrome::AttemptUserExit(); |
| 361 | 330 |
| 362 // Don't hide yet the locker because the chrome screen may become visible | 331 // Don't hide yet the locker because the chrome screen may become visible |
| 363 // briefly. | 332 // briefly. |
| 364 } | 333 } |
| 365 | 334 |
| 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() { | 335 void ScreenLocker::EnableInput() { |
| 395 delegate_->SetInputEnabled(true); | 336 delegate_->SetInputEnabled(true); |
| 396 } | 337 } |
| 397 | 338 |
| 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, | 339 void ScreenLocker::ShowErrorMessage(int error_msg_id, |
| 421 HelpAppLauncher::HelpTopic help_topic_id, | 340 HelpAppLauncher::HelpTopic help_topic_id, |
| 422 bool sign_out_only) { | 341 bool sign_out_only) { |
| 423 delegate_->SetInputEnabled(!sign_out_only); | 342 delegate_->SetInputEnabled(!sign_out_only); |
| 424 delegate_->ShowErrorMessage(error_msg_id, help_topic_id); | 343 delegate_->ShowErrorMessage(error_msg_id, help_topic_id); |
| 425 } | 344 } |
| 426 | 345 |
| 427 void ScreenLocker::SetLoginStatusConsumer( | 346 void ScreenLocker::SetLoginStatusConsumer( |
| 428 chromeos::LoginStatusConsumer* consumer) { | 347 chromeos::LoginStatusConsumer* consumer) { |
| 429 login_status_consumer_ = consumer; | 348 login_status_consumer_ = consumer; |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 581 desktop_background_controller()->MoveDesktopToLockedContainer(); | 500 desktop_background_controller()->MoveDesktopToLockedContainer(); |
| 582 | 501 |
| 583 bool state = true; | 502 bool state = true; |
| 584 VLOG(1) << "Emitting SCREEN_LOCK_STATE_CHANGED with state=" << state; | 503 VLOG(1) << "Emitting SCREEN_LOCK_STATE_CHANGED with state=" << state; |
| 585 content::NotificationService::current()->Notify( | 504 content::NotificationService::current()->Notify( |
| 586 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, | 505 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, |
| 587 content::Source<ScreenLocker>(this), | 506 content::Source<ScreenLocker>(this), |
| 588 content::Details<bool>(&state)); | 507 content::Details<bool>(&state)); |
| 589 VLOG(1) << "Calling session manager's HandleLockScreenShown D-Bus method"; | 508 VLOG(1) << "Calling session manager's HandleLockScreenShown D-Bus method"; |
| 590 DBusThreadManager::Get()->GetSessionManagerClient()->NotifyLockScreenShown(); | 509 DBusThreadManager::Get()->GetSessionManagerClient()->NotifyLockScreenShown(); |
| 591 | |
| 592 ScreenlockBridge::Get()->SetLockHandler(this); | |
| 593 } | 510 } |
| 594 | 511 |
| 595 content::WebUI* ScreenLocker::GetAssociatedWebUI() { | 512 content::WebUI* ScreenLocker::GetAssociatedWebUI() { |
| 596 return delegate_->GetAssociatedWebUI(); | 513 return delegate_->GetAssociatedWebUI(); |
| 597 } | 514 } |
| 598 | 515 |
| 599 bool ScreenLocker::IsUserLoggedIn(const std::string& username) { | 516 bool ScreenLocker::IsUserLoggedIn(const std::string& username) { |
| 600 for (UserList::const_iterator it = users_.begin(); it != users_.end(); ++it) { | 517 for (UserList::const_iterator it = users_.begin(); it != users_.end(); ++it) { |
| 601 if ((*it)->email() == username) | 518 if ((*it)->email() == username) |
| 602 return true; | 519 return true; |
| 603 } | 520 } |
| 604 return false; | 521 return false; |
| 605 } | 522 } |
| 606 | 523 |
| 607 } // namespace chromeos | 524 } // namespace chromeos |
| OLD | NEW |