| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/options2/browser_options_handler2.h" | 5 #include "chrome/browser/ui/webui/options2/browser_options_handler2.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); | 357 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); |
| 358 | 358 |
| 359 #if defined(OS_CHROMEOS) | 359 #if defined(OS_CHROMEOS) |
| 360 if (chromeos::UserManager::Get()->IsUserLoggedIn()) { | 360 if (chromeos::UserManager::Get()->IsUserLoggedIn()) { |
| 361 values->SetString("username", | 361 values->SetString("username", |
| 362 chromeos::UserManager::Get()->GetLoggedInUser().email()); | 362 chromeos::UserManager::Get()->GetLoggedInUser().email()); |
| 363 } | 363 } |
| 364 #endif | 364 #endif |
| 365 | 365 |
| 366 // Pass along sync status early so it will be available during page init. | 366 // Pass along sync status early so it will be available during page init. |
| 367 values->Set("syncData", GetSyncStateDictionary()); | 367 values->Set("syncData", GetSyncStateDictionary().release()); |
| 368 | 368 |
| 369 values->SetString("privacyLearnMoreURL", chrome::kPrivacyLearnMoreURL); | 369 values->SetString("privacyLearnMoreURL", chrome::kPrivacyLearnMoreURL); |
| 370 | 370 |
| 371 values->SetString( | 371 values->SetString( |
| 372 "languageSectionLabel", | 372 "languageSectionLabel", |
| 373 l10n_util::GetStringFUTF16( | 373 l10n_util::GetStringFUTF16( |
| 374 IDS_OPTIONS_ADVANCED_LANGUAGE_LABEL, | 374 IDS_OPTIONS_ADVANCED_LANGUAGE_LABEL, |
| 375 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); | 375 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); |
| 376 | 376 |
| 377 #if defined(OS_CHROMEOS) | 377 #if defined(OS_CHROMEOS) |
| 378 values->SetString("cloudPrintLearnMoreURL", chrome::kCloudPrintLearnMoreURL); | 378 values->SetString("cloudPrintLearnMoreURL", chrome::kCloudPrintLearnMoreURL); |
| 379 | 379 |
| 380 // TODO(pastarmovj): replace this with a call to the CrosSettings list | 380 // TODO(pastarmovj): replace this with a call to the CrosSettings list |
| 381 // handling functionality to come. | 381 // handling functionality to come. |
| 382 values->Set("timezoneList", | 382 values->Set("timezoneList", |
| 383 static_cast<chromeos::options2::SystemSettingsProvider*>( | 383 static_cast<chromeos::options2::SystemSettingsProvider*>( |
| 384 chromeos::CrosSettings::Get()->GetProvider( | 384 chromeos::CrosSettings::Get()->GetProvider( |
| 385 chromeos::kSystemTimezone))->GetTimezoneList()); | 385 chromeos::kSystemTimezone))->GetTimezoneList()); |
| 386 #endif | 386 #endif |
| 387 #if defined(OS_MACOSX) | 387 #if defined(OS_MACOSX) |
| 388 values->SetString("macPasswordsWarning", | 388 values->SetString("macPasswordsWarning", |
| 389 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MAC_WARNING)); | 389 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MAC_WARNING)); |
| 390 values->SetBoolean("multiple_profiles", | 390 values->SetBoolean("multiple_profiles", |
| 391 g_browser_process->profile_manager()->GetNumberOfProfiles() > 1); | 391 g_browser_process->profile_manager()->GetNumberOfProfiles() > 1); |
| 392 #endif | 392 #endif |
| 393 |
| 394 if (multiprofile_) |
| 395 values->Set("profilesInfo", GetProfilesInfoList().release()); |
| 393 } | 396 } |
| 394 | 397 |
| 395 void BrowserOptionsHandler::RegisterCloudPrintValues(DictionaryValue* values) { | 398 void BrowserOptionsHandler::RegisterCloudPrintValues(DictionaryValue* values) { |
| 396 #if defined(OS_CHROMEOS) | 399 #if defined(OS_CHROMEOS) |
| 397 values->SetString("cloudPrintChromeosOptionLabel", | 400 values->SetString("cloudPrintChromeosOptionLabel", |
| 398 l10n_util::GetStringFUTF16( | 401 l10n_util::GetStringFUTF16( |
| 399 IDS_CLOUD_PRINT_CHROMEOS_OPTION_LABEL, | 402 IDS_CLOUD_PRINT_CHROMEOS_OPTION_LABEL, |
| 400 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT))); | 403 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT))); |
| 401 values->SetString("cloudPrintChromeosOptionButton", | 404 values->SetString("cloudPrintChromeosOptionButton", |
| 402 l10n_util::GetStringFUTF16( | 405 l10n_util::GetStringFUTF16( |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 base::Bind(&BrowserOptionsHandler::ScreenMagnifierChangeCallback, | 526 base::Bind(&BrowserOptionsHandler::ScreenMagnifierChangeCallback, |
| 524 base::Unretained(this))); | 527 base::Unretained(this))); |
| 525 web_ui()->RegisterMessageCallback( | 528 web_ui()->RegisterMessageCallback( |
| 526 "virtualKeyboardChange", | 529 "virtualKeyboardChange", |
| 527 base::Bind(&BrowserOptionsHandler::VirtualKeyboardChangeCallback, | 530 base::Bind(&BrowserOptionsHandler::VirtualKeyboardChangeCallback, |
| 528 base::Unretained(this))); | 531 base::Unretained(this))); |
| 529 #endif | 532 #endif |
| 530 } | 533 } |
| 531 | 534 |
| 532 void BrowserOptionsHandler::OnStateChanged() { | 535 void BrowserOptionsHandler::OnStateChanged() { |
| 533 scoped_ptr<DictionaryValue> value(GetSyncStateDictionary()); | 536 web_ui()->CallJavascriptFunction("BrowserOptions.updateSyncState", |
| 534 web_ui()->CallJavascriptFunction("BrowserOptions.updateSyncState", *value); | 537 *GetSyncStateDictionary()); |
| 535 | 538 |
| 536 SendProfilesInfo(); | 539 SendProfilesInfo(); |
| 537 } | 540 } |
| 538 | 541 |
| 539 void BrowserOptionsHandler::InitializeHandler() { | 542 void BrowserOptionsHandler::InitializeHandler() { |
| 540 Profile* profile = Profile::FromWebUI(web_ui()); | 543 Profile* profile = Profile::FromWebUI(web_ui()); |
| 541 PrefService* prefs = profile->GetPrefs(); | 544 PrefService* prefs = profile->GetPrefs(); |
| 542 | 545 |
| 543 ProfileSyncService* sync_service( | 546 ProfileSyncService* sync_service( |
| 544 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile)); | 547 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile)); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 #if !defined(OS_CHROMEOS) | 605 #if !defined(OS_CHROMEOS) |
| 603 proxy_prefs_.reset( | 606 proxy_prefs_.reset( |
| 604 PrefSetObserver::CreateProxyPrefSetObserver(prefs, this)); | 607 PrefSetObserver::CreateProxyPrefSetObserver(prefs, this)); |
| 605 #endif // !defined(OS_CHROMEOS) | 608 #endif // !defined(OS_CHROMEOS) |
| 606 } | 609 } |
| 607 | 610 |
| 608 void BrowserOptionsHandler::InitializePage() { | 611 void BrowserOptionsHandler::InitializePage() { |
| 609 OnTemplateURLServiceChanged(); | 612 OnTemplateURLServiceChanged(); |
| 610 ObserveThemeChanged(); | 613 ObserveThemeChanged(); |
| 611 | 614 |
| 612 if (multiprofile_) | |
| 613 SendProfilesInfo(); | |
| 614 | |
| 615 SetupMetricsReportingCheckbox(); | 615 SetupMetricsReportingCheckbox(); |
| 616 SetupMetricsReportingSettingVisibility(); | 616 SetupMetricsReportingSettingVisibility(); |
| 617 SetupFontSizeSelector(); | 617 SetupFontSizeSelector(); |
| 618 SetupPageZoomSelector(); | 618 SetupPageZoomSelector(); |
| 619 SetupAutoOpenFileTypes(); | 619 SetupAutoOpenFileTypes(); |
| 620 SetupProxySettingsSection(); | 620 SetupProxySettingsSection(); |
| 621 SetupSSLConfigSettings(); | 621 SetupSSLConfigSettings(); |
| 622 #if !defined(OS_CHROMEOS) | 622 #if !defined(OS_CHROMEOS) |
| 623 if (cloud_print_connector_ui_enabled_) { | 623 if (cloud_print_connector_ui_enabled_) { |
| 624 SetupCloudPrintConnectorSection(); | 624 SetupCloudPrintConnectorSection(); |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 896 | 896 |
| 897 void BrowserOptionsHandler::GetInstantFieldTrialStatus(const ListValue* args) { | 897 void BrowserOptionsHandler::GetInstantFieldTrialStatus(const ListValue* args) { |
| 898 Profile* profile = Profile::FromWebUI(web_ui()); | 898 Profile* profile = Profile::FromWebUI(web_ui()); |
| 899 base::FundamentalValue enabled( | 899 base::FundamentalValue enabled( |
| 900 InstantFieldTrial::IsInstantExperiment(profile) && | 900 InstantFieldTrial::IsInstantExperiment(profile) && |
| 901 !InstantFieldTrial::IsHiddenExperiment(profile)); | 901 !InstantFieldTrial::IsHiddenExperiment(profile)); |
| 902 web_ui()->CallJavascriptFunction("BrowserOptions.setInstantFieldTrialStatus", | 902 web_ui()->CallJavascriptFunction("BrowserOptions.setInstantFieldTrialStatus", |
| 903 enabled); | 903 enabled); |
| 904 } | 904 } |
| 905 | 905 |
| 906 void BrowserOptionsHandler::SendProfilesInfo() { | 906 scoped_ptr<ListValue> BrowserOptionsHandler::GetProfilesInfoList() { |
| 907 // Set profile creation text and button if multi-profiles switch is on. | |
| 908 scoped_ptr<Value> visible(Value::CreateBooleanValue(multiprofile_)); | |
| 909 web_ui()->CallJavascriptFunction("BrowserOptions.setProfilesSectionVisible", | |
| 910 *visible); | |
| 911 | |
| 912 if (!multiprofile_) | |
| 913 return; | |
| 914 | |
| 915 ProfileInfoCache& cache = | 907 ProfileInfoCache& cache = |
| 916 g_browser_process->profile_manager()->GetProfileInfoCache(); | 908 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 917 ListValue profile_info_list; | 909 scoped_ptr<ListValue> profile_info_list(new ListValue); |
| 918 FilePath current_profile_path = | 910 FilePath current_profile_path = |
| 919 web_ui()->GetWebContents()->GetBrowserContext()->GetPath(); | 911 web_ui()->GetWebContents()->GetBrowserContext()->GetPath(); |
| 912 |
| 920 for (size_t i = 0, e = cache.GetNumberOfProfiles(); i < e; ++i) { | 913 for (size_t i = 0, e = cache.GetNumberOfProfiles(); i < e; ++i) { |
| 921 DictionaryValue* profile_value = new DictionaryValue(); | 914 DictionaryValue* profile_value = new DictionaryValue(); |
| 922 FilePath profile_path = cache.GetPathOfProfileAtIndex(i); | 915 FilePath profile_path = cache.GetPathOfProfileAtIndex(i); |
| 923 profile_value->SetString("name", cache.GetNameOfProfileAtIndex(i)); | 916 profile_value->SetString("name", cache.GetNameOfProfileAtIndex(i)); |
| 924 profile_value->Set("filePath", base::CreateFilePathValue(profile_path)); | 917 profile_value->Set("filePath", base::CreateFilePathValue(profile_path)); |
| 925 profile_value->SetBoolean("isCurrentProfile", | 918 profile_value->SetBoolean("isCurrentProfile", |
| 926 profile_path == current_profile_path); | 919 profile_path == current_profile_path); |
| 927 | 920 |
| 928 bool is_gaia_picture = | 921 bool is_gaia_picture = |
| 929 cache.IsUsingGAIAPictureOfProfileAtIndex(i) && | 922 cache.IsUsingGAIAPictureOfProfileAtIndex(i) && |
| 930 cache.GetGAIAPictureOfProfileAtIndex(i); | 923 cache.GetGAIAPictureOfProfileAtIndex(i); |
| 931 if (is_gaia_picture) { | 924 if (is_gaia_picture) { |
| 932 gfx::Image icon = profiles::GetAvatarIconForWebUI( | 925 gfx::Image icon = profiles::GetAvatarIconForWebUI( |
| 933 cache.GetAvatarIconOfProfileAtIndex(i), true); | 926 cache.GetAvatarIconOfProfileAtIndex(i), true); |
| 934 profile_value->SetString("iconURL", | 927 profile_value->SetString("iconURL", |
| 935 web_ui_util::GetImageDataUrl(*icon.ToSkBitmap())); | 928 web_ui_util::GetImageDataUrl(*icon.ToSkBitmap())); |
| 936 } else { | 929 } else { |
| 937 size_t icon_index = cache.GetAvatarIconIndexOfProfileAtIndex(i); | 930 size_t icon_index = cache.GetAvatarIconIndexOfProfileAtIndex(i); |
| 938 profile_value->SetString("iconURL", | 931 profile_value->SetString("iconURL", |
| 939 cache.GetDefaultAvatarIconUrl(icon_index)); | 932 cache.GetDefaultAvatarIconUrl(icon_index)); |
| 940 } | 933 } |
| 941 | 934 |
| 942 profile_info_list.Append(profile_value); | 935 profile_info_list->Append(profile_value); |
| 943 } | 936 } |
| 944 | 937 |
| 938 return profile_info_list.Pass(); |
| 939 } |
| 940 |
| 941 void BrowserOptionsHandler::SendProfilesInfo() { |
| 945 web_ui()->CallJavascriptFunction("BrowserOptions.setProfilesInfo", | 942 web_ui()->CallJavascriptFunction("BrowserOptions.setProfilesInfo", |
| 946 profile_info_list); | 943 *GetProfilesInfoList()); |
| 947 } | 944 } |
| 948 | 945 |
| 949 void BrowserOptionsHandler::CreateProfile(const ListValue* args) { | 946 void BrowserOptionsHandler::CreateProfile(const ListValue* args) { |
| 950 // This handler could have been called in managed mode, for example because | 947 // This handler could have been called in managed mode, for example because |
| 951 // the user fiddled with the web inspector. Silently return in this case. | 948 // the user fiddled with the web inspector. Silently return in this case. |
| 952 if (!ProfileManager::IsMultipleProfilesEnabled()) | 949 if (!ProfileManager::IsMultipleProfilesEnabled()) |
| 953 return; | 950 return; |
| 954 ProfileManager::CreateMultiProfileAsync(); | 951 ProfileManager::CreateMultiProfileAsync(); |
| 955 } | 952 } |
| 956 | 953 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 std::string email = chromeos::UserManager::Get()->GetLoggedInUser().email(); | 989 std::string email = chromeos::UserManager::Get()->GetLoggedInUser().email(); |
| 993 if (!email.empty()) { | 990 if (!email.empty()) { |
| 994 web_ui()->CallJavascriptFunction("BrowserOptions.updateAccountPicture"); | 991 web_ui()->CallJavascriptFunction("BrowserOptions.updateAccountPicture"); |
| 995 base::StringValue email_value(email); | 992 base::StringValue email_value(email); |
| 996 web_ui()->CallJavascriptFunction("BrowserOptions.updateAccountPicture", | 993 web_ui()->CallJavascriptFunction("BrowserOptions.updateAccountPicture", |
| 997 email_value); | 994 email_value); |
| 998 } | 995 } |
| 999 } | 996 } |
| 1000 #endif | 997 #endif |
| 1001 | 998 |
| 1002 DictionaryValue* BrowserOptionsHandler::GetSyncStateDictionary() { | 999 scoped_ptr<DictionaryValue> BrowserOptionsHandler::GetSyncStateDictionary() { |
| 1003 DictionaryValue* sync_status = new DictionaryValue; | 1000 scoped_ptr<DictionaryValue> sync_status(new DictionaryValue); |
| 1004 ProfileSyncService* service(ProfileSyncServiceFactory:: | 1001 ProfileSyncService* service(ProfileSyncServiceFactory:: |
| 1005 GetInstance()->GetForProfile(Profile::FromWebUI(web_ui()))); | 1002 GetInstance()->GetForProfile(Profile::FromWebUI(web_ui()))); |
| 1006 sync_status->SetBoolean("syncSystemEnabled", !!service); | 1003 sync_status->SetBoolean("syncSystemEnabled", !!service); |
| 1007 if (!service) | 1004 if (!service) |
| 1008 return sync_status; | 1005 return sync_status.Pass(); |
| 1009 | 1006 |
| 1010 sync_status->SetBoolean("setupCompleted", | 1007 sync_status->SetBoolean("setupCompleted", |
| 1011 service->HasSyncSetupCompleted()); | 1008 service->HasSyncSetupCompleted()); |
| 1012 sync_status->SetBoolean("setupInProgress", service->FirstSetupInProgress()); | 1009 sync_status->SetBoolean("setupInProgress", service->FirstSetupInProgress()); |
| 1013 | 1010 |
| 1014 string16 status_label; | 1011 string16 status_label; |
| 1015 string16 link_label; | 1012 string16 link_label; |
| 1016 SigninManager* signin = SigninManagerFactory::GetForProfile( | 1013 SigninManager* signin = SigninManagerFactory::GetForProfile( |
| 1017 Profile::FromWebUI(web_ui())); | 1014 Profile::FromWebUI(web_ui())); |
| 1018 | 1015 |
| 1019 bool status_has_error = sync_ui_util::GetStatusLabels( | 1016 bool status_has_error = sync_ui_util::GetStatusLabels( |
| 1020 service, *signin, sync_ui_util::WITH_HTML, &status_label, &link_label) == | 1017 service, *signin, sync_ui_util::WITH_HTML, &status_label, &link_label) == |
| 1021 sync_ui_util::SYNC_ERROR; | 1018 sync_ui_util::SYNC_ERROR; |
| 1022 sync_status->SetString("statusText", status_label); | 1019 sync_status->SetString("statusText", status_label); |
| 1023 sync_status->SetString("actionLinkText", link_label); | 1020 sync_status->SetString("actionLinkText", link_label); |
| 1024 sync_status->SetBoolean("hasError", status_has_error); | 1021 sync_status->SetBoolean("hasError", status_has_error); |
| 1025 | 1022 |
| 1026 sync_status->SetBoolean("managed", service->IsManaged()); | 1023 sync_status->SetBoolean("managed", service->IsManaged()); |
| 1027 sync_status->SetBoolean("hasUnrecoverableError", | 1024 sync_status->SetBoolean("hasUnrecoverableError", |
| 1028 service->unrecoverable_error_detected()); | 1025 service->unrecoverable_error_detected()); |
| 1029 sync_status->SetBoolean("autoLoginVisible", | 1026 sync_status->SetBoolean("autoLoginVisible", |
| 1030 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableAutologin) && | 1027 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableAutologin) && |
| 1031 service->AreCredentialsAvailable()); | 1028 service->AreCredentialsAvailable()); |
| 1032 | 1029 |
| 1033 return sync_status; | 1030 return sync_status.Pass(); |
| 1034 } | 1031 } |
| 1035 | 1032 |
| 1036 void BrowserOptionsHandler::HandleSelectDownloadLocation( | 1033 void BrowserOptionsHandler::HandleSelectDownloadLocation( |
| 1037 const ListValue* args) { | 1034 const ListValue* args) { |
| 1038 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); | 1035 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 1039 select_folder_dialog_ = SelectFileDialog::Create(this); | 1036 select_folder_dialog_ = SelectFileDialog::Create(this); |
| 1040 select_folder_dialog_->SelectFile( | 1037 select_folder_dialog_->SelectFile( |
| 1041 SelectFileDialog::SELECT_FOLDER, | 1038 SelectFileDialog::SELECT_FOLDER, |
| 1042 l10n_util::GetStringUTF16(IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE), | 1039 l10n_util::GetStringUTF16(IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE), |
| 1043 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory), | 1040 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory), |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1414 } | 1411 } |
| 1415 | 1412 |
| 1416 void BrowserOptionsHandler::SetupSSLConfigSettings() { | 1413 void BrowserOptionsHandler::SetupSSLConfigSettings() { |
| 1417 base::FundamentalValue checked(rev_checking_enabled_.GetValue()); | 1414 base::FundamentalValue checked(rev_checking_enabled_.GetValue()); |
| 1418 base::FundamentalValue disabled(rev_checking_enabled_.IsManaged()); | 1415 base::FundamentalValue disabled(rev_checking_enabled_.IsManaged()); |
| 1419 web_ui()->CallJavascriptFunction( | 1416 web_ui()->CallJavascriptFunction( |
| 1420 "BrowserOptions.setCheckRevocationCheckboxState", checked, disabled); | 1417 "BrowserOptions.setCheckRevocationCheckboxState", checked, disabled); |
| 1421 } | 1418 } |
| 1422 | 1419 |
| 1423 } // namespace options2 | 1420 } // namespace options2 |
| OLD | NEW |