| 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 * 'settings-lock-screen' allows the user to change how they unlock their | 7 * 'settings-lock-screen' allows the user to change how they unlock their |
| 8 * device. | 8 * device. |
| 9 * | 9 * |
| 10 * Example: | 10 * Example: |
| 11 * | 11 * |
| 12 * <settings-lock-screen | 12 * <settings-lock-screen |
| 13 * prefs="{{prefs}}"> | 13 * prefs="{{prefs}}"> |
| 14 * </settings-lock-screen> | 14 * </settings-lock-screen> |
| 15 */ | 15 */ |
| 16 | 16 |
| 17 Polymer({ | 17 Polymer({ |
| 18 is: 'settings-lock-screen', | 18 is: 'settings-lock-screen', |
| 19 | 19 |
| 20 behaviors: [I18nBehavior, LockStateBehavior, settings.RouteObserverBehavior], | 20 behaviors: [ |
| 21 I18nBehavior, |
| 22 LockStateBehavior, |
| 23 WebUIListenerBehavior, |
| 24 settings.RouteObserverBehavior, |
| 25 ], |
| 21 | 26 |
| 22 properties: { | 27 properties: { |
| 23 /** Preferences state. */ | 28 /** Preferences state. */ |
| 24 prefs: { | 29 prefs: {type: Object}, |
| 25 type: Object | |
| 26 }, | |
| 27 | 30 |
| 28 /** | 31 /** |
| 29 * setModes_ is a partially applied function that stores the previously | 32 * setModes_ is a partially applied function that stores the previously |
| 30 * entered password. It's defined only when the user has already entered a | 33 * entered password. It's defined only when the user has already entered a |
| 31 * valid password. | 34 * valid password. |
| 32 * | 35 * |
| 33 * @type {Object|undefined} | 36 * @type {Object|undefined} |
| 34 * @private | 37 * @private |
| 35 */ | 38 */ |
| 36 setModes_: { | 39 setModes_: { |
| 37 type: Object, | 40 type: Object, |
| 38 observer: 'onSetModesChanged_' | 41 observer: 'onSetModesChanged_', |
| 39 }, | 42 }, |
| 40 | 43 |
| 41 /** | 44 /** |
| 42 * writeUma_ is a function that handles writing uma stats. It may be | 45 * writeUma_ is a function that handles writing uma stats. It may be |
| 43 * overridden for tests. | 46 * overridden for tests. |
| 44 * | 47 * |
| 45 * @type {Function} | 48 * @type {Function} |
| 46 * @private | 49 * @private |
| 47 */ | 50 */ |
| 48 writeUma_: { | 51 writeUma_: { |
| 49 type: Object, | 52 type: Object, |
| 50 value: function() { return settings.recordLockScreenProgress; } | 53 value: function() { |
| 54 return settings.recordLockScreenProgress; |
| 55 }, |
| 51 }, | 56 }, |
| 52 | 57 |
| 53 /** | 58 /** |
| 54 * True if pin unlock settings should be displayed on this machine. | 59 * True if pin unlock settings should be displayed on this machine. |
| 55 * @private | 60 * @private |
| 56 */ | 61 */ |
| 57 pinUnlockEnabled_: { | 62 pinUnlockEnabled_: { |
| 58 type: Boolean, | 63 type: Boolean, |
| 59 value: function() { | 64 value: function() { |
| 60 return loadTimeData.getBoolean('pinUnlockEnabled'); | 65 return loadTimeData.getBoolean('pinUnlockEnabled'); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 72 return loadTimeData.getBoolean('fingerprintUnlockEnabled'); | 77 return loadTimeData.getBoolean('fingerprintUnlockEnabled'); |
| 73 }, | 78 }, |
| 74 readOnly: true, | 79 readOnly: true, |
| 75 }, | 80 }, |
| 76 | 81 |
| 77 /** @private */ | 82 /** @private */ |
| 78 numFingerprints_: { | 83 numFingerprints_: { |
| 79 type: Number, | 84 type: Number, |
| 80 value: 0, | 85 value: 0, |
| 81 }, | 86 }, |
| 87 |
| 88 /** |
| 89 * True if Easy Unlock is allowed on this machine. |
| 90 */ |
| 91 easyUnlockAllowed_: { |
| 92 type: Boolean, |
| 93 value: function() { |
| 94 return loadTimeData.getBoolean('easyUnlockAllowed'); |
| 95 }, |
| 96 readOnly: true, |
| 97 }, |
| 98 |
| 99 /** |
| 100 * True if Easy Unlock is enabled. |
| 101 */ |
| 102 easyUnlockEnabled_: { |
| 103 type: Boolean, |
| 104 value: function() { |
| 105 return loadTimeData.getBoolean('easyUnlockEnabled'); |
| 106 }, |
| 107 }, |
| 108 |
| 109 /** |
| 110 * True if Easy Unlock's proximity detection feature is allowed. |
| 111 */ |
| 112 easyUnlockProximityDetectionAllowed_: { |
| 113 type: Boolean, |
| 114 value: function() { |
| 115 return loadTimeData.getBoolean('easyUnlockAllowed') && |
| 116 loadTimeData.getBoolean('easyUnlockProximityDetectionAllowed'); |
| 117 }, |
| 118 readOnly: true, |
| 119 }, |
| 120 |
| 121 /** @private */ |
| 122 showEasyUnlockTurnOffDialog_: { |
| 123 type: Boolean, |
| 124 value: false, |
| 125 }, |
| 82 }, | 126 }, |
| 83 | 127 |
| 128 /** @private {?settings.EasyUnlockBrowserProxy} */ |
| 129 easyUnlockBrowserProxy_: null, |
| 130 |
| 84 /** @private {?settings.FingerprintBrowserProxy} */ | 131 /** @private {?settings.FingerprintBrowserProxy} */ |
| 85 browserProxy_: null, | 132 fingerprintBrowserProxy_: null, |
| 86 | 133 |
| 87 /** selectedUnlockType is defined in LockStateBehavior. */ | 134 /** selectedUnlockType is defined in LockStateBehavior. */ |
| 88 observers: ['selectedUnlockTypeChanged_(selectedUnlockType)'], | 135 observers: ['selectedUnlockTypeChanged_(selectedUnlockType)'], |
| 89 | 136 |
| 90 /** @override */ | 137 /** @override */ |
| 91 attached: function() { | 138 attached: function() { |
| 92 if (this.shouldAskForPassword_(settings.getCurrentRoute())) | 139 if (this.shouldAskForPassword_(settings.getCurrentRoute())) |
| 93 this.$.passwordPrompt.open(); | 140 this.$.passwordPrompt.open(); |
| 94 this.browserProxy_ = settings.FingerprintBrowserProxyImpl.getInstance(); | 141 |
| 142 this.easyUnlockBrowserProxy_ = |
| 143 settings.EasyUnlockBrowserProxyImpl.getInstance(); |
| 144 this.fingerprintBrowserProxy_ = |
| 145 settings.FingerprintBrowserProxyImpl.getInstance(); |
| 146 |
| 147 if (this.easyUnlockAllowed_) { |
| 148 this.addWebUIListener( |
| 149 'easy-unlock-enabled-status', |
| 150 this.handleEasyUnlockEnabledStatusChanged_.bind(this)); |
| 151 this.easyUnlockBrowserProxy_.getEnabledStatus().then( |
| 152 this.handleEasyUnlockEnabledStatusChanged_.bind(this)); |
| 153 } |
| 95 }, | 154 }, |
| 96 | 155 |
| 97 /** | 156 /** |
| 98 * Overridden from settings.RouteObserverBehavior. | 157 * Overridden from settings.RouteObserverBehavior. |
| 99 * @param {!settings.Route} newRoute | 158 * @param {!settings.Route} newRoute |
| 100 * @param {!settings.Route} oldRoute | 159 * @param {!settings.Route} oldRoute |
| 101 * @protected | 160 * @protected |
| 102 */ | 161 */ |
| 103 currentRouteChanged: function(newRoute, oldRoute) { | 162 currentRouteChanged: function(newRoute, oldRoute) { |
| 104 if (newRoute == settings.Route.LOCK_SCREEN && | 163 if (newRoute == settings.Route.LOCK_SCREEN && |
| 105 this.fingerprintUnlockEnabled_ && | 164 this.fingerprintUnlockEnabled_ && this.fingerprintBrowserProxy_) { |
| 106 this.browserProxy_) { | 165 this.fingerprintBrowserProxy_.getNumFingerprints().then( |
| 107 this.browserProxy_.getNumFingerprints().then( | |
| 108 function(numFingerprints) { | 166 function(numFingerprints) { |
| 109 this.numFingerprints_ = numFingerprints; | 167 this.numFingerprints_ = numFingerprints; |
| 110 }.bind(this)); | 168 }.bind(this)); |
| 111 } | 169 } |
| 112 | 170 |
| 113 if (this.shouldAskForPassword_(newRoute)) { | 171 if (this.shouldAskForPassword_(newRoute)) { |
| 114 this.$.passwordPrompt.open(); | 172 this.$.passwordPrompt.open(); |
| 115 } else if (newRoute != settings.Route.FINGERPRINT && | 173 } else if (newRoute != settings.Route.FINGERPRINT && |
| 116 oldRoute != settings.Route.FINGERPRINT) { | 174 oldRoute != settings.Route.FINGERPRINT) { |
| 117 // If the user navigated away from the lock screen settings page they will | 175 // If the user navigated away from the lock screen settings page they will |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 }, | 257 }, |
| 200 | 258 |
| 201 /** | 259 /** |
| 202 * @param {!settings.Route} route | 260 * @param {!settings.Route} route |
| 203 * @return {boolean} Whether the password dialog should be shown. | 261 * @return {boolean} Whether the password dialog should be shown. |
| 204 * @private | 262 * @private |
| 205 */ | 263 */ |
| 206 shouldAskForPassword_: function(route) { | 264 shouldAskForPassword_: function(route) { |
| 207 return route == settings.Route.LOCK_SCREEN && !this.setModes_; | 265 return route == settings.Route.LOCK_SCREEN && !this.setModes_; |
| 208 }, | 266 }, |
| 267 |
| 268 /** |
| 269 * Handler for when the Easy Unlock enabled status has changed. |
| 270 * @private |
| 271 */ |
| 272 handleEasyUnlockEnabledStatusChanged_: function(easyUnlockEnabled) { |
| 273 this.easyUnlockEnabled_ = easyUnlockEnabled; |
| 274 this.showEasyUnlockTurnOffDialog_ = |
| 275 easyUnlockEnabled && this.showEasyUnlockTurnOffDialog_; |
| 276 }, |
| 277 |
| 278 /** @private */ |
| 279 onEasyUnlockSetupTap_: function() { |
| 280 this.easyUnlockBrowserProxy_.startTurnOnFlow(); |
| 281 }, |
| 282 |
| 283 /** |
| 284 * @param {!Event} e |
| 285 * @private |
| 286 */ |
| 287 onEasyUnlockTurnOffTap_: function(e) { |
| 288 // Prevent the end of the tap event from focusing what is underneath the |
| 289 // button. |
| 290 e.preventDefault(); |
| 291 this.showEasyUnlockTurnOffDialog_ = true; |
| 292 }, |
| 293 |
| 294 /** @private */ |
| 295 onEasyUnlockTurnOffDialogClose_: function() { |
| 296 this.showEasyUnlockTurnOffDialog_ = false; |
| 297 |
| 298 // Restores focus on close to either the turn-off or set-up button, |
| 299 // whichever is being displayed. |
| 300 this.$$('.secondary-button').focus(); |
| 301 }, |
| 302 |
| 303 /** |
| 304 * @param {boolean} enabled |
| 305 * @param {!string} enabledStr |
| 306 * @param {!string} disabledStr |
| 307 * @private |
| 308 */ |
| 309 getEasyUnlockDescription_: function(enabled, enabledStr, disabledStr) { |
| 310 return enabled ? enabledStr : disabledStr; |
| 311 }, |
| 312 |
| 313 /** |
| 314 * @param {boolean} easyUnlockEnabled |
| 315 * @param {boolean} proximityDetectionAllowed |
| 316 * @private |
| 317 */ |
| 318 getShowEasyUnlockToggle_: function( |
| 319 easyUnlockEnabled, proximityDetectionAllowed) { |
| 320 return easyUnlockEnabled && proximityDetectionAllowed; |
| 321 }, |
| 209 }); | 322 }); |
| OLD | NEW |