| Index: chrome/renderer/resources/extensions/bluetooth_custom_bindings.js
|
| diff --git a/chrome/renderer/resources/extensions/bluetooth_custom_bindings.js b/chrome/renderer/resources/extensions/bluetooth_custom_bindings.js
|
| index e1f75f5d78ac9ff69d574696852ab3b6e6308462..273a094932499f99250e1181d5c58efa775f65d5 100644
|
| --- a/chrome/renderer/resources/extensions/bluetooth_custom_bindings.js
|
| +++ b/chrome/renderer/resources/extensions/bluetooth_custom_bindings.js
|
| @@ -2,24 +2,27 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -// Custom bindings for the Bluetooth API.
|
| +// Custom binding for the Bluetooth API.
|
| +
|
| +var binding = require('binding').Binding.create('bluetooth');
|
|
|
| var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
|
| +var chrome = requireNative('chrome').GetChrome();
|
| var sendRequest = require('sendRequest').sendRequest;
|
| var lastError = require('lastError');
|
|
|
| -// Use custom bindings to create an undocumented event listener that will
|
| +// Use custom binding to create an undocumented event listener that will
|
| // receive events about device discovery and call the event listener that was
|
| // provided with the request to begin discovery.
|
| -chromeHidden.registerCustomHook('bluetooth', function(api) {
|
| +binding.registerCustomHook(function(api) {
|
| var apiFunctions = api.apiFunctions;
|
|
|
| chromeHidden.bluetooth = {};
|
|
|
| - function callCallbackIfPresent(args) {
|
| - if (typeof(args[args.length-1]) == "function") {
|
| - args[args.length-1]();
|
| - }
|
| + function callCallbackIfPresent(args, error) {
|
| + var callback = args[args.length - 1];
|
| + if (typeof(callback) == "function")
|
| + lastError.run(error, callback);
|
| }
|
|
|
| chromeHidden.bluetooth.deviceDiscoveredHandler = null;
|
| @@ -35,8 +38,7 @@ chromeHidden.registerCustomHook('bluetooth', function(api) {
|
| var args = arguments;
|
| if (args.length > 0 && args[0] && args[0].deviceCallback) {
|
| if (chromeHidden.bluetooth.deviceDiscoveredHandler != null) {
|
| - lastError.set("Concurrent discovery is not allowed.");
|
| - callCallbackIfPresent(args);
|
| + callCallbackIfPresent(args, "Concurrent discovery is not allowed.");
|
| return;
|
| }
|
|
|
| @@ -49,8 +51,9 @@ chromeHidden.registerCustomHook('bluetooth', function(api) {
|
| this.definition.parameters,
|
| {customCallback:this.customCallback});
|
| } else {
|
| - lastError.set("deviceCallback is required in the options object");
|
| - callCallbackIfPresent(args);
|
| + callCallbackIfPresent(
|
| + args, "deviceCallback is required in the options object");
|
| + return;
|
| }
|
| });
|
| apiFunctions.setCustomCallback('startDiscovery',
|
| @@ -154,3 +157,5 @@ chromeHidden.registerCustomHook('bluetooth', function(api) {
|
| return args;
|
| });
|
| });
|
| +
|
| +exports.binding = binding.generate();
|
|
|