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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/signin/user_manager_screen_handler.h"
8 #include "base/prefs/pref_service.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "base/value_conversions.h"
11 #include "base/values.h"
12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/extensions/api/screenlock_private/screenlock_private_api.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
16 #include "chrome/browser/profiles/profile_info_cache.h"
17 #include "chrome/browser/profiles/profile_info_cache_observer.h"
18 #include "chrome/browser/profiles/profile_manager.h"
19 #include "chrome/browser/profiles/profile_metrics.h"
20 #include "chrome/browser/profiles/profile_window.h"
21 #include "chrome/browser/profiles/profiles_state.h"
22 #include "chrome/browser/signin/local_auth.h"
23 #include "chrome/browser/ui/browser_dialogs.h"
24 #include "chrome/browser/ui/browser_finder.h"
25 #include "chrome/browser/ui/singleton_tabs.h"
26 #include "chrome/common/pref_names.h"
27 #include "chrome/common/url_constants.h"
28 #include "chrome/grit/chromium_strings.h"
29 #include "chrome/grit/generated_resources.h"
30 #include "content/public/browser/web_contents.h"
31 #include "content/public/browser/web_ui.h"
32 #include "google_apis/gaia/gaia_auth_fetcher.h"
33 #include "google_apis/gaia/gaia_constants.h"
34 #include "third_party/skia/include/core/SkBitmap.h"
35 #include "ui/base/l10n/l10n_util.h"
36 #include "ui/base/resource/resource_bundle.h"
37 #include "ui/base/webui/web_ui_util.h"
38 #include "ui/gfx/image/image.h"
39 #include "ui/gfx/image/image_skia.h"
40 #include "ui/gfx/image/image_util.h"
43 // User dictionary keys.
44 const char kKeyUsername
[] = "username";
45 const char kKeyDisplayName
[]= "displayName";
46 const char kKeyEmailAddress
[] = "emailAddress";
47 const char kKeyProfilePath
[] = "profilePath";
48 const char kKeyPublicAccount
[] = "publicAccount";
49 const char kKeySupervisedUser
[] = "supervisedUser";
50 const char kKeySignedIn
[] = "signedIn";
51 const char kKeyCanRemove
[] = "canRemove";
52 const char kKeyIsOwner
[] = "isOwner";
53 const char kKeyIsDesktop
[] = "isDesktopUser";
54 const char kKeyAvatarUrl
[] = "userImage";
55 const char kKeyNeedsSignin
[] = "needsSignin";
57 // JS API callback names.
58 const char kJsApiUserManagerInitialize
[] = "userManagerInitialize";
59 const char kJsApiUserManagerAddUser
[] = "addUser";
60 const char kJsApiUserManagerAuthLaunchUser
[] = "authenticatedLaunchUser";
61 const char kJsApiUserManagerLaunchGuest
[] = "launchGuest";
62 const char kJsApiUserManagerLaunchUser
[] = "launchUser";
63 const char kJsApiUserManagerRemoveUser
[] = "removeUser";
64 const char kJsApiUserManagerAttemptUnlock
[] = "attemptUnlock";
66 const size_t kAvatarIconSize
= 180;
68 void HandleAndDoNothing(const base::ListValue
* args
) {
71 // This callback is run if the only profile has been deleted, and a new
72 // profile has been created to replace it.
73 void OpenNewWindowForProfile(
74 chrome::HostDesktopType desktop_type
,
76 Profile::CreateStatus status
) {
77 if (status
!= Profile::CREATE_STATUS_INITIALIZED
)
79 profiles::FindOrCreateNewWindowForProfile(
81 chrome::startup::IS_PROCESS_STARTUP
,
82 chrome::startup::IS_FIRST_RUN
,
87 // This callback is run after switching to a new profile has finished. This
88 // means either a new browser window has been opened, or an existing one
89 // has been found, which means we can safely close the User Manager without
90 // accidentally terminating the browser process. The task needs to be posted,
91 // as HideUserManager will end up destroying its WebContents, which will
92 // destruct the UserManagerScreenHandler as well.
93 void OnSwitchToProfileComplete() {
94 base::MessageLoop::current()->PostTask(
96 base::Bind(&chrome::HideUserManager
));
99 std::string
GetAvatarImageAtIndex(
100 size_t index
, const ProfileInfoCache
& info_cache
) {
101 bool is_gaia_picture
=
102 info_cache
.IsUsingGAIAPictureOfProfileAtIndex(index
) &&
103 info_cache
.GetGAIAPictureOfProfileAtIndex(index
);
105 // If the avatar is too small (i.e. the old-style low resolution avatar),
106 // it will be pixelated when displayed in the User Manager, so we should
107 // return the placeholder avatar instead.
108 gfx::Image avatar_image
= info_cache
.GetAvatarIconOfProfileAtIndex(index
);
109 if (avatar_image
.Width() <= profiles::kAvatarIconWidth
||
110 avatar_image
.Height() <= profiles::kAvatarIconHeight
) {
111 avatar_image
= ui::ResourceBundle::GetSharedInstance().GetImageNamed(
112 profiles::GetPlaceholderAvatarIconResourceID());
114 gfx::Image resized_image
= profiles::GetSizedAvatarIcon(
115 avatar_image
, is_gaia_picture
, kAvatarIconSize
, kAvatarIconSize
);
116 return webui::GetBitmapDataUrl(resized_image
.AsBitmap());
119 size_t GetIndexOfProfileWithEmailAndName(const ProfileInfoCache
& info_cache
,
120 const base::string16
& email
,
121 const base::string16
& name
) {
122 for (size_t i
= 0; i
< info_cache
.GetNumberOfProfiles(); ++i
) {
123 if (info_cache
.GetUserNameOfProfileAtIndex(i
) == email
&&
125 profiles::GetAvatarNameForProfile(
126 info_cache
.GetPathOfProfileAtIndex(i
)) == name
)) {
130 return std::string::npos
;
133 extensions::ScreenlockPrivateEventRouter
* GetScreenlockRouter(
134 const std::string
& email
) {
135 ProfileInfoCache
& info_cache
=
136 g_browser_process
->profile_manager()->GetProfileInfoCache();
137 const size_t profile_index
= GetIndexOfProfileWithEmailAndName(
138 info_cache
, base::UTF8ToUTF16(email
), base::string16());
139 Profile
* profile
= g_browser_process
->profile_manager()
140 ->GetProfileByPath(info_cache
.GetPathOfProfileAtIndex(profile_index
));
141 return extensions::ScreenlockPrivateEventRouter::GetFactoryInstance()->Get(
145 bool IsGuestModeEnabled() {
146 PrefService
* service
= g_browser_process
->local_state();
148 return service
->GetBoolean(prefs::kBrowserGuestModeEnabled
);
153 // ProfileUpdateObserver ------------------------------------------------------
155 class UserManagerScreenHandler::ProfileUpdateObserver
156 : public ProfileInfoCacheObserver
{
158 ProfileUpdateObserver(
159 ProfileManager
* profile_manager
, UserManagerScreenHandler
* handler
)
160 : profile_manager_(profile_manager
),
161 user_manager_handler_(handler
) {
162 DCHECK(profile_manager_
);
163 DCHECK(user_manager_handler_
);
164 profile_manager_
->GetProfileInfoCache().AddObserver(this);
167 virtual ~ProfileUpdateObserver() {
168 DCHECK(profile_manager_
);
169 profile_manager_
->GetProfileInfoCache().RemoveObserver(this);
173 // ProfileInfoCacheObserver implementation:
174 // If any change has been made to a profile, propagate it to all the
175 // visible user manager screens.
176 virtual void OnProfileAdded(const base::FilePath
& profile_path
) OVERRIDE
{
177 user_manager_handler_
->SendUserList();
180 virtual void OnProfileWasRemoved(
181 const base::FilePath
& profile_path
,
182 const base::string16
& profile_name
) OVERRIDE
{
183 // TODO(noms): Change 'SendUserList' to 'removeUser' JS-call when
184 // UserManager is able to find pod belonging to removed user.
185 user_manager_handler_
->SendUserList();
188 virtual void OnProfileNameChanged(
189 const base::FilePath
& profile_path
,
190 const base::string16
& old_profile_name
) OVERRIDE
{
191 user_manager_handler_
->SendUserList();
194 virtual void OnProfileAvatarChanged(
195 const base::FilePath
& profile_path
) OVERRIDE
{
196 user_manager_handler_
->SendUserList();
199 virtual void OnProfileSigninRequiredChanged(
200 const base::FilePath
& profile_path
) OVERRIDE
{
201 user_manager_handler_
->SendUserList();
204 ProfileManager
* profile_manager_
;
206 UserManagerScreenHandler
* user_manager_handler_
; // Weak; owns us.
208 DISALLOW_COPY_AND_ASSIGN(ProfileUpdateObserver
);
211 // UserManagerScreenHandler ---------------------------------------------------
213 UserManagerScreenHandler::UserManagerScreenHandler()
214 : desktop_type_(chrome::GetActiveDesktop()) {
215 profileInfoCacheObserver_
.reset(
216 new UserManagerScreenHandler::ProfileUpdateObserver(
217 g_browser_process
->profile_manager(), this));
220 UserManagerScreenHandler::~UserManagerScreenHandler() {
221 ScreenlockBridge::Get()->SetLockHandler(NULL
);
224 void UserManagerScreenHandler::ShowBannerMessage(
225 const base::string16
& message
) {
226 web_ui()->CallJavascriptFunction(
227 "login.AccountPickerScreen.showBannerMessage",
228 base::StringValue(message
));
231 void UserManagerScreenHandler::ShowUserPodCustomIcon(
232 const std::string
& user_email
,
233 const ScreenlockBridge::UserPodCustomIconOptions
& icon_options
) {
234 scoped_ptr
<base::DictionaryValue
> icon
= icon_options
.ToDictionaryValue();
235 if (!icon
|| icon
->empty())
237 web_ui()->CallJavascriptFunction(
238 "login.AccountPickerScreen.showUserPodCustomIcon",
239 base::StringValue(user_email
),
243 void UserManagerScreenHandler::HideUserPodCustomIcon(
244 const std::string
& user_email
) {
245 web_ui()->CallJavascriptFunction(
246 "login.AccountPickerScreen.hideUserPodCustomIcon",
247 base::StringValue(user_email
));
250 void UserManagerScreenHandler::EnableInput() {
251 // Nothing here because UI is not disabled when starting to authenticate.
254 void UserManagerScreenHandler::SetAuthType(
255 const std::string
& user_email
,
256 ScreenlockBridge::LockHandler::AuthType auth_type
,
257 const base::string16
& auth_value
) {
258 if (GetAuthType(user_email
) ==
259 ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD
)
262 user_auth_type_map_
[user_email
] = auth_type
;
263 web_ui()->CallJavascriptFunction(
264 "login.AccountPickerScreen.setAuthType",
265 base::StringValue(user_email
),
266 base::FundamentalValue(auth_type
),
267 base::StringValue(auth_value
));
270 ScreenlockBridge::LockHandler::AuthType
UserManagerScreenHandler::GetAuthType(
271 const std::string
& user_email
) const {
272 UserAuthTypeMap::const_iterator it
= user_auth_type_map_
.find(user_email
);
273 if (it
== user_auth_type_map_
.end())
274 return ScreenlockBridge::LockHandler::OFFLINE_PASSWORD
;
278 void UserManagerScreenHandler::Unlock(const std::string
& user_email
) {
279 ProfileInfoCache
& info_cache
=
280 g_browser_process
->profile_manager()->GetProfileInfoCache();
281 const size_t profile_index
= GetIndexOfProfileWithEmailAndName(
282 info_cache
, base::UTF8ToUTF16(user_email
), base::string16());
283 DCHECK_LT(profile_index
, info_cache
.GetNumberOfProfiles());
285 authenticating_profile_index_
= profile_index
;
286 ReportAuthenticationResult(true, ProfileMetrics::AUTH_LOCAL
);
289 void UserManagerScreenHandler::HandleInitialize(const base::ListValue
* args
) {
291 web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserManagerScreen",
292 base::FundamentalValue(IsGuestModeEnabled()));
293 desktop_type_
= chrome::GetHostDesktopTypeForNativeView(
294 web_ui()->GetWebContents()->GetNativeView());
296 ScreenlockBridge::Get()->SetLockHandler(this);
299 void UserManagerScreenHandler::HandleAddUser(const base::ListValue
* args
) {
300 profiles::CreateAndSwitchToNewProfile(desktop_type_
,
301 base::Bind(&OnSwitchToProfileComplete
),
302 ProfileMetrics::ADD_NEW_USER_MANAGER
);
305 void UserManagerScreenHandler::HandleAuthenticatedLaunchUser(
306 const base::ListValue
* args
) {
307 base::string16 email_address
;
308 if (!args
->GetString(0, &email_address
))
311 base::string16 display_name
;
312 if (!args
->GetString(1, &display_name
))
315 std::string password
;
316 if (!args
->GetString(2, &password
))
319 ProfileInfoCache
& info_cache
=
320 g_browser_process
->profile_manager()->GetProfileInfoCache();
321 size_t profile_index
= GetIndexOfProfileWithEmailAndName(
322 info_cache
, email_address
, display_name
);
323 if (profile_index
>= info_cache
.GetNumberOfProfiles()) {
328 authenticating_profile_index_
= profile_index
;
329 if (!chrome::ValidateLocalAuthCredentials(profile_index
, password
)) {
330 // Make a second attempt via an on-line authentication call. This handles
331 // profiles that are missing sign-in credentials and also cases where the
332 // password has been changed externally.
333 client_login_
.reset(new GaiaAuthFetcher(
335 GaiaConstants::kChromeSource
,
336 web_ui()->GetWebContents()->GetBrowserContext()->GetRequestContext()));
337 std::string email_string
;
338 args
->GetString(0, &email_string
);
339 client_login_
->StartClientLogin(
342 GaiaConstants::kSyncService
,
345 GaiaAuthFetcher::HostedAccountsAllowed
);
346 password_attempt_
= password
;
350 ReportAuthenticationResult(true, ProfileMetrics::AUTH_LOCAL
);
353 void UserManagerScreenHandler::HandleRemoveUser(const base::ListValue
* args
) {
355 const base::Value
* profile_path_value
;
356 if (!args
->Get(0, &profile_path_value
))
359 base::FilePath profile_path
;
360 if (!base::GetValueAsFilePath(*profile_path_value
, &profile_path
))
363 // This handler could have been called for a supervised user, for example
364 // because the user fiddled with the web inspector. Silently return in this
366 if (Profile::FromWebUI(web_ui())->IsSupervised())
369 if (!profiles::IsMultipleProfilesEnabled())
372 g_browser_process
->profile_manager()->ScheduleProfileForDeletion(
374 base::Bind(&OpenNewWindowForProfile
, desktop_type_
));
375 ProfileMetrics::LogProfileDeleteUser(
376 ProfileMetrics::DELETE_PROFILE_USER_MANAGER
);
379 void UserManagerScreenHandler::HandleLaunchGuest(const base::ListValue
* args
) {
380 if (IsGuestModeEnabled()) {
381 profiles::SwitchToGuestProfile(desktop_type_
,
382 base::Bind(&OnSwitchToProfileComplete
));
383 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_GUEST
);
385 // The UI should have prevented the user from allowing the selection of
391 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue
* args
) {
392 base::string16 email_address
;
393 base::string16 display_name
;
395 if (!args
->GetString(0, &email_address
) ||
396 !args
->GetString(1, &display_name
)) {
401 ProfileInfoCache
& info_cache
=
402 g_browser_process
->profile_manager()->GetProfileInfoCache();
403 size_t profile_index
= GetIndexOfProfileWithEmailAndName(
404 info_cache
, email_address
, display_name
);
406 if (profile_index
>= info_cache
.GetNumberOfProfiles()) {
411 // It's possible that a user breaks into the user-manager page using the
412 // JavaScript Inspector and causes a "locked" profile to call this
413 // unauthenticated version of "launch" instead of the proper one. Thus,
414 // we have to validate in (secure) C++ code that it really is a profile
415 // not needing authentication. If it is, just ignore the "launch" request.
416 if (info_cache
.ProfileIsSigninRequiredAtIndex(profile_index
))
418 ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_UNNECESSARY
);
420 base::FilePath path
= info_cache
.GetPathOfProfileAtIndex(profile_index
);
421 profiles::SwitchToProfile(path
,
423 false, /* reuse any existing windows */
424 base::Bind(&OnSwitchToProfileComplete
),
425 ProfileMetrics::SWITCH_PROFILE_MANAGER
);
428 void UserManagerScreenHandler::HandleAttemptUnlock(
429 const base::ListValue
* args
) {
431 CHECK(args
->GetString(0, &email
));
432 GetScreenlockRouter(email
)->OnAuthAttempted(GetAuthType(email
), "");
435 void UserManagerScreenHandler::HandleHardlockUserPod(
436 const base::ListValue
* args
) {
438 CHECK(args
->GetString(0, &email
));
440 ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD
,
442 HideUserPodCustomIcon(email
);
445 void UserManagerScreenHandler::OnClientLoginSuccess(
446 const ClientLoginResult
& result
) {
447 chrome::SetLocalAuthCredentials(authenticating_profile_index_
,
449 ReportAuthenticationResult(true, ProfileMetrics::AUTH_ONLINE
);
452 void UserManagerScreenHandler::OnClientLoginFailure(
453 const GoogleServiceAuthError
& error
) {
454 const GoogleServiceAuthError::State state
= error
.state();
455 // Some "error" results mean the password was correct but some other action
456 // should be taken. For our purposes, we only care that the password was
457 // correct so count those as a success.
458 bool success
= (state
== GoogleServiceAuthError::NONE
||
459 state
== GoogleServiceAuthError::CAPTCHA_REQUIRED
||
460 state
== GoogleServiceAuthError::TWO_FACTOR
||
461 state
== GoogleServiceAuthError::ACCOUNT_DELETED
||
462 state
== GoogleServiceAuthError::ACCOUNT_DISABLED
);
463 ReportAuthenticationResult(success
,
464 success
? ProfileMetrics::AUTH_ONLINE
465 : ProfileMetrics::AUTH_FAILED
);
468 void UserManagerScreenHandler::RegisterMessages() {
469 web_ui()->RegisterMessageCallback(kJsApiUserManagerInitialize
,
470 base::Bind(&UserManagerScreenHandler::HandleInitialize
,
471 base::Unretained(this)));
472 web_ui()->RegisterMessageCallback(kJsApiUserManagerAddUser
,
473 base::Bind(&UserManagerScreenHandler::HandleAddUser
,
474 base::Unretained(this)));
475 web_ui()->RegisterMessageCallback(kJsApiUserManagerAuthLaunchUser
,
476 base::Bind(&UserManagerScreenHandler::HandleAuthenticatedLaunchUser
,
477 base::Unretained(this)));
478 web_ui()->RegisterMessageCallback(kJsApiUserManagerLaunchGuest
,
479 base::Bind(&UserManagerScreenHandler::HandleLaunchGuest
,
480 base::Unretained(this)));
481 web_ui()->RegisterMessageCallback(kJsApiUserManagerLaunchUser
,
482 base::Bind(&UserManagerScreenHandler::HandleLaunchUser
,
483 base::Unretained(this)));
484 web_ui()->RegisterMessageCallback(kJsApiUserManagerRemoveUser
,
485 base::Bind(&UserManagerScreenHandler::HandleRemoveUser
,
486 base::Unretained(this)));
487 web_ui()->RegisterMessageCallback(kJsApiUserManagerAttemptUnlock
,
488 base::Bind(&UserManagerScreenHandler::HandleAttemptUnlock
,
489 base::Unretained(this)));
491 const content::WebUI::MessageCallback
& kDoNothingCallback
=
492 base::Bind(&HandleAndDoNothing
);
494 // Unused callbacks from screen_account_picker.js
495 web_ui()->RegisterMessageCallback("accountPickerReady", kDoNothingCallback
);
496 web_ui()->RegisterMessageCallback("loginUIStateChanged", kDoNothingCallback
);
497 web_ui()->RegisterMessageCallback("hideCaptivePortal", kDoNothingCallback
);
498 web_ui()->RegisterMessageCallback("getTouchViewState", kDoNothingCallback
);
499 // Unused callbacks from display_manager.js
500 web_ui()->RegisterMessageCallback("showAddUser", kDoNothingCallback
);
501 web_ui()->RegisterMessageCallback("loadWallpaper", kDoNothingCallback
);
502 web_ui()->RegisterMessageCallback("updateCurrentScreen", kDoNothingCallback
);
503 web_ui()->RegisterMessageCallback("loginVisible", kDoNothingCallback
);
504 // Unused callbacks from user_pod_row.js
505 web_ui()->RegisterMessageCallback("focusPod", kDoNothingCallback
);
508 void UserManagerScreenHandler::GetLocalizedValues(
509 base::DictionaryValue
* localized_strings
) {
511 localized_strings
->SetString("signedIn",
512 l10n_util::GetStringUTF16(IDS_SCREEN_LOCK_ACTIVE_USER
));
513 localized_strings
->SetString("signinButton",
514 l10n_util::GetStringUTF16(IDS_LOGIN_BUTTON
));
515 localized_strings
->SetString("addUser",
516 l10n_util::GetStringUTF16(IDS_ADD_USER_BUTTON
));
517 localized_strings
->SetString("cancel", l10n_util::GetStringUTF16(IDS_CANCEL
));
518 localized_strings
->SetString("browseAsGuest",
519 l10n_util::GetStringUTF16(IDS_GO_INCOGNITO_BUTTON
));
520 localized_strings
->SetString("signOutUser",
521 l10n_util::GetStringUTF16(IDS_SCREEN_LOCK_SIGN_OUT
));
523 // For AccountPickerScreen.
524 localized_strings
->SetString("screenType", "login-add-user");
525 localized_strings
->SetString("highlightStrength", "normal");
526 localized_strings
->SetString("title",
527 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME
));
528 localized_strings
->SetString("passwordHint",
529 l10n_util::GetStringUTF16(IDS_LOGIN_POD_EMPTY_PASSWORD_TEXT
));
530 localized_strings
->SetString("podMenuButtonAccessibleName",
531 l10n_util::GetStringUTF16(IDS_LOGIN_POD_MENU_BUTTON_ACCESSIBLE_NAME
));
532 localized_strings
->SetString("podMenuRemoveItemAccessibleName",
533 l10n_util::GetStringUTF16(
534 IDS_LOGIN_POD_MENU_REMOVE_ITEM_ACCESSIBLE_NAME
));
535 localized_strings
->SetString("removeUser",
536 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BUTTON
));
537 localized_strings
->SetString("passwordFieldAccessibleName",
538 l10n_util::GetStringUTF16(IDS_LOGIN_POD_PASSWORD_FIELD_ACCESSIBLE_NAME
));
539 localized_strings
->SetString("bootIntoWallpaper", "off");
541 // For AccountPickerScreen, the remove user warning overlay.
542 localized_strings
->SetString("removeUserWarningButtonTitle",
543 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING_BUTTON
));
544 localized_strings
->SetString("removeUserWarningText",
545 l10n_util::GetStringUTF16(IDS_LOGIN_POD_USER_REMOVE_WARNING
));
546 localized_strings
->SetString("removeSupervisedUserWarningText",
547 l10n_util::GetStringFUTF16(
548 IDS_LOGIN_POD_SUPERVISED_USER_REMOVE_WARNING
,
549 base::UTF8ToUTF16(chrome::kSupervisedUserManagementDisplayURL
)));
551 // Strings needed for the User Manager tutorial slides.
552 localized_strings
->SetString("tutorialNext",
553 l10n_util::GetStringUTF16(IDS_USER_MANAGER_TUTORIAL_NEXT
));
554 localized_strings
->SetString("tutorialDone",
555 l10n_util::GetStringUTF16(IDS_USER_MANAGER_TUTORIAL_DONE
));
556 localized_strings
->SetString("slideWelcomeTitle",
557 l10n_util::GetStringUTF16(IDS_USER_MANAGER_TUTORIAL_SLIDE_INTRO_TITLE
));
558 localized_strings
->SetString("slideWelcomeText",
559 l10n_util::GetStringUTF16(IDS_USER_MANAGER_TUTORIAL_SLIDE_INTRO_TEXT
));
560 localized_strings
->SetString("slideYourChromeTitle",
561 l10n_util::GetStringUTF16(
562 IDS_USER_MANAGER_TUTORIAL_SLIDE_YOUR_CHROME_TITLE
));
563 localized_strings
->SetString("slideYourChromeText", l10n_util::GetStringUTF16(
564 IDS_USER_MANAGER_TUTORIAL_SLIDE_YOUR_CHROME_TEXT
));
565 localized_strings
->SetString("slideGuestsTitle",
566 l10n_util::GetStringUTF16(IDS_USER_MANAGER_TUTORIAL_SLIDE_GUEST_TITLE
));
567 localized_strings
->SetString("slideGuestsText",
568 l10n_util::GetStringUTF16(IDS_USER_MANAGER_TUTORIAL_SLIDE_GUEST_TEXT
));
569 localized_strings
->SetString("slideFriendsTitle",
570 l10n_util::GetStringUTF16(IDS_USER_MANAGER_TUTORIAL_SLIDE_FRIENDS_TITLE
));
571 localized_strings
->SetString("slideFriendsText",
572 l10n_util::GetStringUTF16(IDS_USER_MANAGER_TUTORIAL_SLIDE_FRIENDS_TEXT
));
573 localized_strings
->SetString("slideCompleteTitle",
574 l10n_util::GetStringUTF16(IDS_USER_MANAGER_TUTORIAL_SLIDE_OUTRO_TITLE
));
575 localized_strings
->SetString("slideCompleteText",
576 l10n_util::GetStringUTF16(IDS_USER_MANAGER_TUTORIAL_SLIDE_OUTRO_TEXT
));
577 localized_strings
->SetString("slideCompleteUserNotFound",
578 l10n_util::GetStringUTF16(
579 IDS_USER_MANAGER_TUTORIAL_SLIDE_OUTRO_USER_NOT_FOUND
));
580 localized_strings
->SetString("slideCompleteAddUser",
581 l10n_util::GetStringUTF16(
582 IDS_USER_MANAGER_TUTORIAL_SLIDE_OUTRO_ADD_USER
));
584 // Strings needed for the user_pod_template public account div, but not ever
585 // actually displayed for desktop users.
586 localized_strings
->SetString("publicAccountReminder", base::string16());
587 localized_strings
->SetString("publicSessionLanguageAndInput",
589 localized_strings
->SetString("publicAccountEnter", base::string16());
590 localized_strings
->SetString("publicAccountEnterAccessibleName",
592 localized_strings
->SetString("publicSessionSelectLanguage", base::string16());
593 localized_strings
->SetString("publicSessionSelectKeyboard", base::string16());
594 localized_strings
->SetString("signinBannerText", base::string16());
595 localized_strings
->SetString("launchAppButton", base::string16());
596 localized_strings
->SetString("multiProfilesRestrictedPolicyTitle",
598 localized_strings
->SetString("multiProfilesNotAllowedPolicyMsg",
600 localized_strings
->SetString("multiProfilesPrimaryOnlyPolicyMsg",
602 localized_strings
->SetString("multiProfilesOwnerPrimaryOnlyMsg",
606 void UserManagerScreenHandler::SendUserList() {
607 base::ListValue users_list
;
608 base::FilePath active_profile_path
=
609 web_ui()->GetWebContents()->GetBrowserContext()->GetPath();
610 const ProfileInfoCache
& info_cache
=
611 g_browser_process
->profile_manager()->GetProfileInfoCache();
613 user_auth_type_map_
.clear();
615 // If the active user is a supervised user, then they may not perform
616 // certain actions (i.e. delete another user).
617 bool active_user_is_supervised
= Profile::FromWebUI(web_ui())->IsSupervised();
618 for (size_t i
= 0; i
< info_cache
.GetNumberOfProfiles(); ++i
) {
619 base::DictionaryValue
* profile_value
= new base::DictionaryValue();
621 base::FilePath profile_path
= info_cache
.GetPathOfProfileAtIndex(i
);
622 bool is_active_user
= (profile_path
== active_profile_path
);
624 profile_value
->SetString(
625 kKeyUsername
, info_cache
.GetUserNameOfProfileAtIndex(i
));
626 profile_value
->SetString(
627 kKeyEmailAddress
, info_cache
.GetUserNameOfProfileAtIndex(i
));
628 // The profiles displayed in the User Manager are never guest profiles.
629 profile_value
->SetString(
631 profiles::GetAvatarNameForProfile(profile_path
));
632 profile_value
->SetString(kKeyProfilePath
, profile_path
.MaybeAsASCII());
633 profile_value
->SetBoolean(kKeyPublicAccount
, false);
634 profile_value
->SetBoolean(
635 kKeySupervisedUser
, info_cache
.ProfileIsSupervisedAtIndex(i
));
636 profile_value
->SetBoolean(kKeySignedIn
, is_active_user
);
637 profile_value
->SetBoolean(
638 kKeyNeedsSignin
, info_cache
.ProfileIsSigninRequiredAtIndex(i
));
639 profile_value
->SetBoolean(kKeyIsOwner
, false);
640 profile_value
->SetBoolean(kKeyCanRemove
, !active_user_is_supervised
);
641 profile_value
->SetBoolean(kKeyIsDesktop
, true);
642 profile_value
->SetString(
643 kKeyAvatarUrl
, GetAvatarImageAtIndex(i
, info_cache
));
645 // The row of user pods should display the active user first.
647 users_list
.Insert(0, profile_value
);
649 users_list
.Append(profile_value
);
652 web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers",
653 users_list
, base::FundamentalValue(IsGuestModeEnabled()));
656 void UserManagerScreenHandler::ReportAuthenticationResult(
658 ProfileMetrics::ProfileAuth auth
) {
659 ProfileMetrics::LogProfileAuthResult(auth
);
660 password_attempt_
.clear();
663 ProfileInfoCache
& info_cache
=
664 g_browser_process
->profile_manager()->GetProfileInfoCache();
665 info_cache
.SetProfileSigninRequiredAtIndex(
666 authenticating_profile_index_
, false);
667 base::FilePath path
= info_cache
.GetPathOfProfileAtIndex(
668 authenticating_profile_index_
);
669 profiles::SwitchToProfile(path
, desktop_type_
, true,
670 base::Bind(&OnSwitchToProfileComplete
),
671 ProfileMetrics::SWITCH_PROFILE_UNLOCK
);
673 web_ui()->CallJavascriptFunction(
674 "cr.ui.Oobe.showSignInError",
675 base::FundamentalValue(0),
677 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_AUTHENTICATING
)),
678 base::StringValue(""),
679 base::FundamentalValue(0));