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

Side by Side Diff: chrome/common/extensions/api/usb.idl

Issue 22914023: Introducing chrome.usb.getDevices/openDevice API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@usb-interface
Patch Set: Rebase to origin/master Created 7 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
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 // Use the <code>chrome.usb</code> API to interact with connected USB 5 // Use the <code>chrome.usb</code> API to interact with connected USB
6 // devices. This API provides access to USB operations from within the context 6 // devices. This API provides access to USB operations from within the context
7 // of an app. Using this API, apps can function as drivers for hardware devices. 7 // of an app. Using this API, apps can function as drivers for hardware devices.
8 namespace usb { 8 namespace usb {
9 9
10 // Direction, Recipient, RequestType, and TransferType all map to their 10 // Direction, Recipient, RequestType, and TransferType all map to their
11 // namesakes within the USB specification. 11 // namesakes within the USB specification.
12 enum Direction {in, out}; 12 enum Direction {in, out};
13 enum Recipient {device, _interface, endpoint, other}; 13 enum Recipient {device, _interface, endpoint, other};
14 enum RequestType {standard, class, vendor, reserved}; 14 enum RequestType {standard, class, vendor, reserved};
15 enum TransferType {control, interrupt, isochronous, bulk}; 15 enum TransferType {control, interrupt, isochronous, bulk};
16 16
17 // For isochronous mode, SynchronizationType and UsageType map to their 17 // For isochronous mode, SynchronizationType and UsageType map to their
18 // namesakes within the USB specification. 18 // namesakes within the USB specification.
19 enum SynchronizationType {asynchronous, adaptive, synchronous}; 19 enum SynchronizationType {asynchronous, adaptive, synchronous};
20 enum UsageType {data, feedback, explicitFeedback}; 20 enum UsageType {data, feedback, explicitFeedback};
21 21
22 // A Device encapsulates everything that is needed to communicate with a USB 22 // Returned by |getDevices| to identify a connected USB device.
23 // device. They are returned by findDevice calls and have all of their
24 // fields populated before being returned.
25 dictionary Device { 23 dictionary Device {
24 // The id of the USB device. It remains unchanged until the device is
25 // unplugged.
26 long device;
27 long vendorId;
28 long productId;
29 };
30
31 // Returned by |openDevice| to be used for USB communication.
32 // Every time a device is opened, a new connection handle is created.
33 //
34 // A connection handle represents the underlying data structure that contains
35 // all the data we need to communicate with a USB device, including the status
36 // of interfaces, the pending transfers, the descriptors, and etc. A connectin
37 // handle id is different from a USB device id.
38 //
39 // All connection handles can work together if the device allows it.
40 // The connection handle will be automatically closed when the app is reloaded
41 // or suspended.
42 //
43 // When a connection handle is closed, all the interfaces it claimed will be
44 // released and all the transfers in progress will be canceled immediately.
45 dictionary ConnectionHandle {
46 // The id of the USB connection handle.
26 long handle; 47 long handle;
27 long vendorId; 48 long vendorId;
28 long productId; 49 long productId;
29 }; 50 };
30 51
31 dictionary EndpointDescriptor { 52 dictionary EndpointDescriptor {
32 long address; 53 long address;
33 TransferType type; 54 TransferType type;
34 Direction direction; 55 Direction direction;
35 long maximumPacketSize; 56 long maximumPacketSize;
36 57
37 // Used for isochronous mode. 58 // Used for isochronous mode.
38 SynchronizationType? synchronization; 59 SynchronizationType? synchronization;
39 UsageType? usage; 60 UsageType? usage;
40 61
41 // If this is an interrupt endpoint, this will be 1-255 62 // If this is an interrupt endpoint, this will be 1-255.
42 long? pollingInterval; 63 long? pollingInterval;
43 }; 64 };
44 65
45 dictionary InterfaceDescriptor { 66 dictionary InterfaceDescriptor {
46 long interfaceNumber; 67 long interfaceNumber;
47 long alternateSetting; 68 long alternateSetting;
48 long interfaceClass; 69 long interfaceClass;
49 long interfaceSubclass; 70 long interfaceSubclass;
50 long interfaceProtocol; 71 long interfaceProtocol;
51 DOMString? description; 72 DOMString? description;
(...skipping 14 matching lines...) Expand all
66 87
67 long request; 88 long request;
68 long value; 89 long value;
69 long index; 90 long index;
70 91
71 // If this transfer is an input transfer, then this field must be set to 92 // If this transfer is an input transfer, then this field must be set to
72 // indicate the expected data length. If this is an output transfer, then 93 // indicate the expected data length. If this is an output transfer, then
73 // this field is ignored. 94 // this field is ignored.
74 long? length; 95 long? length;
75 96
76 // The data payload carried by this transfer. If this is an output tranfer 97 // The data payload carried by this transfer. If this is an output transfer
77 // then this field must be set. 98 // then this field must be set.
78 ArrayBuffer? data; 99 ArrayBuffer? data;
79 }; 100 };
80 101
81 // GenericTransferInfo is used by both bulk and interrupt transfers to 102 // GenericTransferInfo is used by both bulk and interrupt transfers to
82 // specify the parameters of the transfer. 103 // specify the parameters of the transfer.
83 dictionary GenericTransferInfo { 104 dictionary GenericTransferInfo {
84 // The direction of this transfer. 105 // The direction of this transfer.
85 Direction direction; 106 Direction direction;
86 107
(...skipping 27 matching lines...) Expand all
114 dictionary TransferResultInfo { 135 dictionary TransferResultInfo {
115 // A value of 0 indicates that the transfer was a success. Other values 136 // A value of 0 indicates that the transfer was a success. Other values
116 // indicate failure. 137 // indicate failure.
117 long? resultCode; 138 long? resultCode;
118 139
119 // If the transfer was an input transfer then this field will contain all 140 // If the transfer was an input transfer then this field will contain all
120 // of the input data requested. 141 // of the input data requested.
121 ArrayBuffer? data; 142 ArrayBuffer? data;
122 }; 143 };
123 144
124 // FindDevicesOptions describes the properties of devices which are found and 145 // Describes the properties of devices which are found via |getDevices|.
125 // opened via findDevices. 146 dictionary EnumerateDevicesOptions {
126 dictionary FindDevicesOptions {
127 long vendorId; 147 long vendorId;
128 long productId; 148 long productId;
149 };
150
151 // Describes the properties of devices which are found via |findDevices|.
152 dictionary EnumerateDevicesAndRequestAccessOptions {
153 long vendorId;
154 long productId;
155 // The interface id to request access against.
156 // Only available on ChromeOS. It has no effect on other platforms.
129 long? interfaceId; 157 long? interfaceId;
130 }; 158 };
131 159
132 callback VoidCallback = void (); 160 callback VoidCallback = void ();
133 callback FindDevicesCallback = void (Device[] device); 161 callback GetDevicesCallback = void (Device[] devices);
162 callback RequestAccessCallback = void (boolean sucess);
163 callback OpenDeviceCallback = void (ConnectionHandle handle);
164 callback FindDevicesCallback = void (ConnectionHandle[] handles);
134 callback ListInterfacesCallback = void (InterfaceDescriptor[] descriptors); 165 callback ListInterfacesCallback = void (InterfaceDescriptor[] descriptors);
135 callback CloseDeviceCallback = void (); 166 callback CloseDeviceCallback = void ();
136 callback TransferCallback = void (TransferResultInfo info); 167 callback TransferCallback = void (TransferResultInfo info);
137 callback ResetDeviceCallback = void(boolean result); 168 callback ResetDeviceCallback = void(boolean result);
138 169
139 interface Functions { 170 interface Functions {
140 // Finds the first instance of the USB device specified by the vendorId/ 171 // Lists USB devices specified by vendorId/productId/interfaceId tuple.
141 // productId pair and, if permissions allow, opens it for use.
142 // Upon successfully opening a device the callback is invoked with a
143 // populated Device object. On failure, the callback is invoked with null.
144 // |options|: The properties to search for on target devices. 172 // |options|: The properties to search for on target devices.
145 // |callback|: Invoked with the opened Device on success. 173 // |callback|: Invoked with a list of |Device|s on complete.
146 static void findDevices(FindDevicesOptions options, 174 static void getDevices(EnumerateDevicesOptions options,
147 FindDevicesCallback callback); 175 GetDevicesCallback callback);
148 176
149 // Closes an open device instance. Invoking operations on a device after it 177 // This method is ChromeOS specific. Calling this method on other platforms
178 // will fail.
179 // Requests access from the permission broker to an OS claimed device if the
180 // given interface on the device is not claimed.
181 //
182 // |device|: The device to request access to.
183 // |interfaceId|:
184 static void requestAccess(Device device,
185 long interfaceId,
186 RequestAccessCallback callback);
187
188 // Opens a USB device returned by |getDevices|.
189 // |device|: The device to open.
190 // |callback|: Invoked with the created ConnectionHandle on complete.
191 static void openDevice(Device device, OpenDeviceCallback callback);
192
193 // Finds USB devices specified by the vendorId/productId/interfaceId tuple
194 // and, if permissions allow, opens them for use.
195 //
196 // On Chrome OS, you can specify the interfaceId. In that case the method
197 // will request access from permission broker in the same way as in
198 // |requestUsbAcess|.
199 //
200 // If the access request is rejected, or the device is failed to be opened,
201 // its connection handle will not be created or returned.
202 //
203 // Calling this method is equivalent to calling |getDevices| followed by
204 // a series of |requestAccess| (if it is on ChromeOs) and |openDevice|
205 // calls, and returning all the successfully opened connection handles.
206 //
207 // |options|: The properties to search for on target devices.
208 // |callback|: Invoked with the opened ConnectionHandle on complete.
209 static void findDevices(EnumerateDevicesAndRequestAccessOptions options,
210 FindDevicesCallback callback);
211
212 // Closes a connection handle. Invoking operations on a device after it
150 // has been closed is a safe operation, but causes no action to be taken. 213 // has been closed is a safe operation, but causes no action to be taken.
151 // |device|: The device to close. 214 // |handle|: The connection handle to close.
152 // |callback|: The callback to invoke once the device is closed. 215 // |callback|: The callback to invoke once the device is closed.
153 static void closeDevice(Device device, 216 static void closeDevice(ConnectionHandle handle,
154 optional CloseDeviceCallback callback); 217 optional CloseDeviceCallback callback);
155 218
156 // Lists all the interfaces on the USB device. 219 // Lists all the interfaces on the USB device.
157 // |device|: The device from which the interfaces should be listed. 220 // |handle|: The device from which the interfaces should be listed.
158 // |callback|: The callback to invoke when the interfaces are enumerated. 221 // |callback|: The callback to invoke when the interfaces are enumerated.
159 static void listInterfaces(Device device, 222 static void listInterfaces(ConnectionHandle handle,
160 ListInterfacesCallback callback); 223 ListInterfacesCallback callback);
161 224
162 // Claims an interface on the specified USB device. 225 // Claims an interface on the specified USB device.
163 // |device|: The device on which the interface is to be claimed. 226 // Before you can transfer data with endpoints, you must claim their parent
227 // interfaces. Only one connection handle on the same host can claim each
228 // interface. If the interface is already claimed, this call will fail.
229 //
230 // You shall call releaseInterface when the interface is not needed anymore.
231 //
232 // |handle|: The device on which the interface is to be claimed.
164 // |interface|: The interface number to be claimed. 233 // |interface|: The interface number to be claimed.
165 // |callback|: The callback to invoke once the interface is claimed. 234 // |callback|: The callback to invoke once the interface is claimed.
166 static void claimInterface(Device device, long interfaceNumber, 235 static void claimInterface(ConnectionHandle handle, long interfaceNumber,
167 VoidCallback callback); 236 VoidCallback callback);
168 237
169 // Releases a claim to an interface on the provided device. 238 // Releases a claim to an interface on the provided device.
170 // |device|: The device on which the interface is to be released. 239 // |handle|: The device on which the interface is to be released.
171 // |interface|: The interface number to be released. 240 // |interface|: The interface number to be released.
172 // |callback|: The callback to invoke once the interface is released. 241 // |callback|: The callback to invoke once the interface is released.
173 static void releaseInterface(Device device, long interfaceNumber, 242 static void releaseInterface(ConnectionHandle handle, long interfaceNumber,
174 VoidCallback callback); 243 VoidCallback callback);
175 244
176 // Selects an alternate setting on a previously claimed interface on a 245 // Selects an alternate setting on a previously claimed interface on a
177 // device. 246 // device.
178 // |device|: The device on which the interface settings are to be set. 247 // |handle|: The device on which the interface settings are to be set.
179 // |interface|: The interface number to be set. 248 // |interface|: The interface number to be set.
180 // |alternateSetting|: The alternate setting to set. 249 // |alternateSetting|: The alternate setting to set.
181 // |callback|: The callback to invoke once the interface setting is set. 250 // |callback|: The callback to invoke once the interface setting is set.
182 static void setInterfaceAlternateSetting(Device device, 251 static void setInterfaceAlternateSetting(ConnectionHandle handle,
183 long interfaceNumber, long alternateSetting, VoidCallback callback); 252 long interfaceNumber,
253 long alternateSetting,
254 VoidCallback callback);
184 255
185 // Performs a control transfer on the specified device. See the 256 // Performs a control transfer on the specified device. See the
186 // ControlTransferInfo structure for the parameters required to make a 257 // ControlTransferInfo structure for the parameters required to make a
187 // transfer. 258 // transfer.
188 // |device|: An open device to make the transfer on. 259 //
260 // Conceptually control transfer talks to the device itself. You do not need
261 // to claim interface 0 to perform a control transfer.
262 //
263 // |handle|: A connection handle to make the transfer on.
189 // |transferInfo|: The parameters to the transfer. See ControlTransferInfo. 264 // |transferInfo|: The parameters to the transfer. See ControlTransferInfo.
190 // |callback|: Invoked once the transfer has completed. 265 // |callback|: Invoked once the transfer has completed.
191 static void controlTransfer(Device device, 266 static void controlTransfer(ConnectionHandle handle,
192 ControlTransferInfo transferInfo, TransferCallback callback); 267 ControlTransferInfo transferInfo,
268 TransferCallback callback);
193 269
194 // Performs a bulk transfer on the specified device. 270 // Performs a bulk transfer on the specified device.
195 // |device|: An open device to make the transfer on. 271 // |handle|: A connection handle to make the transfer on.
196 // |transferInfo|: The paramters to the transfer. See GenericTransferInfo. 272 // |transferInfo|: The parameters to the transfer. See GenericTransferInfo.
197 // |callback|: Invoked once the transfer has completed. 273 // |callback|: Invoked once the transfer has completed.
198 static void bulkTransfer(Device device, GenericTransferInfo transferInfo, 274 static void bulkTransfer(ConnectionHandle handle,
199 TransferCallback callback); 275 GenericTransferInfo transferInfo,
276 TransferCallback callback);
200 277
201 // Performs an interrupt transfer on the specified device. 278 // Performs an interrupt transfer on the specified device.
202 // |device|: An open device to make the transfer on. 279 // |handle|: A connection handle to make the transfer on.
203 // |transferInfo|: The paramters to the transfer. See GenericTransferInfo. 280 // |transferInfo|: The parameters to the transfer. See GenericTransferInfo.
204 // |callback|: Invoked once the transfer has completed. 281 // |callback|: Invoked once the transfer has completed.
205 static void interruptTransfer(Device device, 282 static void interruptTransfer(ConnectionHandle handle,
206 GenericTransferInfo transferInfo, TransferCallback callback); 283 GenericTransferInfo transferInfo,
284 TransferCallback callback);
207 285
208 // Performs an isochronous transfer on the specific device. 286 // Performs an isochronous transfer on the specific device.
209 // |device|: An open device to make the transfer on. 287 // |handle|: A connection handle to make the transfer on.
210 // |transferInfo|: The parameters to the transfer. See 288 // |transferInfo|: The parameters to the transfer. See
211 // IsochronousTransferInfo. 289 // IsochronousTransferInfo.
212 // |callback|: Invoked once the transfer has been completed. 290 // |callback|: Invoked once the transfer has been completed.
213 static void isochronousTransfer(Device device, 291 static void isochronousTransfer(ConnectionHandle handle,
214 IsochronousTransferInfo transferInfo, 292 IsochronousTransferInfo transferInfo,
215 TransferCallback callback); 293 TransferCallback callback);
216 294
217 // Try to reset the USB device and restore the previous status. 295 // Tries to reset the USB device and restores it to the previous status.
296 // If the reset fails, the given connection handle will be closed and the
297 // USB device will appear to be disconnected then reconnected.
298 // In that case you must call |getDevices| or |findDevices| again to acquire
299 // the device.
218 // 300 //
219 // If the reset fails, the given device will be closed and the USB device 301 // |handle|: A connection handle to reset.
220 // will appear to be disconected and reconnected.
221 // You must call <code>findDevice</code> again to acquire the device.
222 //
223 // |device|: An opened device to reset.
224 // |callback|: Invoked once the device is reset with a boolean indicating 302 // |callback|: Invoked once the device is reset with a boolean indicating
225 // whether the reset is completed successfully. 303 // whether the reset is completed successfully.
226 static void resetDevice(Device device, 304 static void resetDevice(ConnectionHandle handle,
227 ResetDeviceCallback callback); 305 ResetDeviceCallback callback);
228 }; 306 };
229 }; 307 };
OLDNEW
« no previous file with comments | « chrome/browser/usb/usb_service.cc ('k') | chrome/common/extensions/permissions/usb_device_permission_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698