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 var OptionsPage = options.OptionsPage; | |
7 var ArrayDataModel = cr.ui.ArrayDataModel; | |
8 var RepeatingButton = cr.ui.RepeatingButton; | |
9 | |
10 // | |
11 // BrowserOptions class | |
12 // Encapsulated handling of browser options page. | |
13 // | |
14 function BrowserOptions() { | |
15 OptionsPage.call(this, 'settings', loadTimeData.getString('settingsTitle'), | |
16 'settings'); | |
17 } | |
18 | |
19 cr.addSingletonGetter(BrowserOptions); | |
20 | |
21 BrowserOptions.prototype = { | |
22 __proto__: options.OptionsPage.prototype, | |
23 | |
24 // State variables. | |
25 syncSetupCompleted: false, | |
26 | |
27 /** | |
28 * The cached value of the instant.confirm_dialog_shown preference. | |
29 * @type {bool} | |
30 * @private | |
31 */ | |
32 instantConfirmDialogShown_: false, | |
33 | |
34 /** | |
35 * The cached value of the spellcheck.confirm_dialog_shown preference. | |
36 * @type {bool} | |
37 * @private | |
38 */ | |
39 spellcheckConfirmDialogShown_: false, | |
40 | |
41 /** | |
42 * Keeps track of whether |onShowHomeButtonChanged_| has been called. See | |
43 * |onShowHomeButtonChanged_|. | |
44 * @type {bool} | |
45 * @private | |
46 */ | |
47 onShowHomeButtonChangedCalled_: false, | |
48 | |
49 /** | |
50 * @inheritDoc | |
51 */ | |
52 initializePage: function() { | |
53 OptionsPage.prototype.initializePage.call(this); | |
54 var self = this; | |
55 | |
56 // Ensure that navigation events are unblocked on uber page. A reload of | |
57 // the settings page while an overlay is open would otherwise leave uber | |
58 // page in a blocked state, where tab switching is not possible. | |
59 uber.invokeMethodOnParent('stopInterceptingEvents'); | |
60 | |
61 window.addEventListener('message', this.handleWindowMessage_.bind(this)); | |
62 | |
63 $('advanced-settings-expander').onclick = function() { | |
64 self.toggleSectionWithAnimation_( | |
65 $('advanced-settings'), | |
66 $('advanced-settings-container')); | |
67 | |
68 // If the link was focused (i.e., it was activated using the keyboard) | |
69 // and it was used to show the section (rather than hiding it), focus | |
70 // the first element in the container. | |
71 if (document.activeElement === $('advanced-settings-expander') && | |
72 $('advanced-settings').style.height === '') { | |
73 var focusElement = $('advanced-settings-container').querySelector( | |
74 'button, input, list, select, a[href]'); | |
75 if (focusElement) | |
76 focusElement.focus(); | |
77 } | |
78 } | |
79 | |
80 $('advanced-settings').addEventListener('webkitTransitionEnd', | |
81 this.updateAdvancedSettingsExpander_.bind(this)); | |
82 | |
83 if (cr.isChromeOS) | |
84 UIAccountTweaks.applyGuestModeVisibility(document); | |
85 | |
86 // Sync (Sign in) section. | |
87 this.updateSyncState_(loadTimeData.getValue('syncData')); | |
88 | |
89 $('sync-action-link').onclick = function(event) { | |
90 if (cr.isChromeOS) { | |
91 // On Chrome OS, sign out the user and sign in again to get fresh | |
92 // credentials on auth errors. | |
93 SyncSetupOverlay.doSignOutOnAuthError(); | |
94 } else { | |
95 SyncSetupOverlay.showErrorUI(); | |
96 } | |
97 }; | |
98 $('start-stop-sync').onclick = function(event) { | |
99 if (self.syncSetupCompleted) | |
100 SyncSetupOverlay.showStopSyncingUI(); | |
101 else if (cr.isChromeOS) | |
102 SyncSetupOverlay.showSetupUIWithoutLogin(); | |
103 else | |
104 SyncSetupOverlay.showSetupUI(); | |
105 }; | |
106 $('customize-sync').onclick = function(event) { | |
107 if (cr.isChromeOS) | |
108 SyncSetupOverlay.showSetupUIWithoutLogin(); | |
109 else | |
110 SyncSetupOverlay.showSetupUI(); | |
111 }; | |
112 | |
113 // Internet connection section (ChromeOS only). | |
114 if (cr.isChromeOS) { | |
115 options.network.NetworkList.decorate($('network-list')); | |
116 options.network.NetworkList.refreshNetworkData( | |
117 loadTimeData.getValue('networkData')); | |
118 } | |
119 | |
120 // On Startup section. | |
121 Preferences.getInstance().addEventListener('session.restore_on_startup', | |
122 this.onRestoreOnStartupChanged_.bind(this)); | |
123 | |
124 $('startup-set-pages').onclick = function() { | |
125 OptionsPage.navigateToPage('startup'); | |
126 }; | |
127 | |
128 // Appearance section. | |
129 Preferences.getInstance().addEventListener('browser.show_home_button', | |
130 this.onShowHomeButtonChanged_.bind(this)); | |
131 | |
132 Preferences.getInstance().addEventListener('homepage', | |
133 this.onHomePageChanged_.bind(this)); | |
134 Preferences.getInstance().addEventListener('homepage_is_newtabpage', | |
135 this.onHomePageIsNtpChanged_.bind(this)); | |
136 | |
137 $('change-home-page').onclick = function(event) { | |
138 OptionsPage.navigateToPage('homePageOverlay'); | |
139 }; | |
140 | |
141 if ($('set-wallpaper')) { | |
142 $('set-wallpaper').onclick = function(event) { | |
143 chrome.send('openWallpaperManager'); | |
144 }; | |
145 } | |
146 | |
147 $('themes-gallery').onclick = function(event) { | |
148 window.open(loadTimeData.getString('themesGalleryURL')); | |
149 }; | |
150 $('themes-reset').onclick = function(event) { | |
151 chrome.send('themesReset'); | |
152 }; | |
153 | |
154 // Device section (ChromeOS only). | |
155 if (cr.isChromeOS) { | |
156 $('keyboard-settings-button').onclick = function(evt) { | |
157 OptionsPage.navigateToPage('keyboard-overlay'); | |
158 }; | |
159 $('pointer-settings-button').onclick = function(evt) { | |
160 OptionsPage.navigateToPage('pointer-overlay'); | |
161 }; | |
162 } | |
163 | |
164 // Search section. | |
165 $('manage-default-search-engines').onclick = function(event) { | |
166 OptionsPage.navigateToPage('searchEngines'); | |
167 chrome.send('coreOptionsUserMetricsAction', | |
168 ['Options_ManageSearchEngines']); | |
169 }; | |
170 $('default-search-engine').addEventListener('change', | |
171 this.setDefaultSearchEngine_); | |
172 $('instant-enabled-control').customChangeHandler = function(event) { | |
173 if (this.checked && !self.instantConfirmDialogShown_) { | |
174 OptionsPage.showPageByName('instantConfirm', false); | |
175 return true; // Stop default preference processing. | |
176 } | |
177 return false; // Allow default preference processing. | |
178 }; | |
179 Preferences.getInstance().addEventListener('instant.confirm_dialog_shown', | |
180 this.onInstantConfirmDialogShownChanged_.bind(this)); | |
181 | |
182 // Users section. | |
183 if (loadTimeData.valueExists('profilesInfo')) { | |
184 $('profiles-section').hidden = false; | |
185 | |
186 var profilesList = $('profiles-list'); | |
187 options.browser_options.ProfileList.decorate(profilesList); | |
188 profilesList.autoExpands = true; | |
189 | |
190 this.setProfilesInfo_(loadTimeData.getValue('profilesInfo')); | |
191 | |
192 profilesList.addEventListener('change', | |
193 this.setProfileViewButtonsStatus_); | |
194 $('profiles-create').onclick = function(event) { | |
195 chrome.send('createProfileInfo'); | |
196 }; | |
197 $('profiles-manage').onclick = function(event) { | |
198 ManageProfileOverlay.showManageDialog(); | |
199 }; | |
200 $('profiles-delete').onclick = function(event) { | |
201 var selectedProfile = self.getSelectedProfileItem_(); | |
202 if (selectedProfile) | |
203 ManageProfileOverlay.showDeleteDialog(selectedProfile); | |
204 }; | |
205 } | |
206 | |
207 if (cr.isChromeOS) { | |
208 if (!UIAccountTweaks.loggedInAsGuest()) { | |
209 $('account-picture-wrapper').onclick = function(event) { | |
210 OptionsPage.navigateToPage('changePicture'); | |
211 }; | |
212 } | |
213 | |
214 // Username (canonical email) of the currently logged in user or | |
215 // |kGuestUser| if a guest session is active. | |
216 this.username_ = loadTimeData.getString('username'); | |
217 | |
218 this.updateAccountPicture_(); | |
219 | |
220 $('manage-accounts-button').onclick = function(event) { | |
221 OptionsPage.navigateToPage('accounts'); | |
222 chrome.send('coreOptionsUserMetricsAction', | |
223 ['Options_ManageAccounts']); | |
224 }; | |
225 } else { | |
226 $('import-data').onclick = function(event) { | |
227 ImportDataOverlay.show(); | |
228 chrome.send('coreOptionsUserMetricsAction', ['Import_ShowDlg']); | |
229 }; | |
230 | |
231 if ($('themes-GTK-button')) { | |
232 $('themes-GTK-button').onclick = function(event) { | |
233 chrome.send('themesSetGTK'); | |
234 }; | |
235 } | |
236 } | |
237 | |
238 // Default browser section. | |
239 if (!cr.isChromeOS) { | |
240 $('set-as-default-browser').onclick = function(event) { | |
241 chrome.send('becomeDefaultBrowser'); | |
242 }; | |
243 | |
244 $('auto-launch').onclick = this.handleAutoLaunchChanged_; | |
245 } | |
246 | |
247 // Privacy section. | |
248 $('privacyContentSettingsButton').onclick = function(event) { | |
249 OptionsPage.navigateToPage('content'); | |
250 OptionsPage.showTab($('cookies-nav-tab')); | |
251 chrome.send('coreOptionsUserMetricsAction', | |
252 ['Options_ContentSettings']); | |
253 }; | |
254 $('privacyClearDataButton').onclick = function(event) { | |
255 OptionsPage.navigateToPage('clearBrowserData'); | |
256 chrome.send('coreOptionsUserMetricsAction', ['Options_ClearData']); | |
257 }; | |
258 // 'spelling-enabled-control' element is only present on Chrome branded | |
259 // builds. | |
260 if ($('spelling-enabled-control')) { | |
261 $('spelling-enabled-control').customChangeHandler = function(event) { | |
262 if (this.checked && !self.spellcheckConfirmDialogShown_) { | |
263 OptionsPage.showPageByName('spellingConfirm', false); | |
264 return true; | |
265 } | |
266 return false; | |
267 }; | |
268 Preferences.getInstance().addEventListener( | |
269 'spellcheck.confirm_dialog_shown', | |
270 this.onSpellcheckConfirmDialogShownChanged_.bind(this)); | |
271 } | |
272 // 'metricsReportingEnabled' element is only present on Chrome branded | |
273 // builds. | |
274 if ($('metricsReportingEnabled')) { | |
275 $('metricsReportingEnabled').onclick = function(event) { | |
276 chrome.send('metricsReportingCheckboxAction', | |
277 [String(event.target.checked)]); | |
278 }; | |
279 } | |
280 | |
281 // Bluetooth (CrOS only). | |
282 if (cr.isChromeOS) { | |
283 options.system.bluetooth.BluetoothDeviceList.decorate( | |
284 $('bluetooth-paired-devices-list')); | |
285 | |
286 $('bluetooth-add-device').onclick = | |
287 this.handleAddBluetoothDevice_.bind(this); | |
288 | |
289 $('enable-bluetooth').onchange = function(event) { | |
290 var state = $('enable-bluetooth').checked; | |
291 chrome.send('bluetoothEnableChange', [Boolean(state)]); | |
292 }; | |
293 | |
294 $('bluetooth-reconnect-device').onclick = function(event) { | |
295 var device = $('bluetooth-paired-devices-list').selectedItem; | |
296 var address = device.address; | |
297 chrome.send('updateBluetoothDevice', [address, 'connect']); | |
298 OptionsPage.closeOverlay(); | |
299 }; | |
300 | |
301 $('bluetooth-reconnect-device').onmousedown = function(event) { | |
302 // Prevent 'blur' event, which would reset the list selection, | |
303 // thereby disabling the apply button. | |
304 event.preventDefault(); | |
305 }; | |
306 | |
307 $('bluetooth-paired-devices-list').addEventListener('change', | |
308 function() { | |
309 var item = $('bluetooth-paired-devices-list').selectedItem; | |
310 var disabled = !item || item.connected; | |
311 $('bluetooth-reconnect-device').disabled = disabled; | |
312 }); | |
313 } | |
314 | |
315 // Passwords and Forms section. | |
316 $('autofill-settings').onclick = function(event) { | |
317 OptionsPage.navigateToPage('autofill'); | |
318 chrome.send('coreOptionsUserMetricsAction', | |
319 ['Options_ShowAutofillSettings']); | |
320 }; | |
321 $('manage-passwords').onclick = function(event) { | |
322 OptionsPage.navigateToPage('passwords'); | |
323 OptionsPage.showTab($('passwords-nav-tab')); | |
324 chrome.send('coreOptionsUserMetricsAction', | |
325 ['Options_ShowPasswordManager']); | |
326 }; | |
327 if (cr.isChromeOS && UIAccountTweaks.loggedInAsGuest()) { | |
328 // Disable and turn off Autofill in guest mode. | |
329 var autofillEnabled = $('autofill-enabled'); | |
330 autofillEnabled.disabled = true; | |
331 autofillEnabled.checked = false; | |
332 cr.dispatchSimpleEvent(autofillEnabled, 'change'); | |
333 $('autofill-settings').disabled = true; | |
334 | |
335 // Disable and turn off Password Manager in guest mode. | |
336 var passwordManagerEnabled = $('password-manager-enabled'); | |
337 passwordManagerEnabled.disabled = true; | |
338 passwordManagerEnabled.checked = false; | |
339 cr.dispatchSimpleEvent(passwordManagerEnabled, 'change'); | |
340 $('manage-passwords').disabled = true; | |
341 } | |
342 | |
343 if (cr.isMac) { | |
344 $('mac-passwords-warning').hidden = | |
345 !loadTimeData.getBoolean('multiple_profiles'); | |
346 } | |
347 | |
348 // Network section. | |
349 if (!cr.isChromeOS) { | |
350 $('proxiesConfigureButton').onclick = function(event) { | |
351 chrome.send('showNetworkProxySettings'); | |
352 }; | |
353 } | |
354 | |
355 // Web Content section. | |
356 $('fontSettingsCustomizeFontsButton').onclick = function(event) { | |
357 OptionsPage.navigateToPage('fonts'); | |
358 chrome.send('coreOptionsUserMetricsAction', ['Options_FontSettings']); | |
359 }; | |
360 $('defaultFontSize').onchange = function(event) { | |
361 var value = event.target.options[event.target.selectedIndex].value; | |
362 Preferences.setIntegerPref( | |
363 'webkit.webprefs.default_fixed_font_size', | |
364 value - OptionsPage.SIZE_DIFFERENCE_FIXED_STANDARD, ''); | |
365 chrome.send('defaultFontSizeAction', [String(value)]); | |
366 }; | |
367 $('defaultZoomFactor').onchange = function(event) { | |
368 chrome.send('defaultZoomFactorAction', | |
369 [String(event.target.options[event.target.selectedIndex].value)]); | |
370 }; | |
371 | |
372 // Languages section. | |
373 $('language-button').onclick = function(event) { | |
374 OptionsPage.navigateToPage('languages'); | |
375 chrome.send('coreOptionsUserMetricsAction', | |
376 ['Options_LanuageAndSpellCheckSettings']); | |
377 }; | |
378 | |
379 // Downloads section. | |
380 Preferences.getInstance().addEventListener('download.default_directory', | |
381 this.onDefaultDownloadDirectoryChanged_.bind(this)); | |
382 $('downloadLocationChangeButton').onclick = function(event) { | |
383 chrome.send('selectDownloadLocation'); | |
384 }; | |
385 if (!cr.isChromeOS) { | |
386 $('autoOpenFileTypesResetToDefault').onclick = function(event) { | |
387 chrome.send('autoOpenFileTypesAction'); | |
388 }; | |
389 } | |
390 | |
391 // HTTPS/SSL section. | |
392 if (cr.isWindows || cr.isMac) { | |
393 $('certificatesManageButton').onclick = function(event) { | |
394 chrome.send('showManageSSLCertificates'); | |
395 }; | |
396 } else { | |
397 $('certificatesManageButton').onclick = function(event) { | |
398 OptionsPage.navigateToPage('certificates'); | |
399 chrome.send('coreOptionsUserMetricsAction', | |
400 ['Options_ManageSSLCertificates']); | |
401 }; | |
402 } | |
403 $('sslCheckRevocation').onclick = function(event) { | |
404 chrome.send('checkRevocationCheckboxAction', | |
405 [String($('sslCheckRevocation').checked)]); | |
406 }; | |
407 | |
408 // Cloud Print section. | |
409 // 'cloudPrintProxyEnabled' is true for Chrome branded builds on | |
410 // certain platforms, or could be enabled by a lab. | |
411 if (!cr.isChromeOS) { | |
412 $('cloudPrintConnectorSetupButton').onclick = function(event) { | |
413 if ($('cloudPrintManageButton').style.display == 'none') { | |
414 // Disable the button, set its text to the intermediate state. | |
415 $('cloudPrintConnectorSetupButton').textContent = | |
416 loadTimeData.getString('cloudPrintConnectorEnablingButton'); | |
417 $('cloudPrintConnectorSetupButton').disabled = true; | |
418 chrome.send('showCloudPrintSetupDialog'); | |
419 } else { | |
420 chrome.send('disableCloudPrintConnector'); | |
421 } | |
422 }; | |
423 } | |
424 $('cloudPrintManageButton').onclick = function(event) { | |
425 chrome.send('showCloudPrintManagePage'); | |
426 }; | |
427 | |
428 // Accessibility section (CrOS only). | |
429 if (cr.isChromeOS) { | |
430 $('accessibility-spoken-feedback-check').onchange = function(event) { | |
431 chrome.send('spokenFeedbackChange', | |
432 [$('accessibility-spoken-feedback-check').checked]); | |
433 }; | |
434 | |
435 $('accessibility-high-contrast-check').onchange = function(event) { | |
436 chrome.send('highContrastChange', | |
437 [$('accessibility-high-contrast-check').checked]); | |
438 }; | |
439 | |
440 $('accessibility-screen-magnifier-check').onchange = function(event) { | |
441 chrome.send('screenMagnifierChange', | |
442 [$('accessibility-screen-magnifier-check').checked]); | |
443 }; | |
444 } | |
445 | |
446 // Display management section (CrOS only). | |
447 if (cr.isChromeOS) { | |
448 $('display-options-button').onclick = function(event) { | |
449 OptionsPage.navigateToPage('display'); | |
450 chrome.send('coreOptionsUserMetricsAction', | |
451 ['Options_Display']); | |
452 } | |
453 } | |
454 | |
455 // Background mode section. | |
456 if ($('backgroundModeCheckbox')) { | |
457 cr.defineProperty($('backgroundModeCheckbox'), | |
458 'controlledBy', | |
459 cr.PropertyKind.ATTR); | |
460 $('backgroundModeCheckbox').onclick = function(event) { | |
461 chrome.send('backgroundModeAction', | |
462 [String($('backgroundModeCheckbox').checked)]); | |
463 }; | |
464 } | |
465 }, | |
466 | |
467 /** | |
468 * @inheritDoc | |
469 */ | |
470 didShowPage: function() { | |
471 $('search-field').focus(); | |
472 }, | |
473 | |
474 /** | |
475 * Event listener for the 'session.restore_on_startup' pref. | |
476 * @param {Event} event The preference change event. | |
477 * @private | |
478 */ | |
479 onRestoreOnStartupChanged_: function(event) { | |
480 /** @const */ var showPagesValue = Number($('startup-show-pages').value); | |
481 /** @const */ var showHomePageValue = 0; | |
482 | |
483 $('startup-set-pages').disabled = event.value.disabled && | |
484 event.value.value != showPagesValue; | |
485 | |
486 if (event.value.value == showHomePageValue) { | |
487 // If the user previously selected "Show the homepage", the | |
488 // preference will already be migrated to "Open a specific page". So | |
489 // the only way to reach this code is if the 'restore on startup' | |
490 // preference is managed. | |
491 assert(event.value.controlledBy); | |
492 | |
493 // Select "open the following pages" and lock down the list of URLs | |
494 // to reflect the intention of the policy. | |
495 $('startup-show-pages').checked = true; | |
496 StartupOverlay.getInstance().setControlsDisabled(true); | |
497 } else { | |
498 // Re-enable the controls in the startup overlay if necessary. | |
499 StartupOverlay.getInstance().updateControlStates(); | |
500 } | |
501 }, | |
502 | |
503 /** | |
504 * Handler for messages sent from the main uber page. | |
505 * @param {Event} e The 'message' event from the uber page. | |
506 * @private | |
507 */ | |
508 handleWindowMessage_: function(e) { | |
509 if (e.data.method == 'frameSelected') | |
510 $('search-field').focus(); | |
511 }, | |
512 | |
513 /** | |
514 * Shows the given section, with animation. | |
515 * @param {HTMLElement} section The section to be shown. | |
516 * @param {HTMLElement} container The container for the section. Must be | |
517 * inside of |section|. | |
518 * @private | |
519 */ | |
520 showSectionWithAnimation_: function(section, container) { | |
521 this.addTransitionEndListener_(section); | |
522 | |
523 // Unhide | |
524 section.hidden = false; | |
525 | |
526 // Delay starting the transition so that hidden change will be | |
527 // processed. | |
528 setTimeout(function() { | |
529 // Reveal the section using a WebKit transition. | |
530 section.classList.add('sliding'); | |
531 section.style.height = | |
532 container.offsetHeight + 'px'; | |
533 }, 0); | |
534 }, | |
535 | |
536 /** | |
537 * See showSectionWithAnimation_. | |
538 */ | |
539 hideSectionWithAnimation_: function(section, container) { | |
540 this.addTransitionEndListener_(section); | |
541 | |
542 // Before we start hiding the section, we need to set | |
543 // the height to a pixel value. | |
544 section.style.height = container.offsetHeight + 'px'; | |
545 | |
546 // Delay starting the transition so that the height change will be | |
547 // processed. | |
548 setTimeout(function() { | |
549 // Hide the section using a WebKit transition. | |
550 section.classList.add('sliding'); | |
551 section.style.height = ''; | |
552 }, 0); | |
553 }, | |
554 | |
555 /** | |
556 * See showSectionWithAnimation_. | |
557 */ | |
558 toggleSectionWithAnimation_: function(section, container) { | |
559 if (section.style.height == '') | |
560 this.showSectionWithAnimation_(section, container); | |
561 else | |
562 this.hideSectionWithAnimation_(section, container); | |
563 }, | |
564 | |
565 /** | |
566 * Adds a |webkitTransitionEnd| listener to the given section so that | |
567 * it can be animated. The listener will only be added to a given section | |
568 * once, so this can be called as multiple times. | |
569 * @param {HTMLElement} section The section to be animated. | |
570 * @private | |
571 */ | |
572 addTransitionEndListener_: function(section) { | |
573 if (section.hasTransitionEndListener_) | |
574 return; | |
575 | |
576 section.addEventListener('webkitTransitionEnd', | |
577 this.onTransitionEnd_.bind(this)); | |
578 section.hasTransitionEndListener_ = true; | |
579 }, | |
580 | |
581 /** | |
582 * Called after an animation transition has ended. | |
583 * @private | |
584 */ | |
585 onTransitionEnd_: function(event) { | |
586 if (event.propertyName != 'height') | |
587 return; | |
588 | |
589 var section = event.target; | |
590 | |
591 // Disable WebKit transitions. | |
592 section.classList.remove('sliding'); | |
593 | |
594 if (section.style.height == '') { | |
595 // Hide the content so it can't get tab focus. | |
596 section.hidden = true; | |
597 } else { | |
598 // Set the section height to 'auto' to allow for size changes | |
599 // (due to font change or dynamic content). | |
600 section.style.height = 'auto'; | |
601 } | |
602 }, | |
603 | |
604 updateAdvancedSettingsExpander_: function() { | |
605 var expander = $('advanced-settings-expander'); | |
606 if ($('advanced-settings').style.height == '') | |
607 expander.textContent = loadTimeData.getString('showAdvancedSettings'); | |
608 else | |
609 expander.textContent = loadTimeData.getString('hideAdvancedSettings'); | |
610 }, | |
611 | |
612 /** | |
613 * Updates the sync section with the given state. | |
614 * @param {Object} syncData A bunch of data records that describe the status | |
615 * of the sync system. | |
616 * @private | |
617 */ | |
618 updateSyncState_: function(syncData) { | |
619 if (!syncData.syncSystemEnabled) { | |
620 $('sync-section').hidden = true; | |
621 return; | |
622 } | |
623 | |
624 $('sync-section').hidden = false; | |
625 this.syncSetupCompleted = syncData.setupCompleted; | |
626 $('customize-sync').hidden = !syncData.setupCompleted; | |
627 | |
628 var startStopButton = $('start-stop-sync'); | |
629 startStopButton.disabled = syncData.managed || | |
630 syncData.setupInProgress; | |
631 startStopButton.hidden = | |
632 syncData.setupCompleted && cr.isChromeOS; | |
633 startStopButton.textContent = | |
634 syncData.setupCompleted ? | |
635 loadTimeData.getString('syncButtonTextStop') : | |
636 syncData.setupInProgress ? | |
637 loadTimeData.getString('syncButtonTextInProgress') : | |
638 loadTimeData.getString('syncButtonTextStart'); | |
639 | |
640 | |
641 // TODO(estade): can this just be textContent? | |
642 $('sync-status-text').innerHTML = syncData.statusText; | |
643 var statusSet = syncData.statusText.length != 0; | |
644 $('sync-overview').hidden = statusSet; | |
645 $('sync-status').hidden = !statusSet; | |
646 | |
647 $('sync-action-link').textContent = syncData.actionLinkText; | |
648 $('sync-action-link').hidden = syncData.actionLinkText.length == 0; | |
649 $('sync-action-link').disabled = syncData.managed; | |
650 | |
651 if (syncData.hasError) | |
652 $('sync-status').classList.add('sync-error'); | |
653 else | |
654 $('sync-status').classList.remove('sync-error'); | |
655 | |
656 $('customize-sync').disabled = syncData.hasUnrecoverableError; | |
657 // Move #enable-auto-login-checkbox to a different location on CrOS. | |
658 if (cr.isChromeOs) { | |
659 $('sync-general').insertBefore($('sync-status').nextSibling, | |
660 $('enable-auto-login-checkbox')); | |
661 } | |
662 $('enable-auto-login-checkbox').hidden = !syncData.autoLoginVisible; | |
663 }, | |
664 | |
665 /** | |
666 * Get the start/stop sync button DOM element. Used for testing. | |
667 * @return {DOMElement} The start/stop sync button. | |
668 * @private | |
669 */ | |
670 getStartStopSyncButton_: function() { | |
671 return $('start-stop-sync'); | |
672 }, | |
673 | |
674 /** | |
675 * Event listener for the 'show home button' preference. Shows/hides the | |
676 * UI for changing the home page with animation, unless this is the first | |
677 * time this function is called, in which case there is no animation. | |
678 * @param {Event} event The preference change event. | |
679 */ | |
680 onShowHomeButtonChanged_: function(event) { | |
681 var section = $('change-home-page-section'); | |
682 if (this.onShowHomeButtonChangedCalled_) { | |
683 var container = $('change-home-page-section-container'); | |
684 if (event.value.value) | |
685 this.showSectionWithAnimation_(section, container); | |
686 else | |
687 this.hideSectionWithAnimation_(section, container); | |
688 } else { | |
689 section.hidden = !event.value.value; | |
690 this.onShowHomeButtonChangedCalled_ = true; | |
691 } | |
692 }, | |
693 | |
694 /** | |
695 * Event listener for the 'homepage is NTP' preference. Updates the label | |
696 * next to the 'Change' button. | |
697 * @param {Event} event The preference change event. | |
698 */ | |
699 onHomePageIsNtpChanged_: function(event) { | |
700 $('home-page-url').hidden = event.value.value; | |
701 $('home-page-ntp').hidden = !event.value.value; | |
702 }, | |
703 | |
704 /** | |
705 * Event listener for changes to the homepage preference. Updates the label | |
706 * next to the 'Change' button. | |
707 * @param {Event} event The preference change event. | |
708 */ | |
709 onHomePageChanged_: function(event) { | |
710 $('home-page-url').textContent = this.stripHttp_(event.value.value); | |
711 }, | |
712 | |
713 /** | |
714 * Removes the 'http://' from a URL, like the omnibox does. If the string | |
715 * doesn't start with 'http://' it is returned unchanged. | |
716 * @param {string} url The url to be processed | |
717 * @return {string} The url with the 'http://' removed. | |
718 */ | |
719 stripHttp_: function(url) { | |
720 return url.replace(/^http:\/\//, ''); | |
721 }, | |
722 | |
723 /** | |
724 * Shows the autoLaunch preference and initializes its checkbox value. | |
725 * @param {bool} enabled Whether autolaunch is enabled or or not. | |
726 * @private | |
727 */ | |
728 updateAutoLaunchState_: function(enabled) { | |
729 $('auto-launch-option').hidden = false; | |
730 $('auto-launch').checked = enabled; | |
731 }, | |
732 | |
733 /** | |
734 * Called when the value of the instant.confirm_dialog_shown preference | |
735 * changes. Cache this value. | |
736 * @param {Event} event Change event. | |
737 * @private | |
738 */ | |
739 onInstantConfirmDialogShownChanged_: function(event) { | |
740 this.instantConfirmDialogShown_ = event.value.value; | |
741 }, | |
742 | |
743 /** | |
744 * Called when the value of the spellcheck.confirm_dialog_shown preference | |
745 * changes. Cache this value. | |
746 * @param {Event} event Change event. | |
747 * @private | |
748 */ | |
749 onSpellcheckConfirmDialogShownChanged_: function(event) { | |
750 this.spellcheckConfirmDialogShown_ = event.value.value; | |
751 }, | |
752 | |
753 /** | |
754 * Called when the value of the download.default_directory preference | |
755 * changes. | |
756 * @param {Event} event Change event. | |
757 * @private | |
758 */ | |
759 onDefaultDownloadDirectoryChanged_: function(event) { | |
760 $('downloadLocationPath').value = event.value.value; | |
761 if (cr.isChromeOS) { | |
762 // On ChromeOS, strip out /special for drive paths, and | |
763 // /home/chronos/user for local files. | |
764 $('downloadLocationPath').value = $('downloadLocationPath').value. | |
765 replace(/^\/(special|home\/chronos\/user)/, ''); | |
766 } | |
767 }, | |
768 | |
769 /** | |
770 * Update the Default Browsers section based on the current state. | |
771 * @param {string} statusString Description of the current default state. | |
772 * @param {boolean} isDefault Whether or not the browser is currently | |
773 * default. | |
774 * @param {boolean} canBeDefault Whether or not the browser can be default. | |
775 * @private | |
776 */ | |
777 updateDefaultBrowserState_: function(statusString, isDefault, | |
778 canBeDefault) { | |
779 if (!cr.isChromeOS) { | |
780 var label = $('default-browser-state'); | |
781 label.textContent = statusString; | |
782 | |
783 $('set-as-default-browser').hidden = !canBeDefault || isDefault; | |
784 } | |
785 }, | |
786 | |
787 /** | |
788 * Clears the search engine popup. | |
789 * @private | |
790 */ | |
791 clearSearchEngines_: function() { | |
792 $('default-search-engine').textContent = ''; | |
793 }, | |
794 | |
795 /** | |
796 * Updates the search engine popup with the given entries. | |
797 * @param {Array} engines List of available search engines. | |
798 * @param {number} defaultValue The value of the current default engine. | |
799 * @param {boolean} defaultManaged Whether the default search provider is | |
800 * managed. If true, the default search provider can't be changed. | |
801 * @private | |
802 */ | |
803 updateSearchEngines_: function(engines, defaultValue, defaultManaged) { | |
804 this.clearSearchEngines_(); | |
805 engineSelect = $('default-search-engine'); | |
806 engineSelect.disabled = defaultManaged; | |
807 engineCount = engines.length; | |
808 var defaultIndex = -1; | |
809 for (var i = 0; i < engineCount; i++) { | |
810 var engine = engines[i]; | |
811 var option = new Option(engine['name'], engine['index']); | |
812 if (defaultValue == option.value) | |
813 defaultIndex = i; | |
814 engineSelect.appendChild(option); | |
815 } | |
816 if (defaultIndex >= 0) | |
817 engineSelect.selectedIndex = defaultIndex; | |
818 }, | |
819 | |
820 /** | |
821 * Set the default search engine based on the popup selection. | |
822 * @private | |
823 */ | |
824 setDefaultSearchEngine_: function() { | |
825 var engineSelect = $('default-search-engine'); | |
826 var selectedIndex = engineSelect.selectedIndex; | |
827 if (selectedIndex >= 0) { | |
828 var selection = engineSelect.options[selectedIndex]; | |
829 chrome.send('setDefaultSearchEngine', [String(selection.value)]); | |
830 } | |
831 }, | |
832 | |
833 /** | |
834 * Sets or clear whether Chrome should Auto-launch on computer startup. | |
835 * @private | |
836 */ | |
837 handleAutoLaunchChanged_: function() { | |
838 chrome.send('toggleAutoLaunch', [$('auto-launch').checked]); | |
839 }, | |
840 | |
841 /** | |
842 * Get the selected profile item from the profile list. This also works | |
843 * correctly if the list is not displayed. | |
844 * @return {Object} the profile item object, or null if nothing is selected. | |
845 * @private | |
846 */ | |
847 getSelectedProfileItem_: function() { | |
848 var profilesList = $('profiles-list'); | |
849 if (profilesList.hidden) { | |
850 if (profilesList.dataModel.length > 0) | |
851 return profilesList.dataModel.item(0); | |
852 } else { | |
853 return profilesList.selectedItem; | |
854 } | |
855 return null; | |
856 }, | |
857 | |
858 /** | |
859 * Helper function to set the status of profile view buttons to disabled or | |
860 * enabled, depending on the number of profiles and selection status of the | |
861 * profiles list. | |
862 * @private | |
863 */ | |
864 setProfileViewButtonsStatus_: function() { | |
865 var profilesList = $('profiles-list'); | |
866 var selectedProfile = profilesList.selectedItem; | |
867 var hasSelection = selectedProfile != null; | |
868 var hasSingleProfile = profilesList.dataModel.length == 1; | |
869 $('profiles-manage').disabled = !hasSelection || | |
870 !selectedProfile.isCurrentProfile; | |
871 if (hasSelection && !selectedProfile.isCurrentProfile) | |
872 $('profiles-manage').title = loadTimeData.getString('currentUserOnly'); | |
873 else | |
874 $('profiles-manage').title = ''; | |
875 $('profiles-delete').disabled = !hasSelection && !hasSingleProfile; | |
876 var importData = $('import-data'); | |
877 if (importData) { | |
878 importData.disabled = $('import-data').disabled = hasSelection && | |
879 !selectedProfile.isCurrentProfile; | |
880 } | |
881 }, | |
882 | |
883 /** | |
884 * Display the correct dialog layout, depending on how many profiles are | |
885 * available. | |
886 * @param {number} numProfiles The number of profiles to display. | |
887 * @private | |
888 */ | |
889 setProfileViewSingle_: function(numProfiles) { | |
890 var hasSingleProfile = numProfiles == 1; | |
891 $('profiles-list').hidden = hasSingleProfile; | |
892 $('profiles-single-message').hidden = !hasSingleProfile; | |
893 $('profiles-manage').hidden = hasSingleProfile; | |
894 $('profiles-delete').textContent = hasSingleProfile ? | |
895 loadTimeData.getString('profilesDeleteSingle') : | |
896 loadTimeData.getString('profilesDelete'); | |
897 }, | |
898 | |
899 /** | |
900 * Adds all |profiles| to the list. | |
901 * @param {Array.<Object>} profiles An array of profile info objects. | |
902 * each object is of the form: | |
903 * profileInfo = { | |
904 * name: "Profile Name", | |
905 * iconURL: "chrome://path/to/icon/image", | |
906 * filePath: "/path/to/profile/data/on/disk", | |
907 * isCurrentProfile: false | |
908 * }; | |
909 * @private | |
910 */ | |
911 setProfilesInfo_: function(profiles) { | |
912 this.setProfileViewSingle_(profiles.length); | |
913 // add it to the list, even if the list is hidden so we can access it | |
914 // later. | |
915 $('profiles-list').dataModel = new ArrayDataModel(profiles); | |
916 | |
917 // Received new data. If showing the "manage" overlay, keep it up to | |
918 // date. If showing the "delete" overlay, close it. | |
919 if (ManageProfileOverlay.getInstance().visible && | |
920 !$('manage-profile-overlay-manage').hidden) { | |
921 ManageProfileOverlay.showManageDialog(); | |
922 } else { | |
923 ManageProfileOverlay.getInstance().visible = false; | |
924 } | |
925 | |
926 this.setProfileViewButtonsStatus_(); | |
927 }, | |
928 | |
929 /** | |
930 * Returns the currently active profile for this browser window. | |
931 * @return {Object} A profile info object. | |
932 * @private | |
933 */ | |
934 getCurrentProfile_: function() { | |
935 for (var i = 0; i < $('profiles-list').dataModel.length; i++) { | |
936 var profile = $('profiles-list').dataModel.item(i); | |
937 if (profile.isCurrentProfile) | |
938 return profile; | |
939 } | |
940 | |
941 assert(false, | |
942 'There should always be a current profile, but none found.'); | |
943 }, | |
944 | |
945 setGtkThemeButtonEnabled_: function(enabled) { | |
946 if (!cr.isChromeOS && navigator.platform.match(/linux|BSD/i)) | |
947 $('themes-GTK-button').disabled = !enabled; | |
948 }, | |
949 | |
950 setThemesResetButtonEnabled_: function(enabled) { | |
951 $('themes-reset').disabled = !enabled; | |
952 }, | |
953 | |
954 /** | |
955 * (Re)loads IMG element with current user account picture. | |
956 * @private | |
957 */ | |
958 updateAccountPicture_: function() { | |
959 var picture = $('account-picture'); | |
960 if (picture) { | |
961 picture.src = 'chrome://userimage/' + this.username_ + '?id=' + | |
962 Date.now(); | |
963 } | |
964 }, | |
965 | |
966 /** | |
967 * Handle the 'add device' button click. | |
968 * @private | |
969 */ | |
970 handleAddBluetoothDevice_: function() { | |
971 $('bluetooth-unpaired-devices-list').clear(); | |
972 chrome.send('findBluetoothDevices'); | |
973 OptionsPage.showPageByName('bluetooth', false); | |
974 }, | |
975 | |
976 /** | |
977 * Set the checked state of the metrics reporting checkbox. | |
978 * @private | |
979 */ | |
980 setMetricsReportingCheckboxState_: function(checked, disabled) { | |
981 $('metricsReportingEnabled').checked = checked; | |
982 $('metricsReportingEnabled').disabled = disabled; | |
983 }, | |
984 | |
985 /** | |
986 * @private | |
987 */ | |
988 setMetricsReportingSettingVisibility_: function(visible) { | |
989 if (visible) | |
990 $('metricsReportingSetting').style.display = 'block'; | |
991 else | |
992 $('metricsReportingSetting').style.display = 'none'; | |
993 }, | |
994 | |
995 /** | |
996 * Set the visibility of the password generation checkbox. | |
997 * @private | |
998 */ | |
999 setPasswordGenerationSettingVisibility_: function(visible) { | |
1000 if (visible) | |
1001 $('password-generation-checkbox').style.display = 'block'; | |
1002 else | |
1003 $('password-generation-checkbox').style.display = 'none'; | |
1004 }, | |
1005 | |
1006 /** | |
1007 * Set the font size selected item. | |
1008 * @private | |
1009 */ | |
1010 setFontSize_: function(font_size_value) { | |
1011 var selectCtl = $('defaultFontSize'); | |
1012 for (var i = 0; i < selectCtl.options.length; i++) { | |
1013 if (selectCtl.options[i].value == font_size_value) { | |
1014 selectCtl.selectedIndex = i; | |
1015 if ($('Custom')) | |
1016 selectCtl.remove($('Custom').index); | |
1017 return; | |
1018 } | |
1019 } | |
1020 | |
1021 // Add/Select Custom Option in the font size label list. | |
1022 if (!$('Custom')) { | |
1023 var option = new Option(loadTimeData.getString('fontSizeLabelCustom'), | |
1024 -1, false, true); | |
1025 option.setAttribute('id', 'Custom'); | |
1026 selectCtl.add(option); | |
1027 } | |
1028 $('Custom').selected = true; | |
1029 }, | |
1030 | |
1031 /** | |
1032 * Populate the page zoom selector with values received from the caller. | |
1033 * @param {Array} items An array of items to populate the selector. | |
1034 * each object is an array with three elements as follows: | |
1035 * 0: The title of the item (string). | |
1036 * 1: The value of the item (number). | |
1037 * 2: Whether the item should be selected (boolean). | |
1038 * @private | |
1039 */ | |
1040 setupPageZoomSelector_: function(items) { | |
1041 var element = $('defaultZoomFactor'); | |
1042 | |
1043 // Remove any existing content. | |
1044 element.textContent = ''; | |
1045 | |
1046 // Insert new child nodes into select element. | |
1047 var value, title, selected; | |
1048 for (var i = 0; i < items.length; i++) { | |
1049 title = items[i][0]; | |
1050 value = items[i][1]; | |
1051 selected = items[i][2]; | |
1052 element.appendChild(new Option(title, value, false, selected)); | |
1053 } | |
1054 }, | |
1055 | |
1056 /** | |
1057 * Shows/hides the autoOpenFileTypesResetToDefault button and label, with | |
1058 * animation. | |
1059 * @param {boolean} display Whether to show the button and label or not. | |
1060 * @private | |
1061 */ | |
1062 setAutoOpenFileTypesDisplayed_: function(display) { | |
1063 if (cr.isChromeOS) | |
1064 return; | |
1065 | |
1066 if ($('advanced-settings').hidden) { | |
1067 // If the Advanced section is hidden, don't animate the transition. | |
1068 $('auto-open-file-types-section').hidden = !display; | |
1069 } else { | |
1070 if (display) { | |
1071 this.showSectionWithAnimation_( | |
1072 $('auto-open-file-types-section'), | |
1073 $('auto-open-file-types-container')); | |
1074 } else { | |
1075 this.hideSectionWithAnimation_( | |
1076 $('auto-open-file-types-section'), | |
1077 $('auto-open-file-types-container')); | |
1078 } | |
1079 } | |
1080 }, | |
1081 | |
1082 /** | |
1083 * Set the enabled state for the proxy settings button. | |
1084 * @private | |
1085 */ | |
1086 setupProxySettingsSection_: function(disabled, label) { | |
1087 if (!cr.isChromeOS) { | |
1088 $('proxiesConfigureButton').disabled = disabled; | |
1089 $('proxiesLabel').textContent = label; | |
1090 } | |
1091 }, | |
1092 | |
1093 /** | |
1094 * Set the checked state for the sslCheckRevocation checkbox. | |
1095 * @private | |
1096 */ | |
1097 setCheckRevocationCheckboxState_: function(checked, disabled) { | |
1098 $('sslCheckRevocation').checked = checked; | |
1099 $('sslCheckRevocation').disabled = disabled; | |
1100 }, | |
1101 | |
1102 /** | |
1103 * Set the checked state for the backgroundModeCheckbox element. | |
1104 * @private | |
1105 */ | |
1106 setBackgroundModeCheckboxState_: function( | |
1107 checked, disabled, controlled_by) { | |
1108 $('backgroundModeCheckbox').checked = checked; | |
1109 $('backgroundModeCheckbox').disabled = disabled; | |
1110 $('backgroundModeCheckbox').controlledBy = controlled_by; | |
1111 OptionsPage.updateManagedBannerVisibility(); | |
1112 }, | |
1113 | |
1114 /** | |
1115 * Set the Cloud Print proxy UI to enabled, disabled, or processing. | |
1116 * @private | |
1117 */ | |
1118 setupCloudPrintConnectorSection_: function(disabled, label, allowed) { | |
1119 if (!cr.isChromeOS) { | |
1120 $('cloudPrintConnectorLabel').textContent = label; | |
1121 if (disabled || !allowed) { | |
1122 $('cloudPrintConnectorSetupButton').textContent = | |
1123 loadTimeData.getString('cloudPrintConnectorDisabledButton'); | |
1124 $('cloudPrintManageButton').style.display = 'none'; | |
1125 } else { | |
1126 $('cloudPrintConnectorSetupButton').textContent = | |
1127 loadTimeData.getString('cloudPrintConnectorEnabledButton'); | |
1128 $('cloudPrintManageButton').style.display = 'inline'; | |
1129 } | |
1130 $('cloudPrintConnectorSetupButton').disabled = !allowed; | |
1131 } | |
1132 }, | |
1133 | |
1134 /** | |
1135 * @private | |
1136 */ | |
1137 removeCloudPrintConnectorSection_: function() { | |
1138 if (!cr.isChromeOS) { | |
1139 var connectorSectionElm = $('cloud-print-connector-section'); | |
1140 if (connectorSectionElm) | |
1141 connectorSectionElm.parentNode.removeChild(connectorSectionElm); | |
1142 } | |
1143 }, | |
1144 | |
1145 /** | |
1146 * Set the initial state of the spoken feedback checkbox. | |
1147 * @private | |
1148 */ | |
1149 setSpokenFeedbackCheckboxState_: function(checked) { | |
1150 $('accessibility-spoken-feedback-check').checked = checked; | |
1151 }, | |
1152 | |
1153 /** | |
1154 * Set the initial state of the high contrast checkbox. | |
1155 * @private | |
1156 */ | |
1157 setHighContrastCheckboxState_: function(checked) { | |
1158 $('accessibility-high-contrast-check').checked = checked; | |
1159 }, | |
1160 | |
1161 /** | |
1162 * Set the initial state of the screen magnifier checkbox. | |
1163 * @private | |
1164 */ | |
1165 setScreenMagnifierCheckboxState_: function(checked) { | |
1166 $('accessibility-screen-magnifier-check').checked = checked; | |
1167 }, | |
1168 | |
1169 /** | |
1170 * Set the initial state of the virtual keyboard checkbox. | |
1171 * @private | |
1172 */ | |
1173 setVirtualKeyboardCheckboxState_: function(checked) { | |
1174 // TODO(zork): Update UI | |
1175 }, | |
1176 | |
1177 /** | |
1178 * Show/hide mouse settings slider. | |
1179 * @private | |
1180 */ | |
1181 showMouseControls_: function(show) { | |
1182 $('mouse-settings').hidden = !show; | |
1183 }, | |
1184 | |
1185 /** | |
1186 * Show/hide touchpad settings slider. | |
1187 * @private | |
1188 */ | |
1189 showTouchpadControls_: function(show) { | |
1190 $('touchpad-settings').hidden = !show; | |
1191 }, | |
1192 | |
1193 /** | |
1194 * Show/hide the display options button on the System settings page. | |
1195 * @private | |
1196 */ | |
1197 showDisplayOptions_: function(show) { | |
1198 $('display-options-section').hidden = !show; | |
1199 }, | |
1200 | |
1201 /** | |
1202 * Activate the bluetooth settings section on the System settings page. | |
1203 * @private | |
1204 */ | |
1205 showBluetoothSettings_: function() { | |
1206 $('bluetooth-devices').hidden = false; | |
1207 }, | |
1208 | |
1209 /** | |
1210 * Dectivates the bluetooth settings section from the System settings page. | |
1211 * @private | |
1212 */ | |
1213 hideBluetoothSettings_: function() { | |
1214 $('bluetooth-devices').hidden = true; | |
1215 }, | |
1216 | |
1217 /** | |
1218 * Sets the state of the checkbox indicating if bluetooth is turned on. The | |
1219 * state of the "Find devices" button and the list of discovered devices may | |
1220 * also be affected by a change to the state. | |
1221 * @param {boolean} checked Flag Indicating if Bluetooth is turned on. | |
1222 * @private | |
1223 */ | |
1224 setBluetoothState_: function(checked) { | |
1225 $('enable-bluetooth').checked = checked; | |
1226 $('bluetooth-paired-devices-list').parentNode.hidden = !checked; | |
1227 $('bluetooth-add-device').hidden = !checked; | |
1228 $('bluetooth-reconnect-device').hidden = !checked; | |
1229 // Flush list of previously discovered devices if bluetooth is turned off. | |
1230 if (!checked) { | |
1231 $('bluetooth-paired-devices-list').clear(); | |
1232 $('bluetooth-unpaired-devices-list').clear(); | |
1233 } else { | |
1234 chrome.send('getPairedBluetoothDevices'); | |
1235 } | |
1236 }, | |
1237 | |
1238 /** | |
1239 * Adds an element to the list of available bluetooth devices. If an element | |
1240 * with a matching address is found, the existing element is updated. | |
1241 * @param {{name: string, | |
1242 * address: string, | |
1243 * paired: boolean, | |
1244 * bonded: boolean, | |
1245 * connected: boolean}} device | |
1246 * Decription of the bluetooth device. | |
1247 * @private | |
1248 */ | |
1249 addBluetoothDevice_: function(device) { | |
1250 var list = $('bluetooth-unpaired-devices-list'); | |
1251 if (device.paired) { | |
1252 // Test to see if the device is currently in the unpaired list, in which | |
1253 // case it should be removed from that list. | |
1254 var index = $('bluetooth-unpaired-devices-list').find(device.address); | |
1255 if (index != undefined) | |
1256 $('bluetooth-unpaired-devices-list').deleteItemAtIndex(index); | |
1257 list = $('bluetooth-paired-devices-list'); | |
1258 } else { | |
1259 // Test to see if the device is currently in the paired list, in which | |
1260 // case it should be removed from that list. | |
1261 var index = $('bluetooth-paired-devices-list').find(device.address); | |
1262 if (index != undefined) | |
1263 $('bluetooth-paired-devices-list').deleteItemAtIndex(index); | |
1264 } | |
1265 list.appendDevice(device); | |
1266 | |
1267 // One device can be in the process of pairing. If found, display | |
1268 // the Bluetooth pairing overlay. | |
1269 if (device.pairing) | |
1270 BluetoothPairing.showDialog(device); | |
1271 }, | |
1272 | |
1273 /** | |
1274 * Removes an element from the list of available devices. | |
1275 * @param {string} address Unique address of the device. | |
1276 * @private | |
1277 */ | |
1278 removeBluetoothDevice_: function(address) { | |
1279 var index = $('bluetooth-unpaired-devices-list').find(address); | |
1280 if (index != undefined) { | |
1281 $('bluetooth-unpaired-devices-list').deleteItemAtIndex(index); | |
1282 } else { | |
1283 index = $('bluetooth-paired-devices-list').find(address); | |
1284 if (index != undefined) | |
1285 $('bluetooth-paired-devices-list').deleteItemAtIndex(index); | |
1286 } | |
1287 } | |
1288 | |
1289 }; | |
1290 | |
1291 //Forward public APIs to private implementations. | |
1292 [ | |
1293 'addBluetoothDevice', | |
1294 'getCurrentProfile', | |
1295 'getStartStopSyncButton', | |
1296 'hideBluetoothSettings', | |
1297 'removeCloudPrintConnectorSection', | |
1298 'removeBluetoothDevice', | |
1299 'setAutoOpenFileTypesDisplayed', | |
1300 'setBackgroundModeCheckboxState', | |
1301 'setBluetoothState', | |
1302 'setCheckRevocationCheckboxState', | |
1303 'setFontSize', | |
1304 'setGtkThemeButtonEnabled', | |
1305 'setHighContrastCheckboxState', | |
1306 'setMetricsReportingCheckboxState', | |
1307 'setMetricsReportingSettingVisibility', | |
1308 'setPasswordGenerationSettingVisibility', | |
1309 'setProfilesInfo', | |
1310 'setScreenMagnifierCheckboxState', | |
1311 'setSpokenFeedbackCheckboxState', | |
1312 'setThemesResetButtonEnabled', | |
1313 'setupCloudPrintConnectorSection', | |
1314 'setupPageZoomSelector', | |
1315 'setupProxySettingsSection', | |
1316 'setVirtualKeyboardCheckboxState', | |
1317 'showBluetoothSettings', | |
1318 'showDisplayOptions', | |
1319 'showMouseControls', | |
1320 'showTouchpadControls', | |
1321 'updateAccountPicture', | |
1322 'updateAutoLaunchState', | |
1323 'updateDefaultBrowserState', | |
1324 'updateManagedBannerVisibility', | |
1325 'updateSearchEngines', | |
1326 'updateSyncState', | |
1327 'updateStartupPages', | |
1328 ].forEach(function(name) { | |
1329 BrowserOptions[name] = function() { | |
1330 var instance = BrowserOptions.getInstance(); | |
1331 return instance[name + '_'].apply(instance, arguments); | |
1332 }; | |
1333 }); | |
1334 | |
1335 if (cr.isChromeOS) { | |
1336 /** | |
1337 * Returns username (canonical email) of the user logged in (ChromeOS only). | |
1338 * @return {string} user email. | |
1339 */ | |
1340 // TODO(jhawkins): Investigate the use case for this method. | |
1341 BrowserOptions.getLoggedInUsername = function() { | |
1342 return BrowserOptions.getInstance().username_; | |
1343 }; | |
1344 } | |
1345 | |
1346 // Export | |
1347 return { | |
1348 BrowserOptions: BrowserOptions | |
1349 }; | |
1350 }); | |
OLD | NEW |