| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef USBDevice_h | 5 #ifndef USBDevice_h |
| 6 #define USBDevice_h | 6 #define USBDevice_h |
| 7 | 7 |
| 8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
| 9 #include "bindings/core/v8/ScriptWrappable.h" | 9 #include "bindings/core/v8/ScriptWrappable.h" |
| 10 #include "bindings/modules/v8/UnionTypesModules.h" | 10 #include "bindings/modules/v8/UnionTypesModules.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 public: | 30 public: |
| 31 using WebType = OwnPtr<WebUSBDevice>; | 31 using WebType = OwnPtr<WebUSBDevice>; |
| 32 | 32 |
| 33 static USBDevice* create(PassOwnPtr<WebUSBDevice> device, ExecutionContext*
context) | 33 static USBDevice* create(PassOwnPtr<WebUSBDevice> device, ExecutionContext*
context) |
| 34 { | 34 { |
| 35 return new USBDevice(device, context); | 35 return new USBDevice(device, context); |
| 36 } | 36 } |
| 37 | 37 |
| 38 static USBDevice* take(ScriptPromiseResolver*, PassOwnPtr<WebUSBDevice>); | 38 static USBDevice* take(ScriptPromiseResolver*, PassOwnPtr<WebUSBDevice>); |
| 39 | 39 |
| 40 explicit USBDevice(PassOwnPtr<WebUSBDevice> device, ExecutionContext* contex
t) | 40 explicit USBDevice(PassOwnPtr<WebUSBDevice>, ExecutionContext*); |
| 41 : ContextLifecycleObserver(context) | |
| 42 , m_device(device) | |
| 43 , m_opened(false) | |
| 44 , m_deviceStateChangeInProgress(false) | |
| 45 { | |
| 46 } | |
| 47 | |
| 48 virtual ~USBDevice() { } | 41 virtual ~USBDevice() { } |
| 49 | 42 |
| 50 const WebUSBDeviceInfo& info() const { return m_device->info(); } | 43 const WebUSBDeviceInfo& info() const { return m_device->info(); } |
| 51 void onDeviceOpenedOrClosed(bool); | 44 void onDeviceOpenedOrClosed(bool); |
| 45 void onConfigurationSelected(bool success, int configurationIndex); |
| 52 | 46 |
| 53 // IDL exposed interface: | 47 // IDL exposed interface: |
| 54 String guid() const { return info().guid; } | 48 String guid() const { return info().guid; } |
| 55 uint8_t usbVersionMajor() { return info().usbVersionMajor; } | 49 uint8_t usbVersionMajor() { return info().usbVersionMajor; } |
| 56 uint8_t usbVersionMinor() { return info().usbVersionMinor; } | 50 uint8_t usbVersionMinor() { return info().usbVersionMinor; } |
| 57 uint8_t usbVersionSubminor() { return info().usbVersionSubminor; } | 51 uint8_t usbVersionSubminor() { return info().usbVersionSubminor; } |
| 58 uint8_t deviceClass() { return info().deviceClass; } | 52 uint8_t deviceClass() { return info().deviceClass; } |
| 59 uint8_t deviceSubclass() const { return info().deviceSubclass; } | 53 uint8_t deviceSubclass() const { return info().deviceSubclass; } |
| 60 uint8_t deviceProtocol() const { return info().deviceProtocol; } | 54 uint8_t deviceProtocol() const { return info().deviceProtocol; } |
| 61 uint16_t vendorId() const { return info().vendorID; } | 55 uint16_t vendorId() const { return info().vendorID; } |
| 62 uint16_t productId() const { return info().productID; } | 56 uint16_t productId() const { return info().productID; } |
| 63 uint8_t deviceVersionMajor() const { return info().deviceVersionMajor; } | 57 uint8_t deviceVersionMajor() const { return info().deviceVersionMajor; } |
| 64 uint8_t deviceVersionMinor() const { return info().deviceVersionMinor; } | 58 uint8_t deviceVersionMinor() const { return info().deviceVersionMinor; } |
| 65 uint8_t deviceVersionSubminor() const { return info().deviceVersionSubminor;
} | 59 uint8_t deviceVersionSubminor() const { return info().deviceVersionSubminor;
} |
| 66 String manufacturerName() const { return info().manufacturerName; } | 60 String manufacturerName() const { return info().manufacturerName; } |
| 67 String productName() const { return info().productName; } | 61 String productName() const { return info().productName; } |
| 68 String serialNumber() const { return info().serialNumber; } | 62 String serialNumber() const { return info().serialNumber; } |
| 63 USBConfiguration* configuration() const; |
| 69 HeapVector<Member<USBConfiguration>> configurations() const; | 64 HeapVector<Member<USBConfiguration>> configurations() const; |
| 70 bool opened() const { return m_opened; } | 65 bool opened() const { return m_opened; } |
| 71 | 66 |
| 72 ScriptPromise open(ScriptState*); | 67 ScriptPromise open(ScriptState*); |
| 73 ScriptPromise close(ScriptState*); | 68 ScriptPromise close(ScriptState*); |
| 74 ScriptPromise getConfiguration(ScriptState*); | 69 ScriptPromise selectConfiguration(ScriptState*, uint8_t configurationValue); |
| 75 ScriptPromise setConfiguration(ScriptState*, uint8_t configurationValue); | |
| 76 ScriptPromise claimInterface(ScriptState*, uint8_t interfaceNumber); | 70 ScriptPromise claimInterface(ScriptState*, uint8_t interfaceNumber); |
| 77 ScriptPromise releaseInterface(ScriptState*, uint8_t interfaceNumber); | 71 ScriptPromise releaseInterface(ScriptState*, uint8_t interfaceNumber); |
| 78 ScriptPromise setInterface(ScriptState*, uint8_t interfaceNumber, uint8_t al
ternateSetting); | 72 ScriptPromise setInterface(ScriptState*, uint8_t interfaceNumber, uint8_t al
ternateSetting); |
| 79 ScriptPromise controlTransferIn(ScriptState*, const USBControlTransferParame
ters& setup, unsigned length); | 73 ScriptPromise controlTransferIn(ScriptState*, const USBControlTransferParame
ters& setup, unsigned length); |
| 80 ScriptPromise controlTransferOut(ScriptState*, const USBControlTransferParam
eters& setup); | 74 ScriptPromise controlTransferOut(ScriptState*, const USBControlTransferParam
eters& setup); |
| 81 ScriptPromise controlTransferOut(ScriptState*, const USBControlTransferParam
eters& setup, const ArrayBufferOrArrayBufferView& data); | 75 ScriptPromise controlTransferOut(ScriptState*, const USBControlTransferParam
eters& setup, const ArrayBufferOrArrayBufferView& data); |
| 82 ScriptPromise clearHalt(ScriptState*, uint8_t endpointNumber); | 76 ScriptPromise clearHalt(ScriptState*, uint8_t endpointNumber); |
| 83 ScriptPromise transferIn(ScriptState*, uint8_t endpointNumber, unsigned leng
th); | 77 ScriptPromise transferIn(ScriptState*, uint8_t endpointNumber, unsigned leng
th); |
| 84 ScriptPromise transferOut(ScriptState*, uint8_t endpointNumber, const ArrayB
ufferOrArrayBufferView& data); | 78 ScriptPromise transferOut(ScriptState*, uint8_t endpointNumber, const ArrayB
ufferOrArrayBufferView& data); |
| 85 ScriptPromise isochronousTransferIn(ScriptState*, uint8_t endpointNumber, Ve
ctor<unsigned> packetLengths); | 79 ScriptPromise isochronousTransferIn(ScriptState*, uint8_t endpointNumber, Ve
ctor<unsigned> packetLengths); |
| 86 ScriptPromise isochronousTransferOut(ScriptState*, uint8_t endpointNumber, c
onst ArrayBufferOrArrayBufferView& data, Vector<unsigned> packetLengths); | 80 ScriptPromise isochronousTransferOut(ScriptState*, uint8_t endpointNumber, c
onst ArrayBufferOrArrayBufferView& data, Vector<unsigned> packetLengths); |
| 87 ScriptPromise reset(ScriptState*); | 81 ScriptPromise reset(ScriptState*); |
| 88 | 82 |
| 89 void contextDestroyed() override; | 83 void contextDestroyed() override; |
| 90 | 84 |
| 91 DECLARE_TRACE(); | 85 DECLARE_TRACE(); |
| 92 | 86 |
| 93 private: | 87 private: |
| 88 int findConfigurationIndex(uint8_t configurationValue) const; |
| 89 bool ensureDeviceConfigured(ScriptPromiseResolver*) const; |
| 90 |
| 94 OwnPtr<WebUSBDevice> m_device; | 91 OwnPtr<WebUSBDevice> m_device; |
| 95 bool m_opened; | 92 bool m_opened; |
| 96 bool m_deviceStateChangeInProgress; | 93 bool m_deviceStateChangeInProgress; |
| 94 int m_configurationIndex; |
| 97 }; | 95 }; |
| 98 | 96 |
| 99 } // namespace blink | 97 } // namespace blink |
| 100 | 98 |
| 101 #endif // USBDevice_h | 99 #endif // USBDevice_h |
| OLD | NEW |