| Index: chrome/renderer/resources/extensions/experimental.bluetooth_custom_bindings.js
|
| ===================================================================
|
| --- chrome/renderer/resources/extensions/experimental.bluetooth_custom_bindings.js (revision 157029)
|
| +++ chrome/renderer/resources/extensions/experimental.bluetooth_custom_bindings.js (working copy)
|
| @@ -6,7 +6,7 @@
|
|
|
| var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
|
| var sendRequest = require('sendRequest').sendRequest;
|
| -var lastError = require('lastError');
|
| +var lastError = require('last_error');
|
|
|
| // Use custom bindings to create an undocumented event listener that will
|
| // receive events about device discovery and call the event listener that was
|
| @@ -15,31 +15,20 @@
|
| 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(
|
| @@ -49,8 +38,12 @@
|
| this.definition.parameters,
|
| {customCallback:this.customCallback});
|
| } else {
|
| - lastError.set("deviceCallback is required in the options object");
|
| - callCallbackIfPresent(args);
|
| + if (typeof(args[args.length-1]) == "function") {
|
| + var callback = args[args.length-1];
|
| + lastError.set("deviceCallback is required in the options object");
|
| + callback();
|
| + return;
|
| + }
|
| }
|
| });
|
| apiFunctions.setCustomCallback('startDiscovery',
|
| @@ -65,37 +58,4 @@
|
| 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;
|
| - });
|
| });
|
|
|