Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: chrome/browser/resources/bluetooth_internals/bluetooth_internals.js

Issue 2372433002: POC for adapter service (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | chrome/browser/ui/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 (function() {
10 let adapterService = null;
11 let adapterClient = null;
12 let adapterHandle = null;
13 let clientHandle = null;
9 14
10 document.addEventListener('DOMContentLoaded', function() { 15 /**
11 console.log('Welcome to Bluetooth Internals.'); 16 * Helper to convert callback-based define() API to a promise-based API.
12 }); 17 * @param {!Array<string>} moduleNames
18 * @return {!Promise}
19 */
20 function importModules(moduleNames) {
21 return new Promise(function(resolve, reject) {
22 define(moduleNames, function(var_args) {
23 resolve(Array.from(arguments));
24 });
25 });
26 }
27
28 /**
29 * Initializes Mojo proxies for page and Bluetooth services.
30 * @return {!Promise}
31 */
32 function initializeProxies() {
33 return importModules([
34 'content/public/renderer/frame_interfaces',
35 'chrome/browser/ui/webui/bluetooth_internals/' +
36 'bluetooth_internals.mojom',
37 'device/bluetooth/public/interfaces/bluetooth.mojom',
38 'mojo/public/js/connection',
39 ])
40 .then(([frameInterfaces, mojom, bluetooth, connection]) => {
41
42 class AdapterClientImpl extends bluetooth.AdapterClient.stubClass {
43 constructor() { super(); }
44
45 /**
46 * Prints added device to console
47 * @param {!Object} device the device that was added
48 */
49 deviceAdded(device) {
50 console.log('Device added');
51 console.log(device);
52 }
53
54 /**
55 * Prints removed device to console
56 * @param {!Object} device the device that was removed
57 */
58 deviceRemoved(device) {
59 console.log('Device added');
60 console.log(device);
61 }
62 }
63
64
65 adapterService = connection.bindHandleToProxy(
66 frameInterfaces.getInterface(bluetooth.Adapter.name),
67 bluetooth.Adapter);
68
69 // Create a message pipe and bind one end to client implementation
70 adapterClient = new AdapterClientImpl();
71 clientHandle = connection.bindStubDerivedImpl(adapterClient);
72 adapterService.setClient(clientHandle);
73 });
74 }
75
76 document.addEventListener('DOMContentLoaded', function() {
77 initializeProxies()
78 .then(() => {
79 return adapterService.getDevices();
80 })
81 .then((response) => console.log(response.devices));
82 });
83 })();
OLDNEW
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | chrome/browser/ui/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698