File: device-list.js

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (198 lines) | stat: -rw-r--r-- 5,254 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Polymer({
  is: 'device-list',

  properties: {
    /**
     * The label of the list to be displayed.
     * @type {string}
     */
    label: {
      type: String,
      value: 'Device List',
    },

    /**
     * Info of the devices contained in the list.
     * @type {Array<DeviceInfo>}
     */
    devices: Array,

    /**
     * Set with the selected device when the unlock key dialog is opened.
     */
    deviceForDialog_: {
      type: Object,
      value: null
    },

    /**
     * True if currently toggling a device as an unlock key.
     */
    toggleUnlockKeyInProgress_: {
      type: Boolean,
      value: false,
    },
  },

  /**
   * Shows the toggle unlock key dialog when the toggle button is pressed for an
   * item.
   * @param {Event} event
   */
  showUnlockKeyDialog_: function(event) {
    this.deviceForDialog_ = event.model.item;
    var dialog = this.querySelector('#unlock-key-dialog');
    dialog.open();
  },

  /**
   * Called when the unlock key dialog button is clicked to make the selected
   * device an unlock key or remove it as an unlock key.
   * @param {Event} event
   */
  toggleUnlockKey_: function(event) {
    if (!this.deviceForDialog_)
      return;
    this.toggleUnlockKeyInProgress_ = true;
    CryptAuthInterface.addObserver(this);

    var publicKey = this.deviceForDialog_.publicKey;
    var makeUnlockKey = !this.deviceForDialog_.unlockKey;
    CryptAuthInterface.toggleUnlockKey(publicKey, makeUnlockKey);
  },

  /**
   * Called when the toggling the unlock key completes, so we can close the
   * dialog.
   */
  onUnlockKeyToggled: function() {
    this.toggleUnlockKeyInProgress_ = false;
    CryptAuthInterface.removeObserver(this);
    var dialog = this.querySelector('#unlock-key-dialog');
    dialog.close();
  },

  /**
   * Handles when the toggle connection button is clicked for a list item.
   * @param {Event} event
   */
  toggleConnection_: function(event) {
    var deviceInfo = event.model.item;
    chrome.send('toggleConnection', [deviceInfo.publicKey]);
  },

  /**
   * @param {string} reason The device ineligibility reason.
   * @return {string} The prettified ineligibility reason.
   * @private
   */
  prettifyReason_: function(reason) {
    if (reason == null || reason == '')
      return '';
    var reasonWithSpaces = reason.replace(/([A-Z])/g, ' $1');
    return reasonWithSpaces[0].toUpperCase() + reasonWithSpaces.slice(1);
  },

  /**
   * @param {string} connectionStatus The Bluetooth connection status.
   * @return {string} The icon id to be shown for the connection state.
   * @private
   */
  getIconForConnection_: function(connectionStatus) {
    switch (connectionStatus) {
      case 'connected':
        return 'device:bluetooth-connected';
      case 'disconnected':
        return 'device:bluetooth';
      case 'connecting':
        return 'device:bluetooth-searching';
      default:
        return 'device:bluetooth-disabled';
    }
  },

  /**
   * @param {DeviceInfo} device
   * @return {string} The icon id to be shown for the unlock key state of the
   *     device.
   */
  getIconForUnlockKey_: function(device) {
    return 'hardware:phonelink' + (!device.unlockKey ? '-off' : '');
  },

  /**
   * @param {Object} remoteState The remote state of the device.
   * @return {string} The icon representing the state.
   */
  getIconForRemoteState_: function(remoteState) {
    if (remoteState != null && remoteState.userPresent &&
        remoteState.secureScreenLock && remoteState.trustAgent) {
      return 'icons:lock-open';
    } else {
      return 'icons:lock-outline';
    }
  },

  /**
   * @param {string} reason The device ineligibility reason.
   * @return {string} The icon id to be shown for the ineligibility reason.
   * @private
   */
  getIconForIneligibilityReason_: function(reason) {
    switch (reason) {
      case 'badOsVersion':
        return 'notification:system-update';
      case 'bluetoothNotSupported':
        return 'device:bluetooth-disabled';
      case 'deviceOffline':
        return 'device:signal-cellular-off';
      case 'invalidCredentials':
        return 'notification:sync-problem';
      default:
        return 'error';
    };
  },

  /**
   * @param {number} userPresence
   * @return {string}
   */
  getUserPresenceText_: function(userPresence) {
    var userPresenceMap = {
      0: 'User Present',
      1: 'User Absent',
      2: 'User Presence Unknown',
    };
    return userPresenceMap[userPresence];
  },

  /**
   * @param {number} screenLock
   * @return {string}
   */
  getScreenLockText_: function(screenLock) {
    var screenLockMap = {
      0: 'Secure Screen Lock Enabled',
      1: 'Secure Screen Lock Disabled',
      2: 'Secure Screen Lock State Unknown',
    };
    return screenLockMap[screenLock];
  },

  /**
   * @param {number} trustAgent
   * @return {string}
   */
  getTrustAgentText_: function(trustAgent) {
    var trustAgentMap = {
      0: 'Trust Agent Enabled',
      1: 'Trust Agent Disabled',
      2: 'Trust Agent Unsupported',
    };
    return trustAgentMap[trustAgent];
  },
});