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

Unified 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, 3 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 side-by-side diff with in-line comments
Download patch
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..95f7dd79df2fb6ffe7a98381d1dfa9c6792a65b9 100644
--- a/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js
+++ b/chrome/browser/resources/bluetooth_internals/bluetooth_internals.js
@@ -6,7 +6,88 @@
* 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.prototype.slice.call(arguments, 0));
+ });
+ });
+ }
+
+ /**
+ * 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((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.
+ let [frameInterfaces, mojom, bluetooth, connection] = modules;
+ 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.
+ frameInterfaces.getInterface(mojom.InternalsPageHandler.name),
+ mojom.InternalsPageHandler);
+
+ 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
+ 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');
ortuno 2016/09/26 01:57:56 Device removed :)
mbrunson 2016/09/28 02:18:22 Yes. That makes much more sense. :)
+ console.log(device);
+ }
+ }
+
+ adapterClient = new AdapterClientImpl();
+
+ return new Promise((resolve) => {
ortuno 2016/09/26 01:57:56 There is no indication that initializeProxies() wi
+
+ // Create adapter service interface request
+ adapterHandle = connection.bindProxy(resolve, bluetooth.Adapter);
+
+ // Create a message pipe and bind one end to client implementation
+ 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
+
+ // Send interface request and other end of client message pipe to
+ // C++
+ pageHandler.getAdapterService(adapterHandle, clientHandle);
+ });
+ });
+ }
+
+ document.addEventListener('DOMContentLoaded', function() {
+ initializeProxies()
+ .then((service) => {
+ adapterService = service;
+ return service.getDevices();
+ })
+ .then((response) => console.log(response.devices));
+ });
+})();

Powered by Google App Engine
This is Rietveld 408576698