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

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

Issue 2539733004: MD Settings: Overhaul Easy Unlock Turn Off Dialog. (Closed)
Patch Set: fix copy pasta Created 4 years 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
« no previous file with comments | « no previous file | chrome/browser/resources/settings/people_page/people_page.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 A dialog allowing the user to turn off the Easy Unlock feature. 6 * @fileoverview A dialog allowing the user to turn off the Easy Unlock feature.
7 */ 7 */
8 8
9 (function() { 9 (function() {
10 10
11 /** 11 /**
12 * Possible UI statuses for the EasyUnlockTurnOffDialogElement. 12 * Possible UI statuses for the EasyUnlockTurnOffDialogElement.
13 * See easy_unlock_settings_handler.cc. 13 * See easy_unlock_settings_handler.cc.
14 * @enum {string} 14 * @enum {string}
15 */ 15 */
16 var EasyUnlockTurnOffStatus = { 16 var EasyUnlockTurnOffStatus = {
17 UNKNOWN: 'unknown', 17 UNKNOWN: 'unknown',
18 OFFLINE: 'offline', 18 OFFLINE: 'offline',
19 IDLE: 'idle', 19 IDLE: 'idle',
20 PENDING: 'pending', 20 PENDING: 'pending',
21 SERVER_ERROR: 'server-error', 21 SERVER_ERROR: 'server-error',
22 }; 22 };
23 23
24 Polymer({ 24 Polymer({
25 is: 'easy-unlock-turn-off-dialog', 25 is: 'easy-unlock-turn-off-dialog',
26 26
27 behaviors: [I18nBehavior, WebUIListenerBehavior], 27 behaviors: [I18nBehavior, WebUIListenerBehavior],
28 28
29 properties: { 29 properties: {
30 /** @private {!settings.EasyUnlockBrowserProxy} */
31 browserProxy_: Object,
32
33 /** @private {!EasyUnlockTurnOffStatus} */ 30 /** @private {!EasyUnlockTurnOffStatus} */
34 status_: { 31 status_: {
35 type: String, 32 type: String,
36 value: EasyUnlockTurnOffStatus.UNKNOWN, 33 value: EasyUnlockTurnOffStatus.UNKNOWN,
37 }, 34 },
38
39 /** @private {?WebUIListener} */
40 turnOffStatusWebUiListener_: {
41 type: Object,
42 value: null,
43 },
44 }, 35 },
45 36
37 /** @private {settings.EasyUnlockBrowserProxy} */
38 browserProxy_: null,
39
46 /** @override */ 40 /** @override */
47 ready: function() { 41 attached: function() {
48 this.browserProxy_ = settings.EasyUnlockBrowserProxyImpl.getInstance(); 42 this.browserProxy_ = settings.EasyUnlockBrowserProxyImpl.getInstance();
49 43
50 this.addWebUIListener( 44 this.addWebUIListener(
51 'easy-unlock-enabled-status', 45 'easy-unlock-enabled-status',
52 this.handleEasyUnlockEnabledStatusChanged_.bind(this)); 46 this.handleEasyUnlockEnabledStatusChanged_.bind(this));
53 },
54 47
55 /** 48 this.addWebUIListener(
56 * Opens the dialog. 49 'easy-unlock-turn-off-flow-status',
57 */ 50 function(status) { this.status_ = status; }.bind(this));
58 open: function() { 51
52 // Since the dialog text depends on the status, defer opening until we have
53 // retrieved the turn off status to prevent UI flicker.
59 this.getTurnOffStatus_().then(function(status) { 54 this.getTurnOffStatus_().then(function(status) {
60 this.status_ = status; 55 this.status_ = status;
61 this.$.dialog.showModal(); 56 this.$.dialog.showModal();
62 }.bind(this)); 57 }.bind(this));
63
64 // The turn off flow status listener should only be active when the dialog
65 // is actually open.
66 assert(this.turnOffStatusWebUiListener_ == null);
67 this.turnOffStatusWebUiListener_ = cr.addWebUIListener(
68 'easy-unlock-turn-off-flow-status',
69 function(status) { this.status_ = status; }.bind(this));
70 }, 58 },
71 59
72 /** 60 /**
73 * @return {!Promise<!EasyUnlockTurnOffStatus>} 61 * @return {!Promise<!EasyUnlockTurnOffStatus>}
74 * @private 62 * @private
75 */ 63 */
76 getTurnOffStatus_: function() { 64 getTurnOffStatus_: function() {
77 return navigator.onLine ? 65 return navigator.onLine ?
78 this.browserProxy_.getTurnOffFlowStatus() : 66 this.browserProxy_.getTurnOffFlowStatus() :
79 Promise.resolve(EasyUnlockTurnOffStatus.OFFLINE); 67 Promise.resolve(EasyUnlockTurnOffStatus.OFFLINE);
80 }, 68 },
81 69
82 /** 70 /**
83 * This dialog listens for Easy Unlock to become disabled. This signals 71 * This dialog listens for Easy Unlock to become disabled. This signals
84 * that the turnoff process has succeeded. Regardless of whether the turnoff 72 * that the turnoff process has succeeded. Regardless of whether the turnoff
85 * was initiated from this tab or another, this closes the dialog. 73 * was initiated from this tab or another, this closes the dialog.
86 * @param {boolean} easyUnlockEnabled 74 * @param {boolean} easyUnlockEnabled
87 * @private 75 * @private
88 */ 76 */
89 handleEasyUnlockEnabledStatusChanged_: function(easyUnlockEnabled) { 77 handleEasyUnlockEnabledStatusChanged_: function(easyUnlockEnabled) {
90 var dialog = /** @type {!CrDialogElement} */ this.$.dialog; 78 var dialog = /** @type {!CrDialogElement} */ this.$.dialog;
91 if (!easyUnlockEnabled && dialog.open) 79 if (!easyUnlockEnabled && dialog.open)
92 this.onCancelTap_(); 80 this.onCancelTap_();
93 }, 81 },
94 82
95 /** @private */ 83 /** @private */
96 onCancelTap_: function() { 84 onCancelTap_: function() {
97 if (this.turnOffStatusWebUiListener_) {
98 cr.removeWebUIListener(this.turnOffStatusWebUiListener_);
99 this.turnOffStatusWebUiListener_ = null;
100 }
101
102 this.browserProxy_.cancelTurnOffFlow(); 85 this.browserProxy_.cancelTurnOffFlow();
103 this.$.dialog.close(); 86 this.$.dialog.close();
104 }, 87 },
105 88
106 /** @private */ 89 /** @private */
107 onTurnOffTap_: function() { 90 onTurnOffTap_: function() {
108 this.browserProxy_.startTurnOffFlow(); 91 this.browserProxy_.startTurnOffFlow();
109 }, 92 },
110 93
111 /** 94 /**
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 * @return {boolean} 180 * @return {boolean}
198 * @private 181 * @private
199 */ 182 */
200 isTurnOffButtonEnabled_: function(status) { 183 isTurnOffButtonEnabled_: function(status) {
201 return status == EasyUnlockTurnOffStatus.IDLE || 184 return status == EasyUnlockTurnOffStatus.IDLE ||
202 status == EasyUnlockTurnOffStatus.SERVER_ERROR; 185 status == EasyUnlockTurnOffStatus.SERVER_ERROR;
203 }, 186 },
204 }); 187 });
205 188
206 })(); 189 })();
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/settings/people_page/people_page.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698