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

Side by Side Diff: chrome/browser/resources/settings/sync_page/sync_page.js

Issue 1503333003: Settings People Rewrite: Make Sync/Sign-in naming consistent to People. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge upstream changes Created 5 years 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
OLDNEW
(Empty)
1 // Copyright 2015 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 (function() {
6
7 /**
8 * Names of the radio buttons which allow the user to choose his encryption
9 * mechanism.
10 * @enum {string}
11 */
12 var RadioButtonNames = {
13 ENCRYPT_WITH_GOOGLE: 'encrypt-with-google',
14 ENCRYPT_WITH_PASSPHRASE: 'encrypt-with-passphrase',
15 };
16
17 /**
18 * @fileoverview
19 * 'settings-sync-page' is the settings page containing sync settings.
20 *
21 * Example:
22 *
23 * <iron-animated-pages>
24 * <settings-sync-page></settings-sync-page>
25 * ... other pages ...
26 * </iron-animated-pages>
27 *
28 * @group Chrome Settings Elements
29 * @element settings-sync-page
30 */
31 Polymer({
32 is: 'settings-sync-page',
33
34 behaviors: [
35 I18nBehavior,
36 ],
37
38 properties: {
39 /**
40 * The current active route.
41 */
42 currentRoute: {
43 type: Object,
44 observer: 'currentRouteChanged_',
45 },
46
47 /**
48 * The current sync preferences, supplied by settings.SyncPrivateApi.
49 * @type {?settings.SyncPrefs}
50 */
51 syncPrefs: {
52 type: Object,
53 },
54
55 /**
56 * Whether the "create passphrase" inputs should be shown. These inputs
57 * give the user the opportunity to use a custom passphrase instead of
58 * authenticating with his Google credentials.
59 */
60 creatingNewPassphrase: {
61 type: Boolean,
62 value: false,
63 },
64
65 /**
66 * True if subpage needs the user's old Google password. This can happen
67 * when the user changes his password after encrypting his sync data.
68 *
69 * TODO(tommycli): FROM the C++ handler, the syncPrefs.usePassphrase field
70 * is true if and only if there is a custom non-Google Sync password.
71 *
72 * But going TO the C++ handler, the syncPrefs.usePassphrase field is true
73 * if there is either a custom or Google password. There is a separate
74 * syncPrefs.isGooglePassphrase field.
75 *
76 * We keep an extra state variable here because we mutate the
77 * syncPrefs.usePassphrase field in the OK button handler.
78 * Remove this once we fix refactor the legacy SyncSetupHandler.
79 */
80 askOldGooglePassphrase: {
81 type: Boolean,
82 value: false,
83 },
84 },
85
86 created: function() {
87 settings.SyncPrivateApi.setSyncPrefsCallback(
88 this.handleSyncPrefsFetched_.bind(this));
89 },
90
91 /** @private */
92 currentRouteChanged_: function() {
93 if (this.currentRoute.section == 'people' &&
94 this.currentRoute.subpage.length == 1 &&
95 this.currentRoute.subpage[0] == 'sync') {
96 // Display loading page until the settings have been retrieved.
97 this.$.pages.selected = 'loading';
98 settings.SyncPrivateApi.didNavigateToSyncPage();
99 } else {
100 settings.SyncPrivateApi.didNavigateAwayFromSyncPage();
101 }
102 },
103
104 /**
105 * Handler for when the sync state is pushed from settings.SyncPrivateApi.
106 * @private
107 */
108 handleSyncPrefsFetched_: function(syncPrefs) {
109 this.syncPrefs = syncPrefs;
110
111 this.askOldGooglePassphrase =
112 this.syncPrefs.showPassphrase && !this.syncPrefs.usePassphrase;
113
114 this.creatingNewPassphrase = false;
115
116 this.$.pages.selected = 'main';
117 },
118
119 /**
120 * Handler for when the sync all data types checkbox is changed.
121 * @param {Event} event
122 * @private
123 */
124 onSyncAllDataTypesChanged_: function(event) {
125 if (event.target.checked) {
126 this.set('syncPrefs.syncAllDataTypes', true);
127 this.set('syncPrefs.appsSynced', true);
128 this.set('syncPrefs.extensionsSynced', true);
129 this.set('syncPrefs.preferencesSynced', true);
130 this.set('syncPrefs.autofillSynced', true);
131 this.set('syncPrefs.typedUrlsSynced', true);
132 this.set('syncPrefs.themesSynced', true);
133 this.set('syncPrefs.bookmarksSynced', true);
134 this.set('syncPrefs.passwordsSynced', true);
135 this.set('syncPrefs.tabsSynced', true);
136 }
137 },
138
139 /** @private */
140 onCancelTap_: function() {
141 // Event is caught by settings-animated-pages.
142 this.fire('subpage-back');
143 },
144
145 /**
146 * Sets the sync data by sending it to the settings.SyncPrivateApi.
147 * @private
148 */
149 onOkTap_: function() {
150 if (this.creatingNewPassphrase) {
151 // If a new password has been entered but it is invalid, do not send the
152 // sync state to the API.
153 if (!this.validateCreatedPassphrases_())
154 return;
155
156 this.syncPrefs.encryptAllData = true;
157 }
158
159 this.syncPrefs.isGooglePassphrase = this.askOldGooglePassphrase;
160 this.syncPrefs.usePassphrase =
161 this.creatingNewPassphrase || this.syncPrefs.showPassphrase;
162
163 if (this.syncPrefs.usePassphrase) {
164 var field = this.creatingNewPassphrase ?
165 this.$$('#passphraseInput') : this.$$('#existingPassphraseInput');
166 this.syncPrefs.passphrase = field.value;
167 field.value = '';
168 }
169
170 settings.SyncPrivateApi.setSyncPrefs(
171 this.syncPrefs, this.setPageStatusCallback_.bind(this));
172 },
173
174 /**
175 * Callback invoked from calling settings.SyncPrivateApi.setSyncPrefs().
176 * @param {!settings.PageStatus} callbackState
177 * @private
178 */
179 setPageStatusCallback_: function(callbackState) {
180 if (callbackState == settings.PageStatus.DONE) {
181 this.onCancelTap_();
182 } else if (callbackState == settings.PageStatus.TIMEOUT) {
183 this.$.pages.selected = 'timeout';
184 } else if (callbackState ==
185 settings.PageStatus.PASSPHRASE_ERROR) {
186 this.$$('#incorrectPassphraseError').hidden = false;
187 }
188 },
189
190 /**
191 * Called when the encryption
192 * @private
193 */
194 onEncryptionRadioSelectionChanged_: function(event) {
195 this.creatingNewPassphrase =
196 event.target.selected == RadioButtonNames.ENCRYPT_WITH_PASSPHRASE;
197 },
198
199 /**
200 * Computed binding returning the selected encryption radio button.
201 * @private
202 */
203 selectedEncryptionRadio_: function() {
204 return this.encryptionRadiosDisabled_() ?
205 RadioButtonNames.ENCRYPT_WITH_PASSPHRASE :
206 RadioButtonNames.ENCRYPT_WITH_GOOGLE;
207 },
208
209 /**
210 * Computed binding returning the selected encryption radio button.
211 * @private
212 */
213 encryptionRadiosDisabled_: function() {
214 return this.syncPrefs.usePassphrase || this.syncPrefs.encryptAllData;
215 },
216
217 /**
218 * Computed binding returning the encryption text body.
219 * @private
220 */
221 encryptWithPassphraseBody_: function() {
222 if (this.syncPrefs && this.syncPrefs.fullEncryptionBody)
223 return this.syncPrefs.fullEncryptionBody;
224
225 return this.i18n('encryptWithSyncPassphraseLabel');
226 },
227
228 /**
229 * @param {boolean} syncAllDataTypes
230 * @param {boolean} enforced
231 * @return {boolean} Whether the sync checkbox should be disabled.
232 */
233 shouldSyncCheckboxBeDisabled_: function(syncAllDataTypes, enforced) {
234 return syncAllDataTypes || enforced;
235 },
236
237 /**
238 * Checks the supplied passphrases to ensure that they are not empty and that
239 * they match each other. Additionally, displays error UI if they are
240 * invalid.
241 * @return {boolean} Whether the check was successful (i.e., that the
242 * passphrases were valid).
243 * @private
244 */
245 validateCreatedPassphrases_: function() {
246 this.$$('#emptyPassphraseError').hidden = true;
247 this.$$('#mismatchedPassphraseError').hidden = true;
248
249 var passphrase = this.$$('#passphraseInput').value;
250 if (!passphrase) {
251 this.$$('#emptyPassphraseError').hidden = false;
252 return false;
253 }
254
255 var confirmation = this.$$('#passphraseConfirmationInput').value;
256 if (passphrase != confirmation) {
257 this.$$('#mismatchedPassphraseError').hidden = false;
258 return false;
259 }
260
261 return true;
262 },
263 });
264
265 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698