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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « Source/modules/webusb/USBConfiguration.h ('k') | Source/modules/webusb/USBConfiguration.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "modules/webusb/USBConfiguration.h"
7
8 #include "bindings/core/v8/ExceptionState.h"
9 #include "modules/webusb/USBDevice.h"
10 #include "modules/webusb/USBInterface.h"
11
12 namespace blink {
13
14 USBConfiguration* USBConfiguration::create(const USBDevice* device, size_t confi gurationIndex)
15 {
16 return new USBConfiguration(device, configurationIndex);
17 }
18
19 USBConfiguration* USBConfiguration::create(const USBDevice* device, size_t confi gurationValue, ExceptionState& exceptionState)
20 {
21 for (size_t i = 0; i < device->info().configurations.size(); ++i) {
22 if (device->info().configurations[i].configurationValue == configuration Value)
23 return new USBConfiguration(device, i);
24 }
25 exceptionState.throwRangeError("Invalid configuration value.");
26 return nullptr;
27 }
28
29 USBConfiguration::USBConfiguration(const USBDevice* device, size_t configuration Index)
30 : m_device(device)
31 , m_configurationIndex(configurationIndex)
32 {
33 ASSERT(m_device);
34 ASSERT(m_configurationIndex < m_device->info().configurations.size());
35 }
36
37 const WebUSBDeviceInfo::Configuration& USBConfiguration::info() const
38 {
39 return m_device->info().configurations[m_configurationIndex];
40 }
41
42 uint8_t USBConfiguration::configurationValue() const
43 {
44 return info().configurationValue;
45 }
46
47 String USBConfiguration::configurationName() const
48 {
49 return info().configurationName;
50 }
51
52 HeapVector<Member<USBInterface>> USBConfiguration::interfaces() const
53 {
54 HeapVector<Member<USBInterface>> interfaces;
55 for (size_t i = 0; i < info().interfaces.size(); ++i)
56 interfaces.append(USBInterface::create(this, i));
57 return interfaces;
58 }
59
60 DEFINE_TRACE(USBConfiguration)
61 {
62 visitor->trace(m_device);
63 }
64
65 } // namespace blink
OLDNEW
« 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