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 base::string16& email) { |
Mike Lerman
2015/01/13 19:55:41
Optional simpliciation: Change the email parameter
noms (inactive)
2015/01/13 21:36:42
Done.
| |
116 const base::string16& name) { | |
117 for (size_t i = 0; i < info_cache.GetNumberOfProfiles(); ++i) { | 116 for (size_t i = 0; i < info_cache.GetNumberOfProfiles(); ++i) { |
118 if (info_cache.GetUserNameOfProfileAtIndex(i) == email && | 117 if (info_cache.GetUserNameOfProfileAtIndex(i) == email) |
119 (name.empty() || | |
120 profiles::GetAvatarNameForProfile( | |
121 info_cache.GetPathOfProfileAtIndex(i)) == name)) { | |
122 return i; | 118 return i; |
123 } | |
124 } | 119 } |
125 return std::string::npos; | 120 return std::string::npos; |
126 } | 121 } |
127 | 122 |
128 extensions::ScreenlockPrivateEventRouter* GetScreenlockRouter( | 123 extensions::ScreenlockPrivateEventRouter* GetScreenlockRouter( |
129 const std::string& email) { | 124 const std::string& email) { |
130 ProfileInfoCache& info_cache = | 125 const ProfileInfoCache& info_cache = |
131 g_browser_process->profile_manager()->GetProfileInfoCache(); | 126 g_browser_process->profile_manager()->GetProfileInfoCache(); |
132 const size_t profile_index = GetIndexOfProfileWithEmailAndName( | 127 const size_t profile_index = GetIndexOfProfileWithEmail( |
133 info_cache, base::UTF8ToUTF16(email), base::string16()); | 128 info_cache, base::UTF8ToUTF16(email)); |
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 = GetIndexOfProfileWithEmail( |
281 info_cache, base::UTF8ToUTF16(user_email), base::string16()); | 276 info_cache, base::UTF8ToUTF16(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 |
Mike Lerman
2015/01/13 19:55:41
nit: Remove empty line.
noms (inactive)
2015/01/13 21:36:42
Done.
| |
325 if (!args->GetString(0, &email_address)) | 320 const base::Value* profile_path_value; |
321 if (!args->Get(0, &profile_path_value)) | |
326 return; | 322 return; |
327 | 323 |
328 base::string16 display_name; | 324 base::FilePath profile_path; |
329 if (!args->GetString(1, &display_name)) | 325 if (!base::GetValueAsFilePath(*profile_path_value, &profile_path)) |
326 return; | |
327 | |
328 base::string16 email_address; | |
329 if (!args->GetString(1, &email_address)) | |
330 return; | 330 return; |
331 | 331 |
332 std::string password; | 332 std::string password; |
333 if (!args->GetString(2, &password)) | 333 if (!args->GetString(2, &password)) |
334 return; | 334 return; |
335 | 335 |
336 ProfileInfoCache& info_cache = | 336 const ProfileInfoCache& info_cache = |
337 g_browser_process->profile_manager()->GetProfileInfoCache(); | 337 g_browser_process->profile_manager()->GetProfileInfoCache(); |
338 size_t profile_index = GetIndexOfProfileWithEmailAndName( | 338 size_t profile_index = info_cache.GetIndexOfProfileWithPath(profile_path); |
339 info_cache, email_address, display_name); | 339 |
340 if (profile_index >= info_cache.GetNumberOfProfiles()) { | 340 if (profile_index == std::string::npos) { |
341 NOTREACHED(); | 341 NOTREACHED(); |
342 return; | 342 return; |
343 } | 343 } |
344 | 344 |
345 authenticating_profile_index_ = profile_index; | 345 authenticating_profile_index_ = profile_index; |
346 if (!chrome::ValidateLocalAuthCredentials(profile_index, password)) { | 346 if (!chrome::ValidateLocalAuthCredentials(profile_index, password)) { |
347 // Make a second attempt via an on-line authentication call. This handles | 347 // 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 | 348 // profiles that are missing sign-in credentials and also cases where the |
349 // password has been changed externally. | 349 // password has been changed externally. |
350 client_login_.reset(new GaiaAuthFetcher( | 350 client_login_.reset(new GaiaAuthFetcher( |
351 this, | 351 this, |
352 GaiaConstants::kChromeSource, | 352 GaiaConstants::kChromeSource, |
353 web_ui()->GetWebContents()->GetBrowserContext()->GetRequestContext())); | 353 web_ui()->GetWebContents()->GetBrowserContext()->GetRequestContext())); |
354 std::string email_string; | 354 |
355 args->GetString(0, &email_string); | |
356 client_login_->StartClientLogin( | 355 client_login_->StartClientLogin( |
357 email_string, | 356 base::UTF16ToUTF8(email_address), |
358 password, | 357 password, |
359 GaiaConstants::kSyncService, | 358 GaiaConstants::kSyncService, |
360 std::string(), | 359 std::string(), |
361 std::string(), | 360 std::string(), |
362 GaiaAuthFetcher::HostedAccountsAllowed); | 361 GaiaAuthFetcher::HostedAccountsAllowed); |
363 password_attempt_ = password; | 362 password_attempt_ = password; |
364 return; | 363 return; |
365 } | 364 } |
366 | 365 |
367 ReportAuthenticationResult(true, ProfileMetrics::AUTH_LOCAL); | 366 ReportAuthenticationResult(true, ProfileMetrics::AUTH_LOCAL); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
401 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, | 400 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, |
402 weak_ptr_factory_.GetWeakPtr())); | 401 weak_ptr_factory_.GetWeakPtr())); |
403 } else { | 402 } else { |
404 // The UI should have prevented the user from allowing the selection of | 403 // The UI should have prevented the user from allowing the selection of |
405 // guest mode. | 404 // guest mode. |
406 NOTREACHED(); | 405 NOTREACHED(); |
407 } | 406 } |
408 } | 407 } |
409 | 408 |
410 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { | 409 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { |
411 base::string16 email_address; | 410 const base::Value* profile_path_value; |
Mike Lerman
2015/01/13 19:55:41
nit: Initialize profile_path_value to NULL (or nul
noms (inactive)
2015/01/13 21:36:42
Done.
| |
412 base::string16 display_name; | 411 if (!args->Get(0, &profile_path_value)) |
412 return; | |
413 | 413 |
414 if (!args->GetString(0, &email_address) || | 414 base::FilePath profile_path; |
415 !args->GetString(1, &display_name)) { | 415 if (!base::GetValueAsFilePath(*profile_path_value, &profile_path)) |
416 return; | |
417 | |
418 const ProfileInfoCache& info_cache = | |
419 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
420 size_t profile_index = info_cache.GetIndexOfProfileWithPath(profile_path); | |
421 | |
422 if (profile_index == std::string::npos) { | |
416 NOTREACHED(); | 423 NOTREACHED(); |
417 return; | 424 return; |
418 } | 425 } |
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 | 426 |
430 // It's possible that a user breaks into the user-manager page using the | 427 // 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 | 428 // JavaScript Inspector and causes a "locked" profile to call this |
432 // unauthenticated version of "launch" instead of the proper one. Thus, | 429 // 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 | 430 // 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. | 431 // not needing authentication. If it is, just ignore the "launch" request. |
435 if (info_cache.ProfileIsSigninRequiredAtIndex(profile_index)) | 432 if (info_cache.ProfileIsSigninRequiredAtIndex(profile_index)) |
436 return; | 433 return; |
437 ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_UNNECESSARY); | 434 ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_UNNECESSARY); |
438 | 435 |
439 base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index); | |
440 profiles::SwitchToProfile( | 436 profiles::SwitchToProfile( |
441 path, | 437 profile_path, |
442 desktop_type_, | 438 desktop_type_, |
443 false, /* reuse any existing windows */ | 439 false, /* reuse any existing windows */ |
444 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, | 440 base::Bind(&UserManagerScreenHandler::OnSwitchToProfileComplete, |
445 weak_ptr_factory_.GetWeakPtr()), | 441 weak_ptr_factory_.GetWeakPtr()), |
446 ProfileMetrics::SWITCH_PROFILE_MANAGER); | 442 ProfileMetrics::SWITCH_PROFILE_MANAGER); |
447 } | 443 } |
448 | 444 |
449 void UserManagerScreenHandler::HandleAttemptUnlock( | 445 void UserManagerScreenHandler::HandleAttemptUnlock( |
450 const base::ListValue* args) { | 446 const base::ListValue* args) { |
451 std::string email; | 447 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); | 656 bool is_active_user = (profile_path == active_profile_path); |
661 | 657 |
662 profile_value->SetString( | 658 profile_value->SetString( |
663 kKeyUsername, info_cache.GetUserNameOfProfileAtIndex(i)); | 659 kKeyUsername, info_cache.GetUserNameOfProfileAtIndex(i)); |
664 profile_value->SetString( | 660 profile_value->SetString( |
665 kKeyEmailAddress, info_cache.GetUserNameOfProfileAtIndex(i)); | 661 kKeyEmailAddress, info_cache.GetUserNameOfProfileAtIndex(i)); |
666 // The profiles displayed in the User Manager are never guest profiles. | 662 // The profiles displayed in the User Manager are never guest profiles. |
667 profile_value->SetString( | 663 profile_value->SetString( |
668 kKeyDisplayName, | 664 kKeyDisplayName, |
669 profiles::GetAvatarNameForProfile(profile_path)); | 665 profiles::GetAvatarNameForProfile(profile_path)); |
670 profile_value->SetString(kKeyProfilePath, profile_path.MaybeAsASCII()); | 666 profile_value->SetString(kKeyProfilePath, profile_path.MaybeAsASCII()); |
Mike Lerman
2015/01/13 19:55:41
FilePath::MaybeAsASCII() returns std::string() whe
noms (inactive)
2015/01/13 21:36:42
I used base::CreateFilePathValue(), which is what
Mike Lerman
2015/01/14 01:53:17
Chrome://settings doesn't seem to do anything with
| |
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 |