Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Side by Side Diff: chrome/browser/resources/sync_setup_overlay.js

Issue 703193003: sync setup: move mistaken local statics to instance members. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ok-cancel
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.exportPath('options'); 5 cr.exportPath('options');
6 6
7 /** @typedef {{appsEnforced: boolean, 7 /** @typedef {{appsEnforced: boolean,
8 * appsRegistered: boolean, 8 * appsRegistered: boolean,
9 * appsSynced: boolean, 9 * appsSynced: boolean,
10 * autofillEnforced: boolean, 10 * autofillEnforced: boolean,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 options.DataTypeSelection = { 55 options.DataTypeSelection = {
56 SYNC_EVERYTHING: 0, 56 SYNC_EVERYTHING: 0,
57 CHOOSE_WHAT_TO_SYNC: 1, 57 CHOOSE_WHAT_TO_SYNC: 1,
58 SYNC_NOTHING: 2 58 SYNC_NOTHING: 2
59 }; 59 };
60 60
61 cr.define('options', function() { 61 cr.define('options', function() {
62 /** @const */ var Page = cr.ui.pageManager.Page; 62 /** @const */ var Page = cr.ui.pageManager.Page;
63 /** @const */ var PageManager = cr.ui.pageManager.PageManager; 63 /** @const */ var PageManager = cr.ui.pageManager.PageManager;
64 64
65 // TODO(dbeam): none of these variables are used. This is not Java.
66
67 // True if the synced account uses a custom passphrase.
68 var usePassphrase_ = false;
69
70 // True if the synced account uses 'encrypt everything'.
71 var useEncryptEverything_ = false;
72
73 // An object used as a cache of the arguments passed in while initially
74 // displaying the advanced sync settings dialog. Used to switch between the
75 // options in the main drop-down menu. Reset when the dialog is closed.
76 var syncConfigureArgs_ = null;
77
78 // A dictionary that maps the sync data type checkbox names to their checked
79 // state. Initialized when the advanced settings dialog is first brought up,
80 // updated any time a box is checked / unchecked, and reset when the dialog is
81 // closed. Used to restore checkbox state while switching between the options
82 // in the main drop-down menu. All checkboxes are checked and disabled when
83 // the "Sync everything" menu-item is selected, and unchecked and disabled
84 // when "Sync nothing" is selected. When "Choose what to sync" is selected,
85 // the boxes are restored to their most recent checked state from this cache.
86 var dataTypeBoxesChecked_ = {};
87
88 // A dictionary that maps the sync data type checkbox names to their disabled
89 // state (when a data type is enabled programmatically without user choice).
90 // Initialized when the advanced settings dialog is first brought up, and
91 // reset when the dialog is closed.
92 var dataTypeBoxesDisabled_ = {};
93
94 /** 65 /**
95 * SyncSetupOverlay class 66 * SyncSetupOverlay class
96 * Encapsulated handling of the 'Sync Setup' overlay page. 67 * Encapsulated handling of the 'Sync Setup' overlay page.
97 * @class 68 * @class
98 */ 69 */
99 function SyncSetupOverlay() { 70 function SyncSetupOverlay() {
100 Page.call(this, 'syncSetup', 71 Page.call(this, 'syncSetup',
101 loadTimeData.getString('syncSetupOverlayTabTitle'), 72 loadTimeData.getString('syncSetupOverlayTabTitle'),
102 'sync-setup-overlay'); 73 'sync-setup-overlay');
103 } 74 }
104 75
105 cr.addSingletonGetter(SyncSetupOverlay); 76 cr.addSingletonGetter(SyncSetupOverlay);
106 77
107 SyncSetupOverlay.prototype = { 78 SyncSetupOverlay.prototype = {
108 __proto__: Page.prototype, 79 __proto__: Page.prototype,
109 80
81 /**
82 * True if the synced account uses a custom passphrase.
83 * @private {boolean}
84 */
85 usePassphrase_: false,
86
87 /**
88 * True if the synced account uses 'encrypt everything'.
89 * @private {boolean}
90 */
91 useEncryptEverything_: false,
92
93 /**
94 * An object used as a cache of the arguments passed in while initially
95 * displaying the advanced sync settings dialog. Used to switch between the
96 * options in the main drop-down menu. Reset when the dialog is closed.
97 * @private {?SyncConfig}
98 */
99 syncConfigureArgs_: null,
100
101 /**
102 * A dictionary that maps the sync data type checkbox names to their checked
103 * state. Initialized when the advanced settings dialog is first brought up,
104 * updated any time a box is checked / unchecked, and reset when the dialog
105 * is closed. Used to restore checkbox state while switching between the
106 * options in the main drop-down menu. All checkboxes are checked and
107 * disabled when the "Sync everything" menu-item is selected, and unchecked
108 * and disabled when "Sync nothing" is selected. When "Choose what to sync"
109 * is selected, the boxes are restored to their most recent checked state
110 * from this cache.
111 * @private {Object}
112 */
113 dataTypeBoxesChecked_: {},
114
115 /**
116 * A dictionary that maps the sync data type checkbox names to their
117 * disabled state (when a data type is enabled programmatically without user
118 * choice). Initialized when the advanced settings dialog is first brought
119 * up, and reset when the dialog is closed.
120 * @private {Object}
121 */
122 dataTypeBoxesDisabled_: {},
123
110 /** @override */ 124 /** @override */
111 initializePage: function() { 125 initializePage: function() {
112 Page.prototype.initializePage.call(this); 126 Page.prototype.initializePage.call(this);
113 127
114 var self = this; 128 var self = this;
115 129
116 // If 'profilesInfo' doesn't exist, it's forbidden to delete profile. 130 // If 'profilesInfo' doesn't exist, it's forbidden to delete profile.
117 // So don't display the delete-profile checkbox. 131 // So don't display the delete-profile checkbox.
118 if (!loadTimeData.valueExists('profilesInfo') && 132 if (!loadTimeData.valueExists('profilesInfo') &&
119 $('sync-setup-delete-profile')) { 133 $('sync-setup-delete-profile')) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 * advanced sync settings dialog. Called when "Choose what to sync" is 211 * advanced sync settings dialog. Called when "Choose what to sync" is
198 * selected. Required because all the checkboxes are checked when 212 * selected. Required because all the checkboxes are checked when
199 * "Sync everything" is selected, and unchecked when "Sync nothing" is 213 * "Sync everything" is selected, and unchecked when "Sync nothing" is
200 * selected. Note: We only restore checkboxes for data types that are 214 * selected. Note: We only restore checkboxes for data types that are
201 * actually visible and whose old values are found in the cache, since it's 215 * actually visible and whose old values are found in the cache, since it's
202 * possible for some data types to not be registered, and therefore, their 216 * possible for some data types to not be registered, and therefore, their
203 * checkboxes remain hidden, and never get cached. 217 * checkboxes remain hidden, and never get cached.
204 * @private 218 * @private
205 */ 219 */
206 restoreDataTypeCheckboxes_: function() { 220 restoreDataTypeCheckboxes_: function() {
207 for (var dataType in dataTypeBoxesChecked_) { 221 for (var dataType in this.dataTypeBoxesChecked_) {
208 $(dataType).checked = dataTypeBoxesChecked_[dataType]; 222 $(dataType).checked = this.dataTypeBoxesChecked_[dataType];
209 } 223 }
210 }, 224 },
211 225
212 /** 226 /**
213 * Enables / grays out the sync data type checkboxes in the advanced 227 * Enables / grays out the sync data type checkboxes in the advanced
214 * settings dialog. 228 * settings dialog.
215 * @param {boolean} enabled True for enabled, false for grayed out. 229 * @param {boolean} enabled True for enabled, false for grayed out.
216 * @private 230 * @private
217 */ 231 */
218 setDataTypeCheckboxesEnabled_: function(enabled) { 232 setDataTypeCheckboxesEnabled_: function(enabled) {
219 for (var dataType in dataTypeBoxesDisabled_) { 233 for (var dataType in this.dataTypeBoxesDisabled_) {
220 $(dataType).disabled = !enabled || dataTypeBoxesDisabled_[dataType]; 234 $(dataType).disabled =
235 !enabled || this.dataTypeBoxesDisabled_[dataType];
221 } 236 }
222 }, 237 },
223 238
224 /** 239 /**
225 * Sets the state of the sync data type checkboxes based on whether "Sync 240 * Sets the state of the sync data type checkboxes based on whether "Sync
226 * everything", "Choose what to sync", or "Sync nothing" are selected in the 241 * everything", "Choose what to sync", or "Sync nothing" are selected in the
227 * drop-down menu of the advanced settings dialog. 242 * drop-down menu of the advanced settings dialog.
228 * @param {options.DataTypeSelection} selectedIndex Index of user's 243 * @param {options.DataTypeSelection} selectedIndex Index of user's
229 * selection. 244 * selection.
230 * @private 245 * @private
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 $('customize-link').disabled = disabled; 367 $('customize-link').disabled = disabled;
353 $('customize-link').onclick = disabled ? null : function() { 368 $('customize-link').onclick = disabled ? null : function() {
354 SyncSetupOverlay.showCustomizePage(self.syncConfigureArgs_, 369 SyncSetupOverlay.showCustomizePage(self.syncConfigureArgs_,
355 options.DataTypeSelection.SYNC_EVERYTHING); 370 options.DataTypeSelection.SYNC_EVERYTHING);
356 return false; 371 return false;
357 }; 372 };
358 }, 373 },
359 374
360 /** 375 /**
361 * Shows or hides the sync data type checkboxes in the advanced sync 376 * Shows or hides the sync data type checkboxes in the advanced sync
362 * settings dialog. Also initializes |dataTypeBoxesChecked_| and 377 * settings dialog. Also initializes |this.dataTypeBoxesChecked_| and
363 * |dataTypeBoxedDisabled_| with their values, and makes their onclick 378 * |this.dataTypeBoxedDisabled_| with their values, and makes their onclick
364 * handlers update |dataTypeBoxesChecked_|. 379 * handlers update |this.dataTypeBoxesChecked_|.
365 * @param {SyncConfig} args The configuration data used to show/hide UI. 380 * @param {SyncConfig} args The configuration data used to show/hide UI.
366 * @private 381 * @private
367 */ 382 */
368 setChooseDataTypesCheckboxes_: function(args) { 383 setChooseDataTypesCheckboxes_: function(args) {
369 var datatypeSelect = $('sync-select-datatypes'); 384 var datatypeSelect = $('sync-select-datatypes');
370 datatypeSelect.selectedIndex = args.syncAllDataTypes ? 385 datatypeSelect.selectedIndex = args.syncAllDataTypes ?
371 options.DataTypeSelection.SYNC_EVERYTHING : 386 options.DataTypeSelection.SYNC_EVERYTHING :
372 options.DataTypeSelection.CHOOSE_WHAT_TO_SYNC; 387 options.DataTypeSelection.CHOOSE_WHAT_TO_SYNC;
373 388
374 $('bookmarks-checkbox').checked = args.bookmarksSynced; 389 $('bookmarks-checkbox').checked = args.bookmarksSynced;
375 dataTypeBoxesChecked_['bookmarks-checkbox'] = args.bookmarksSynced; 390 this.dataTypeBoxesChecked_['bookmarks-checkbox'] = args.bookmarksSynced;
376 dataTypeBoxesDisabled_['bookmarks-checkbox'] = args.bookmarksEnforced; 391 this.dataTypeBoxesDisabled_['bookmarks-checkbox'] =
392 args.bookmarksEnforced;
377 $('bookmarks-checkbox').onclick = this.handleDataTypeClick_; 393 $('bookmarks-checkbox').onclick = this.handleDataTypeClick_;
378 394
379 $('preferences-checkbox').checked = args.preferencesSynced; 395 $('preferences-checkbox').checked = args.preferencesSynced;
380 dataTypeBoxesChecked_['preferences-checkbox'] = args.preferencesSynced; 396 this.dataTypeBoxesChecked_['preferences-checkbox'] =
381 dataTypeBoxesDisabled_['preferences-checkbox'] = args.preferencesEnforced; 397 args.preferencesSynced;
398 this.dataTypeBoxesDisabled_['preferences-checkbox'] =
399 args.preferencesEnforced;
382 $('preferences-checkbox').onclick = this.handleDataTypeClick_; 400 $('preferences-checkbox').onclick = this.handleDataTypeClick_;
383 401
384 $('themes-checkbox').checked = args.themesSynced; 402 $('themes-checkbox').checked = args.themesSynced;
385 dataTypeBoxesChecked_['themes-checkbox'] = args.themesSynced; 403 this.dataTypeBoxesChecked_['themes-checkbox'] = args.themesSynced;
386 dataTypeBoxesDisabled_['themes-checkbox'] = args.themesEnforced; 404 this.dataTypeBoxesDisabled_['themes-checkbox'] = args.themesEnforced;
387 $('themes-checkbox').onclick = this.handleDataTypeClick_; 405 $('themes-checkbox').onclick = this.handleDataTypeClick_;
388 406
389 if (args.passwordsRegistered) { 407 if (args.passwordsRegistered) {
390 $('passwords-checkbox').checked = args.passwordsSynced; 408 $('passwords-checkbox').checked = args.passwordsSynced;
391 dataTypeBoxesChecked_['passwords-checkbox'] = args.passwordsSynced; 409 this.dataTypeBoxesChecked_['passwords-checkbox'] = args.passwordsSynced;
392 dataTypeBoxesDisabled_['passwords-checkbox'] = args.passwordsEnforced; 410 this.dataTypeBoxesDisabled_['passwords-checkbox'] =
411 args.passwordsEnforced;
393 $('passwords-checkbox').onclick = this.handleDataTypeClick_; 412 $('passwords-checkbox').onclick = this.handleDataTypeClick_;
394 $('passwords-item').hidden = false; 413 $('passwords-item').hidden = false;
395 } else { 414 } else {
396 $('passwords-item').hidden = true; 415 $('passwords-item').hidden = true;
397 } 416 }
398 if (args.autofillRegistered) { 417 if (args.autofillRegistered) {
399 $('autofill-checkbox').checked = args.autofillSynced; 418 $('autofill-checkbox').checked = args.autofillSynced;
400 dataTypeBoxesChecked_['autofill-checkbox'] = args.autofillSynced; 419 this.dataTypeBoxesChecked_['autofill-checkbox'] = args.autofillSynced;
401 dataTypeBoxesDisabled_['autofill-checkbox'] = args.autofillEnforced; 420 this.dataTypeBoxesDisabled_['autofill-checkbox'] =
421 args.autofillEnforced;
402 $('autofill-checkbox').onclick = this.handleDataTypeClick_; 422 $('autofill-checkbox').onclick = this.handleDataTypeClick_;
403 $('autofill-item').hidden = false; 423 $('autofill-item').hidden = false;
404 } else { 424 } else {
405 $('autofill-item').hidden = true; 425 $('autofill-item').hidden = true;
406 } 426 }
407 if (args.extensionsRegistered) { 427 if (args.extensionsRegistered) {
408 $('extensions-checkbox').checked = args.extensionsSynced; 428 $('extensions-checkbox').checked = args.extensionsSynced;
409 dataTypeBoxesChecked_['extensions-checkbox'] = args.extensionsSynced; 429 this.dataTypeBoxesChecked_['extensions-checkbox'] =
410 dataTypeBoxesDisabled_['extensions-checkbox'] = args.extensionsEnforced; 430 args.extensionsSynced;
431 this.dataTypeBoxesDisabled_['extensions-checkbox'] =
432 args.extensionsEnforced;
411 $('extensions-checkbox').onclick = this.handleDataTypeClick_; 433 $('extensions-checkbox').onclick = this.handleDataTypeClick_;
412 $('extensions-item').hidden = false; 434 $('extensions-item').hidden = false;
413 } else { 435 } else {
414 $('extensions-item').hidden = true; 436 $('extensions-item').hidden = true;
415 } 437 }
416 if (args.typedUrlsRegistered) { 438 if (args.typedUrlsRegistered) {
417 $('typed-urls-checkbox').checked = args.typedUrlsSynced; 439 $('typed-urls-checkbox').checked = args.typedUrlsSynced;
418 dataTypeBoxesChecked_['typed-urls-checkbox'] = args.typedUrlsSynced; 440 this.dataTypeBoxesChecked_['typed-urls-checkbox'] =
419 dataTypeBoxesDisabled_['typed-urls-checkbox'] = args.typedUrlsEnforced; 441 args.typedUrlsSynced;
442 this.dataTypeBoxesDisabled_['typed-urls-checkbox'] =
443 args.typedUrlsEnforced;
420 $('typed-urls-checkbox').onclick = this.handleDataTypeClick_; 444 $('typed-urls-checkbox').onclick = this.handleDataTypeClick_;
421 $('omnibox-item').hidden = false; 445 $('omnibox-item').hidden = false;
422 } else { 446 } else {
423 $('omnibox-item').hidden = true; 447 $('omnibox-item').hidden = true;
424 } 448 }
425 if (args.appsRegistered) { 449 if (args.appsRegistered) {
426 $('apps-checkbox').checked = args.appsSynced; 450 $('apps-checkbox').checked = args.appsSynced;
427 dataTypeBoxesChecked_['apps-checkbox'] = args.appsSynced; 451 this.dataTypeBoxesChecked_['apps-checkbox'] = args.appsSynced;
428 dataTypeBoxesDisabled_['apps-checkbox'] = args.appsEnforced; 452 this.dataTypeBoxesDisabled_['apps-checkbox'] = args.appsEnforced;
429 $('apps-checkbox').onclick = this.handleDataTypeClick_; 453 $('apps-checkbox').onclick = this.handleDataTypeClick_;
430 $('apps-item').hidden = false; 454 $('apps-item').hidden = false;
431 } else { 455 } else {
432 $('apps-item').hidden = true; 456 $('apps-item').hidden = true;
433 } 457 }
434 if (args.tabsRegistered) { 458 if (args.tabsRegistered) {
435 $('tabs-checkbox').checked = args.tabsSynced; 459 $('tabs-checkbox').checked = args.tabsSynced;
436 dataTypeBoxesChecked_['tabs-checkbox'] = args.tabsSynced; 460 this.dataTypeBoxesChecked_['tabs-checkbox'] = args.tabsSynced;
437 dataTypeBoxesDisabled_['tabs-checkbox'] = args.tabsEnforced; 461 this.dataTypeBoxesDisabled_['tabs-checkbox'] = args.tabsEnforced;
438 $('tabs-checkbox').onclick = this.handleDataTypeClick_; 462 $('tabs-checkbox').onclick = this.handleDataTypeClick_;
439 $('tabs-item').hidden = false; 463 $('tabs-item').hidden = false;
440 } else { 464 } else {
441 $('tabs-item').hidden = true; 465 $('tabs-item').hidden = true;
442 } 466 }
443 if (args.wifiCredentialsRegistered) { 467 if (args.wifiCredentialsRegistered) {
444 $('wifi-credentials-checkbox').checked = args.wifiCredentialsSynced; 468 $('wifi-credentials-checkbox').checked = args.wifiCredentialsSynced;
445 dataTypeBoxesChecked_['wifi-credentials-checkbox'] = 469 this.dataTypeBoxesChecked_['wifi-credentials-checkbox'] =
446 args.wifiCredentialsSynced; 470 args.wifiCredentialsSynced;
447 dataTypeBoxesDisabled_['wifi-credentials-checkbox'] = 471 this.dataTypeBoxesDisabled_['wifi-credentials-checkbox'] =
448 args.wifiCredentialsEnforced; 472 args.wifiCredentialsEnforced;
449 $('wifi-credentials-checkbox').onclick = this.handleDataTypeClick_; 473 $('wifi-credentials-checkbox').onclick = this.handleDataTypeClick_;
450 $('wifi-credentials-item').hidden = false; 474 $('wifi-credentials-item').hidden = false;
451 } else { 475 } else {
452 $('wifi-credentials-item').hidden = true; 476 $('wifi-credentials-item').hidden = true;
453 } 477 }
454 478
455 this.setDataTypeCheckboxes_(datatypeSelect.selectedIndex); 479 this.setDataTypeCheckboxes_(datatypeSelect.selectedIndex);
456 }, 480 },
457 481
458 /** 482 /**
459 * Updates the cached values of the sync data type checkboxes stored in 483 * Updates the cached values of the sync data type checkboxes stored in
460 * |dataTypeBoxesChecked_|. Used as an onclick handler for each data type 484 * |this.dataTypeBoxesChecked_|. Used as an onclick handler for each data
461 * checkbox. 485 * type checkbox.
462 * @private 486 * @private
463 */ 487 */
464 handleDataTypeClick_: function() { 488 handleDataTypeClick_: function() {
465 dataTypeBoxesChecked_[this.id] = this.checked; 489 this.dataTypeBoxesChecked_[this.id] = this.checked;
466 chrome.send('coreOptionsUserMetricsAction', 490 chrome.send('coreOptionsUserMetricsAction',
467 ['Options_SyncToggleDataType']); 491 ['Options_SyncToggleDataType']);
468 }, 492 },
469 493
470 /** 494 /**
471 * @param {SyncConfig} args 495 * @param {SyncConfig} args
472 */ 496 */
473 setEncryptionRadios_: function(args) { 497 setEncryptionRadios_: function(args) {
474 if (!args.encryptAllData && !args.usePassphrase) { 498 if (!args.encryptAllData && !args.usePassphrase) {
475 $('basic-encryption-option').checked = true; 499 $('basic-encryption-option').checked = true;
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 875
852 SyncSetupOverlay.showStopSyncingUI = function() { 876 SyncSetupOverlay.showStopSyncingUI = function() {
853 SyncSetupOverlay.getInstance().showStopSyncingUI_(); 877 SyncSetupOverlay.getInstance().showStopSyncingUI_();
854 }; 878 };
855 879
856 // Export 880 // Export
857 return { 881 return {
858 SyncSetupOverlay: SyncSetupOverlay 882 SyncSetupOverlay: SyncSetupOverlay
859 }; 883 };
860 }); 884 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698