diff options
6 files changed, 79 insertions, 19 deletions
diff --git a/chrome/browser/chromeos/cros_settings_provider_user.cc b/chrome/browser/chromeos/cros_settings_provider_user.cc index c4c5725..33b11f2 100644 --- a/chrome/browser/chromeos/cros_settings_provider_user.cc +++ b/chrome/browser/chromeos/cros_settings_provider_user.cc @@ -88,6 +88,7 @@ UserCrosSettingsProvider::~UserCrosSettingsProvider() { SignedSettingsHelper::Get()->CancelCallback(this); } +// static void UserCrosSettingsProvider::RegisterPrefs(PrefService* local_state) { // Cached signed settings values local_state->RegisterBooleanPref(kAccountsPrefAllowGuest, true); @@ -97,20 +98,24 @@ void UserCrosSettingsProvider::RegisterPrefs(PrefService* local_state) { local_state->RegisterStringPref(kDeviceOwner, ""); } +// static bool UserCrosSettingsProvider::cached_allow_guest() { return g_browser_process->local_state()->GetBoolean(kAccountsPrefAllowGuest); } +// static bool UserCrosSettingsProvider::cached_allow_new_user() { return g_browser_process->local_state()->GetBoolean( kAccountsPrefAllowNewUser); } +// static bool UserCrosSettingsProvider::cached_show_users_on_signin() { return g_browser_process->local_state()->GetBoolean( kAccountsPrefShowUserNamesOnSignIn); } +// static const ListValue* UserCrosSettingsProvider::cached_whitelist() { PrefService* prefs = g_browser_process->local_state(); const ListValue* cached_users = prefs->GetList(kAccountsPrefUsers); @@ -125,10 +130,26 @@ const ListValue* UserCrosSettingsProvider::cached_whitelist() { return cached_users; } +// static std::string UserCrosSettingsProvider::cached_owner() { return g_browser_process->local_state()->GetString(kDeviceOwner); } +// static +bool UserCrosSettingsProvider::IsEmailInCachedWhitelist( + const std::string& email) { + const ListValue* whitelist = cached_whitelist(); + if (whitelist) { + StringValue email_value(email); + for (ListValue::const_iterator i(whitelist->begin()); + i != whitelist->end(); ++i) { + if ((*i)->Equals(&email_value)) + return true; + } + } + return false; +} + void UserCrosSettingsProvider::Set(const std::string& path, Value* in_value) { if (!UserManager::Get()->current_user_is_owner()) { LOG(WARNING) << "Changing settings from non-owner, setting=" << path; diff --git a/chrome/browser/chromeos/cros_settings_provider_user.h b/chrome/browser/chromeos/cros_settings_provider_user.h index f0c5509..c9ac4d9 100644 --- a/chrome/browser/chromeos/cros_settings_provider_user.h +++ b/chrome/browser/chromeos/cros_settings_provider_user.h @@ -34,6 +34,11 @@ class UserCrosSettingsProvider : public CrosSettingsProvider, static const ListValue* cached_whitelist(); static std::string cached_owner(); + // Returns true if given email is in user whitelist. + // Note this function is for display purpose only and should use + // CheckWhitelist op for the real whitelist check. + static bool IsEmailInCachedWhitelist(const std::string& email); + // CrosSettingsProvider implementation. virtual void Set(const std::string& path, Value* in_value); virtual bool Get(const std::string& path, Value** out_value) const; diff --git a/chrome/browser/chromeos/dom_ui/accounts_options_handler.cc b/chrome/browser/chromeos/dom_ui/accounts_options_handler.cc index 0176d7e..93361c6 100644 --- a/chrome/browser/chromeos/dom_ui/accounts_options_handler.cc +++ b/chrome/browser/chromeos/dom_ui/accounts_options_handler.cc @@ -31,6 +31,8 @@ void AccountsOptionsHandler::RegisterMessages() { NewCallback(this, &AccountsOptionsHandler::UnwhitelistUser)); dom_ui_->RegisterMessageCallback("fetchUserPictures", NewCallback(this, &AccountsOptionsHandler::FetchUserPictures)); + dom_ui_->RegisterMessageCallback("whitelistExistingUsers", + NewCallback(this, &AccountsOptionsHandler::WhitelistExistingUsers)); } void AccountsOptionsHandler::GetLocalizedValues( @@ -97,4 +99,24 @@ void AccountsOptionsHandler::FetchUserPictures(const ListValue* args) { user_pictures); } +void AccountsOptionsHandler::WhitelistExistingUsers(const ListValue* args) { + ListValue whitelist_users; + + std::vector<UserManager::User> users = UserManager::Get()->GetUsers(); + for (std::vector<UserManager::User>::const_iterator it = users.begin(); + it < users.end(); ++it) { + const std::string& email = it->email(); + if (!UserCrosSettingsProvider::IsEmailInCachedWhitelist(email)) { + DictionaryValue* user_dict = new DictionaryValue; + user_dict->SetString("name", it->GetDisplayName()); + user_dict->SetString("email", email); + user_dict->SetBoolean("owner", false); + + whitelist_users.Append(user_dict); + } + } + + dom_ui_->CallJavascriptFunction(L"AccountsOptions.addUsers", whitelist_users); +} + } // namespace chromeos diff --git a/chrome/browser/chromeos/dom_ui/accounts_options_handler.h b/chrome/browser/chromeos/dom_ui/accounts_options_handler.h index 177b447..2fbf76d 100644 --- a/chrome/browser/chromeos/dom_ui/accounts_options_handler.h +++ b/chrome/browser/chromeos/dom_ui/accounts_options_handler.h @@ -34,6 +34,9 @@ class AccountsOptionsHandler : public CrosOptionsPageUIHandler { // Javascript callback to fetch known user pictures. void FetchUserPictures(const ListValue* args); + // Javascript callback to auto add existing users to white list. + void WhitelistExistingUsers(const ListValue* args); + DISALLOW_COPY_AND_ASSIGN(AccountsOptionsHandler); }; diff --git a/chrome/browser/chromeos/login/existing_user_controller.cc b/chrome/browser/chromeos/login/existing_user_controller.cc index 36bfead..c7f7b69 100644 --- a/chrome/browser/chromeos/login/existing_user_controller.cc +++ b/chrome/browser/chromeos/login/existing_user_controller.cc @@ -98,22 +98,6 @@ void EnableTooltipsIfNeeded(const std::vector<UserController*>& controllers) { } } -// Returns true if given email is in user whitelist. -// Note this function is for display purpose only and should use -// CheckWhitelist op for the real whitelist check. -bool IsEmailInCachedWhitelist(const std::string& email) { - const ListValue* whitelist = UserCrosSettingsProvider::cached_whitelist(); - if (whitelist) { - StringValue email_value(email); - for (ListValue::const_iterator i(whitelist->begin()); - i != whitelist->end(); ++i) { - if ((*i)->Equals(&email_value)) - return true; - } - } - return false; -} - } // namespace ExistingUserController* @@ -149,7 +133,8 @@ ExistingUserController::ExistingUserController( // TODO(xiyuan): Clean user profile whose email is not in whitelist. if (UserCrosSettingsProvider::cached_allow_new_user() || - IsEmailInCachedWhitelist(users[i].email())) { + UserCrosSettingsProvider::IsEmailInCachedWhitelist( + users[i].email())) { controllers_.push_back(new UserController(this, users[i])); } } diff --git a/chrome/browser/resources/options/chromeos_accounts_options.js b/chrome/browser/resources/options/chromeos_accounts_options.js index f633931..1cc5b5c 100644 --- a/chrome/browser/resources/options/chromeos_accounts_options.js +++ b/chrome/browser/resources/options/chromeos_accounts_options.js @@ -43,6 +43,9 @@ cr.define('options', function() { userNameEdit.disabled = !AccountsOptions.currentUserIsOwner(); this.addEventListener('visibleChange', this.handleVisibleChange_); + + $('allowGuestCheck').addEventListener('click', + this.handleAllowGuestCheckClick_); }, /** @@ -59,12 +62,23 @@ cr.define('options', function() { }, /** + * Handler for allow guest check click. + * @private + */ + handleAllowGuestCheckClick_: function(e) { + // Whitelist existing users when guest login is being disabled. + if (!$('allowGuestCheck').checked) { + chrome.send('whitelistExistingUsers', []); + } + }, + + /** * Handler for "add" event fired from userNameEdit. * @private * @param {Event} e Add event fired from userNameEdit. */ handleAddUser_: function(e) { - $('userList').addUser(e.user); + AccountsOptions.addUsers([e.user]); } }; @@ -80,7 +94,17 @@ cr.define('options', function() { */ AccountsOptions.setUserPictures = function(cache) { $('userList').setUserPictures(cache); - } + }; + + /** + * Adds given users to userList. + */ + AccountsOptions.addUsers = function(users) { + var userList = $('userList'); + for (var i = 0; i < users.length; ++i) { + userList.addUser(users[i]); + } + }; // Export return { |