| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/webui/options2/advanced_options_handler.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/basictypes.h" | |
| 10 #include "base/bind.h" | |
| 11 #include "base/bind_helpers.h" | |
| 12 #include "base/command_line.h" | |
| 13 #include "base/utf_string_conversions.h" | |
| 14 #include "base/values.h" | |
| 15 #include "chrome/browser/browser_process.h" | |
| 16 #include "chrome/browser/chrome_page_zoom.h" | |
| 17 #include "chrome/browser/download/download_prefs.h" | |
| 18 #include "chrome/browser/google/google_util.h" | |
| 19 #include "chrome/browser/prefs/pref_service.h" | |
| 20 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" | |
| 21 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.
h" | |
| 22 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" | |
| 23 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" | |
| 24 #include "chrome/browser/profiles/profile.h" | |
| 25 #include "chrome/browser/service/service_process_control.h" | |
| 26 #include "chrome/browser/ui/options/options_util.h" | |
| 27 #include "chrome/common/chrome_notification_types.h" | |
| 28 #include "chrome/common/chrome_switches.h" | |
| 29 #include "chrome/common/pref_names.h" | |
| 30 #include "chrome/common/url_constants.h" | |
| 31 #include "content/browser/download/download_manager.h" | |
| 32 #include "content/browser/tab_contents/tab_contents.h" | |
| 33 #include "content/browser/tab_contents/tab_contents_view.h" | |
| 34 #include "content/browser/user_metrics.h" | |
| 35 #include "content/public/browser/notification_details.h" | |
| 36 #include "content/public/browser/notification_types.h" | |
| 37 #include "content/public/common/page_zoom.h" | |
| 38 #include "grit/chromium_strings.h" | |
| 39 #include "grit/generated_resources.h" | |
| 40 #include "grit/locale_settings.h" | |
| 41 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | |
| 42 #include "ui/base/l10n/l10n_util.h" | |
| 43 | |
| 44 #if !defined(OS_CHROMEOS) | |
| 45 #include "chrome/browser/printing/cloud_print/cloud_print_setup_handler.h" | |
| 46 #include "chrome/browser/ui/webui/options2/advanced_options_utils.h" | |
| 47 #endif | |
| 48 | |
| 49 AdvancedOptionsHandler::AdvancedOptionsHandler() { | |
| 50 | |
| 51 #if(!defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)) | |
| 52 // On Windows, we need the PDF plugin which is only guaranteed to exist on | |
| 53 // Google Chrome builds. Use a command-line switch for Windows non-Google | |
| 54 // Chrome builds. | |
| 55 cloud_print_proxy_ui_enabled_ = CommandLine::ForCurrentProcess()->HasSwitch( | |
| 56 switches::kEnableCloudPrintProxy); | |
| 57 #elif(!defined(OS_CHROMEOS)) | |
| 58 // Always enabled for Mac, Linux and Google Chrome Windows builds. | |
| 59 // Never enabled for Chrome OS, we don't even need to indicate it. | |
| 60 cloud_print_proxy_ui_enabled_ = true; | |
| 61 #endif | |
| 62 } | |
| 63 | |
| 64 AdvancedOptionsHandler::~AdvancedOptionsHandler() { | |
| 65 // There may be pending file dialogs, we need to tell them that we've gone | |
| 66 // away so they don't try and call back to us. | |
| 67 if (select_folder_dialog_.get()) | |
| 68 select_folder_dialog_->ListenerDestroyed(); | |
| 69 } | |
| 70 | |
| 71 void AdvancedOptionsHandler::GetLocalizedValues( | |
| 72 DictionaryValue* localized_strings) { | |
| 73 DCHECK(localized_strings); | |
| 74 | |
| 75 static OptionsStringResource resources[] = { | |
| 76 { "downloadLocationGroupName", | |
| 77 IDS_OPTIONS_DOWNLOADLOCATION_GROUP_NAME }, | |
| 78 { "downloadLocationChangeButton", | |
| 79 IDS_OPTIONS_DOWNLOADLOCATION_CHANGE_BUTTON }, | |
| 80 { "downloadLocationBrowseTitle", | |
| 81 IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE }, | |
| 82 { "downloadLocationBrowseWindowTitle", | |
| 83 IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_WINDOW_TITLE }, | |
| 84 { "downloadLocationAskForSaveLocation", | |
| 85 IDS_OPTIONS_DOWNLOADLOCATION_ASKFORSAVELOCATION }, | |
| 86 { "autoOpenFileTypesInfo", | |
| 87 IDS_OPTIONS_OPEN_FILE_TYPES_AUTOMATICALLY }, | |
| 88 { "autoOpenFileTypesResetToDefault", | |
| 89 IDS_OPTIONS_AUTOOPENFILETYPES_RESETTODEFAULT }, | |
| 90 { "translateEnableTranslate", | |
| 91 IDS_OPTIONS_TRANSLATE_ENABLE_TRANSLATE }, | |
| 92 { "certificatesManageButton", | |
| 93 IDS_OPTIONS_CERTIFICATES_MANAGE_BUTTON }, | |
| 94 { "proxiesLabel", | |
| 95 IDS_OPTIONS_PROXIES_LABEL }, | |
| 96 #if !defined(OS_CHROMEOS) | |
| 97 { "proxiesConfigureButton", | |
| 98 IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON }, | |
| 99 #endif | |
| 100 { "safeBrowsingEnableProtection", | |
| 101 IDS_OPTIONS_SAFEBROWSING_ENABLEPROTECTION }, | |
| 102 { "sslGroupDescription", | |
| 103 IDS_OPTIONS_SSL_GROUP_DESCRIPTION }, | |
| 104 { "sslCheckRevocation", | |
| 105 IDS_OPTIONS_SSL_CHECKREVOCATION }, | |
| 106 { "networkPredictionEnabledDescription", | |
| 107 IDS_NETWORK_PREDICTION_ENABLED_DESCRIPTION }, | |
| 108 { "privacyContentSettingsButton", | |
| 109 IDS_OPTIONS_PRIVACY_CONTENT_SETTINGS_BUTTON }, | |
| 110 { "privacyClearDataButton", | |
| 111 IDS_OPTIONS_PRIVACY_CLEAR_DATA_BUTTON }, | |
| 112 { "linkDoctorPref", | |
| 113 IDS_OPTIONS_LINKDOCTOR_PREF }, | |
| 114 { "suggestPref", | |
| 115 IDS_OPTIONS_SUGGEST_PREF }, | |
| 116 { "tabsToLinksPref", | |
| 117 IDS_OPTIONS_TABS_TO_LINKS_PREF }, | |
| 118 { "fontSettingsInfo", | |
| 119 IDS_OPTIONS_FONTSETTINGS_INFO }, | |
| 120 { "defaultZoomFactorLabel", | |
| 121 IDS_OPTIONS_DEFAULT_ZOOM_LEVEL_LABEL }, | |
| 122 { "defaultFontSizeLabel", | |
| 123 IDS_OPTIONS_DEFAULT_FONT_SIZE_LABEL }, | |
| 124 { "fontSizeLabelVerySmall", | |
| 125 IDS_OPTIONS_FONT_SIZE_LABEL_VERY_SMALL }, | |
| 126 { "fontSizeLabelSmall", | |
| 127 IDS_OPTIONS_FONT_SIZE_LABEL_SMALL }, | |
| 128 { "fontSizeLabelMedium", | |
| 129 IDS_OPTIONS_FONT_SIZE_LABEL_MEDIUM }, | |
| 130 { "fontSizeLabelLarge", | |
| 131 IDS_OPTIONS_FONT_SIZE_LABEL_LARGE }, | |
| 132 { "fontSizeLabelVeryLarge", | |
| 133 IDS_OPTIONS_FONT_SIZE_LABEL_VERY_LARGE }, | |
| 134 { "fontSizeLabelCustom", | |
| 135 IDS_OPTIONS_FONT_SIZE_LABEL_CUSTOM }, | |
| 136 { "fontSettingsCustomizeFontsButton", | |
| 137 IDS_OPTIONS_FONTSETTINGS_CUSTOMIZE_FONTS_BUTTON }, | |
| 138 { "languageAndSpellCheckSettingsButton", | |
| 139 IDS_OPTIONS_LANGUAGE_AND_SPELLCHECK_BUTTON }, | |
| 140 { "advancedSectionTitlePrivacy", | |
| 141 IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY }, | |
| 142 { "advancedSectionTitleContent", | |
| 143 IDS_OPTIONS_ADVANCED_SECTION_TITLE_CONTENT }, | |
| 144 { "advancedSectionTitleSecurity", | |
| 145 IDS_OPTIONS_ADVANCED_SECTION_TITLE_SECURITY }, | |
| 146 { "advancedSectionTitleNetwork", | |
| 147 IDS_OPTIONS_ADVANCED_SECTION_TITLE_NETWORK }, | |
| 148 { "advancedSectionTitleTranslate", | |
| 149 IDS_OPTIONS_ADVANCED_SECTION_TITLE_TRANSLATE }, | |
| 150 { "translateEnableTranslate", | |
| 151 IDS_OPTIONS_TRANSLATE_ENABLE_TRANSLATE }, | |
| 152 { "enableLogging", | |
| 153 IDS_OPTIONS_ENABLE_LOGGING }, | |
| 154 { "improveBrowsingExperience", | |
| 155 IDS_OPTIONS_IMPROVE_BROWSING_EXPERIENCE }, | |
| 156 { "disableWebServices", | |
| 157 IDS_OPTIONS_DISABLE_WEB_SERVICES }, | |
| 158 #if defined(OS_CHROMEOS) | |
| 159 { "cloudPrintChromeosOptionLabel", | |
| 160 IDS_CLOUD_PRINT_CHROMEOS_OPTION_LABEL }, | |
| 161 { "cloudPrintChromeosOptionButton", | |
| 162 IDS_CLOUD_PRINT_CHROMEOS_OPTION_BUTTON }, | |
| 163 #endif | |
| 164 { "cloudPrintOptionsStaticLabel", | |
| 165 IDS_CLOUD_PRINT_SETUP_DIALOG_TITLE }, | |
| 166 { "cloudPrintProxyEnabledManageButton", | |
| 167 IDS_OPTIONS_CLOUD_PRINT_PROXY_ENABLED_MANAGE_BUTTON }, | |
| 168 { "advancedSectionTitleCloudPrint", | |
| 169 IDS_OPTIONS_ADVANCED_SECTION_TITLE_CLOUD_PRINT }, | |
| 170 #if !defined(OS_CHROMEOS) | |
| 171 { "cloudPrintProxyDisabledLabel", | |
| 172 IDS_OPTIONS_CLOUD_PRINT_PROXY_DISABLED_LABEL }, | |
| 173 { "cloudPrintProxyDisabledButton", | |
| 174 IDS_OPTIONS_CLOUD_PRINT_PROXY_DISABLED_BUTTON }, | |
| 175 { "cloudPrintProxyEnabledButton", | |
| 176 IDS_OPTIONS_CLOUD_PRINT_PROXY_ENABLED_BUTTON }, | |
| 177 { "cloudPrintProxyEnablingButton", | |
| 178 IDS_OPTIONS_CLOUD_PRINT_PROXY_ENABLING_BUTTON }, | |
| 179 #endif | |
| 180 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) | |
| 181 { "advancedSectionTitleBackground", | |
| 182 IDS_OPTIONS_ADVANCED_SECTION_TITLE_BACKGROUND }, | |
| 183 { "backgroundModeCheckbox", | |
| 184 IDS_OPTIONS_BACKGROUND_ENABLE_BACKGROUND_MODE }, | |
| 185 #endif | |
| 186 }; | |
| 187 | |
| 188 RegisterStrings(localized_strings, resources, arraysize(resources)); | |
| 189 RegisterTitle(localized_strings, "advancedPage", | |
| 190 IDS_OPTIONS_ADVANCED_TAB_LABEL); | |
| 191 | |
| 192 localized_strings->SetString("privacyLearnMoreURL", | |
| 193 google_util::AppendGoogleLocaleParam( | |
| 194 GURL(chrome::kPrivacyLearnMoreURL)).spec()); | |
| 195 | |
| 196 #if defined(OS_CHROMEOS) | |
| 197 localized_strings->SetString("cloudPrintLearnMoreURL", | |
| 198 google_util::AppendGoogleLocaleParam( | |
| 199 GURL(chrome::kCloudPrintLearnMoreURL)).spec()); | |
| 200 #endif | |
| 201 } | |
| 202 | |
| 203 void AdvancedOptionsHandler::Initialize() { | |
| 204 DCHECK(web_ui_); | |
| 205 SetupMetricsReportingCheckbox(); | |
| 206 SetupMetricsReportingSettingVisibility(); | |
| 207 SetupFontSizeSelector(); | |
| 208 SetupPageZoomSelector(); | |
| 209 SetupAutoOpenFileTypesDisabledAttribute(); | |
| 210 SetupProxySettingsSection(); | |
| 211 SetupSSLConfigSettings(); | |
| 212 #if !defined(OS_CHROMEOS) | |
| 213 if (cloud_print_proxy_ui_enabled_) { | |
| 214 SetupCloudPrintProxySection(); | |
| 215 RefreshCloudPrintStatusFromService(); | |
| 216 } else { | |
| 217 RemoveCloudPrintProxySection(); | |
| 218 } | |
| 219 #endif | |
| 220 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) | |
| 221 SetupBackgroundModeSettings(); | |
| 222 #endif | |
| 223 | |
| 224 } | |
| 225 | |
| 226 WebUIMessageHandler* AdvancedOptionsHandler::Attach(WebUI* web_ui) { | |
| 227 // Call through to superclass. | |
| 228 WebUIMessageHandler* handler = OptionsPage2UIHandler::Attach(web_ui); | |
| 229 | |
| 230 // Register for preferences that we need to observe manually. These have | |
| 231 // special behaviors that aren't handled by the standard prefs UI. | |
| 232 DCHECK(web_ui_); | |
| 233 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs(); | |
| 234 #if !defined(OS_CHROMEOS) | |
| 235 enable_metrics_recording_.Init(prefs::kMetricsReportingEnabled, | |
| 236 g_browser_process->local_state(), this); | |
| 237 cloud_print_proxy_email_.Init(prefs::kCloudPrintEmail, prefs, this); | |
| 238 cloud_print_proxy_enabled_.Init(prefs::kCloudPrintProxyEnabled, prefs, this); | |
| 239 #endif | |
| 240 | |
| 241 rev_checking_enabled_.Init(prefs::kCertRevocationCheckingEnabled, | |
| 242 g_browser_process->local_state(), this); | |
| 243 | |
| 244 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) | |
| 245 background_mode_enabled_.Init(prefs::kBackgroundModeEnabled, | |
| 246 g_browser_process->local_state(), | |
| 247 this); | |
| 248 #endif | |
| 249 | |
| 250 auto_open_files_.Init(prefs::kDownloadExtensionsToOpen, prefs, this); | |
| 251 default_font_size_.Init(prefs::kWebKitDefaultFontSize, prefs, this); | |
| 252 default_zoom_level_.Init(prefs::kDefaultZoomLevel, prefs, this); | |
| 253 #if !defined(OS_CHROMEOS) | |
| 254 proxy_prefs_.reset( | |
| 255 PrefSetObserver::CreateProxyPrefSetObserver(prefs, this)); | |
| 256 #endif // !defined(OS_CHROMEOS) | |
| 257 | |
| 258 // Return result from the superclass. | |
| 259 return handler; | |
| 260 } | |
| 261 | |
| 262 void AdvancedOptionsHandler::RegisterMessages() { | |
| 263 // Setup handlers specific to this panel. | |
| 264 DCHECK(web_ui_); | |
| 265 web_ui_->RegisterMessageCallback("selectDownloadLocation", | |
| 266 base::Bind(&AdvancedOptionsHandler::HandleSelectDownloadLocation, | |
| 267 base::Unretained(this))); | |
| 268 web_ui_->RegisterMessageCallback("autoOpenFileTypesAction", | |
| 269 base::Bind(&AdvancedOptionsHandler::HandleAutoOpenButton, | |
| 270 base::Unretained(this))); | |
| 271 web_ui_->RegisterMessageCallback("defaultFontSizeAction", | |
| 272 base::Bind(&AdvancedOptionsHandler::HandleDefaultFontSize, | |
| 273 base::Unretained(this))); | |
| 274 web_ui_->RegisterMessageCallback("defaultZoomFactorAction", | |
| 275 base::Bind(&AdvancedOptionsHandler::HandleDefaultZoomFactor, | |
| 276 base::Unretained(this))); | |
| 277 #if !defined(OS_CHROMEOS) | |
| 278 web_ui_->RegisterMessageCallback("metricsReportingCheckboxAction", | |
| 279 base::Bind(&AdvancedOptionsHandler::HandleMetricsReportingCheckbox, | |
| 280 base::Unretained(this))); | |
| 281 #endif | |
| 282 #if !defined(USE_NSS) && !defined(USE_OPENSSL) | |
| 283 web_ui_->RegisterMessageCallback("showManageSSLCertificates", | |
| 284 base::Bind(&AdvancedOptionsHandler::ShowManageSSLCertificates, | |
| 285 base::Unretained(this))); | |
| 286 #endif | |
| 287 web_ui_->RegisterMessageCallback("showCloudPrintManagePage", | |
| 288 base::Bind(&AdvancedOptionsHandler::ShowCloudPrintManagePage, | |
| 289 base::Unretained(this))); | |
| 290 #if !defined(OS_CHROMEOS) | |
| 291 if (cloud_print_proxy_ui_enabled_) { | |
| 292 web_ui_->RegisterMessageCallback("showCloudPrintSetupDialog", | |
| 293 base::Bind(&AdvancedOptionsHandler::ShowCloudPrintSetupDialog, | |
| 294 base::Unretained(this))); | |
| 295 web_ui_->RegisterMessageCallback("disableCloudPrintProxy", | |
| 296 base::Bind(&AdvancedOptionsHandler::HandleDisableCloudPrintProxy, | |
| 297 base::Unretained(this))); | |
| 298 } | |
| 299 web_ui_->RegisterMessageCallback("showNetworkProxySettings", | |
| 300 base::Bind(&AdvancedOptionsHandler::ShowNetworkProxySettings, | |
| 301 base::Unretained(this))); | |
| 302 #endif | |
| 303 web_ui_->RegisterMessageCallback("checkRevocationCheckboxAction", | |
| 304 base::Bind(&AdvancedOptionsHandler::HandleCheckRevocationCheckbox, | |
| 305 base::Unretained(this))); | |
| 306 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) | |
| 307 web_ui_->RegisterMessageCallback("backgroundModeAction", | |
| 308 base::Bind(&AdvancedOptionsHandler::HandleBackgroundModeCheckbox, | |
| 309 base::Unretained(this))); | |
| 310 #endif | |
| 311 } | |
| 312 | |
| 313 void AdvancedOptionsHandler::Observe( | |
| 314 int type, | |
| 315 const content::NotificationSource& source, | |
| 316 const content::NotificationDetails& details) { | |
| 317 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | |
| 318 std::string* pref_name = content::Details<std::string>(details).ptr(); | |
| 319 if (*pref_name == prefs::kDownloadExtensionsToOpen) { | |
| 320 SetupAutoOpenFileTypesDisabledAttribute(); | |
| 321 #if !defined(OS_CHROMEOS) | |
| 322 } else if (proxy_prefs_->IsObserved(*pref_name)) { | |
| 323 SetupProxySettingsSection(); | |
| 324 #endif // !defined(OS_CHROMEOS) | |
| 325 } else if ((*pref_name == prefs::kCloudPrintEmail) || | |
| 326 (*pref_name == prefs::kCloudPrintProxyEnabled)) { | |
| 327 #if !defined(OS_CHROMEOS) | |
| 328 if (cloud_print_proxy_ui_enabled_) | |
| 329 SetupCloudPrintProxySection(); | |
| 330 #endif | |
| 331 } else if (*pref_name == prefs::kWebKitDefaultFontSize) { | |
| 332 SetupFontSizeSelector(); | |
| 333 } else if (*pref_name == prefs::kDefaultZoomLevel) { | |
| 334 SetupPageZoomSelector(); | |
| 335 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) | |
| 336 } else if (*pref_name == prefs::kBackgroundModeEnabled) { | |
| 337 SetupBackgroundModeSettings(); | |
| 338 #endif | |
| 339 } | |
| 340 } | |
| 341 } | |
| 342 | |
| 343 void AdvancedOptionsHandler::HandleSelectDownloadLocation( | |
| 344 const ListValue* args) { | |
| 345 PrefService* pref_service = Profile::FromWebUI(web_ui_)->GetPrefs(); | |
| 346 select_folder_dialog_ = SelectFileDialog::Create(this); | |
| 347 select_folder_dialog_->SelectFile( | |
| 348 SelectFileDialog::SELECT_FOLDER, | |
| 349 l10n_util::GetStringUTF16(IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE), | |
| 350 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory), | |
| 351 NULL, 0, FILE_PATH_LITERAL(""), web_ui_->tab_contents(), | |
| 352 web_ui_->tab_contents()->view()->GetTopLevelNativeWindow(), NULL); | |
| 353 } | |
| 354 | |
| 355 void AdvancedOptionsHandler::FileSelected(const FilePath& path, int index, | |
| 356 void* params) { | |
| 357 UserMetrics::RecordAction(UserMetricsAction("Options_SetDownloadDirectory")); | |
| 358 PrefService* pref_service = Profile::FromWebUI(web_ui_)->GetPrefs(); | |
| 359 pref_service->SetFilePath(prefs::kDownloadDefaultDirectory, path); | |
| 360 } | |
| 361 | |
| 362 void AdvancedOptionsHandler::OnCloudPrintSetupClosed() { | |
| 363 #if !defined(OS_CHROMEOS) | |
| 364 if (cloud_print_proxy_ui_enabled_) | |
| 365 SetupCloudPrintProxySection(); | |
| 366 #endif | |
| 367 } | |
| 368 | |
| 369 void AdvancedOptionsHandler::HandleAutoOpenButton(const ListValue* args) { | |
| 370 UserMetrics::RecordAction(UserMetricsAction("Options_ResetAutoOpenFiles")); | |
| 371 DownloadManager* manager = | |
| 372 web_ui_->tab_contents()->browser_context()->GetDownloadManager(); | |
| 373 if (manager) | |
| 374 DownloadPrefs::FromDownloadManager(manager)->ResetAutoOpen(); | |
| 375 } | |
| 376 | |
| 377 void AdvancedOptionsHandler::HandleMetricsReportingCheckbox( | |
| 378 const ListValue* args) { | |
| 379 #if defined(GOOGLE_CHROME_BUILD) && !defined(OS_CHROMEOS) | |
| 380 std::string checked_str = UTF16ToUTF8(ExtractStringValue(args)); | |
| 381 bool enabled = checked_str == "true"; | |
| 382 UserMetrics::RecordAction( | |
| 383 enabled ? | |
| 384 UserMetricsAction("Options_MetricsReportingCheckbox_Enable") : | |
| 385 UserMetricsAction("Options_MetricsReportingCheckbox_Disable")); | |
| 386 bool is_enabled = OptionsUtil::ResolveMetricsReportingEnabled(enabled); | |
| 387 enable_metrics_recording_.SetValue(is_enabled); | |
| 388 SetupMetricsReportingCheckbox(); | |
| 389 #endif | |
| 390 } | |
| 391 | |
| 392 void AdvancedOptionsHandler::HandleDefaultFontSize(const ListValue* args) { | |
| 393 int font_size; | |
| 394 if (ExtractIntegerValue(args, &font_size)) { | |
| 395 if (font_size > 0) { | |
| 396 default_font_size_.SetValue(font_size); | |
| 397 SetupFontSizeSelector(); | |
| 398 } | |
| 399 } | |
| 400 } | |
| 401 | |
| 402 void AdvancedOptionsHandler::HandleDefaultZoomFactor(const ListValue* args) { | |
| 403 double zoom_factor; | |
| 404 if (ExtractDoubleValue(args, &zoom_factor)) { | |
| 405 default_zoom_level_.SetValue( | |
| 406 WebKit::WebView::zoomFactorToZoomLevel(zoom_factor)); | |
| 407 } | |
| 408 } | |
| 409 | |
| 410 void AdvancedOptionsHandler::HandleCheckRevocationCheckbox( | |
| 411 const ListValue* args) { | |
| 412 std::string checked_str = UTF16ToUTF8(ExtractStringValue(args)); | |
| 413 bool enabled = checked_str == "true"; | |
| 414 UserMetrics::RecordAction( | |
| 415 enabled ? | |
| 416 UserMetricsAction("Options_CheckCertRevocation_Enable") : | |
| 417 UserMetricsAction("Options_CheckCertRevocation_Disable")); | |
| 418 rev_checking_enabled_.SetValue(enabled); | |
| 419 } | |
| 420 | |
| 421 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) | |
| 422 void AdvancedOptionsHandler::HandleBackgroundModeCheckbox( | |
| 423 const ListValue* args) { | |
| 424 std::string checked_str = UTF16ToUTF8(ExtractStringValue(args)); | |
| 425 bool enabled = checked_str == "true"; | |
| 426 UserMetrics::RecordAction(enabled ? | |
| 427 UserMetricsAction("Options_BackgroundMode_Enable") : | |
| 428 UserMetricsAction("Options_BackgroundMode_Disable")); | |
| 429 background_mode_enabled_.SetValue(enabled); | |
| 430 } | |
| 431 | |
| 432 void AdvancedOptionsHandler::SetupBackgroundModeSettings() { | |
| 433 base::FundamentalValue checked(background_mode_enabled_.GetValue()); | |
| 434 web_ui_->CallJavascriptFunction( | |
| 435 "options.AdvancedOptions.SetBackgroundModeCheckboxState", checked); | |
| 436 } | |
| 437 #endif | |
| 438 | |
| 439 #if !defined(OS_CHROMEOS) | |
| 440 void AdvancedOptionsHandler::ShowNetworkProxySettings(const ListValue* args) { | |
| 441 UserMetrics::RecordAction(UserMetricsAction("Options_ShowProxySettings")); | |
| 442 AdvancedOptionsUtilities::ShowNetworkProxySettings(web_ui_->tab_contents()); | |
| 443 } | |
| 444 #endif | |
| 445 | |
| 446 #if !defined(USE_NSS) && !defined(USE_OPENSSL) | |
| 447 void AdvancedOptionsHandler::ShowManageSSLCertificates(const ListValue* args) { | |
| 448 UserMetrics::RecordAction(UserMetricsAction("Options_ManageSSLCertificates")); | |
| 449 AdvancedOptionsUtilities::ShowManageSSLCertificates(web_ui_->tab_contents()); | |
| 450 } | |
| 451 #endif | |
| 452 | |
| 453 void AdvancedOptionsHandler::ShowCloudPrintManagePage(const ListValue* args) { | |
| 454 UserMetrics::RecordAction(UserMetricsAction("Options_ManageCloudPrinters")); | |
| 455 // Open a new tab in the current window for the management page. | |
| 456 Profile* profile = Profile::FromWebUI(web_ui_); | |
| 457 web_ui_->tab_contents()->OpenURL( | |
| 458 CloudPrintURL(profile).GetCloudPrintServiceManageURL(), | |
| 459 GURL(), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK); | |
| 460 } | |
| 461 | |
| 462 #if !defined(OS_CHROMEOS) | |
| 463 void AdvancedOptionsHandler::ShowCloudPrintSetupDialog(const ListValue* args) { | |
| 464 UserMetrics::RecordAction(UserMetricsAction("Options_EnableCloudPrintProxy")); | |
| 465 // Open the connector enable page in the current tab. | |
| 466 Profile* profile = Profile::FromWebUI(web_ui_); | |
| 467 web_ui_->tab_contents()->OpenURL( | |
| 468 CloudPrintURL(profile).GetCloudPrintServiceEnableURL( | |
| 469 CloudPrintProxyServiceFactory::GetForProfile(profile)->proxy_id()), | |
| 470 GURL(), CURRENT_TAB, content::PAGE_TRANSITION_LINK); | |
| 471 } | |
| 472 | |
| 473 void AdvancedOptionsHandler::HandleDisableCloudPrintProxy( | |
| 474 const ListValue* args) { | |
| 475 UserMetrics::RecordAction( | |
| 476 UserMetricsAction("Options_DisableCloudPrintProxy")); | |
| 477 CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui_))-> | |
| 478 DisableForUser(); | |
| 479 } | |
| 480 | |
| 481 void AdvancedOptionsHandler::RefreshCloudPrintStatusFromService() { | |
| 482 if (cloud_print_proxy_ui_enabled_) | |
| 483 CloudPrintProxyServiceFactory::GetForProfile(Profile::FromWebUI(web_ui_))-> | |
| 484 RefreshStatusFromService(); | |
| 485 } | |
| 486 | |
| 487 void AdvancedOptionsHandler::SetupCloudPrintProxySection() { | |
| 488 Profile* profile = Profile::FromWebUI(web_ui_); | |
| 489 if (!CloudPrintProxyServiceFactory::GetForProfile(profile)) { | |
| 490 cloud_print_proxy_ui_enabled_ = false; | |
| 491 RemoveCloudPrintProxySection(); | |
| 492 return; | |
| 493 } | |
| 494 | |
| 495 bool cloud_print_proxy_allowed = | |
| 496 !cloud_print_proxy_enabled_.IsManaged() || | |
| 497 cloud_print_proxy_enabled_.GetValue(); | |
| 498 base::FundamentalValue allowed(cloud_print_proxy_allowed); | |
| 499 | |
| 500 std::string email; | |
| 501 if (profile->GetPrefs()->HasPrefPath(prefs::kCloudPrintEmail) && | |
| 502 cloud_print_proxy_allowed) { | |
| 503 email = profile->GetPrefs()->GetString(prefs::kCloudPrintEmail); | |
| 504 } | |
| 505 base::FundamentalValue disabled(email.empty()); | |
| 506 | |
| 507 string16 label_str; | |
| 508 if (email.empty()) { | |
| 509 label_str = l10n_util::GetStringUTF16( | |
| 510 IDS_OPTIONS_CLOUD_PRINT_PROXY_DISABLED_LABEL); | |
| 511 } else { | |
| 512 label_str = l10n_util::GetStringFUTF16( | |
| 513 IDS_OPTIONS_CLOUD_PRINT_PROXY_ENABLED_LABEL, UTF8ToUTF16(email)); | |
| 514 } | |
| 515 StringValue label(label_str); | |
| 516 | |
| 517 web_ui_->CallJavascriptFunction( | |
| 518 "options.AdvancedOptions.SetupCloudPrintProxySection", | |
| 519 disabled, label, allowed); | |
| 520 } | |
| 521 | |
| 522 void AdvancedOptionsHandler::RemoveCloudPrintProxySection() { | |
| 523 web_ui_->CallJavascriptFunction( | |
| 524 "options.AdvancedOptions.RemoveCloudPrintProxySection"); | |
| 525 } | |
| 526 | |
| 527 #endif | |
| 528 | |
| 529 void AdvancedOptionsHandler::SetupMetricsReportingCheckbox() { | |
| 530 #if defined(GOOGLE_CHROME_BUILD) && !defined(OS_CHROMEOS) | |
| 531 base::FundamentalValue checked(enable_metrics_recording_.GetValue()); | |
| 532 base::FundamentalValue disabled(enable_metrics_recording_.IsManaged()); | |
| 533 web_ui_->CallJavascriptFunction( | |
| 534 "options.AdvancedOptions.SetMetricsReportingCheckboxState", checked, | |
| 535 disabled); | |
| 536 #endif | |
| 537 } | |
| 538 | |
| 539 void AdvancedOptionsHandler::SetupMetricsReportingSettingVisibility() { | |
| 540 #if defined(GOOGLE_CHROME_BUILD) && defined(OS_CHROMEOS) | |
| 541 // Don't show the reporting setting if we are in the guest mode. | |
| 542 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession)) { | |
| 543 base::FundamentalValue visible(false); | |
| 544 web_ui_->CallJavascriptFunction( | |
| 545 "options.AdvancedOptions.SetMetricsReportingSettingVisibility", | |
| 546 visible); | |
| 547 } | |
| 548 #endif | |
| 549 } | |
| 550 | |
| 551 void AdvancedOptionsHandler::SetupFontSizeSelector() { | |
| 552 // We're only interested in integer values, so convert to int. | |
| 553 base::FundamentalValue font_size(default_font_size_.GetValue()); | |
| 554 web_ui_->CallJavascriptFunction( | |
| 555 "options.AdvancedOptions.SetFontSize", font_size); | |
| 556 } | |
| 557 | |
| 558 void AdvancedOptionsHandler::SetupPageZoomSelector() { | |
| 559 PrefService* pref_service = Profile::FromWebUI(web_ui_)->GetPrefs(); | |
| 560 double default_zoom_level = pref_service->GetDouble(prefs::kDefaultZoomLevel); | |
| 561 double default_zoom_factor = | |
| 562 WebKit::WebView::zoomLevelToZoomFactor(default_zoom_level); | |
| 563 | |
| 564 // Generate a vector of zoom factors from an array of known presets along with | |
| 565 // the default factor added if necessary. | |
| 566 std::vector<double> zoom_factors = | |
| 567 chrome_page_zoom::PresetZoomFactors(default_zoom_factor); | |
| 568 | |
| 569 // Iterate through the zoom factors and and build the contents of the | |
| 570 // selector that will be sent to the javascript handler. | |
| 571 // Each item in the list has the following parameters: | |
| 572 // 1. Title (string). | |
| 573 // 2. Value (double). | |
| 574 // 3. Is selected? (bool). | |
| 575 ListValue zoom_factors_value; | |
| 576 for (std::vector<double>::const_iterator i = zoom_factors.begin(); | |
| 577 i != zoom_factors.end(); ++i) { | |
| 578 ListValue* option = new ListValue(); | |
| 579 double factor = *i; | |
| 580 int percent = static_cast<int>(factor * 100 + 0.5); | |
| 581 option->Append(Value::CreateStringValue( | |
| 582 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, percent))); | |
| 583 option->Append(Value::CreateDoubleValue(factor)); | |
| 584 bool selected = content::ZoomValuesEqual(factor, default_zoom_factor); | |
| 585 option->Append(Value::CreateBooleanValue(selected)); | |
| 586 zoom_factors_value.Append(option); | |
| 587 } | |
| 588 | |
| 589 web_ui_->CallJavascriptFunction( | |
| 590 "options.AdvancedOptions.SetupPageZoomSelector", zoom_factors_value); | |
| 591 } | |
| 592 | |
| 593 void AdvancedOptionsHandler::SetupAutoOpenFileTypesDisabledAttribute() { | |
| 594 // Set the enabled state for the AutoOpenFileTypesResetToDefault button. | |
| 595 // We enable the button if the user has any auto-open file types registered. | |
| 596 DownloadManager* manager = | |
| 597 web_ui_->tab_contents()->browser_context()->GetDownloadManager(); | |
| 598 bool disabled = !(manager && | |
| 599 DownloadPrefs::FromDownloadManager(manager)->IsAutoOpenUsed()); | |
| 600 base::FundamentalValue value(disabled); | |
| 601 web_ui_->CallJavascriptFunction( | |
| 602 "options.AdvancedOptions.SetAutoOpenFileTypesDisabledAttribute", value); | |
| 603 } | |
| 604 | |
| 605 void AdvancedOptionsHandler::SetupProxySettingsSection() { | |
| 606 #if !defined(OS_CHROMEOS) | |
| 607 // Disable the button if proxy settings are managed by a sysadmin or | |
| 608 // overridden by an extension. | |
| 609 PrefService* pref_service = Profile::FromWebUI(web_ui_)->GetPrefs(); | |
| 610 const PrefService::Preference* proxy_config = | |
| 611 pref_service->FindPreference(prefs::kProxy); | |
| 612 bool is_extension_controlled = (proxy_config && | |
| 613 proxy_config->IsExtensionControlled()); | |
| 614 | |
| 615 base::FundamentalValue disabled(proxy_prefs_->IsManaged() || | |
| 616 is_extension_controlled); | |
| 617 | |
| 618 // Get the appropriate info string to describe the button. | |
| 619 string16 label_str; | |
| 620 if (is_extension_controlled) { | |
| 621 label_str = l10n_util::GetStringUTF16(IDS_OPTIONS_EXTENSION_PROXIES_LABEL); | |
| 622 } else { | |
| 623 label_str = l10n_util::GetStringFUTF16(IDS_OPTIONS_SYSTEM_PROXIES_LABEL, | |
| 624 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | |
| 625 } | |
| 626 StringValue label(label_str); | |
| 627 | |
| 628 web_ui_->CallJavascriptFunction( | |
| 629 "options.AdvancedOptions.SetupProxySettingsSection", disabled, label); | |
| 630 #endif // !defined(OS_CHROMEOS) | |
| 631 } | |
| 632 | |
| 633 void AdvancedOptionsHandler::SetupSSLConfigSettings() { | |
| 634 { | |
| 635 base::FundamentalValue checked(rev_checking_enabled_.GetValue()); | |
| 636 base::FundamentalValue disabled(rev_checking_enabled_.IsManaged()); | |
| 637 web_ui_->CallJavascriptFunction( | |
| 638 "options.AdvancedOptions.SetCheckRevocationCheckboxState", checked, | |
| 639 disabled); | |
| 640 } | |
| 641 } | |
| OLD | NEW |