| 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 available for other elements to access. | |
| 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 /** | |
| 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({ | |
| 47 is: 'settings-quick-unlock-authenticate', | |
| 48 | |
| 49 properties: { | |
| 50 /** @type {!settings.Route} */ | |
| 51 currentRoute: { | |
| 52 type: Object, | |
| 53 observer: 'onRouteChanged_', | |
| 54 }, | |
| 55 | |
| 56 /** | |
| 57 * A wrapper around chrome.quickUnlockPrivate.setModes with the account | |
| 58 * password already supplied. If this is null, the authentication screen | |
| 59 * needs to be redisplayed. This property will be cleared after | |
| 60 * PASSWORD_ACTIVE_DURATION_MS milliseconds. | |
| 61 */ | |
| 62 setModes: { | |
| 63 type: Object, | |
| 64 notify: true | |
| 65 }, | |
| 66 | |
| 67 /** | |
| 68 * Name of the profile. | |
| 69 */ | |
| 70 profileName: String, | |
| 71 | |
| 72 /** | |
| 73 * The actual value of the password field. This is cleared whenever the | |
| 74 * authentication screen is not displayed so that the user's password is not | |
| 75 * easily available to an attacker. The actual password is stored as an | |
| 76 * captured closure variable inside of setModes. | |
| 77 * @private | |
| 78 */ | |
| 79 password_: String, | |
| 80 | |
| 81 /** | |
| 82 * Helper property which marks password as valid/invalid. | |
| 83 * @private | |
| 84 */ | |
| 85 passwordInvalid_: Boolean | |
| 86 }, | |
| 87 | |
| 88 /** @private */ | |
| 89 onRouteChanged_: function(currentRoute) { | |
| 90 // Clear local state if this screen is not active so if this screen shows | |
| 91 // up again the user will get a fresh UI. | |
| 92 if (this.currentRoute != settings.Route.QUICK_UNLOCK_AUTHENTICATE) { | |
| 93 this.password_ = ''; | |
| 94 this.passwordInvalid_ = false; | |
| 95 } | |
| 96 }, | |
| 97 | |
| 98 /** | |
| 99 * Start or restart a timer to check the account password and move past the | |
| 100 * authentication screen. | |
| 101 * @private | |
| 102 */ | |
| 103 startDelayedPasswordCheck_: function() { | |
| 104 clearTimeout(this.delayedPasswordCheckTimeout_); | |
| 105 this.delayedPasswordCheckTimeout_ = | |
| 106 setTimeout(this.checkPasswordNow_.bind(this), AUTOSUBMIT_DELAY_MS); | |
| 107 }, | |
| 108 | |
| 109 /** | |
| 110 * Run the account password check right now. This will cancel any delayed | |
| 111 * check. | |
| 112 * @private | |
| 113 */ | |
| 114 checkPasswordNow_: function() { | |
| 115 clearTimeout(this.delayedPasswordCheckTimeout_); | |
| 116 clearTimeout(this.clearAccountPasswordTimeout_); | |
| 117 | |
| 118 // The user might have started entering a password and then deleted it all. | |
| 119 // Do not submit/show an error in this case. | |
| 120 if (!this.password_) { | |
| 121 this.passwordInvalid_ = false; | |
| 122 return; | |
| 123 } | |
| 124 | |
| 125 function onPasswordChecked(valid) { | |
| 126 // The password might have been cleared during the duration of the | |
| 127 // getActiveModes call. | |
| 128 this.passwordInvalid_ = !valid && !!this.password_; | |
| 129 | |
| 130 if (valid) { | |
| 131 // Create the |this.setModes| closure and automatically clear it after | |
| 132 // |PASSWORD_ACTIVE_DURATION_MS|. | |
| 133 var password = this.password_; | |
| 134 this.password_ = ''; | |
| 135 | |
| 136 this.setModes = function(modes, credentials, onComplete) { | |
| 137 chrome.quickUnlockPrivate.setModes( | |
| 138 password, modes, credentials, onComplete); | |
| 139 }; | |
| 140 | |
| 141 function clearSetModes() { | |
| 142 // Reset the password so that any cached references to this.setModes | |
| 143 // will fail. | |
| 144 password = ''; | |
| 145 this.setModes = null; | |
| 146 } | |
| 147 | |
| 148 this.clearAccountPasswordTimeout_ = setTimeout( | |
| 149 clearSetModes.bind(this), PASSWORD_ACTIVE_DURATION_MS); | |
| 150 | |
| 151 settings.navigateTo(settings.Route.QUICK_UNLOCK_CHOOSE_METHOD); | |
| 152 } | |
| 153 } | |
| 154 | |
| 155 checkAccountPassword_(this.password_, onPasswordChecked.bind(this)); | |
| 156 } | |
| 157 }); | |
| 158 | |
| 159 })(); | |
| OLD | NEW |