OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/personal_options_handler.h" | 5 #include "chrome/browser/ui/webui/options/personal_options_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/string_number_conversions.h" |
13 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
14 #include "base/time.h" | 15 #include "base/time.h" |
15 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "base/value_conversions.h" |
16 #include "base/values.h" | 18 #include "base/values.h" |
17 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 20 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/profiles/profile_info_cache.h" |
19 #include "chrome/browser/profiles/profile_manager.h" | 23 #include "chrome/browser/profiles/profile_manager.h" |
20 #include "chrome/browser/sync/profile_sync_service.h" | 24 #include "chrome/browser/sync/profile_sync_service.h" |
21 #include "chrome/browser/sync/sync_setup_flow.h" | 25 #include "chrome/browser/sync/sync_setup_flow.h" |
22 #include "chrome/browser/sync/sync_ui_util.h" | 26 #include "chrome/browser/sync/sync_ui_util.h" |
23 #include "chrome/browser/themes/theme_service.h" | 27 #include "chrome/browser/themes/theme_service.h" |
24 #include "chrome/browser/themes/theme_service_factory.h" | 28 #include "chrome/browser/themes/theme_service_factory.h" |
25 #include "chrome/common/chrome_notification_types.h" | 29 #include "chrome/common/chrome_notification_types.h" |
26 #include "chrome/common/chrome_paths.h" | 30 #include "chrome/common/chrome_paths.h" |
27 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
28 #include "chrome/common/net/gaia/google_service_auth_error.h" | 32 #include "chrome/common/net/gaia/google_service_auth_error.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 75 |
72 | 76 |
73 localized_strings->SetString( | 77 localized_strings->SetString( |
74 "syncOverview", | 78 "syncOverview", |
75 l10n_util::GetStringFUTF16(IDS_SYNC_OVERVIEW, | 79 l10n_util::GetStringFUTF16(IDS_SYNC_OVERVIEW, |
76 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); | 80 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); |
77 localized_strings->SetString( | 81 localized_strings->SetString( |
78 "syncFurtherOverview", | 82 "syncFurtherOverview", |
79 l10n_util::GetStringUTF16(IDS_SYNC_FURTHER_OVERVIEW)); | 83 l10n_util::GetStringUTF16(IDS_SYNC_FURTHER_OVERVIEW)); |
80 localized_strings->SetString("syncSection", | 84 localized_strings->SetString("syncSection", |
81 multiprofile_ ? | 85 l10n_util::GetStringUTF16(IDS_SYNC_OPTIONS_GROUP_NAME)); |
82 l10n_util::GetStringUTF16(IDS_PROFILES_OPTIONS_GROUP_NAME) : | |
83 l10n_util::GetStringUTF16(IDS_SYNC_OPTIONS_GROUP_NAME)); | |
84 localized_strings->SetString("customizeSync", | 86 localized_strings->SetString("customizeSync", |
85 multiprofile_ ? | 87 l10n_util::GetStringUTF16(IDS_SYNC_CUSTOMIZE_BUTTON_LABEL)); |
86 l10n_util::GetStringUTF16(IDS_PROFILES_SYNC_CUSTOMIZE_BUTTON_LABEL) : | 88 |
87 l10n_util::GetStringUTF16(IDS_SYNC_CUSTOMIZE_BUTTON_LABEL)); | 89 localized_strings->SetString("profiles", |
88 if (multiprofile_) { | 90 l10n_util::GetStringUTF16(IDS_PROFILES_OPTIONS_GROUP_NAME)); |
89 localized_strings->SetString("createNewProfile", | 91 localized_strings->SetString("profilesCreate", |
90 l10n_util::GetStringUTF16(IDS_PROFILES_CREATE_INFO)); | 92 l10n_util::GetStringUTF16(IDS_PROFILES_CREATE_BUTTON_LABEL)); |
91 localized_strings->SetString("createProfileButton", | 93 localized_strings->SetString("profilesManage", |
92 l10n_util::GetStringUTF16(IDS_PROFILES_CREATE_BUTTON_LABEL)); | 94 l10n_util::GetStringUTF16(IDS_PROFILES_MANAGE_BUTTON_LABEL)); |
93 } | 95 localized_strings->SetString("profilesDelete", |
| 96 l10n_util::GetStringUTF16(IDS_PROFILES_DELETE_BUTTON_LABEL)); |
| 97 localized_strings->SetString("profilesListItemCurrent", |
| 98 l10n_util::GetStringUTF16(IDS_PROFILES_LIST_ITEM_CURRENT)); |
94 | 99 |
95 localized_strings->SetString("passwords", | 100 localized_strings->SetString("passwords", |
96 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_GROUP_NAME)); | 101 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_GROUP_NAME)); |
97 localized_strings->SetString("passwordsAskToSave", | 102 localized_strings->SetString("passwordsAskToSave", |
98 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_ASKTOSAVE)); | 103 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_ASKTOSAVE)); |
99 localized_strings->SetString("passwordsNeverSave", | 104 localized_strings->SetString("passwordsNeverSave", |
100 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_NEVERSAVE)); | 105 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_NEVERSAVE)); |
101 localized_strings->SetString("manage_passwords", | 106 localized_strings->SetString("manage_passwords", |
102 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS)); | 107 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS)); |
103 | 108 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 #if defined(TOOLKIT_GTK) | 199 #if defined(TOOLKIT_GTK) |
195 web_ui_->RegisterMessageCallback( | 200 web_ui_->RegisterMessageCallback( |
196 "themesSetGTK", | 201 "themesSetGTK", |
197 NewCallback(this, &PersonalOptionsHandler::ThemesSetGTK)); | 202 NewCallback(this, &PersonalOptionsHandler::ThemesSetGTK)); |
198 #endif | 203 #endif |
199 #if defined(OS_CHROMEOS) | 204 #if defined(OS_CHROMEOS) |
200 web_ui_->RegisterMessageCallback( | 205 web_ui_->RegisterMessageCallback( |
201 "loadAccountPicture", | 206 "loadAccountPicture", |
202 NewCallback(this, &PersonalOptionsHandler::LoadAccountPicture)); | 207 NewCallback(this, &PersonalOptionsHandler::LoadAccountPicture)); |
203 #endif | 208 #endif |
| 209 web_ui_->RegisterMessageCallback( |
| 210 "createProfile", |
| 211 NewCallback(this, &PersonalOptionsHandler::CreateProfile)); |
204 } | 212 } |
205 | 213 |
206 void PersonalOptionsHandler::Observe(int type, | 214 void PersonalOptionsHandler::Observe(int type, |
207 const NotificationSource& source, | 215 const NotificationSource& source, |
208 const NotificationDetails& details) { | 216 const NotificationDetails& details) { |
209 if (type == chrome::NOTIFICATION_BROWSER_THEME_CHANGED) { | 217 if (type == chrome::NOTIFICATION_BROWSER_THEME_CHANGED) { |
210 ObserveThemeChanged(); | 218 ObserveThemeChanged(); |
| 219 } else if (multiprofile_ && |
| 220 type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED) { |
| 221 SendProfilesInfo(); |
211 #if defined(OS_CHROMEOS) | 222 #if defined(OS_CHROMEOS) |
212 } else if (type == chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED) { | 223 } else if (type == chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED) { |
213 LoadAccountPicture(NULL); | 224 LoadAccountPicture(NULL); |
214 #endif | 225 #endif |
215 } else { | 226 } else { |
216 OptionsPageUIHandler::Observe(type, source, details); | 227 OptionsPageUIHandler::Observe(type, source, details); |
217 } | 228 } |
218 } | 229 } |
219 | 230 |
220 void PersonalOptionsHandler::OnStateChanged() { | 231 void PersonalOptionsHandler::OnStateChanged() { |
(...skipping 18 matching lines...) Expand all Loading... |
239 status_label.assign(l10n_util::GetStringFUTF16( | 250 status_label.assign(l10n_util::GetStringFUTF16( |
240 IDS_SYNC_ACCOUNT_SYNCING_TO_USER, | 251 IDS_SYNC_ACCOUNT_SYNCING_TO_USER, |
241 user_name, | 252 user_name, |
242 ASCIIToUTF16(chrome::kSyncGoogleDashboardURL))); | 253 ASCIIToUTF16(chrome::kSyncGoogleDashboardURL))); |
243 } | 254 } |
244 | 255 |
245 string16 start_stop_button_label; | 256 string16 start_stop_button_label; |
246 bool is_start_stop_button_visible = false; | 257 bool is_start_stop_button_visible = false; |
247 bool is_start_stop_button_enabled = false; | 258 bool is_start_stop_button_enabled = false; |
248 if (sync_setup_completed) { | 259 if (sync_setup_completed) { |
249 start_stop_button_label = multiprofile_ ? | 260 start_stop_button_label = |
250 l10n_util::GetStringUTF16(IDS_PROFILES_DISCONNECT_BUTTON_LABEL) : | |
251 l10n_util::GetStringUTF16(IDS_SYNC_STOP_SYNCING_BUTTON_LABEL); | 261 l10n_util::GetStringUTF16(IDS_SYNC_STOP_SYNCING_BUTTON_LABEL); |
252 #if defined(OS_CHROMEOS) | 262 #if defined(OS_CHROMEOS) |
253 is_start_stop_button_visible = false; | 263 is_start_stop_button_visible = false; |
254 #else | 264 #else |
255 is_start_stop_button_visible = true; | 265 is_start_stop_button_visible = true; |
256 #endif // defined(OS_CHROMEOS) | 266 #endif // defined(OS_CHROMEOS) |
257 is_start_stop_button_enabled = !managed; | 267 is_start_stop_button_enabled = !managed; |
258 } else if (service->SetupInProgress()) { | 268 } else if (service->SetupInProgress()) { |
259 start_stop_button_label = | 269 start_stop_button_label = |
260 l10n_util::GetStringUTF16(IDS_SYNC_NTP_SETUP_IN_PROGRESS); | 270 l10n_util::GetStringUTF16(IDS_SYNC_NTP_SETUP_IN_PROGRESS); |
261 is_start_stop_button_visible = true; | 271 is_start_stop_button_visible = true; |
262 is_start_stop_button_enabled = false; | 272 is_start_stop_button_enabled = false; |
263 } else { | 273 } else { |
264 start_stop_button_label = | 274 start_stop_button_label = |
265 multiprofile_ ? | 275 l10n_util::GetStringUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL); |
266 l10n_util::GetStringUTF16(IDS_PROFILES_CONNECT_BUTTON_LABEL) : | |
267 l10n_util::GetStringUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL); | |
268 is_start_stop_button_visible = true; | 276 is_start_stop_button_visible = true; |
269 is_start_stop_button_enabled = !managed; | 277 is_start_stop_button_enabled = !managed; |
270 } | 278 } |
271 | 279 |
272 scoped_ptr<Value> completed(Value::CreateBooleanValue(sync_setup_completed)); | 280 scoped_ptr<Value> completed(Value::CreateBooleanValue(sync_setup_completed)); |
273 web_ui_->CallJavascriptFunction("PersonalOptions.setSyncSetupCompleted", | 281 web_ui_->CallJavascriptFunction("PersonalOptions.setSyncSetupCompleted", |
274 *completed); | 282 *completed); |
275 | 283 |
276 scoped_ptr<Value> label(Value::CreateStringValue(status_label)); | 284 scoped_ptr<Value> label(Value::CreateStringValue(status_label)); |
277 web_ui_->CallJavascriptFunction("PersonalOptions.setSyncStatus", *label); | 285 web_ui_->CallJavascriptFunction("PersonalOptions.setSyncStatus", *label); |
(...skipping 18 matching lines...) Expand all Loading... |
296 | 304 |
297 enabled.reset(Value::CreateBooleanValue(!managed)); | 305 enabled.reset(Value::CreateBooleanValue(!managed)); |
298 web_ui_->CallJavascriptFunction("PersonalOptions.setSyncActionLinkEnabled", | 306 web_ui_->CallJavascriptFunction("PersonalOptions.setSyncActionLinkEnabled", |
299 *enabled); | 307 *enabled); |
300 | 308 |
301 visible.reset(Value::CreateBooleanValue(status_has_error)); | 309 visible.reset(Value::CreateBooleanValue(status_has_error)); |
302 web_ui_->CallJavascriptFunction("PersonalOptions.setSyncStatusErrorVisible", | 310 web_ui_->CallJavascriptFunction("PersonalOptions.setSyncStatusErrorVisible", |
303 *visible); | 311 *visible); |
304 | 312 |
305 // Set profile creation text and button if multi-profiles switch is on. | 313 // Set profile creation text and button if multi-profiles switch is on. |
306 if (multiprofile_) { | 314 visible.reset(Value::CreateBooleanValue(multiprofile_)); |
307 visible.reset(Value::CreateBooleanValue(true)); | 315 web_ui_->CallJavascriptFunction("PersonalOptions.setProfilesSectionVisible", |
308 web_ui_->CallJavascriptFunction("PersonalOptions.setProfilesSectionVisible", | 316 *visible); |
309 *visible); | 317 if (multiprofile_) |
310 | 318 SendProfilesInfo(); |
311 // TODO(mirandac): enable when back end is ready. | |
312 enabled.reset(Value::CreateBooleanValue(false)); | |
313 web_ui_->CallJavascriptFunction( | |
314 "PersonalOptions.setNewProfileButtonEnabled", *enabled); | |
315 } else { | |
316 visible.reset(Value::CreateBooleanValue(false)); | |
317 web_ui_->CallJavascriptFunction("PersonalOptions.setProfilesSectionVisible", | |
318 *visible); | |
319 } | |
320 } | 319 } |
321 | 320 |
322 void PersonalOptionsHandler::OnLoginSuccess() { | 321 void PersonalOptionsHandler::OnLoginSuccess() { |
323 OnStateChanged(); | 322 OnStateChanged(); |
324 } | 323 } |
325 | 324 |
326 void PersonalOptionsHandler::OnLoginFailure( | 325 void PersonalOptionsHandler::OnLoginFailure( |
327 const GoogleServiceAuthError& error) { | 326 const GoogleServiceAuthError& error) { |
328 OnStateChanged(); | 327 OnStateChanged(); |
329 } | 328 } |
(...skipping 14 matching lines...) Expand all Loading... |
344 bool is_classic_theme = !is_gtk_theme && theme_service->UsingDefaultTheme(); | 343 bool is_classic_theme = !is_gtk_theme && theme_service->UsingDefaultTheme(); |
345 FundamentalValue enabled(!is_classic_theme); | 344 FundamentalValue enabled(!is_classic_theme); |
346 web_ui_->CallJavascriptFunction( | 345 web_ui_->CallJavascriptFunction( |
347 "options.PersonalOptions.setThemesResetButtonEnabled", enabled); | 346 "options.PersonalOptions.setThemesResetButtonEnabled", enabled); |
348 } | 347 } |
349 | 348 |
350 void PersonalOptionsHandler::Initialize() { | 349 void PersonalOptionsHandler::Initialize() { |
351 // Listen for theme installation. | 350 // Listen for theme installation. |
352 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 351 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
353 NotificationService::AllSources()); | 352 NotificationService::AllSources()); |
| 353 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
| 354 NotificationService::AllSources()); |
354 ObserveThemeChanged(); | 355 ObserveThemeChanged(); |
355 | 356 |
356 ProfileSyncService* sync_service = | 357 ProfileSyncService* sync_service = |
357 web_ui_->GetProfile()->GetProfileSyncService(); | 358 web_ui_->GetProfile()->GetProfileSyncService(); |
358 if (sync_service) { | 359 if (sync_service) { |
359 sync_service->AddObserver(this); | 360 sync_service->AddObserver(this); |
360 OnStateChanged(); | 361 OnStateChanged(); |
361 | 362 |
362 DictionaryValue args; | 363 DictionaryValue args; |
363 SyncSetupFlow::GetArgsForConfigure(sync_service, &args); | 364 SyncSetupFlow::GetArgsForConfigure(sync_service, &args); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 timestamp)); | 398 timestamp)); |
398 web_ui_->CallJavascriptFunction("PersonalOptions.setAccountPicture", | 399 web_ui_->CallJavascriptFunction("PersonalOptions.setAccountPicture", |
399 image_url); | 400 image_url); |
400 | 401 |
401 StringValue email_value(email); | 402 StringValue email_value(email); |
402 web_ui_->CallJavascriptFunction("AccountsOptions.updateAccountPicture", | 403 web_ui_->CallJavascriptFunction("AccountsOptions.updateAccountPicture", |
403 email_value, image_url); | 404 email_value, image_url); |
404 } | 405 } |
405 } | 406 } |
406 #endif | 407 #endif |
| 408 |
| 409 void PersonalOptionsHandler::SendProfilesInfo() { |
| 410 ProfileInfoCache& cache = |
| 411 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 412 ListValue profile_info_list; |
| 413 FilePath current_profile_path = web_ui_->GetProfile()->GetPath(); |
| 414 for (size_t i = 0, e = cache.GetNumberOfProfiles(); i < e; ++i) { |
| 415 DictionaryValue *profile_value = new DictionaryValue(); |
| 416 size_t icon_index = cache.GetAvatarIconIndexOfProfileAtIndex(i); |
| 417 FilePath profile_path = cache.GetPathOfProfileAtIndex(i); |
| 418 profile_value->SetString("name", cache.GetNameOfProfileAtIndex(i)); |
| 419 profile_value->SetString("iconURL", |
| 420 cache.GetDefaultAvatarIconUrl(icon_index)); |
| 421 profile_value->Set("filePath", |
| 422 base::CreateFilePathValue( |
| 423 profile_path)); |
| 424 profile_value->SetBoolean("isCurrentProfile", |
| 425 profile_path == current_profile_path); |
| 426 profile_info_list.Append(profile_value); |
| 427 } |
| 428 |
| 429 web_ui_->CallJavascriptFunction("PersonalOptions.setProfilesInfo", |
| 430 profile_info_list); |
| 431 } |
| 432 |
| 433 void PersonalOptionsHandler::CreateProfile(const ListValue* args) { |
| 434 ProfileManager::CreateMultiProfileAsync(); |
| 435 } |
| 436 |
OLD | NEW |