1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef EXTENSIONS_BROWSER_API_USB_USB_API_H_
#define EXTENSIONS_BROWSER_API_USB_USB_API_H_
#include <stddef.h>
#include <stdint.h>
#include <string>
#include <vector>
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "device/usb/usb_device.h"
#include "device/usb/usb_device_filter.h"
#include "device/usb/usb_device_handle.h"
#include "extensions/browser/api/api_resource_manager.h"
#include "extensions/browser/extension_function.h"
#include "extensions/common/api/usb.h"
#include "net/base/io_buffer.h"
namespace extensions {
class DevicePermissionEntry;
class DevicePermissions;
class DevicePermissionsPrompt;
class DevicePermissionsManager;
class UsbDeviceResource;
class UsbPermissionCheckingFunction : public UIThreadExtensionFunction {
protected:
UsbPermissionCheckingFunction();
~UsbPermissionCheckingFunction() override;
bool HasDevicePermission(scoped_refptr<device::UsbDevice> device);
void RecordDeviceLastUsed();
private:
DevicePermissionsManager* device_permissions_manager_;
scoped_refptr<DevicePermissionEntry> permission_entry_;
};
class UsbConnectionFunction : public UIThreadExtensionFunction {
protected:
UsbConnectionFunction();
~UsbConnectionFunction() override;
scoped_refptr<device::UsbDeviceHandle> GetDeviceHandle(
const extensions::api::usb::ConnectionHandle& handle);
void ReleaseDeviceHandle(
const extensions::api::usb::ConnectionHandle& handle);
};
class UsbTransferFunction : public UsbConnectionFunction {
protected:
UsbTransferFunction();
~UsbTransferFunction() override;
void OnCompleted(device::UsbTransferStatus status,
scoped_refptr<net::IOBuffer> data,
size_t length);
};
class UsbFindDevicesFunction : public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("usb.findDevices", USB_FINDDEVICES)
UsbFindDevicesFunction();
private:
~UsbFindDevicesFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
void OnGetDevicesComplete(
const std::vector<scoped_refptr<device::UsbDevice>>& devices);
void OnDeviceOpened(scoped_refptr<device::UsbDeviceHandle> device_handle);
void OpenComplete();
uint16_t vendor_id_;
uint16_t product_id_;
scoped_ptr<base::ListValue> result_;
base::Closure barrier_;
DISALLOW_COPY_AND_ASSIGN(UsbFindDevicesFunction);
};
class UsbGetDevicesFunction : public UsbPermissionCheckingFunction {
public:
DECLARE_EXTENSION_FUNCTION("usb.getDevices", USB_GETDEVICES)
UsbGetDevicesFunction();
private:
~UsbGetDevicesFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
void OnGetDevicesComplete(
const std::vector<scoped_refptr<device::UsbDevice>>& devices);
std::vector<device::UsbDeviceFilter> filters_;
DISALLOW_COPY_AND_ASSIGN(UsbGetDevicesFunction);
};
class UsbGetUserSelectedDevicesFunction : public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("usb.getUserSelectedDevices",
USB_GETUSERSELECTEDDEVICES)
UsbGetUserSelectedDevicesFunction();
private:
~UsbGetUserSelectedDevicesFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
void OnDevicesChosen(
const std::vector<scoped_refptr<device::UsbDevice>>& devices);
scoped_ptr<DevicePermissionsPrompt> prompt_;
DISALLOW_COPY_AND_ASSIGN(UsbGetUserSelectedDevicesFunction);
};
class UsbGetConfigurationsFunction : public UsbPermissionCheckingFunction {
public:
DECLARE_EXTENSION_FUNCTION("usb.getConfigurations", USB_GETCONFIGURATIONS);
UsbGetConfigurationsFunction();
private:
~UsbGetConfigurationsFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
DISALLOW_COPY_AND_ASSIGN(UsbGetConfigurationsFunction);
};
class UsbRequestAccessFunction : public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("usb.requestAccess", USB_REQUESTACCESS)
UsbRequestAccessFunction();
private:
~UsbRequestAccessFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
DISALLOW_COPY_AND_ASSIGN(UsbRequestAccessFunction);
};
class UsbOpenDeviceFunction : public UsbPermissionCheckingFunction {
public:
DECLARE_EXTENSION_FUNCTION("usb.openDevice", USB_OPENDEVICE)
UsbOpenDeviceFunction();
private:
~UsbOpenDeviceFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
void OnDeviceOpened(scoped_refptr<device::UsbDeviceHandle> device_handle);
DISALLOW_COPY_AND_ASSIGN(UsbOpenDeviceFunction);
};
class UsbSetConfigurationFunction : public UsbConnectionFunction {
public:
DECLARE_EXTENSION_FUNCTION("usb.setConfiguration", USB_SETCONFIGURATION)
UsbSetConfigurationFunction();
private:
~UsbSetConfigurationFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
void OnComplete(bool success);
DISALLOW_COPY_AND_ASSIGN(UsbSetConfigurationFunction);
};
class UsbGetConfigurationFunction : public UsbConnectionFunction {
public:
DECLARE_EXTENSION_FUNCTION("usb.getConfiguration", USB_GETCONFIGURATION)
UsbGetConfigurationFunction();
private:
~UsbGetConfigurationFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
DISALLOW_COPY_AND_ASSIGN(UsbGetConfigurationFunction);
};
class UsbListInterfacesFunction : public UsbConnectionFunction {
public:
DECLARE_EXTENSION_FUNCTION("usb.listInterfaces", USB_LISTINTERFACES)
UsbListInterfacesFunction();
private:
~UsbListInterfacesFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
DISALLOW_COPY_AND_ASSIGN(UsbListInterfacesFunction);
};
class UsbCloseDeviceFunction : public UsbConnectionFunction {
public:
DECLARE_EXTENSION_FUNCTION("usb.closeDevice", USB_CLOSEDEVICE)
UsbCloseDeviceFunction();
private:
~UsbCloseDeviceFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
DISALLOW_COPY_AND_ASSIGN(UsbCloseDeviceFunction);
};
class UsbClaimInterfaceFunction : public UsbConnectionFunction {
public:
DECLARE_EXTENSION_FUNCTION("usb.claimInterface", USB_CLAIMINTERFACE)
UsbClaimInterfaceFunction();
protected:
~UsbClaimInterfaceFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
void OnComplete(bool success);
DISALLOW_COPY_AND_ASSIGN(UsbClaimInterfaceFunction);
};
class UsbReleaseInterfaceFunction : public UsbConnectionFunction {
public:
DECLARE_EXTENSION_FUNCTION("usb.releaseInterface", USB_RELEASEINTERFACE)
UsbReleaseInterfaceFunction();
private:
~UsbReleaseInterfaceFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
DISALLOW_COPY_AND_ASSIGN(UsbReleaseInterfaceFunction);
};
class UsbSetInterfaceAlternateSettingFunction : public UsbConnectionFunction {
public:
DECLARE_EXTENSION_FUNCTION("usb.setInterfaceAlternateSetting",
USB_SETINTERFACEALTERNATESETTING)
UsbSetInterfaceAlternateSettingFunction();
private:
~UsbSetInterfaceAlternateSettingFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
void OnComplete(bool success);
DISALLOW_COPY_AND_ASSIGN(UsbSetInterfaceAlternateSettingFunction);
};
class UsbControlTransferFunction : public UsbTransferFunction {
public:
DECLARE_EXTENSION_FUNCTION("usb.controlTransfer", USB_CONTROLTRANSFER)
UsbControlTransferFunction();
private:
~UsbControlTransferFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
DISALLOW_COPY_AND_ASSIGN(UsbControlTransferFunction);
};
class UsbBulkTransferFunction : public UsbTransferFunction {
public:
DECLARE_EXTENSION_FUNCTION("usb.bulkTransfer", USB_BULKTRANSFER)
UsbBulkTransferFunction();
private:
~UsbBulkTransferFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
DISALLOW_COPY_AND_ASSIGN(UsbBulkTransferFunction);
};
class UsbInterruptTransferFunction : public UsbTransferFunction {
public:
DECLARE_EXTENSION_FUNCTION("usb.interruptTransfer", USB_INTERRUPTTRANSFER)
UsbInterruptTransferFunction();
private:
~UsbInterruptTransferFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
DISALLOW_COPY_AND_ASSIGN(UsbInterruptTransferFunction);
};
class UsbIsochronousTransferFunction : public UsbTransferFunction {
public:
DECLARE_EXTENSION_FUNCTION("usb.isochronousTransfer", USB_ISOCHRONOUSTRANSFER)
UsbIsochronousTransferFunction();
private:
~UsbIsochronousTransferFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
DISALLOW_COPY_AND_ASSIGN(UsbIsochronousTransferFunction);
};
class UsbResetDeviceFunction : public UsbConnectionFunction {
public:
DECLARE_EXTENSION_FUNCTION("usb.resetDevice", USB_RESETDEVICE)
UsbResetDeviceFunction();
private:
~UsbResetDeviceFunction() override;
// ExtensionFunction:
ResponseAction Run() override;
void OnComplete(bool success);
scoped_ptr<extensions::api::usb::ResetDevice::Params> parameters_;
DISALLOW_COPY_AND_ASSIGN(UsbResetDeviceFunction);
};
} // namespace extensions
#endif // EXTENSIONS_BROWSER_API_USB_USB_API_H_
|