Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/webui/signin/user_chooser_screen_handler.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "chrome/browser/browser_process.h" | |
| 9 #include "chrome/browser/profiles/profile.h" | |
| 10 #include "chrome/browser/profiles/profile_info_cache.h" | |
| 11 #include "chrome/browser/profiles/profile_info_util.h" | |
| 12 #include "chrome/browser/profiles/profile_manager.h" | |
| 13 #include "chrome/browser/ui/browser_commands.h" | |
| 14 #include "chrome/browser/ui/browser_finder.h" | |
| 15 #include "chrome/browser/ui/singleton_tabs.h" | |
| 16 #include "grit/browser_resources.h" | |
| 17 #include "grit/chromium_strings.h" | |
| 18 #include "grit/generated_resources.h" | |
| 19 #include "third_party/skia/include/core/SkBitmap.h" | |
| 20 #include "ui/base/l10n/l10n_util.h" | |
| 21 #include "ui/gfx/image/image_util.h" | |
| 22 #include "ui/webui/web_ui_util.h" | |
| 23 | |
| 24 namespace { | |
| 25 // User dictionary keys. | |
| 26 const char kKeyUsername[] = "username"; | |
| 27 const char kKeyDisplayName[]= "displayName"; | |
| 28 const char kKeyEmailAddress[] = "emailAddress"; | |
| 29 const char kKeyPublicAccount[] = "publicAccount"; | |
| 30 const char kKeyLocallyManagedUser[] = "locallyManagedUser"; | |
| 31 const char kKeySignedIn[] = "signedIn"; | |
| 32 const char kKeyCanRemove[] = "canRemove"; | |
| 33 const char kKeyIsOwner[] = "isOwner"; | |
| 34 const char kKeyIsDesktop[] = "isDesktopScreen"; | |
| 35 const char kKeyAvatarUrl[] = "userImage"; | |
| 36 const char kKeyNeedsSignin[] = "needsSignin"; | |
| 37 const char kGAIAPictureFileNameKey[] = "gaia_picture_file_name"; | |
| 38 | |
| 39 // Max number of users to show. | |
| 40 const size_t kMaxUsers = 18; | |
| 41 | |
| 42 // Type of the login screen UI that is currently presented to user. | |
| 43 const char kSourceGaiaSignin[] = "gaia-signin"; | |
| 44 const char kSourceAccountPicker[] = "account-picker"; | |
| 45 | |
| 46 // JS API callback names. | |
| 47 const char kJsApiUserChooserInitialize[] = "userChooserInitialize"; | |
| 48 const char kJsApiUserChooserAddUser[] = "addUser"; | |
| 49 const char kJsApiUserChooserLaunchGuest[] = "launchGuest"; | |
| 50 const char kJsApiUserChooserLaunchUser[] = "launchUser"; | |
| 51 const char kJsApiUserChooserRemoveUser[] = "removeUser"; | |
| 52 } // namespace | |
| 53 | |
| 54 UserChooserScreenHandler::UserChooserScreenHandler() { | |
| 55 } | |
| 56 | |
| 57 UserChooserScreenHandler::~UserChooserScreenHandler() { | |
| 58 } | |
| 59 | |
| 60 void UserChooserScreenHandler::HandleInitialize(const base::ListValue* args) { | |
| 61 SendUserList(); | |
| 62 web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserChooserScreen"); | |
| 63 } | |
| 64 | |
| 65 void UserChooserScreenHandler::HandleAddUser(const base::ListValue* args) { | |
| 66 // TODO(noms): Should redirect to a sign in page. | |
| 67 chrome::ShowSingletonTab(chrome::FindBrowserWithWebContents( | |
| 68 web_ui()->GetWebContents()), | |
| 69 GURL("chrome://settings/createProfile")); | |
| 70 } | |
| 71 | |
| 72 void UserChooserScreenHandler::HandleRemoveUser(const base::ListValue* args) { | |
| 73 // TODO(noms): Should delete the user. | |
| 74 chrome::ShowSingletonTab(chrome::FindBrowserWithWebContents( | |
| 75 web_ui()->GetWebContents()), | |
| 76 GURL("chrome://settings/search#Users")); | |
| 77 } | |
| 78 | |
| 79 void UserChooserScreenHandler::HandleLaunchGuest(const base::ListValue* args) { | |
| 80 // TODO(noms): Once guest mode is ready, should launch a guest browser. | |
| 81 chrome::NewIncognitoWindow(chrome::FindBrowserWithWebContents( | |
| 82 web_ui()->GetWebContents())); | |
| 83 } | |
| 84 | |
| 85 void UserChooserScreenHandler::HandleLaunchUser(const base::ListValue* args) { | |
| 86 string16 emailAddress; | |
| 87 string16 displayName; | |
| 88 | |
| 89 if (!args->GetString(0, &emailAddress) || | |
| 90 !args->GetString(1, &displayName)) { | |
| 91 NOTREACHED(); | |
| 92 return; | |
| 93 } | |
| 94 | |
| 95 ProfileInfoCache& info_cache = | |
| 96 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
| 97 chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop(); | |
| 98 | |
| 99 for (size_t i = 0; i < info_cache.GetNumberOfProfiles(); ++i) { | |
| 100 if (info_cache.GetUserNameOfProfileAtIndex(i) == emailAddress && | |
| 101 info_cache.GetNameOfProfileAtIndex(i) == displayName) { | |
|
Nikita (slow)
2013/06/11 18:43:28
Why you have to check both email and displayName?
noms (inactive)
2013/06/11 19:39:41
On the desktop you can have local profiles that ar
Nikita (slow)
2013/06/13 08:12:38
I've realized that there's probably no code that p
| |
| 102 base::FilePath path = info_cache.GetPathOfProfileAtIndex(i); | |
| 103 ProfileManager::SwitchToProfile(path, desktop_type, true); | |
| 104 break; | |
| 105 } | |
| 106 } | |
| 107 } | |
| 108 | |
| 109 void UserChooserScreenHandler::RegisterMessages() { | |
| 110 web_ui()->RegisterMessageCallback(kJsApiUserChooserInitialize, | |
| 111 base::Bind(&UserChooserScreenHandler::HandleInitialize, | |
| 112 base::Unretained(this))); | |
| 113 web_ui()->RegisterMessageCallback(kJsApiUserChooserAddUser, | |
| 114 base::Bind(&UserChooserScreenHandler::HandleAddUser, | |
| 115 base::Unretained(this))); | |
| 116 web_ui()->RegisterMessageCallback(kJsApiUserChooserLaunchGuest, | |
| 117 base::Bind(&UserChooserScreenHandler::HandleLaunchGuest, | |
| 118 base::Unretained(this))); | |
| 119 web_ui()->RegisterMessageCallback(kJsApiUserChooserLaunchUser, | |
| 120 base::Bind(&UserChooserScreenHandler::HandleLaunchUser, | |
| 121 base::Unretained(this))); | |
| 122 web_ui()->RegisterMessageCallback(kJsApiUserChooserRemoveUser, | |
| 123 base::Bind(&UserChooserScreenHandler::HandleRemoveUser, | |
| 124 base::Unretained(this))); | |
| 125 } | |
| 126 | |
| 127 void UserChooserScreenHandler::GetLocalizedValues( | |
| 128 base::DictionaryValue* localized_strings) { | |
| 129 | |
| 130 // For Header Bar. | |
| 131 localized_strings->SetString("signedIn", | |
| 132 l10n_util::GetStringUTF16(IDS_SCREEN_LOCK_ACTIVE_USER)); | |
| 133 localized_strings->SetString("signinButton", | |
| 134 l10n_util::GetStringUTF16(IDS_LOGIN_BUTTON)); | |
| 135 localized_strings->SetString("addUser", | |
| 136 l10n_util::GetStringUTF16(IDS_ADD_USER_BUTTON)); | |
| 137 localized_strings->SetString("cancel", l10n_util::GetStringUTF16(IDS_CANCEL)); | |
| 138 localized_strings->SetString("browseAsGuest", | |
| 139 l10n_util::GetStringUTF16(IDS_GO_INCOGNITO_BUTTON)); | |
| 140 localized_strings->SetString("createAccount", | |
| 141 l10n_util::GetStringUTF16(IDS_CREATE_ACCOUNT_HTML)); | |
| 142 localized_strings->SetString("guestSignin", | |
| 143 l10n_util::GetStringUTF16(IDS_BROWSE_WITHOUT_SIGNING_IN_HTML)); | |
| 144 localized_strings->SetString("shutDown", | |
| 145 l10n_util::GetStringUTF16(IDS_SHUTDOWN_BUTTON)); | |
| 146 localized_strings->SetString("showApps", | |
| 147 l10n_util::GetStringUTF16(IDS_KIOSK_APPS_BUTTON)); | |
| 148 localized_strings->SetString("signOutUser", | |
| 149 l10n_util::GetStringUTF16(IDS_SCREEN_LOCK_SIGN_OUT)); | |
| 150 localized_strings->SetString("bootIntoWallpaper", "off"); | |
| 151 localized_strings->SetBoolean("enableAppMode", false); | |
| 152 | |
| 153 // For AccountPickerScreen. | |
| 154 localized_strings->SetString("screenType", "login-add-user"); | |
| 155 localized_strings->SetString("highlightStrength", "normal"); | |
| 156 localized_strings->SetString("title", "User Chooser"); | |
| 157 localized_strings->SetString("publicAccountReminder", | |
| 158 l10n_util::GetStringUTF16(IDS_LOGIN_PUBLIC_ACCOUNT_SIGNOUT_REMINDER)); | |
| 159 localized_strings->SetString("publicAccountEnter", | |
| 160 l10n_util::GetStringUTF16(IDS_LOGIN_PUBLIC_ACCOUNT_ENTER)); | |
| 161 localized_strings->SetString("publicAccountEnterAccessibleName", | |
| 162 l10n_util::GetStringUTF16( | |
| 163 IDS_LOGIN_PUBLIC_ACCOUNT_ENTER_ACCESSIBLE_NAME)); | |
| 164 localized_strings->SetString("lockAnimationsType", "new"); | |
| 165 localized_strings->SetString("passwordHint", | |
| 166 l10n_util::GetStringUTF16(IDS_LOGIN_POD_EMPTY_PASSWORD_TEXT)); | |
| 167 localized_strings->SetString("podMenuButtonAccessibleName", | |
| 168 l10n_util::GetStringUTF16(IDS_LOGIN_POD_MENU_BUTTON_ACCESSIBLE_NAME)); | |
| 169 localized_strings->SetString("podMenuRemoveItemAccessibleName", | |
| 170 l10n_util::GetStringUTF16( | |
| 171 IDS_LOGIN_POD_MENU_REMOVE_ITEM_ACCESSIBLE_NAME)); | |
| 172 localized_strings->SetString("ownerUserPattern", | |
| 173 l10n_util::GetStringUTF16(IDS_LOGIN_POD_OWNER_USER)); | |
| 174 localized_strings->SetString("removeUser", | |
| 175 l10n_util::GetStringUTF16(IDS_LOGIN_POD_REMOVE_USER)); | |
| 176 localized_strings->SetString("passwordFieldAccessibleName", | |
| 177 l10n_util::GetStringUTF16(IDS_LOGIN_POD_PASSWORD_FIELD_ACCESSIBLE_NAME)); | |
| 178 localized_strings->SetString("publicAccountInfoFormat", | |
| 179 l10n_util::GetStringUTF16(IDS_LOGIN_PUBLIC_ACCOUNT_INFO_FORMAT)); | |
| 180 | |
| 181 // For GaiaSigninScreen. | |
| 182 localized_strings->SetString("signinScreenTitle", | |
| 183 l10n_util::GetStringUTF16(IDS_SIGNIN_SCREEN_TITLE)); | |
| 184 localized_strings->SetString("createLocallyManagedUser", | |
| 185 l10n_util::GetStringUTF16(IDS_CREATE_LOCALLY_MANAGED_USER_HTML)); | |
| 186 localized_strings->SetString("createManagedUserFeatureName", | |
| 187 l10n_util::GetStringUTF16(IDS_CREATE_LOCALLY_MANAGED_USER_FEATURE_NAME)); | |
| 188 localized_strings->SetString("createManagedUserNoManagerText", | |
| 189 l10n_util::GetStringUTF16( | |
| 190 IDS_CREATE_LOCALLY_MANAGED_USER_NO_MANAGER_TEXT)); | |
| 191 localized_strings->SetString("learnMore", | |
| 192 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); | |
| 193 } | |
| 194 | |
| 195 void UserChooserScreenHandler::SendUserList() { | |
| 196 ListValue users_list; | |
| 197 base::FilePath current_profile_path = | |
| 198 web_ui()->GetWebContents()->GetBrowserContext()->GetPath(); | |
| 199 const ProfileInfoCache& info_cache = | |
| 200 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
| 201 | |
| 202 for (size_t i = 0; i < info_cache.GetNumberOfProfiles(); ++i) { | |
| 203 DictionaryValue* profile_value = new DictionaryValue(); | |
| 204 | |
| 205 base::FilePath profile_path = info_cache.GetPathOfProfileAtIndex(i); | |
| 206 bool is_active_user = (profile_path == current_profile_path); | |
| 207 bool needs_signin = info_cache.ProfileIsSigninRequiredAtIndex(i); | |
| 208 | |
| 209 profile_value->SetString( | |
| 210 kKeyUsername, info_cache.GetUserNameOfProfileAtIndex(i)); | |
| 211 profile_value->SetString( | |
| 212 kKeyEmailAddress, info_cache.GetUserNameOfProfileAtIndex(i)); | |
| 213 profile_value->SetString( | |
| 214 kKeyDisplayName, info_cache.GetNameOfProfileAtIndex(i)); | |
| 215 profile_value->SetBoolean(kKeyPublicAccount, false); | |
| 216 profile_value->SetBoolean(kKeyLocallyManagedUser, false); | |
| 217 profile_value->SetBoolean(kKeySignedIn, is_active_user); | |
| 218 profile_value->SetBoolean(kKeyNeedsSignin, needs_signin); | |
| 219 profile_value->SetBoolean(kKeyIsOwner, false); | |
| 220 profile_value->SetBoolean(kKeyCanRemove, true); | |
| 221 profile_value->SetBoolean(kKeyIsDesktop, true); | |
| 222 | |
| 223 bool is_gaia_picture = | |
| 224 info_cache.IsUsingGAIAPictureOfProfileAtIndex(i) && | |
| 225 info_cache.GetGAIAPictureOfProfileAtIndex(i); | |
| 226 | |
| 227 gfx::Image icon = profiles::GetSizedAvatarIconWithBorder( | |
| 228 info_cache.GetAvatarIconOfProfileAtIndex(i), is_gaia_picture, 160, 160); | |
| 229 profile_value->SetString(kKeyAvatarUrl, | |
| 230 webui::GetBitmapDataUrl(icon.AsBitmap())); | |
| 231 | |
| 232 if (is_active_user) | |
| 233 users_list.Insert(0, profile_value); | |
| 234 else | |
| 235 users_list.Append(profile_value); | |
| 236 } | |
| 237 | |
| 238 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers", | |
| 239 users_list, base::FundamentalValue(false), base::FundamentalValue(true)); | |
| 240 } | |
| OLD | NEW |