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

Unified Diff: chrome/renderer/resources/extensions/experimental.bluetooth_custom_bindings.js

Issue 10916331: Revert 156348 (caused http://crbug.com/149828) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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/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;
- });
});

Powered by Google App Engine
This is Rietveld 408576698