advanced_options.js revision dc0f95d653279beabeb9817299e2902918ba123e
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('fonts');
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('languages');
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('certificates');
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        $('promptForDownload').onclick = function(event) {
93          chrome.send('promptForDownloadAction',
94              [String($('promptForDownload').checked)]);
95        };
96
97        // Remove Windows-style accelerators from the Browse button label.
98        // TODO(csilv): Remove this after the accelerator has been removed from
99        // the localized strings file, pending removal of old options window.
100        $('downloadLocationChangeButton').textContent =
101            localStrings.getStringWithoutAccelerator(
102                'downloadLocationChangeButton');
103      } else {
104        $('proxiesConfigureButton').onclick = function(event) {
105          OptionsPage.navigateToPage('proxy');
106          chrome.send('coreOptionsUserMetricsAction',
107              ['Options_ShowProxySettings']);
108        };
109      }
110
111      if (cr.isWindows) {
112        $('sslCheckRevocation').onclick = function(event) {
113          chrome.send('checkRevocationCheckboxAction',
114              [String($('sslCheckRevocation').checked)]);
115        };
116        $('sslUseSSL3').onclick = function(event) {
117          chrome.send('useSSL3CheckboxAction',
118              [String($('sslUseSSL3').checked)]);
119        };
120        $('sslUseTLS1').onclick = function(event) {
121          chrome.send('useTLS1CheckboxAction',
122              [String($('sslUseTLS1').checked)]);
123        };
124        $('gearSettingsConfigureGearsButton').onclick = function(event) {
125          chrome.send('showGearsSettings');
126        };
127      }
128
129      // 'cloudPrintProxyEnabled' is true for Chrome branded builds on
130      // certain platforms, or could be enabled by a lab.
131      if (!cr.isChromeOS) {
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      if ($('remotingSetupButton')) {
149          $('remotingSetupButton').onclick = function(event) {
150              chrome.send('showRemotingSetupDialog');
151          }
152          $('remotingStopButton').onclick = function(event) {
153              chrome.send('disableRemoting');
154          }
155      }
156  }
157  };
158
159  //
160  // Chrome callbacks
161  //
162
163  // Set the checked state of the metrics reporting checkbox.
164  AdvancedOptions.SetMetricsReportingCheckboxState = function(
165      checked, disabled) {
166    $('metricsReportingEnabled').checked = checked;
167    $('metricsReportingEnabled').disabled = disabled;
168    if (disabled)
169      $('metricsReportingEnabledText').className = 'disable-services-span';
170  }
171
172  AdvancedOptions.SetMetricsReportingSettingVisibility = function(visible) {
173    if (visible) {
174      $('metricsReportingSetting').style.display = 'block';
175    } else {
176      $('metricsReportingSetting').style.display = 'none';
177    }
178  }
179
180  // Set the font size selected item.
181  AdvancedOptions.SetFontSize = function(fixed_font_size_value,
182      font_size_value) {
183    var selectCtl = $('defaultFontSize');
184    if (fixed_font_size_value == font_size_value) {
185      for (var i = 0; i < selectCtl.options.length; i++) {
186        if (selectCtl.options[i].value == font_size_value) {
187          selectCtl.selectedIndex = i;
188          if ($('Custom'))
189            selectCtl.remove($('Custom').index);
190          return;
191        }
192      }
193    }
194
195    // Add/Select Custom Option in the font size label list.
196    if (!$('Custom')) {
197      var option = new Option(localStrings.getString('fontSizeLabelCustom'),
198                              -1, false, true);
199      option.setAttribute("id", "Custom");
200      selectCtl.add(option);
201    }
202    $('Custom').selected = true;
203  };
204
205  // Set the download path.
206  AdvancedOptions.SetDownloadLocationPath = function(path, disabled) {
207    if (!cr.isChromeOS)
208      $('downloadLocationPath').value = path;
209      $('downloadLocationChangeButton').disabled = disabled;
210  };
211
212  // Set the prompt for download checkbox.
213  AdvancedOptions.SetPromptForDownload = function(checked, disabled) {
214    $('promptForDownload').checked = checked;
215    $('promptForDownload').disabled = disabled;
216    if (disabled)
217      $('promptForDownloadLabel').className = 'informational-text';
218    else
219      $('promptForDownloadLabel').className = '';
220  };
221
222  // Set the enabled state for the autoOpenFileTypesResetToDefault button.
223  AdvancedOptions.SetAutoOpenFileTypesDisabledAttribute = function(disabled) {
224    if (!cr.isChromeOS) {
225      $('autoOpenFileTypesResetToDefault').disabled = disabled;
226
227      if (disabled)
228        $('auto-open-file-types-label').classList.add('disabled');
229      else
230        $('auto-open-file-types-label').classList.remove('disabled');
231    }
232  };
233
234  // Set the enabled state for the proxy settings button.
235  AdvancedOptions.SetupProxySettingsSection = function(disabled, label) {
236    $('proxiesConfigureButton').disabled = disabled;
237    $('proxiesLabel').textContent = label;
238  };
239
240  // Set the checked state for the sslCheckRevocation checkbox.
241  AdvancedOptions.SetCheckRevocationCheckboxState = function(
242      checked, disabled) {
243    $('sslCheckRevocation').checked = checked;
244    $('sslCheckRevocation').disabled = disabled;
245  };
246
247  // Set the checked state for the sslUseSSL3 checkbox.
248  AdvancedOptions.SetUseSSL3CheckboxState = function(checked, disabled) {
249    $('sslUseSSL3').checked = checked;
250    $('sslUseSSL3').disabled = disabled;
251  };
252
253  // Set the checked state for the sslUseTLS1 checkbox.
254  AdvancedOptions.SetUseTLS1CheckboxState = function(checked, disabled) {
255    $('sslUseTLS1').checked = checked;
256    $('sslUseTLS1').disabled = disabled;
257  };
258
259  // Set the Cloud Print proxy UI to enabled, disabled, or processing.
260  AdvancedOptions.SetupCloudPrintProxySection = function(
261        disabled, label, allowed) {
262    if (!cr.isChromeOS) {
263      $('cloudPrintProxyLabel').textContent = label;
264      if (disabled || !allowed) {
265        $('cloudPrintProxySetupButton').textContent =
266          localStrings.getString('cloudPrintProxyDisabledButton');
267        $('cloudPrintProxyManageButton').style.display = 'none';
268      } else {
269        $('cloudPrintProxySetupButton').textContent =
270          localStrings.getString('cloudPrintProxyEnabledButton');
271        $('cloudPrintProxyManageButton').style.display = 'inline';
272      }
273      $('cloudPrintProxySetupButton').disabled = !allowed;
274    }
275  };
276
277  AdvancedOptions.RemoveCloudPrintProxySection = function() {
278    if (!cr.isChromeOS) {
279      var proxySectionElm = $('cloud-print-proxy-section');
280      if (proxySectionElm)
281        proxySectionElm.parentNode.removeChild(proxySectionElm);
282    }
283  };
284
285  AdvancedOptions.SetRemotingStatus = function(enabled, status) {
286    if (enabled) {
287      $('remotingSetupButton').style.display = 'none';
288      $('remotingStopButton').style.display = 'inline';
289    } else {
290      $('remotingSetupButton').style.display = 'inline';
291      $('remotingStopButton').style.display = 'none';
292    }
293    $('remotingStatus').textContent = status;
294  };
295
296  AdvancedOptions.RemoveRemotingSection = function() {
297    var proxySectionElm = $('remoting-section');
298    if (proxySectionElm)
299      proxySectionElm.parentNode.removeChild(proxySectionElm);
300  };
301
302  // Export
303  return {
304    AdvancedOptions: AdvancedOptions
305  };
306
307});
308