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

Side by Side Diff: Source/modules/webusb/USBInterface.cpp

Issue 1245363002: Add WebUSB bindings and client interface (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: iface ctors, OWNERS, rebase 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/USBInterface.h ('k') | Source/modules/webusb/USBInterface.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/USBInterface.h"
7
8 #include "bindings/core/v8/ExceptionState.h"
9 #include "modules/webusb/USBAlternateInterface.h"
10 #include "modules/webusb/USBConfiguration.h"
11
12 namespace blink {
13
14 // static
15 USBInterface* USBInterface::create(const USBConfiguration* configuration, size_t interfaceIndex)
16 {
17 return new USBInterface(configuration, interfaceIndex);
18 }
19
20 // static
21 USBInterface* USBInterface::create(const USBConfiguration* configuration, size_t interfaceIndex, ExceptionState& exceptionState)
22 {
23 if (interfaceIndex < configuration->info().interfaces.size())
24 return new USBInterface(configuration, interfaceIndex);
25 exceptionState.throwRangeError("Invalid interface index.");
26 return nullptr;
27 }
28
29 USBInterface::USBInterface(const USBConfiguration* configuration, size_t interfa ceIndex)
30 : m_configuration(configuration)
31 , m_interfaceIndex(interfaceIndex)
32 {
33 }
34
35 const WebUSBDeviceInfo::Interface& USBInterface::info() const
36 {
37 const WebUSBDeviceInfo::Configuration& configInfo = m_configuration->info();
38 ASSERT(m_interfaceIndex < configInfo.interfaces.size());
39 return configInfo.interfaces[m_interfaceIndex];
40 }
41
42 uint8_t USBInterface::interfaceNumber() const
43 {
44 return info().interfaceNumber;
45 }
46
47 HeapVector<Member<USBAlternateInterface>> USBInterface::alternates() const
48 {
49 HeapVector<Member<USBAlternateInterface>> alternates;
50 for (size_t i = 0; i < info().alternates.size(); ++i)
51 alternates.append(USBAlternateInterface::create(this, i));
52 return alternates;
53 }
54
55 DEFINE_TRACE(USBInterface)
56 {
57 visitor->trace(m_configuration);
58 }
59
60 } // namespace blink
OLDNEW
« 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