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

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

Issue 2357383002: bluetooth: Add device list retrieval for chrome://bluetooth-internals (Closed)
Patch Set: Mojo interface and implementation fixes 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
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.prototype.slice.call(arguments, 0));
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((modules) => {
ortuno 2016/09/26 01:57:56 Unless I'm missing something you should be able to
mbrunson 2016/09/28 02:18:22 Done.
41 let [frameInterfaces, mojom, bluetooth, connection] = modules;
42 let pageHandler = connection.bindHandleToProxy(
ortuno 2016/09/26 01:57:56 Consider moving this further down to where it is u
mbrunson 2016/09/28 02:18:22 Done.
43 frameInterfaces.getInterface(mojom.InternalsPageHandler.name),
44 mojom.InternalsPageHandler);
45
46 class AdapterClientImpl extends bluetooth.AdapterClient.stubClass {
scheib 2016/09/26 19:37:26 Move the AdapterClientImpl class definition to the
mbrunson 2016/09/28 02:18:22 I've moved the declaration up and put the subclass
47 constructor() { super(); }
48
49 /**
50 * Prints added device to console
51 * @param {!Object} device the device that was added
52 */
53 deviceAdded(device) {
54 console.log('Device added');
55 console.log(device);
56 }
57
58 /**
59 * Prints removed device to console
60 * @param {!Object} device the device that was removed
61 */
62 deviceRemoved(device) {
63 console.log('Device added');
ortuno 2016/09/26 01:57:56 Device removed :)
mbrunson 2016/09/28 02:18:22 Yes. That makes much more sense. :)
64 console.log(device);
65 }
66 }
67
68 adapterClient = new AdapterClientImpl();
69
70 return new Promise((resolve) => {
ortuno 2016/09/26 01:57:56 There is no indication that initializeProxies() wi
71
72 // Create adapter service interface request
73 adapterHandle = connection.bindProxy(resolve, bluetooth.Adapter);
74
75 // Create a message pipe and bind one end to client implementation
76 clientHandle = connection.bindStubDerivedImpl(adapterClient);
ortuno 2016/09/26 07:45:17 You are creating a different pipe for the client.
scheib 2016/09/26 18:00:37 https://www.chromium.org/developers/design-documen
mbrunson 2016/09/28 02:18:22 Ok. When I was writing the adapter service, I spec
77
78 // Send interface request and other end of client message pipe to
79 // C++
80 pageHandler.getAdapterService(adapterHandle, clientHandle);
81 });
82 });
83 }
84
85 document.addEventListener('DOMContentLoaded', function() {
86 initializeProxies()
87 .then((service) => {
88 adapterService = service;
89 return service.getDevices();
90 })
91 .then((response) => console.log(response.devices));
92 });
93 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698