Roll src/third_party/WebKit eac3800:0237a66 (svn 202606:202607)
[chromium-blink-merge.git] / components / proximity_auth / webui / resources / device-list.js
blobae9375a7f62ca3fad61d49cad2716760619189c7
1 // Copyright 2015 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.
5 Polymer({
6 is: 'device-list',
8 properties: {
9 /**
10 * The label of the list to be displayed.
11 * @type {string}
13 label: {
14 type: String,
15 value: 'Device List',
18 /**
19 * Info of the devices contained in the list.
20 * @type {Array<DeviceInfo>}
22 devices: Array,
24 /**
25 * Set with the selected device when the unlock key dialog is opened.
27 deviceForDialog_: {
28 type: Object,
29 value: null
32 /**
33 * True if currently toggling a device as an unlock key.
35 toggleUnlockKeyInProgress_: {
36 type: Boolean,
37 value: false,
41 /**
42 * Shows the toggle unlock key dialog when the toggle button is pressed for an
43 * item.
44 * @param {Event} event
46 showUnlockKeyDialog_: function(event) {
47 this.deviceForDialog_ = event.model.item;
48 var dialog = this.querySelector('#unlock-key-dialog');
49 dialog.open();
52 /**
53 * Called when the unlock key dialog button is clicked to make the selected
54 * device an unlock key or remove it as an unlock key.
55 * @param {Event} event
57 toggleUnlockKey_: function(event) {
58 if (!this.deviceForDialog_)
59 return;
60 this.toggleUnlockKeyInProgress_ = true;
61 CryptAuthInterface.addObserver(this);
63 var publicKey = this.deviceForDialog_.publicKey;
64 var makeUnlockKey = !this.deviceForDialog_.unlockKey;
65 CryptAuthInterface.toggleUnlockKey(publicKey, makeUnlockKey);
68 /**
69 * Called when the toggling the unlock key completes, so we can close the
70 * dialog.
72 onUnlockKeyToggled: function() {
73 this.toggleUnlockKeyInProgress_ = false;
74 CryptAuthInterface.removeObserver(this);
75 var dialog = this.querySelector('#unlock-key-dialog');
76 dialog.close();
79 /**
80 * Handles when the toggle connection button is clicked for a list item.
81 * @param {Event} event
83 toggleConnection_: function(event) {
84 var deviceInfo = event.model.item;
85 chrome.send('toggleConnection', [deviceInfo.publicKey]);
88 /**
89 * @param {string} reason The device ineligibility reason.
90 * @return {string} The prettified ineligibility reason.
91 * @private
93 prettifyReason_: function(reason) {
94 if (reason == null || reason == '')
95 return '';
96 var reasonWithSpaces = reason.replace(/([A-Z])/g, ' $1');
97 return reasonWithSpaces[0].toUpperCase() + reasonWithSpaces.slice(1);
101 * @param {string} connectionStatus The Bluetooth connection status.
102 * @return {string} The icon id to be shown for the connection state.
103 * @private
105 getIconForConnection_: function(connectionStatus) {
106 switch (connectionStatus) {
107 case 'connected':
108 return 'device:bluetooth-connected';
109 case 'disconnected':
110 return 'device:bluetooth';
111 case 'connecting':
112 return 'device:bluetooth-searching';
113 default:
114 return 'device:bluetooth-disabled';
119 * @param {DeviceInfo} device
120 * @return {string} The icon id to be shown for the unlock key state of the
121 * device.
123 getIconForUnlockKey_: function(device) {
124 return 'hardware:phonelink' + (!device.unlockKey ? '-off' : '');
128 * @param {Object} remoteState The remote state of the device.
129 * @return {string} The icon representing the state.
131 getIconForRemoteState_: function(remoteState) {
132 if (remoteState != null && remoteState.userPresent &&
133 remoteState.secureScreenLock && remoteState.trustAgent) {
134 return 'icons:lock-open';
135 } else {
136 return 'icons:lock-outline';
141 * @param {string} reason The device ineligibility reason.
142 * @return {string} The icon id to be shown for the ineligibility reason.
143 * @private
145 getIconForIneligibilityReason_: function(reason) {
146 switch (reason) {
147 case 'badOsVersion':
148 return 'notification:system-update';
149 case 'bluetoothNotSupported':
150 return 'device:bluetooth-disabled';
151 case 'deviceOffline':
152 return 'device:signal-cellular-off';
153 case 'invalidCredentials':
154 return 'notification:sync-problem';
155 default:
156 return 'error';
161 * @param {number} userPresence
162 * @return {string}
164 getUserPresenceText_: function(userPresence) {
165 var userPresenceMap = {
166 0: 'User Present',
167 1: 'User Absent',
168 2: 'User Presence Unknown',
170 return userPresenceMap[userPresence];
174 * @param {number} screenLock
175 * @return {string}
177 getScreenLockText_: function(screenLock) {
178 var screenLockMap = {
179 0: 'Secure Screen Lock Enabled',
180 1: 'Secure Screen Lock Disabled',
181 2: 'Secure Screen Lock State Unknown',
183 return screenLockMap[screenLock];
187 * @param {number} trustAgent
188 * @return {string}
190 getTrustAgentText_: function(trustAgent) {
191 var trustAgentMap = {
192 0: 'Trust Agent Enabled',
193 1: 'Trust Agent Disabled',
194 2: 'Trust Agent Unsupported',
196 return trustAgentMap[trustAgent];