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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/signin/user_chooser_screen_handler.cc
diff --git a/chrome/browser/ui/webui/signin/user_chooser_screen_handler.cc b/chrome/browser/ui/webui/signin/user_chooser_screen_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0485663c25e78ad2ec77be49c3bb7caef7349411
--- /dev/null
+++ b/chrome/browser/ui/webui/signin/user_chooser_screen_handler.cc
@@ -0,0 +1,244 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/webui/signin/user_chooser_screen_handler.h"
+
+#include "base/bind.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/profiles/avatar_menu_model.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_info_cache.h"
+#include "chrome/browser/profiles/profile_info_util.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/browser/ui/browser_commands.h"
+#include "chrome/browser/ui/browser_finder.h"
+#include "chrome/browser/ui/singleton_tabs.h"
+#include "grit/browser_resources.h"
+#include "grit/chromium_strings.h"
+#include "grit/generated_resources.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/gfx/image/image_util.h"
+#include "ui/webui/web_ui_util.h"
+
+namespace {
+// User dictionary keys.
+const char kKeyUsername[] = "username";
+const char kKeyDisplayName[]= "displayName";
+const char kKeyEmailAddress[] = "emailAddress";
+const char kKeyPublicAccount[] = "publicAccount";
+const char kKeyLocallyManagedUser[] = "locallyManagedUser";
+const char kKeySignedIn[] = "signedIn";
+const char kKeyCanRemove[] = "canRemove";
+const char kKeyIsOwner[] = "isOwner";
+const char kKeyIsDesktop[] = "isDesktopScreen";
+const char kKeyAvatarUrl[] = "userImage";
+const char kUserOAuthTokenStatus[] = "oauthTokenStatus";
+const char kGAIAPictureFileNameKey[] = "gaia_picture_file_name";
+
+// Max number of users to show.
+const size_t kMaxUsers = 18;
+
+// Type of the login screen UI that is currently presented to user.
+const char kSourceGaiaSignin[] = "gaia-signin";
+const char kSourceAccountPicker[] = "account-picker";
+
+// JS API callback names.
+const char kJsApiUserChooserInitialize[] = "userChooserInitialize";
+const char kJsApiUserChooserAddUser[] = "addUser";
+const char kJsApiUserChooserLaunchGuest[] = "launchGuest";
+const char kJsApiUserChooserLaunchUser[] = "launchUser";
+const char kJsApiUserChooserRemoveUser[] = "removeUser";
+} // namespace
+
+UserChooserScreenHandler::UserChooserScreenHandler() {
+ avatar_menu_model_.reset(new AvatarMenuModel(
+ &g_browser_process->profile_manager()->GetProfileInfoCache(),
+ NULL, NULL));
+}
+
+UserChooserScreenHandler::~UserChooserScreenHandler() {
+}
+
+void UserChooserScreenHandler::HandleInitialize(const base::ListValue* args) {
+ SendUserList();
+ web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserChooserScreen");
+}
+
+void UserChooserScreenHandler::HandleAddUser(const base::ListValue* args) {
+ chrome::ShowSingletonTab(chrome::FindBrowserWithWebContents(
+ web_ui()->GetWebContents()),
+ GURL("chrome://settings/createProfile"));
+}
+
+void UserChooserScreenHandler::HandleRemoveUser(const base::ListValue* args) {
+ 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.
+ web_ui()->GetWebContents()),
+ GURL("chrome://settings/search#Users"));
+}
+
+void UserChooserScreenHandler::HandleLaunchGuest(const base::ListValue* args) {
+ 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.
+ web_ui()->GetWebContents()));
+}
+
+void UserChooserScreenHandler::HandleLaunchUser(const base::ListValue* args) {
+ string16 emailAddress;
+ string16 displayName;
+
+ if (!args->GetString(0, &emailAddress) ||
+ !args->GetString(1, &displayName)) {
+ NOTREACHED();
+ return;
+ }
+
+ ProfileInfoCache& info_cache =
+ g_browser_process->profile_manager()->GetProfileInfoCache();
+
+ for (size_t i = 0; i < info_cache.GetNumberOfProfiles(); ++i) {
+ if (info_cache.GetUserNameOfProfileAtIndex(i) == emailAddress &&
+ info_cache.GetNameOfProfileAtIndex(i) == displayName) {
+ 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.
+ break;
+ }
+ }
+}
+
+void UserChooserScreenHandler::RegisterMessages() {
+ web_ui()->RegisterMessageCallback(kJsApiUserChooserInitialize,
+ base::Bind(&UserChooserScreenHandler::HandleInitialize,
+ base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(kJsApiUserChooserAddUser,
+ base::Bind(&UserChooserScreenHandler::HandleAddUser,
+ base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(kJsApiUserChooserLaunchGuest,
+ base::Bind(&UserChooserScreenHandler::HandleLaunchGuest,
+ base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(kJsApiUserChooserLaunchUser,
+ base::Bind(&UserChooserScreenHandler::HandleLaunchUser,
+ base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(kJsApiUserChooserRemoveUser,
+ base::Bind(&UserChooserScreenHandler::HandleRemoveUser,
+ base::Unretained(this)));
+}
+
+void UserChooserScreenHandler::GetLocalizedValues(
+ base::DictionaryValue* localized_strings) {
+
+ // For Header Bar.
+ localized_strings->SetString("signedIn",
+ l10n_util::GetStringUTF16(IDS_SCREEN_LOCK_ACTIVE_USER));
+ localized_strings->SetString("signinButton",
+ l10n_util::GetStringUTF16(IDS_LOGIN_BUTTON));
+ localized_strings->SetString("addUser",
+ l10n_util::GetStringUTF16(IDS_ADD_USER_BUTTON));
+ localized_strings->SetString("cancel", l10n_util::GetStringUTF16(IDS_CANCEL));
+ localized_strings->SetString("browseAsGuest",
+ l10n_util::GetStringUTF16(IDS_GO_INCOGNITO_BUTTON));
+ localized_strings->SetString("createAccount",
+ l10n_util::GetStringUTF16(IDS_CREATE_ACCOUNT_HTML));
+ localized_strings->SetString("guestSignin",
+ l10n_util::GetStringUTF16(IDS_BROWSE_WITHOUT_SIGNING_IN_HTML));
+ localized_strings->SetString("shutDown",
+ l10n_util::GetStringUTF16(IDS_SHUTDOWN_BUTTON));
+ localized_strings->SetString("showApps",
+ l10n_util::GetStringUTF16(IDS_KIOSK_APPS_BUTTON));
+ localized_strings->SetString("signOutUser",
+ l10n_util::GetStringUTF16(IDS_SCREEN_LOCK_SIGN_OUT));
+ localized_strings->SetString("bootIntoWallpaper", "off");
+ localized_strings->SetBoolean("enableAppMode", false);
+
+ // For AccountPickerScreen.
+ localized_strings->SetString("screenType", "login-add-user");
+ localized_strings->SetString("highlightStrength", "normal");
+ localized_strings->SetString("title", "User Chooser");
+ localized_strings->SetString("publicAccountReminder",
+ l10n_util::GetStringUTF16(IDS_LOGIN_PUBLIC_ACCOUNT_SIGNOUT_REMINDER));
+ localized_strings->SetString("publicAccountEnter",
+ l10n_util::GetStringUTF16(IDS_LOGIN_PUBLIC_ACCOUNT_ENTER));
+ localized_strings->SetString("publicAccountEnterAccessibleName",
+ l10n_util::GetStringUTF16(
+ IDS_LOGIN_PUBLIC_ACCOUNT_ENTER_ACCESSIBLE_NAME));
+ localized_strings->SetString("lockAnimationsType", "new");
+ localized_strings->SetString("passwordHint",
+ l10n_util::GetStringUTF16(IDS_LOGIN_POD_EMPTY_PASSWORD_TEXT));
+ localized_strings->SetString("podMenuButtonAccessibleName",
+ l10n_util::GetStringUTF16(IDS_LOGIN_POD_MENU_BUTTON_ACCESSIBLE_NAME));
+ localized_strings->SetString("podMenuRemoveItemAccessibleName",
+ l10n_util::GetStringUTF16(
+ IDS_LOGIN_POD_MENU_REMOVE_ITEM_ACCESSIBLE_NAME));
+ localized_strings->SetString("ownerUserPattern",
+ l10n_util::GetStringUTF16(IDS_LOGIN_POD_OWNER_USER));
+ localized_strings->SetString("removeUser",
+ l10n_util::GetStringUTF16(IDS_LOGIN_POD_REMOVE_USER));
+ localized_strings->SetString("passwordFieldAccessibleName",
+ l10n_util::GetStringUTF16(IDS_LOGIN_POD_PASSWORD_FIELD_ACCESSIBLE_NAME));
+ localized_strings->SetString("publicAccountInfoFormat",
+ l10n_util::GetStringUTF16(IDS_LOGIN_PUBLIC_ACCOUNT_INFO_FORMAT));
+
+ // For GaiaSigninScreen.
+ localized_strings->SetString("signinScreenTitle",
+ l10n_util::GetStringUTF16(IDS_SIGNIN_SCREEN_TITLE));
+ localized_strings->SetString("createLocallyManagedUser",
+ l10n_util::GetStringUTF16(IDS_CREATE_LOCALLY_MANAGED_USER_HTML));
+ localized_strings->SetString("createManagedUserFeatureName",
+ l10n_util::GetStringUTF16(IDS_CREATE_LOCALLY_MANAGED_USER_FEATURE_NAME));
+ localized_strings->SetString("createManagedUserNoManagerText",
+ l10n_util::GetStringUTF16(
+ IDS_CREATE_LOCALLY_MANAGED_USER_NO_MANAGER_TEXT));
+ localized_strings->SetString("learnMore",
+ l10n_util::GetStringUTF16(IDS_LEARN_MORE));
+}
+
+void UserChooserScreenHandler::SendUserList() {
+ ListValue users_list;
+ base::FilePath current_profile_path =
+ web_ui()->GetWebContents()->GetBrowserContext()->GetPath();
+ const ProfileInfoCache& info_cache =
+ g_browser_process->profile_manager()->GetProfileInfoCache();
+
+ for (size_t i = 0; i < info_cache.GetNumberOfProfiles(); ++i) {
+ DictionaryValue* profile_value = new DictionaryValue();
+
+ base::FilePath profile_path = info_cache.GetPathOfProfileAtIndex(i);
+ bool is_active_user = (profile_path == current_profile_path);
+ bool needs_signin = info_cache.ProfileIsSigninRequiredAtIndex(i);
+
+ profile_value->SetString(
+ kKeyUsername, info_cache.GetUserNameOfProfileAtIndex(i));
+ profile_value->SetString(
+ kKeyEmailAddress, info_cache.GetUserNameOfProfileAtIndex(i));
+ profile_value->SetString(
+ kKeyDisplayName, info_cache.GetNameOfProfileAtIndex(i));
+ profile_value->SetBoolean(kKeyPublicAccount, false);
+ profile_value->SetBoolean(kKeyLocallyManagedUser, false);
+ profile_value->SetBoolean(kKeySignedIn, is_active_user);
+
+ /*var OAuthTokenStatus = {
+ UNKNOWN: 0, INVALID_OLD: 1, VALID_OLD: 2, INVALID_NEW: 3, VALID_NEW: 4
+ };*/
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.
+ profile_value->SetInteger(kUserOAuthTokenStatus, needs_signin ? 2 : 0);
+ 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.
+ profile_value->SetBoolean(kKeyIsOwner, false);
+ profile_value->SetBoolean(kKeyCanRemove, true);
+ profile_value->SetBoolean(kKeyIsDesktop, true);
+
+ bool is_gaia_picture =
+ info_cache.IsUsingGAIAPictureOfProfileAtIndex(i) &&
+ info_cache.GetGAIAPictureOfProfileAtIndex(i);
+
+ gfx::Image icon = profiles::GetSizedAvatarIconWithBorder(
+ info_cache.GetAvatarIconOfProfileAtIndex(i), is_gaia_picture, 160, 160);
+ profile_value->SetString(kKeyAvatarUrl,
+ webui::GetBitmapDataUrl(icon.AsBitmap()));
+
+ if (is_active_user)
+ users_list.Insert(0, profile_value);
+ else
+ users_list.Append(profile_value);
+ }
+
+ web_ui()->CallJavascriptFunction("login.AccountPickerScreen.loadUsers",
+ users_list, base::FundamentalValue(false), base::FundamentalValue(true));
+}

Powered by Google App Engine
This is Rietveld 408576698