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" |
44 #include "chrome/browser/chromeos/options/take_photo_dialog.h" | 45 #include "chrome/browser/chromeos/options/take_photo_dialog.h" |
45 #include "chrome/browser/ui/browser_window.h" | 46 #include "chrome/browser/ui/browser_window.h" |
46 #include "chrome/browser/ui/views/window.h" | 47 #include "chrome/browser/ui/views/window.h" |
47 #include "third_party/skia/include/core/SkBitmap.h" | 48 #include "third_party/skia/include/core/SkBitmap.h" |
48 #endif // defined(OS_CHROMEOS) | 49 #endif // defined(OS_CHROMEOS) |
49 #if defined(TOOLKIT_GTK) | 50 #if defined(TOOLKIT_GTK) |
50 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 51 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
51 #endif // defined(TOOLKIT_GTK) | 52 #endif // defined(TOOLKIT_GTK) |
52 | 53 |
53 PersonalOptionsHandler::PersonalOptionsHandler() { | 54 PersonalOptionsHandler::PersonalOptionsHandler() { |
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 Profile* profile = |
64 web_ui_->GetProfile()->GetProfileSyncService(); | 65 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
| 66 ProfileSyncService* sync_service = profile->GetProfileSyncService(); |
65 if (sync_service) | 67 if (sync_service) |
66 sync_service->RemoveObserver(this); | 68 sync_service->RemoveObserver(this); |
67 } | 69 } |
68 | 70 |
69 void PersonalOptionsHandler::GetLocalizedValues( | 71 void PersonalOptionsHandler::GetLocalizedValues( |
70 DictionaryValue* localized_strings) { | 72 DictionaryValue* localized_strings) { |
71 DCHECK(localized_strings); | 73 DCHECK(localized_strings); |
72 | 74 |
73 RegisterTitle(localized_strings, "personalPage", | 75 RegisterTitle(localized_strings, "personalPage", |
74 IDS_OPTIONS_CONTENT_TAB_LABEL); | 76 IDS_OPTIONS_CONTENT_TAB_LABEL); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 LoadAccountPicture(NULL); | 228 LoadAccountPicture(NULL); |
227 #endif | 229 #endif |
228 } else { | 230 } else { |
229 OptionsPageUIHandler::Observe(type, source, details); | 231 OptionsPageUIHandler::Observe(type, source, details); |
230 } | 232 } |
231 } | 233 } |
232 | 234 |
233 void PersonalOptionsHandler::OnStateChanged() { | 235 void PersonalOptionsHandler::OnStateChanged() { |
234 string16 status_label; | 236 string16 status_label; |
235 string16 link_label; | 237 string16 link_label; |
236 ProfileSyncService* service = web_ui_->GetProfile()->GetProfileSyncService(); | 238 Profile* profile = |
| 239 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
| 240 ProfileSyncService* service = profile->GetProfileSyncService(); |
237 DCHECK(service); | 241 DCHECK(service); |
238 bool managed = service->IsManaged(); | 242 bool managed = service->IsManaged(); |
239 bool sync_setup_completed = service->HasSyncSetupCompleted(); | 243 bool sync_setup_completed = service->HasSyncSetupCompleted(); |
240 bool status_has_error = sync_ui_util::GetStatusLabels( | 244 bool status_has_error = sync_ui_util::GetStatusLabels( |
241 service, &status_label, &link_label) == sync_ui_util::SYNC_ERROR; | 245 service, &status_label, &link_label) == sync_ui_util::SYNC_ERROR; |
242 browser_sync::SyncBackendHost::StatusSummary summary = | 246 browser_sync::SyncBackendHost::StatusSummary summary = |
243 service->QuerySyncStatusSummary(); | 247 service->QuerySyncStatusSummary(); |
244 | 248 |
245 // TODO(jhawkins): This is terribly hacky. Sync should pass us this state, but | 249 // TODO(jhawkins): This is terribly hacky. Sync should pass us this state, but |
246 // we have to fix the other callers of | 250 // 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() { | 331 void PersonalOptionsHandler::OnLoginSuccess() { |
328 OnStateChanged(); | 332 OnStateChanged(); |
329 } | 333 } |
330 | 334 |
331 void PersonalOptionsHandler::OnLoginFailure( | 335 void PersonalOptionsHandler::OnLoginFailure( |
332 const GoogleServiceAuthError& error) { | 336 const GoogleServiceAuthError& error) { |
333 OnStateChanged(); | 337 OnStateChanged(); |
334 } | 338 } |
335 | 339 |
336 void PersonalOptionsHandler::ObserveThemeChanged() { | 340 void PersonalOptionsHandler::ObserveThemeChanged() { |
337 Profile* profile = web_ui_->GetProfile(); | 341 Profile* profile = |
| 342 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
338 #if defined(TOOLKIT_GTK) | 343 #if defined(TOOLKIT_GTK) |
339 GtkThemeService* theme_service = GtkThemeService::GetFrom(profile); | 344 GtkThemeService* theme_service = GtkThemeService::GetFrom(profile); |
340 bool is_gtk_theme = theme_service->UsingNativeTheme(); | 345 bool is_gtk_theme = theme_service->UsingNativeTheme(); |
341 FundamentalValue gtk_enabled(!is_gtk_theme); | 346 FundamentalValue gtk_enabled(!is_gtk_theme); |
342 web_ui_->CallJavascriptFunction( | 347 web_ui_->CallJavascriptFunction( |
343 "options.PersonalOptions.setGtkThemeButtonEnabled", gtk_enabled); | 348 "options.PersonalOptions.setGtkThemeButtonEnabled", gtk_enabled); |
344 #else | 349 #else |
345 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile); | 350 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile); |
346 bool is_gtk_theme = false; | 351 bool is_gtk_theme = false; |
347 #endif | 352 #endif |
348 | 353 |
349 bool is_classic_theme = !is_gtk_theme && theme_service->UsingDefaultTheme(); | 354 bool is_classic_theme = !is_gtk_theme && theme_service->UsingDefaultTheme(); |
350 FundamentalValue enabled(!is_classic_theme); | 355 FundamentalValue enabled(!is_classic_theme); |
351 web_ui_->CallJavascriptFunction( | 356 web_ui_->CallJavascriptFunction( |
352 "options.PersonalOptions.setThemesResetButtonEnabled", enabled); | 357 "options.PersonalOptions.setThemesResetButtonEnabled", enabled); |
353 } | 358 } |
354 | 359 |
355 void PersonalOptionsHandler::Initialize() { | 360 void PersonalOptionsHandler::Initialize() { |
| 361 Profile* profile = |
| 362 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
| 363 |
356 // Listen for theme installation. | 364 // Listen for theme installation. |
357 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 365 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
358 Source<ThemeService>(ThemeServiceFactory::GetForProfile( | 366 Source<ThemeService>(ThemeServiceFactory::GetForProfile( |
359 web_ui_->GetProfile()))); | 367 profile))); |
360 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, | 368 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
361 NotificationService::AllSources()); | 369 NotificationService::AllSources()); |
362 ObserveThemeChanged(); | 370 ObserveThemeChanged(); |
363 | 371 |
364 ProfileSyncService* sync_service = | 372 ProfileSyncService* sync_service = profile->GetProfileSyncService(); |
365 web_ui_->GetProfile()->GetProfileSyncService(); | |
366 if (sync_service) { | 373 if (sync_service) { |
367 sync_service->AddObserver(this); | 374 sync_service->AddObserver(this); |
368 OnStateChanged(); | 375 OnStateChanged(); |
369 } else { | 376 } else { |
370 web_ui_->CallJavascriptFunction("options.PersonalOptions.hideSyncSection"); | 377 web_ui_->CallJavascriptFunction("options.PersonalOptions.hideSyncSection"); |
371 } | 378 } |
372 } | 379 } |
373 | 380 |
374 void PersonalOptionsHandler::ThemesReset(const ListValue* args) { | 381 void PersonalOptionsHandler::ThemesReset(const ListValue* args) { |
375 UserMetrics::RecordAction(UserMetricsAction("Options_ThemesReset")); | 382 UserMetrics::RecordAction(UserMetricsAction("Options_ThemesReset")); |
| 383 Profile* profile = |
| 384 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
376 ThemeServiceFactory::GetForProfile(web_ui_->GetProfile())->UseDefaultTheme(); | 385 ThemeServiceFactory::GetForProfile(web_ui_->GetProfile())->UseDefaultTheme(); |
377 } | 386 } |
378 | 387 |
379 #if defined(TOOLKIT_GTK) | 388 #if defined(TOOLKIT_GTK) |
380 void PersonalOptionsHandler::ThemesSetGTK(const ListValue* args) { | 389 void PersonalOptionsHandler::ThemesSetGTK(const ListValue* args) { |
381 UserMetrics::RecordAction(UserMetricsAction("Options_GtkThemeSet")); | 390 UserMetrics::RecordAction(UserMetricsAction("Options_GtkThemeSet")); |
| 391 Profile* profile = |
| 392 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
382 ThemeServiceFactory::GetForProfile(web_ui_->GetProfile())->SetNativeTheme(); | 393 ThemeServiceFactory::GetForProfile(web_ui_->GetProfile())->SetNativeTheme(); |
383 } | 394 } |
384 #endif | 395 #endif |
385 | 396 |
386 #if defined(OS_CHROMEOS) | 397 #if defined(OS_CHROMEOS) |
387 void PersonalOptionsHandler::LoadAccountPicture(const ListValue* args) { | 398 void PersonalOptionsHandler::LoadAccountPicture(const ListValue* args) { |
388 const chromeos::UserManager::User& user = | 399 const chromeos::UserManager::User& user = |
389 chromeos::UserManager::Get()->logged_in_user(); | 400 chromeos::UserManager::Get()->logged_in_user(); |
390 std::string email = user.email(); | 401 std::string email = user.email(); |
391 if (!email.empty()) { | 402 if (!email.empty()) { |
(...skipping 12 matching lines...) Expand all Loading... |
404 web_ui_->CallJavascriptFunction("AccountsOptions.updateAccountPicture", | 415 web_ui_->CallJavascriptFunction("AccountsOptions.updateAccountPicture", |
405 email_value, image_url); | 416 email_value, image_url); |
406 } | 417 } |
407 } | 418 } |
408 #endif | 419 #endif |
409 | 420 |
410 void PersonalOptionsHandler::SendProfilesInfo() { | 421 void PersonalOptionsHandler::SendProfilesInfo() { |
411 ProfileInfoCache& cache = | 422 ProfileInfoCache& cache = |
412 g_browser_process->profile_manager()->GetProfileInfoCache(); | 423 g_browser_process->profile_manager()->GetProfileInfoCache(); |
413 ListValue profile_info_list; | 424 ListValue profile_info_list; |
414 FilePath current_profile_path = web_ui_->GetProfile()->GetPath(); | 425 FilePath current_profile_path = |
| 426 web_ui_->tab_contents()->browser_context()->GetPath(); |
415 for (size_t i = 0, e = cache.GetNumberOfProfiles(); i < e; ++i) { | 427 for (size_t i = 0, e = cache.GetNumberOfProfiles(); i < e; ++i) { |
416 DictionaryValue *profile_value = new DictionaryValue(); | 428 DictionaryValue *profile_value = new DictionaryValue(); |
417 size_t icon_index = cache.GetAvatarIconIndexOfProfileAtIndex(i); | 429 size_t icon_index = cache.GetAvatarIconIndexOfProfileAtIndex(i); |
418 FilePath profile_path = cache.GetPathOfProfileAtIndex(i); | 430 FilePath profile_path = cache.GetPathOfProfileAtIndex(i); |
419 profile_value->SetString("name", cache.GetNameOfProfileAtIndex(i)); | 431 profile_value->SetString("name", cache.GetNameOfProfileAtIndex(i)); |
420 profile_value->SetString("iconURL", | 432 profile_value->SetString("iconURL", |
421 cache.GetDefaultAvatarIconUrl(icon_index)); | 433 cache.GetDefaultAvatarIconUrl(icon_index)); |
422 profile_value->Set("filePath", | 434 profile_value->Set("filePath", |
423 base::CreateFilePathValue( | 435 base::CreateFilePathValue( |
424 profile_path)); | 436 profile_path)); |
425 profile_value->SetBoolean("isCurrentProfile", | 437 profile_value->SetBoolean("isCurrentProfile", |
426 profile_path == current_profile_path); | 438 profile_path == current_profile_path); |
427 profile_info_list.Append(profile_value); | 439 profile_info_list.Append(profile_value); |
428 } | 440 } |
429 | 441 |
430 web_ui_->CallJavascriptFunction("PersonalOptions.setProfilesInfo", | 442 web_ui_->CallJavascriptFunction("PersonalOptions.setProfilesInfo", |
431 profile_info_list); | 443 profile_info_list); |
432 } | 444 } |
433 | 445 |
434 void PersonalOptionsHandler::CreateProfile(const ListValue* args) { | 446 void PersonalOptionsHandler::CreateProfile(const ListValue* args) { |
435 ProfileManager::CreateMultiProfileAsync(); | 447 ProfileManager::CreateMultiProfileAsync(); |
436 } | 448 } |
437 | 449 |
OLD | NEW |