OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 $('advanced-section-back-button').onclick = | |
32 OptionsPage.navigateToPage.bind(OptionsPage, this.parentPage.name); | |
33 | |
34 // Date and time section (CrOS only). | |
35 if (cr.isChromeOS && AccountsOptions.loggedInAsGuest()) { | |
36 // Disable time-related settings if we're not logged in as a real user. | |
37 $('timezone-select').disabled = true; | |
38 $('use-24hour-clock').disabled = true; | |
39 } | |
40 | |
41 // Privacy section. | |
42 $('privacyContentSettingsButton').onclick = function(event) { | |
43 OptionsPage.navigateToPage('content'); | |
44 OptionsPage.showTab($('cookies-nav-tab')); | |
45 chrome.send('coreOptionsUserMetricsAction', | |
46 ['Options_ContentSettings']); | |
47 }; | |
48 $('privacyClearDataButton').onclick = function(event) { | |
49 OptionsPage.navigateToPage('clearBrowserData'); | |
50 chrome.send('coreOptionsUserMetricsAction', ['Options_ClearData']); | |
51 }; | |
52 // 'metricsReportingEnabled' element is only present on Chrome branded | |
53 // builds. | |
54 if ($('metricsReportingEnabled')) { | |
55 $('metricsReportingEnabled').onclick = function(event) { | |
56 chrome.send('metricsReportingCheckboxAction', | |
57 [String(event.target.checked)]); | |
58 }; | |
59 } | |
60 | |
61 // Bluetooth (CrOS only). | |
62 if (cr.isChromeOS) { | |
63 options.system.bluetooth.BluetoothDeviceList.decorate( | |
64 $('bluetooth-paired-devices-list')); | |
65 | |
66 $('bluetooth-add-device').onclick = function(event) { | |
67 findBluetoothDevices_(true); | |
68 OptionsPage.navigateToPage('bluetooth'); | |
69 }; | |
70 | |
71 $('enable-bluetooth').onchange = function(event) { | |
72 var state = $('enable-bluetooth').checked; | |
73 chrome.send('bluetoothEnableChange', [Boolean(state)]); | |
74 }; | |
75 | |
76 $('bluetooth-reconnect-device').onclick = function(event) { | |
77 var device = $('bluetooth-paired-devices-list').selectedItem; | |
78 var address = device.address; | |
79 chrome.send('updateBluetoothDevice', [address, 'connect']); | |
80 OptionsPage.closeOverlay(); | |
81 }; | |
82 | |
83 $('bluetooth-reconnect-device').onmousedown = function(event) { | |
84 // Prevent 'blur' event, which would reset the list selection, | |
85 // thereby disabling the apply button. | |
86 event.preventDefault(); | |
87 }; | |
88 | |
89 $('bluetooth-paired-devices-list').addEventListener('change', | |
90 function() { | |
91 var item = $('bluetooth-paired-devices-list').selectedItem; | |
92 var disabled = !item || !item.paired || item.connected; | |
93 $('bluetooth-reconnect-device').disabled = disabled; | |
94 }); | |
95 } | |
96 | |
97 // Passwords and Forms section. | |
98 $('autofill-settings').onclick = function(event) { | |
99 OptionsPage.navigateToPage('autofill'); | |
100 chrome.send('coreOptionsUserMetricsAction', | |
101 ['Options_ShowAutofillSettings']); | |
102 }; | |
103 $('manage-passwords').onclick = function(event) { | |
104 OptionsPage.navigateToPage('passwords'); | |
105 OptionsPage.showTab($('passwords-nav-tab')); | |
106 chrome.send('coreOptionsUserMetricsAction', | |
107 ['Options_ShowPasswordManager']); | |
108 }; | |
109 if (AdvancedOptions.GuestModeActive()) { | |
110 // Disable and turn off Autofill in guest mode. | |
111 var autofillEnabled = $('autofill-enabled'); | |
112 autofillEnabled.disabled = true; | |
113 autofillEnabled.checked = false; | |
114 cr.dispatchSimpleEvent(autofillEnabled, 'change'); | |
115 $('autofill-settings').disabled = true; | |
116 | |
117 // Disable and turn off Password Manager in guest mode. | |
118 var passwordManagerEnabled = $('password-manager-enabled'); | |
119 passwordManagerEnabled.disabled = true; | |
120 passwordManagerEnabled.checked = false; | |
121 cr.dispatchSimpleEvent(passwordManagerEnabled, 'change'); | |
122 $('manage-passwords').disabled = true; | |
123 | |
124 // Hide the entire section on ChromeOS | |
125 if (cr.isChromeOS) | |
126 $('passwords-and-autofill-section').hidden = true; | |
127 } | |
128 $('mac-passwords-warning').hidden = | |
129 !(localStrings.getString('macPasswordsWarning')); | |
130 | |
131 // Network section. | |
132 if (!cr.isChromeOS) { | |
133 $('proxiesConfigureButton').onclick = function(event) { | |
134 chrome.send('showNetworkProxySettings'); | |
135 }; | |
136 } | |
137 | |
138 // Web Content section. | |
139 $('fontSettingsCustomizeFontsButton').onclick = function(event) { | |
140 OptionsPage.navigateToPage('fonts'); | |
141 chrome.send('coreOptionsUserMetricsAction', ['Options_FontSettings']); | |
142 }; | |
143 $('defaultFontSize').onchange = function(event) { | |
144 var value = event.target.options[event.target.selectedIndex].value; | |
145 Preferences.setIntegerPref( | |
146 'webkit.webprefs.global.default_fixed_font_size', | |
147 value - OptionsPage.SIZE_DIFFERENCE_FIXED_STANDARD, ''); | |
148 chrome.send('defaultFontSizeAction', [String(value)]); | |
149 }; | |
150 $('defaultZoomFactor').onchange = function(event) { | |
151 chrome.send('defaultZoomFactorAction', | |
152 [String(event.target.options[event.target.selectedIndex].value)]); | |
153 }; | |
154 | |
155 // Languages section. | |
156 $('language-button').onclick = function(event) { | |
157 OptionsPage.navigateToPage('languages'); | |
158 chrome.send('coreOptionsUserMetricsAction', | |
159 ['Options_LanuageAndSpellCheckSettings']); | |
160 }; | |
161 | |
162 // Downloads section. | |
163 if (!cr.isChromeOS) { | |
164 $('downloadLocationChangeButton').onclick = function(event) { | |
165 chrome.send('selectDownloadLocation'); | |
166 }; | |
167 // This text field is always disabled. Setting ".disabled = true" isn't | |
168 // enough, since a policy can disable it but shouldn't re-enable when | |
169 // it is removed. | |
170 $('downloadLocationPath').setDisabled('readonly', true); | |
171 $('autoOpenFileTypesResetToDefault').onclick = function(event) { | |
172 chrome.send('autoOpenFileTypesAction'); | |
173 }; | |
174 } | |
175 | |
176 // HTTPS/SSL section. | |
177 if (cr.isWindows || cr.isMac) { | |
178 $('certificatesManageButton').onclick = function(event) { | |
179 chrome.send('showManageSSLCertificates'); | |
180 }; | |
181 } else { | |
182 $('certificatesManageButton').onclick = function(event) { | |
183 OptionsPage.navigateToPage('certificates'); | |
184 chrome.send('coreOptionsUserMetricsAction', | |
185 ['Options_ManageSSLCertificates']); | |
186 }; | |
187 } | |
188 $('sslCheckRevocation').onclick = function(event) { | |
189 chrome.send('checkRevocationCheckboxAction', | |
190 [String($('sslCheckRevocation').checked)]); | |
191 }; | |
192 | |
193 // Cloud Print section. | |
194 // 'cloudPrintProxyEnabled' is true for Chrome branded builds on | |
195 // certain platforms, or could be enabled by a lab. | |
196 if (!cr.isChromeOS) { | |
197 $('cloudPrintConnectorSetupButton').onclick = function(event) { | |
198 if ($('cloudPrintManageButton').style.display == 'none') { | |
199 // Disable the button, set it's text to the intermediate state. | |
200 $('cloudPrintConnectorSetupButton').textContent = | |
201 localStrings.getString('cloudPrintConnectorEnablingButton'); | |
202 $('cloudPrintConnectorSetupButton').disabled = true; | |
203 chrome.send('showCloudPrintSetupDialog'); | |
204 } else { | |
205 chrome.send('disableCloudPrintConnector'); | |
206 } | |
207 }; | |
208 } | |
209 $('cloudPrintManageButton').onclick = function(event) { | |
210 chrome.send('showCloudPrintManagePage'); | |
211 }; | |
212 | |
213 // Accessibility section (CrOS only). | |
214 if (cr.isChromeOS) { | |
215 $('accessibility-spoken-feedback-check').onchange = function(event) { | |
216 chrome.send('spokenFeedbackChange', | |
217 [$('accessibility-spoken-feedback-check').checked]); | |
218 }; | |
219 } | |
220 | |
221 // Background mode section. | |
222 if ($('backgroundModeCheckbox')) { | |
223 $('backgroundModeCheckbox').onclick = function(event) { | |
224 chrome.send('backgroundModeAction', | |
225 [String($('backgroundModeCheckbox').checked)]); | |
226 }; | |
227 } | |
228 } | |
229 }; | |
230 | |
231 /** | |
232 * Scan for bluetooth devices. | |
233 * @param {boolean} reset Indicates if the list of unpaired devices should be | |
234 * cleared. | |
235 * @private | |
236 */ | |
237 function findBluetoothDevices_(reset) { | |
238 $('bluetooth-unpaired-devices-list').clear(); | |
239 chrome.send('findBluetoothDevices'); | |
240 } | |
241 | |
242 // | |
243 // Chrome callbacks | |
244 // | |
245 | |
246 // Set the checked state of the metrics reporting checkbox. | |
247 AdvancedOptions.SetMetricsReportingCheckboxState = function( | |
248 checked, disabled) { | |
249 $('metricsReportingEnabled').checked = checked; | |
250 $('metricsReportingEnabled').disabled = disabled; | |
251 if (disabled) | |
252 $('metricsReportingEnabledText').className = 'disable-services-span'; | |
253 }; | |
254 | |
255 AdvancedOptions.SetMetricsReportingSettingVisibility = function(visible) { | |
256 if (visible) { | |
257 $('metricsReportingSetting').style.display = 'block'; | |
258 } else { | |
259 $('metricsReportingSetting').style.display = 'none'; | |
260 } | |
261 }; | |
262 | |
263 /** | |
264 * Returns whether the browser in guest mode. Some features are disabled or | |
265 * hidden in guest mode. | |
266 * @return {boolean} True if guest mode is currently active. | |
267 */ | |
268 AdvancedOptions.GuestModeActive = function() { | |
269 return cr.commandLine && cr.commandLine.options['--bwsi']; | |
270 }; | |
271 | |
272 // Set the font size selected item. | |
273 AdvancedOptions.SetFontSize = function(font_size_value) { | |
274 var selectCtl = $('defaultFontSize'); | |
275 for (var i = 0; i < selectCtl.options.length; i++) { | |
276 if (selectCtl.options[i].value == font_size_value) { | |
277 selectCtl.selectedIndex = i; | |
278 if ($('Custom')) | |
279 selectCtl.remove($('Custom').index); | |
280 return; | |
281 } | |
282 } | |
283 | |
284 // Add/Select Custom Option in the font size label list. | |
285 if (!$('Custom')) { | |
286 var option = new Option(localStrings.getString('fontSizeLabelCustom'), | |
287 -1, false, true); | |
288 option.setAttribute('id', 'Custom'); | |
289 selectCtl.add(option); | |
290 } | |
291 $('Custom').selected = true; | |
292 }; | |
293 | |
294 /** | |
295 * Populate the page zoom selector with values received from the caller. | |
296 * @param {Array} items An array of items to populate the selector. | |
297 * each object is an array with three elements as follows: | |
298 * 0: The title of the item (string). | |
299 * 1: The value of the item (number). | |
300 * 2: Whether the item should be selected (boolean). | |
301 */ | |
302 AdvancedOptions.SetupPageZoomSelector = function(items) { | |
303 var element = $('defaultZoomFactor'); | |
304 | |
305 // Remove any existing content. | |
306 element.textContent = ''; | |
307 | |
308 // Insert new child nodes into select element. | |
309 var value, title, selected; | |
310 for (var i = 0; i < items.length; i++) { | |
311 title = items[i][0]; | |
312 value = items[i][1]; | |
313 selected = items[i][2]; | |
314 element.appendChild(new Option(title, value, false, selected)); | |
315 } | |
316 }; | |
317 | |
318 // Set the enabled state for the autoOpenFileTypesResetToDefault button. | |
319 AdvancedOptions.SetAutoOpenFileTypesDisabledAttribute = function(disabled) { | |
320 if (!cr.isChromeOS) { | |
321 $('autoOpenFileTypesResetToDefault').disabled = disabled; | |
322 | |
323 if (disabled) | |
324 $('auto-open-file-types-label').classList.add('disabled'); | |
325 else | |
326 $('auto-open-file-types-label').classList.remove('disabled'); | |
327 } | |
328 }; | |
329 | |
330 // Set the enabled state for the proxy settings button. | |
331 AdvancedOptions.SetupProxySettingsSection = function(disabled, label) { | |
332 if (!cr.isChromeOS) { | |
333 $('proxiesConfigureButton').disabled = disabled; | |
334 $('proxiesLabel').textContent = label; | |
335 } | |
336 }; | |
337 | |
338 // Set the checked state for the sslCheckRevocation checkbox. | |
339 AdvancedOptions.SetCheckRevocationCheckboxState = function( | |
340 checked, disabled) { | |
341 $('sslCheckRevocation').checked = checked; | |
342 $('sslCheckRevocation').disabled = disabled; | |
343 }; | |
344 | |
345 // Set the checked state for the backgroundModeCheckbox element. | |
346 AdvancedOptions.SetBackgroundModeCheckboxState = function(checked) { | |
347 $('backgroundModeCheckbox').checked = checked; | |
348 }; | |
349 | |
350 // Set the Cloud Print proxy UI to enabled, disabled, or processing. | |
351 AdvancedOptions.SetupCloudPrintConnectorSection = function( | |
352 disabled, label, allowed) { | |
353 if (!cr.isChromeOS) { | |
354 $('cloudPrintConnectorLabel').textContent = label; | |
355 if (disabled || !allowed) { | |
356 $('cloudPrintConnectorSetupButton').textContent = | |
357 localStrings.getString('cloudPrintConnectorDisabledButton'); | |
358 $('cloudPrintManageButton').style.display = 'none'; | |
359 } else { | |
360 $('cloudPrintConnectorSetupButton').textContent = | |
361 localStrings.getString('cloudPrintConnectorEnabledButton'); | |
362 $('cloudPrintManageButton').style.display = 'inline'; | |
363 } | |
364 $('cloudPrintConnectorSetupButton').disabled = !allowed; | |
365 } | |
366 }; | |
367 | |
368 AdvancedOptions.RemoveCloudPrintConnectorSection = function() { | |
369 if (!cr.isChromeOS) { | |
370 var connectorSectionElm = $('cloud-print-connector-section'); | |
371 if (connectorSectionElm) | |
372 connectorSectionElm.parentNode.removeChild(connectorSectionElm); | |
373 } | |
374 }; | |
375 | |
376 /** | |
377 * Set the initial state of the spoken feedback checkbox. | |
378 */ | |
379 AdvancedOptions.setSpokenFeedbackCheckboxState = function(checked) { | |
380 $('accessibility-spoken-feedback-check').checked = checked; | |
381 }; | |
382 | |
383 /** | |
384 * Set the initial state of the high contrast checkbox. | |
385 */ | |
386 AdvancedOptions.setHighContrastCheckboxState = function(checked) { | |
387 // TODO(zork): Update UI | |
388 }; | |
389 | |
390 /** | |
391 * Set the initial state of the screen magnifier checkbox. | |
392 */ | |
393 AdvancedOptions.setScreenMagnifierCheckboxState = function(checked) { | |
394 // TODO(zork): Update UI | |
395 }; | |
396 | |
397 /** | |
398 * Set the initial state of the virtual keyboard checkbox. | |
399 */ | |
400 AdvancedOptions.setVirtualKeyboardCheckboxState = function(checked) { | |
401 // TODO(zork): Update UI | |
402 }; | |
403 | |
404 /** | |
405 * Activate the bluetooth settings section on the System settings page. | |
406 */ | |
407 AdvancedOptions.showBluetoothSettings = function() { | |
408 $('bluetooth-devices').hidden = false; | |
409 }; | |
410 | |
411 /** | |
412 * Sets the state of the checkbox indicating if bluetooth is turned on. The | |
413 * state of the "Find devices" button and the list of discovered devices may | |
414 * also be affected by a change to the state. | |
415 * @param {boolean} checked Flag Indicating if Bluetooth is turned on. | |
416 */ | |
417 AdvancedOptions.setBluetoothState = function(checked) { | |
418 $('enable-bluetooth').checked = checked; | |
419 $('bluetooth-paired-devices-list').parentNode.hidden = !checked; | |
420 $('bluetooth-add-device').hidden = !checked; | |
421 $('bluetooth-reconnect-device').hidden = !checked; | |
422 // Flush list of previously discovered devices if bluetooth is turned off. | |
423 if (!checked) { | |
424 $('bluetooth-paired-devices-list').clear(); | |
425 $('bluetooth-unpaired-devices-list').clear(); | |
426 } else { | |
427 chrome.send('getPairedBluetoothDevices'); | |
428 } | |
429 } | |
430 | |
431 /** | |
432 * Adds an element to the list of available bluetooth devices. If an element | |
433 * with a matching address is found, the existing element is updated. | |
434 * @param {{name: string, | |
435 * address: string, | |
436 * icon: string, | |
437 * paired: boolean, | |
438 * connected: boolean}} device | |
439 * Decription of the bluetooth device. | |
440 */ | |
441 AdvancedOptions.addBluetoothDevice = function(device) { | |
442 var list = $('bluetooth-unpaired-devices-list'); | |
443 if (device.paired) { | |
444 // Test to see if the device is currently in the unpaired list, in which | |
445 // case it should be removed from that list. | |
446 var index = $('bluetooth-unpaired-devices-list').find(device.address); | |
447 if (index != undefined) | |
448 $('bluetooth-unpaired-devices-list').deleteItemAtIndex(index); | |
449 list = $('bluetooth-paired-devices-list'); | |
450 } | |
451 list.appendDevice(device); | |
452 | |
453 // One device can be in the process of pairing. If found, display | |
454 // the Bluetooth pairing overlay. | |
455 if (device.pairing) | |
456 BluetoothPairing.showDialog(device); | |
457 }; | |
458 | |
459 // Export | |
460 return { | |
461 AdvancedOptions: AdvancedOptions | |
462 }; | |
463 | |
464 }); | |
OLD | NEW |