| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/webusb/USBConfiguration.h" | 5 #include "modules/webusb/USBConfiguration.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "device/usb/public/interfaces/device.mojom-wtf.h" |
| 8 #include "modules/webusb/USBDevice.h" | 9 #include "modules/webusb/USBDevice.h" |
| 9 #include "modules/webusb/USBInterface.h" | 10 #include "modules/webusb/USBInterface.h" |
| 10 | 11 |
| 11 namespace blink { | 12 namespace blink { |
| 12 | 13 |
| 13 USBConfiguration* USBConfiguration::create(const USBDevice* device, size_t confi
gurationIndex) | 14 USBConfiguration* USBConfiguration::create(const USBDevice* device, size_t confi
gurationIndex) |
| 14 { | 15 { |
| 15 return new USBConfiguration(device, configurationIndex); | 16 return new USBConfiguration(device, configurationIndex); |
| 16 } | 17 } |
| 17 | 18 |
| 18 USBConfiguration* USBConfiguration::create(const USBDevice* device, size_t confi
gurationValue, ExceptionState& exceptionState) | 19 USBConfiguration* USBConfiguration::create(const USBDevice* device, size_t confi
gurationValue, ExceptionState& exceptionState) |
| 19 { | 20 { |
| 20 for (size_t i = 0; i < device->info().configurations.size(); ++i) { | 21 const auto& configurations = device->info().configurations; |
| 21 if (device->info().configurations[i].configurationValue == configuration
Value) | 22 for (size_t i = 0; i < configurations.size(); ++i) { |
| 23 if (configurations[i]->configuration_value == configurationValue) |
| 22 return new USBConfiguration(device, i); | 24 return new USBConfiguration(device, i); |
| 23 } | 25 } |
| 24 exceptionState.throwRangeError("Invalid configuration value."); | 26 exceptionState.throwRangeError("Invalid configuration value."); |
| 25 return nullptr; | 27 return nullptr; |
| 26 } | 28 } |
| 27 | 29 |
| 28 USBConfiguration* USBConfiguration::createFromValue(const USBDevice* device, uin
t8_t configurationValue) | |
| 29 { | |
| 30 for (size_t i = 0; i < device->info().configurations.size(); ++i) { | |
| 31 if (device->info().configurations[i].configurationValue == configuration
Value) | |
| 32 return new USBConfiguration(device, i); | |
| 33 } | |
| 34 return nullptr; | |
| 35 } | |
| 36 | |
| 37 USBConfiguration::USBConfiguration(const USBDevice* device, size_t configuration
Index) | 30 USBConfiguration::USBConfiguration(const USBDevice* device, size_t configuration
Index) |
| 38 : m_device(device) | 31 : m_device(device) |
| 39 , m_configurationIndex(configurationIndex) | 32 , m_configurationIndex(configurationIndex) |
| 40 { | 33 { |
| 41 ASSERT(m_device); | 34 ASSERT(m_device); |
| 42 ASSERT(m_configurationIndex < m_device->info().configurations.size()); | 35 ASSERT(m_configurationIndex < m_device->info().configurations.size()); |
| 43 } | 36 } |
| 44 | 37 |
| 45 const USBDevice* USBConfiguration::device() const | 38 const USBDevice* USBConfiguration::device() const |
| 46 { | 39 { |
| 47 return m_device; | 40 return m_device; |
| 48 } | 41 } |
| 49 | 42 |
| 50 size_t USBConfiguration::index() const | 43 size_t USBConfiguration::index() const |
| 51 { | 44 { |
| 52 return m_configurationIndex; | 45 return m_configurationIndex; |
| 53 } | 46 } |
| 54 | 47 |
| 55 const WebUSBDeviceInfo::Configuration& USBConfiguration::info() const | 48 const device::usb::wtf::ConfigurationInfo& USBConfiguration::info() const |
| 56 { | 49 { |
| 57 return m_device->info().configurations[m_configurationIndex]; | 50 return *m_device->info().configurations[m_configurationIndex]; |
| 58 } | |
| 59 | |
| 60 uint8_t USBConfiguration::configurationValue() const | |
| 61 { | |
| 62 return info().configurationValue; | |
| 63 } | |
| 64 | |
| 65 String USBConfiguration::configurationName() const | |
| 66 { | |
| 67 return info().configurationName; | |
| 68 } | 51 } |
| 69 | 52 |
| 70 HeapVector<Member<USBInterface>> USBConfiguration::interfaces() const | 53 HeapVector<Member<USBInterface>> USBConfiguration::interfaces() const |
| 71 { | 54 { |
| 72 HeapVector<Member<USBInterface>> interfaces; | 55 HeapVector<Member<USBInterface>> interfaces; |
| 73 for (size_t i = 0; i < info().interfaces.size(); ++i) | 56 for (size_t i = 0; i < info().interfaces.size(); ++i) |
| 74 interfaces.append(USBInterface::create(this, i)); | 57 interfaces.append(USBInterface::create(this, i)); |
| 75 return interfaces; | 58 return interfaces; |
| 76 } | 59 } |
| 77 | 60 |
| 78 DEFINE_TRACE(USBConfiguration) | 61 DEFINE_TRACE(USBConfiguration) |
| 79 { | 62 { |
| 80 visitor->trace(m_device); | 63 visitor->trace(m_device); |
| 81 } | 64 } |
| 82 | 65 |
| 83 } // namespace blink | 66 } // namespace blink |
| OLD | NEW |