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

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: Address 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, QuickUnlockPasswordDetectBehavior
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 this.boundOnPrefsChanged_ = function(prefs) {
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 this.boundOnActiveModesChanged_ = this.updateUnlockType_.bind(this);
76
77 chrome.settingsPrivate.onPrefsChanged.addListener(
78 this.boundOnPrefsChanged_);
79 chrome.quickUnlockPrivate.onActiveModesChanged.addListener(
80 this.boundOnActiveModesChanged_);
81
82 this.askForPasswordIfUnset();
83 },
84
85 /** @override */
86 detached: function() {
87 chrome.settingsPrivate.onPrefsChanged.removeListener(
88 this.boundOnPrefsChanged_);
89 chrome.quickUnlockPrivate.onActiveModesChanged.removeListener(
90 this.boundOnActiveModesChanged_);
91 },
92
93 /** @private */
94 onRouteChanged_: function() {
95 if (this.isScreenActive(QuickUnlockScreen.CHOOSE_METHOD))
96 this.askForPasswordIfUnset();
97 },
98
99 /** @private */
100 onSetModesChanged_: function() {
101 if (this.isScreenActive(QuickUnlockScreen.CHOOSE_METHOD))
102 this.askForPasswordIfUnset();
103 },
104
105 /**
106 * Updates the selected unlock type radio group. This function will get called
107 * after preferences are initialized, after the quick unlock mode has been
108 * changed, and after the lockscreen preference has changed.
109 *
110 * @private
111 */
112 updateUnlockType_: function() {
113 // The quickUnlockPrivate.onActiveModesChanged event could trigger this
114 // function before CrSettingsPrefs is initialized if another settings page
115 // changes the quick unlock state.
116 if (!CrSettingsPrefs.isInitialized)
117 return;
118
119 if (!this.getPref(ENABLE_LOCK_SCREEN_PREF).value) {
120 this.selectedUnlockType_ = QuickUnlockUnlockType.NONE;
121 return;
122 }
123
124 chrome.quickUnlockPrivate.getActiveModes(function(modes) {
125 if (modes.includes(chrome.quickUnlockPrivate.QuickUnlockMode.PIN)) {
126 this.selectedUnlockType_ = QuickUnlockUnlockType.PIN_PASSWORD;
127 } else if (this.selectedUnlockType_ !=
128 QuickUnlockUnlockType.PIN_PASSWORD) {
129 // We don't want to clobber an existing PIN+PASSWORD state because the
130 // user needs to configure that option before actually using it.
131 //
132 // Specifically, this check is needed because this function gets called
133 // by the pref system after changing the unlock type from NONE to
134 // PIN+PASSWORD. Without the conditional assignment, this function would
135 // change the PIN+PASSWORD lock type to PASSWORD because the PIN hasn't
136 // been configured yet.
137 this.selectedUnlockType_ = QuickUnlockUnlockType.PASSWORD;
138 }
139 }.bind(this));
140 },
141
142 /**
143 * Called when the unlock type has changed.
144 * @param {!string} selected The current unlock type.
145 * @param {?string} previous The old unlock type. undefined if not present.
146 * @private
147 */
148 selectedUnlockTypeChanged_: function(selected, previous) {
149 // This method gets invoked when setting the initial value from the existing
150 // state. In that case, we don't need to bother updating the prefs.
151 if (!previous)
152 return;
153
154 this.setPrefValue(ENABLE_LOCK_SCREEN_PREF,
155 selected != QuickUnlockUnlockType.NONE);
156 if (selected != QuickUnlockUnlockType.PIN_PASSWORD && this.setModes) {
157 this.setModes.call(null, [], [], function(didSet) {
158 assert(didSet, 'Failed to clear quick unlock modes');
159 });
160 }
161 },
162
163 /**
164 * Retruns true if the setup pin section should be shown.
165 * @param {!string} selectedUnlockType The current unlock type. Used to let
166 * polymer know about the dependency.
167 * @private
168 */
169 showSetupPin_: function(selectedUnlockType) {
170 return selectedUnlockType === QuickUnlockUnlockType.PIN_PASSWORD;
171 },
172
173 /** @private */
174 onConfigurePin_: function() {
175 this.currentRoute = {
176 page: 'basic',
177 section: 'people',
178 subpage: [QuickUnlockScreen.CHOOSE_METHOD, QuickUnlockScreen.SETUP_PIN]
179 };
180 },
181 });
182
183 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698