OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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/options2/chromeos/accounts_options_handler.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" |
| 9 #include "base/json/json_reader.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/utf_string_conversions.h" |
| 12 #include "base/values.h" |
| 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/chromeos/cros_settings.h" |
| 15 #include "chrome/browser/chromeos/cros_settings_names.h" |
| 16 #include "chrome/browser/chromeos/login/authenticator.h" |
| 17 #include "chrome/browser/chromeos/login/user_manager.h" |
| 18 #include "chrome/browser/prefs/pref_service.h" |
| 19 #include "chrome/browser/policy/browser_policy_connector.h" |
| 20 #include "grit/generated_resources.h" |
| 21 #include "ui/base/l10n/l10n_util.h" |
| 22 |
| 23 namespace chromeos { |
| 24 |
| 25 namespace { |
| 26 |
| 27 // Adds specified user to the whitelist. Returns false if that user is already |
| 28 // in the whitelist. |
| 29 bool WhitelistUser(const std::string& username) { |
| 30 CrosSettings* cros_settings = CrosSettings::Get(); |
| 31 if (cros_settings->FindEmailInList(kAccountsPrefUsers, username)) |
| 32 return false; |
| 33 base::StringValue username_value(username); |
| 34 cros_settings->AppendToList(kAccountsPrefUsers, &username_value); |
| 35 return true; |
| 36 } |
| 37 |
| 38 } // namespace |
| 39 |
| 40 AccountsOptionsHandler::AccountsOptionsHandler() { |
| 41 } |
| 42 |
| 43 AccountsOptionsHandler::~AccountsOptionsHandler() { |
| 44 } |
| 45 |
| 46 void AccountsOptionsHandler::RegisterMessages() { |
| 47 DCHECK(web_ui_); |
| 48 web_ui_->RegisterMessageCallback("whitelistUser", |
| 49 base::Bind(&AccountsOptionsHandler::HandleWhitelistUser, |
| 50 base::Unretained(this))); |
| 51 web_ui_->RegisterMessageCallback("unwhitelistUser", |
| 52 base::Bind(&AccountsOptionsHandler::HandleUnwhitelistUser, |
| 53 base::Unretained(this))); |
| 54 web_ui_->RegisterMessageCallback("whitelistExistingUsers", |
| 55 base::Bind(&AccountsOptionsHandler::HandleWhitelistExistingUsers, |
| 56 base::Unretained(this))); |
| 57 } |
| 58 |
| 59 void AccountsOptionsHandler::GetLocalizedValues( |
| 60 base::DictionaryValue* localized_strings) { |
| 61 DCHECK(localized_strings); |
| 62 |
| 63 RegisterTitle(localized_strings, "accountsPage", |
| 64 IDS_OPTIONS_ACCOUNTS_TAB_LABEL); |
| 65 |
| 66 localized_strings->SetString("allow_BWSI", l10n_util::GetStringUTF16( |
| 67 IDS_OPTIONS_ACCOUNTS_ALLOW_BWSI_DESCRIPTION)); |
| 68 localized_strings->SetString("use_whitelist",l10n_util::GetStringUTF16( |
| 69 IDS_OPTIONS_ACCOUNTS_USE_WHITELIST_DESCRIPTION)); |
| 70 localized_strings->SetString("show_user_on_signin",l10n_util::GetStringUTF16( |
| 71 IDS_OPTIONS_ACCOUNTS_SHOW_USER_NAMES_ON_SINGIN_DESCRIPTION)); |
| 72 localized_strings->SetString("username_edit_hint",l10n_util::GetStringUTF16( |
| 73 IDS_OPTIONS_ACCOUNTS_USERNAME_EDIT_HINT)); |
| 74 localized_strings->SetString("username_format",l10n_util::GetStringUTF16( |
| 75 IDS_OPTIONS_ACCOUNTS_USERNAME_FORMAT)); |
| 76 localized_strings->SetString("add_users",l10n_util::GetStringUTF16( |
| 77 IDS_OPTIONS_ACCOUNTS_ADD_USERS)); |
| 78 localized_strings->SetString("owner_only", l10n_util::GetStringUTF16( |
| 79 IDS_OPTIONS_ACCOUNTS_OWNER_ONLY)); |
| 80 |
| 81 std::string owner_email; |
| 82 CrosSettings::Get()->GetString(kDeviceOwner, &owner_email); |
| 83 // Translate owner's email to the display email. |
| 84 std::string display_email = |
| 85 UserManager::Get()->GetUserDisplayEmail(owner_email); |
| 86 localized_strings->SetString("owner_user_id", UTF8ToUTF16(display_email)); |
| 87 |
| 88 localized_strings->SetString("current_user_is_owner", |
| 89 UserManager::Get()->current_user_is_owner() ? |
| 90 ASCIIToUTF16("true") : ASCIIToUTF16("false")); |
| 91 localized_strings->SetString("logged_in_as_guest", |
| 92 UserManager::Get()->IsLoggedInAsGuest() ? |
| 93 ASCIIToUTF16("true") : ASCIIToUTF16("false")); |
| 94 localized_strings->SetString("whitelist_is_managed", |
| 95 g_browser_process->browser_policy_connector()->IsEnterpriseManaged() ? |
| 96 ASCIIToUTF16("true") : ASCIIToUTF16("false")); |
| 97 } |
| 98 |
| 99 void AccountsOptionsHandler::HandleWhitelistUser(const base::ListValue* args) { |
| 100 std::string typed_email; |
| 101 std::string name; |
| 102 if (!args->GetString(0, &typed_email) || |
| 103 !args->GetString(1, &name)) { |
| 104 return; |
| 105 } |
| 106 |
| 107 WhitelistUser(Authenticator::Canonicalize(typed_email)); |
| 108 } |
| 109 |
| 110 void AccountsOptionsHandler::HandleUnwhitelistUser( |
| 111 const base::ListValue* args) { |
| 112 std::string email; |
| 113 if (!args->GetString(0, &email)) { |
| 114 return; |
| 115 } |
| 116 |
| 117 base::StringValue canonical_email(Authenticator::Canonicalize(email)); |
| 118 CrosSettings::Get()->RemoveFromList(kAccountsPrefUsers, &canonical_email); |
| 119 UserManager::Get()->RemoveUser(email, NULL); |
| 120 } |
| 121 |
| 122 void AccountsOptionsHandler::HandleWhitelistExistingUsers( |
| 123 const base::ListValue* args) { |
| 124 DCHECK(args && args->empty()); |
| 125 |
| 126 const UserList& users = UserManager::Get()->GetUsers(); |
| 127 for (UserList::const_iterator it = users.begin(); it < users.end(); ++it) { |
| 128 WhitelistUser((*it)->email()); |
| 129 } |
| 130 } |
| 131 |
| 132 } // namespace chromeos |
OLD | NEW |