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" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "chrome/browser/sync/profile_sync_service.h" | 24 #include "chrome/browser/sync/profile_sync_service.h" |
25 #include "chrome/browser/sync/sync_setup_flow.h" | 25 #include "chrome/browser/sync/sync_setup_flow.h" |
26 #include "chrome/browser/sync/sync_ui_util.h" | 26 #include "chrome/browser/sync/sync_ui_util.h" |
27 #include "chrome/browser/themes/theme_service.h" | 27 #include "chrome/browser/themes/theme_service.h" |
28 #include "chrome/browser/themes/theme_service_factory.h" | 28 #include "chrome/browser/themes/theme_service_factory.h" |
29 #include "chrome/common/chrome_notification_types.h" | 29 #include "chrome/common/chrome_notification_types.h" |
30 #include "chrome/common/chrome_paths.h" | 30 #include "chrome/common/chrome_paths.h" |
31 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
32 #include "chrome/common/net/gaia/google_service_auth_error.h" | 32 #include "chrome/common/net/gaia/google_service_auth_error.h" |
33 #include "chrome/common/url_constants.h" | 33 #include "chrome/common/url_constants.h" |
| 34 #include "content/browser/tab_contents/tab_contents.h" |
34 #include "content/browser/user_metrics.h" | 35 #include "content/browser/user_metrics.h" |
35 #include "content/common/notification_service.h" | 36 #include "content/common/notification_service.h" |
36 #include "grit/chromium_strings.h" | 37 #include "grit/chromium_strings.h" |
37 #include "grit/generated_resources.h" | 38 #include "grit/generated_resources.h" |
38 #include "grit/locale_settings.h" | 39 #include "grit/locale_settings.h" |
39 #include "grit/theme_resources.h" | 40 #include "grit/theme_resources.h" |
40 #include "ui/base/l10n/l10n_util.h" | 41 #include "ui/base/l10n/l10n_util.h" |
41 | 42 |
42 #if defined(OS_CHROMEOS) | 43 #if defined(OS_CHROMEOS) |
43 #include "chrome/browser/chromeos/login/user_manager.h" | 44 #include "chrome/browser/chromeos/login/user_manager.h" |
(...skipping 10 matching lines...) Expand all Loading... |
54 multiprofile_ = ProfileManager::IsMultipleProfilesEnabled(); | 55 multiprofile_ = ProfileManager::IsMultipleProfilesEnabled(); |
55 #if defined(OS_CHROMEOS) | 56 #if defined(OS_CHROMEOS) |
56 registrar_.Add(this, | 57 registrar_.Add(this, |
57 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, | 58 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, |
58 NotificationService::AllSources()); | 59 NotificationService::AllSources()); |
59 #endif | 60 #endif |
60 } | 61 } |
61 | 62 |
62 PersonalOptionsHandler::~PersonalOptionsHandler() { | 63 PersonalOptionsHandler::~PersonalOptionsHandler() { |
63 ProfileSyncService* sync_service = | 64 ProfileSyncService* sync_service = |
64 web_ui_->GetProfile()->GetProfileSyncService(); | 65 Profile::FromWebUI(web_ui_)->GetProfileSyncService(); |
65 if (sync_service) | 66 if (sync_service) |
66 sync_service->RemoveObserver(this); | 67 sync_service->RemoveObserver(this); |
67 } | 68 } |
68 | 69 |
69 void PersonalOptionsHandler::GetLocalizedValues( | 70 void PersonalOptionsHandler::GetLocalizedValues( |
70 DictionaryValue* localized_strings) { | 71 DictionaryValue* localized_strings) { |
71 DCHECK(localized_strings); | 72 DCHECK(localized_strings); |
72 | 73 |
73 RegisterTitle(localized_strings, "personalPage", | 74 RegisterTitle(localized_strings, "personalPage", |
74 IDS_OPTIONS_CONTENT_TAB_LABEL); | 75 IDS_OPTIONS_CONTENT_TAB_LABEL); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 LoadAccountPicture(NULL); | 227 LoadAccountPicture(NULL); |
227 #endif | 228 #endif |
228 } else { | 229 } else { |
229 OptionsPageUIHandler::Observe(type, source, details); | 230 OptionsPageUIHandler::Observe(type, source, details); |
230 } | 231 } |
231 } | 232 } |
232 | 233 |
233 void PersonalOptionsHandler::OnStateChanged() { | 234 void PersonalOptionsHandler::OnStateChanged() { |
234 string16 status_label; | 235 string16 status_label; |
235 string16 link_label; | 236 string16 link_label; |
236 ProfileSyncService* service = web_ui_->GetProfile()->GetProfileSyncService(); | 237 ProfileSyncService* service = |
| 238 Profile::FromWebUI(web_ui_)->GetProfileSyncService(); |
237 DCHECK(service); | 239 DCHECK(service); |
238 bool managed = service->IsManaged(); | 240 bool managed = service->IsManaged(); |
239 bool sync_setup_completed = service->HasSyncSetupCompleted(); | 241 bool sync_setup_completed = service->HasSyncSetupCompleted(); |
240 bool status_has_error = sync_ui_util::GetStatusLabels( | 242 bool status_has_error = sync_ui_util::GetStatusLabels( |
241 service, &status_label, &link_label) == sync_ui_util::SYNC_ERROR; | 243 service, &status_label, &link_label) == sync_ui_util::SYNC_ERROR; |
242 browser_sync::SyncBackendHost::StatusSummary summary = | 244 browser_sync::SyncBackendHost::StatusSummary summary = |
243 service->QuerySyncStatusSummary(); | 245 service->QuerySyncStatusSummary(); |
244 | 246 |
245 // TODO(jhawkins): This is terribly hacky. Sync should pass us this state, but | 247 // TODO(jhawkins): This is terribly hacky. Sync should pass us this state, but |
246 // we have to fix the other callers of | 248 // we have to fix the other callers of |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 void PersonalOptionsHandler::OnLoginSuccess() { | 329 void PersonalOptionsHandler::OnLoginSuccess() { |
328 OnStateChanged(); | 330 OnStateChanged(); |
329 } | 331 } |
330 | 332 |
331 void PersonalOptionsHandler::OnLoginFailure( | 333 void PersonalOptionsHandler::OnLoginFailure( |
332 const GoogleServiceAuthError& error) { | 334 const GoogleServiceAuthError& error) { |
333 OnStateChanged(); | 335 OnStateChanged(); |
334 } | 336 } |
335 | 337 |
336 void PersonalOptionsHandler::ObserveThemeChanged() { | 338 void PersonalOptionsHandler::ObserveThemeChanged() { |
337 Profile* profile = web_ui_->GetProfile(); | 339 Profile* profile = Profile::FromWebUI(web_ui_); |
338 #if defined(TOOLKIT_GTK) | 340 #if defined(TOOLKIT_GTK) |
339 GtkThemeService* theme_service = GtkThemeService::GetFrom(profile); | 341 GtkThemeService* theme_service = GtkThemeService::GetFrom(profile); |
340 bool is_gtk_theme = theme_service->UsingNativeTheme(); | 342 bool is_gtk_theme = theme_service->UsingNativeTheme(); |
341 FundamentalValue gtk_enabled(!is_gtk_theme); | 343 FundamentalValue gtk_enabled(!is_gtk_theme); |
342 web_ui_->CallJavascriptFunction( | 344 web_ui_->CallJavascriptFunction( |
343 "options.PersonalOptions.setGtkThemeButtonEnabled", gtk_enabled); | 345 "options.PersonalOptions.setGtkThemeButtonEnabled", gtk_enabled); |
344 #else | 346 #else |
345 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile); | 347 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile); |
346 bool is_gtk_theme = false; | 348 bool is_gtk_theme = false; |
347 #endif | 349 #endif |
348 | 350 |
349 bool is_classic_theme = !is_gtk_theme && theme_service->UsingDefaultTheme(); | 351 bool is_classic_theme = !is_gtk_theme && theme_service->UsingDefaultTheme(); |
350 FundamentalValue enabled(!is_classic_theme); | 352 FundamentalValue enabled(!is_classic_theme); |
351 web_ui_->CallJavascriptFunction( | 353 web_ui_->CallJavascriptFunction( |
352 "options.PersonalOptions.setThemesResetButtonEnabled", enabled); | 354 "options.PersonalOptions.setThemesResetButtonEnabled", enabled); |
353 } | 355 } |
354 | 356 |
355 void PersonalOptionsHandler::Initialize() { | 357 void PersonalOptionsHandler::Initialize() { |
| 358 Profile* profile = Profile::FromWebUI(web_ui_); |
| 359 |
356 // Listen for theme installation. | 360 // Listen for theme installation. |
357 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 361 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
358 Source<ThemeService>(ThemeServiceFactory::GetForProfile( | 362 Source<ThemeService>(ThemeServiceFactory::GetForProfile( |
359 web_ui_->GetProfile()))); | 363 profile))); |
360 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, | 364 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
361 NotificationService::AllSources()); | 365 NotificationService::AllSources()); |
362 ObserveThemeChanged(); | 366 ObserveThemeChanged(); |
363 | 367 |
364 ProfileSyncService* sync_service = | 368 ProfileSyncService* sync_service = profile->GetProfileSyncService(); |
365 web_ui_->GetProfile()->GetProfileSyncService(); | |
366 if (sync_service) { | 369 if (sync_service) { |
367 sync_service->AddObserver(this); | 370 sync_service->AddObserver(this); |
368 OnStateChanged(); | 371 OnStateChanged(); |
369 } else { | 372 } else { |
370 web_ui_->CallJavascriptFunction("options.PersonalOptions.hideSyncSection"); | 373 web_ui_->CallJavascriptFunction("options.PersonalOptions.hideSyncSection"); |
371 } | 374 } |
372 } | 375 } |
373 | 376 |
374 void PersonalOptionsHandler::ThemesReset(const ListValue* args) { | 377 void PersonalOptionsHandler::ThemesReset(const ListValue* args) { |
375 UserMetrics::RecordAction(UserMetricsAction("Options_ThemesReset")); | 378 UserMetrics::RecordAction(UserMetricsAction("Options_ThemesReset")); |
376 ThemeServiceFactory::GetForProfile(web_ui_->GetProfile())->UseDefaultTheme(); | 379 Profile* profile = Profile::FromWebUI(web_ui_); |
| 380 ThemeServiceFactory::GetForProfile(profile)->UseDefaultTheme(); |
377 } | 381 } |
378 | 382 |
379 #if defined(TOOLKIT_GTK) | 383 #if defined(TOOLKIT_GTK) |
380 void PersonalOptionsHandler::ThemesSetGTK(const ListValue* args) { | 384 void PersonalOptionsHandler::ThemesSetGTK(const ListValue* args) { |
381 UserMetrics::RecordAction(UserMetricsAction("Options_GtkThemeSet")); | 385 UserMetrics::RecordAction(UserMetricsAction("Options_GtkThemeSet")); |
382 ThemeServiceFactory::GetForProfile(web_ui_->GetProfile())->SetNativeTheme(); | 386 Profile* profile = Profile::FromWebUI(web_ui_); |
| 387 ThemeServiceFactory::GetForProfile(profile)->SetNativeTheme(); |
383 } | 388 } |
384 #endif | 389 #endif |
385 | 390 |
386 #if defined(OS_CHROMEOS) | 391 #if defined(OS_CHROMEOS) |
387 void PersonalOptionsHandler::LoadAccountPicture(const ListValue* args) { | 392 void PersonalOptionsHandler::LoadAccountPicture(const ListValue* args) { |
388 const chromeos::UserManager::User& user = | 393 const chromeos::UserManager::User& user = |
389 chromeos::UserManager::Get()->logged_in_user(); | 394 chromeos::UserManager::Get()->logged_in_user(); |
390 std::string email = user.email(); | 395 std::string email = user.email(); |
391 if (!email.empty()) { | 396 if (!email.empty()) { |
392 // int64 is either long or long long, but we need a certain format | 397 // int64 is either long or long long, but we need a certain format |
(...skipping 11 matching lines...) Expand all Loading... |
404 web_ui_->CallJavascriptFunction("AccountsOptions.updateAccountPicture", | 409 web_ui_->CallJavascriptFunction("AccountsOptions.updateAccountPicture", |
405 email_value, image_url); | 410 email_value, image_url); |
406 } | 411 } |
407 } | 412 } |
408 #endif | 413 #endif |
409 | 414 |
410 void PersonalOptionsHandler::SendProfilesInfo() { | 415 void PersonalOptionsHandler::SendProfilesInfo() { |
411 ProfileInfoCache& cache = | 416 ProfileInfoCache& cache = |
412 g_browser_process->profile_manager()->GetProfileInfoCache(); | 417 g_browser_process->profile_manager()->GetProfileInfoCache(); |
413 ListValue profile_info_list; | 418 ListValue profile_info_list; |
414 FilePath current_profile_path = web_ui_->GetProfile()->GetPath(); | 419 FilePath current_profile_path = |
| 420 web_ui_->tab_contents()->browser_context()->GetPath(); |
415 for (size_t i = 0, e = cache.GetNumberOfProfiles(); i < e; ++i) { | 421 for (size_t i = 0, e = cache.GetNumberOfProfiles(); i < e; ++i) { |
416 DictionaryValue *profile_value = new DictionaryValue(); | 422 DictionaryValue *profile_value = new DictionaryValue(); |
417 size_t icon_index = cache.GetAvatarIconIndexOfProfileAtIndex(i); | 423 size_t icon_index = cache.GetAvatarIconIndexOfProfileAtIndex(i); |
418 FilePath profile_path = cache.GetPathOfProfileAtIndex(i); | 424 FilePath profile_path = cache.GetPathOfProfileAtIndex(i); |
419 profile_value->SetString("name", cache.GetNameOfProfileAtIndex(i)); | 425 profile_value->SetString("name", cache.GetNameOfProfileAtIndex(i)); |
420 profile_value->SetString("iconURL", | 426 profile_value->SetString("iconURL", |
421 cache.GetDefaultAvatarIconUrl(icon_index)); | 427 cache.GetDefaultAvatarIconUrl(icon_index)); |
422 profile_value->Set("filePath", | 428 profile_value->Set("filePath", |
423 base::CreateFilePathValue( | 429 base::CreateFilePathValue( |
424 profile_path)); | 430 profile_path)); |
425 profile_value->SetBoolean("isCurrentProfile", | 431 profile_value->SetBoolean("isCurrentProfile", |
426 profile_path == current_profile_path); | 432 profile_path == current_profile_path); |
427 profile_info_list.Append(profile_value); | 433 profile_info_list.Append(profile_value); |
428 } | 434 } |
429 | 435 |
430 web_ui_->CallJavascriptFunction("PersonalOptions.setProfilesInfo", | 436 web_ui_->CallJavascriptFunction("PersonalOptions.setProfilesInfo", |
431 profile_info_list); | 437 profile_info_list); |
432 } | 438 } |
433 | 439 |
434 void PersonalOptionsHandler::CreateProfile(const ListValue* args) { | 440 void PersonalOptionsHandler::CreateProfile(const ListValue* args) { |
435 ProfileManager::CreateMultiProfileAsync(); | 441 ProfileManager::CreateMultiProfileAsync(); |
436 } | 442 } |
437 | 443 |
OLD | NEW |