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::ProfileCategoryStats 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 base::DictionaryValue* stat = new base::DictionaryValue(); |
| 595 stat->SetIntegerWithoutPathExpansion("count", item.count); |
| 596 stat->SetBooleanWithoutPathExpansion("success", item.success); |
| 597 return_value.SetWithoutPathExpansion(item.category, stat); |
| 598 } |
| 599 web_ui()->CallJavascriptFunction("updateRemoveWarningDialog", |
| 600 return_profile_path, return_value); |
| 601 } |
| 602 |
558 void UserManagerScreenHandler::OnGetTokenInfoResponse( | 603 void UserManagerScreenHandler::OnGetTokenInfoResponse( |
559 scoped_ptr<base::DictionaryValue> token_info) { | 604 scoped_ptr<base::DictionaryValue> token_info) { |
560 // Password is unchanged so user just mistyped it. Ask again. | 605 // Password is unchanged so user just mistyped it. Ask again. |
561 ReportAuthenticationResult(false, ProfileMetrics::AUTH_FAILED); | 606 ReportAuthenticationResult(false, ProfileMetrics::AUTH_FAILED); |
562 } | 607 } |
563 | 608 |
564 void UserManagerScreenHandler::OnOAuthError() { | 609 void UserManagerScreenHandler::OnOAuthError() { |
565 // Password has changed. Go through online signin flow. | 610 // Password has changed. Go through online signin flow. |
566 DCHECK(!email_address_.empty()); | 611 DCHECK(!email_address_.empty()); |
567 oauth_client_.reset(); | 612 oauth_client_.reset(); |
(...skipping 24 matching lines...) Expand all Loading... |
592 base::Bind(&UserManagerScreenHandler::HandleLaunchUser, | 637 base::Bind(&UserManagerScreenHandler::HandleLaunchUser, |
593 base::Unretained(this))); | 638 base::Unretained(this))); |
594 web_ui()->RegisterMessageCallback(kJsApiUserManagerRemoveUser, | 639 web_ui()->RegisterMessageCallback(kJsApiUserManagerRemoveUser, |
595 base::Bind(&UserManagerScreenHandler::HandleRemoveUser, | 640 base::Bind(&UserManagerScreenHandler::HandleRemoveUser, |
596 base::Unretained(this))); | 641 base::Unretained(this))); |
597 web_ui()->RegisterMessageCallback(kJsApiUserManagerAttemptUnlock, | 642 web_ui()->RegisterMessageCallback(kJsApiUserManagerAttemptUnlock, |
598 base::Bind(&UserManagerScreenHandler::HandleAttemptUnlock, | 643 base::Bind(&UserManagerScreenHandler::HandleAttemptUnlock, |
599 base::Unretained(this))); | 644 base::Unretained(this))); |
600 web_ui()->RegisterMessageCallback(kJsApiUserManagerLogRemoveUserWarningShown, | 645 web_ui()->RegisterMessageCallback(kJsApiUserManagerLogRemoveUserWarningShown, |
601 base::Bind(&HandleLogRemoveUserWarningShown)); | 646 base::Bind(&HandleLogRemoveUserWarningShown)); |
| 647 web_ui()->RegisterMessageCallback(kJsApiUserManagerRemoveUserWarningLoadStats, |
| 648 base::Bind(&UserManagerScreenHandler::HandleRemoveUserWarningLoadStats, |
| 649 base::Unretained(this))); |
602 | 650 |
603 const content::WebUI::MessageCallback& kDoNothingCallback = | 651 const content::WebUI::MessageCallback& kDoNothingCallback = |
604 base::Bind(&HandleAndDoNothing); | 652 base::Bind(&HandleAndDoNothing); |
605 | 653 |
606 // Unused callbacks from screen_account_picker.js | 654 // Unused callbacks from screen_account_picker.js |
607 web_ui()->RegisterMessageCallback("accountPickerReady", kDoNothingCallback); | 655 web_ui()->RegisterMessageCallback("accountPickerReady", kDoNothingCallback); |
608 web_ui()->RegisterMessageCallback("loginUIStateChanged", kDoNothingCallback); | 656 web_ui()->RegisterMessageCallback("loginUIStateChanged", kDoNothingCallback); |
609 web_ui()->RegisterMessageCallback("hideCaptivePortal", kDoNothingCallback); | 657 web_ui()->RegisterMessageCallback("hideCaptivePortal", kDoNothingCallback); |
610 web_ui()->RegisterMessageCallback("getTouchViewState", kDoNothingCallback); | 658 web_ui()->RegisterMessageCallback("getTouchViewState", kDoNothingCallback); |
611 // Unused callbacks from display_manager.js | 659 // 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)); | 696 IDS_LOGIN_POD_MENU_REMOVE_ITEM_ACCESSIBLE_NAME)); |
649 localized_strings->SetString("removeUser", | 697 localized_strings->SetString("removeUser", |
650 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BUTTON)); | 698 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BUTTON)); |
651 localized_strings->SetString("passwordFieldAccessibleName", | 699 localized_strings->SetString("passwordFieldAccessibleName", |
652 l10n_util::GetStringUTF16(IDS_LOGIN_POD_PASSWORD_FIELD_ACCESSIBLE_NAME)); | 700 l10n_util::GetStringUTF16(IDS_LOGIN_POD_PASSWORD_FIELD_ACCESSIBLE_NAME)); |
653 localized_strings->SetString("bootIntoWallpaper", "off"); | 701 localized_strings->SetString("bootIntoWallpaper", "off"); |
654 | 702 |
655 // For AccountPickerScreen, the remove user warning overlay. | 703 // For AccountPickerScreen, the remove user warning overlay. |
656 localized_strings->SetString("removeUserWarningButtonTitle", | 704 localized_strings->SetString("removeUserWarningButtonTitle", |
657 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BUTTON)); | 705 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BUTTON)); |
658 localized_strings->SetString("removeUserWarningText", | 706 localized_strings->SetString("removeUserWarningTextNonSync", |
659 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING)); | 707 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_NONSYNC)); |
| 708 localized_strings->SetString("removeUserWarningTextNonSyncNoStats", |
| 709 l10n_util::GetStringUTF16( |
| 710 IDS_LOGIN_POD_USER_REMOVE_WARNING_NONSYNC_NOSTATS)); |
| 711 localized_strings->SetString("removeUserWarningTextHistory", |
| 712 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_HISTORY)); |
| 713 localized_strings->SetString("removeUserWarningTextPasswords", |
| 714 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_PASSWORDS)); |
| 715 localized_strings->SetString("removeUserWarningTextBookmarks", |
| 716 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BOOKMARKS)); |
| 717 localized_strings->SetString("removeUserWarningTextSettings", |
| 718 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_SETTINGS)); |
| 719 localized_strings->SetString("removeUserWarningTextCalculating", |
| 720 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_CALCULATING)); |
| 721 localized_strings->SetString("removeUserWarningTextSync", |
| 722 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_SYNC)); |
| 723 localized_strings->SetString("removeUserWarningTextSyncNoStats", |
| 724 l10n_util::GetStringUTF16( |
| 725 IDS_LOGIN_POD_USER_REMOVE_WARNING_SYNC_NOSTATS)); |
660 localized_strings->SetString("removeLegacySupervisedUserWarningText", | 726 localized_strings->SetString("removeLegacySupervisedUserWarningText", |
661 l10n_util::GetStringFUTF16( | 727 l10n_util::GetStringFUTF16( |
662 IDS_LOGIN_POD_LEGACY_SUPERVISED_USER_REMOVE_WARNING, | 728 IDS_LOGIN_POD_LEGACY_SUPERVISED_USER_REMOVE_WARNING, |
663 base::UTF8ToUTF16(chrome::kSupervisedUserManagementDisplayURL))); | 729 base::UTF8ToUTF16(chrome::kSupervisedUserManagementDisplayURL))); |
664 | 730 |
665 // Strings needed for the User Manager tutorial slides. | 731 // Strings needed for the User Manager tutorial slides. |
666 localized_strings->SetString("tutorialNext", | 732 localized_strings->SetString("tutorialNext", |
667 l10n_util::GetStringUTF16(IDS_USER_MANAGER_TUTORIAL_NEXT)); | 733 l10n_util::GetStringUTF16(IDS_USER_MANAGER_TUTORIAL_NEXT)); |
668 localized_strings->SetString("tutorialDone", | 734 localized_strings->SetString("tutorialDone", |
669 l10n_util::GetStringUTF16(IDS_USER_MANAGER_TUTORIAL_DONE)); | 735 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)); | 817 kKeyNeedsSignin, info_cache->ProfileIsSigninRequiredAtIndex(i)); |
752 profile_value->SetBoolean( | 818 profile_value->SetBoolean( |
753 kKeyHasLocalCreds, | 819 kKeyHasLocalCreds, |
754 !info_cache->GetLocalAuthCredentialsOfProfileAtIndex(i).empty()); | 820 !info_cache->GetLocalAuthCredentialsOfProfileAtIndex(i).empty()); |
755 profile_value->SetBoolean(kKeyIsOwner, false); | 821 profile_value->SetBoolean(kKeyIsOwner, false); |
756 profile_value->SetBoolean(kKeyCanRemove, can_remove); | 822 profile_value->SetBoolean(kKeyCanRemove, can_remove); |
757 profile_value->SetBoolean(kKeyIsDesktop, true); | 823 profile_value->SetBoolean(kKeyIsDesktop, true); |
758 profile_value->SetString( | 824 profile_value->SetString( |
759 kKeyAvatarUrl, GetAvatarImageAtIndex(i, info_cache)); | 825 kKeyAvatarUrl, GetAvatarImageAtIndex(i, info_cache)); |
760 | 826 |
| 827 // GetProfileByPath returns a pointer if the profile is fully loaded, NULL |
| 828 // otherwise. |
| 829 Profile* profile = |
| 830 g_browser_process->profile_manager()->GetProfileByPath(profile_path); |
| 831 profile_value->SetBoolean(kKeyIsProfileLoaded, profile != nullptr); |
| 832 |
761 users_list.Append(profile_value); | 833 users_list.Append(profile_value); |
762 } | 834 } |
763 | 835 |
764 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers", | 836 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers", |
765 users_list, base::FundamentalValue(IsGuestModeEnabled())); | 837 users_list, base::FundamentalValue(IsGuestModeEnabled())); |
766 | 838 |
767 // This is the latest C++ code we have in the flow to show the UserManager. | 839 // 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 | 840 // This may be invoked more than once per UserManager lifetime; the |
769 // UserManager will ensure all relevant logging only happens once. | 841 // UserManager will ensure all relevant logging only happens once. |
770 UserManager::OnUserManagerShown(); | 842 UserManager::OnUserManagerShown(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
848 Profile* profile, Profile::CreateStatus profile_create_status) { | 920 Profile* profile, Profile::CreateStatus profile_create_status) { |
849 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_); | 921 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_); |
850 if (browser && browser->window()) { | 922 if (browser && browser->window()) { |
851 OnBrowserWindowReady(browser); | 923 OnBrowserWindowReady(browser); |
852 } else { | 924 } else { |
853 registrar_.Add(this, | 925 registrar_.Add(this, |
854 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 926 chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
855 content::NotificationService::AllSources()); | 927 content::NotificationService::AllSources()); |
856 } | 928 } |
857 } | 929 } |
OLD | NEW |