| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/webui/signin/user_manager_screen_handler.h" | 5 #include "chrome/browser/ui/webui/signin/user_manager_screen_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/value_conversions.h" | 10 #include "base/value_conversions.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 if (avatar_image.Width() <= profiles::kAvatarIconWidth || | 104 if (avatar_image.Width() <= profiles::kAvatarIconWidth || |
| 105 avatar_image.Height() <= profiles::kAvatarIconHeight ) { | 105 avatar_image.Height() <= profiles::kAvatarIconHeight ) { |
| 106 avatar_image = ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 106 avatar_image = ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 107 profiles::GetPlaceholderAvatarIconResourceID()); | 107 profiles::GetPlaceholderAvatarIconResourceID()); |
| 108 } | 108 } |
| 109 gfx::Image resized_image = profiles::GetSizedAvatarIcon( | 109 gfx::Image resized_image = profiles::GetSizedAvatarIcon( |
| 110 avatar_image, is_gaia_picture, kAvatarIconSize, kAvatarIconSize); | 110 avatar_image, is_gaia_picture, kAvatarIconSize, kAvatarIconSize); |
| 111 return webui::GetBitmapDataUrl(resized_image.AsBitmap()); | 111 return webui::GetBitmapDataUrl(resized_image.AsBitmap()); |
| 112 } | 112 } |
| 113 | 113 |
| 114 size_t GetIndexOfProfileWithEmailAndName(const ProfileInfoCache& info_cache, | 114 size_t GetIndexOfProfileWithEmail(const ProfileInfoCache& info_cache, |
| 115 const base::string16& email, | 115 const std::string& email) { |
| 116 const base::string16& name) { | 116 const base::string16& profile_email = base::UTF8ToUTF16(email); |
| 117 for (size_t i = 0; i < info_cache.GetNumberOfProfiles(); ++i) { | 117 for (size_t i = 0; i < info_cache.GetNumberOfProfiles(); ++i) { |
| 118 if (info_cache.GetUserNameOfProfileAtIndex(i) == email && | 118 if (info_cache.GetUserNameOfProfileAtIndex(i) == profile_email) |
| 119 (name.empty() || | |
| 120 profiles::GetAvatarNameForProfile( | |
| 121 info_cache.GetPathOfProfileAtIndex(i)) == name)) { | |
| 122 return i; | 119 return i; |
| 123 } | |
| 124 } | 120 } |
| 125 return std::string::npos; | 121 return std::string::npos; |
| 126 } | 122 } |
| 127 | 123 |
| 128 extensions::ScreenlockPrivateEventRouter* GetScreenlockRouter( | 124 extensions::ScreenlockPrivateEventRouter* GetScreenlockRouter( |
| 129 const std::string& email) { | 125 const std::string& email) { |
| 130 ProfileInfoCache& info_cache = | 126 const ProfileInfoCache& info_cache = |
| 131 g_browser_process->profile_manager()->GetProfileInfoCache(); | 127 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 132 const size_t profile_index = GetIndexOfProfileWithEmailAndName( | 128 const size_t profile_index = GetIndexOfProfileWithEmail(info_cache, email); |
| 133 info_cache, base::UTF8ToUTF16(email), base::string16()); | |
| 134 Profile* profile = g_browser_process->profile_manager() | 129 Profile* profile = g_browser_process->profile_manager() |
| 135 ->GetProfileByPath(info_cache.GetPathOfProfileAtIndex(profile_index)); | 130 ->GetProfileByPath(info_cache.GetPathOfProfileAtIndex(profile_index)); |
| 136 return extensions::ScreenlockPrivateEventRouter::GetFactoryInstance()->Get( | 131 return extensions::ScreenlockPrivateEventRouter::GetFactoryInstance()->Get( |
| 137 profile); | 132 profile); |
| 138 } | 133 } |
| 139 | 134 |
| 140 bool IsGuestModeEnabled() { | 135 bool IsGuestModeEnabled() { |
| 141 PrefService* service = g_browser_process->local_state(); | 136 PrefService* service = g_browser_process->local_state(); |
| 142 DCHECK(service); | 137 DCHECK(service); |
| 143 return service->GetBoolean(prefs::kBrowserGuestModeEnabled); | 138 return service->GetBoolean(prefs::kBrowserGuestModeEnabled); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 | 263 |
| 269 ScreenlockBridge::LockHandler::AuthType UserManagerScreenHandler::GetAuthType( | 264 ScreenlockBridge::LockHandler::AuthType UserManagerScreenHandler::GetAuthType( |
| 270 const std::string& user_email) const { | 265 const std::string& user_email) const { |
| 271 UserAuthTypeMap::const_iterator it = user_auth_type_map_.find(user_email); | 266 UserAuthTypeMap::const_iterator it = user_auth_type_map_.find(user_email); |
| 272 if (it == user_auth_type_map_.end()) | 267 if (it == user_auth_type_map_.end()) |
| 273 return ScreenlockBridge::LockHandler::OFFLINE_PASSWORD; | 268 return ScreenlockBridge::LockHandler::OFFLINE_PASSWORD; |
| 274 return it->second; | 269 return it->second; |
| 275 } | 270 } |
| 276 | 271 |
| 277 void UserManagerScreenHandler::Unlock(const std::string& user_email) { | 272 void UserManagerScreenHandler::Unlock(const std::string& user_email) { |
| 278 ProfileInfoCache& info_cache = | 273 const ProfileInfoCache& info_cache = |
| 279 g_browser_process->profile_manager()->GetProfileInfoCache(); | 274 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 280 const size_t profile_index = GetIndexOfProfileWithEmailAndName( | 275 const size_t profile_index = |
| 281 info_cache, base::UTF8ToUTF16(user_email), base::string16()); | 276 GetIndexOfProfileWithEmail(info_cache, user_email); |
| 282 DCHECK_LT(profile_index, info_cache.GetNumberOfProfiles()); | 277 DCHECK_LT(profile_index, info_cache.GetNumberOfProfiles()); |
| 283 | 278 |
| 284 authenticating_profile_index_ = profile_index; | 279 authenticating_profile_index_ = profile_index; |
| 285 ReportAuthenticationResult(true, ProfileMetrics::AUTH_LOCAL); | 280 ReportAuthenticationResult(true, ProfileMetrics::AUTH_LOCAL); |
| 286 } | 281 } |
| 287 | 282 |
| 288 void UserManagerScreenHandler::AttemptEasySignin( | 283 void UserManagerScreenHandler::AttemptEasySignin( |
| 289 const std::string& user_email, | 284 const std::string& user_email, |
| 290 const std::string& secret, | 285 const std::string& secret, |
| 291 const std::string& key_label) { | 286 const std::string& key_label) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 314 } | 309 } |
| 315 profiles::CreateAndSwitchToNewProfile( | 310 profiles::CreateAndSwitchToNewProfile( |
| 316 desktop_type_, | 311 desktop_type_, |
| 317 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, | 312 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, |
| 318 weak_ptr_factory_.GetWeakPtr()), | 313 weak_ptr_factory_.GetWeakPtr()), |
| 319 ProfileMetrics::ADD_NEW_USER_MANAGER); | 314 ProfileMetrics::ADD_NEW_USER_MANAGER); |
| 320 } | 315 } |
| 321 | 316 |
| 322 void UserManagerScreenHandler::HandleAuthenticatedLaunchUser( | 317 void UserManagerScreenHandler::HandleAuthenticatedLaunchUser( |
| 323 const base::ListValue* args) { | 318 const base::ListValue* args) { |
| 324 base::string16 email_address; | 319 const base::Value* profile_path_value; |
| 325 if (!args->GetString(0, &email_address)) | 320 if (!args->Get(0, &profile_path_value)) |
| 326 return; | 321 return; |
| 327 | 322 |
| 328 base::string16 display_name; | 323 base::FilePath profile_path; |
| 329 if (!args->GetString(1, &display_name)) | 324 if (!base::GetValueAsFilePath(*profile_path_value, &profile_path)) |
| 325 return; |
| 326 |
| 327 base::string16 email_address; |
| 328 if (!args->GetString(1, &email_address)) |
| 330 return; | 329 return; |
| 331 | 330 |
| 332 std::string password; | 331 std::string password; |
| 333 if (!args->GetString(2, &password)) | 332 if (!args->GetString(2, &password)) |
| 334 return; | 333 return; |
| 335 | 334 |
| 336 ProfileInfoCache& info_cache = | 335 const ProfileInfoCache& info_cache = |
| 337 g_browser_process->profile_manager()->GetProfileInfoCache(); | 336 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 338 size_t profile_index = GetIndexOfProfileWithEmailAndName( | 337 size_t profile_index = info_cache.GetIndexOfProfileWithPath(profile_path); |
| 339 info_cache, email_address, display_name); | 338 |
| 340 if (profile_index >= info_cache.GetNumberOfProfiles()) { | 339 if (profile_index == std::string::npos) { |
| 341 NOTREACHED(); | 340 NOTREACHED(); |
| 342 return; | 341 return; |
| 343 } | 342 } |
| 344 | 343 |
| 345 authenticating_profile_index_ = profile_index; | 344 authenticating_profile_index_ = profile_index; |
| 346 if (!chrome::ValidateLocalAuthCredentials(profile_index, password)) { | 345 if (!chrome::ValidateLocalAuthCredentials(profile_index, password)) { |
| 347 // Make a second attempt via an on-line authentication call. This handles | 346 // Make a second attempt via an on-line authentication call. This handles |
| 348 // profiles that are missing sign-in credentials and also cases where the | 347 // profiles that are missing sign-in credentials and also cases where the |
| 349 // password has been changed externally. | 348 // password has been changed externally. |
| 350 client_login_.reset(new GaiaAuthFetcher( | 349 client_login_.reset(new GaiaAuthFetcher( |
| 351 this, | 350 this, |
| 352 GaiaConstants::kChromeSource, | 351 GaiaConstants::kChromeSource, |
| 353 web_ui()->GetWebContents()->GetBrowserContext()->GetRequestContext())); | 352 web_ui()->GetWebContents()->GetBrowserContext()->GetRequestContext())); |
| 354 std::string email_string; | 353 |
| 355 args->GetString(0, &email_string); | |
| 356 client_login_->StartClientLogin( | 354 client_login_->StartClientLogin( |
| 357 email_string, | 355 base::UTF16ToUTF8(email_address), |
| 358 password, | 356 password, |
| 359 GaiaConstants::kSyncService, | 357 GaiaConstants::kSyncService, |
| 360 std::string(), | 358 std::string(), |
| 361 std::string(), | 359 std::string(), |
| 362 GaiaAuthFetcher::HostedAccountsAllowed); | 360 GaiaAuthFetcher::HostedAccountsAllowed); |
| 363 password_attempt_ = password; | 361 password_attempt_ = password; |
| 364 return; | 362 return; |
| 365 } | 363 } |
| 366 | 364 |
| 367 ReportAuthenticationResult(true, ProfileMetrics::AUTH_LOCAL); | 365 ReportAuthenticationResult(true, ProfileMetrics::AUTH_LOCAL); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, | 399 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, |
| 402 weak_ptr_factory_.GetWeakPtr())); | 400 weak_ptr_factory_.GetWeakPtr())); |
| 403 } else { | 401 } else { |
| 404 // The UI should have prevented the user from allowing the selection of | 402 // The UI should have prevented the user from allowing the selection of |
| 405 // guest mode. | 403 // guest mode. |
| 406 NOTREACHED(); | 404 NOTREACHED(); |
| 407 } | 405 } |
| 408 } | 406 } |
| 409 | 407 |
| 410 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { | 408 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { |
| 411 base::string16 email_address; | 409 const base::Value* profile_path_value = NULL; |
| 412 base::string16 display_name; | 410 if (!args->Get(0, &profile_path_value)) |
| 411 return; |
| 413 | 412 |
| 414 if (!args->GetString(0, &email_address) || | 413 base::FilePath profile_path; |
| 415 !args->GetString(1, &display_name)) { | 414 if (!base::GetValueAsFilePath(*profile_path_value, &profile_path)) |
| 415 return; |
| 416 |
| 417 const ProfileInfoCache& info_cache = |
| 418 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 419 size_t profile_index = info_cache.GetIndexOfProfileWithPath(profile_path); |
| 420 |
| 421 if (profile_index == std::string::npos) { |
| 416 NOTREACHED(); | 422 NOTREACHED(); |
| 417 return; | 423 return; |
| 418 } | 424 } |
| 419 | |
| 420 ProfileInfoCache& info_cache = | |
| 421 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
| 422 size_t profile_index = GetIndexOfProfileWithEmailAndName( | |
| 423 info_cache, email_address, display_name); | |
| 424 | |
| 425 if (profile_index >= info_cache.GetNumberOfProfiles()) { | |
| 426 NOTREACHED(); | |
| 427 return; | |
| 428 } | |
| 429 | 425 |
| 430 // It's possible that a user breaks into the user-manager page using the | 426 // It's possible that a user breaks into the user-manager page using the |
| 431 // JavaScript Inspector and causes a "locked" profile to call this | 427 // JavaScript Inspector and causes a "locked" profile to call this |
| 432 // unauthenticated version of "launch" instead of the proper one. Thus, | 428 // unauthenticated version of "launch" instead of the proper one. Thus, |
| 433 // we have to validate in (secure) C++ code that it really is a profile | 429 // we have to validate in (secure) C++ code that it really is a profile |
| 434 // not needing authentication. If it is, just ignore the "launch" request. | 430 // not needing authentication. If it is, just ignore the "launch" request. |
| 435 if (info_cache.ProfileIsSigninRequiredAtIndex(profile_index)) | 431 if (info_cache.ProfileIsSigninRequiredAtIndex(profile_index)) |
| 436 return; | 432 return; |
| 437 ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_UNNECESSARY); | 433 ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_UNNECESSARY); |
| 438 | 434 |
| 439 base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index); | |
| 440 profiles::SwitchToProfile( | 435 profiles::SwitchToProfile( |
| 441 path, | 436 profile_path, |
| 442 desktop_type_, | 437 desktop_type_, |
| 443 false, /* reuse any existing windows */ | 438 false, /* reuse any existing windows */ |
| 444 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, | 439 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, |
| 445 weak_ptr_factory_.GetWeakPtr()), | 440 weak_ptr_factory_.GetWeakPtr()), |
| 446 ProfileMetrics::SWITCH_PROFILE_MANAGER); | 441 ProfileMetrics::SWITCH_PROFILE_MANAGER); |
| 447 } | 442 } |
| 448 | 443 |
| 449 void UserManagerScreenHandler::HandleAttemptUnlock( | 444 void UserManagerScreenHandler::HandleAttemptUnlock( |
| 450 const base::ListValue* args) { | 445 const base::ListValue* args) { |
| 451 std::string email; | 446 std::string email; |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 bool is_active_user = (profile_path == active_profile_path); | 655 bool is_active_user = (profile_path == active_profile_path); |
| 661 | 656 |
| 662 profile_value->SetString( | 657 profile_value->SetString( |
| 663 kKeyUsername, info_cache.GetUserNameOfProfileAtIndex(i)); | 658 kKeyUsername, info_cache.GetUserNameOfProfileAtIndex(i)); |
| 664 profile_value->SetString( | 659 profile_value->SetString( |
| 665 kKeyEmailAddress, info_cache.GetUserNameOfProfileAtIndex(i)); | 660 kKeyEmailAddress, info_cache.GetUserNameOfProfileAtIndex(i)); |
| 666 // The profiles displayed in the User Manager are never guest profiles. | 661 // The profiles displayed in the User Manager are never guest profiles. |
| 667 profile_value->SetString( | 662 profile_value->SetString( |
| 668 kKeyDisplayName, | 663 kKeyDisplayName, |
| 669 profiles::GetAvatarNameForProfile(profile_path)); | 664 profiles::GetAvatarNameForProfile(profile_path)); |
| 670 profile_value->SetString(kKeyProfilePath, profile_path.MaybeAsASCII()); | 665 profile_value->Set( |
| 666 kKeyProfilePath, base::CreateFilePathValue(profile_path)); |
| 671 profile_value->SetBoolean(kKeyPublicAccount, false); | 667 profile_value->SetBoolean(kKeyPublicAccount, false); |
| 672 profile_value->SetBoolean( | 668 profile_value->SetBoolean( |
| 673 kKeySupervisedUser, info_cache.ProfileIsSupervisedAtIndex(i)); | 669 kKeySupervisedUser, info_cache.ProfileIsSupervisedAtIndex(i)); |
| 674 profile_value->SetBoolean( | 670 profile_value->SetBoolean( |
| 675 kKeyChildUser, info_cache.ProfileIsChildAtIndex(i)); | 671 kKeyChildUser, info_cache.ProfileIsChildAtIndex(i)); |
| 676 profile_value->SetBoolean(kKeySignedIn, is_active_user); | 672 profile_value->SetBoolean(kKeySignedIn, is_active_user); |
| 677 profile_value->SetBoolean( | 673 profile_value->SetBoolean( |
| 678 kKeyNeedsSignin, info_cache.ProfileIsSigninRequiredAtIndex(i)); | 674 kKeyNeedsSignin, info_cache.ProfileIsSigninRequiredAtIndex(i)); |
| 679 profile_value->SetBoolean(kKeyIsOwner, false); | 675 profile_value->SetBoolean(kKeyIsOwner, false); |
| 680 profile_value->SetBoolean(kKeyCanRemove, !active_user_is_supervised); | 676 profile_value->SetBoolean(kKeyCanRemove, !active_user_is_supervised); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 693 users_list, base::FundamentalValue(IsGuestModeEnabled())); | 689 users_list, base::FundamentalValue(IsGuestModeEnabled())); |
| 694 } | 690 } |
| 695 | 691 |
| 696 void UserManagerScreenHandler::ReportAuthenticationResult( | 692 void UserManagerScreenHandler::ReportAuthenticationResult( |
| 697 bool success, | 693 bool success, |
| 698 ProfileMetrics::ProfileAuth auth) { | 694 ProfileMetrics::ProfileAuth auth) { |
| 699 ProfileMetrics::LogProfileAuthResult(auth); | 695 ProfileMetrics::LogProfileAuthResult(auth); |
| 700 password_attempt_.clear(); | 696 password_attempt_.clear(); |
| 701 | 697 |
| 702 if (success) { | 698 if (success) { |
| 703 ProfileInfoCache& info_cache = | 699 const ProfileInfoCache& info_cache = |
| 704 g_browser_process->profile_manager()->GetProfileInfoCache(); | 700 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 705 base::FilePath path = info_cache.GetPathOfProfileAtIndex( | 701 base::FilePath path = info_cache.GetPathOfProfileAtIndex( |
| 706 authenticating_profile_index_); | 702 authenticating_profile_index_); |
| 707 profiles::SwitchToProfile( | 703 profiles::SwitchToProfile( |
| 708 path, | 704 path, |
| 709 desktop_type_, | 705 desktop_type_, |
| 710 true, | 706 true, |
| 711 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, | 707 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, |
| 712 weak_ptr_factory_.GetWeakPtr()), | 708 weak_ptr_factory_.GetWeakPtr()), |
| 713 ProfileMetrics::SWITCH_PROFILE_UNLOCK); | 709 ProfileMetrics::SWITCH_PROFILE_UNLOCK); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 Profile* profile, Profile::CreateStatus profile_create_status) { | 778 Profile* profile, Profile::CreateStatus profile_create_status) { |
| 783 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_); | 779 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_); |
| 784 if (browser && browser->window()) { | 780 if (browser && browser->window()) { |
| 785 OnBrowserWindowReady(browser); | 781 OnBrowserWindowReady(browser); |
| 786 } else { | 782 } else { |
| 787 registrar_.Add(this, | 783 registrar_.Add(this, |
| 788 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 784 chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
| 789 content::NotificationService::AllSources()); | 785 content::NotificationService::AllSources()); |
| 790 } | 786 } |
| 791 } | 787 } |
| OLD | NEW |