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.
10 * The label of the list to be displayed.
19 * Info of the devices contained in the list.
20 * @type {Array<DeviceInfo>}
25 * Set with the selected device when the unlock key dialog is opened.
33 * True if currently toggling a device as an unlock key.
35 toggleUnlockKeyInProgress_
: {
42 * Shows the toggle unlock key dialog when the toggle button is pressed for an
44 * @param {Event} event
46 showUnlockKeyDialog_: function(event
) {
47 this.deviceForDialog_
= event
.model
.item
;
48 var dialog
= this.querySelector('#unlock-key-dialog');
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_
)
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
);
69 * Called when the toggling the unlock key completes, so we can close the
72 onUnlockKeyToggled: function() {
73 this.toggleUnlockKeyInProgress_
= false;
74 CryptAuthInterface
.removeObserver(this);
75 var dialog
= this.querySelector('#unlock-key-dialog');
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
]);
89 * @param {string} reason The device ineligibility reason.
90 * @return {string} The prettified ineligibility reason.
93 prettifyReason_: function(reason
) {
94 if (reason
== null || reason
== '')
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.
105 getIconForConnection_: function(connectionStatus
) {
106 switch (connectionStatus
) {
108 return 'device:bluetooth-connected';
110 return 'device:bluetooth';
112 return 'device:bluetooth-searching';
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
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';
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.
145 getIconForIneligibilityReason_: function(reason
) {
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';
161 * @param {number} userPresence
164 getUserPresenceText_: function(userPresence
) {
165 var userPresenceMap
= {
168 2: 'User Presence Unknown',
170 return userPresenceMap
[userPresence
];
174 * @param {number} screenLock
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
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
];