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"; | |
86 const size_t kAvatarIconSize = 180; | 88 const size_t kAvatarIconSize = 180; |
87 const int kMaxOAuthRetries = 3; | 89 const int kMaxOAuthRetries = 3; |
88 | 90 |
89 void HandleAndDoNothing(const base::ListValue* args) { | 91 void HandleAndDoNothing(const base::ListValue* args) { |
90 } | 92 } |
91 | 93 |
92 // This callback is run if the only profile has been deleted, and a new | 94 // This callback is run if the only profile has been deleted, and a new |
93 // profile has been created to replace it. | 95 // profile has been created to replace it. |
94 void OpenNewWindowForProfile( | 96 void OpenNewWindowForProfile( |
95 chrome::HostDesktopType desktop_type, | 97 chrome::HostDesktopType desktop_type, |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
548 const base::ListValue* args) { | 550 const base::ListValue* args) { |
549 std::string email; | 551 std::string email; |
550 CHECK(args->GetString(0, &email)); | 552 CHECK(args->GetString(0, &email)); |
551 SetAuthType( | 553 SetAuthType( |
552 email, | 554 email, |
553 proximity_auth::ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD, | 555 proximity_auth::ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD, |
554 base::string16()); | 556 base::string16()); |
555 HideUserPodCustomIcon(email); | 557 HideUserPodCustomIcon(email); |
556 } | 558 } |
557 | 559 |
560 void UserManagerScreenHandler::HandleRemoveUserWarningLoadStats( | |
561 const base::ListValue* args) { | |
562 const base::Value* profile_path_value; | |
563 | |
564 if (!args->Get(0, &profile_path_value)) | |
565 return; | |
566 | |
567 base::FilePath profile_path; | |
568 | |
569 if (!base::GetValueAsFilePath(*profile_path_value, &profile_path)) | |
570 return; | |
571 | |
572 base::StringValue return_profile_path(profile_path.value()); | |
573 Profile* profile = g_browser_process->profile_manager()-> | |
574 GetProfileByPath(profile_path); | |
575 | |
576 if (!profile) | |
577 return; | |
578 | |
579 profiles::GetProfileStatistics( | |
580 profile, | |
581 base::Bind( | |
582 &UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback, | |
583 weak_ptr_factory_.GetWeakPtr(), profile_path), | |
584 &tracker_); | |
585 } | |
586 | |
587 void UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback( | |
588 base::FilePath profile_path, | |
589 profiles::ProfileStatisticsReturn result) { | |
590 // Copy result into return_value. | |
591 base::StringValue return_profile_path(profile_path.value()); | |
592 base::DictionaryValue return_value; | |
593 for (const auto& item : result) { | |
594 if (item.success) { | |
595 return_value.SetIntegerWithoutPathExpansion(item.category, item.count); | |
596 } else { | |
597 return_value.SetBooleanWithoutPathExpansion(item.category, false); | |
Mike Lerman
2015/08/17 14:23:38
This is a little ugly, to be placing a value that
lwchkg
2015/08/19 06:19:45
Two options here:
1. Leave boolean "false" here.
2
Mike Lerman
2015/08/20 14:52:11
Try the json thing; I expect it will yield very re
lwchkg
2015/08/20 16:06:24
Good. Anyway, we are already passing a json alread
lwchkg
2015/08/22 15:35:29
Updated on patch #13 already. I've forgot to annou
Mike Lerman
2015/08/24 14:45:40
This looks really good!
| |
598 } | |
599 } | |
600 web_ui()->CallJavascriptFunction("updateRemoveWarningDialog", | |
601 return_profile_path, return_value); | |
602 } | |
603 | |
558 void UserManagerScreenHandler::OnGetTokenInfoResponse( | 604 void UserManagerScreenHandler::OnGetTokenInfoResponse( |
559 scoped_ptr<base::DictionaryValue> token_info) { | 605 scoped_ptr<base::DictionaryValue> token_info) { |
560 // Password is unchanged so user just mistyped it. Ask again. | 606 // Password is unchanged so user just mistyped it. Ask again. |
561 ReportAuthenticationResult(false, ProfileMetrics::AUTH_FAILED); | 607 ReportAuthenticationResult(false, ProfileMetrics::AUTH_FAILED); |
562 } | 608 } |
563 | 609 |
564 void UserManagerScreenHandler::OnOAuthError() { | 610 void UserManagerScreenHandler::OnOAuthError() { |
565 // Password has changed. Go through online signin flow. | 611 // Password has changed. Go through online signin flow. |
566 DCHECK(!email_address_.empty()); | 612 DCHECK(!email_address_.empty()); |
567 oauth_client_.reset(); | 613 oauth_client_.reset(); |
(...skipping 24 matching lines...) Expand all Loading... | |
592 base::Bind(&UserManagerScreenHandler::HandleLaunchUser, | 638 base::Bind(&UserManagerScreenHandler::HandleLaunchUser, |
593 base::Unretained(this))); | 639 base::Unretained(this))); |
594 web_ui()->RegisterMessageCallback(kJsApiUserManagerRemoveUser, | 640 web_ui()->RegisterMessageCallback(kJsApiUserManagerRemoveUser, |
595 base::Bind(&UserManagerScreenHandler::HandleRemoveUser, | 641 base::Bind(&UserManagerScreenHandler::HandleRemoveUser, |
596 base::Unretained(this))); | 642 base::Unretained(this))); |
597 web_ui()->RegisterMessageCallback(kJsApiUserManagerAttemptUnlock, | 643 web_ui()->RegisterMessageCallback(kJsApiUserManagerAttemptUnlock, |
598 base::Bind(&UserManagerScreenHandler::HandleAttemptUnlock, | 644 base::Bind(&UserManagerScreenHandler::HandleAttemptUnlock, |
599 base::Unretained(this))); | 645 base::Unretained(this))); |
600 web_ui()->RegisterMessageCallback(kJsApiUserManagerLogRemoveUserWarningShown, | 646 web_ui()->RegisterMessageCallback(kJsApiUserManagerLogRemoveUserWarningShown, |
601 base::Bind(&HandleLogRemoveUserWarningShown)); | 647 base::Bind(&HandleLogRemoveUserWarningShown)); |
648 web_ui()->RegisterMessageCallback(kJsApiUserManagerRemoveUserWarningLoadStats, | |
649 base::Bind(&UserManagerScreenHandler::HandleRemoveUserWarningLoadStats, | |
650 base::Unretained(this))); | |
602 | 651 |
603 const content::WebUI::MessageCallback& kDoNothingCallback = | 652 const content::WebUI::MessageCallback& kDoNothingCallback = |
604 base::Bind(&HandleAndDoNothing); | 653 base::Bind(&HandleAndDoNothing); |
605 | 654 |
606 // Unused callbacks from screen_account_picker.js | 655 // Unused callbacks from screen_account_picker.js |
607 web_ui()->RegisterMessageCallback("accountPickerReady", kDoNothingCallback); | 656 web_ui()->RegisterMessageCallback("accountPickerReady", kDoNothingCallback); |
608 web_ui()->RegisterMessageCallback("loginUIStateChanged", kDoNothingCallback); | 657 web_ui()->RegisterMessageCallback("loginUIStateChanged", kDoNothingCallback); |
609 web_ui()->RegisterMessageCallback("hideCaptivePortal", kDoNothingCallback); | 658 web_ui()->RegisterMessageCallback("hideCaptivePortal", kDoNothingCallback); |
610 web_ui()->RegisterMessageCallback("getTouchViewState", kDoNothingCallback); | 659 web_ui()->RegisterMessageCallback("getTouchViewState", kDoNothingCallback); |
611 // Unused callbacks from display_manager.js | 660 // Unused callbacks from display_manager.js |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
648 IDS_LOGIN_POD_MENU_REMOVE_ITEM_ACCESSIBLE_NAME)); | 697 IDS_LOGIN_POD_MENU_REMOVE_ITEM_ACCESSIBLE_NAME)); |
649 localized_strings->SetString("removeUser", | 698 localized_strings->SetString("removeUser", |
650 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BUTTON)); | 699 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BUTTON)); |
651 localized_strings->SetString("passwordFieldAccessibleName", | 700 localized_strings->SetString("passwordFieldAccessibleName", |
652 l10n_util::GetStringUTF16(IDS_LOGIN_POD_PASSWORD_FIELD_ACCESSIBLE_NAME)); | 701 l10n_util::GetStringUTF16(IDS_LOGIN_POD_PASSWORD_FIELD_ACCESSIBLE_NAME)); |
653 localized_strings->SetString("bootIntoWallpaper", "off"); | 702 localized_strings->SetString("bootIntoWallpaper", "off"); |
654 | 703 |
655 // For AccountPickerScreen, the remove user warning overlay. | 704 // For AccountPickerScreen, the remove user warning overlay. |
656 localized_strings->SetString("removeUserWarningButtonTitle", | 705 localized_strings->SetString("removeUserWarningButtonTitle", |
657 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BUTTON)); | 706 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BUTTON)); |
658 localized_strings->SetString("removeUserWarningText", | 707 localized_strings->SetString("removeUserWarningTextNonSync", |
659 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING)); | 708 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_NONSYNC)); |
709 localized_strings->SetString("removeUserWarningTextNonSyncNoStats", | |
710 l10n_util::GetStringUTF16( | |
711 IDS_LOGIN_POD_USER_REMOVE_WARNING_NONSYNC_NOSTATS)); | |
712 localized_strings->SetString("removeUserWarningTextHistory", | |
713 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_HISTORY)); | |
714 localized_strings->SetString("removeUserWarningTextPasswords", | |
715 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_PASSWORDS)); | |
716 localized_strings->SetString("removeUserWarningTextBookmarks", | |
717 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BOOKMARKS)); | |
718 localized_strings->SetString("removeUserWarningTextSettings", | |
719 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_SETTINGS)); | |
720 localized_strings->SetString("removeUserWarningTextCalculating", | |
721 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_CALCULATING)); | |
722 localized_strings->SetString("removeUserWarningTextSync", | |
723 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_SYNC)); | |
724 localized_strings->SetString("removeUserWarningTextSyncNoStats", | |
725 l10n_util::GetStringUTF16( | |
726 IDS_LOGIN_POD_USER_REMOVE_WARNING_SYNC_NOSTATS)); | |
660 localized_strings->SetString("removeLegacySupervisedUserWarningText", | 727 localized_strings->SetString("removeLegacySupervisedUserWarningText", |
661 l10n_util::GetStringFUTF16( | 728 l10n_util::GetStringFUTF16( |
662 IDS_LOGIN_POD_LEGACY_SUPERVISED_USER_REMOVE_WARNING, | 729 IDS_LOGIN_POD_LEGACY_SUPERVISED_USER_REMOVE_WARNING, |
663 base::UTF8ToUTF16(chrome::kSupervisedUserManagementDisplayURL))); | 730 base::UTF8ToUTF16(chrome::kSupervisedUserManagementDisplayURL))); |
664 | 731 |
665 // Strings needed for the User Manager tutorial slides. | 732 // Strings needed for the User Manager tutorial slides. |
666 localized_strings->SetString("tutorialNext", | 733 localized_strings->SetString("tutorialNext", |
667 l10n_util::GetStringUTF16(IDS_USER_MANAGER_TUTORIAL_NEXT)); | 734 l10n_util::GetStringUTF16(IDS_USER_MANAGER_TUTORIAL_NEXT)); |
668 localized_strings->SetString("tutorialDone", | 735 localized_strings->SetString("tutorialDone", |
669 l10n_util::GetStringUTF16(IDS_USER_MANAGER_TUTORIAL_DONE)); | 736 l10n_util::GetStringUTF16(IDS_USER_MANAGER_TUTORIAL_DONE)); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
751 kKeyNeedsSignin, info_cache->ProfileIsSigninRequiredAtIndex(i)); | 818 kKeyNeedsSignin, info_cache->ProfileIsSigninRequiredAtIndex(i)); |
752 profile_value->SetBoolean( | 819 profile_value->SetBoolean( |
753 kKeyHasLocalCreds, | 820 kKeyHasLocalCreds, |
754 !info_cache->GetLocalAuthCredentialsOfProfileAtIndex(i).empty()); | 821 !info_cache->GetLocalAuthCredentialsOfProfileAtIndex(i).empty()); |
755 profile_value->SetBoolean(kKeyIsOwner, false); | 822 profile_value->SetBoolean(kKeyIsOwner, false); |
756 profile_value->SetBoolean(kKeyCanRemove, can_remove); | 823 profile_value->SetBoolean(kKeyCanRemove, can_remove); |
757 profile_value->SetBoolean(kKeyIsDesktop, true); | 824 profile_value->SetBoolean(kKeyIsDesktop, true); |
758 profile_value->SetString( | 825 profile_value->SetString( |
759 kKeyAvatarUrl, GetAvatarImageAtIndex(i, info_cache)); | 826 kKeyAvatarUrl, GetAvatarImageAtIndex(i, info_cache)); |
760 | 827 |
828 // GetProfileByPath returns a pointer if the profile is fully loaded, NULL | |
829 // otherwise. | |
830 Profile* profile = | |
831 g_browser_process->profile_manager()->GetProfileByPath(profile_path); | |
832 profile_value->SetBoolean(kKeyIsProfileLoaded, profile != nullptr); | |
833 | |
761 users_list.Append(profile_value); | 834 users_list.Append(profile_value); |
762 } | 835 } |
763 | 836 |
764 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers", | 837 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers", |
765 users_list, base::FundamentalValue(IsGuestModeEnabled())); | 838 users_list, base::FundamentalValue(IsGuestModeEnabled())); |
766 | 839 |
767 // This is the latest C++ code we have in the flow to show the UserManager. | 840 // This is the latest C++ code we have in the flow to show the UserManager. |
768 // This may be invoked more than once per UserManager lifetime; the | 841 // This may be invoked more than once per UserManager lifetime; the |
769 // UserManager will ensure all relevant logging only happens once. | 842 // UserManager will ensure all relevant logging only happens once. |
770 UserManager::OnUserManagerShown(); | 843 UserManager::OnUserManagerShown(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
848 Profile* profile, Profile::CreateStatus profile_create_status) { | 921 Profile* profile, Profile::CreateStatus profile_create_status) { |
849 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_); | 922 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_); |
850 if (browser && browser->window()) { | 923 if (browser && browser->window()) { |
851 OnBrowserWindowReady(browser); | 924 OnBrowserWindowReady(browser); |
852 } else { | 925 } else { |
853 registrar_.Add(this, | 926 registrar_.Add(this, |
854 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 927 chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
855 content::NotificationService::AllSources()); | 928 content::NotificationService::AllSources()); |
856 } | 929 } |
857 } | 930 } |
OLD | NEW |