| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 (function() { | 5 (function() { |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Names of the radio buttons which allow the user to choose his encryption | 8 * Names of the radio buttons which allow the user to choose his encryption |
| 9 * mechanism. | 9 * mechanism. |
| 10 * @enum {string} | 10 * @enum {string} |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 * Whether the "create passphrase" inputs should be shown. These inputs | 92 * Whether the "create passphrase" inputs should be shown. These inputs |
| 93 * give the user the opportunity to use a custom passphrase instead of | 93 * give the user the opportunity to use a custom passphrase instead of |
| 94 * authenticating with his Google credentials. | 94 * authenticating with his Google credentials. |
| 95 * @private | 95 * @private |
| 96 */ | 96 */ |
| 97 creatingNewPassphrase_: { | 97 creatingNewPassphrase_: { |
| 98 type: Boolean, | 98 type: Boolean, |
| 99 value: false, | 99 value: false, |
| 100 }, | 100 }, |
| 101 | 101 |
| 102 /** |
| 103 * The passphrase input field value. |
| 104 * @private |
| 105 */ |
| 106 passphrase_: { |
| 107 type: String, |
| 108 value: '', |
| 109 }, |
| 110 |
| 111 /** |
| 112 * The passphrase confirmation input field value. |
| 113 * @private |
| 114 */ |
| 115 confirmation_: { |
| 116 type: String, |
| 117 value: '', |
| 118 }, |
| 119 |
| 120 /** |
| 121 * The existing passphrase input field value. |
| 122 * @private |
| 123 */ |
| 124 existingPassphrase_: { |
| 125 type: String, |
| 126 value: '', |
| 127 }, |
| 128 |
| 102 /** @private {!settings.SyncBrowserProxy} */ | 129 /** @private {!settings.SyncBrowserProxy} */ |
| 103 browserProxy_: { | 130 browserProxy_: { |
| 104 type: Object, | 131 type: Object, |
| 105 value: function() { | 132 value: function() { |
| 106 return settings.SyncBrowserProxyImpl.getInstance(); | 133 return settings.SyncBrowserProxyImpl.getInstance(); |
| 107 }, | 134 }, |
| 108 }, | 135 }, |
| 109 | 136 |
| 110 /** | 137 /** |
| 111 * The unload callback is needed because the sign-in flow needs to know | 138 * The unload callback is needed because the sign-in flow needs to know |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 * @private | 280 * @private |
| 254 */ | 281 */ |
| 255 onAutofillDataTypeChanged_: function() { | 282 onAutofillDataTypeChanged_: function() { |
| 256 this.set('syncPrefs.paymentsIntegrationEnabled', | 283 this.set('syncPrefs.paymentsIntegrationEnabled', |
| 257 this.syncPrefs.autofillSynced); | 284 this.syncPrefs.autofillSynced); |
| 258 | 285 |
| 259 this.onSingleSyncDataTypeChanged_(); | 286 this.onSingleSyncDataTypeChanged_(); |
| 260 }, | 287 }, |
| 261 | 288 |
| 262 /** | 289 /** |
| 290 * @param {string} passphrase The passphrase input field value |
| 291 * @param {string} confirmation The passphrase confirmation input field value. |
| 292 * @return {boolean} Whether the passphrase save button should be enabled. |
| 293 * @private |
| 294 */ |
| 295 isSaveNewPassphraseEnabled_: function(passphrase, confirmation) { |
| 296 return passphrase !== '' && confirmation !== ''; |
| 297 }, |
| 298 |
| 299 /** |
| 263 * Sends the newly created custom sync passphrase to the browser. | 300 * Sends the newly created custom sync passphrase to the browser. |
| 264 * @private | 301 * @private |
| 265 */ | 302 */ |
| 266 onSaveNewPassphraseTap_: function() { | 303 onSaveNewPassphraseTap_: function() { |
| 267 assert(this.creatingNewPassphrase_); | 304 assert(this.creatingNewPassphrase_); |
| 268 | 305 |
| 269 // If a new password has been entered but it is invalid, do not send the | 306 // If a new password has been entered but it is invalid, do not send the |
| 270 // sync state to the API. | 307 // sync state to the API. |
| 271 if (!this.validateCreatedPassphrases_()) | 308 if (!this.validateCreatedPassphrases_()) |
| 272 return; | 309 return; |
| 273 | 310 |
| 274 this.syncPrefs.encryptAllData = true; | 311 this.syncPrefs.encryptAllData = true; |
| 275 this.syncPrefs.setNewPassphrase = true; | 312 this.syncPrefs.setNewPassphrase = true; |
| 276 this.syncPrefs.passphrase = this.$$('#passphraseInput').value; | 313 this.syncPrefs.passphrase = this.passphrase_; |
| 277 | 314 |
| 278 this.browserProxy_.setSyncEncryption(this.syncPrefs).then( | 315 this.browserProxy_.setSyncEncryption(this.syncPrefs).then( |
| 279 this.handlePageStatusChanged_.bind(this)); | 316 this.handlePageStatusChanged_.bind(this)); |
| 280 }, | 317 }, |
| 281 | 318 |
| 282 /** | 319 /** |
| 283 * Sends the user-entered existing password to re-enable sync. | 320 * Sends the user-entered existing password to re-enable sync. |
| 284 * @private | 321 * @private |
| 285 */ | 322 */ |
| 286 onSubmitExistingPassphraseTap_: function() { | 323 onSubmitExistingPassphraseTap_: function() { |
| 287 assert(!this.creatingNewPassphrase_); | 324 assert(!this.creatingNewPassphrase_); |
| 288 | 325 |
| 289 this.syncPrefs.setNewPassphrase = false; | 326 this.syncPrefs.setNewPassphrase = false; |
| 290 | 327 |
| 291 var existingPassphraseInput = this.$$('#existingPassphraseInput'); | 328 this.syncPrefs.passphrase = this.existingPassphrase_; |
| 292 this.syncPrefs.passphrase = existingPassphraseInput.value; | 329 this.existingPassphrase_ = ''; |
| 293 existingPassphraseInput.value = ''; | |
| 294 | 330 |
| 295 this.browserProxy_.setSyncEncryption(this.syncPrefs).then( | 331 this.browserProxy_.setSyncEncryption(this.syncPrefs).then( |
| 296 this.handlePageStatusChanged_.bind(this)); | 332 this.handlePageStatusChanged_.bind(this)); |
| 297 }, | 333 }, |
| 298 | 334 |
| 299 /** | 335 /** |
| 300 * Called when the page status updates. | 336 * Called when the page status updates. |
| 301 * @param {!settings.PageStatus} pageStatus | 337 * @param {!settings.PageStatus} pageStatus |
| 302 * @private | 338 * @private |
| 303 */ | 339 */ |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 * Computed binding returning the selected encryption radio button. | 372 * Computed binding returning the selected encryption radio button. |
| 337 * @private | 373 * @private |
| 338 */ | 374 */ |
| 339 selectedEncryptionRadio_: function() { | 375 selectedEncryptionRadio_: function() { |
| 340 return this.syncPrefs.encryptAllData || this.creatingNewPassphrase_ ? | 376 return this.syncPrefs.encryptAllData || this.creatingNewPassphrase_ ? |
| 341 RadioButtonNames.ENCRYPT_WITH_PASSPHRASE : | 377 RadioButtonNames.ENCRYPT_WITH_PASSPHRASE : |
| 342 RadioButtonNames.ENCRYPT_WITH_GOOGLE; | 378 RadioButtonNames.ENCRYPT_WITH_GOOGLE; |
| 343 }, | 379 }, |
| 344 | 380 |
| 345 /** | 381 /** |
| 346 * Computed binding returning the encryption text body. | 382 * Computed binding returning text of the prompt for entering the passphrase. |
| 347 * @private | 383 * @private |
| 348 */ | 384 */ |
| 349 encryptWithPassphraseBody_: function() { | 385 enterPassphrasePrompt_: function() { |
| 350 if (this.syncPrefs && this.syncPrefs.fullEncryptionBody) | 386 if (this.syncPrefs && this.syncPrefs.passphraseTypeIsCustom) |
| 351 return this.syncPrefs.fullEncryptionBody; | 387 return this.syncPrefs.enterPassphraseBody; |
| 352 | 388 |
| 353 return this.i18n('encryptWithSyncPassphraseLabel'); | 389 return this.syncPrefs.enterGooglePassphraseBody; |
| 354 }, | 390 }, |
| 355 | 391 |
| 356 /** | 392 /** |
| 357 * @param {boolean} syncAllDataTypes | 393 * @param {boolean} syncAllDataTypes |
| 358 * @param {boolean} enforced | 394 * @param {boolean} enforced |
| 359 * @return {boolean} Whether the sync checkbox should be disabled. | 395 * @return {boolean} Whether the sync checkbox should be disabled. |
| 360 */ | 396 */ |
| 361 shouldSyncCheckboxBeDisabled_: function(syncAllDataTypes, enforced) { | 397 shouldSyncCheckboxBeDisabled_: function(syncAllDataTypes, enforced) { |
| 362 return syncAllDataTypes || enforced; | 398 return syncAllDataTypes || enforced; |
| 363 }, | 399 }, |
| 364 | 400 |
| 365 /** | 401 /** |
| 366 * @param {boolean} syncAllDataTypes | 402 * @param {boolean} syncAllDataTypes |
| 367 * @param {boolean} autofillSynced | 403 * @param {boolean} autofillSynced |
| 368 * @return {boolean} Whether the sync checkbox should be disabled. | 404 * @return {boolean} Whether the sync checkbox should be disabled. |
| 369 */ | 405 */ |
| 370 shouldPaymentsCheckboxBeDisabled_: function( | 406 shouldPaymentsCheckboxBeDisabled_: function( |
| 371 syncAllDataTypes, autofillSynced) { | 407 syncAllDataTypes, autofillSynced) { |
| 372 return syncAllDataTypes || !autofillSynced; | 408 return syncAllDataTypes || !autofillSynced; |
| 373 }, | 409 }, |
| 374 | 410 |
| 375 /** | 411 /** |
| 376 * Checks the supplied passphrases to ensure that they are not empty and that | 412 * Checks the supplied passphrases to ensure that they are not empty and that |
| 377 * they match each other. Additionally, displays error UI if they are | 413 * they match each other. Additionally, displays error UI if they are invalid. |
| 378 * invalid. | |
| 379 * @return {boolean} Whether the check was successful (i.e., that the | 414 * @return {boolean} Whether the check was successful (i.e., that the |
| 380 * passphrases were valid). | 415 * passphrases were valid). |
| 381 * @private | 416 * @private |
| 382 */ | 417 */ |
| 383 validateCreatedPassphrases_: function() { | 418 validateCreatedPassphrases_: function() { |
| 384 var passphraseInput = this.$$('#passphraseInput'); | 419 var emptyPassphrase = !this.passphrase_; |
| 385 var passphraseConfirmationInput = this.$$('#passphraseConfirmationInput'); | 420 var mismatchedPassphrase = this.passphrase_ != this.confirmation_; |
| 386 | 421 |
| 387 var passphrase = passphraseInput.value; | 422 this.$$('#passphraseInput').invalid = emptyPassphrase; |
| 388 var confirmation = passphraseConfirmationInput.value; | 423 this.$$('#passphraseConfirmationInput').invalid = |
| 389 | |
| 390 var emptyPassphrase = !passphrase; | |
| 391 var mismatchedPassphrase = passphrase != confirmation; | |
| 392 | |
| 393 passphraseInput.invalid = emptyPassphrase; | |
| 394 passphraseConfirmationInput.invalid = | |
| 395 !emptyPassphrase && mismatchedPassphrase; | 424 !emptyPassphrase && mismatchedPassphrase; |
| 396 | 425 |
| 397 return !emptyPassphrase && !mismatchedPassphrase; | 426 return !emptyPassphrase && !mismatchedPassphrase; |
| 398 }, | 427 }, |
| 399 }); | 428 }); |
| 400 | 429 |
| 401 })(); | 430 })(); |
| OLD | NEW |