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 * profile-name="[[profileName_]]"> | |
21 * </settings-quick-unlock-authenticate> | |
22 */ | |
23 | |
24 (function() { | |
25 'use strict'; | |
26 | |
27 /** @const */ var PASSWORD_ACTIVE_DURATION_MS = 10 * 60 * 1000; // Ten minutes. | |
28 /** @const */ var AUTOSUBMIT_DELAY_MS = 500; // .5 seconds | |
29 | |
30 /** | |
31 * Helper method that checks if |password| is valid. | |
32 * @param {string} password | |
33 * @param {function(boolean):void} onCheck | |
34 */ | |
35 function checkAccountPassword_(password, onCheck) { | |
36 // We check the account password by trying to update the active set of quick | |
37 // unlock modes without changing any credentials. | |
38 chrome.quickUnlockPrivate.getActiveModes(function(modes) { | |
39 var credentials = | |
40 /** @type {!Array<string>} */ (Array(modes.length).fill('')); | |
41 chrome.quickUnlockPrivate.setModes(password, modes, credentials, onCheck); | |
42 }); | |
43 } | |
44 | |
45 Polymer({ | |
46 is: 'settings-quick-unlock-authenticate', | |
47 | |
48 behavior: [settings.RouteObserverBehavior], | |
49 | |
50 properties: { | |
51 /** | |
52 * A wrapper around chrome.quickUnlockPrivate.setModes with the account | |
53 * password already supplied. If this is null, the authentication screen | |
54 * needs to be redisplayed. This property will be cleared after | |
55 * PASSWORD_ACTIVE_DURATION_MS milliseconds. | |
56 */ | |
57 setModes: { | |
58 type: Object, | |
59 notify: true | |
60 }, | |
61 | |
62 /** | |
63 * Name of the profile. | |
64 */ | |
65 profileName: String, | |
66 | |
67 /** | |
68 * The actual value of the password field. This is cleared whenever the | |
69 * authentication screen is not displayed so that the user's password is not | |
70 * easily available to an attacker. The actual password is stored as an | |
71 * captured closure variable inside of setModes. | |
72 * @private | |
73 */ | |
74 password_: String, | |
75 | |
76 /** | |
77 * Helper property which marks password as valid/invalid. | |
78 * @private | |
79 */ | |
80 passwordInvalid_: Boolean | |
81 }, | |
82 | |
83 /** @protected */ | |
84 currentRouteChanged: function() { | |
85 // Clear local state if this screen is not active so if this screen shows | |
86 // up again the user will get a fresh UI. | |
87 if (settings.getCurrentRoute() == settings.Route.QUICK_UNLOCK_AUTHENTICATE) | |
88 return; | |
89 | |
90 this.password_ = ''; | |
91 this.passwordInvalid_ = false; | |
92 }, | |
93 | |
94 /** | |
95 * Start or restart a timer to check the account password and move past the | |
96 * authentication screen. | |
97 * @private | |
98 */ | |
99 startDelayedPasswordCheck_: function() { | |
100 clearTimeout(this.delayedPasswordCheckTimeout_); | |
101 this.delayedPasswordCheckTimeout_ = | |
102 setTimeout(this.checkPasswordNow_.bind(this), AUTOSUBMIT_DELAY_MS); | |
103 }, | |
104 | |
105 /** | |
106 * Run the account password check right now. This will cancel any delayed | |
107 * check. | |
108 * @private | |
109 */ | |
110 checkPasswordNow_: function() { | |
111 clearTimeout(this.delayedPasswordCheckTimeout_); | |
112 clearTimeout(this.clearAccountPasswordTimeout_); | |
113 | |
114 // The user might have started entering a password and then deleted it all. | |
115 // Do not submit/show an error in this case. | |
116 if (!this.password_) { | |
117 this.passwordInvalid_ = false; | |
118 return; | |
119 } | |
120 | |
121 function onPasswordChecked(valid) { | |
122 // The password might have been cleared during the duration of the | |
123 // getActiveModes call. | |
124 this.passwordInvalid_ = !valid && !!this.password_; | |
125 | |
126 if (valid) { | |
127 // Create the |this.setModes| closure and automatically clear it after | |
128 // |PASSWORD_ACTIVE_DURATION_MS|. | |
129 var password = this.password_; | |
130 this.password_ = ''; | |
131 | |
132 this.setModes = function(modes, credentials, onComplete) { | |
133 chrome.quickUnlockPrivate.setModes( | |
134 password, modes, credentials, onComplete); | |
135 }; | |
136 | |
137 function clearSetModes() { | |
138 // Reset the password so that any cached references to this.setModes | |
139 // will fail. | |
140 password = ''; | |
141 this.setModes = null; | |
142 } | |
143 | |
144 this.clearAccountPasswordTimeout_ = setTimeout( | |
145 clearSetModes.bind(this), PASSWORD_ACTIVE_DURATION_MS); | |
146 | |
147 settings.navigateTo(settings.Route.QUICK_UNLOCK_CHOOSE_METHOD); | |
148 } | |
149 } | |
150 | |
151 checkAccountPassword_(this.password_, onPasswordChecked.bind(this)); | |
152 } | |
153 }); | |
154 | |
155 })(); | |
OLD | NEW |