| Index: chrome/browser/resources/bluetooth_internals/bluetooth_internals.js
|
| diff --git a/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js b/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js
|
| index 308779cb50e4ed62fb1168bf63515bbd91d2ec74..98126d73d0978adf51269dc39a7225dd461fddc1 100644
|
| --- a/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js
|
| +++ b/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js
|
| @@ -6,7 +6,78 @@
|
| * Javascript for bluetooth_internals.html, served from
|
| * chrome://bluetooth-internals/.
|
| */
|
| +(function() {
|
| + let adapterService = null;
|
| + let adapterClient = null;
|
| + let adapterHandle = null;
|
| + let clientHandle = null;
|
|
|
| -document.addEventListener('DOMContentLoaded', function() {
|
| - console.log('Welcome to Bluetooth Internals.');
|
| -});
|
| + /**
|
| + * Helper to convert callback-based define() API to a promise-based API.
|
| + * @param {!Array<string>} moduleNames
|
| + * @return {!Promise}
|
| + */
|
| + function importModules(moduleNames) {
|
| + return new Promise(function(resolve, reject) {
|
| + define(moduleNames, function(var_args) {
|
| + resolve(Array.from(arguments));
|
| + });
|
| + });
|
| + }
|
| +
|
| + /**
|
| + * Initializes Mojo proxies for page and Bluetooth services.
|
| + * @return {!Promise}
|
| + */
|
| + function initializeProxies() {
|
| + return importModules([
|
| + 'content/public/renderer/frame_interfaces',
|
| + 'chrome/browser/ui/webui/bluetooth_internals/' +
|
| + 'bluetooth_internals.mojom',
|
| + 'device/bluetooth/public/interfaces/bluetooth.mojom',
|
| + 'mojo/public/js/connection',
|
| + ])
|
| + .then(([frameInterfaces, mojom, bluetooth, connection]) => {
|
| +
|
| + class AdapterClientImpl extends bluetooth.AdapterClient.stubClass {
|
| + constructor() { super(); }
|
| +
|
| + /**
|
| + * Prints added device to console
|
| + * @param {!Object} device the device that was added
|
| + */
|
| + deviceAdded(device) {
|
| + console.log('Device added');
|
| + console.log(device);
|
| + }
|
| +
|
| + /**
|
| + * Prints removed device to console
|
| + * @param {!Object} device the device that was removed
|
| + */
|
| + deviceRemoved(device) {
|
| + console.log('Device added');
|
| + console.log(device);
|
| + }
|
| + }
|
| +
|
| +
|
| + adapterService = connection.bindHandleToProxy(
|
| + frameInterfaces.getInterface(bluetooth.Adapter.name),
|
| + bluetooth.Adapter);
|
| +
|
| + // Create a message pipe and bind one end to client implementation
|
| + adapterClient = new AdapterClientImpl();
|
| + clientHandle = connection.bindStubDerivedImpl(adapterClient);
|
| + adapterService.setClient(clientHandle);
|
| + });
|
| + }
|
| +
|
| + document.addEventListener('DOMContentLoaded', function() {
|
| + initializeProxies()
|
| + .then(() => {
|
| + return adapterService.getDevices();
|
| + })
|
| + .then((response) => console.log(response.devices));
|
| + });
|
| +})();
|
|
|