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

Unified Diff: Source/modules/webusb/USBDevice.cpp

Issue 1352283005: Add getConfiguration method to USBDevice. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Update webexposed/global-interface-listing-expected.txt. Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/webusb/USBDevice.h ('k') | Source/modules/webusb/USBDevice.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/webusb/USBDevice.cpp
diff --git a/Source/modules/webusb/USBDevice.cpp b/Source/modules/webusb/USBDevice.cpp
index afaa2f85ec6f41a6c805385d5ff916d8e4b0c94d..6cb2ddacce3cb66703f13cbe2f26ef7fbdc44b30 100644
--- a/Source/modules/webusb/USBDevice.cpp
+++ b/Source/modules/webusb/USBDevice.cpp
@@ -72,6 +72,29 @@ String convertTransferStatus(const WebUSBTransferInfo::Status& status)
}
}
+class GetConfigurationPromiseAdapter : public WebCallbacks<uint8_t, const WebUSBError&> {
+public:
+ GetConfigurationPromiseAdapter(USBDevice* device, ScriptPromiseResolver* resolver) : m_device(device), m_resolver(resolver) {}
+
+ void onSuccess(uint8_t value) override
+ {
+ if (!m_resolver->executionContext() || m_resolver->executionContext()->activeDOMObjectsAreStopped())
+ return;
+ m_resolver->resolve(USBConfiguration::createFromValue(m_device, value));
+ }
+
+ void onError(const WebUSBError& e) override
+ {
+ if (!m_resolver->executionContext() || m_resolver->executionContext()->activeDOMObjectsAreStopped())
+ return;
+ m_resolver->reject(USBError::take(m_resolver, e));
+ }
+
+private:
+ Persistent<USBDevice> m_device;
+ Persistent<ScriptPromiseResolver> m_resolver;
+};
+
class InputTransferResult {
WTF_MAKE_NONCOPYABLE(InputTransferResult);
public:
@@ -152,6 +175,14 @@ ScriptPromise USBDevice::close(ScriptState* scriptState)
return promise;
}
+ScriptPromise USBDevice::getConfiguration(ScriptState* scriptState)
+{
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
+ ScriptPromise promise = resolver->promise();
+ m_device->getConfiguration(new GetConfigurationPromiseAdapter(this, resolver));
+ return promise;
+}
+
ScriptPromise USBDevice::setConfiguration(ScriptState* scriptState, uint8_t configurationValue)
{
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
« no previous file with comments | « Source/modules/webusb/USBDevice.h ('k') | Source/modules/webusb/USBDevice.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698