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/location.h" | 8 #include "base/location.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/profiler/scoped_tracker.h" | 10 #include "base/profiler/scoped_tracker.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 const char kKeyProfilePath[] = "profilePath"; | 64 const char kKeyProfilePath[] = "profilePath"; |
65 const char kKeyPublicAccount[] = "publicAccount"; | 65 const char kKeyPublicAccount[] = "publicAccount"; |
66 const char kKeyLegacySupervisedUser[] = "legacySupervisedUser"; | 66 const char kKeyLegacySupervisedUser[] = "legacySupervisedUser"; |
67 const char kKeyChildUser[] = "childUser"; | 67 const char kKeyChildUser[] = "childUser"; |
68 const char kKeyCanRemove[] = "canRemove"; | 68 const char kKeyCanRemove[] = "canRemove"; |
69 const char kKeyIsOwner[] = "isOwner"; | 69 const char kKeyIsOwner[] = "isOwner"; |
70 const char kKeyIsDesktop[] = "isDesktopUser"; | 70 const char kKeyIsDesktop[] = "isDesktopUser"; |
71 const char kKeyAvatarUrl[] = "userImage"; | 71 const char kKeyAvatarUrl[] = "userImage"; |
72 const char kKeyNeedsSignin[] = "needsSignin"; | 72 const char kKeyNeedsSignin[] = "needsSignin"; |
73 const char kKeyHasLocalCreds[] = "hasLocalCreds"; | 73 const char kKeyHasLocalCreds[] = "hasLocalCreds"; |
74 const char kKeyIsProfileLoaded[] = "isProfileLoaded"; | |
74 | 75 |
75 // JS API callback names. | 76 // JS API callback names. |
76 const char kJsApiUserManagerInitialize[] = "userManagerInitialize"; | 77 const char kJsApiUserManagerInitialize[] = "userManagerInitialize"; |
77 const char kJsApiUserManagerAddUser[] = "addUser"; | 78 const char kJsApiUserManagerAddUser[] = "addUser"; |
78 const char kJsApiUserManagerAuthLaunchUser[] = "authenticatedLaunchUser"; | 79 const char kJsApiUserManagerAuthLaunchUser[] = "authenticatedLaunchUser"; |
79 const char kJsApiUserManagerLaunchGuest[] = "launchGuest"; | 80 const char kJsApiUserManagerLaunchGuest[] = "launchGuest"; |
80 const char kJsApiUserManagerLaunchUser[] = "launchUser"; | 81 const char kJsApiUserManagerLaunchUser[] = "launchUser"; |
81 const char kJsApiUserManagerRemoveUser[] = "removeUser"; | 82 const char kJsApiUserManagerRemoveUser[] = "removeUser"; |
82 const char kJsApiUserManagerAttemptUnlock[] = "attemptUnlock"; | 83 const char kJsApiUserManagerAttemptUnlock[] = "attemptUnlock"; |
83 const char kJsApiUserManagerLogRemoveUserWarningShown[] = | 84 const char kJsApiUserManagerLogRemoveUserWarningShown[] = |
84 "logRemoveUserWarningShown"; | 85 "logRemoveUserWarningShown"; |
85 | 86 const char kJsApiUserManagerRemoveUserWarningLoadStats[] = |
87 "removeUserWarningLoadStats"; | |
88 const char kJsApiUserManagerGetRemoveWarningDialogMessage[] = | |
89 "getRemoveWarningDialogMessage"; | |
86 const size_t kAvatarIconSize = 180; | 90 const size_t kAvatarIconSize = 180; |
87 const int kMaxOAuthRetries = 3; | 91 const int kMaxOAuthRetries = 3; |
88 | 92 |
89 void HandleAndDoNothing(const base::ListValue* args) { | 93 void HandleAndDoNothing(const base::ListValue* args) { |
90 } | 94 } |
91 | 95 |
92 // This callback is run if the only profile has been deleted, and a new | 96 // This callback is run if the only profile has been deleted, and a new |
93 // profile has been created to replace it. | 97 // profile has been created to replace it. |
94 void OpenNewWindowForProfile( | 98 void OpenNewWindowForProfile( |
95 chrome::HostDesktopType desktop_type, | 99 chrome::HostDesktopType desktop_type, |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
553 const base::ListValue* args) { | 557 const base::ListValue* args) { |
554 std::string email; | 558 std::string email; |
555 CHECK(args->GetString(0, &email)); | 559 CHECK(args->GetString(0, &email)); |
556 SetAuthType( | 560 SetAuthType( |
557 email, | 561 email, |
558 proximity_auth::ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD, | 562 proximity_auth::ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD, |
559 base::string16()); | 563 base::string16()); |
560 HideUserPodCustomIcon(email); | 564 HideUserPodCustomIcon(email); |
561 } | 565 } |
562 | 566 |
567 void UserManagerScreenHandler::HandleRemoveUserWarningLoadStats( | |
568 const base::ListValue* args) { | |
569 const base::Value* profile_path_value; | |
570 | |
571 if (!args->Get(0, &profile_path_value)) | |
572 return; | |
573 | |
574 base::FilePath profile_path; | |
575 | |
576 if (!base::GetValueAsFilePath(*profile_path_value, &profile_path)) | |
577 return; | |
578 | |
579 base::StringValue return_profile_path(profile_path.value()); | |
580 Profile* profile = g_browser_process->profile_manager()-> | |
581 GetProfileByPath(profile_path); | |
582 | |
583 if (!profile) | |
584 return; | |
585 | |
586 profiles::GetProfileStatistics( | |
587 profile, | |
588 base::Bind( | |
589 &UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback, | |
590 weak_ptr_factory_.GetWeakPtr(), profile_path), | |
591 &tracker_); | |
592 } | |
593 | |
594 void UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback( | |
595 base::FilePath profile_path, | |
596 profiles::ProfileCategoryStats result) { | |
597 // Copy result into return_value. | |
598 base::StringValue return_profile_path(profile_path.value()); | |
599 base::DictionaryValue return_value; | |
600 for (const auto& item : result) { | |
601 base::DictionaryValue* stat = new base::DictionaryValue(); | |
602 stat->SetIntegerWithoutPathExpansion("count", item.count); | |
603 stat->SetBooleanWithoutPathExpansion("success", item.success); | |
604 return_value.SetWithoutPathExpansion(item.category, stat); | |
605 } | |
606 web_ui()->CallJavascriptFunction("updateRemoveWarningDialog", | |
607 return_profile_path, return_value); | |
608 } | |
609 | |
610 void UserManagerScreenHandler::HandleGetRemoveWarningDialogMessage( | |
611 const base::ListValue* args) { | |
612 const base::DictionaryValue* arg; | |
613 if (!args->GetDictionary(0, &arg)) | |
614 return; | |
615 | |
616 std::string profile_path(""); | |
617 bool is_synced_user = false, has_errors = false; | |
Mike Lerman
2015/09/21 19:24:51
please only declare one variable per line. no need
lwchkg
2015/09/28 18:54:20
Acknowledged for one variable per line. But I must
| |
618 | |
619 if (!arg->GetString("profilePath", &profile_path) || | |
620 !arg->GetBoolean("isSyncedUser", &is_synced_user) || | |
621 !arg->GetBoolean("hasErrors", &has_errors)) | |
622 return; | |
623 | |
624 int total_count = 0; | |
625 if (!arg->GetInteger("totalCount", &total_count)) | |
626 return; | |
627 | |
628 int message_id = is_synced_user ? | |
629 (has_errors ? IDS_LOGIN_POD_USER_REMOVE_WARNING_SYNC_WITH_ERRORS : | |
630 IDS_LOGIN_POD_USER_REMOVE_WARNING_SYNC) : | |
631 (has_errors ? IDS_LOGIN_POD_USER_REMOVE_WARNING_NONSYNC_WITH_ERRORS : | |
632 IDS_LOGIN_POD_USER_REMOVE_WARNING_NONSYNC); | |
633 | |
634 base::StringValue message = base::StringValue( | |
635 l10n_util::GetPluralStringFUTF16(message_id, total_count)); | |
636 | |
637 web_ui()->CallJavascriptFunction("updateRemoveWarningDialogSetMessage", | |
638 base::StringValue(profile_path), | |
639 message, | |
640 base::FundamentalValue(total_count)); | |
641 } | |
642 | |
563 void UserManagerScreenHandler::OnGetTokenInfoResponse( | 643 void UserManagerScreenHandler::OnGetTokenInfoResponse( |
564 scoped_ptr<base::DictionaryValue> token_info) { | 644 scoped_ptr<base::DictionaryValue> token_info) { |
565 // Password is unchanged so user just mistyped it. Ask again. | 645 // Password is unchanged so user just mistyped it. Ask again. |
566 ReportAuthenticationResult(false, ProfileMetrics::AUTH_FAILED); | 646 ReportAuthenticationResult(false, ProfileMetrics::AUTH_FAILED); |
567 } | 647 } |
568 | 648 |
569 void UserManagerScreenHandler::OnOAuthError() { | 649 void UserManagerScreenHandler::OnOAuthError() { |
570 // Password has changed. Go through online signin flow. | 650 // Password has changed. Go through online signin flow. |
571 DCHECK(!email_address_.empty()); | 651 DCHECK(!email_address_.empty()); |
572 oauth_client_.reset(); | 652 oauth_client_.reset(); |
(...skipping 24 matching lines...) Expand all Loading... | |
597 base::Bind(&UserManagerScreenHandler::HandleLaunchUser, | 677 base::Bind(&UserManagerScreenHandler::HandleLaunchUser, |
598 base::Unretained(this))); | 678 base::Unretained(this))); |
599 web_ui()->RegisterMessageCallback(kJsApiUserManagerRemoveUser, | 679 web_ui()->RegisterMessageCallback(kJsApiUserManagerRemoveUser, |
600 base::Bind(&UserManagerScreenHandler::HandleRemoveUser, | 680 base::Bind(&UserManagerScreenHandler::HandleRemoveUser, |
601 base::Unretained(this))); | 681 base::Unretained(this))); |
602 web_ui()->RegisterMessageCallback(kJsApiUserManagerAttemptUnlock, | 682 web_ui()->RegisterMessageCallback(kJsApiUserManagerAttemptUnlock, |
603 base::Bind(&UserManagerScreenHandler::HandleAttemptUnlock, | 683 base::Bind(&UserManagerScreenHandler::HandleAttemptUnlock, |
604 base::Unretained(this))); | 684 base::Unretained(this))); |
605 web_ui()->RegisterMessageCallback(kJsApiUserManagerLogRemoveUserWarningShown, | 685 web_ui()->RegisterMessageCallback(kJsApiUserManagerLogRemoveUserWarningShown, |
606 base::Bind(&HandleLogRemoveUserWarningShown)); | 686 base::Bind(&HandleLogRemoveUserWarningShown)); |
687 web_ui()->RegisterMessageCallback(kJsApiUserManagerRemoveUserWarningLoadStats, | |
688 base::Bind(&UserManagerScreenHandler::HandleRemoveUserWarningLoadStats, | |
689 base::Unretained(this))); | |
690 web_ui()->RegisterMessageCallback( | |
691 kJsApiUserManagerGetRemoveWarningDialogMessage, | |
692 base::Bind(&UserManagerScreenHandler::HandleGetRemoveWarningDialogMessage, | |
693 base::Unretained(this))); | |
607 | 694 |
608 const content::WebUI::MessageCallback& kDoNothingCallback = | 695 const content::WebUI::MessageCallback& kDoNothingCallback = |
609 base::Bind(&HandleAndDoNothing); | 696 base::Bind(&HandleAndDoNothing); |
610 | 697 |
611 // Unused callbacks from screen_account_picker.js | 698 // Unused callbacks from screen_account_picker.js |
612 web_ui()->RegisterMessageCallback("accountPickerReady", kDoNothingCallback); | 699 web_ui()->RegisterMessageCallback("accountPickerReady", kDoNothingCallback); |
613 web_ui()->RegisterMessageCallback("loginUIStateChanged", kDoNothingCallback); | 700 web_ui()->RegisterMessageCallback("loginUIStateChanged", kDoNothingCallback); |
614 web_ui()->RegisterMessageCallback("hideCaptivePortal", kDoNothingCallback); | 701 web_ui()->RegisterMessageCallback("hideCaptivePortal", kDoNothingCallback); |
615 web_ui()->RegisterMessageCallback("getTouchViewState", kDoNothingCallback); | 702 web_ui()->RegisterMessageCallback("getTouchViewState", kDoNothingCallback); |
616 // Unused callbacks from display_manager.js | 703 // Unused callbacks from display_manager.js |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
653 IDS_LOGIN_POD_MENU_REMOVE_ITEM_ACCESSIBLE_NAME)); | 740 IDS_LOGIN_POD_MENU_REMOVE_ITEM_ACCESSIBLE_NAME)); |
654 localized_strings->SetString("removeUser", | 741 localized_strings->SetString("removeUser", |
655 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BUTTON)); | 742 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BUTTON)); |
656 localized_strings->SetString("passwordFieldAccessibleName", | 743 localized_strings->SetString("passwordFieldAccessibleName", |
657 l10n_util::GetStringUTF16(IDS_LOGIN_POD_PASSWORD_FIELD_ACCESSIBLE_NAME)); | 744 l10n_util::GetStringUTF16(IDS_LOGIN_POD_PASSWORD_FIELD_ACCESSIBLE_NAME)); |
658 localized_strings->SetString("bootIntoWallpaper", "off"); | 745 localized_strings->SetString("bootIntoWallpaper", "off"); |
659 | 746 |
660 // For AccountPickerScreen, the remove user warning overlay. | 747 // For AccountPickerScreen, the remove user warning overlay. |
661 localized_strings->SetString("removeUserWarningButtonTitle", | 748 localized_strings->SetString("removeUserWarningButtonTitle", |
662 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BUTTON)); | 749 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BUTTON)); |
663 localized_strings->SetString("removeUserWarningText", | 750 localized_strings->SetString("removeUserWarningTextNonSyncNoStats", |
664 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING)); | 751 l10n_util::GetStringUTF16( |
752 IDS_LOGIN_POD_USER_REMOVE_WARNING_NONSYNC_NOSTATS)); | |
753 localized_strings->SetString("removeUserWarningTextNonSyncCalculating", | |
754 l10n_util::GetStringUTF16( | |
755 IDS_LOGIN_POD_USER_REMOVE_WARNING_NONSYNC_CALCULATING)); | |
756 localized_strings->SetString("removeUserWarningTextHistory", | |
757 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_HISTORY)); | |
758 localized_strings->SetString("removeUserWarningTextPasswords", | |
759 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_PASSWORDS)); | |
760 localized_strings->SetString("removeUserWarningTextBookmarks", | |
761 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BOOKMARKS)); | |
762 localized_strings->SetString("removeUserWarningTextSettings", | |
763 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_SETTINGS)); | |
764 localized_strings->SetString("removeUserWarningTextCalculating", | |
765 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_CALCULATING)); | |
766 localized_strings->SetString("removeUserWarningTextSyncNoStats", | |
767 l10n_util::GetStringUTF16( | |
768 IDS_LOGIN_POD_USER_REMOVE_WARNING_SYNC_NOSTATS)); | |
769 localized_strings->SetString("removeUserWarningTextSyncCalculating", | |
770 l10n_util::GetStringUTF16( | |
771 IDS_LOGIN_POD_USER_REMOVE_WARNING_SYNC_CALCULATING)); | |
665 localized_strings->SetString("removeLegacySupervisedUserWarningText", | 772 localized_strings->SetString("removeLegacySupervisedUserWarningText", |
666 l10n_util::GetStringFUTF16( | 773 l10n_util::GetStringFUTF16( |
667 IDS_LOGIN_POD_LEGACY_SUPERVISED_USER_REMOVE_WARNING, | 774 IDS_LOGIN_POD_LEGACY_SUPERVISED_USER_REMOVE_WARNING, |
668 base::UTF8ToUTF16( | 775 base::UTF8ToUTF16( |
669 chrome::kLegacySupervisedUserManagementDisplayURL))); | 776 chrome::kLegacySupervisedUserManagementDisplayURL))); |
670 | 777 |
671 // Strings needed for the User Manager tutorial slides. | 778 // Strings needed for the User Manager tutorial slides. |
672 localized_strings->SetString("tutorialNext", | 779 localized_strings->SetString("tutorialNext", |
673 l10n_util::GetStringUTF16(IDS_USER_MANAGER_TUTORIAL_NEXT)); | 780 l10n_util::GetStringUTF16(IDS_USER_MANAGER_TUTORIAL_NEXT)); |
674 localized_strings->SetString("tutorialDone", | 781 localized_strings->SetString("tutorialDone", |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
762 kKeyNeedsSignin, info_cache->ProfileIsSigninRequiredAtIndex(i)); | 869 kKeyNeedsSignin, info_cache->ProfileIsSigninRequiredAtIndex(i)); |
763 profile_value->SetBoolean( | 870 profile_value->SetBoolean( |
764 kKeyHasLocalCreds, | 871 kKeyHasLocalCreds, |
765 !info_cache->GetLocalAuthCredentialsOfProfileAtIndex(i).empty()); | 872 !info_cache->GetLocalAuthCredentialsOfProfileAtIndex(i).empty()); |
766 profile_value->SetBoolean(kKeyIsOwner, false); | 873 profile_value->SetBoolean(kKeyIsOwner, false); |
767 profile_value->SetBoolean(kKeyCanRemove, can_remove); | 874 profile_value->SetBoolean(kKeyCanRemove, can_remove); |
768 profile_value->SetBoolean(kKeyIsDesktop, true); | 875 profile_value->SetBoolean(kKeyIsDesktop, true); |
769 profile_value->SetString( | 876 profile_value->SetString( |
770 kKeyAvatarUrl, GetAvatarImageAtIndex(i, info_cache)); | 877 kKeyAvatarUrl, GetAvatarImageAtIndex(i, info_cache)); |
771 | 878 |
879 // GetProfileByPath returns a pointer if the profile is fully loaded, NULL | |
880 // otherwise. | |
881 Profile* profile = | |
882 g_browser_process->profile_manager()->GetProfileByPath(profile_path); | |
883 profile_value->SetBoolean(kKeyIsProfileLoaded, profile != nullptr); | |
884 | |
772 users_list.Append(profile_value); | 885 users_list.Append(profile_value); |
773 } | 886 } |
774 | 887 |
775 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers", | 888 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers", |
776 users_list, base::FundamentalValue(IsGuestModeEnabled())); | 889 users_list, base::FundamentalValue(IsGuestModeEnabled())); |
777 | 890 |
778 // This is the latest C++ code we have in the flow to show the UserManager. | 891 // This is the latest C++ code we have in the flow to show the UserManager. |
779 // This may be invoked more than once per UserManager lifetime; the | 892 // This may be invoked more than once per UserManager lifetime; the |
780 // UserManager will ensure all relevant logging only happens once. | 893 // UserManager will ensure all relevant logging only happens once. |
781 UserManager::OnUserManagerShown(); | 894 UserManager::OnUserManagerShown(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
859 Profile* profile, Profile::CreateStatus profile_create_status) { | 972 Profile* profile, Profile::CreateStatus profile_create_status) { |
860 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_); | 973 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_); |
861 if (browser && browser->window()) { | 974 if (browser && browser->window()) { |
862 OnBrowserWindowReady(browser); | 975 OnBrowserWindowReady(browser); |
863 } else { | 976 } else { |
864 registrar_.Add(this, | 977 registrar_.Add(this, |
865 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 978 chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
866 content::NotificationService::AllSources()); | 979 content::NotificationService::AllSources()); |
867 } | 980 } |
868 } | 981 } |
OLD | NEW |