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 * This element provides a wrapper around chrome.quickUnlockPrivate.setModes | |
| 13 * which has a prebound account password (the |set-modes| property). The account | |
| 14 * password by itself is not avaialble for other elements to access. | |
|
tommycli
2016/06/29 21:04:23
typo on "available"
jdufault
2016/06/29 22:02:04
Done.
| |
| 15 * | |
| 16 * Example: | |
| 17 * | |
| 18 * <settings-quick-unlock-authenticate | |
| 19 * set-modes="[[setModes]]" | |
| 20 * current-route="{{currentRoute}}" | |
| 21 * profile-name="[[profileName_]]"> | |
| 22 * </settings-quick-unlock-authenticate> | |
| 23 */ | |
| 24 | |
| 25 (function() { | |
| 26 'use strict'; | |
| 27 | |
| 28 /** @const */ var PASSWORD_ACTIVE_DURATION_MS = 10 * 60 * 1000; // Ten minutes. | |
| 29 /** @const */ var AUTOSUBMIT_DELAY_MS = 500; // .5 seconds | |
| 30 | |
| 31 Polymer({ | |
| 32 is: 'settings-quick-unlock-authenticate', | |
| 33 | |
| 34 behaviors: [ | |
| 35 QuickUnlockRoutingBehavior, | |
| 36 ], | |
| 37 | |
| 38 properties: { | |
| 39 /** | |
| 40 * A partially applied chrome.quickUnlockPrivate.setModes function, where | |
| 41 * the password has already been provided. If this is null, then the | |
| 42 * authentication screen needs to be redispalyed to recapture the user's | |
|
tommycli
2016/06/29 21:04:23
"redisplayed" typo
jdufault
2016/06/29 22:02:04
Done.
| |
| 43 * password. The value stored here will reset after | |
| 44 * PASSWORD_ACTIVE_DURATION_MS milliseconds. | |
| 45 */ | |
|
tommycli
2016/06/29 21:04:23
How about revise the comment to similar to:
If th
jdufault
2016/06/29 22:02:04
Done.
| |
| 46 setModes: { | |
| 47 type: Object, | |
| 48 notify: true | |
| 49 }, | |
| 50 | |
| 51 /** | |
| 52 * Name of the profile. | |
| 53 */ | |
| 54 profileName: String, | |
| 55 | |
| 56 /** | |
| 57 * The actual value of the password field. This is cleared whenever the | |
| 58 * authentication screen is not displayed so that the user's password is not | |
| 59 * easily available to an attacker. The actual password is stored as an | |
| 60 * captured closure variable inside of setModes. | |
| 61 * @private | |
| 62 */ | |
| 63 password_: String, | |
| 64 | |
| 65 /** | |
| 66 * Helper property which marks password as valid/invalid. | |
| 67 * @private | |
| 68 */ | |
| 69 passwordInvalid_: Boolean | |
| 70 }, | |
| 71 | |
| 72 observers: [ | |
| 73 'onRouteChanged_(currentRoute)' | |
| 74 ], | |
| 75 | |
| 76 /** @private */ | |
| 77 onRouteChanged_: function(currentRoute) { | |
| 78 // Clear local state if this screen is not active so if this screen shows | |
| 79 // up again the user will get a fresh UI. | |
| 80 if (!this.isScreenActive(QuickUnlockScreen.AUTHENTICATE)) { | |
| 81 this.password_ = ''; | |
| 82 this.passwordInvalid_ = false; | |
| 83 } | |
| 84 }, | |
| 85 | |
| 86 /** | |
| 87 * Start or restart a timer to check the account password and move past the | |
| 88 * authentication screen. | |
| 89 * @private | |
| 90 */ | |
| 91 startDelayedPasswordCheck_: function() { | |
| 92 clearTimeout(this.delayedPasswordCheckTimeout_); | |
| 93 this.delayedPasswordCheckTimeout_ = | |
| 94 setTimeout(this.checkPasswordNow_.bind(this), AUTOSUBMIT_DELAY_MS); | |
| 95 }, | |
| 96 | |
| 97 /** | |
| 98 * Run the account password check right now. This will cancel any delayed | |
| 99 * check. | |
| 100 * @private | |
| 101 */ | |
| 102 checkPasswordNow_: function() { | |
| 103 clearTimeout(this.delayedPasswordCheckTimeout_); | |
| 104 clearTimeout(this.clearAccountPasswordTimeout_); | |
| 105 | |
| 106 // The user might have started entering a password and then deleted it all. | |
| 107 // Do not submit/show an error in this case. | |
| 108 if (!this.password_) { | |
| 109 this.passwordInvalid_ = false; | |
| 110 return; | |
| 111 } | |
| 112 | |
| 113 // We check the account password by trying to update the active set of quick | |
| 114 // unlock modes without changing any credentials. | |
| 115 chrome.quickUnlockPrivate.getActiveModes(function(modes) { | |
| 116 var credentials = | |
| 117 /** @type {!Array<string>} */ (Array(modes.length).fill('')); | |
| 118 chrome.quickUnlockPrivate.setModes(this.password_, modes, credentials, | |
| 119 onPasswordChecked.bind(this)); | |
| 120 }.bind(this)); | |
|
tommycli
2016/06/29 21:04:23
Here i'd recommend something instead like this:
v
jdufault
2016/06/29 22:02:04
I've pulled the chrome.quickUnlockPrivate calls ou
| |
| 121 | |
| 122 function onPasswordChecked(valid) { | |
| 123 // Note that the password might have been cleared during the duration of | |
| 124 // the getActiveModes call. | |
| 125 this.passwordInvalid_ = !valid && !!this.password_; | |
| 126 | |
| 127 if (valid) { | |
| 128 // Create the |this.setModes| closure and automatically clear it after | |
| 129 // |PASSWORD_ACTIVE_DURATION_MS|. | |
| 130 var password = this.password_; | |
| 131 this.password_ = ''; | |
| 132 | |
| 133 this.setModes = function(modes, credentials, onComplete) { | |
| 134 chrome.quickUnlockPrivate.setModes( | |
| 135 password, modes, credentials, onComplete); | |
| 136 }; | |
| 137 | |
| 138 function clearSetModes() { | |
| 139 // Reset the password so that any cached references to this.setModes | |
| 140 // will fail. | |
| 141 password = ''; | |
| 142 this.setModes = null; | |
| 143 } | |
| 144 | |
| 145 this.clearAccountPasswordTimeout_ = setTimeout( | |
| 146 clearSetModes.bind(this), PASSWORD_ACTIVE_DURATION_MS); | |
| 147 | |
| 148 this.currentRoute = { | |
| 149 page: 'basic', | |
| 150 section: 'people', | |
| 151 subpage: [QuickUnlockScreen.CHOOSE_METHOD] | |
| 152 }; | |
| 153 } | |
| 154 } | |
| 155 } | |
| 156 }); | |
| 157 | |
| 158 })(); | |
| OLD | NEW |