advanced_options.js revision 201ade2fbba22bfb27ae029f4d23fca6ded109a0
1// Copyright (c) 2010 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
5cr.define('options', function() {
6
7var OptionsPage = options.OptionsPage;
8
9  //
10  // AdvancedOptions class
11  // Encapsulated handling of advanced options page.
12  //
13  function AdvancedOptions() {
14    OptionsPage.call(this, 'advanced', templateData.advancedPage,
15                     'advancedPage');
16  }
17
18  cr.addSingletonGetter(AdvancedOptions);
19
20  AdvancedOptions.prototype = {
21    // Inherit AdvancedOptions from OptionsPage.
22    __proto__: options.OptionsPage.prototype,
23
24    /**
25     * Initializes the page.
26     */
27    initializePage: function() {
28      // Call base class implementation to starts preference initialization.
29      OptionsPage.prototype.initializePage.call(this);
30
31      // Set up click handlers for buttons.
32      $('privacyContentSettingsButton').onclick = function(event) {
33        OptionsPage.showPageByName('content');
34        OptionsPage.showTab($('cookies-nav-tab'));
35        chrome.send('coreOptionsUserMetricsAction',
36            ['Options_ContentSettings']);
37      };
38      $('privacyClearDataButton').onclick = function(event) {
39        OptionsPage.showOverlay('clearBrowserDataOverlay');
40        chrome.send('coreOptionsUserMetricsAction', ['Options_ClearData']);
41      };
42
43      // 'metricsReportingEnabled' element is only present on Chrome branded
44      // builds.
45      if ($('metricsReportingEnabled')) {
46        $('metricsReportingEnabled').onclick = function(event) {
47          chrome.send('metricsReportingCheckboxAction',
48              [String(event.target.checked)]);
49        };
50      }
51
52      $('autoOpenFileTypesResetToDefault').onclick = function(event) {
53        chrome.send('autoOpenFileTypesAction');
54      };
55      $('fontSettingsCustomizeFontsButton').onclick = function(event) {
56        OptionsPage.showPageByName('fontSettings');
57        chrome.send('coreOptionsUserMetricsAction', ['Options_FontSettings']);
58      };
59      $('defaultZoomLevel').onchange = function(event) {
60        chrome.send('defaultZoomLevelAction',
61            [String(event.target.options[event.target.selectedIndex].value)]);
62      }
63      $('optionsReset').onclick = function(event) {
64        AlertOverlay.show(undefined,
65            localStrings.getString('optionsResetMessage'),
66            localStrings.getString('optionsResetOkLabel'),
67            localStrings.getString('optionsResetCancelLabel'),
68            function() { chrome.send('resetToDefaults'); });
69      }
70
71      if (cr.isWindows || cr.isMac) {
72        $('certificatesManageButton').onclick = function(event) {
73          chrome.send('showManageSSLCertificates');
74        };
75      } else {
76        $('certificatesManageButton').onclick = function(event) {
77          OptionsPage.showPageByName('certificateManager');
78          OptionsPage.showTab($('personal-certs-nav-tab'));
79          chrome.send('coreOptionsUserMetricsAction',
80                      ['Options_ManageSSLCertificates']);
81        };
82      }
83
84      if (!cr.isChromeOS) {
85        $('proxiesConfigureButton').onclick = function(event) {
86          chrome.send('showNetworkProxySettings');
87        };
88        $('downloadLocationBrowseButton').onclick = function(event) {
89          chrome.send('selectDownloadLocation');
90        };
91
92        // Remove Windows-style accelerators from the Browse button label.
93        // TODO(csilv): Remove this after the accelerator has been removed from
94        // the localized strings file, pending removal of old options window.
95        $('downloadLocationBrowseButton').textContent =
96            localStrings.getStringWithoutAccelerator(
97                'downloadLocationBrowseButton');
98      } else {
99        $('proxiesConfigureButton').onclick = function(event) {
100          OptionsPage.showPageByName('proxy');
101          chrome.send('coreOptionsUserMetricsAction',
102              ['Options_ShowProxySettings']);
103        };
104      }
105
106      if (cr.isWindows) {
107        $('sslCheckRevocation').onclick = function(event) {
108          chrome.send('checkRevocationCheckboxAction',
109              [String($('sslCheckRevocation').checked)]);
110        };
111        $('sslUseSSL2').onclick = function(event) {
112          chrome.send('useSSL2CheckboxAction',
113              [String($('sslUseSSL2').checked)]);
114        };
115        $('sslUseSSL3').onclick = function(event) {
116          chrome.send('useSSL3CheckboxAction',
117              [String($('sslUseSSL3').checked)]);
118        };
119        $('sslUseTLS1').onclick = function(event) {
120          chrome.send('useTLS1CheckboxAction',
121              [String($('sslUseTLS1').checked)]);
122        };
123        $('gearSettingsConfigureGearsButton').onclick = function(event) {
124          chrome.send('showGearsSettings');
125        };
126      }
127
128      // 'cloudPrintProxyEnabled' is true for Chrome branded builds on
129      // certain platforms, or could be enabled by a lab.
130      if (!cr.isChromeOS &&
131          localStrings.getString('enable-cloud-print-proxy') == 'true') {
132        $('cloudPrintProxySetupButton').onclick = function(event) {
133          if ($('cloudPrintProxyManageButton').style.display == 'none') {
134            // Disable the button, set it's text to the intermediate state.
135            $('cloudPrintProxySetupButton').textContent =
136              localStrings.getString('cloudPrintProxyEnablingButton');
137            $('cloudPrintProxySetupButton').disabled = true;
138            chrome.send('showCloudPrintSetupDialog');
139          } else {
140            chrome.send('disableCloudPrintProxy');
141          }
142        };
143        $('cloudPrintProxyManageButton').onclick = function(event) {
144          chrome.send('showCloudPrintManagePage');
145        };
146      }
147    },
148
149    /**
150     * Show a 'restart required' alert.
151     * @private
152     */
153    showRestartRequiredAlert_: function() {
154      AlertOverlay.show(undefined,
155          localStrings.getString('optionsRestartRequired'),
156          undefined, '', undefined);
157    }
158  };
159
160  //
161  // Chrome callbacks
162  //
163
164  // Set the checked state of the metrics reporting checkbox.
165  AdvancedOptions.SetMetricsReportingCheckboxState = function(checked,
166      disabled, user_changed) {
167    $('metricsReportingEnabled').checked = checked;
168    $('metricsReportingEnabled').disabled = disabled;
169
170    if (user_changed)
171      AdvancedOptions.getInstance().showRestartRequiredAlert_();
172  }
173
174  AdvancedOptions.SetMetricsReportingSettingVisibility = function(visible) {
175    if (visible) {
176      $('metricsReportingSetting').style.display = 'block';
177    } else {
178      $('metricsReportingSetting').style.display = 'none';
179    }
180  }
181
182  // Set the default zoom level selected item.
183  AdvancedOptions.SetDefaultZoomLevel = function(value) {
184    var selectCtl = $('defaultZoomLevel');
185    for (var i = 0; i < selectCtl.options.length; i++) {
186      if (selectCtl.options[i].value == value) {
187        selectCtl.selectedIndex = i;
188        return;
189      }
190    }
191    selectCtl.selectedIndex = 4;  // 100%
192  };
193
194  // Set the download path.
195  AdvancedOptions.SetDownloadLocationPath = function(path) {
196    if (!cr.isChromeOS)
197      $('downloadLocationPath').value = path;
198  };
199
200  // Set the enabled state for the autoOpenFileTypesResetToDefault button.
201  AdvancedOptions.SetAutoOpenFileTypesDisabledAttribute = function(disabled) {
202    $('autoOpenFileTypesResetToDefault').disabled = disabled;
203  };
204
205  // Set the enabled state for the proxy settings button.
206  AdvancedOptions.SetupProxySettingsSection = function(disabled, label) {
207    $('proxiesConfigureButton').disabled = disabled;
208    $('proxiesLabel').textContent = label;
209  };
210
211  // Set the checked state for the sslCheckRevocation checkbox.
212  AdvancedOptions.SetCheckRevocationCheckboxState = function(checked,
213      disabled) {
214    $('sslCheckRevocation').checked = checked;
215    $('sslCheckRevocation').disabled = disabled;
216  };
217
218  // Set the checked state for the sslUseSSL2 checkbox.
219  AdvancedOptions.SetUseSSL2CheckboxState = function(checked, disabled) {
220    $('sslUseSSL2').checked = checked;
221    $('sslUseSSL2').disabled = disabled;
222  };
223
224  // Set the checked state for the sslUseSSL3 checkbox.
225  AdvancedOptions.SetUseSSL3CheckboxState = function(checked, disabled) {
226    $('sslUseSSL3').checked = checked;
227    $('sslUseSSL3').disabled = disabled;
228  };
229
230  // Set the checked state for the sslUseTLS1 checkbox.
231  AdvancedOptions.SetUseTLS1CheckboxState = function(checked, disabled) {
232    $('sslUseTLS1').checked = checked;
233    $('sslUseTLS1').disabled = disabled;
234  };
235
236  // Set the Cloud Print proxy UI to enabled, disabled, or processing.
237  AdvancedOptions.SetupCloudPrintProxySection = function(disabled, label) {
238    if (!cr.isChromeOS) {
239      $('cloudPrintProxyLabel').textContent = label;
240      if (disabled) {
241        $('cloudPrintProxySetupButton').textContent =
242          localStrings.getString('cloudPrintProxyDisabledButton');
243        $('cloudPrintProxyManageButton').style.display = 'none';
244      } else {
245        $('cloudPrintProxySetupButton').textContent =
246          localStrings.getString('cloudPrintProxyEnabledButton');
247        $('cloudPrintProxyManageButton').style.display = 'inline';
248      }
249      $('cloudPrintProxySetupButton').disabled = false;
250    }
251  };
252
253  AdvancedOptions.HideCloudPrintProxySection = function() {
254    if (!cr.isChromeOS) {
255      $('cloud-print-proxy-section').style.display = 'none';
256    }
257  };
258
259  // Export
260  return {
261    AdvancedOptions: AdvancedOptions
262  };
263
264});
265