Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(390)

Side by Side Diff: chrome/browser/resources/settings/people_page/quick_unlock_choose_method.js

Issue 2097673002: Add a settings screen that lets the user choose how they unlock their device. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pin-unlock-settings-authenticate
Patch Set: Adjust for authenticate screen comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 * 'settings-quick-unlock-choose-method' allows the user to change how they
8 * unlock their device. Note that setting up the unlock method is delegated
9 * to other elements.
10 *
11 * Example:
12 *
13 * <settings-quick-unlock-choose-method
14 * set-modes="[[quickUnlockSetModes]]"
15 * current-route="{{currentRoute}}"
16 * prefs="{{prefs}}">
17 * </settings-quick-unlock-choose-method>
18 */
19
20 (function() {
21 'use strict';
22
23 /** @const */ var ENABLE_LOCK_SCREEN_PREF = 'settings.enable_screen_lock';
24
25 /** @enum {string} */
26 var QuickUnlockUnlockType = {
27 VALUE_PENDING: 'value_pending',
28 NONE: 'none',
29 PASSWORD: 'password',
30 PIN_PASSWORD: 'pin+password'
31 };
32
33 Polymer({
34 is: 'settings-quick-unlock-choose-method',
35
36 behaviors: [
37 PrefsBehavior, QuickUnlockValidatingBehavior
38 ],
39
40 properties: {
41 /** Preferences state. */
42 prefs: {
43 type: Object,
44 notify: true,
45 },
46
47 /**
48 * The currently selected unlock type.
49 * @type {!QuickUnlockUnlockType}
50 * @private
51 */
52 selectedUnlockType_: {
53 type: String,
54 notify: true,
55 value: QuickUnlockUnlockType.VALUE_PENDING,
56 observer: 'selectedUnlockTypeChanged_'
57 }
58 },
59
60 observers: [
61 'onRouteChanged_(currentRoute)',
62 'onSetModesChanged_(setModes)'
63 ],
64
65 /** @override */
66 attached: function() {
67 CrSettingsPrefs.initialized.then(this.updateUnlockType_.bind(this));
68
69 chrome.settingsPrivate.onPrefsChanged.addListener(function(prefs) {
tommycli 2016/06/29 22:56:09 This needs a corresponding removal in detached rig
jdufault 2016/06/30 18:10:18 Done.
70 for (var i = 0; i < prefs.length; ++i) {
71 if (prefs[i].key == ENABLE_LOCK_SCREEN_PREF)
72 this.updateUnlockType_();
73 }
74 }.bind(this));
75
76 chrome.quickUnlockPrivate.onActiveModesChanged.addListener(
tommycli 2016/06/29 22:56:09 Same here right?
jdufault 2016/06/30 18:10:18 Done.
77 this.updateUnlockType_.bind(this));
78
79 this.checkForPassword();
80 },
81
82 /** @private */
83 onRouteChanged_: function() {
84 if (this.isScreenActive(QuickUnlockScreen.CHOOSE_METHOD))
85 this.checkForPassword();
86 },
87
88 /** @private */
89 onSetModesChanged_: function() {
90 if (this.isScreenActive(QuickUnlockScreen.CHOOSE_METHOD))
91 this.checkForPassword();
92 },
93
94 /**
95 * Updates the selected unlock type radio group. This function will get called
96 * after preferences are initialized, after the quick unlock mode has been
97 * changed, and after the lockscreen preference has changed.
98 *
99 * @private
100 */
101 updateUnlockType_: function() {
102 // The quickUnlockPrivate.onActiveModesChanged event could trigger this
103 // function before CrSettingsPrefs is initialized if another settings page
104 // changes the quick unlock state.
105 if (!CrSettingsPrefs.isInitialized)
106 return;
107
108 var hasScreenLock = this.getPref(ENABLE_LOCK_SCREEN_PREF).value;
tommycli 2016/06/29 22:56:09 Just move that into the if predicate
jdufault 2016/06/30 18:10:18 Done.
109 if (!hasScreenLock) {
110 this.selectedUnlockType_ = QuickUnlockUnlockType.NONE;
111 return;
112 }
113
114 chrome.quickUnlockPrivate.getActiveModes(function(modes) {
115 if (modes.includes(chrome.quickUnlockPrivate.QuickUnlockMode.PIN)) {
116 this.selectedUnlockType_ = QuickUnlockUnlockType.PIN_PASSWORD;
117 } else if (this.selectedUnlockType_ !=
118 QuickUnlockUnlockType.PIN_PASSWORD) {
119 // We don't want to clobber an existing PIN+PASSWORD state because the
120 // user needs to configure that option before actually using it.
121 //
122 // Specifically, this check is needed because this function gets called
123 // by the pref system after changing the unlock type from NONE to
124 // PIN+PASSWORD. Without the conditional assignment, this function would
125 // change the PIN+PASSWORD lock type to PASSWORD because the PIN hasn't
126 // been configured yet.
127 this.selectedUnlockType_ = QuickUnlockUnlockType.PASSWORD;
128 }
129 }.bind(this));
130 },
131
132 /**
133 * Called when the unlock type has changed.
134 * @param {!string} selected The current unlock type.
135 * @param {?string} previous The old unlock type. undefined if not present.
136 * @private
137 */
138 selectedUnlockTypeChanged_: function(selected, previous) {
139 // This method gets invoked when setting the initial value from the existing
140 // state. In that case, we don't need to bother updating the prefs.
141 if (!previous)
142 return;
143
144 var showLockScreen = selected != QuickUnlockUnlockType.NONE;
145 var showPinConfiguration = selected == QuickUnlockUnlockType.PIN_PASSWORD;
tommycli 2016/06/29 22:56:09 Since these vars are only used once each and are p
jdufault 2016/06/30 18:10:18 Done.
146
147 this.setPrefValue(ENABLE_LOCK_SCREEN_PREF, showLockScreen);
148 if (!showPinConfiguration) {
149 this.setModes.call(null, [], [], function(didSet) {
tommycli 2016/06/29 22:56:09 I think setModes already has the password partiall
jdufault 2016/06/30 18:10:18 null is for the `this` object. I'd prefer to use t
150 if (!didSet) {
tommycli 2016/06/29 22:56:09 Is it standard to print a console error on an unex
jdufault 2016/06/30 18:10:18 No UI right now, unfortunately. Right now, this fu
tommycli 2016/07/01 19:02:42 Ah, if it can only fail due to programmer error, I
jdufault 2016/07/13 00:19:22 Done.
151 console.error('Failed to clear quick unlock modes');
152 }
153 }.bind(this));
154 }
155 },
156
157 /**
158 * Used to show/hide the configure button for PIN unlock.
159 * @param {!string} selectedUnlockType The current unlock type. Used to let
160 * polymer know about the dependency.
161 * @private
162 */
163 computeConfigureContainerStyle_: function(selectedUnlockType) {
tommycli 2016/06/29 22:56:09 Is there a hard UI requirement spelled out to make
jdufault 2016/06/30 18:10:18 No, there's no hard UI requirement, but using hidd
tommycli 2016/07/01 19:02:42 Where's the code to the radio group animating in a
jdufault 2016/07/13 00:19:22 The radio group animation is part of paper-radio-g
164 if (selectedUnlockType == QuickUnlockUnlockType.PIN_PASSWORD)
165 return 'opacity: 1;';
166 return 'opacity: 0;';
167 },
168
169 /** @private */
170 onConfigurePin_: function() {
171 this.currentRoute = {
172 page: 'basic',
173 section: 'people',
174 subpage: [QuickUnlockScreen.CHOOSE_METHOD, QuickUnlockScreen.SETUP_PIN]
175 };
176 },
177 });
178
179 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698