Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/options/manage_profile_handler.h" | 5 #include "chrome/browser/ui/webui/settings/settings_manage_profile_handler.h" |
|
Dan Beam
2015/12/28 23:28:57
why did this need a "Settings" in front? it's in
tommycli
2016/01/04 21:40:13
Yeah other compiler complications. Originally it w
| |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/prefs/scoped_user_pref_update.h" | 10 #include "base/prefs/scoped_user_pref_update.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/value_conversions.h" | 14 #include "base/value_conversions.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
| 18 #include "chrome/browser/profiles/gaia_info_update_service.h" | 18 #include "chrome/browser/profiles/gaia_info_update_service.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 20 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 21 #include "chrome/browser/profiles/profile_info_cache.h" | 21 #include "chrome/browser/profiles/profile_info_cache.h" |
| 22 #include "chrome/browser/profiles/profile_manager.h" | 22 #include "chrome/browser/profiles/profile_manager.h" |
| 23 #include "chrome/browser/profiles/profile_metrics.h" | 23 #include "chrome/browser/profiles/profile_metrics.h" |
| 24 #include "chrome/browser/profiles/profile_shortcut_manager.h" | 24 #include "chrome/browser/profiles/profile_shortcut_manager.h" |
| 25 #include "chrome/browser/profiles/profile_window.h" | 25 #include "chrome/browser/profiles/profile_window.h" |
| 26 #include "chrome/browser/profiles/profiles_state.h" | 26 #include "chrome/browser/profiles/profiles_state.h" |
| 27 #include "chrome/browser/signin/signin_manager_factory.h" | 27 #include "chrome/browser/signin/signin_manager_factory.h" |
| 28 #include "chrome/browser/sync/profile_sync_service_factory.h" | |
| 29 #include "chrome/browser/ui/browser_finder.h" | 28 #include "chrome/browser/ui/browser_finder.h" |
| 30 #include "chrome/browser/ui/webui/options/options_handlers_helper.h" | 29 #include "chrome/browser/ui/webui/options/options_handlers_helper.h" |
| 31 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
| 32 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
| 33 #include "chrome/grit/chromium_strings.h" | 32 #include "chrome/grit/chromium_strings.h" |
| 34 #include "chrome/grit/generated_resources.h" | 33 #include "chrome/grit/generated_resources.h" |
| 35 #include "components/browser_sync/browser/profile_sync_service.h" | |
| 36 #include "components/signin/core/browser/signin_manager.h" | 34 #include "components/signin/core/browser/signin_manager.h" |
| 37 #include "components/signin/core/common/profile_management_switches.h" | 35 #include "components/signin/core/common/profile_management_switches.h" |
| 38 #include "content/public/browser/browser_thread.h" | 36 #include "content/public/browser/browser_thread.h" |
| 39 #include "content/public/browser/notification_service.h" | 37 #include "content/public/browser/notification_service.h" |
| 40 #include "content/public/browser/web_ui.h" | 38 #include "content/public/browser/web_ui.h" |
| 41 #include "google_apis/gaia/gaia_auth_util.h" | 39 #include "google_apis/gaia/gaia_auth_util.h" |
| 42 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
| 43 #include "ui/base/webui/web_ui_util.h" | 41 #include "ui/base/webui/web_ui_util.h" |
| 44 | 42 |
| 45 #if defined(ENABLE_SETTINGS_APP) | 43 namespace settings { |
| 46 #include "chrome/browser/ui/app_list/app_list_service.h" | |
| 47 #include "content/public/browser/web_contents.h" | |
| 48 #endif | |
| 49 | 44 |
| 50 namespace options { | 45 ManageProfileHandler::ManageProfileHandler(Profile* profile) |
| 51 | 46 : profile_(profile), weak_factory_(this) { |
| 52 namespace { | 47 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); |
| 53 | |
| 54 const char kCreateProfileIdentifier[] = "create"; | |
| 55 const char kManageProfileIdentifier[] = "manage"; | |
| 56 | |
| 57 // Given |args| from the WebUI, parses value 0 as a FilePath |profile_file_path| | |
| 58 // and returns true on success. | |
| 59 bool GetProfilePathFromArgs(const base::ListValue* args, | |
| 60 base::FilePath* profile_file_path) { | |
| 61 const base::Value* file_path_value; | |
| 62 if (!args->Get(0, &file_path_value)) | |
| 63 return false; | |
| 64 return base::GetValueAsFilePath(*file_path_value, profile_file_path); | |
| 65 } | |
| 66 | |
| 67 void HandleLogDeleteUserDialogShown(const base::ListValue* args) { | |
| 68 ProfileMetrics::LogProfileDeleteUser( | |
| 69 ProfileMetrics::DELETE_PROFILE_SETTINGS_SHOW_WARNING); | |
| 70 } | |
| 71 | |
| 72 } // namespace | |
| 73 | |
| 74 ManageProfileHandler::ManageProfileHandler() | |
| 75 : weak_factory_(this) { | |
| 76 } | 48 } |
| 77 | 49 |
| 78 ManageProfileHandler::~ManageProfileHandler() { | 50 ManageProfileHandler::~ManageProfileHandler() { |
| 79 ProfileSyncService* service = | 51 g_browser_process->profile_manager()-> |
| 80 ProfileSyncServiceFactory::GetForProfile(Profile::FromWebUI(web_ui())); | 52 GetProfileInfoCache().RemoveObserver(this); |
| 81 // Sync may be disabled in tests. | |
| 82 if (service) | |
| 83 service->RemoveObserver(this); | |
| 84 } | |
| 85 | |
| 86 void ManageProfileHandler::GetLocalizedValues( | |
| 87 base::DictionaryValue* localized_strings) { | |
| 88 DCHECK(localized_strings); | |
| 89 | |
| 90 static OptionsStringResource resources[] = { | |
| 91 { "manageProfilesNameLabel", IDS_PROFILES_MANAGE_NAME_LABEL }, | |
| 92 { "manageProfilesIconLabel", IDS_PROFILES_MANAGE_ICON_LABEL }, | |
| 93 { "manageProfilesExistingSupervisedUser", | |
| 94 IDS_PROFILES_CREATE_LEGACY_SUPERVISED_USER_ERROR_EXISTS_REMOTELY }, | |
| 95 { "managedProfilesExistingLocalSupervisedUser", | |
| 96 IDS_PROFILES_CREATE_LEGACY_SUPERVISED_USER_ERROR_EXISTS_LOCALLY }, | |
| 97 { "manageProfilesSupervisedSignedInLabel", | |
| 98 IDS_PROFILES_CREATE_SUPERVISED_SIGNED_IN_LABEL }, | |
| 99 { "manageProfilesSupervisedNotSignedIn", | |
| 100 IDS_PROFILES_CREATE_SUPERVISED_NOT_SIGNED_IN_HTML }, | |
| 101 { "manageProfilesSupervisedAccountDetailsOutOfDate", | |
| 102 IDS_PROFILES_CREATE_SUPERVISED_ACCOUNT_DETAILS_OUT_OF_DATE_LABEL }, | |
| 103 { "manageProfilesSupervisedSignInAgainLink", | |
| 104 IDS_PROFILES_GAIA_REAUTH_TITLE }, | |
| 105 { "manageProfilesConfirm", IDS_SAVE }, | |
| 106 { "deleteProfileTitle", IDS_PROFILES_DELETE_TITLE }, | |
| 107 { "deleteProfileOK", IDS_PROFILES_DELETE_OK_BUTTON_LABEL }, | |
| 108 { "deleteProfileMessage", IDS_PROFILES_DELETE_MESSAGE }, | |
| 109 { "disconnectManagedProfileTitle", | |
| 110 IDS_PROFILES_DISCONNECT_MANAGED_PROFILE_TITLE }, | |
| 111 { "disconnectManagedProfileOK", | |
| 112 IDS_PROFILES_DISCONNECT_MANAGED_PROFILE_OK_BUTTON_LABEL }, | |
| 113 { "createProfileTitle", IDS_PROFILES_CREATE_TITLE }, | |
| 114 { "createProfileInstructions", IDS_PROFILES_CREATE_INSTRUCTIONS }, | |
| 115 { "createProfileConfirm", IDS_ADD }, | |
| 116 { "createProfileShortcutCheckbox", IDS_PROFILES_CREATE_SHORTCUT_CHECKBOX }, | |
| 117 { "createProfileShortcutButton", IDS_PROFILES_CREATE_SHORTCUT_BUTTON }, | |
| 118 { "removeProfileShortcutButton", IDS_PROFILES_REMOVE_SHORTCUT_BUTTON }, | |
| 119 { "importExistingSupervisedUserLink", | |
| 120 IDS_IMPORT_EXISTING_LEGACY_SUPERVISED_USER_TITLE }, | |
| 121 }; | |
| 122 | |
| 123 RegisterStrings(localized_strings, resources, arraysize(resources)); | |
| 124 RegisterTitle(localized_strings, "manageProfile", IDS_PROFILES_MANAGE_TITLE); | |
| 125 RegisterTitle(localized_strings, "createProfile", IDS_PROFILES_CREATE_TITLE); | |
| 126 | |
| 127 base::string16 supervised_user_dashboard_url = | |
| 128 base::ASCIIToUTF16(chrome::kLegacySupervisedUserManagementURL); | |
| 129 base::string16 supervised_user_dashboard_display = | |
| 130 base::ASCIIToUTF16(chrome::kLegacySupervisedUserManagementDisplayURL); | |
| 131 localized_strings->SetString("deleteSupervisedProfileAddendum", | |
| 132 l10n_util::GetStringFUTF16(IDS_PROFILES_DELETE_LEGACY_SUPERVISED_ADDENDUM, | |
| 133 supervised_user_dashboard_url, | |
| 134 supervised_user_dashboard_display)); | |
| 135 | |
| 136 localized_strings->SetBoolean("profileShortcutsEnabled", | |
| 137 ProfileShortcutManager::IsFeatureEnabled()); | |
| 138 | |
| 139 GenerateSignedinUserSpecificStrings(localized_strings); | |
| 140 } | |
| 141 | |
| 142 void ManageProfileHandler::InitializeHandler() { | |
| 143 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); | |
| 144 | |
| 145 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 146 pref_change_registrar_.Init(profile->GetPrefs()); | |
| 147 pref_change_registrar_.Add( | |
| 148 prefs::kSupervisedUserCreationAllowed, | |
| 149 base::Bind(&ManageProfileHandler::OnCreateSupervisedUserPrefChange, | |
| 150 base::Unretained(this))); | |
| 151 ProfileSyncService* service = | |
| 152 ProfileSyncServiceFactory::GetForProfile(profile); | |
| 153 // Sync may be disabled for tests. | |
| 154 if (service) | |
| 155 service->AddObserver(this); | |
| 156 } | |
| 157 | |
| 158 void ManageProfileHandler::InitializePage() { | |
| 159 SendExistingProfileNames(); | |
| 160 OnCreateSupervisedUserPrefChange(); | |
| 161 } | 53 } |
| 162 | 54 |
| 163 void ManageProfileHandler::RegisterMessages() { | 55 void ManageProfileHandler::RegisterMessages() { |
| 164 web_ui()->RegisterMessageCallback("setProfileIconAndName", | 56 web_ui()->RegisterMessageCallback("setProfileIconAndName", |
| 165 base::Bind(&ManageProfileHandler::SetProfileIconAndName, | 57 base::Bind(&ManageProfileHandler::SetProfileIconAndName, |
| 166 base::Unretained(this))); | 58 base::Unretained(this))); |
| 167 web_ui()->RegisterMessageCallback("requestDefaultProfileIcons", | 59 web_ui()->RegisterMessageCallback("requestDefaultProfileIcons", |
| 168 base::Bind(&ManageProfileHandler::RequestDefaultProfileIcons, | 60 base::Bind(&ManageProfileHandler::RequestDefaultProfileIcons, |
| 169 base::Unretained(this))); | 61 base::Unretained(this))); |
| 170 web_ui()->RegisterMessageCallback("requestNewProfileDefaults", | |
| 171 base::Bind(&ManageProfileHandler::RequestNewProfileDefaults, | |
| 172 base::Unretained(this))); | |
| 173 web_ui()->RegisterMessageCallback("requestHasProfileShortcuts", | 62 web_ui()->RegisterMessageCallback("requestHasProfileShortcuts", |
| 174 base::Bind(&ManageProfileHandler::RequestHasProfileShortcuts, | 63 base::Bind(&ManageProfileHandler::RequestHasProfileShortcuts, |
| 175 base::Unretained(this))); | 64 base::Unretained(this))); |
| 176 web_ui()->RegisterMessageCallback("requestCreateProfileUpdate", | |
| 177 base::Bind(&ManageProfileHandler::RequestCreateProfileUpdate, | |
| 178 base::Unretained(this))); | |
| 179 web_ui()->RegisterMessageCallback("profileIconSelectionChanged", | 65 web_ui()->RegisterMessageCallback("profileIconSelectionChanged", |
| 180 base::Bind(&ManageProfileHandler::ProfileIconSelectionChanged, | 66 base::Bind(&ManageProfileHandler::ProfileIconSelectionChanged, |
| 181 base::Unretained(this))); | 67 base::Unretained(this))); |
| 182 #if defined(ENABLE_SETTINGS_APP) | |
| 183 web_ui()->RegisterMessageCallback("switchAppListProfile", | |
| 184 base::Bind(&ManageProfileHandler::SwitchAppListProfile, | |
| 185 base::Unretained(this))); | |
| 186 #endif | |
| 187 web_ui()->RegisterMessageCallback("addProfileShortcut", | 68 web_ui()->RegisterMessageCallback("addProfileShortcut", |
| 188 base::Bind(&ManageProfileHandler::AddProfileShortcut, | 69 base::Bind(&ManageProfileHandler::AddProfileShortcut, |
| 189 base::Unretained(this))); | 70 base::Unretained(this))); |
| 190 web_ui()->RegisterMessageCallback("removeProfileShortcut", | 71 web_ui()->RegisterMessageCallback("removeProfileShortcut", |
| 191 base::Bind(&ManageProfileHandler::RemoveProfileShortcut, | 72 base::Bind(&ManageProfileHandler::RemoveProfileShortcut, |
| 192 base::Unretained(this))); | 73 base::Unretained(this))); |
| 193 web_ui()->RegisterMessageCallback("refreshGaiaPicture", | 74 web_ui()->RegisterMessageCallback("refreshGaiaPicture", |
| 194 base::Bind(&ManageProfileHandler::RefreshGaiaPicture, | 75 base::Bind(&ManageProfileHandler::RefreshGaiaPicture, |
| 195 base::Unretained(this))); | 76 base::Unretained(this))); |
| 196 web_ui()->RegisterMessageCallback( | |
| 197 "showDisconnectManagedProfileDialog", | |
| 198 base::Bind(&ManageProfileHandler::ShowDisconnectManagedProfileDialog, | |
| 199 base::Unretained(this))); | |
| 200 web_ui()->RegisterMessageCallback("logDeleteUserDialogShown", | |
| 201 base::Bind(&HandleLogDeleteUserDialogShown)); | |
| 202 } | |
| 203 | |
| 204 void ManageProfileHandler::Uninitialize() { | |
| 205 g_browser_process->profile_manager()-> | |
| 206 GetProfileInfoCache().RemoveObserver(this); | |
| 207 } | |
| 208 | |
| 209 void ManageProfileHandler::OnProfileAdded(const base::FilePath& profile_path) { | |
| 210 SendExistingProfileNames(); | |
| 211 } | |
| 212 | |
| 213 void ManageProfileHandler::OnProfileWasRemoved( | |
| 214 const base::FilePath& profile_path, | |
| 215 const base::string16& profile_name) { | |
| 216 SendExistingProfileNames(); | |
| 217 } | 77 } |
| 218 | 78 |
| 219 void ManageProfileHandler::OnProfileNameChanged( | 79 void ManageProfileHandler::OnProfileNameChanged( |
| 220 const base::FilePath& profile_path, | 80 const base::FilePath& profile_path, |
| 221 const base::string16& old_profile_name) { | 81 const base::string16& old_profile_name) { |
| 222 base::StringValue value(kManageProfileIdentifier); | 82 SendAvailableIcons(); |
| 223 SendProfileIconsAndNames(value); | |
| 224 } | 83 } |
| 225 | 84 |
| 226 void ManageProfileHandler::OnProfileAvatarChanged( | 85 void ManageProfileHandler::OnProfileAvatarChanged( |
| 227 const base::FilePath& profile_path) { | 86 const base::FilePath& profile_path) { |
| 228 base::StringValue value(kManageProfileIdentifier); | 87 SendAvailableIcons(); |
| 229 SendProfileIconsAndNames(value); | |
| 230 } | |
| 231 | |
| 232 void ManageProfileHandler::OnStateChanged() { | |
| 233 RequestCreateProfileUpdate(NULL); | |
| 234 } | |
| 235 | |
| 236 void ManageProfileHandler::GenerateSignedinUserSpecificStrings( | |
| 237 base::DictionaryValue* dictionary) { | |
| 238 std::string username; | |
| 239 std::string domain_name; | |
| 240 | |
| 241 #if !defined(OS_CHROMEOS) | |
| 242 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 243 DCHECK(profile); | |
| 244 SigninManagerBase* manager = SigninManagerFactory::GetForProfile(profile); | |
| 245 if (manager) { | |
| 246 username = manager->GetAuthenticatedAccountInfo().email; | |
| 247 // If there is no one logged in or if the profile name is empty then the | |
| 248 // domain name is empty. This happens in browser tests. | |
| 249 if (!username.empty()) { | |
| 250 domain_name = "<span id=disconnect-managed-profile-domain-name>" + | |
| 251 gaia::ExtractDomainName(username) + "</span>"; | |
| 252 } | |
| 253 } | |
| 254 #endif | |
| 255 | |
| 256 dictionary->SetString( | |
| 257 "disconnectManagedProfileDomainInformation", | |
| 258 l10n_util::GetStringFUTF16( | |
| 259 IDS_PROFILES_DISCONNECT_MANAGED_PROFILE_DOMAIN_INFORMATION, | |
| 260 base::ASCIIToUTF16(domain_name))); | |
| 261 | |
| 262 dictionary->SetString( | |
| 263 "disconnectManagedProfileText", | |
| 264 l10n_util::GetStringFUTF16( | |
| 265 IDS_PROFILES_DISCONNECT_MANAGED_PROFILE_TEXT, | |
| 266 base::UTF8ToUTF16(username), | |
| 267 base::UTF8ToUTF16(chrome::kSyncGoogleDashboardURL))); | |
| 268 } | 88 } |
| 269 | 89 |
| 270 void ManageProfileHandler::RequestDefaultProfileIcons( | 90 void ManageProfileHandler::RequestDefaultProfileIcons( |
| 271 const base::ListValue* args) { | 91 const base::ListValue* args) { |
| 272 std::string mode; | 92 SendAvailableIcons(); |
| 273 bool ok = args->GetString(0, &mode); | |
| 274 DCHECK(ok); | |
| 275 DCHECK(mode == kCreateProfileIdentifier || mode == kManageProfileIdentifier); | |
| 276 if (ok) { | |
| 277 base::StringValue value(mode); | |
| 278 SendProfileIconsAndNames(value); | |
| 279 } | |
| 280 } | 93 } |
| 281 | 94 |
| 282 void ManageProfileHandler::RequestNewProfileDefaults( | 95 void ManageProfileHandler::SendAvailableIcons() { |
| 283 const base::ListValue* args) { | |
| 284 const ProfileInfoCache& cache = | |
| 285 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
| 286 const size_t icon_index = cache.ChooseAvatarIconIndexForNewProfile(); | |
| 287 | |
| 288 base::DictionaryValue profile_info; | |
| 289 profile_info.SetString("name", cache.ChooseNameForNewProfile(icon_index)); | |
| 290 profile_info.SetString("iconURL", | |
| 291 profiles::GetDefaultAvatarIconUrl(icon_index)); | |
| 292 | |
| 293 web_ui()->CallJavascriptFunction( | |
| 294 "ManageProfileOverlay.receiveNewProfileDefaults", profile_info); | |
| 295 } | |
| 296 | |
| 297 void ManageProfileHandler::SendProfileIconsAndNames( | |
| 298 const base::StringValue& mode) { | |
| 299 base::ListValue image_url_list; | 96 base::ListValue image_url_list; |
| 300 base::ListValue default_name_list; | |
| 301 | |
| 302 const ProfileInfoCache& cache = | 97 const ProfileInfoCache& cache = |
| 303 g_browser_process->profile_manager()->GetProfileInfoCache(); | 98 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 304 | 99 |
| 305 // In manage mode, first add the GAIA picture if it is available. No GAIA | 100 // First add the GAIA picture if it is available. |
| 306 // picture in create mode. | 101 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); |
| 307 if (mode.GetString() == kManageProfileIdentifier) { | 102 if (profile_index != std::string::npos) { |
| 308 Profile* profile = Profile::FromWebUI(web_ui()); | 103 const gfx::Image* icon = |
| 309 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 104 cache.GetGAIAPictureOfProfileAtIndex(profile_index); |
| 310 if (profile_index != std::string::npos) { | 105 if (icon) { |
| 311 const gfx::Image* icon = | 106 gfx::Image icon2 = profiles::GetAvatarIconForWebUI(*icon, true); |
| 312 cache.GetGAIAPictureOfProfileAtIndex(profile_index); | 107 gaia_picture_url_ = webui::GetBitmapDataUrl(icon2.AsBitmap()); |
| 313 if (icon) { | 108 image_url_list.AppendString(gaia_picture_url_); |
| 314 gfx::Image icon2 = profiles::GetAvatarIconForWebUI(*icon, true); | |
| 315 gaia_picture_url_ = webui::GetBitmapDataUrl(icon2.AsBitmap()); | |
| 316 image_url_list.AppendString(gaia_picture_url_); | |
| 317 default_name_list.AppendString(std::string()); | |
| 318 } | |
| 319 } | 109 } |
| 320 } | 110 } |
| 321 | 111 |
| 322 // Next add the default avatar icons and names. | 112 // Next add the default avatar icons and names. |
| 323 for (size_t i = 0; i < profiles::GetDefaultAvatarIconCount(); i++) { | 113 for (size_t i = 0; i < profiles::GetDefaultAvatarIconCount(); i++) { |
| 324 std::string url = profiles::GetDefaultAvatarIconUrl(i); | 114 std::string url = profiles::GetDefaultAvatarIconUrl(i); |
| 325 image_url_list.AppendString(url); | 115 image_url_list.AppendString(url); |
| 326 default_name_list.AppendString(cache.ChooseNameForNewProfile(i)); | |
| 327 } | 116 } |
| 328 | 117 |
| 329 web_ui()->CallJavascriptFunction( | 118 web_ui()->CallJavascriptFunction( |
| 330 "ManageProfileOverlay.receiveDefaultProfileIconsAndNames", mode, | 119 "settings.SyncPrivateApi.receiveAvailableIcons", |
| 331 image_url_list, default_name_list); | 120 image_url_list); |
| 332 } | |
| 333 | |
| 334 void ManageProfileHandler::SendExistingProfileNames() { | |
| 335 const ProfileInfoCache& cache = | |
| 336 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
| 337 base::DictionaryValue profile_name_dict; | |
| 338 for (size_t i = 0, e = cache.GetNumberOfProfiles(); i < e; ++i) { | |
| 339 profile_name_dict.SetBoolean( | |
| 340 base::UTF16ToUTF8(cache.GetNameOfProfileAtIndex(i)), true); | |
| 341 } | |
| 342 | |
| 343 web_ui()->CallJavascriptFunction( | |
| 344 "ManageProfileOverlay.receiveExistingProfileNames", profile_name_dict); | |
| 345 } | |
| 346 | |
| 347 void ManageProfileHandler::ShowDisconnectManagedProfileDialog( | |
| 348 const base::ListValue* args) { | |
| 349 base::DictionaryValue replacements; | |
| 350 GenerateSignedinUserSpecificStrings(&replacements); | |
| 351 web_ui()->CallJavascriptFunction( | |
| 352 "ManageProfileOverlay.showDisconnectManagedProfileDialog", replacements); | |
| 353 } | 121 } |
| 354 | 122 |
| 355 void ManageProfileHandler::SetProfileIconAndName(const base::ListValue* args) { | 123 void ManageProfileHandler::SetProfileIconAndName(const base::ListValue* args) { |
| 356 DCHECK(args); | 124 DCHECK(args); |
| 357 | 125 |
| 358 base::FilePath profile_file_path; | 126 std::string icon_url; |
| 359 if (!GetProfilePathFromArgs(args, &profile_file_path)) | 127 if (!args->GetString(0, &icon_url)) |
| 360 return; | 128 return; |
| 361 | 129 |
| 362 Profile* profile = | 130 PrefService* pref_service = profile_->GetPrefs(); |
| 363 g_browser_process->profile_manager()->GetProfile(profile_file_path); | |
| 364 if (!profile) | |
| 365 return; | |
| 366 | |
| 367 std::string icon_url; | |
| 368 if (!args->GetString(1, &icon_url)) | |
| 369 return; | |
| 370 | |
| 371 PrefService* pref_service = profile->GetPrefs(); | |
| 372 // Updating the profile preferences will cause the cache to be updated. | 131 // Updating the profile preferences will cause the cache to be updated. |
| 373 | 132 |
| 374 // Metrics logging variable. | 133 // Metrics logging variable. |
| 375 bool previously_using_gaia_icon = | 134 bool previously_using_gaia_icon = |
| 376 pref_service->GetBoolean(prefs::kProfileUsingGAIAAvatar); | 135 pref_service->GetBoolean(prefs::kProfileUsingGAIAAvatar); |
| 377 | 136 |
| 378 size_t new_icon_index; | 137 size_t new_icon_index; |
| 379 if (icon_url == gaia_picture_url_) { | 138 if (icon_url == gaia_picture_url_) { |
| 380 pref_service->SetBoolean(prefs::kProfileUsingDefaultAvatar, false); | 139 pref_service->SetBoolean(prefs::kProfileUsingDefaultAvatar, false); |
| 381 pref_service->SetBoolean(prefs::kProfileUsingGAIAAvatar, true); | 140 pref_service->SetBoolean(prefs::kProfileUsingGAIAAvatar, true); |
| 382 if (!previously_using_gaia_icon) { | 141 if (!previously_using_gaia_icon) { |
| 383 // Only log if they changed to the GAIA photo. | 142 // Only log if they changed to the GAIA photo. |
| 384 // Selection of GAIA photo as avatar is logged as part of the function | 143 // Selection of GAIA photo as avatar is logged as part of the function |
| 385 // below. | 144 // below. |
| 386 ProfileMetrics::LogProfileSwitchGaia(ProfileMetrics::GAIA_OPT_IN); | 145 ProfileMetrics::LogProfileSwitchGaia(ProfileMetrics::GAIA_OPT_IN); |
| 387 } | 146 } |
| 388 } else if (profiles::IsDefaultAvatarIconUrl(icon_url, &new_icon_index)) { | 147 } else if (profiles::IsDefaultAvatarIconUrl(icon_url, &new_icon_index)) { |
| 389 ProfileMetrics::LogProfileAvatarSelection(new_icon_index); | 148 ProfileMetrics::LogProfileAvatarSelection(new_icon_index); |
| 390 pref_service->SetInteger(prefs::kProfileAvatarIndex, new_icon_index); | 149 pref_service->SetInteger(prefs::kProfileAvatarIndex, new_icon_index); |
| 391 pref_service->SetBoolean(prefs::kProfileUsingDefaultAvatar, false); | 150 pref_service->SetBoolean(prefs::kProfileUsingDefaultAvatar, false); |
| 392 pref_service->SetBoolean(prefs::kProfileUsingGAIAAvatar, false); | 151 pref_service->SetBoolean(prefs::kProfileUsingGAIAAvatar, false); |
| 393 } else { | 152 } else { |
| 394 // Only default avatars and Gaia account photos are supported. | 153 // Only default avatars and Gaia account photos are supported. |
| 395 CHECK(false); | 154 CHECK(false); |
| 396 } | 155 } |
| 397 ProfileMetrics::LogProfileUpdate(profile_file_path); | 156 ProfileMetrics::LogProfileUpdate(profile_->GetPath()); |
| 398 | 157 |
| 399 if (profile->IsLegacySupervised()) | 158 if (profile_->IsLegacySupervised()) |
| 400 return; | 159 return; |
| 401 | 160 |
| 402 base::string16 new_profile_name; | 161 base::string16 new_profile_name; |
| 403 if (!args->GetString(2, &new_profile_name)) | 162 if (!args->GetString(1, &new_profile_name)) |
| 404 return; | 163 return; |
| 405 | 164 |
| 406 base::TrimWhitespace(new_profile_name, base::TRIM_ALL, &new_profile_name); | 165 base::TrimWhitespace(new_profile_name, base::TRIM_ALL, &new_profile_name); |
| 407 CHECK(!new_profile_name.empty()); | 166 CHECK(!new_profile_name.empty()); |
| 408 profiles::UpdateProfileName(profile, new_profile_name); | 167 profiles::UpdateProfileName(profile_, new_profile_name); |
| 409 } | 168 } |
| 410 | 169 |
| 411 #if defined(ENABLE_SETTINGS_APP) | |
| 412 void ManageProfileHandler::SwitchAppListProfile(const base::ListValue* args) { | |
| 413 DCHECK(args); | |
| 414 DCHECK(profiles::IsMultipleProfilesEnabled()); | |
| 415 | |
| 416 const base::Value* file_path_value; | |
| 417 base::FilePath profile_file_path; | |
| 418 if (!args->Get(0, &file_path_value) || | |
| 419 !base::GetValueAsFilePath(*file_path_value, &profile_file_path)) | |
| 420 return; | |
| 421 | |
| 422 AppListService* app_list_service = AppListService::Get( | |
| 423 options::helper::GetDesktopType(web_ui())); | |
| 424 app_list_service->SetProfilePath(profile_file_path); | |
| 425 app_list_service->Show(); | |
| 426 | |
| 427 // Close the settings app, since it will now be for the wrong profile. | |
| 428 web_ui()->GetWebContents()->Close(); | |
| 429 } | |
| 430 #endif // defined(ENABLE_SETTINGS_APP) | |
| 431 | |
| 432 void ManageProfileHandler::ProfileIconSelectionChanged( | 170 void ManageProfileHandler::ProfileIconSelectionChanged( |
| 433 const base::ListValue* args) { | 171 const base::ListValue* args) { |
| 434 DCHECK(args); | 172 DCHECK(args); |
| 435 | 173 |
| 436 base::FilePath profile_file_path; | |
| 437 if (!GetProfilePathFromArgs(args, &profile_file_path)) | |
| 438 return; | |
| 439 | |
| 440 // Currently this only supports editing the current profile's info. | |
| 441 if (profile_file_path != Profile::FromWebUI(web_ui())->GetPath()) | |
| 442 return; | |
| 443 | |
| 444 std::string icon_url; | 174 std::string icon_url; |
| 445 if (!args->GetString(1, &icon_url)) | 175 if (!args->GetString(0, &icon_url)) |
| 446 return; | 176 return; |
| 447 | 177 |
| 448 if (icon_url != gaia_picture_url_) | 178 if (icon_url != gaia_picture_url_) |
| 449 return; | 179 return; |
| 450 | 180 |
| 451 // If the selection is the GAIA picture then also show the profile name in the | 181 // If the selection is the GAIA picture then also show the profile name in the |
| 452 // text field. This will display either the GAIA given name, if available, | 182 // text field. This will display either the GAIA given name, if available, |
| 453 // or the first name. | 183 // or the first name. |
| 454 ProfileInfoCache& cache = | 184 ProfileInfoCache& cache = |
| 455 g_browser_process->profile_manager()->GetProfileInfoCache(); | 185 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 456 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); | 186 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); |
| 457 if (profile_index == std::string::npos) | 187 if (profile_index == std::string::npos) |
| 458 return; | 188 return; |
| 459 base::string16 gaia_name = cache.GetNameOfProfileAtIndex(profile_index); | 189 base::string16 gaia_name = cache.GetNameOfProfileAtIndex(profile_index); |
| 460 if (gaia_name.empty()) | 190 if (gaia_name.empty()) |
| 461 return; | 191 return; |
| 462 | 192 |
| 463 base::StringValue gaia_name_value(gaia_name); | 193 base::StringValue gaia_name_value(gaia_name); |
| 464 base::StringValue mode_value(kManageProfileIdentifier); | 194 web_ui()->CallJavascriptFunction( |
| 465 web_ui()->CallJavascriptFunction("ManageProfileOverlay.setProfileName", | 195 "settings.SyncPrivateApi.setProfileName", |
| 466 gaia_name_value, mode_value); | 196 gaia_name_value); |
| 467 } | 197 } |
| 468 | 198 |
| 469 void ManageProfileHandler::RequestHasProfileShortcuts( | 199 void ManageProfileHandler::RequestHasProfileShortcuts( |
| 470 const base::ListValue* args) { | 200 const base::ListValue* args) { |
| 471 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 201 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 472 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); | 202 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); |
| 473 | 203 |
| 474 base::FilePath profile_file_path; | |
| 475 if (!GetProfilePathFromArgs(args, &profile_file_path)) | |
| 476 return; | |
| 477 | |
| 478 const ProfileInfoCache& cache = | 204 const ProfileInfoCache& cache = |
| 479 g_browser_process->profile_manager()->GetProfileInfoCache(); | 205 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 480 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_file_path); | 206 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); |
| 481 if (profile_index == std::string::npos) | 207 if (profile_index == std::string::npos) |
| 482 return; | 208 return; |
| 483 | 209 |
| 484 // Don't show the add/remove desktop shortcut button in the single user case. | 210 // Don't show the add/remove desktop shortcut button in the single user case. |
| 485 if (cache.GetNumberOfProfiles() <= 1) | 211 if (cache.GetNumberOfProfiles() <= 1) |
| 486 return; | 212 return; |
| 487 | 213 |
| 488 const base::FilePath profile_path = | 214 const base::FilePath profile_path = |
| 489 cache.GetPathOfProfileAtIndex(profile_index); | 215 cache.GetPathOfProfileAtIndex(profile_index); |
| 490 ProfileShortcutManager* shortcut_manager = | 216 ProfileShortcutManager* shortcut_manager = |
| 491 g_browser_process->profile_manager()->profile_shortcut_manager(); | 217 g_browser_process->profile_manager()->profile_shortcut_manager(); |
| 492 shortcut_manager->HasProfileShortcuts( | 218 shortcut_manager->HasProfileShortcuts( |
| 493 profile_path, base::Bind(&ManageProfileHandler::OnHasProfileShortcuts, | 219 profile_path, base::Bind(&ManageProfileHandler::OnHasProfileShortcuts, |
| 494 weak_factory_.GetWeakPtr())); | 220 weak_factory_.GetWeakPtr())); |
| 495 } | 221 } |
| 496 | 222 |
| 497 void ManageProfileHandler::RequestCreateProfileUpdate( | |
| 498 const base::ListValue* args) { | |
| 499 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 500 SigninManagerBase* manager = | |
| 501 SigninManagerFactory::GetForProfile(profile); | |
| 502 base::string16 username = | |
| 503 base::UTF8ToUTF16(manager->GetAuthenticatedAccountInfo().email); | |
| 504 ProfileSyncService* service = | |
| 505 ProfileSyncServiceFactory::GetForProfile(profile); | |
| 506 GoogleServiceAuthError::State state = GoogleServiceAuthError::NONE; | |
| 507 | |
| 508 // |service| might be null if Sync is disabled from the command line. | |
| 509 if (service) | |
| 510 state = service->GetAuthError().state(); | |
| 511 | |
| 512 bool has_error = (!service || | |
| 513 state == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || | |
| 514 state == GoogleServiceAuthError::USER_NOT_SIGNED_UP || | |
| 515 state == GoogleServiceAuthError::ACCOUNT_DELETED || | |
| 516 state == GoogleServiceAuthError::ACCOUNT_DISABLED); | |
| 517 web_ui()->CallJavascriptFunction("CreateProfileOverlay.updateSignedInStatus", | |
| 518 base::StringValue(username), | |
| 519 base::FundamentalValue(has_error)); | |
| 520 | |
| 521 OnCreateSupervisedUserPrefChange(); | |
| 522 } | |
| 523 | |
| 524 void ManageProfileHandler::OnCreateSupervisedUserPrefChange() { | |
| 525 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); | |
| 526 base::FundamentalValue allowed( | |
| 527 prefs->GetBoolean(prefs::kSupervisedUserCreationAllowed)); | |
| 528 web_ui()->CallJavascriptFunction( | |
| 529 "CreateProfileOverlay.updateSupervisedUsersAllowed", allowed); | |
| 530 } | |
| 531 | |
| 532 void ManageProfileHandler::OnHasProfileShortcuts(bool has_shortcuts) { | 223 void ManageProfileHandler::OnHasProfileShortcuts(bool has_shortcuts) { |
| 533 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 224 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 534 | 225 |
| 535 const base::FundamentalValue has_shortcuts_value(has_shortcuts); | 226 const base::FundamentalValue has_shortcuts_value(has_shortcuts); |
| 536 web_ui()->CallJavascriptFunction( | 227 web_ui()->CallJavascriptFunction( |
| 537 "ManageProfileOverlay.receiveHasProfileShortcuts", has_shortcuts_value); | 228 "settings.SyncPrivateApi.receiveHasProfileShortcuts", |
| 229 has_shortcuts_value); | |
| 538 } | 230 } |
| 539 | 231 |
| 540 void ManageProfileHandler::AddProfileShortcut(const base::ListValue* args) { | 232 void ManageProfileHandler::AddProfileShortcut(const base::ListValue* args) { |
| 541 base::FilePath profile_file_path; | |
| 542 if (!GetProfilePathFromArgs(args, &profile_file_path)) | |
| 543 return; | |
| 544 | |
| 545 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); | 233 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); |
| 546 ProfileShortcutManager* shortcut_manager = | 234 ProfileShortcutManager* shortcut_manager = |
| 547 g_browser_process->profile_manager()->profile_shortcut_manager(); | 235 g_browser_process->profile_manager()->profile_shortcut_manager(); |
| 548 DCHECK(shortcut_manager); | 236 DCHECK(shortcut_manager); |
| 549 | 237 |
| 550 shortcut_manager->CreateProfileShortcut(profile_file_path); | 238 shortcut_manager->CreateProfileShortcut(profile_->GetPath()); |
| 551 | 239 |
| 552 // Update the UI buttons. | 240 // Update the UI buttons. |
| 553 OnHasProfileShortcuts(true); | 241 OnHasProfileShortcuts(true); |
| 554 } | 242 } |
| 555 | 243 |
| 556 void ManageProfileHandler::RemoveProfileShortcut(const base::ListValue* args) { | 244 void ManageProfileHandler::RemoveProfileShortcut(const base::ListValue* args) { |
| 557 base::FilePath profile_file_path; | |
| 558 if (!GetProfilePathFromArgs(args, &profile_file_path)) | |
| 559 return; | |
| 560 | |
| 561 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); | 245 DCHECK(ProfileShortcutManager::IsFeatureEnabled()); |
| 562 ProfileShortcutManager* shortcut_manager = | 246 ProfileShortcutManager* shortcut_manager = |
| 563 g_browser_process->profile_manager()->profile_shortcut_manager(); | 247 g_browser_process->profile_manager()->profile_shortcut_manager(); |
| 564 DCHECK(shortcut_manager); | 248 DCHECK(shortcut_manager); |
| 565 | 249 |
| 566 shortcut_manager->RemoveProfileShortcuts(profile_file_path); | 250 shortcut_manager->RemoveProfileShortcuts(profile_->GetPath()); |
| 567 | 251 |
| 568 // Update the UI buttons. | 252 // Update the UI buttons. |
| 569 OnHasProfileShortcuts(false); | 253 OnHasProfileShortcuts(false); |
| 570 } | 254 } |
| 571 | 255 |
| 572 void ManageProfileHandler::RefreshGaiaPicture(const base::ListValue* args) { | 256 void ManageProfileHandler::RefreshGaiaPicture(const base::ListValue* args) { |
| 573 profiles::UpdateGaiaProfileInfoIfNeeded(Profile::FromWebUI(web_ui())); | 257 profiles::UpdateGaiaProfileInfoIfNeeded(Profile::FromWebUI(web_ui())); |
| 574 } | 258 } |
| 575 | 259 |
| 576 } // namespace options | 260 } // namespace settings |
| OLD | NEW |