| Index: chrome/renderer/resources/extensions/experimental.bluetooth_custom_bindings.js
|
| diff --git a/chrome/renderer/resources/extensions/experimental.bluetooth_custom_bindings.js b/chrome/renderer/resources/extensions/experimental.bluetooth_custom_bindings.js
|
| index 76f525b84bcfd31173dbe67144098689e0f7b685..1a32767f6ef8d79d008d67f5ef4478b58cfe1562 100644
|
| --- a/chrome/renderer/resources/extensions/experimental.bluetooth_custom_bindings.js
|
| +++ b/chrome/renderer/resources/extensions/experimental.bluetooth_custom_bindings.js
|
| @@ -6,7 +6,7 @@
|
|
|
| var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
|
| var sendRequest = require('sendRequest').sendRequest;
|
| -var lastError = require('last_error');
|
| +var lastError = require('lastError');
|
|
|
| // Use custom bindings to create an undocumented event listener that will
|
| // receive events about device discovery and call the event listener that was
|
| @@ -15,20 +15,31 @@ chromeHidden.registerCustomHook('experimental.bluetooth', function(api) {
|
| var apiFunctions = api.apiFunctions;
|
|
|
| chromeHidden.bluetooth = {};
|
| +
|
| + function callCallbackIfPresent(args) {
|
| + if (typeof(args[args.length-1]) == "function") {
|
| + args[args.length-1]();
|
| + }
|
| + }
|
| +
|
| chromeHidden.bluetooth.deviceDiscoveredHandler = null;
|
| chromeHidden.bluetooth.onDeviceDiscovered =
|
| new chrome.Event("experimental.bluetooth.onDeviceDiscovered");
|
| -
|
| function clearDeviceDiscoveredHandler() {
|
| chromeHidden.bluetooth.onDeviceDiscovered.removeListener(
|
| chromeHidden.bluetooth.deviceDiscoveredHandler);
|
| chromeHidden.bluetooth.deviceDiscoveredHandler = null;
|
| }
|
| -
|
| apiFunctions.setHandleRequest('startDiscovery',
|
| function() {
|
| 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);
|
| + return;
|
| + }
|
| +
|
| chromeHidden.bluetooth.deviceDiscoveredHandler =
|
| args[0].deviceCallback;
|
| chromeHidden.bluetooth.onDeviceDiscovered.addListener(
|
| @@ -38,12 +49,8 @@ chromeHidden.registerCustomHook('experimental.bluetooth', function(api) {
|
| this.definition.parameters,
|
| {customCallback:this.customCallback});
|
| } else {
|
| - if (typeof(args[args.length-1]) == "function") {
|
| - var callback = args[args.length-1];
|
| - lastError.set("deviceCallback is required in the options object");
|
| - callback();
|
| - return;
|
| - }
|
| + lastError.set("deviceCallback is required in the options object");
|
| + callCallbackIfPresent(args);
|
| }
|
| });
|
| apiFunctions.setCustomCallback('startDiscovery',
|
| @@ -58,4 +65,37 @@ chromeHidden.registerCustomHook('experimental.bluetooth', function(api) {
|
| clearDeviceDiscoveredHandler();
|
| sendRequest(this.name, arguments, this.definition.parameters);
|
| });
|
| +
|
| + chromeHidden.bluetooth.deviceSearchResultHandler = null;
|
| + chromeHidden.bluetooth.onDeviceSearchResult =
|
| + new chrome.Event("experimental.bluetooth.onDeviceSearchResult");
|
| + apiFunctions.setHandleRequest('getDevices',
|
| + function() {
|
| + var args = arguments;
|
| + if (args.length > 0 && args[0] && args[0].deviceCallback) {
|
| + if (chromeHidden.bluetooth.deviceSearchResultHandler != null) {
|
| + lastError.set("Concurrent calls to getDevices are not allowed.");
|
| + callCallbackIfPresent(args);
|
| + return;
|
| + }
|
| +
|
| + chromeHidden.bluetooth.deviceSearchResultHandler =
|
| + args[0].deviceCallback;
|
| + chromeHidden.bluetooth.onDeviceSearchResult.addListener(
|
| + chromeHidden.bluetooth.deviceSearchResultHandler);
|
| + sendRequest(this.name,
|
| + args,
|
| + this.definition.parameters,
|
| + {customCallback:this.customCallback});
|
| + } else {
|
| + lastError.set("deviceCallback is required in the options object");
|
| + callCallbackIfPresent(args);
|
| + }
|
| + });
|
| + apiFunctions.setCustomCallback('getDevices',
|
| + function(name, request, response) {
|
| + chromeHidden.bluetooth.onDeviceSearchResult.removeListener(
|
| + chromeHidden.bluetooth.deviceSearchResultHandler);
|
| + chromeHidden.bluetooth.deviceSearchResultHandler = null;
|
| + });
|
| });
|
|
|