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

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: fix linux CrOS browser test Created 7 years, 5 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 "base/values.h"
9 #include "chrome/browser/browser_process.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/profiles/profile_window.h"
15 #include "chrome/browser/ui/browser_commands.h"
16 #include "chrome/browser/ui/browser_finder.h"
17 #include "chrome/browser/ui/singleton_tabs.h"
18 #include "content/public/browser/web_contents.h"
19 #include "content/public/browser/web_ui.h"
20 #include "grit/browser_resources.h"
21 #include "grit/chromium_strings.h"
22 #include "grit/generated_resources.h"
23 #include "third_party/skia/include/core/SkBitmap.h"
24 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/gfx/image/image_util.h"
26 #include "ui/webui/web_ui_util.h"
27
28 namespace {
29 // User dictionary keys.
30 const char kKeyUsername[] = "username";
31 const char kKeyDisplayName[]= "displayName";
32 const char kKeyEmailAddress[] = "emailAddress";
33 const char kKeyPublicAccount[] = "publicAccount";
34 const char kKeyLocallyManagedUser[] = "locallyManagedUser";
35 const char kKeySignedIn[] = "signedIn";
36 const char kKeyCanRemove[] = "canRemove";
37 const char kKeyIsOwner[] = "isOwner";
38 const char kKeyIsDesktop[] = "isDesktopUser";
39 const char kKeyAvatarUrl[] = "userImage";
40 const char kKeyNeedsSignin[] = "needsSignin";
41 const char kGAIAPictureFileNameKey[] = "gaia_picture_file_name";
42
43 // Max number of users to show.
44 const size_t kMaxUsers = 18;
45
46 // Type of the login screen UI that is currently presented to user.
47 const char kSourceGaiaSignin[] = "gaia-signin";
48 const char kSourceAccountPicker[] = "account-picker";
49
50 // JS API callback names.
51 const char kJsApiUserChooserInitialize[] = "userChooserInitialize";
52 const char kJsApiUserChooserAddUser[] = "addUser";
53 const char kJsApiUserChooserLaunchGuest[] = "launchGuest";
54 const char kJsApiUserChooserLaunchUser[] = "launchUser";
55 const char kJsApiUserChooserRemoveUser[] = "removeUser";
56
57 void HandleAndDoNothing(const base::ListValue* args) {
58 }
59
60 } // namespace
61
62 UserChooserScreenHandler::UserChooserScreenHandler() {
63 }
64
65 UserChooserScreenHandler::~UserChooserScreenHandler() {
66 }
67
68 void UserChooserScreenHandler::HandleInitialize(const base::ListValue* args) {
69 SendUserList();
70 web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserChooserScreen");
71 }
72
73 void UserChooserScreenHandler::HandleAddUser(const base::ListValue* args) {
74 // TODO(noms): Should redirect to a sign in page.
75 chrome::ShowSingletonTab(chrome::FindBrowserWithWebContents(
76 web_ui()->GetWebContents()),
77 GURL("chrome://settings/createProfile"));
78 }
79
80 void UserChooserScreenHandler::HandleRemoveUser(const base::ListValue* args) {
81 // TODO(noms): Should delete the user.
82 chrome::ShowSingletonTab(chrome::FindBrowserWithWebContents(
83 web_ui()->GetWebContents()),
84 GURL("chrome://settings/search#Users"));
85 }
86
87 void UserChooserScreenHandler::HandleLaunchGuest(const base::ListValue* args) {
88 // TODO(noms): Once guest mode is ready, should launch a guest browser.
89 chrome::NewIncognitoWindow(chrome::FindBrowserWithWebContents(
90 web_ui()->GetWebContents()));
91 }
92
93 void UserChooserScreenHandler::HandleLaunchUser(const base::ListValue* args) {
94 string16 emailAddress;
95 string16 displayName;
96
97 if (!args->GetString(0, &emailAddress) ||
98 !args->GetString(1, &displayName)) {
99 NOTREACHED();
100 return;
101 }
102
103 ProfileInfoCache& info_cache =
104 g_browser_process->profile_manager()->GetProfileInfoCache();
105 chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop();
106
107 for (size_t i = 0; i < info_cache.GetNumberOfProfiles(); ++i) {
108 if (info_cache.GetUserNameOfProfileAtIndex(i) == emailAddress &&
109 info_cache.GetNameOfProfileAtIndex(i) == displayName) {
110 base::FilePath path = info_cache.GetPathOfProfileAtIndex(i);
111 profiles::SwitchToProfile(path, desktop_type, true);
112 break;
113 }
114 }
115 }
116
117 void UserChooserScreenHandler::RegisterMessages() {
118 web_ui()->RegisterMessageCallback(kJsApiUserChooserInitialize,
119 base::Bind(&UserChooserScreenHandler::HandleInitialize,
120 base::Unretained(this)));
121 web_ui()->RegisterMessageCallback(kJsApiUserChooserAddUser,
122 base::Bind(&UserChooserScreenHandler::HandleAddUser,
123 base::Unretained(this)));
124 web_ui()->RegisterMessageCallback(kJsApiUserChooserLaunchGuest,
125 base::Bind(&UserChooserScreenHandler::HandleLaunchGuest,
126 base::Unretained(this)));
127 web_ui()->RegisterMessageCallback(kJsApiUserChooserLaunchUser,
128 base::Bind(&UserChooserScreenHandler::HandleLaunchUser,
129 base::Unretained(this)));
130 web_ui()->RegisterMessageCallback(kJsApiUserChooserRemoveUser,
131 base::Bind(&UserChooserScreenHandler::HandleRemoveUser,
132 base::Unretained(this)));
133
134 const content::WebUI::MessageCallback& kDoNothingCallback =
135 base::Bind(&HandleAndDoNothing);
136
137 // Unused callbacks from screen_account_picker.js
138 web_ui()->RegisterMessageCallback("accountPickerReady", kDoNothingCallback);
139 web_ui()->RegisterMessageCallback("loginUIStateChanged", kDoNothingCallback);
140 web_ui()->RegisterMessageCallback("hideCaptivePortal", kDoNothingCallback);
141 // Unused callbacks from display_manager.js
142 web_ui()->RegisterMessageCallback("showAddUser", kDoNothingCallback);
143 web_ui()->RegisterMessageCallback("loadWallpaper", kDoNothingCallback);
144 web_ui()->RegisterMessageCallback("updateCurrentScreen", kDoNothingCallback);
145 web_ui()->RegisterMessageCallback("loginVisible", kDoNothingCallback);
146 // Unused callbacks from user_pod_row.js
147 web_ui()->RegisterMessageCallback("userImagesLoaded", kDoNothingCallback);
148 }
149
150 void UserChooserScreenHandler::GetLocalizedValues(
151 base::DictionaryValue* localized_strings) {
152 // For Control Bar.
153 localized_strings->SetString("signedIn",
154 l10n_util::GetStringUTF16(IDS_SCREEN_LOCK_ACTIVE_USER));
155 localized_strings->SetString("signinButton",
156 l10n_util::GetStringUTF16(IDS_LOGIN_BUTTON));
157 localized_strings->SetString("addUser",
158 l10n_util::GetStringUTF16(IDS_ADD_USER_BUTTON));
159 localized_strings->SetString("cancel", l10n_util::GetStringUTF16(IDS_CANCEL));
160 localized_strings->SetString("browseAsGuest",
161 l10n_util::GetStringUTF16(IDS_GO_INCOGNITO_BUTTON));
162 localized_strings->SetString("signOutUser",
163 l10n_util::GetStringUTF16(IDS_SCREEN_LOCK_SIGN_OUT));
164
165 // For AccountPickerScreen.
166 localized_strings->SetString("screenType", "login-add-user");
167 localized_strings->SetString("highlightStrength", "normal");
168 localized_strings->SetString("title", "User Chooser");
169 localized_strings->SetString("passwordHint",
170 l10n_util::GetStringUTF16(IDS_LOGIN_POD_EMPTY_PASSWORD_TEXT));
171 localized_strings->SetString("podMenuButtonAccessibleName",
172 l10n_util::GetStringUTF16(IDS_LOGIN_POD_MENU_BUTTON_ACCESSIBLE_NAME));
173 localized_strings->SetString("podMenuRemoveItemAccessibleName",
174 l10n_util::GetStringUTF16(
175 IDS_LOGIN_POD_MENU_REMOVE_ITEM_ACCESSIBLE_NAME));
176 localized_strings->SetString("removeUser",
177 l10n_util::GetStringUTF16(IDS_LOGIN_POD_REMOVE_USER));
178 localized_strings->SetString("passwordFieldAccessibleName",
179 l10n_util::GetStringUTF16(IDS_LOGIN_POD_PASSWORD_FIELD_ACCESSIBLE_NAME));
180 localized_strings->SetString("bootIntoWallpaper", "off");
181
182 }
183
184 void UserChooserScreenHandler::SendUserList() {
185 ListValue users_list;
186 base::FilePath current_profile_path =
187 web_ui()->GetWebContents()->GetBrowserContext()->GetPath();
188 const ProfileInfoCache& info_cache =
189 g_browser_process->profile_manager()->GetProfileInfoCache();
190
191 for (size_t i = 0; i < info_cache.GetNumberOfProfiles(); ++i) {
192 DictionaryValue* profile_value = new DictionaryValue();
193
194 base::FilePath profile_path = info_cache.GetPathOfProfileAtIndex(i);
195 bool is_active_user = (profile_path == current_profile_path);
196 bool needs_signin = info_cache.ProfileIsSigninRequiredAtIndex(i);
197
198 profile_value->SetString(
199 kKeyUsername, info_cache.GetUserNameOfProfileAtIndex(i));
200 profile_value->SetString(
201 kKeyEmailAddress, info_cache.GetUserNameOfProfileAtIndex(i));
202 profile_value->SetString(
203 kKeyDisplayName, info_cache.GetNameOfProfileAtIndex(i));
204 profile_value->SetBoolean(kKeyPublicAccount, false);
205 profile_value->SetBoolean(kKeyLocallyManagedUser, false);
206 profile_value->SetBoolean(kKeySignedIn, is_active_user);
207 profile_value->SetBoolean(kKeyNeedsSignin, needs_signin);
208 profile_value->SetBoolean(kKeyIsOwner, false);
209 profile_value->SetBoolean(kKeyCanRemove, true);
210 profile_value->SetBoolean(kKeyIsDesktop, true);
211
212 bool is_gaia_picture =
213 info_cache.IsUsingGAIAPictureOfProfileAtIndex(i) &&
214 info_cache.GetGAIAPictureOfProfileAtIndex(i);
215
216 gfx::Image icon = profiles::GetSizedAvatarIconWithBorder(
217 info_cache.GetAvatarIconOfProfileAtIndex(i), is_gaia_picture, 160, 160);
218 profile_value->SetString(kKeyAvatarUrl,
219 webui::GetBitmapDataUrl(icon.AsBitmap()));
220
221 if (is_active_user)
222 users_list.Insert(0, profile_value);
223 else
224 users_list.Append(profile_value);
225 }
226
227 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers",
228 users_list, base::FundamentalValue(false), base::FundamentalValue(true));
229 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/signin/user_chooser_screen_handler.h ('k') | chrome/browser/ui/webui/signin/user_chooser_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698