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

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

Issue 1252913014: WebUSB bindings part 3 (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: update expeced interface listing Created 5 years, 4 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/USBInterface.h ('k') | Source/modules/webusb/USBInterface.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/webusb/USBInterface.cpp
diff --git a/Source/modules/webusb/USBInterface.cpp b/Source/modules/webusb/USBInterface.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..1c13bbccffb1e50de6c54073fb55cf87836bdcec
--- /dev/null
+++ b/Source/modules/webusb/USBInterface.cpp
@@ -0,0 +1,51 @@
+// Copyright 2015 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.
+
+#include "config.h"
+#include "modules/webusb/USBInterface.h"
+
+#include "bindings/core/v8/ExceptionState.h"
+#include "modules/webusb/USBConfiguration.h"
+
+namespace blink {
+
+USBInterface* USBInterface::create(const USBConfiguration* configuration, size_t interfaceIndex)
+{
+ return new USBInterface(configuration, interfaceIndex);
+}
+
+USBInterface* USBInterface::create(const USBConfiguration* configuration, size_t interfaceNumber, ExceptionState& exceptionState)
+{
+ for (size_t i = 0; i < configuration->info().interfaces.size(); ++i) {
+ if (configuration->info().interfaces[i].interfaceNumber == interfaceNumber)
+ return new USBInterface(configuration, i);
+ }
+ exceptionState.throwRangeError("Invalid interface index.");
+ return nullptr;
+}
+
+USBInterface::USBInterface(const USBConfiguration* configuration, size_t interfaceIndex)
+ : m_configuration(configuration)
+ , m_interfaceIndex(interfaceIndex)
+{
+ ASSERT(m_configuration);
+ ASSERT(m_interfaceIndex < m_configuration->info().interfaces.size());
+}
+
+const WebUSBDeviceInfo::Interface& USBInterface::info() const
+{
+ return m_configuration->info().interfaces[m_interfaceIndex];
+}
+
+uint8_t USBInterface::interfaceNumber() const
+{
+ return info().interfaceNumber;
+}
+
+DEFINE_TRACE(USBInterface)
+{
+ visitor->trace(m_configuration);
+}
+
+} // namespace blink
« no previous file with comments | « Source/modules/webusb/USBInterface.h ('k') | Source/modules/webusb/USBInterface.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698