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