| 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..23f02c3329b4a650c37ba5233bcaae368860b965 100644
|
| --- a/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js
|
| +++ b/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js
|
| @@ -7,6 +7,82 @@
|
| * chrome://bluetooth-internals/.
|
| */
|
|
|
| -document.addEventListener('DOMContentLoaded', function() {
|
| - console.log('Welcome to Bluetooth Internals.');
|
| -});
|
| +/**
|
| + * The implementation of AdapterClient in
|
| + * device/bluetooth/public/interfaces/adapter.mojom.
|
| + */
|
| +var AdapterClient = function() {};
|
| +AdapterClient.prototype = {
|
| + /**
|
| + * Prints added device to console.
|
| + * @param {!Object} device the device that was added
|
| + */
|
| + deviceAdded: function(device) {
|
| + console.log('Device added');
|
| + console.log(device);
|
| + },
|
| +
|
| + /**
|
| + * Prints removed device to console.
|
| + * @param {!Object} device the device that was removed
|
| + */
|
| + deviceRemoved: function(device) {
|
| + console.log('Device removed');
|
| + console.log(device);
|
| + }
|
| +};
|
| +
|
| +(function() {
|
| + var adapter = null;
|
| + var adapterClient = null;
|
| + var adapterClientHandle = null;
|
| +
|
| + /**
|
| + * TODO: Move to shared location. See crbug.com/652361.
|
| + * 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.prototype.slice.call(arguments, 0));
|
| + });
|
| + });
|
| + }
|
| +
|
| + /**
|
| + * Initializes Mojo proxies for page and Bluetooth services.
|
| + * @return {!Promise}
|
| + */
|
| + function initializeProxies() {
|
| + return importModules([
|
| + 'content/public/renderer/frame_interfaces',
|
| + 'device/bluetooth/public/interfaces/adapter.mojom',
|
| + 'mojo/public/js/connection',
|
| + ]).then(function([frameInterfaces, bluetoothAdapter, connection]) {
|
| + console.log('Loaded modules');
|
| +
|
| + // Hook up the instance properties.
|
| + AdapterClient.prototype.__proto__ =
|
| + bluetoothAdapter.AdapterClient.stubClass.prototype;
|
| +
|
| + // Create a message pipe and bind one end to client
|
| + // implementation.
|
| + adapterClient = new AdapterClient();
|
| + adapterClientHandle = connection.bindStubDerivedImpl(adapterClient);
|
| +
|
| + adapter = connection.bindHandleToProxy(
|
| + frameInterfaces.getInterface(bluetoothAdapter.Adapter.name),
|
| + bluetoothAdapter.Adapter);
|
| +
|
| + adapter.setClient(adapterClientHandle);
|
| + });
|
| + }
|
| +
|
| + document.addEventListener('DOMContentLoaded', function() {
|
| + initializeProxies()
|
| + .then(function() { return adapter.getDevices(); })
|
| + .then(function(response) { console.log(response.devices); });
|
| + });
|
| +})();
|
|
|