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

Unified Diff: Source/modules/webusb/USBConfiguration.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/USBConfiguration.h ('k') | Source/modules/webusb/USBConfiguration.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/webusb/USBConfiguration.cpp
diff --git a/Source/modules/webusb/USBConfiguration.cpp b/Source/modules/webusb/USBConfiguration.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..d08a98e301388c30356c900cad1cb6da8ac0d34c
--- /dev/null
+++ b/Source/modules/webusb/USBConfiguration.cpp
@@ -0,0 +1,65 @@
+// 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/USBConfiguration.h"
+
+#include "bindings/core/v8/ExceptionState.h"
+#include "modules/webusb/USBDevice.h"
+#include "modules/webusb/USBInterface.h"
+
+namespace blink {
+
+USBConfiguration* USBConfiguration::create(const USBDevice* device, size_t configurationIndex)
+{
+ return new USBConfiguration(device, configurationIndex);
+}
+
+USBConfiguration* USBConfiguration::create(const USBDevice* device, size_t configurationValue, ExceptionState& exceptionState)
+{
+ for (size_t i = 0; i < device->info().configurations.size(); ++i) {
+ if (device->info().configurations[i].configurationValue == configurationValue)
+ return new USBConfiguration(device, i);
+ }
+ exceptionState.throwRangeError("Invalid configuration value.");
+ return nullptr;
+}
+
+USBConfiguration::USBConfiguration(const USBDevice* device, size_t configurationIndex)
+ : m_device(device)
+ , m_configurationIndex(configurationIndex)
+{
+ ASSERT(m_device);
+ ASSERT(m_configurationIndex < m_device->info().configurations.size());
+}
+
+const WebUSBDeviceInfo::Configuration& USBConfiguration::info() const
+{
+ return m_device->info().configurations[m_configurationIndex];
+}
+
+uint8_t USBConfiguration::configurationValue() const
+{
+ return info().configurationValue;
+}
+
+String USBConfiguration::configurationName() const
+{
+ return info().configurationName;
+}
+
+HeapVector<Member<USBInterface>> USBConfiguration::interfaces() const
+{
+ HeapVector<Member<USBInterface>> interfaces;
+ for (size_t i = 0; i < info().interfaces.size(); ++i)
+ interfaces.append(USBInterface::create(this, i));
+ return interfaces;
+}
+
+DEFINE_TRACE(USBConfiguration)
+{
+ visitor->trace(m_device);
+}
+
+} // namespace blink
« no previous file with comments | « Source/modules/webusb/USBConfiguration.h ('k') | Source/modules/webusb/USBConfiguration.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698