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

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