OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 * A bluetooth device. | 6 * A bluetooth device. |
7 * @constructor | 7 * @constructor |
8 */ | 8 */ |
9 var BluetoothDevice = function() { | 9 var BluetoothDevice = function() { |
10 // The device's address (MAC format, must be unique). | 10 // The device's address (MAC format, must be unique). |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 Polymer({ | 54 Polymer({ |
55 is: 'bluetooth-settings', | 55 is: 'bluetooth-settings', |
56 | 56 |
57 behaviors: [Polymer.NeonAnimatableBehavior], | 57 behaviors: [Polymer.NeonAnimatableBehavior], |
58 | 58 |
59 properties: { | 59 properties: { |
60 /** | 60 /** |
61 * A set of bluetooth devices. | 61 * A set of bluetooth devices. |
62 * @type !Array<!BluetoothDevice> | 62 * @type !Array<!BluetoothDevice> |
63 */ | 63 */ |
64 devices: {type: Array, value: function() { return []; }}, | 64 devices: { |
| 65 type: Array, |
| 66 value: function() { |
| 67 return []; |
| 68 } |
| 69 }, |
65 | 70 |
66 /** | 71 /** |
67 * A set of predefined bluetooth devices. | 72 * A set of predefined bluetooth devices. |
68 * @type !Array<!Bluetooth> | 73 * @type !Array<!Bluetooth> |
69 */ | 74 */ |
70 predefinedDevices: {type: Array, value: function() { return []; }}, | 75 predefinedDevices: { |
| 76 type: Array, |
| 77 value: function() { |
| 78 return []; |
| 79 } |
| 80 }, |
71 | 81 |
72 /** | 82 /** |
73 * A bluetooth device object which is currently being edited. | 83 * A bluetooth device object which is currently being edited. |
74 * @type {BluetoothDevice} | 84 * @type {BluetoothDevice} |
75 */ | 85 */ |
76 currentEditableObject: { | 86 currentEditableObject: { |
77 type: Object, | 87 type: Object, |
78 value: function() { return {}; } | 88 value: function() { |
| 89 return {}; |
| 90 } |
79 }, | 91 }, |
80 | 92 |
81 /** | 93 /** |
82 * The index of the bluetooth device object which is currently being edited. | 94 * The index of the bluetooth device object which is currently being edited. |
83 * This is initially set to -1 (i.e. no device selected) because not custom | 95 * This is initially set to -1 (i.e. no device selected) because not custom |
84 * devices exist when the page loads. | 96 * devices exist when the page loads. |
85 */ | 97 */ |
86 currentEditIndex: {type: Number, value: function() { return -1; }}, | 98 currentEditIndex: { |
| 99 type: Number, |
| 100 value: function() { |
| 101 return -1; |
| 102 } |
| 103 }, |
87 | 104 |
88 /** | 105 /** |
89 * A set of options for the possible bluetooth device classes/types. | 106 * A set of options for the possible bluetooth device classes/types. |
90 * Object |value| attribute comes from values in the WebUI, set in | 107 * Object |value| attribute comes from values in the WebUI, set in |
91 * setDeviceClassOptions. | 108 * setDeviceClassOptions. |
92 * @type !Array<! {text: string, value: int} > | 109 * @type !Array<! {text: string, value: int} > |
93 */ | 110 */ |
94 deviceClassOptions: { | 111 deviceClassOptions: { |
95 type: Array, | 112 type: Array, |
96 value: function() { | 113 value: function() { |
97 return [ | 114 return [ |
98 {text: 'Unknown', value: 0}, | 115 {text: 'Unknown', value: 0}, {text: 'Mouse', value: 0x2580}, |
99 {text: 'Mouse', value: 0x2580}, | 116 {text: 'Keyboard', value: 0x2540}, {text: 'Audio', value: 0x240408}, |
100 {text: 'Keyboard', value: 0x2540}, | 117 {text: 'Phone', value: 0x7a020c}, {text: 'Computer', value: 0x104} |
101 {text: 'Audio', value: 0x240408}, | |
102 {text: 'Phone', value: 0x7a020c}, | |
103 {text: 'Computer', value: 0x104} | |
104 ]; | 118 ]; |
105 } | 119 } |
106 }, | 120 }, |
107 | 121 |
108 /** | 122 /** |
109 * A set of strings representing the method to be used for | 123 * A set of strings representing the method to be used for |
110 * authenticating a device during a pair request. | 124 * authenticating a device during a pair request. |
111 * @type !Array<string> | 125 * @type !Array<string> |
112 */ | 126 */ |
113 deviceAuthenticationMethods: { | 127 deviceAuthenticationMethods: { |
114 type: Array, | 128 type: Array, |
115 value: function() { return []; } | 129 value: function() { |
| 130 return []; |
| 131 } |
116 }, | 132 }, |
117 | 133 |
118 /** | 134 /** |
119 * A set of strings representing the actions which can be done when | 135 * A set of strings representing the actions which can be done when |
120 * a secure device is paired/requests a pair. | 136 * a secure device is paired/requests a pair. |
121 * @type !Array<string> | 137 * @type !Array<string> |
122 */ | 138 */ |
123 deviceAuthenticationActions: { | 139 deviceAuthenticationActions: { |
124 type: Array, | 140 type: Array, |
125 value: function() { return []; } | 141 value: function() { |
| 142 return []; |
| 143 } |
126 }, | 144 }, |
127 }, | 145 }, |
128 | 146 |
129 /** | 147 /** |
130 * Contains keys for all the device paths which have been discovered. Used | 148 * Contains keys for all the device paths which have been discovered. Used |
131 * to look up whether or not a device is listed already. | 149 * to look up whether or not a device is listed already. |
132 * @type {Object} | 150 * @type {Object} |
133 */ | 151 */ |
134 devicePaths: {}, | 152 devicePaths: {}, |
135 | 153 |
136 ready: function() { | 154 ready: function() { |
137 chrome.send('requestBluetoothInfo'); | 155 chrome.send('requestBluetoothInfo'); |
138 }, | 156 }, |
139 | 157 |
140 observers: ['currentEditableObjectChanged(currentEditableObject.*)'], | 158 observers: ['currentEditableObjectChanged(currentEditableObject.*)'], |
141 | 159 |
142 /** | 160 /** |
143 * Called when a property of the currently editable object is edited. | 161 * Called when a property of the currently editable object is edited. |
144 * Sets the corresponding property for the object in |this.devices|. | 162 * Sets the corresponding property for the object in |this.devices|. |
145 * @param {Object} obj An object containing event information (ex. which | 163 * @param {Object} obj An object containing event information (ex. which |
146 * property of |this.currentEditableObject| was changed, what its value | 164 * property of |this.currentEditableObject| was changed, what its value |
147 * is, etc.) | 165 * is, etc.) |
148 */ | 166 */ |
149 currentEditableObjectChanged: function(obj) { | 167 currentEditableObjectChanged: function(obj) { |
150 if (this.currentEditIndex >= 0) { | 168 if (this.currentEditIndex >= 0) { |
151 var prop = obj.path.split('.')[1]; | 169 var prop = obj.path.split('.')[1]; |
152 this.set('devices.' + this.currentEditIndex.toString() + '.' + prop, | 170 this.set( |
153 obj.value); | 171 'devices.' + this.currentEditIndex.toString() + '.' + prop, |
| 172 obj.value); |
154 } | 173 } |
155 }, | 174 }, |
156 | 175 |
157 /** | 176 /** |
158 * Called when the device edit dialog is opened. Re-validates necessary input | 177 * Called when the device edit dialog is opened. Re-validates necessary input |
159 * fields. | 178 * fields. |
160 */ | 179 */ |
161 editDialogOpened: function() { | 180 editDialogOpened: function() { |
162 this.validateAddress(); | 181 this.validateAddress(); |
163 this.validatePath(); | 182 this.validatePath(); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 */ | 282 */ |
264 showAuthToken: function(pairMethod) { | 283 showAuthToken: function(pairMethod) { |
265 return pairMethod && pairMethod != 'None'; | 284 return pairMethod && pairMethod != 'None'; |
266 }, | 285 }, |
267 | 286 |
268 /** | 287 /** |
269 * Called by the WebUI which provides a list of devices which are connected | 288 * Called by the WebUI which provides a list of devices which are connected |
270 * to the main adapter. | 289 * to the main adapter. |
271 * @param {!Array<!BluetoothDevice>} devices A list of bluetooth devices. | 290 * @param {!Array<!BluetoothDevice>} devices A list of bluetooth devices. |
272 */ | 291 */ |
273 updateBluetoothInfo: function(predefinedDevices, loadedCustomDevices, | 292 updateBluetoothInfo: function( |
274 pairingMethodOptions, pairingActionOptions) { | 293 predefinedDevices, loadedCustomDevices, pairingMethodOptions, |
| 294 pairingActionOptions) { |
275 this.predefinedDevices = this.loadDevicesFromList(predefinedDevices, true); | 295 this.predefinedDevices = this.loadDevicesFromList(predefinedDevices, true); |
276 this.devices = this.loadDevicesFromList(loadedCustomDevices, false); | 296 this.devices = this.loadDevicesFromList(loadedCustomDevices, false); |
277 this.deviceAuthenticationMethods = pairingMethodOptions; | 297 this.deviceAuthenticationMethods = pairingMethodOptions; |
278 this.deviceAuthenticationActions = pairingActionOptions; | 298 this.deviceAuthenticationActions = pairingActionOptions; |
279 }, | 299 }, |
280 | 300 |
281 /** | 301 /** |
282 * Builds complete BluetoothDevice objects for each element in |devices_list|. | 302 * Builds complete BluetoothDevice objects for each element in |devices_list|. |
283 * @param {!Array<!BluetoothDevice>} devices_list A list of incomplete | 303 * @param {!Array<!BluetoothDevice>} devices_list A list of incomplete |
284 * BluetoothDevice provided by the C++ WebUI. | 304 * BluetoothDevice provided by the C++ WebUI. |
285 * @param {boolean} predefined Whether or not the device is a predefined one. | 305 * @param {boolean} predefined Whether or not the device is a predefined one. |
286 */ | 306 */ |
287 loadDevicesFromList: function(devices, predefined) { | 307 loadDevicesFromList: function(devices, predefined) { |
288 /** @type {!Array<!BluetoothDevice>} */ var deviceList = []; | 308 /** @type {!Array<!BluetoothDevice>} */ var deviceList = []; |
289 | 309 |
290 for (var i = 0; i < devices.length; ++i) { | 310 for (var i = 0; i < devices.length; ++i) { |
291 if (this.devicePaths[devices[i].path] != undefined) continue; | 311 if (this.devicePaths[devices[i].path] != undefined) |
| 312 continue; |
292 | 313 |
293 // Get the label for the device class which should be selected. | 314 // Get the label for the device class which should be selected. |
294 devices[i].class = this.getTextForDeviceClass(devices[i].classValue); | 315 devices[i].class = this.getTextForDeviceClass(devices[i].classValue); |
295 devices[i].pairingAuthToken = devices[i].pairingAuthToken.toString(); | 316 devices[i].pairingAuthToken = devices[i].pairingAuthToken.toString(); |
296 deviceList.push(devices[i]); | 317 deviceList.push(devices[i]); |
297 this.devicePaths[devices[i].path] = { | 318 this.devicePaths[devices[i].path] = { |
298 predefined: predefined, | 319 predefined: predefined, |
299 index: deviceList.length - 1 | 320 index: deviceList.length - 1 |
300 }; | 321 }; |
301 } | 322 } |
302 | 323 |
303 return deviceList; | 324 return deviceList; |
304 }, | 325 }, |
305 | 326 |
306 /** | 327 /** |
307 * Called when a device is paired from the Tray. Checks the paired box for | 328 * Called when a device is paired from the Tray. Checks the paired box for |
308 * the device with path |path|. | 329 * the device with path |path|. |
309 */ | 330 */ |
310 devicePairedFromTray: function(path) { | 331 devicePairedFromTray: function(path) { |
311 var obj = this.devicePaths[path]; | 332 var obj = this.devicePaths[path]; |
312 | 333 |
313 if (obj == undefined) return; | 334 if (obj == undefined) |
| 335 return; |
314 | 336 |
315 var index = obj.index; | 337 var index = obj.index; |
316 var devicePath = (obj.predefined ? 'predefinedDevices.' : 'devices.'); | 338 var devicePath = (obj.predefined ? 'predefinedDevices.' : 'devices.'); |
317 devicePath += obj.index.toString(); | 339 devicePath += obj.index.toString(); |
318 this.set(devicePath + '.paired', true); | 340 this.set(devicePath + '.paired', true); |
319 }, | 341 }, |
320 | 342 |
321 /** | 343 /** |
322 * On-change handler for a checkbox in the device list. Pairs/unpairs the | 344 * On-change handler for a checkbox in the device list. Pairs/unpairs the |
323 * device associated with the box checked/unchecked. | 345 * device associated with the box checked/unchecked. |
(...skipping 28 matching lines...) Expand all Loading... |
352 } | 374 } |
353 }, | 375 }, |
354 | 376 |
355 /** | 377 /** |
356 * Called from Chrome OS back-end when a pair request fails. | 378 * Called from Chrome OS back-end when a pair request fails. |
357 * @param {string} path The path of the device which failed to pair. | 379 * @param {string} path The path of the device which failed to pair. |
358 */ | 380 */ |
359 pairFailed: function(path) { | 381 pairFailed: function(path) { |
360 var obj = this.devicePaths[path]; | 382 var obj = this.devicePaths[path]; |
361 | 383 |
362 if (obj == undefined) return; | 384 if (obj == undefined) |
| 385 return; |
363 | 386 |
364 var devicePath = (obj.predefined ? 'predefinedDevices.' : 'devices.'); | 387 var devicePath = (obj.predefined ? 'predefinedDevices.' : 'devices.'); |
365 devicePath += obj.index.toString(); | 388 devicePath += obj.index.toString(); |
366 this.set(devicePath + '.paired', false); | 389 this.set(devicePath + '.paired', false); |
367 }, | 390 }, |
368 | 391 |
369 /** | 392 /** |
370 * On-change event handler for a checkbox in the device list. | 393 * On-change event handler for a checkbox in the device list. |
371 * @param {Event} event Contains event data. |event.model.index| is the index | 394 * @param {Event} event Contains event data. |event.model.index| is the index |
372 * of the item which the target is contained in. | 395 * of the item which the target is contained in. |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 this.splice('devices', index, 1); | 498 this.splice('devices', index, 1); |
476 }, | 499 }, |
477 | 500 |
478 /** | 501 /** |
479 * This function is called when a device is removed from the main bluetooth | 502 * This function is called when a device is removed from the main bluetooth |
480 * adapter's device list. It sets that device's |.discoverable| and |.paired| | 503 * adapter's device list. It sets that device's |.discoverable| and |.paired| |
481 * attributes to false. | 504 * attributes to false. |
482 * @param {string} path A bluetooth device's path. | 505 * @param {string} path A bluetooth device's path. |
483 */ | 506 */ |
484 deviceRemovedFromMainAdapter: function(path) { | 507 deviceRemovedFromMainAdapter: function(path) { |
485 if (this.devicePaths[path] == undefined) return; | 508 if (this.devicePaths[path] == undefined) |
| 509 return; |
486 | 510 |
487 var obj = this.devicePaths[path]; | 511 var obj = this.devicePaths[path]; |
488 var devicePath = (obj.predefined ? 'predefinedDevices.' : 'devices.'); | 512 var devicePath = (obj.predefined ? 'predefinedDevices.' : 'devices.'); |
489 devicePath += obj.index.toString(); | 513 devicePath += obj.index.toString(); |
490 this.set(devicePath + '.discoverable', false); | 514 this.set(devicePath + '.discoverable', false); |
491 this.set(devicePath + '.paired', false); | 515 this.set(devicePath + '.paired', false); |
492 }, | 516 }, |
493 | 517 |
494 /** | 518 /** |
495 * Returns the text for the label that corresponds to |classValue|. | 519 * Returns the text for the label that corresponds to |classValue|. |
(...skipping 14 matching lines...) Expand all Loading... |
510 * @return {number} The value which |classText| represents. | 534 * @return {number} The value which |classText| represents. |
511 */ | 535 */ |
512 getValueForDeviceClass: function(classText) { | 536 getValueForDeviceClass: function(classText) { |
513 for (var i = 0; i < this.deviceClassOptions.length; ++i) { | 537 for (var i = 0; i < this.deviceClassOptions.length; ++i) { |
514 if (this.deviceClassOptions[i].text == classText) | 538 if (this.deviceClassOptions[i].text == classText) |
515 return this.deviceClassOptions[i].value; | 539 return this.deviceClassOptions[i].value; |
516 } | 540 } |
517 return 0; | 541 return 0; |
518 }, | 542 }, |
519 }); | 543 }); |
OLD | NEW |