Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 /** | |
| 6 * @fileoverview | |
| 7 * | |
| 8 * 'settings-quick-unlock-authenticate' shows a password input prompt to the | |
| 9 * user. It validates the password is correct. Once the user has entered their | |
| 10 * account password, the page navigates to the quick unlock setup methods page. | |
| 11 * | |
| 12 * Example: | |
| 13 * | |
| 14 * <settings-quick-unlock-authenticate | |
| 15 * account-password="{{quickUnlockAccountPassword}}" | |
| 16 * current-route="{{currentRoute}}" | |
| 17 * profile-name="[[profileName_]]"> | |
| 18 * </settings-quick-unlock-authenticate> | |
| 19 */ | |
| 20 | |
| 21 /** @const */ var PASSWORD_ACTIVE_DURATION_MS = 10 * 60 * 1000; // Ten minutes. | |
| 22 | |
| 23 Polymer({ | |
| 24 is: 'settings-quick-unlock-authenticate', | |
| 25 | |
| 26 behaviors: [ | |
| 27 QuickUnlockRoutingBehavior | |
| 28 ], | |
| 29 | |
| 30 properties: { | |
| 31 /** | |
| 32 * The user's account/gaia password. This value will self-reset after a | |
| 33 * preset duration (see PASSWORD_ACTIVE_DURATION_MS). | |
| 34 */ | |
| 35 accountPassword: { | |
| 36 type: String, | |
| 37 notify: true, | |
| 38 value: '' | |
| 39 }, | |
| 40 | |
| 41 /** | |
| 42 * Name of the profile. | |
| 43 */ | |
| 44 profileName: String, | |
| 45 | |
| 46 /** | |
| 47 * The actual value of the password field. Stored separately from | |
| 48 * accountPassword to split up the different lifetimes. | |
| 49 * @private | |
| 50 */ | |
| 51 password_: String, | |
| 52 | |
| 53 /** | |
| 54 * Helper property which marks password as valid/invalid. | |
| 55 * @private | |
| 56 */ | |
| 57 passwordInvalid_: Boolean | |
| 58 }, | |
| 59 | |
| 60 observers: [ | |
| 61 'onRouteChanged_(currentRoute)' | |
| 62 ], | |
| 63 | |
| 64 /** @override */ | |
| 65 screenType: function() { | |
| 66 return QuickUnlockScreen.AUTHENTICATE; | |
| 67 }, | |
| 68 | |
| 69 /** @private */ | |
| 70 onRouteChanged_: function(currentRoute) { | |
| 71 // Clear local state if this screen is not active so if this screen shows | |
| 72 // up again the user will get a fresh UI. | |
| 73 if (!this.isScreenActive(QuickUnlockScreen.AUTHENTICATE)) { | |
| 74 this.password_ = ''; | |
| 75 this.passwordInvalid_ = false; | |
| 76 } | |
| 77 }, | |
| 78 | |
| 79 /** | |
| 80 * Start or restart a timer to check the account password and move past the | |
| 81 * authentication screen. | |
| 82 * @private | |
| 83 */ | |
| 84 startDelayedPasswordCheck_: function() { | |
|
tommycli
2016/06/24 00:56:38
There's no Submit button? Can the user still press
jdufault
2016/06/29 19:06:39
Right, there is no submit button. Pressing enter w
| |
| 85 clearTimeout(this.delayedPasswordCheckoutTimeout_); | |
| 86 this.delayedPasswordCheckoutTimeout_ = | |
| 87 setTimeout(this.checkPasswordNow_.bind(this), 500); | |
| 88 }, | |
| 89 | |
| 90 /** | |
| 91 * Run the account password check right now. This will cancel any delayed | |
| 92 * check. | |
| 93 * @private | |
| 94 */ | |
| 95 checkPasswordNow_: function() { | |
| 96 clearTimeout(this.delayedPasswordCheckoutTimeout_); | |
| 97 | |
| 98 // The user might have started entering a password and then deleted it all. | |
| 99 // Do not submit/show an error in this case. | |
| 100 if (!this.password_) { | |
| 101 this.passwordInvalid_ = false; | |
| 102 return; | |
| 103 } | |
| 104 | |
| 105 // We check the account password by trying to update the active set of quick | |
| 106 // unlock modes without changing any credentials. | |
| 107 chrome.quickUnlockPrivate.getActiveModes(function(modes) { | |
| 108 var credentials = Array(modes.length).fill(''); | |
| 109 chrome.quickUnlockPrivate.setModes(this.password_, modes, credentials, | |
| 110 onPasswordChecked.bind(this)); | |
| 111 }.bind(this)); | |
| 112 | |
| 113 function onPasswordChecked(valid) { | |
| 114 // Note that the password might have been cleared during the duration of | |
| 115 // the getActiveModes call. | |
| 116 this.passwordInvalid_ = !valid && !!this.password_; | |
| 117 | |
| 118 if (valid) { | |
| 119 // Set the account password, clear it after | |
| 120 // |PASSWORD_ACTIVE_DURATION_MS|, and navigate to the choose method | |
| 121 // screen. | |
| 122 this.accountPassword = this.password_; | |
| 123 setTimeout(this.clearAccountPassword_.bind(this), | |
|
tommycli
2016/06/24 00:56:39
We would want to cancel this timeout if we re-ente
jdufault
2016/06/29 19:06:39
Done
| |
| 124 PASSWORD_ACTIVE_DURATION_MS); | |
| 125 | |
| 126 this.navigateToScreen(QuickUnlockScreen.CHOOSE_METHOD); | |
| 127 } | |
| 128 } | |
| 129 }, | |
| 130 | |
| 131 /** @private */ | |
| 132 clearAccountPassword_: function() { | |
| 133 this.accountPassword = ''; | |
| 134 } | |
| 135 }); | |
| OLD | NEW |