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 // 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 var value = event.target.options[event.target.selectedIndex].value; | |
64 Preferences.setIntegerPref( | |
65 'webkit.webprefs.global.default_fixed_font_size', | |
66 value - OptionsPage.SIZE_DIFFERENCE_FIXED_STANDARD, ''); | |
67 chrome.send('defaultFontSizeAction', [String(value)]); | |
68 }; | |
69 $('defaultZoomFactor').onchange = function(event) { | |
70 chrome.send('defaultZoomFactorAction', | |
71 [String(event.target.options[event.target.selectedIndex].value)]); | |
72 }; | |
73 | |
74 $('language-button').onclick = function(event) { | |
75 OptionsPage.navigateToPage('languages'); | |
76 chrome.send('coreOptionsUserMetricsAction', | |
77 ['Options_LanuageAndSpellCheckSettings']); | |
78 }; | |
79 | |
80 if (cr.isWindows || cr.isMac) { | |
81 $('certificatesManageButton').onclick = function(event) { | |
82 chrome.send('showManageSSLCertificates'); | |
83 }; | |
84 } else { | |
85 $('certificatesManageButton').onclick = function(event) { | |
86 OptionsPage.navigateToPage('certificates'); | |
87 chrome.send('coreOptionsUserMetricsAction', | |
88 ['Options_ManageSSLCertificates']); | |
89 }; | |
90 } | |
91 | |
92 if (!cr.isChromeOS) { | |
93 $('proxiesConfigureButton').onclick = function(event) { | |
94 chrome.send('showNetworkProxySettings'); | |
95 }; | |
96 $('downloadLocationChangeButton').onclick = function(event) { | |
97 chrome.send('selectDownloadLocation'); | |
98 }; | |
99 // This text field is always disabled. Setting ".disabled = true" isn't | |
100 // enough, since a policy can disable it but shouldn't re-enable when | |
101 // it is removed. | |
102 $('downloadLocationPath').setDisabled('readonly', true); | |
103 } | |
104 | |
105 $('sslCheckRevocation').onclick = function(event) { | |
106 chrome.send('checkRevocationCheckboxAction', | |
107 [String($('sslCheckRevocation').checked)]); | |
108 }; | |
109 | |
110 if ($('backgroundModeCheckbox')) { | |
111 cr.defineProperty($('backgroundModeCheckbox'), | |
112 'controlledBy', | |
113 cr.PropertyKind.ATTR); | |
114 $('backgroundModeCheckbox').onclick = function(event) { | |
115 chrome.send('backgroundModeAction', | |
116 [String($('backgroundModeCheckbox').checked)]); | |
117 }; | |
118 } | |
119 | |
120 // 'cloudPrintProxyEnabled' is true for Chrome branded builds on | |
121 // certain platforms, or could be enabled by a lab. | |
122 if (!cr.isChromeOS) { | |
123 $('cloudPrintConnectorSetupButton').onclick = function(event) { | |
124 if ($('cloudPrintManageButton').style.display == 'none') { | |
125 // Disable the button, set it's text to the intermediate state. | |
126 $('cloudPrintConnectorSetupButton').textContent = | |
127 localStrings.getString('cloudPrintConnectorEnablingButton'); | |
128 $('cloudPrintConnectorSetupButton').disabled = true; | |
129 chrome.send('showCloudPrintSetupDialog'); | |
130 } else { | |
131 chrome.send('disableCloudPrintConnector'); | |
132 } | |
133 }; | |
134 } | |
135 $('cloudPrintManageButton').onclick = function(event) { | |
136 chrome.send('showCloudPrintManagePage'); | |
137 }; | |
138 | |
139 } | |
140 }; | |
141 | |
142 // | |
143 // Chrome callbacks | |
144 // | |
145 | |
146 // Set the checked state of the metrics reporting checkbox. | |
147 AdvancedOptions.SetMetricsReportingCheckboxState = function( | |
148 checked, disabled) { | |
149 $('metricsReportingEnabled').checked = checked; | |
150 $('metricsReportingEnabled').disabled = disabled; | |
151 if (disabled) | |
152 $('metricsReportingEnabledText').className = 'disable-services-span'; | |
153 } | |
154 | |
155 AdvancedOptions.SetMetricsReportingSettingVisibility = function(visible) { | |
156 if (visible) { | |
157 $('metricsReportingSetting').style.display = 'block'; | |
158 } else { | |
159 $('metricsReportingSetting').style.display = 'none'; | |
160 } | |
161 } | |
162 | |
163 // Set the font size selected item. | |
164 AdvancedOptions.SetFontSize = function(font_size_value) { | |
165 var selectCtl = $('defaultFontSize'); | |
166 for (var i = 0; i < selectCtl.options.length; i++) { | |
167 if (selectCtl.options[i].value == font_size_value) { | |
168 selectCtl.selectedIndex = i; | |
169 if ($('Custom')) | |
170 selectCtl.remove($('Custom').index); | |
171 return; | |
172 } | |
173 } | |
174 | |
175 // Add/Select Custom Option in the font size label list. | |
176 if (!$('Custom')) { | |
177 var option = new Option(localStrings.getString('fontSizeLabelCustom'), | |
178 -1, false, true); | |
179 option.setAttribute("id", "Custom"); | |
180 selectCtl.add(option); | |
181 } | |
182 $('Custom').selected = true; | |
183 }; | |
184 | |
185 /** | |
186 * Populate the page zoom selector with values received from the caller. | |
187 * @param {Array} items An array of items to populate the selector. | |
188 * each object is an array with three elements as follows: | |
189 * 0: The title of the item (string). | |
190 * 1: The value of the item (number). | |
191 * 2: Whether the item should be selected (boolean). | |
192 */ | |
193 AdvancedOptions.SetupPageZoomSelector = function(items) { | |
194 var element = $('defaultZoomFactor'); | |
195 | |
196 // Remove any existing content. | |
197 element.textContent = ''; | |
198 | |
199 // Insert new child nodes into select element. | |
200 var value, title, selected; | |
201 for (var i = 0; i < items.length; i++) { | |
202 title = items[i][0]; | |
203 value = items[i][1]; | |
204 selected = items[i][2]; | |
205 element.appendChild(new Option(title, value, false, selected)); | |
206 } | |
207 }; | |
208 | |
209 // Set the enabled state for the autoOpenFileTypesResetToDefault button. | |
210 AdvancedOptions.SetAutoOpenFileTypesDisabledAttribute = function(disabled) { | |
211 if (!cr.isChromeOS) { | |
212 $('autoOpenFileTypesResetToDefault').disabled = disabled; | |
213 | |
214 if (disabled) | |
215 $('auto-open-file-types-label').classList.add('disabled'); | |
216 else | |
217 $('auto-open-file-types-label').classList.remove('disabled'); | |
218 } | |
219 }; | |
220 | |
221 // Set the enabled state for the proxy settings button. | |
222 AdvancedOptions.SetupProxySettingsSection = function(disabled, label) { | |
223 if (!cr.isChromeOS) { | |
224 $('proxiesConfigureButton').disabled = disabled; | |
225 $('proxiesLabel').textContent = label; | |
226 } | |
227 }; | |
228 | |
229 // Set the checked state for the sslCheckRevocation checkbox. | |
230 AdvancedOptions.SetCheckRevocationCheckboxState = function( | |
231 checked, disabled) { | |
232 $('sslCheckRevocation').checked = checked; | |
233 $('sslCheckRevocation').disabled = disabled; | |
234 }; | |
235 | |
236 // Set the checked state for the backgroundModeCheckbox element. | |
237 AdvancedOptions.SetBackgroundModeCheckboxState = function( | |
238 checked, disabled, controlled_by) { | |
239 $('backgroundModeCheckbox').checked = checked; | |
240 $('backgroundModeCheckbox').disabled = disabled; | |
241 $('backgroundModeCheckbox').controlledBy = controlled_by; | |
242 OptionsPage.updateManagedBannerVisibility(); | |
243 }; | |
244 | |
245 // Set the Cloud Print proxy UI to enabled, disabled, or processing. | |
246 AdvancedOptions.SetupCloudPrintConnectorSection = function( | |
247 disabled, label, allowed) { | |
248 if (!cr.isChromeOS) { | |
249 $('cloudPrintConnectorLabel').textContent = label; | |
250 if (disabled || !allowed) { | |
251 $('cloudPrintConnectorSetupButton').textContent = | |
252 localStrings.getString('cloudPrintConnectorDisabledButton'); | |
253 $('cloudPrintManageButton').style.display = 'none'; | |
254 } else { | |
255 $('cloudPrintConnectorSetupButton').textContent = | |
256 localStrings.getString('cloudPrintConnectorEnabledButton'); | |
257 $('cloudPrintManageButton').style.display = 'inline'; | |
258 } | |
259 $('cloudPrintConnectorSetupButton').disabled = !allowed; | |
260 } | |
261 }; | |
262 | |
263 AdvancedOptions.RemoveCloudPrintConnectorSection = function() { | |
264 if (!cr.isChromeOS) { | |
265 var connectorSectionElm = $('cloud-print-connector-section'); | |
266 if (connectorSectionElm) | |
267 connectorSectionElm.parentNode.removeChild(connectorSectionElm); | |
268 } | |
269 }; | |
270 | |
271 // Export | |
272 return { | |
273 AdvancedOptions: AdvancedOptions | |
274 }; | |
275 | |
276 }); | |
OLD | NEW |