Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: chrome/browser/ui/webui/signin/user_chooser_screen_handler.cc

Issue 16104008: First try at a user management screen for the desktop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: code cleanup Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/avatar_menu_model.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_info_cache.h"
12 #include "chrome/browser/profiles/profile_info_util.h"
13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/browser/ui/browser_commands.h"
15 #include "chrome/browser/ui/browser_finder.h"
16 #include "chrome/browser/ui/singleton_tabs.h"
17 #include "grit/browser_resources.h"
18 #include "grit/chromium_strings.h"
19 #include "grit/generated_resources.h"
20 #include "third_party/skia/include/core/SkBitmap.h"
21 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/gfx/image/image_util.h"
23 #include "ui/webui/web_ui_util.h"
24
25 namespace {
26 // User dictionary keys.
27 const char kKeyUsername[] = "username";
28 const char kKeyDisplayName[]= "displayName";
29 const char kKeyEmailAddress[] = "emailAddress";
30 const char kKeyPublicAccount[] = "publicAccount";
31 const char kKeyLocallyManagedUser[] = "locallyManagedUser";
32 const char kKeySignedIn[] = "signedIn";
33 const char kKeyCanRemove[] = "canRemove";
34 const char kKeyIsOwner[] = "isOwner";
35 const char kKeyIsDesktop[] = "isDesktopScreen";
36 const char kKeyAvatarUrl[] = "userImage";
37 const char kUserOAuthTokenStatus[] = "oauthTokenStatus";
38 const char kGAIAPictureFileNameKey[] = "gaia_picture_file_name";
39
40 // Max number of users to show.
41 const size_t kMaxUsers = 18;
42
43 // Type of the login screen UI that is currently presented to user.
44 const char kSourceGaiaSignin[] = "gaia-signin";
45 const char kSourceAccountPicker[] = "account-picker";
46
47 // JS API callback names.
48 const char kJsApiUserChooserInitialize[] = "userChooserInitialize";
49 const char kJsApiUserChooserAddUser[] = "addUser";
50 const char kJsApiUserChooserLaunchGuest[] = "launchGuest";
51 const char kJsApiUserChooserLaunchUser[] = "launchUser";
52 const char kJsApiUserChooserRemoveUser[] = "removeUser";
53 } // namespace
54
55 UserChooserScreenHandler::UserChooserScreenHandler() {
56 avatar_menu_model_.reset(new AvatarMenuModel(
57 &g_browser_process->profile_manager()->GetProfileInfoCache(),
58 NULL, NULL));
59 }
60
61 UserChooserScreenHandler::~UserChooserScreenHandler() {
62 }
63
64 void UserChooserScreenHandler::HandleInitialize(const base::ListValue* args) {
65 SendUserList();
66 web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserChooserScreen");
67 }
68
69 void UserChooserScreenHandler::HandleAddUser(const base::ListValue* args) {
70 chrome::ShowSingletonTab(chrome::FindBrowserWithWebContents(
71 web_ui()->GetWebContents()),
72 GURL("chrome://settings/createProfile"));
73 }
74
75 void UserChooserScreenHandler::HandleRemoveUser(const base::ListValue* args) {
76 chrome::ShowSingletonTab(chrome::FindBrowserWithWebContents(
Roger Tawa OOO till Jul 10th 2013/06/05 18:53:56 Add a TODO here for what the real behaviour should
noms 2013/06/06 19:01:36 Done.
77 web_ui()->GetWebContents()),
78 GURL("chrome://settings/search#Users"));
79 }
80
81 void UserChooserScreenHandler::HandleLaunchGuest(const base::ListValue* args) {
82 chrome::NewIncognitoWindow(chrome::FindBrowserWithWebContents(
Roger Tawa OOO till Jul 10th 2013/06/05 18:53:56 Add a TODO here for what the real behaviour should
noms 2013/06/06 19:01:36 Done.
83 web_ui()->GetWebContents()));
84 }
85
86 void UserChooserScreenHandler::HandleLaunchUser(const base::ListValue* args) {
87 string16 emailAddress;
88 string16 displayName;
89
90 if (!args->GetString(0, &emailAddress) ||
91 !args->GetString(1, &displayName)) {
92 NOTREACHED();
93 return;
94 }
95
96 ProfileInfoCache& info_cache =
97 g_browser_process->profile_manager()->GetProfileInfoCache();
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) {
102 avatar_menu_model_->SwitchToProfile(i, true);
Roger Tawa OOO till Jul 10th 2013/06/05 18:53:56 This seems to be the only use of the menu model.
noms 2013/06/06 19:01:36 Done.
103 break;
104 }
105 }
106 }
107
108 void UserChooserScreenHandler::RegisterMessages() {
109 web_ui()->RegisterMessageCallback(kJsApiUserChooserInitialize,
110 base::Bind(&UserChooserScreenHandler::HandleInitialize,
111 base::Unretained(this)));
112 web_ui()->RegisterMessageCallback(kJsApiUserChooserAddUser,
113 base::Bind(&UserChooserScreenHandler::HandleAddUser,
114 base::Unretained(this)));
115 web_ui()->RegisterMessageCallback(kJsApiUserChooserLaunchGuest,
116 base::Bind(&UserChooserScreenHandler::HandleLaunchGuest,
117 base::Unretained(this)));
118 web_ui()->RegisterMessageCallback(kJsApiUserChooserLaunchUser,
119 base::Bind(&UserChooserScreenHandler::HandleLaunchUser,
120 base::Unretained(this)));
121 web_ui()->RegisterMessageCallback(kJsApiUserChooserRemoveUser,
122 base::Bind(&UserChooserScreenHandler::HandleRemoveUser,
123 base::Unretained(this)));
124 }
125
126 void UserChooserScreenHandler::GetLocalizedValues(
127 base::DictionaryValue* localized_strings) {
128
129 // For Header Bar.
130 localized_strings->SetString("signedIn",
131 l10n_util::GetStringUTF16(IDS_SCREEN_LOCK_ACTIVE_USER));
132 localized_strings->SetString("signinButton",
133 l10n_util::GetStringUTF16(IDS_LOGIN_BUTTON));
134 localized_strings->SetString("addUser",
135 l10n_util::GetStringUTF16(IDS_ADD_USER_BUTTON));
136 localized_strings->SetString("cancel", l10n_util::GetStringUTF16(IDS_CANCEL));
137 localized_strings->SetString("browseAsGuest",
138 l10n_util::GetStringUTF16(IDS_GO_INCOGNITO_BUTTON));
139 localized_strings->SetString("createAccount",
140 l10n_util::GetStringUTF16(IDS_CREATE_ACCOUNT_HTML));
141 localized_strings->SetString("guestSignin",
142 l10n_util::GetStringUTF16(IDS_BROWSE_WITHOUT_SIGNING_IN_HTML));
143 localized_strings->SetString("shutDown",
144 l10n_util::GetStringUTF16(IDS_SHUTDOWN_BUTTON));
145 localized_strings->SetString("showApps",
146 l10n_util::GetStringUTF16(IDS_KIOSK_APPS_BUTTON));
147 localized_strings->SetString("signOutUser",
148 l10n_util::GetStringUTF16(IDS_SCREEN_LOCK_SIGN_OUT));
149 localized_strings->SetString("bootIntoWallpaper", "off");
150 localized_strings->SetBoolean("enableAppMode", false);
151
152 // For AccountPickerScreen.
153 localized_strings->SetString("screenType", "login-add-user");
154 localized_strings->SetString("highlightStrength", "normal");
155 localized_strings->SetString("title", "User Chooser");
156 localized_strings->SetString("publicAccountReminder",
157 l10n_util::GetStringUTF16(IDS_LOGIN_PUBLIC_ACCOUNT_SIGNOUT_REMINDER));
158 localized_strings->SetString("publicAccountEnter",
159 l10n_util::GetStringUTF16(IDS_LOGIN_PUBLIC_ACCOUNT_ENTER));
160 localized_strings->SetString("publicAccountEnterAccessibleName",
161 l10n_util::GetStringUTF16(
162 IDS_LOGIN_PUBLIC_ACCOUNT_ENTER_ACCESSIBLE_NAME));
163 localized_strings->SetString("lockAnimationsType", "new");
164 localized_strings->SetString("passwordHint",
165 l10n_util::GetStringUTF16(IDS_LOGIN_POD_EMPTY_PASSWORD_TEXT));
166 localized_strings->SetString("podMenuButtonAccessibleName",
167 l10n_util::GetStringUTF16(IDS_LOGIN_POD_MENU_BUTTON_ACCESSIBLE_NAME));
168 localized_strings->SetString("podMenuRemoveItemAccessibleName",
169 l10n_util::GetStringUTF16(
170 IDS_LOGIN_POD_MENU_REMOVE_ITEM_ACCESSIBLE_NAME));
171 localized_strings->SetString("ownerUserPattern",
172 l10n_util::GetStringUTF16(IDS_LOGIN_POD_OWNER_USER));
173 localized_strings->SetString("removeUser",
174 l10n_util::GetStringUTF16(IDS_LOGIN_POD_REMOVE_USER));
175 localized_strings->SetString("passwordFieldAccessibleName",
176 l10n_util::GetStringUTF16(IDS_LOGIN_POD_PASSWORD_FIELD_ACCESSIBLE_NAME));
177 localized_strings->SetString("publicAccountInfoFormat",
178 l10n_util::GetStringUTF16(IDS_LOGIN_PUBLIC_ACCOUNT_INFO_FORMAT));
179
180 // For GaiaSigninScreen.
181 localized_strings->SetString("signinScreenTitle",
182 l10n_util::GetStringUTF16(IDS_SIGNIN_SCREEN_TITLE));
183 localized_strings->SetString("createLocallyManagedUser",
184 l10n_util::GetStringUTF16(IDS_CREATE_LOCALLY_MANAGED_USER_HTML));
185 localized_strings->SetString("createManagedUserFeatureName",
186 l10n_util::GetStringUTF16(IDS_CREATE_LOCALLY_MANAGED_USER_FEATURE_NAME));
187 localized_strings->SetString("createManagedUserNoManagerText",
188 l10n_util::GetStringUTF16(
189 IDS_CREATE_LOCALLY_MANAGED_USER_NO_MANAGER_TEXT));
190 localized_strings->SetString("learnMore",
191 l10n_util::GetStringUTF16(IDS_LEARN_MORE));
192 }
193
194 void UserChooserScreenHandler::SendUserList() {
195 ListValue users_list;
196 base::FilePath current_profile_path =
197 web_ui()->GetWebContents()->GetBrowserContext()->GetPath();
198 const ProfileInfoCache& info_cache =
199 g_browser_process->profile_manager()->GetProfileInfoCache();
200
201 for (size_t i = 0; i < info_cache.GetNumberOfProfiles(); ++i) {
202 DictionaryValue* profile_value = new DictionaryValue();
203
204 base::FilePath profile_path = info_cache.GetPathOfProfileAtIndex(i);
205 bool is_active_user = (profile_path == current_profile_path);
206 bool needs_signin = info_cache.ProfileIsSigninRequiredAtIndex(i);
207
208 profile_value->SetString(
209 kKeyUsername, info_cache.GetUserNameOfProfileAtIndex(i));
210 profile_value->SetString(
211 kKeyEmailAddress, info_cache.GetUserNameOfProfileAtIndex(i));
212 profile_value->SetString(
213 kKeyDisplayName, info_cache.GetNameOfProfileAtIndex(i));
214 profile_value->SetBoolean(kKeyPublicAccount, false);
215 profile_value->SetBoolean(kKeyLocallyManagedUser, false);
216 profile_value->SetBoolean(kKeySignedIn, is_active_user);
217
218 /*var OAuthTokenStatus = {
219 UNKNOWN: 0, INVALID_OLD: 1, VALID_OLD: 2, INVALID_NEW: 3, VALID_NEW: 4
220 };*/
Roger Tawa OOO till Jul 10th 2013/06/05 18:53:56 I guess this commented out code is a reference to
noms 2013/06/06 19:01:36 Done.
221 profile_value->SetInteger(kUserOAuthTokenStatus, needs_signin ? 2 : 0);
222 profile_value->SetBoolean(kKeySignedIn, is_active_user);
Roger Tawa OOO till Jul 10th 2013/06/05 18:53:56 Already set at line 216.
noms 2013/06/06 19:01:36 Done.
223 profile_value->SetBoolean(kKeyIsOwner, false);
224 profile_value->SetBoolean(kKeyCanRemove, true);
225 profile_value->SetBoolean(kKeyIsDesktop, true);
226
227 bool is_gaia_picture =
228 info_cache.IsUsingGAIAPictureOfProfileAtIndex(i) &&
229 info_cache.GetGAIAPictureOfProfileAtIndex(i);
230
231 gfx::Image icon = profiles::GetSizedAvatarIconWithBorder(
232 info_cache.GetAvatarIconOfProfileAtIndex(i), is_gaia_picture, 160, 160);
233 profile_value->SetString(kKeyAvatarUrl,
234 webui::GetBitmapDataUrl(icon.AsBitmap()));
235
236 if (is_active_user)
237 users_list.Insert(0, profile_value);
238 else
239 users_list.Append(profile_value);
240 }
241
242 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers",
243 users_list, base::FundamentalValue(false), base::FundamentalValue(true));
244 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698