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

Side by Side Diff: chrome/renderer/resources/extensions/experimental.bluetooth_custom_bindings.js

Issue 10915148: Change getDevices to use a DeviceCallback. (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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Custom bindings for the Bluetooth API. 5 // Custom bindings for the Bluetooth API.
6 6
7 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); 7 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
8 var sendRequest = require('sendRequest').sendRequest; 8 var sendRequest = require('sendRequest').sendRequest;
9 var lastError = require('last_error'); 9 var lastError = require('last_error');
10 10
11 // Use custom bindings to create an undocumented event listener that will 11 // Use custom bindings to create an undocumented event listener that will
12 // receive events about device discovery and call the event listener that was 12 // receive events about device discovery and call the event listener that was
13 // provided with the request to begin discovery. 13 // provided with the request to begin discovery.
14 chromeHidden.registerCustomHook('experimental.bluetooth', function(api) { 14 chromeHidden.registerCustomHook('experimental.bluetooth', function(api) {
15 var apiFunctions = api.apiFunctions; 15 var apiFunctions = api.apiFunctions;
16 16
17 chromeHidden.bluetooth = {}; 17 chromeHidden.bluetooth = {};
18
18 chromeHidden.bluetooth.deviceDiscoveredHandler = null; 19 chromeHidden.bluetooth.deviceDiscoveredHandler = null;
19 chromeHidden.bluetooth.onDeviceDiscovered = 20 chromeHidden.bluetooth.onDeviceDiscovered =
20 new chrome.Event("experimental.bluetooth.onDeviceDiscovered"); 21 new chrome.Event("experimental.bluetooth.onDeviceDiscovered");
21
22 function clearDeviceDiscoveredHandler() { 22 function clearDeviceDiscoveredHandler() {
23 chromeHidden.bluetooth.onDeviceDiscovered.removeListener( 23 chromeHidden.bluetooth.onDeviceDiscovered.removeListener(
24 chromeHidden.bluetooth.deviceDiscoveredHandler); 24 chromeHidden.bluetooth.deviceDiscoveredHandler);
25 chromeHidden.bluetooth.deviceDiscoveredHandler = null; 25 chromeHidden.bluetooth.deviceDiscoveredHandler = null;
26 } 26 }
27
28 apiFunctions.setHandleRequest('startDiscovery', 27 apiFunctions.setHandleRequest('startDiscovery',
29 function() { 28 function() {
30 var args = arguments; 29 var args = arguments;
31 if (args.length > 0 && args[0] && args[0].deviceCallback) { 30 if (args.length > 0 && args[0] && args[0].deviceCallback) {
32 chromeHidden.bluetooth.deviceDiscoveredHandler = 31 chromeHidden.bluetooth.deviceDiscoveredHandler =
33 args[0].deviceCallback; 32 args[0].deviceCallback;
34 chromeHidden.bluetooth.onDeviceDiscovered.addListener( 33 chromeHidden.bluetooth.onDeviceDiscovered.addListener(
35 chromeHidden.bluetooth.deviceDiscoveredHandler); 34 chromeHidden.bluetooth.deviceDiscoveredHandler);
36 sendRequest(this.name, 35 sendRequest(this.name,
37 args, 36 args,
(...skipping 13 matching lines...) Expand all
51 if (chrome.runtime.lastError) { 50 if (chrome.runtime.lastError) {
52 clearDeviceDiscoveredHandler(); 51 clearDeviceDiscoveredHandler();
53 return; 52 return;
54 } 53 }
55 }); 54 });
56 apiFunctions.setHandleRequest('stopDiscovery', 55 apiFunctions.setHandleRequest('stopDiscovery',
57 function() { 56 function() {
58 clearDeviceDiscoveredHandler(); 57 clearDeviceDiscoveredHandler();
59 sendRequest(this.name, arguments, this.definition.parameters); 58 sendRequest(this.name, arguments, this.definition.parameters);
60 }); 59 });
60
61 chromeHidden.bluetooth.deviceSearchResultHandler = null;
62 chromeHidden.bluetooth.onDeviceSearchResult =
63 new chrome.Event("experimental.bluetooth.onDeviceSearchResult");
64 apiFunctions.setHandleRequest('getDevices',
65 function() {
66 var args = arguments;
67 if (args.length > 0 && args[0] && args[0].deviceCallback) {
68 chromeHidden.bluetooth.deviceSearchResultHandler =
69 args[0].deviceCallback;
70 chromeHidden.bluetooth.onDeviceSearchResult.addListener(
71 chromeHidden.bluetooth.deviceSearchResultHandler);
asargent_no_longer_on_chrome 2012/09/11 17:42:56 It looks like your intention is to only handle a s
bryeung 2012/09/11 18:37:30 Great catch. I'm fine with disallowing concurrent
72 sendRequest(this.name,
73 args,
74 this.definition.parameters,
75 {customCallback:this.customCallback});
76 } else {
77 if (typeof(args[args.length-1]) == "function") {
78 var callback = args[args.length-1];
79 lastError.set("deviceCallback is required in the options object");
80 callback();
81 return;
82 }
83 }
84 });
85 apiFunctions.setCustomCallback('getDevices',
86 function(name, request, response) {
87 chromeHidden.bluetooth.onDeviceSearchResult.removeListener(
88 chromeHidden.bluetooth.deviceSearchResultHandler);
89 chromeHidden.bluetooth.deviceSearchResultHandler = null;
90 });
61 }); 91 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698