advanced_options.js revision 72a454cd3513ac24fbdd0e0cb9ad70b86a99b801
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
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.advancedPageTabTitle,
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.navigateToPage('content');
34        OptionsPage.showTab($('cookies-nav-tab'));
35        chrome.send('coreOptionsUserMetricsAction',
36            ['Options_ContentSettings']);
37      };
38      $('privacyClearDataButton').onclick = function(event) {
39        OptionsPage.navigateToPage('clearBrowserData');
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      if (!cr.isChromeOS) {
53        $('autoOpenFileTypesResetToDefault').onclick = function(event) {
54          chrome.send('autoOpenFileTypesAction');
55        };
56      }
57
58      $('fontSettingsCustomizeFontsButton').onclick = function(event) {
59        OptionsPage.navigateToPage('fontSettings');
60        chrome.send('coreOptionsUserMetricsAction', ['Options_FontSettings']);
61      };
62      $('defaultFontSize').onchange = function(event) {
63        chrome.send('defaultFontSizeAction',
64            [String(event.target.options[event.target.selectedIndex].value)]);
65      };
66      $('language-button').onclick = function(event) {
67        OptionsPage.navigateToPage('language');
68        chrome.send('coreOptionsUserMetricsAction',
69            ['Options_LanuageAndSpellCheckSettings']);
70      };
71
72      if (cr.isWindows || cr.isMac) {
73        $('certificatesManageButton').onclick = function(event) {
74          chrome.send('showManageSSLCertificates');
75        };
76      } else {
77        $('certificatesManageButton').onclick = function(event) {
78          OptionsPage.navigateToPage('certificateManager');
79          OptionsPage.showTab($('personal-certs-nav-tab'));
80          chrome.send('coreOptionsUserMetricsAction',
81                      ['Options_ManageSSLCertificates']);
82        };
83      }
84
85      if (!cr.isChromeOS) {
86        $('proxiesConfigureButton').onclick = function(event) {
87          chrome.send('showNetworkProxySettings');
88        };
89        $('downloadLocationChangeButton').onclick = function(event) {
90          chrome.send('selectDownloadLocation');
91        };
92
93        // Remove Windows-style accelerators from the Browse button label.
94        // TODO(csilv): Remove this after the accelerator has been removed from
95        // the localized strings file, pending removal of old options window.
96        $('downloadLocationChangeButton').textContent =
97            localStrings.getStringWithoutAccelerator(
98                'downloadLocationChangeButton');
99      } else {
100        $('proxiesConfigureButton').onclick = function(event) {
101          OptionsPage.navigateToPage('proxy');
102          chrome.send('coreOptionsUserMetricsAction',
103              ['Options_ShowProxySettings']);
104        };
105      }
106
107      if (cr.isWindows) {
108        $('sslCheckRevocation').onclick = function(event) {
109          chrome.send('checkRevocationCheckboxAction',
110              [String($('sslCheckRevocation').checked)]);
111        };
112        $('sslUseSSL3').onclick = function(event) {
113          chrome.send('useSSL3CheckboxAction',
114              [String($('sslUseSSL3').checked)]);
115        };
116        $('sslUseTLS1').onclick = function(event) {
117          chrome.send('useTLS1CheckboxAction',
118              [String($('sslUseTLS1').checked)]);
119        };
120        $('gearSettingsConfigureGearsButton').onclick = function(event) {
121          chrome.send('showGearsSettings');
122        };
123      }
124
125      // 'cloudPrintProxyEnabled' is true for Chrome branded builds on
126      // certain platforms, or could be enabled by a lab.
127      if (!cr.isChromeOS &&
128          localStrings.getString('enable-cloud-print-proxy') == 'true') {
129        $('cloudPrintProxySetupButton').onclick = function(event) {
130          if ($('cloudPrintProxyManageButton').style.display == 'none') {
131            // Disable the button, set it's text to the intermediate state.
132            $('cloudPrintProxySetupButton').textContent =
133              localStrings.getString('cloudPrintProxyEnablingButton');
134            $('cloudPrintProxySetupButton').disabled = true;
135            chrome.send('showCloudPrintSetupDialog');
136          } else {
137            chrome.send('disableCloudPrintProxy');
138          }
139        };
140        $('cloudPrintProxyManageButton').onclick = function(event) {
141          chrome.send('showCloudPrintManagePage');
142        };
143      }
144
145      if ($('remotingSetupButton')) {
146          $('remotingSetupButton').onclick = function(event) {
147              chrome.send('showRemotingSetupDialog');
148          }
149          $('remotingStopButton').onclick = function(event) {
150              chrome.send('disableRemoting');
151          }
152      }
153  }
154  };
155
156  //
157  // Chrome callbacks
158  //
159
160  // Set the checked state of the metrics reporting checkbox.
161  AdvancedOptions.SetMetricsReportingCheckboxState = function(
162      checked, disabled) {
163    $('metricsReportingEnabled').checked = checked;
164    $('metricsReportingEnabled').disabled = disabled;
165    if (disabled)
166      $('metricsReportingEnabledText').className = 'disable-services-span';
167  }
168
169  AdvancedOptions.SetMetricsReportingSettingVisibility = function(visible) {
170    if (visible) {
171      $('metricsReportingSetting').style.display = 'block';
172    } else {
173      $('metricsReportingSetting').style.display = 'none';
174    }
175  }
176
177  // Set the font size selected item.
178  AdvancedOptions.SetFontSize = function(fixed_font_size_value,
179      font_size_value) {
180    var selectCtl = $('defaultFontSize');
181    if (fixed_font_size_value == font_size_value) {
182      for (var i = 0; i < selectCtl.options.length; i++) {
183        if (selectCtl.options[i].value == font_size_value) {
184          selectCtl.selectedIndex = i;
185          if ($('Custom'))
186            selectCtl.remove($('Custom').index);
187          return;
188        }
189      }
190    }
191
192    // Add/Select Custom Option in the font size label list.
193    if (!$('Custom')) {
194      var option = new Option(localStrings.getString('fontSizeLabelCustom'),
195                              -1, false, true);
196      option.setAttribute("id", "Custom");
197      selectCtl.add(option);
198    }
199    $('Custom').selected = true;
200  };
201
202  // Set the download path.
203  AdvancedOptions.SetDownloadLocationPath = function(path) {
204    if (!cr.isChromeOS)
205      $('downloadLocationPath').value = path;
206  };
207
208  // Set the enabled state for the autoOpenFileTypesResetToDefault button.
209  AdvancedOptions.SetAutoOpenFileTypesDisabledAttribute = function(disabled) {
210    if (!cr.isChromeOS) {
211      $('autoOpenFileTypesResetToDefault').disabled = disabled;
212
213      if (disabled)
214        $('auto-open-file-types-label').classList.add('disabled');
215      else
216        $('auto-open-file-types-label').classList.remove('disabled');
217    }
218  };
219
220  // Set the enabled state for the proxy settings button.
221  AdvancedOptions.SetupProxySettingsSection = function(disabled, label) {
222    $('proxiesConfigureButton').disabled = disabled;
223    $('proxiesLabel').textContent = label;
224  };
225
226  // Set the checked state for the sslCheckRevocation checkbox.
227  AdvancedOptions.SetCheckRevocationCheckboxState = function(
228      checked, disabled) {
229    $('sslCheckRevocation').checked = checked;
230    $('sslCheckRevocation').disabled = disabled;
231  };
232
233  // Set the checked state for the sslUseSSL3 checkbox.
234  AdvancedOptions.SetUseSSL3CheckboxState = function(checked, disabled) {
235    $('sslUseSSL3').checked = checked;
236    $('sslUseSSL3').disabled = disabled;
237  };
238
239  // Set the checked state for the sslUseTLS1 checkbox.
240  AdvancedOptions.SetUseTLS1CheckboxState = function(checked, disabled) {
241    $('sslUseTLS1').checked = checked;
242    $('sslUseTLS1').disabled = disabled;
243  };
244
245  // Set the Cloud Print proxy UI to enabled, disabled, or processing.
246  AdvancedOptions.SetupCloudPrintProxySection = function(
247        disabled, label, allowed) {
248    if (!cr.isChromeOS) {
249      $('cloudPrintProxyLabel').textContent = label;
250      if (disabled || !allowed) {
251        $('cloudPrintProxySetupButton').textContent =
252          localStrings.getString('cloudPrintProxyDisabledButton');
253        $('cloudPrintProxyManageButton').style.display = 'none';
254      } else {
255        $('cloudPrintProxySetupButton').textContent =
256          localStrings.getString('cloudPrintProxyEnabledButton');
257        $('cloudPrintProxyManageButton').style.display = 'inline';
258      }
259      $('cloudPrintProxySetupButton').disabled = !allowed;
260    }
261  };
262
263  AdvancedOptions.RemoveCloudPrintProxySection = function() {
264    if (!cr.isChromeOS) {
265      var proxySectionElm = $('cloud-print-proxy-section');
266      if (proxySectionElm)
267        proxySectionElm.parentNode.removeChild(proxySectionElm);
268    }
269  };
270
271  AdvancedOptions.SetRemotingStatus = function(enabled, status) {
272    if (enabled) {
273      $('remotingSetupButton').style.display = 'none';
274      $('remotingStopButton').style.display = 'inline';
275    } else {
276      $('remotingSetupButton').style.display = 'inline';
277      $('remotingStopButton').style.display = 'none';
278    }
279    $('remotingStatus').textContent = status;
280  };
281
282  AdvancedOptions.RemoveRemotingSection = function() {
283    var proxySectionElm = $('remoting-section');
284    if (proxySectionElm)
285      proxySectionElm.parentNode.removeChild(proxySectionElm);
286  };
287
288  // Export
289  return {
290    AdvancedOptions: AdvancedOptions
291  };
292
293});
294