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 #include "config.h" | 5 #include "config.h" |
6 #include "modules/webusb/USB.h" | 6 #include "modules/webusb/USB.h" |
7 | 7 |
8 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
9 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 if (filter.hasProtocolCode()) | 48 if (filter.hasProtocolCode()) |
49 webFilter.protocolCode = filter.protocolCode(); | 49 webFilter.protocolCode = filter.protocolCode(); |
50 } | 50 } |
51 } | 51 } |
52 | 52 |
53 // Allows using a CallbackPromiseAdapter with a WebVector to resolve the | 53 // Allows using a CallbackPromiseAdapter with a WebVector to resolve the |
54 // getDevices() promise with a HeapVector owning USBDevices. | 54 // getDevices() promise with a HeapVector owning USBDevices. |
55 class DeviceArray { | 55 class DeviceArray { |
56 WTF_MAKE_NONCOPYABLE(DeviceArray); | 56 WTF_MAKE_NONCOPYABLE(DeviceArray); |
57 public: | 57 public: |
58 using WebType = WebVector<WebUSBDevice*>; | 58 using WebType = OwnPtr<WebVector<WebUSBDevice*>>; |
59 | 59 |
60 static HeapVector<Member<USBDevice>> take(ScriptPromiseResolver*, PassOwnPtr
<WebType> webDevices) | 60 static HeapVector<Member<USBDevice>> take(ScriptPromiseResolver*, PassOwnPtr
<WebVector<WebUSBDevice*>> webDevices) |
61 { | 61 { |
62 HeapVector<Member<USBDevice>> devices; | 62 HeapVector<Member<USBDevice>> devices; |
63 for (const auto webDevice : *webDevices) | 63 for (const auto webDevice : *webDevices) |
64 devices.append(USBDevice::create(adoptPtr(webDevice))); | 64 devices.append(USBDevice::create(adoptPtr(webDevice))); |
65 return devices; | 65 return devices; |
66 } | 66 } |
67 | 67 |
68 private: | 68 private: |
69 DeviceArray() = delete; | 69 DeviceArray() = delete; |
70 }; | 70 }; |
71 | 71 |
72 } // namespace | 72 } // namespace |
73 | 73 |
74 USB::USB(LocalFrame& frame) | 74 USB::USB(LocalFrame& frame) |
75 : m_controller(USBController::from(frame)) | 75 : m_controller(USBController::from(frame)) |
76 { | 76 { |
77 } | 77 } |
78 | 78 |
79 ScriptPromise USB::getDevices(ScriptState* scriptState, const USBDeviceEnumerati
onOptions& options) | 79 ScriptPromise USB::getDevices(ScriptState* scriptState, const USBDeviceEnumerati
onOptions& options) |
80 { | 80 { |
81 WebUSBClient* client = m_controller->client(); | 81 WebUSBClient* client = m_controller->client(); |
82 if (!client) | 82 if (!client) |
83 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); | 83 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); |
84 | 84 |
85 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 85 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
86 ScriptPromise promise = resolver->promise(); | 86 ScriptPromise promise = resolver->promise(); |
87 | 87 |
88 WebUSBDeviceEnumerationOptions webOptions; | 88 WebUSBDeviceEnumerationOptions webOptions; |
89 convertDeviceEnumerationOptions(options, &webOptions); | 89 convertDeviceEnumerationOptions(options, &webOptions); |
90 | 90 client->getDevices(webOptions, new CallbackPromiseAdapter<DeviceArray, USBEr
ror>(resolver)); |
91 // TODO(rockot): Re-enable this after CPA changes land. | |
92 // That's https://codereview.chromium.org/1240763002/ and dependent patches. | |
93 // client->getDevices(webOptions, new CallbackPromiseAdapter<DeviceArray, US
BError>(resolver)); | |
94 ASSERT_NOT_REACHED(); | |
95 | |
96 return promise; | 91 return promise; |
97 } | 92 } |
98 | 93 |
99 DEFINE_TRACE(USB) | 94 DEFINE_TRACE(USB) |
100 { | 95 { |
101 visitor->trace(m_controller); | 96 visitor->trace(m_controller); |
102 } | 97 } |
103 | 98 |
104 } // namespace blink | 99 } // namespace blink |
OLD | NEW |