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