| OLD | NEW |
| 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 * Javascript for bluetooth_internals.html, served from | 6 * Javascript for bluetooth_internals.html, served from |
| 7 * chrome://bluetooth-internals/. | 7 * chrome://bluetooth-internals/. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 // Exposed to get access for testing. |
| 11 var adapterClient = null; |
| 12 var deviceTable = null; |
| 13 |
| 10 cr.define('bluetooth_internals', function() { | 14 cr.define('bluetooth_internals', function() { |
| 11 /** | 15 /** |
| 12 * The implementation of AdapterClient in | 16 * The implementation of AdapterClient in |
| 13 * device/bluetooth/public/interfaces/adapter.mojom. This also manages the | 17 * device/bluetooth/public/interfaces/adapter.mojom. This also manages the |
| 14 * client-side collection of devices. | 18 * client-side collection of devices. |
| 15 * @constructor | 19 * @constructor |
| 16 */ | 20 */ |
| 17 var AdapterClient = function() { | 21 var AdapterClient = function() { |
| 18 this.devices = new device_collection.DeviceCollection([]); | 22 this.devices = new device_collection.DeviceCollection([]); |
| 19 }; | 23 }; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 37 /** | 41 /** |
| 38 * Updates the cached device. | 42 * Updates the cached device. |
| 39 * @param {!interfaces.BluetoothDevice.DeviceInfo} deviceInfo | 43 * @param {!interfaces.BluetoothDevice.DeviceInfo} deviceInfo |
| 40 */ | 44 */ |
| 41 deviceChanged: function(deviceInfo) { | 45 deviceChanged: function(deviceInfo) { |
| 42 console.log(new Date(), deviceInfo); | 46 console.log(new Date(), deviceInfo); |
| 43 this.devices.addOrUpdate(deviceInfo); | 47 this.devices.addOrUpdate(deviceInfo); |
| 44 } | 48 } |
| 45 }; | 49 }; |
| 46 | 50 |
| 47 var adapterClient = null; | |
| 48 | |
| 49 function initialize() { | 51 function initialize() { |
| 50 interfaces.initialize() | 52 interfaces.initialize() |
| 51 .then(function() { | 53 .then(function() { |
| 52 // Hook up the instance properties. | 54 // Hook up the instance properties. |
| 53 AdapterClient.prototype.__proto__ = | 55 AdapterClient.prototype.__proto__ = |
| 54 interfaces.BluetoothAdapter.AdapterClient.stubClass.prototype; | 56 interfaces.BluetoothAdapter.AdapterClient.stubClass.prototype; |
| 55 | 57 |
| 56 adapterClient = new AdapterClient(); | 58 adapterClient = new AdapterClient(); |
| 57 interfaces.DefaultAdapter.setClient( | 59 interfaces.DefaultAdapter.setClient( |
| 58 interfaces.Connection.bindStubDerivedImpl(adapterClient)); | 60 interfaces.Connection.bindStubDerivedImpl(adapterClient)); |
| 59 }) | 61 }) |
| 60 .then(function() { return adapter.getInfo(); }) | 62 .then(function() { return adapter.getInfo(); }) |
| 61 .then(function(response) { console.log('adapter', response.info); }) | 63 .then(function(response) { console.log('adapter', response.info); }) |
| 62 .then(function() { return adapter.getDevices(); }) | 64 .then(function() { return adapter.getDevices(); }) |
| 63 .then(function(response) { | 65 .then(function(response) { |
| 64 response.devices.forEach(adapterClient.deviceAdded, | 66 response.devices.forEach(adapterClient.deviceAdded, |
| 65 adapterClient /** this */); | 67 adapterClient /** this */); |
| 66 | 68 |
| 67 var deviceTable = new device_table.DeviceTable(); | 69 deviceTable = new device_table.DeviceTable(); |
| 68 deviceTable.setDevices(adapterClient.devices); | 70 deviceTable.setDevices(adapterClient.devices); |
| 71 deviceTable.id = 'device-table'; |
| 69 document.body.appendChild(deviceTable); | 72 document.body.appendChild(deviceTable); |
| 70 }) | 73 }) |
| 71 .catch(function(error) { console.error(error); }); | 74 .catch(function(error) { console.error(error); }); |
| 72 } | 75 } |
| 73 | 76 |
| 74 return { | 77 return { |
| 75 initialize: initialize | 78 initialize: initialize |
| 76 }; | 79 }; |
| 77 | 80 |
| 78 }); | 81 }); |
| 79 | 82 |
| 80 document.addEventListener('DOMContentLoaded', bluetooth_internals.initialize); | 83 document.addEventListener('DOMContentLoaded', bluetooth_internals.initialize); |
| OLD | NEW |