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.
5 cr
.define('options', function() {
6 /** @const */ var OptionsPage
= options
.OptionsPage
;
8 // True if the synced account uses a custom passphrase.
9 var usePassphrase_
= false;
11 // True if the synced account uses 'encrypt everything'.
12 var useEncryptEverything_
= false;
14 // An object used as a cache of the arguments passed in while initially
15 // displaying the advanced sync settings dialog. Used to switch between the
16 // options in the main drop-down menu. Reset when the dialog is closed.
17 var syncConfigureArgs_
= null;
19 // A dictionary that maps the sync data type checkbox names to their checked
20 // state. Initialized when the advanced settings dialog is first brought up,
21 // updated any time a box is checked / unchecked, and reset when the dialog is
22 // closed. Used to restore checkbox state while switching between the options
23 // in the main drop-down menu. All checkboxes are checked and disabled when
24 // the "Sync everything" menu-item is selected, and unchecked and disabled
25 // when "Sync nothing" is selected. When "Choose what to sync" is selected,
26 // the boxes are restored to their most recent checked state from this cache.
27 var dataTypeBoxes_
= {};
29 // Used to determine whether to bring the OK button / passphrase field into
31 var confirmPageVisible_
= false;
32 var customizePageVisible_
= false;
35 * The user's selection in the synced data type drop-down menu, as an index.
39 var DataTypeSelection
= {
41 CHOOSE_WHAT_TO_SYNC
: 1,
46 * SyncSetupOverlay class
47 * Encapsulated handling of the 'Sync Setup' overlay page.
50 function SyncSetupOverlay() {
51 OptionsPage
.call(this, 'syncSetup',
52 loadTimeData
.getString('syncSetupOverlayTabTitle'),
53 'sync-setup-overlay');
56 cr
.addSingletonGetter(SyncSetupOverlay
);
58 SyncSetupOverlay
.prototype = {
59 __proto__
: OptionsPage
.prototype,
62 * Initializes the page.
64 initializePage: function() {
65 OptionsPage
.prototype.initializePage
.call(this);
68 $('basic-encryption-option').onchange
=
69 $('full-encryption-option').onchange = function() {
70 self
.onEncryptionRadioChanged_();
72 $('choose-datatypes-cancel').onclick
=
73 $('confirm-everything-cancel').onclick
=
74 $('stop-syncing-cancel').onclick
=
75 $('sync-spinner-cancel').onclick = function() {
78 $('confirm-everything-ok').onclick = function() {
79 self
.sendConfiguration_();
81 $('timeout-ok').onclick = function() {
82 chrome
.send('CloseTimeout');
85 $('stop-syncing-ok').onclick = function() {
86 var deleteProfile
= $('delete-profile') != undefined &&
87 $('delete-profile').checked
;
88 chrome
.send('SyncSetupStopSyncing', [deleteProfile
]);
93 showOverlay_: function() {
94 OptionsPage
.navigateToPage('syncSetup');
97 closeOverlay_: function() {
98 this.syncConfigureArgs_
= null;
99 this.dataTypeBoxes_
= {};
101 var overlay
= $('sync-setup-overlay');
103 OptionsPage
.closeOverlay();
107 didShowPage: function() {
108 chrome
.send('SyncSetupShowSetupUI');
112 didClosePage: function() {
113 chrome
.send('SyncSetupDidClosePage');
116 onEncryptionRadioChanged_: function() {
117 var visible
= $('full-encryption-option').checked
;
118 $('sync-custom-passphrase').hidden
= !visible
;
122 * Sets the checked state of the individual sync data type checkboxes in the
123 * advanced sync settings dialog.
124 * @param {boolean} value True for checked, false for unchecked.
127 checkAllDataTypeCheckboxes_: function(value
) {
128 // Only check / uncheck the visible ones (since there's no way to uncheck
129 // / check the invisible ones).
130 var checkboxes
= $('choose-data-types-body').querySelectorAll(
131 '.sync-type-checkbox:not([hidden]) input');
132 for (var i
= 0; i
< checkboxes
.length
; i
++) {
133 checkboxes
[i
].checked
= value
;
138 * Restores the checked states of the sync data type checkboxes in the
139 * advanced sync settings dialog. Called when "Choose what to sync" is
140 * selected. Required because all the checkboxes are checked when
141 * "Sync everything" is selected, and unchecked when "Sync nothing" is
142 * selected. Note: We only restore checkboxes for data types that are
143 * actually visible and whose old values are found in the cache, since it's
144 * possible for some data types to not be registered, and therefore, their
145 * checkboxes remain hidden, and never get cached.
148 restoreDataTypeCheckboxes_: function() {
149 for (dataType
in dataTypeBoxes_
) {
150 $(dataType
).checked
= dataTypeBoxes_
[dataType
];
155 * Enables / grays out the sync data type checkboxes in the advanced
157 * @param {boolean} enabled True for enabled, false for grayed out.
160 setDataTypeCheckboxesEnabled_: function(enabled
) {
161 var checkboxes
= $('choose-data-types-body').querySelectorAll('input');
162 for (var i
= 0; i
< checkboxes
.length
; i
++) {
163 checkboxes
[i
].disabled
= !enabled
;
168 * Sets the state of the sync data type checkboxes based on whether "Sync
169 * everything", "Choose what to sync", or "Sync nothing" are selected in the
170 * drop-down menu of the advanced settings dialog.
171 * @param {cr.DataTypeSelection} selectedIndex Index of user's selection.
174 setDataTypeCheckboxes_: function(selectedIndex
) {
175 if (selectedIndex
== DataTypeSelection
.CHOOSE_WHAT_TO_SYNC
) {
176 this.setDataTypeCheckboxesEnabled_(true);
177 this.restoreDataTypeCheckboxes_();
179 this.setDataTypeCheckboxesEnabled_(false);
180 this.checkAllDataTypeCheckboxes_(selectedIndex
==
181 DataTypeSelection
.SYNC_EVERYTHING
);
185 checkPassphraseMatch_: function() {
186 var emptyError
= $('empty-error');
187 var mismatchError
= $('mismatch-error');
188 emptyError
.hidden
= true;
189 mismatchError
.hidden
= true;
191 var f
= $('choose-data-types-form');
192 if (!$('full-encryption-option').checked
||
193 $('basic-encryption-option').disabled
) {
197 var customPassphrase
= $('custom-passphrase');
198 if (customPassphrase
.value
.length
== 0) {
199 emptyError
.hidden
= false;
203 var confirmPassphrase
= $('confirm-passphrase');
204 if (confirmPassphrase
.value
!= customPassphrase
.value
) {
205 mismatchError
.hidden
= false;
212 sendConfiguration_: function() {
213 var encryptAllData
= $('full-encryption-option').checked
;
216 var customPassphrase
;
217 var googlePassphrase
= false;
218 if (!$('sync-existing-passphrase-container').hidden
) {
219 // If we were prompted for an existing passphrase, use it.
220 customPassphrase
= $('choose-data-types-form').passphrase
.value
;
221 usePassphrase
= true;
222 // If we were displaying the 'enter your old google password' prompt,
223 // then that means this is the user's google password.
224 googlePassphrase
= !$('google-passphrase-needed-body').hidden
;
225 // We allow an empty passphrase, in case the user has disabled
226 // all their encrypted datatypes. In that case, the PSS will accept
227 // the passphrase and finish configuration. If the user has enabled
228 // encrypted datatypes, the PSS will prompt again specifying that the
229 // passphrase failed.
230 } else if (!$('basic-encryption-option').disabled
&&
231 $('full-encryption-option').checked
) {
232 // The user is setting a custom passphrase for the first time.
233 if (!this.checkPassphraseMatch_())
235 customPassphrase
= $('custom-passphrase').value
;
236 usePassphrase
= true;
238 // The user is not setting a custom passphrase.
239 usePassphrase
= false;
242 // Don't allow the user to tweak the settings once we send the
243 // configuration to the backend.
244 this.setInputElementsDisabledState_(true);
245 $('use-default-link').hidden
= true;
246 $('use-default-link').disabled
= true;
247 $('use-default-link').onclick
= null;
249 // These values need to be kept in sync with where they are read in
250 // SyncSetupFlow::GetDataTypeChoiceData().
251 var syncAll
= $('sync-select-datatypes').selectedIndex
==
252 DataTypeSelection
.SYNC_EVERYTHING
;
253 var syncNothing
= $('sync-select-datatypes').selectedIndex
==
254 DataTypeSelection
.SYNC_NOTHING
;
255 var result
= JSON
.stringify({
256 'syncAllDataTypes': syncAll
,
257 'syncNothing': syncNothing
,
258 'bookmarksSynced': syncAll
|| $('bookmarks-checkbox').checked
,
259 'preferencesSynced': syncAll
|| $('preferences-checkbox').checked
,
260 'themesSynced': syncAll
|| $('themes-checkbox').checked
,
261 'passwordsSynced': syncAll
|| $('passwords-checkbox').checked
,
262 'autofillSynced': syncAll
|| $('autofill-checkbox').checked
,
263 'extensionsSynced': syncAll
|| $('extensions-checkbox').checked
,
264 'typedUrlsSynced': syncAll
|| $('typed-urls-checkbox').checked
,
265 'appsSynced': syncAll
|| $('apps-checkbox').checked
,
266 'tabsSynced': syncAll
|| $('tabs-checkbox').checked
,
267 'encryptAllData': encryptAllData
,
268 'usePassphrase': usePassphrase
,
269 'isGooglePassphrase': googlePassphrase
,
270 'passphrase': customPassphrase
272 chrome
.send('SyncSetupConfigure', [result
]);
276 * Sets the disabled property of all input elements within the 'Customize
277 * Sync Preferences' screen. This is used to prohibit the user from changing
278 * the inputs after confirming the customized sync preferences, or resetting
279 * the state when re-showing the dialog.
280 * @param {boolean} disabled True if controls should be set to disabled.
283 setInputElementsDisabledState_: function(disabled
) {
284 var configureElements
=
285 $('customize-sync-preferences').querySelectorAll('input');
286 for (var i
= 0; i
< configureElements
.length
; i
++)
287 configureElements
[i
].disabled
= disabled
;
288 $('sync-select-datatypes').disabled
= disabled
;
290 $('customize-link').hidden
= disabled
;
291 $('customize-link').disabled
= disabled
;
292 $('customize-link').onclick
= (disabled
? null : function() {
293 SyncSetupOverlay
.showCustomizePage(null,
294 DataTypeSelection
.SYNC_EVERYTHING
);
300 * Shows or hides the sync data type checkboxes in the advanced sync
301 * settings dialog. Also initializes |dataTypeBoxes_| with their values, and
302 * makes their onclick handlers update |dataTypeBoxes_|.
303 * @param {Object} args The configuration data used to show/hide UI.
306 setChooseDataTypesCheckboxes_: function(args
) {
307 var datatypeSelect
= $('sync-select-datatypes');
308 datatypeSelect
.selectedIndex
= args
.syncAllDataTypes
?
309 DataTypeSelection
.SYNC_EVERYTHING
:
310 DataTypeSelection
.CHOOSE_WHAT_TO_SYNC
;
312 $('bookmarks-checkbox').checked
= args
.bookmarksSynced
;
313 dataTypeBoxes_
['bookmarks-checkbox'] = args
.bookmarksSynced
;
314 $('bookmarks-checkbox').onclick
= this.handleDataTypeClick_
;
316 $('preferences-checkbox').checked
= args
.preferencesSynced
;
317 dataTypeBoxes_
['preferences-checkbox'] = args
.preferencesSynced
;
318 $('preferences-checkbox').onclick
= this.handleDataTypeClick_
;
320 $('themes-checkbox').checked
= args
.themesSynced
;
321 dataTypeBoxes_
['themes-checkbox'] = args
.themesSynced
;
322 $('themes-checkbox').onclick
= this.handleDataTypeClick_
;
324 if (args
.passwordsRegistered
) {
325 $('passwords-checkbox').checked
= args
.passwordsSynced
;
326 dataTypeBoxes_
['passwords-checkbox'] = args
.passwordsSynced
;
327 $('passwords-checkbox').onclick
= this.handleDataTypeClick_
;
328 $('passwords-item').hidden
= false;
330 $('passwords-item').hidden
= true;
332 if (args
.autofillRegistered
) {
333 $('autofill-checkbox').checked
= args
.autofillSynced
;
334 dataTypeBoxes_
['autofill-checkbox'] = args
.autofillSynced
;
335 $('autofill-checkbox').onclick
= this.handleDataTypeClick_
;
336 $('autofill-item').hidden
= false;
338 $('autofill-item').hidden
= true;
340 if (args
.extensionsRegistered
) {
341 $('extensions-checkbox').checked
= args
.extensionsSynced
;
342 dataTypeBoxes_
['extensions-checkbox'] = args
.extensionsSynced
;
343 $('extensions-checkbox').onclick
= this.handleDataTypeClick_
;
344 $('extensions-item').hidden
= false;
346 $('extensions-item').hidden
= true;
348 if (args
.typedUrlsRegistered
) {
349 $('typed-urls-checkbox').checked
= args
.typedUrlsSynced
;
350 dataTypeBoxes_
['typed-urls-checkbox'] = args
.typedUrlsSynced
;
351 $('typed-urls-checkbox').onclick
= this.handleDataTypeClick_
;
352 $('omnibox-item').hidden
= false;
354 $('omnibox-item').hidden
= true;
356 if (args
.appsRegistered
) {
357 $('apps-checkbox').checked
= args
.appsSynced
;
358 dataTypeBoxes_
['apps-checkbox'] = args
.appsSynced
;
359 $('apps-checkbox').onclick
= this.handleDataTypeClick_
;
360 $('apps-item').hidden
= false;
362 $('apps-item').hidden
= true;
364 if (args
.tabsRegistered
) {
365 $('tabs-checkbox').checked
= args
.tabsSynced
;
366 dataTypeBoxes_
['tabs-checkbox'] = args
.tabsSynced
;
367 $('tabs-checkbox').onclick
= this.handleDataTypeClick_
;
368 $('tabs-item').hidden
= false;
370 $('tabs-item').hidden
= true;
373 this.setDataTypeCheckboxes_(datatypeSelect
.selectedIndex
);
377 * Updates the cached values of the sync data type checkboxes stored in
378 * |dataTypeBoxes_|. Used as an onclick handler for each data type checkbox.
381 handleDataTypeClick_: function() {
382 dataTypeBoxes_
[this.id
] = this.checked
;
385 setEncryptionRadios_: function(args
) {
386 if (!args
.encryptAllData
&& !args
.usePassphrase
) {
387 $('basic-encryption-option').checked
= true;
389 $('full-encryption-option').checked
= true;
390 $('full-encryption-option').disabled
= true;
391 $('basic-encryption-option').disabled
= true;
395 setCheckboxesAndErrors_: function(args
) {
396 this.setChooseDataTypesCheckboxes_(args
);
397 this.setEncryptionRadios_(args
);
400 showConfigure_: function(args
) {
401 var datatypeSelect
= $('sync-select-datatypes');
404 // Cache the sync config args so they can be reused when we transition
405 // between the drop-down menu items in the advanced settings dialog.
407 this.syncConfigureArgs_
= args
;
409 // Required in order to determine whether to give focus to the OK button
410 // or passphrase field. See crbug.com/310555 and crbug.com/306353.
411 this.confirmPageVisible_
= false;
412 this.customizePageVisible_
= false;
414 // Once the advanced sync settings dialog is visible, we transition
415 // between its drop-down menu items as follows:
416 // "Sync everything": Show encryption and passphrase sections, and disable
417 // and check all data type checkboxes.
418 // "Sync nothing": Hide encryption and passphrase sections, and disable
419 // and uncheck all data type checkboxes.
420 // "Choose what to sync": Show encryption and passphrase sections, enable
421 // data type checkboxes, and restore their checked state to the last time
422 // the "Choose what to sync" was selected while the dialog was still up.
423 datatypeSelect
.onchange = function() {
424 if (this.selectedIndex
== DataTypeSelection
.SYNC_NOTHING
) {
425 self
.showSyncNothingPage_();
427 self
.showCustomizePage_(self
.syncConfigureArgs_
, this.selectedIndex
);
428 if (this.selectedIndex
== DataTypeSelection
.SYNC_EVERYTHING
)
429 self
.checkAllDataTypeCheckboxes_(true);
431 self
.restoreDataTypeCheckboxes_();
435 this.resetPage_('sync-setup-configure');
436 $('sync-setup-configure').hidden
= false;
438 // onsubmit is changed when submitting a passphrase. Reset it to its
440 $('choose-data-types-form').onsubmit = function() {
441 self
.sendConfiguration_();
446 this.setCheckboxesAndErrors_(args
);
448 this.useEncryptEverything_
= args
.encryptAllData
;
450 // Determine whether to display the 'OK, sync everything' confirmation
451 // dialog or the advanced sync settings dialog, and assign focus to the
452 // OK button, or to the passphrase field if a passphrase is required.
453 this.usePassphrase_
= args
.usePassphrase
;
454 if (args
.showSyncEverythingPage
== false || this.usePassphrase_
||
455 args
.syncAllDataTypes
== false || args
.showPassphrase
) {
456 var index
= args
.syncAllDataTypes
?
457 DataTypeSelection
.SYNC_EVERYTHING
:
458 DataTypeSelection
.CHOOSE_WHAT_TO_SYNC
;
459 this.showCustomizePage_(args
, index
);
461 this.showSyncEverythingPage_();
466 showSpinner_: function() {
467 this.resetPage_('sync-setup-spinner');
468 $('sync-setup-spinner').hidden
= false;
471 showTimeoutPage_: function() {
472 this.resetPage_('sync-setup-timeout');
473 $('sync-setup-timeout').hidden
= false;
476 showSyncEverythingPage_: function() {
477 // Determine whether to bring the OK button into focus.
478 var wasConfirmPageHidden
= !this.confirmPageVisible_
;
479 this.confirmPageVisible_
= true;
480 this.customizePageVisible_
= false;
482 $('confirm-sync-preferences').hidden
= false;
483 $('customize-sync-preferences').hidden
= true;
485 // Reset the selection to 'Sync everything'.
486 $('sync-select-datatypes').selectedIndex
= 0;
488 // The default state is to sync everything.
489 this.setDataTypeCheckboxes_(DataTypeSelection
.SYNC_EVERYTHING
);
491 if (!this.usePassphrase_
)
492 $('sync-custom-passphrase').hidden
= true;
494 if (!this.useEncryptEverything_
&& !this.usePassphrase_
)
495 $('basic-encryption-option').checked
= true;
497 // Give the OK button focus only when the dialog wasn't already visible.
498 if (wasConfirmPageHidden
)
499 $('confirm-everything-ok').focus();
503 * Reveals the UI for when the user chooses not to sync any data types.
504 * This happens when the user signs in and selects "Sync nothing" in the
505 * advanced sync settings dialog.
508 showSyncNothingPage_: function() {
509 // Reset the selection to 'Sync nothing'.
510 $('sync-select-datatypes').selectedIndex
= DataTypeSelection
.SYNC_NOTHING
;
512 // Uncheck and disable the individual data type checkboxes.
513 this.checkAllDataTypeCheckboxes_(false);
514 this.setDataTypeCheckboxesEnabled_(false);
516 // Hide the encryption section.
517 $('customize-sync-encryption-new').hidden
= true;
518 $('sync-custom-passphrase-container').hidden
= true;
519 $('sync-existing-passphrase-container').hidden
= true;
521 // Hide the "use default settings" link.
522 $('use-default-link').hidden
= true;
523 $('use-default-link').disabled
= true;
524 $('use-default-link').onclick
= null;
528 * Reveals the UI for entering a custom passphrase during initial setup.
529 * This happens if the user has previously enabled a custom passphrase on a
531 * @param {Array} args The args that contain the passphrase UI
535 showPassphraseContainer_: function(args
) {
536 // Once we require a passphrase, we prevent the user from returning to
537 // the Sync Everything pane.
538 $('use-default-link').hidden
= true;
539 $('use-default-link').disabled
= true;
540 $('use-default-link').onclick
= null;
541 $('sync-custom-passphrase-container').hidden
= true;
542 $('sync-existing-passphrase-container').hidden
= false;
544 // Hide the selection options within the new encryption section when
545 // prompting for a passphrase.
546 $('sync-new-encryption-section-container').hidden
= true;
548 $('normal-body').hidden
= true;
549 $('google-passphrase-needed-body').hidden
= true;
550 // Display the correct prompt to the user depending on what type of
551 // passphrase is needed.
552 if (args
.usePassphrase
)
553 $('normal-body').hidden
= false;
555 $('google-passphrase-needed-body').hidden
= false;
557 $('passphrase-learn-more').hidden
= false;
558 // Warn the user about their incorrect passphrase if we need a passphrase
559 // and the passphrase field is non-empty (meaning they tried to set it
560 // previously but failed).
561 $('incorrect-passphrase').hidden
=
562 !(args
.usePassphrase
&& args
.passphraseFailed
);
564 $('sync-passphrase-warning').hidden
= false;
568 * Displays the advanced sync setting dialog, and pre-selects either the
569 * "Sync everything" or the "Choose what to sync" drop-down menu item.
570 * @param {cr.DataTypeSelection} index Index of item to pre-select.
573 showCustomizePage_: function(args
, index
) {
574 // Determine whether to bring the OK button field into focus.
575 var wasCustomizePageHidden
= !this.customizePageVisible_
;
576 this.customizePageVisible_
= true;
577 this.confirmPageVisible_
= false;
579 $('confirm-sync-preferences').hidden
= true;
580 $('customize-sync-preferences').hidden
= false;
582 $('sync-custom-passphrase-container').hidden
= false;
583 $('sync-new-encryption-section-container').hidden
= false;
584 $('customize-sync-encryption-new').hidden
= false;
586 $('sync-existing-passphrase-container').hidden
= true;
588 $('sync-select-datatypes').selectedIndex
= index
;
589 this.setDataTypeCheckboxesEnabled_(
590 index
== DataTypeSelection
.CHOOSE_WHAT_TO_SYNC
);
592 // Give the OK button focus only when the dialog wasn't already visible.
593 if (wasCustomizePageHidden
)
594 $('choose-datatypes-ok').focus();
596 if (args
&& args
.showPassphrase
) {
597 this.showPassphraseContainer_(args
);
598 // Give the passphrase field focus only when the dialog wasn't already
600 if (wasCustomizePageHidden
)
601 $('passphrase').focus();
603 // We only show the 'Use Default' link if we're not prompting for an
604 // existing passphrase.
605 $('use-default-link').hidden
= false;
606 $('use-default-link').disabled
= false;
607 $('use-default-link').onclick = function() {
608 SyncSetupOverlay
.showSyncEverythingPage();
615 * Shows the appropriate sync setup page.
616 * @param {string} page A page of the sync setup to show.
617 * @param {object} args Data from the C++ to forward on to the right
620 showSyncSetupPage_: function(page
, args
) {
621 // If the user clicks the OK button, dismiss the dialog immediately, and
622 // do not go through the process of hiding elements of the overlay.
623 // See crbug.com/308873.
624 if (page
== 'done') {
625 this.closeOverlay_();
629 this.setThrobbersVisible_(false);
631 // Hide an existing visible overlay (ensuring the close button is not
633 var children
= document
.querySelectorAll(
634 '#sync-setup-overlay > *:not(.close-button)');
635 for (var i
= 0; i
< children
.length
; i
++)
636 children
[i
].hidden
= true;
638 this.setInputElementsDisabledState_(false);
640 // If new passphrase bodies are present, overwrite the existing ones.
641 if (args
&& args
.enterPassphraseBody
!= undefined)
642 $('normal-body').innerHTML
= args
.enterPassphraseBody
;
643 if (args
&& args
.enterGooglePassphraseBody
!= undefined) {
644 $('google-passphrase-needed-body').innerHTML
=
645 args
.enterGooglePassphraseBody
;
647 if (args
&& args
.fullEncryptionBody
!= undefined)
648 $('full-encryption-body').innerHTML
= args
.fullEncryptionBody
;
650 // NOTE: Because both showGaiaLogin_() and showConfigure_() change the
651 // focus, we need to ensure that the overlay container and dialog aren't
652 // [hidden] (as trying to focus() nodes inside of a [hidden] DOM section
656 if (page
== 'configure' || page
== 'passphrase')
657 this.showConfigure_(args
);
658 else if (page
== 'spinner')
660 else if (page
== 'timeout')
661 this.showTimeoutPage_();
665 * Changes the visibility of throbbers on this page.
666 * @param {boolean} visible Whether or not to set all throbber nodes
669 setThrobbersVisible_: function(visible
) {
670 var throbbers
= this.pageDiv
.getElementsByClassName('throbber');
671 for (var i
= 0; i
< throbbers
.length
; i
++)
672 throbbers
[i
].style
.visibility
= visible
? 'visible' : 'hidden';
676 * Reset the state of all descendant elements of a root element to their
678 * The initial state is specified by adding a class to the descendant
679 * element in sync_setup_overlay.html.
680 * @param {HTMLElement} pageElementId The root page element id.
683 resetPage_: function(pageElementId
) {
684 var page
= $(pageElementId
);
685 var forEach = function(arr
, fn
) {
686 var length
= arr
.length
;
687 for (var i
= 0; i
< length
; i
++) {
692 forEach(page
.getElementsByClassName('reset-hidden'),
693 function(elt
) { elt
.hidden
= true; });
694 forEach(page
.getElementsByClassName('reset-shown'),
695 function(elt
) { elt
.hidden
= false; });
696 forEach(page
.getElementsByClassName('reset-disabled'),
697 function(elt
) { elt
.disabled
= true; });
698 forEach(page
.getElementsByClassName('reset-enabled'),
699 function(elt
) { elt
.disabled
= false; });
700 forEach(page
.getElementsByClassName('reset-value'),
701 function(elt
) { elt
.value
= ''; });
702 forEach(page
.getElementsByClassName('reset-opaque'),
703 function(elt
) { elt
.classList
.remove('transparent'); });
707 * Displays the stop syncing dialog.
710 showStopSyncingUI_: function() {
711 // Hide any visible children of the overlay.
712 var overlay
= $('sync-setup-overlay');
713 for (var i
= 0; i
< overlay
.children
.length
; i
++)
714 overlay
.children
[i
].hidden
= true;
716 // Bypass OptionsPage.navigateToPage because it will call didShowPage
717 // which will set its own visible page, based on the flow state.
720 $('sync-setup-stop-syncing').hidden
= false;
721 $('stop-syncing-cancel').focus();
725 * Determines the appropriate page to show in the Sync Setup UI based on
726 * the state of the Sync backend. Does nothing if the user is not signed in.
729 showSetupUI_: function() {
730 chrome
.send('SyncSetupShowSetupUI');
734 * Starts the signin process for the user. Does nothing if the user is
738 startSignIn_: function() {
739 chrome
.send('SyncSetupStartSignIn');
743 * Forces user to sign out of Chrome for Chrome OS.
746 doSignOutOnAuthError_: function() {
747 chrome
.send('SyncSetupDoSignOutOnAuthError');
751 // These methods are for general consumption.
752 SyncSetupOverlay
.closeOverlay = function() {
753 SyncSetupOverlay
.getInstance().closeOverlay_();
756 SyncSetupOverlay
.showSetupUI = function() {
757 SyncSetupOverlay
.getInstance().showSetupUI_();
760 SyncSetupOverlay
.startSignIn = function() {
761 SyncSetupOverlay
.getInstance().startSignIn_();
764 SyncSetupOverlay
.doSignOutOnAuthError = function() {
765 SyncSetupOverlay
.getInstance().doSignOutOnAuthError_();
768 SyncSetupOverlay
.showSyncSetupPage = function(page
, args
) {
769 SyncSetupOverlay
.getInstance().showSyncSetupPage_(page
, args
);
772 SyncSetupOverlay
.showCustomizePage = function(args
, index
) {
773 SyncSetupOverlay
.getInstance().showCustomizePage_(args
, index
);
776 SyncSetupOverlay
.showSyncEverythingPage = function() {
777 SyncSetupOverlay
.getInstance().showSyncEverythingPage_();
780 SyncSetupOverlay
.showStopSyncingUI = function() {
781 SyncSetupOverlay
.getInstance().showStopSyncingUI_();
786 SyncSetupOverlay
: SyncSetupOverlay