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