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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 namespace { | 48 namespace { |
49 // User dictionary keys. | 49 // User dictionary keys. |
50 const char kKeyUsername[] = "username"; | 50 const char kKeyUsername[] = "username"; |
51 const char kKeyDisplayName[]= "displayName"; | 51 const char kKeyDisplayName[]= "displayName"; |
52 const char kKeyEmailAddress[] = "emailAddress"; | 52 const char kKeyEmailAddress[] = "emailAddress"; |
53 const char kKeyProfilePath[] = "profilePath"; | 53 const char kKeyProfilePath[] = "profilePath"; |
54 const char kKeyPublicAccount[] = "publicAccount"; | 54 const char kKeyPublicAccount[] = "publicAccount"; |
55 const char kKeySupervisedUser[] = "supervisedUser"; | 55 const char kKeySupervisedUser[] = "supervisedUser"; |
56 const char kKeyChildUser[] = "childUser"; | 56 const char kKeyChildUser[] = "childUser"; |
57 const char kKeySignedIn[] = "signedIn"; | |
58 const char kKeyCanRemove[] = "canRemove"; | 57 const char kKeyCanRemove[] = "canRemove"; |
59 const char kKeyIsOwner[] = "isOwner"; | 58 const char kKeyIsOwner[] = "isOwner"; |
60 const char kKeyIsDesktop[] = "isDesktopUser"; | 59 const char kKeyIsDesktop[] = "isDesktopUser"; |
61 const char kKeyAvatarUrl[] = "userImage"; | 60 const char kKeyAvatarUrl[] = "userImage"; |
62 const char kKeyNeedsSignin[] = "needsSignin"; | 61 const char kKeyNeedsSignin[] = "needsSignin"; |
63 | 62 |
64 // JS API callback names. | 63 // JS API callback names. |
65 const char kJsApiUserManagerInitialize[] = "userManagerInitialize"; | 64 const char kJsApiUserManagerInitialize[] = "userManagerInitialize"; |
66 const char kJsApiUserManagerAddUser[] = "addUser"; | 65 const char kJsApiUserManagerAddUser[] = "addUser"; |
67 const char kJsApiUserManagerAuthLaunchUser[] = "authenticatedLaunchUser"; | 66 const char kJsApiUserManagerAuthLaunchUser[] = "authenticatedLaunchUser"; |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 void UserManagerScreenHandler::HandleRemoveUser(const base::ListValue* args) { | 369 void UserManagerScreenHandler::HandleRemoveUser(const base::ListValue* args) { |
371 DCHECK(args); | 370 DCHECK(args); |
372 const base::Value* profile_path_value; | 371 const base::Value* profile_path_value; |
373 if (!args->Get(0, &profile_path_value)) | 372 if (!args->Get(0, &profile_path_value)) |
374 return; | 373 return; |
375 | 374 |
376 base::FilePath profile_path; | 375 base::FilePath profile_path; |
377 if (!base::GetValueAsFilePath(*profile_path_value, &profile_path)) | 376 if (!base::GetValueAsFilePath(*profile_path_value, &profile_path)) |
378 return; | 377 return; |
379 | 378 |
380 // This handler could have been called for a supervised user, for example | |
381 // because the user fiddled with the web inspector. Silently return in this | |
382 // case. | |
383 if (Profile::FromWebUI(web_ui())->IsSupervised()) | |
384 return; | |
385 | |
386 if (!profiles::IsMultipleProfilesEnabled()) | 379 if (!profiles::IsMultipleProfilesEnabled()) |
387 return; | 380 return; |
388 | 381 |
389 g_browser_process->profile_manager()->ScheduleProfileForDeletion( | 382 g_browser_process->profile_manager()->ScheduleProfileForDeletion( |
390 profile_path, | 383 profile_path, |
391 base::Bind(&OpenNewWindowForProfile, desktop_type_)); | 384 base::Bind(&OpenNewWindowForProfile, desktop_type_)); |
392 ProfileMetrics::LogProfileDeleteUser( | 385 ProfileMetrics::LogProfileDeleteUser( |
393 ProfileMetrics::DELETE_PROFILE_USER_MANAGER); | 386 ProfileMetrics::DELETE_PROFILE_USER_MANAGER); |
394 } | 387 } |
395 | 388 |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 localized_strings->SetString("multiProfilesNotAllowedPolicyMsg", | 629 localized_strings->SetString("multiProfilesNotAllowedPolicyMsg", |
637 base::string16()); | 630 base::string16()); |
638 localized_strings->SetString("multiProfilesPrimaryOnlyPolicyMsg", | 631 localized_strings->SetString("multiProfilesPrimaryOnlyPolicyMsg", |
639 base::string16()); | 632 base::string16()); |
640 localized_strings->SetString("multiProfilesOwnerPrimaryOnlyMsg", | 633 localized_strings->SetString("multiProfilesOwnerPrimaryOnlyMsg", |
641 base::string16()); | 634 base::string16()); |
642 } | 635 } |
643 | 636 |
644 void UserManagerScreenHandler::SendUserList() { | 637 void UserManagerScreenHandler::SendUserList() { |
645 base::ListValue users_list; | 638 base::ListValue users_list; |
646 base::FilePath active_profile_path = | |
647 web_ui()->GetWebContents()->GetBrowserContext()->GetPath(); | |
648 const ProfileInfoCache& info_cache = | 639 const ProfileInfoCache& info_cache = |
649 g_browser_process->profile_manager()->GetProfileInfoCache(); | 640 g_browser_process->profile_manager()->GetProfileInfoCache(); |
650 | 641 |
651 user_auth_type_map_.clear(); | 642 user_auth_type_map_.clear(); |
652 | 643 |
653 // If the active user is a supervised user, then they may not perform | |
654 // certain actions (i.e. delete another user). | |
655 bool active_user_is_supervised = Profile::FromWebUI(web_ui())->IsSupervised(); | |
656 for (size_t i = 0; i < info_cache.GetNumberOfProfiles(); ++i) { | 644 for (size_t i = 0; i < info_cache.GetNumberOfProfiles(); ++i) { |
657 base::DictionaryValue* profile_value = new base::DictionaryValue(); | 645 base::DictionaryValue* profile_value = new base::DictionaryValue(); |
658 | |
659 base::FilePath profile_path = info_cache.GetPathOfProfileAtIndex(i); | 646 base::FilePath profile_path = info_cache.GetPathOfProfileAtIndex(i); |
660 bool is_active_user = (profile_path == active_profile_path); | |
661 | 647 |
662 profile_value->SetString( | 648 profile_value->SetString( |
663 kKeyUsername, info_cache.GetUserNameOfProfileAtIndex(i)); | 649 kKeyUsername, info_cache.GetUserNameOfProfileAtIndex(i)); |
664 profile_value->SetString( | 650 profile_value->SetString( |
665 kKeyEmailAddress, info_cache.GetUserNameOfProfileAtIndex(i)); | 651 kKeyEmailAddress, info_cache.GetUserNameOfProfileAtIndex(i)); |
666 // The profiles displayed in the User Manager are never guest profiles. | |
667 profile_value->SetString( | 652 profile_value->SetString( |
668 kKeyDisplayName, | 653 kKeyDisplayName, |
669 profiles::GetAvatarNameForProfile(profile_path)); | 654 profiles::GetAvatarNameForProfile(profile_path)); |
670 profile_value->SetString(kKeyProfilePath, profile_path.MaybeAsASCII()); | 655 profile_value->SetString(kKeyProfilePath, profile_path.MaybeAsASCII()); |
671 profile_value->SetBoolean(kKeyPublicAccount, false); | 656 profile_value->SetBoolean(kKeyPublicAccount, false); |
672 profile_value->SetBoolean( | 657 profile_value->SetBoolean( |
673 kKeySupervisedUser, info_cache.ProfileIsSupervisedAtIndex(i)); | 658 kKeySupervisedUser, info_cache.ProfileIsSupervisedAtIndex(i)); |
674 profile_value->SetBoolean( | 659 profile_value->SetBoolean( |
675 kKeyChildUser, info_cache.ProfileIsChildAtIndex(i)); | 660 kKeyChildUser, info_cache.ProfileIsChildAtIndex(i)); |
676 profile_value->SetBoolean(kKeySignedIn, is_active_user); | |
677 profile_value->SetBoolean( | 661 profile_value->SetBoolean( |
678 kKeyNeedsSignin, info_cache.ProfileIsSigninRequiredAtIndex(i)); | 662 kKeyNeedsSignin, info_cache.ProfileIsSigninRequiredAtIndex(i)); |
679 profile_value->SetBoolean(kKeyIsOwner, false); | 663 profile_value->SetBoolean(kKeyIsOwner, false); |
680 profile_value->SetBoolean(kKeyCanRemove, !active_user_is_supervised); | 664 profile_value->SetBoolean(kKeyCanRemove, true); |
681 profile_value->SetBoolean(kKeyIsDesktop, true); | 665 profile_value->SetBoolean(kKeyIsDesktop, true); |
682 profile_value->SetString( | 666 profile_value->SetString( |
683 kKeyAvatarUrl, GetAvatarImageAtIndex(i, info_cache)); | 667 kKeyAvatarUrl, GetAvatarImageAtIndex(i, info_cache)); |
684 | 668 |
685 // The row of user pods should display the active user first. | 669 users_list.Append(profile_value); |
686 if (is_active_user) | |
687 users_list.Insert(0, profile_value); | |
688 else | |
689 users_list.Append(profile_value); | |
690 } | 670 } |
691 | 671 |
692 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers", | 672 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers", |
693 users_list, base::FundamentalValue(IsGuestModeEnabled())); | 673 users_list, base::FundamentalValue(IsGuestModeEnabled())); |
694 } | 674 } |
695 | 675 |
696 void UserManagerScreenHandler::ReportAuthenticationResult( | 676 void UserManagerScreenHandler::ReportAuthenticationResult( |
697 bool success, | 677 bool success, |
698 ProfileMetrics::ProfileAuth auth) { | 678 ProfileMetrics::ProfileAuth auth) { |
699 ProfileMetrics::LogProfileAuthResult(auth); | 679 ProfileMetrics::LogProfileAuthResult(auth); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 Profile* profile, Profile::CreateStatus profile_create_status) { | 762 Profile* profile, Profile::CreateStatus profile_create_status) { |
783 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_); | 763 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_); |
784 if (browser && browser->window()) { | 764 if (browser && browser->window()) { |
785 OnBrowserWindowReady(browser); | 765 OnBrowserWindowReady(browser); |
786 } else { | 766 } else { |
787 registrar_.Add(this, | 767 registrar_.Add(this, |
788 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 768 chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
789 content::NotificationService::AllSources()); | 769 content::NotificationService::AllSources()); |
790 } | 770 } |
791 } | 771 } |
OLD | NEW |