| OLD | NEW |
| 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 Mojo interface helpers and global variables, served from | 6 * Javascript for Mojo interface helpers and global variables, served from |
| 7 * chrome://bluetooth-internals/. | 7 * chrome://bluetooth-internals/. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 cr.define('interfaces', function() { | 10 cr.define('interfaces', function() { |
| 11 | |
| 12 /** | |
| 13 * TODO(crbug.com/652361): Move to shared location. | |
| 14 * Helper to convert callback-based define() API to a promise-based API. | |
| 15 * @param {!Array<string>} moduleNames | |
| 16 * @return {!Promise} | |
| 17 */ | |
| 18 function importModules(moduleNames) { | |
| 19 return new Promise(function(resolve, reject) { | |
| 20 define(moduleNames, function(var_args) { | |
| 21 resolve(Array.prototype.slice.call(arguments, 0)); | |
| 22 }); | |
| 23 }); | |
| 24 } | |
| 25 | |
| 26 /** | 11 /** |
| 27 * Initializes Mojo proxies for page and Bluetooth services. | 12 * Initializes Mojo proxies for page and Bluetooth services. |
| 28 * @return {!Promise} resolves if adapter is acquired, rejects if Bluetooth | 13 * @return {!Promise} resolves if adapter is acquired, rejects if Bluetooth |
| 29 * is not supported. | 14 * is not supported. |
| 30 */ | 15 */ |
| 31 function initializeProxies() { | 16 function initializeProxies() { |
| 32 return importModules([ | 17 return importModules([ |
| 33 'content/public/renderer/frame_interfaces', | 18 'content/public/renderer/frame_interfaces', |
| 34 'device/bluetooth/public/interfaces/adapter.mojom', | 19 'device/bluetooth/public/interfaces/adapter.mojom', |
| 35 'device/bluetooth/public/interfaces/device.mojom', | 20 'device/bluetooth/public/interfaces/device.mojom', |
| (...skipping 20 matching lines...) Expand all Loading... |
| 56 adapter = interfaces.Connection.bindHandleToProxy( | 41 adapter = interfaces.Connection.bindHandleToProxy( |
| 57 response.adapter, | 42 response.adapter, |
| 58 interfaces.BluetoothAdapter.Adapter); | 43 interfaces.BluetoothAdapter.Adapter); |
| 59 | 44 |
| 60 Object.assign(interfaces, { | 45 Object.assign(interfaces, { |
| 61 DefaultAdapter: adapter, | 46 DefaultAdapter: adapter, |
| 62 }); | 47 }); |
| 63 }); | 48 }); |
| 64 } | 49 } |
| 65 | 50 |
| 51 /** |
| 52 * Overriden by tests to give them a chance to setup a fake Mojo browser proxy |
| 53 * before any other code executes. |
| 54 * @return {!Promise} A promise firing once necessary setup has been completed. |
| 55 */ |
| 56 var setupFn = window.setupFn || function() { return Promise.resolve(); }; |
| 57 |
| 58 function initialize() { |
| 59 return setupFn().then(initializeProxies); |
| 60 } |
| 61 |
| 66 return { | 62 return { |
| 67 initialize: initializeProxies, | 63 initialize: initialize, |
| 68 }; | 64 }; |
| 69 }); | 65 }); |
| OLD | NEW |