| 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/USBDevice.h" | 6 #include "modules/webusb/USBDevice.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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 case WebUSBTransferInfo::Status::Stall: | 65 case WebUSBTransferInfo::Status::Stall: |
| 66 return "stall"; | 66 return "stall"; |
| 67 case WebUSBTransferInfo::Status::Babble: | 67 case WebUSBTransferInfo::Status::Babble: |
| 68 return "babble"; | 68 return "babble"; |
| 69 default: | 69 default: |
| 70 ASSERT_NOT_REACHED(); | 70 ASSERT_NOT_REACHED(); |
| 71 return ""; | 71 return ""; |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 | 74 |
| 75 class GetConfigurationPromiseAdapter : public WebCallbacks<uint8_t, const WebUSB
Error&> { |
| 76 public: |
| 77 GetConfigurationPromiseAdapter(USBDevice* device, ScriptPromiseResolver* res
olver) : m_device(device), m_resolver(resolver) {} |
| 78 |
| 79 void onSuccess(uint8_t value) override |
| 80 { |
| 81 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) |
| 82 return; |
| 83 m_resolver->resolve(USBConfiguration::createFromValue(m_device, value)); |
| 84 } |
| 85 |
| 86 void onError(const WebUSBError& e) override |
| 87 { |
| 88 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) |
| 89 return; |
| 90 m_resolver->reject(USBError::take(m_resolver, e)); |
| 91 } |
| 92 |
| 93 private: |
| 94 Persistent<USBDevice> m_device; |
| 95 Persistent<ScriptPromiseResolver> m_resolver; |
| 96 }; |
| 97 |
| 75 class InputTransferResult { | 98 class InputTransferResult { |
| 76 WTF_MAKE_NONCOPYABLE(InputTransferResult); | 99 WTF_MAKE_NONCOPYABLE(InputTransferResult); |
| 77 public: | 100 public: |
| 78 using WebType = OwnPtr<WebUSBTransferInfo>; | 101 using WebType = OwnPtr<WebUSBTransferInfo>; |
| 79 | 102 |
| 80 static USBInTransferResult* take(ScriptPromiseResolver*, PassOwnPtr<WebUSBTr
ansferInfo> webTransferInfo) | 103 static USBInTransferResult* take(ScriptPromiseResolver*, PassOwnPtr<WebUSBTr
ansferInfo> webTransferInfo) |
| 81 { | 104 { |
| 82 return USBInTransferResult::create(convertTransferStatus(webTransferInfo
->status), webTransferInfo->data); | 105 return USBInTransferResult::create(convertTransferStatus(webTransferInfo
->status), webTransferInfo->data); |
| 83 } | 106 } |
| 84 | 107 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 } | 168 } |
| 146 | 169 |
| 147 ScriptPromise USBDevice::close(ScriptState* scriptState) | 170 ScriptPromise USBDevice::close(ScriptState* scriptState) |
| 148 { | 171 { |
| 149 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 172 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 150 ScriptPromise promise = resolver->promise(); | 173 ScriptPromise promise = resolver->promise(); |
| 151 m_device->close(new CallbackPromiseAdapter<void, USBError>(resolver)); | 174 m_device->close(new CallbackPromiseAdapter<void, USBError>(resolver)); |
| 152 return promise; | 175 return promise; |
| 153 } | 176 } |
| 154 | 177 |
| 178 ScriptPromise USBDevice::getConfiguration(ScriptState* scriptState) |
| 179 { |
| 180 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 181 ScriptPromise promise = resolver->promise(); |
| 182 m_device->getConfiguration(new GetConfigurationPromiseAdapter(this, resolver
)); |
| 183 return promise; |
| 184 } |
| 185 |
| 155 ScriptPromise USBDevice::setConfiguration(ScriptState* scriptState, uint8_t conf
igurationValue) | 186 ScriptPromise USBDevice::setConfiguration(ScriptState* scriptState, uint8_t conf
igurationValue) |
| 156 { | 187 { |
| 157 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 188 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 158 ScriptPromise promise = resolver->promise(); | 189 ScriptPromise promise = resolver->promise(); |
| 159 m_device->setConfiguration(configurationValue, new CallbackPromiseAdapter<vo
id, USBError>(resolver)); | 190 m_device->setConfiguration(configurationValue, new CallbackPromiseAdapter<vo
id, USBError>(resolver)); |
| 160 return promise; | 191 return promise; |
| 161 } | 192 } |
| 162 | 193 |
| 163 ScriptPromise USBDevice::claimInterface(ScriptState* scriptState, uint8_t interf
aceNumber) | 194 ScriptPromise USBDevice::claimInterface(ScriptState* scriptState, uint8_t interf
aceNumber) |
| 164 { | 195 { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 | 283 |
| 253 ScriptPromise USBDevice::reset(ScriptState* scriptState) | 284 ScriptPromise USBDevice::reset(ScriptState* scriptState) |
| 254 { | 285 { |
| 255 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 286 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 256 ScriptPromise promise = resolver->promise(); | 287 ScriptPromise promise = resolver->promise(); |
| 257 m_device->reset(new CallbackPromiseAdapter<void, USBError>(resolver)); | 288 m_device->reset(new CallbackPromiseAdapter<void, USBError>(resolver)); |
| 258 return promise; | 289 return promise; |
| 259 } | 290 } |
| 260 | 291 |
| 261 } // namespace blink | 292 } // namespace blink |
| OLD | NEW |