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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 const char kKeyEmailAddress[] = "emailAddress"; | 63 const char kKeyEmailAddress[] = "emailAddress"; |
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 kKeyIsProfileLoaded[] = "isProfileLoaded"; | |
73 | 74 |
74 // JS API callback names. | 75 // JS API callback names. |
75 const char kJsApiUserManagerInitialize[] = "userManagerInitialize"; | 76 const char kJsApiUserManagerInitialize[] = "userManagerInitialize"; |
76 const char kJsApiUserManagerAddUser[] = "addUser"; | 77 const char kJsApiUserManagerAddUser[] = "addUser"; |
77 const char kJsApiUserManagerAuthLaunchUser[] = "authenticatedLaunchUser"; | 78 const char kJsApiUserManagerAuthLaunchUser[] = "authenticatedLaunchUser"; |
78 const char kJsApiUserManagerLaunchGuest[] = "launchGuest"; | 79 const char kJsApiUserManagerLaunchGuest[] = "launchGuest"; |
79 const char kJsApiUserManagerLaunchUser[] = "launchUser"; | 80 const char kJsApiUserManagerLaunchUser[] = "launchUser"; |
80 const char kJsApiUserManagerRemoveUser[] = "removeUser"; | 81 const char kJsApiUserManagerRemoveUser[] = "removeUser"; |
81 const char kJsApiUserManagerAttemptUnlock[] = "attemptUnlock"; | 82 const char kJsApiUserManagerAttemptUnlock[] = "attemptUnlock"; |
82 const char kJsApiUserManagerLogRemoveUserWarningShown[] = | 83 const char kJsApiUserManagerLogRemoveUserWarningShown[] = |
83 "logRemoveUserWarningShown"; | 84 "logRemoveUserWarningShown"; |
84 | 85 const char kJsApiUserManagerRemoveUserWarningLoadStats[] = |
86 "removeUserWarningLoadStats"; | |
85 const size_t kAvatarIconSize = 180; | 87 const size_t kAvatarIconSize = 180; |
86 const int kMaxOAuthRetries = 3; | 88 const int kMaxOAuthRetries = 3; |
87 | 89 |
88 void HandleAndDoNothing(const base::ListValue* args) { | 90 void HandleAndDoNothing(const base::ListValue* args) { |
89 } | 91 } |
90 | 92 |
91 // This callback is run if the only profile has been deleted, and a new | 93 // This callback is run if the only profile has been deleted, and a new |
92 // profile has been created to replace it. | 94 // profile has been created to replace it. |
93 void OpenNewWindowForProfile( | 95 void OpenNewWindowForProfile( |
94 chrome::HostDesktopType desktop_type, | 96 chrome::HostDesktopType desktop_type, |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
541 const base::ListValue* args) { | 543 const base::ListValue* args) { |
542 std::string email; | 544 std::string email; |
543 CHECK(args->GetString(0, &email)); | 545 CHECK(args->GetString(0, &email)); |
544 SetAuthType( | 546 SetAuthType( |
545 email, | 547 email, |
546 proximity_auth::ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD, | 548 proximity_auth::ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD, |
547 base::string16()); | 549 base::string16()); |
548 HideUserPodCustomIcon(email); | 550 HideUserPodCustomIcon(email); |
549 } | 551 } |
550 | 552 |
553 void UserManagerScreenHandler::HandleRemoveUserWarningLoadStats( | |
554 const base::ListValue* args) { | |
555 const base::Value* profile_path_value; | |
556 | |
557 if (!args->Get(0, &profile_path_value)) | |
558 return; | |
559 | |
560 base::FilePath profile_path; | |
561 | |
562 if (!base::GetValueAsFilePath(*profile_path_value, &profile_path)) | |
563 return; | |
564 | |
565 base::StringValue return_profile_path(profile_path.value()); | |
566 Profile* profile = g_browser_process->profile_manager()-> | |
567 GetProfileByPath(profile_path); | |
568 | |
569 if (!profile) | |
570 return; | |
571 | |
572 profiles::GetProfileStatistics( | |
573 profile, | |
574 base::Bind( | |
575 &UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback, | |
576 weak_ptr_factory_.GetWeakPtr(), profile_path), | |
577 &tracker_); | |
578 } | |
579 | |
580 void UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback( | |
581 base::FilePath profile_path, | |
582 profiles::ProfileStatisticsValues result) { | |
583 // Copy result into return_value. | |
584 base::StringValue return_profile_path(profile_path.value()); | |
585 base::DictionaryValue return_value; | |
586 for (profiles::ProfileStatisticsValues::const_iterator | |
587 iter = result.begin(); iter != result.end(); iter++) { | |
588 return_value.SetIntegerWithoutPathExpansion(iter->first, iter->second); | |
589 } | |
590 web_ui()->CallJavascriptFunction("updateRemoveWarningDialog", | |
591 return_profile_path, return_value); | |
592 } | |
593 | |
551 void UserManagerScreenHandler::OnGetTokenInfoResponse( | 594 void UserManagerScreenHandler::OnGetTokenInfoResponse( |
552 scoped_ptr<base::DictionaryValue> token_info) { | 595 scoped_ptr<base::DictionaryValue> token_info) { |
553 // Password is unchanged so user just mistyped it. Ask again. | 596 // Password is unchanged so user just mistyped it. Ask again. |
554 ReportAuthenticationResult(false, ProfileMetrics::AUTH_FAILED); | 597 ReportAuthenticationResult(false, ProfileMetrics::AUTH_FAILED); |
555 } | 598 } |
556 | 599 |
557 void UserManagerScreenHandler::OnOAuthError() { | 600 void UserManagerScreenHandler::OnOAuthError() { |
558 // Password has changed. Go through online signin flow. | 601 // Password has changed. Go through online signin flow. |
559 DCHECK(!email_address_.empty()); | 602 DCHECK(!email_address_.empty()); |
560 oauth_client_.reset(); | 603 oauth_client_.reset(); |
(...skipping 24 matching lines...) Expand all Loading... | |
585 base::Bind(&UserManagerScreenHandler::HandleLaunchUser, | 628 base::Bind(&UserManagerScreenHandler::HandleLaunchUser, |
586 base::Unretained(this))); | 629 base::Unretained(this))); |
587 web_ui()->RegisterMessageCallback(kJsApiUserManagerRemoveUser, | 630 web_ui()->RegisterMessageCallback(kJsApiUserManagerRemoveUser, |
588 base::Bind(&UserManagerScreenHandler::HandleRemoveUser, | 631 base::Bind(&UserManagerScreenHandler::HandleRemoveUser, |
589 base::Unretained(this))); | 632 base::Unretained(this))); |
590 web_ui()->RegisterMessageCallback(kJsApiUserManagerAttemptUnlock, | 633 web_ui()->RegisterMessageCallback(kJsApiUserManagerAttemptUnlock, |
591 base::Bind(&UserManagerScreenHandler::HandleAttemptUnlock, | 634 base::Bind(&UserManagerScreenHandler::HandleAttemptUnlock, |
592 base::Unretained(this))); | 635 base::Unretained(this))); |
593 web_ui()->RegisterMessageCallback(kJsApiUserManagerLogRemoveUserWarningShown, | 636 web_ui()->RegisterMessageCallback(kJsApiUserManagerLogRemoveUserWarningShown, |
594 base::Bind(&HandleLogRemoveUserWarningShown)); | 637 base::Bind(&HandleLogRemoveUserWarningShown)); |
638 web_ui()->RegisterMessageCallback(kJsApiUserManagerRemoveUserWarningLoadStats, | |
639 base::Bind(&UserManagerScreenHandler::HandleRemoveUserWarningLoadStats, | |
640 base::Unretained(this))); | |
595 | 641 |
596 const content::WebUI::MessageCallback& kDoNothingCallback = | 642 const content::WebUI::MessageCallback& kDoNothingCallback = |
597 base::Bind(&HandleAndDoNothing); | 643 base::Bind(&HandleAndDoNothing); |
598 | 644 |
599 // Unused callbacks from screen_account_picker.js | 645 // Unused callbacks from screen_account_picker.js |
600 web_ui()->RegisterMessageCallback("accountPickerReady", kDoNothingCallback); | 646 web_ui()->RegisterMessageCallback("accountPickerReady", kDoNothingCallback); |
601 web_ui()->RegisterMessageCallback("loginUIStateChanged", kDoNothingCallback); | 647 web_ui()->RegisterMessageCallback("loginUIStateChanged", kDoNothingCallback); |
602 web_ui()->RegisterMessageCallback("hideCaptivePortal", kDoNothingCallback); | 648 web_ui()->RegisterMessageCallback("hideCaptivePortal", kDoNothingCallback); |
603 web_ui()->RegisterMessageCallback("getTouchViewState", kDoNothingCallback); | 649 web_ui()->RegisterMessageCallback("getTouchViewState", kDoNothingCallback); |
604 // Unused callbacks from display_manager.js | 650 // Unused callbacks from display_manager.js |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
641 IDS_LOGIN_POD_MENU_REMOVE_ITEM_ACCESSIBLE_NAME)); | 687 IDS_LOGIN_POD_MENU_REMOVE_ITEM_ACCESSIBLE_NAME)); |
642 localized_strings->SetString("removeUser", | 688 localized_strings->SetString("removeUser", |
643 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BUTTON)); | 689 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BUTTON)); |
644 localized_strings->SetString("passwordFieldAccessibleName", | 690 localized_strings->SetString("passwordFieldAccessibleName", |
645 l10n_util::GetStringUTF16(IDS_LOGIN_POD_PASSWORD_FIELD_ACCESSIBLE_NAME)); | 691 l10n_util::GetStringUTF16(IDS_LOGIN_POD_PASSWORD_FIELD_ACCESSIBLE_NAME)); |
646 localized_strings->SetString("bootIntoWallpaper", "off"); | 692 localized_strings->SetString("bootIntoWallpaper", "off"); |
647 | 693 |
648 // For AccountPickerScreen, the remove user warning overlay. | 694 // For AccountPickerScreen, the remove user warning overlay. |
649 localized_strings->SetString("removeUserWarningButtonTitle", | 695 localized_strings->SetString("removeUserWarningButtonTitle", |
650 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BUTTON)); | 696 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BUTTON)); |
651 localized_strings->SetString("removeUserWarningText", | 697 localized_strings->SetString("removeUserWarningTextNonSync", |
652 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING)); | 698 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_NONSYNC)); |
699 localized_strings->SetString("removeUserWarningTextNonSyncNoStats", | |
700 l10n_util::GetStringUTF16( | |
701 IDS_LOGIN_POD_USER_REMOVE_WARNING_NONSYNC_NOSTATS)); | |
702 localized_strings->SetString("removeUserWarningTextHistory", | |
703 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_HISTORY)); | |
704 localized_strings->SetString("removeUserWarningTextPasswords", | |
705 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_PASSWORDS)); | |
706 localized_strings->SetString("removeUserWarningTextBookmarks", | |
707 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BOOKMARKS)); | |
708 localized_strings->SetString("removeUserWarningTextSettings", | |
709 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_SETTINGS)); | |
710 localized_strings->SetString("removeUserWarningTextCalculating", | |
711 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_CALCULATING)); | |
712 localized_strings->SetString("removeUserWarningTextSync", | |
713 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_SYNC)); | |
714 localized_strings->SetString("removeUserWarningTextSyncNoStats", | |
715 l10n_util::GetStringUTF16( | |
716 IDS_LOGIN_POD_USER_REMOVE_WARNING_SYNC_NOSTATS)); | |
653 localized_strings->SetString("removeLegacySupervisedUserWarningText", | 717 localized_strings->SetString("removeLegacySupervisedUserWarningText", |
654 l10n_util::GetStringFUTF16( | 718 l10n_util::GetStringFUTF16( |
655 IDS_LOGIN_POD_LEGACY_SUPERVISED_USER_REMOVE_WARNING, | 719 IDS_LOGIN_POD_LEGACY_SUPERVISED_USER_REMOVE_WARNING, |
656 base::UTF8ToUTF16(chrome::kSupervisedUserManagementDisplayURL))); | 720 base::UTF8ToUTF16(chrome::kSupervisedUserManagementDisplayURL))); |
657 | 721 |
658 // Strings needed for the User Manager tutorial slides. | 722 // Strings needed for the User Manager tutorial slides. |
659 localized_strings->SetString("tutorialNext", | 723 localized_strings->SetString("tutorialNext", |
660 l10n_util::GetStringUTF16(IDS_USER_MANAGER_TUTORIAL_NEXT)); | 724 l10n_util::GetStringUTF16(IDS_USER_MANAGER_TUTORIAL_NEXT)); |
661 localized_strings->SetString("tutorialDone", | 725 localized_strings->SetString("tutorialDone", |
662 l10n_util::GetStringUTF16(IDS_USER_MANAGER_TUTORIAL_DONE)); | 726 l10n_util::GetStringUTF16(IDS_USER_MANAGER_TUTORIAL_DONE)); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
741 profile_value->SetBoolean( | 805 profile_value->SetBoolean( |
742 kKeyChildUser, info_cache->ProfileIsChildAtIndex(i)); | 806 kKeyChildUser, info_cache->ProfileIsChildAtIndex(i)); |
743 profile_value->SetBoolean( | 807 profile_value->SetBoolean( |
744 kKeyNeedsSignin, info_cache->ProfileIsSigninRequiredAtIndex(i)); | 808 kKeyNeedsSignin, info_cache->ProfileIsSigninRequiredAtIndex(i)); |
745 profile_value->SetBoolean(kKeyIsOwner, false); | 809 profile_value->SetBoolean(kKeyIsOwner, false); |
746 profile_value->SetBoolean(kKeyCanRemove, can_remove); | 810 profile_value->SetBoolean(kKeyCanRemove, can_remove); |
747 profile_value->SetBoolean(kKeyIsDesktop, true); | 811 profile_value->SetBoolean(kKeyIsDesktop, true); |
748 profile_value->SetString( | 812 profile_value->SetString( |
749 kKeyAvatarUrl, GetAvatarImageAtIndex(i, info_cache)); | 813 kKeyAvatarUrl, GetAvatarImageAtIndex(i, info_cache)); |
750 | 814 |
815 // GetProfileByPath returns a pointer if the profile is fully loaded, NULL | |
816 // otherwise. | |
817 Profile* profile = | |
818 g_browser_process->profile_manager()->GetProfileByPath(profile_path); | |
819 profile_value->SetBoolean(kKeyIsProfileLoaded, profile ? true : false); | |
Mike Lerman
2015/08/13 14:56:33
(optional) the condition can written more simply a
lwchkg
2015/08/13 16:20:17
Acknowledged.
| |
820 | |
751 users_list.Append(profile_value); | 821 users_list.Append(profile_value); |
752 } | 822 } |
753 | 823 |
754 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers", | 824 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers", |
755 users_list, base::FundamentalValue(IsGuestModeEnabled())); | 825 users_list, base::FundamentalValue(IsGuestModeEnabled())); |
756 | 826 |
757 // This is the latest C++ code we have in the flow to show the UserManager. | 827 // This is the latest C++ code we have in the flow to show the UserManager. |
758 // This may be invoked more than once per UserManager lifetime; the | 828 // This may be invoked more than once per UserManager lifetime; the |
759 // UserManager will ensure all relevant logging only happens once. | 829 // UserManager will ensure all relevant logging only happens once. |
760 UserManager::OnUserManagerShown(); | 830 UserManager::OnUserManagerShown(); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
839 Profile* profile, Profile::CreateStatus profile_create_status) { | 909 Profile* profile, Profile::CreateStatus profile_create_status) { |
840 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_); | 910 Browser* browser = chrome::FindAnyBrowser(profile, false, desktop_type_); |
841 if (browser && browser->window()) { | 911 if (browser && browser->window()) { |
842 OnBrowserWindowReady(browser); | 912 OnBrowserWindowReady(browser); |
843 } else { | 913 } else { |
844 registrar_.Add(this, | 914 registrar_.Add(this, |
845 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 915 chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
846 content::NotificationService::AllSources()); | 916 content::NotificationService::AllSources()); |
847 } | 917 } |
848 } | 918 } |
OLD | NEW |