Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 /** | 5 /** |
| 6 * @fileoverview | 6 * @fileoverview |
| 7 * | 7 * |
| 8 * 'settings-quick-unlock-authenticate' shows a password input prompt to the | 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 | 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. | 10 * account password, the page navigates to the quick unlock setup methods page. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 * profile-name="[[profileName_]]"> | 21 * profile-name="[[profileName_]]"> |
| 22 * </settings-quick-unlock-authenticate> | 22 * </settings-quick-unlock-authenticate> |
| 23 */ | 23 */ |
| 24 | 24 |
| 25 (function() { | 25 (function() { |
| 26 'use strict'; | 26 'use strict'; |
| 27 | 27 |
| 28 /** @const */ var PASSWORD_ACTIVE_DURATION_MS = 10 * 60 * 1000; // Ten minutes. | 28 /** @const */ var PASSWORD_ACTIVE_DURATION_MS = 10 * 60 * 1000; // Ten minutes. |
| 29 /** @const */ var AUTOSUBMIT_DELAY_MS = 500; // .5 seconds | 29 /** @const */ var AUTOSUBMIT_DELAY_MS = 500; // .5 seconds |
| 30 | 30 |
| 31 /** | |
| 32 * Helper method that checks if |password| is valid. | |
| 33 * @param {string} password | |
| 34 * @param {function(boolean):void} onCheck | |
| 35 */ | |
| 36 function checkAccountPassword_(password, onCheck) { | |
| 37 // We check the account password by trying to update the active set of quick | |
| 38 // unlock modes without changing any credentials. | |
| 39 chrome.quickUnlockPrivate.getActiveModes(function(modes) { | |
| 40 var credentials = | |
| 41 /** @type {!Array<string>} */ (Array(modes.length).fill('')); | |
| 42 chrome.quickUnlockPrivate.setModes(password, modes, credentials, onCheck); | |
| 43 }); | |
| 44 } | |
| 45 | |
| 46 Polymer({ | 31 Polymer({ |
| 47 is: 'settings-quick-unlock-authenticate', | 32 is: 'settings-quick-unlock-authenticate', |
| 48 | 33 |
| 49 behaviors: [ | 34 behaviors: [ |
| 50 QuickUnlockRoutingBehavior, | 35 QuickUnlockRoutingBehavior, |
| 51 ], | 36 ], |
| 52 | 37 |
| 53 properties: { | 38 properties: { |
| 54 /** | 39 /** |
| 55 * A wrapper around chrome.quickUnlockPrivate.setModes with the account | 40 * A wrapper around chrome.quickUnlockPrivate.setModes with the account |
| 56 * password already supplied. If this is null, the authentication screen | 41 * password already supplied. If this is null, the authentication screen |
| 57 * needs to be redisplayed. This property will be cleared after | 42 * needs to be redisplayed. This property will be cleared after |
| 58 * PASSWORD_ACTIVE_DURATION_MS milliseconds. | 43 * PASSWORD_ACTIVE_DURATION_MS milliseconds. |
|
tommycli
2016/07/18 20:47:24
nit: Update comment to say |this.passwordActiveDur
jdufault
2016/07/19 00:11:07
Done.
| |
| 59 */ | 44 */ |
| 60 setModes: { | 45 setModes: { |
| 61 type: Object, | 46 type: Object, |
| 62 notify: true | 47 notify: true |
| 63 }, | 48 }, |
| 64 | 49 |
| 65 /** | 50 /** |
| 66 * Name of the profile. | 51 * Name of the profile. |
| 67 */ | 52 */ |
| 68 profileName: String, | 53 profileName: String, |
| 69 | 54 |
| 70 /** | 55 /** |
| 71 * The actual value of the password field. This is cleared whenever the | 56 * The actual value of the password field. This is cleared whenever the |
| 72 * authentication screen is not displayed so that the user's password is not | 57 * authentication screen is not displayed so that the user's password is not |
| 73 * easily available to an attacker. The actual password is stored as an | 58 * easily available to an attacker. The actual password is stored as an |
| 74 * captured closure variable inside of setModes. | 59 * captured closure variable inside of setModes. |
| 75 * @private | 60 * @private |
| 76 */ | 61 */ |
| 77 password_: String, | 62 password_: String, |
| 78 | 63 |
| 79 /** | 64 /** |
| 80 * Helper property which marks password as valid/invalid. | 65 * Helper property which marks password as valid/invalid. |
| 81 * @private | 66 * @private |
| 82 */ | 67 */ |
| 83 passwordInvalid_: Boolean | 68 passwordInvalid_: Boolean, |
| 69 | |
| 70 /** | |
| 71 * Interface for chrome.quickUnlockPrivate calls. May be overriden by tests. | |
| 72 * @private | |
| 73 * @type {QuickUnlockPrivate} | |
| 74 */ | |
| 75 quickUnlockPrivate_: { | |
| 76 type: Object, | |
| 77 value: chrome.quickUnlockPrivate | |
| 78 }, | |
| 79 | |
| 80 /** | |
| 81 * PASSWORD_ACTIVE_DURATION_MS value. May be overridden by tests. | |
| 82 * @private | |
| 83 */ | |
| 84 passwordActiveDurationMs_: { | |
| 85 type: Number, | |
| 86 value: PASSWORD_ACTIVE_DURATION_MS | |
| 87 }, | |
| 88 | |
| 89 /** | |
| 90 * AUTOSUBMIT_DELAY_MS value. May be overridden by tests. | |
| 91 * @private | |
| 92 */ | |
| 93 autosubmitDelayMs_: { | |
| 94 type: Number, | |
| 95 value: AUTOSUBMIT_DELAY_MS | |
| 96 } | |
| 84 }, | 97 }, |
| 85 | 98 |
| 86 observers: [ | 99 observers: [ |
| 87 'onRouteChanged_(currentRoute)' | 100 'onRouteChanged_(currentRoute)' |
| 88 ], | 101 ], |
| 89 | 102 |
| 90 /** @private */ | 103 /** @private */ |
| 91 onRouteChanged_: function(currentRoute) { | 104 onRouteChanged_: function(currentRoute) { |
| 92 // Clear local state if this screen is not active so if this screen shows | 105 // Clear local state if this screen is not active so if this screen shows |
| 93 // up again the user will get a fresh UI. | 106 // up again the user will get a fresh UI. |
| 94 if (!this.isScreenActive(QuickUnlockScreen.AUTHENTICATE)) { | 107 if (!this.isScreenActive(QuickUnlockScreen.AUTHENTICATE)) { |
| 95 this.password_ = ''; | 108 this.password_ = ''; |
| 96 this.passwordInvalid_ = false; | 109 this.passwordInvalid_ = false; |
| 97 } | 110 } |
| 98 }, | 111 }, |
| 99 | 112 |
| 100 /** | 113 /** |
| 101 * Start or restart a timer to check the account password and move past the | 114 * Start or restart a timer to check the account password and move past the |
| 102 * authentication screen. | 115 * authentication screen. |
| 103 * @private | 116 * @private |
| 104 */ | 117 */ |
| 105 startDelayedPasswordCheck_: function() { | 118 startDelayedPasswordCheck_: function() { |
| 106 clearTimeout(this.delayedPasswordCheckTimeout_); | 119 clearTimeout(this.delayedPasswordCheckTimeout_); |
| 107 this.delayedPasswordCheckTimeout_ = | 120 this.delayedPasswordCheckTimeout_ = |
| 108 setTimeout(this.checkPasswordNow_.bind(this), AUTOSUBMIT_DELAY_MS); | 121 setTimeout(this.checkPasswordNow_.bind(this), this.autosubmitDelayMs_); |
| 109 }, | 122 }, |
| 110 | 123 |
| 111 /** | 124 /** |
| 112 * Run the account password check right now. This will cancel any delayed | 125 * Run the account password check right now. This will cancel any delayed |
| 113 * check. | 126 * check. |
| 114 * @private | 127 * @private |
| 115 */ | 128 */ |
| 116 checkPasswordNow_: function() { | 129 checkPasswordNow_: function() { |
| 117 clearTimeout(this.delayedPasswordCheckTimeout_); | 130 clearTimeout(this.delayedPasswordCheckTimeout_); |
| 118 clearTimeout(this.clearAccountPasswordTimeout_); | 131 clearTimeout(this.clearAccountPasswordTimeout_); |
| 119 | 132 |
| 120 // The user might have started entering a password and then deleted it all. | 133 // The user might have started entering a password and then deleted it all. |
| 121 // Do not submit/show an error in this case. | 134 // Do not submit/show an error in this case. |
| 122 if (!this.password_) { | 135 if (!this.password_) { |
| 123 this.passwordInvalid_ = false; | 136 this.passwordInvalid_ = false; |
| 124 return; | 137 return; |
| 125 } | 138 } |
| 126 | 139 |
| 127 function onPasswordChecked(valid) { | 140 function onPasswordChecked(valid) { |
| 128 // The password might have been cleared during the duration of the | 141 // The password might have been cleared during the duration of the |
| 129 // getActiveModes call. | 142 // getActiveModes call. |
| 130 this.passwordInvalid_ = !valid && !!this.password_; | 143 this.passwordInvalid_ = !valid && !!this.password_; |
| 131 | 144 |
| 132 if (valid) { | 145 if (valid) { |
| 133 // Create the |this.setModes| closure and automatically clear it after | 146 // Create the |this.setModes| closure and automatically clear it after |
| 134 // |PASSWORD_ACTIVE_DURATION_MS|. | 147 // |this.passwordActiveDurationMs_|. |
| 135 var password = this.password_; | 148 var password = this.password_; |
| 136 this.password_ = ''; | 149 this.password_ = ''; |
| 137 | 150 |
| 138 this.setModes = function(modes, credentials, onComplete) { | 151 this.setModes = function(modes, credentials, onComplete) { |
| 139 chrome.quickUnlockPrivate.setModes( | 152 this.quickUnlockPrivate_.setModes( |
| 140 password, modes, credentials, onComplete); | 153 password, modes, credentials, onComplete); |
| 141 }; | 154 }.bind(this); |
| 142 | 155 |
| 143 function clearSetModes() { | 156 function clearSetModes() { |
| 144 // Reset the password so that any cached references to this.setModes | 157 // Reset the password so that any cached references to this.setModes |
| 145 // will fail. | 158 // will fail. |
| 146 password = ''; | 159 password = ''; |
| 147 this.setModes = null; | 160 this.setModes = null; |
| 148 } | 161 } |
| 149 | 162 |
| 150 this.clearAccountPasswordTimeout_ = setTimeout( | 163 this.clearAccountPasswordTimeout_ = setTimeout( |
| 151 clearSetModes.bind(this), PASSWORD_ACTIVE_DURATION_MS); | 164 clearSetModes.bind(this), this.passwordActiveDurationMs_); |
| 152 | 165 |
| 153 this.currentRoute = { | 166 this.currentRoute = { |
| 154 page: 'basic', | 167 page: 'basic', |
| 155 section: 'people', | 168 section: 'people', |
| 156 subpage: [QuickUnlockScreen.CHOOSE_METHOD] | 169 subpage: [QuickUnlockScreen.CHOOSE_METHOD] |
| 157 }; | 170 }; |
| 158 } | 171 } |
| 159 } | 172 } |
| 160 | 173 |
| 161 checkAccountPassword_(this.password_, onPasswordChecked.bind(this)); | 174 this.checkAccountPassword_(this.password_, onPasswordChecked.bind(this)); |
|
tommycli
2016/07/18 20:47:24
Is this only called in one place? If so, why not i
jdufault
2016/07/19 00:11:07
The way we check for account password is a bit con
tommycli
2016/07/19 21:27:12
Okay that makes sense.
| |
| 175 }, | |
| 176 | |
| 177 /** | |
| 178 * Helper method that checks if |password| is valid. | |
| 179 * @param {string} password | |
| 180 * @param {function(boolean):void} onCheck | |
| 181 */ | |
| 182 checkAccountPassword_: function(password, onCheck) { | |
| 183 // We check the account password by trying to update the active set of quick | |
| 184 // unlock modes without changing any credentials. | |
| 185 this.quickUnlockPrivate_.getActiveModes(function(modes) { | |
| 186 var credentials = | |
| 187 /** @type {!Array<string>} */ (Array(modes.length).fill('')); | |
| 188 this.quickUnlockPrivate_.setModes(password, modes, credentials, onCheck); | |
| 189 }.bind(this)); | |
| 162 } | 190 } |
| 163 }); | 191 }); |
| 164 | 192 |
| 165 })(); | 193 })(); |
| OLD | NEW |