OLD | NEW |
---|---|
(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 "content/renderer/usb/type_converters.h" | |
6 | |
7 #include "base/logging.h" | |
8 | |
9 namespace mojo { | |
10 | |
11 // static | |
12 blink::WebUSBDevice::TransferDirection | |
13 TypeConverter<blink::WebUSBDevice::TransferDirection, | |
14 device::usb::TransferDirection>:: | |
15 Convert(const device::usb::TransferDirection& direction) { | |
16 switch (direction) { | |
17 case device::usb::TRANSFER_DIRECTION_IN: | |
18 return blink::WebUSBDevice::TransferDirection::In; | |
19 case device::usb::TRANSFER_DIRECTION_OUT: | |
20 return blink::WebUSBDevice::TransferDirection::Out; | |
21 default: | |
22 NOTREACHED(); | |
23 return blink::WebUSBDevice::TransferDirection::In; | |
24 } | |
25 } | |
26 | |
27 // static | |
28 device::usb::TransferDirection | |
29 TypeConverter<device::usb::TransferDirection, | |
30 blink::WebUSBDevice::TransferDirection>:: | |
31 Convert(const blink::WebUSBDevice::TransferDirection& direction) { | |
32 switch (direction) { | |
33 case blink::WebUSBDevice::TransferDirection::In: | |
34 return device::usb::TRANSFER_DIRECTION_IN; | |
35 case blink::WebUSBDevice::TransferDirection::Out: | |
36 return device::usb::TRANSFER_DIRECTION_OUT; | |
37 default: | |
38 NOTREACHED(); | |
39 return device::usb::TRANSFER_DIRECTION_IN; | |
40 } | |
41 } | |
42 | |
43 // static | |
44 device::usb::ControlTransferType | |
45 TypeConverter<device::usb::ControlTransferType, | |
46 blink::WebUSBDevice::RequestType>:: | |
47 Convert(const blink::WebUSBDevice::RequestType& direction) { | |
48 switch (direction) { | |
49 case blink::WebUSBDevice::RequestType::Standard: | |
50 return device::usb::CONTROL_TRANSFER_TYPE_STANDARD; | |
51 case blink::WebUSBDevice::RequestType::Class: | |
52 return device::usb::CONTROL_TRANSFER_TYPE_CLASS; | |
53 case blink::WebUSBDevice::RequestType::Vendor: | |
54 return device::usb::CONTROL_TRANSFER_TYPE_VENDOR; | |
55 default: | |
56 NOTREACHED(); | |
57 return device::usb::CONTROL_TRANSFER_TYPE_STANDARD; | |
58 } | |
59 } | |
60 | |
61 // static | |
62 device::usb::ControlTransferRecipient | |
63 TypeConverter<device::usb::ControlTransferRecipient, | |
64 blink::WebUSBDevice::RequestRecipient>:: | |
65 Convert(const blink::WebUSBDevice::RequestRecipient& direction) { | |
66 switch (direction) { | |
67 case blink::WebUSBDevice::RequestRecipient::Device: | |
68 return device::usb::CONTROL_TRANSFER_RECIPIENT_DEVICE; | |
69 case blink::WebUSBDevice::RequestRecipient::Interface: | |
70 return device::usb::CONTROL_TRANSFER_RECIPIENT_INTERFACE; | |
71 case blink::WebUSBDevice::RequestRecipient::Endpoint: | |
72 return device::usb::CONTROL_TRANSFER_RECIPIENT_ENDPOINT; | |
73 default: | |
Reilly Grant (use Gerrit)
2015/08/17 22:41:36
Missing case for CONTROL_TRANSFER_RECIPIENT_OTHER.
Ken Rockot(use gerrit already)
2015/08/17 22:50:07
Done. Somehow I neglected to make RequestRecipient
| |
74 NOTREACHED(); | |
75 return device::usb::CONTROL_TRANSFER_RECIPIENT_DEVICE; | |
76 } | |
77 } | |
78 | |
79 // static | |
80 device::usb::ControlTransferParamsPtr | |
81 TypeConverter<device::usb::ControlTransferParamsPtr, | |
82 blink::WebUSBDevice::ControlTransferParameters>:: | |
83 Convert(const blink::WebUSBDevice::ControlTransferParameters& parameters) { | |
84 device::usb::ControlTransferParamsPtr params = | |
85 device::usb::ControlTransferParams::New(); | |
86 params->type = | |
87 mojo::ConvertTo<device::usb::ControlTransferType>(parameters.type); | |
88 params->recipient = mojo::ConvertTo<device::usb::ControlTransferRecipient>( | |
89 parameters.recipient); | |
90 params->request = parameters.request; | |
91 params->value = parameters.value; | |
92 params->index = parameters.index; | |
93 return params.Pass(); | |
94 } | |
95 | |
96 // static | |
97 blink::WebUSBDeviceInfo::Endpoint::Type TypeConverter< | |
98 blink::WebUSBDeviceInfo::Endpoint::Type, | |
99 device::usb::EndpointType>::Convert(const device::usb::EndpointType& | |
100 endpoint_type) { | |
101 switch (endpoint_type) { | |
102 case device::usb::ENDPOINT_TYPE_BULK: | |
103 return blink::WebUSBDeviceInfo::Endpoint::Type::Bulk; | |
104 case device::usb::ENDPOINT_TYPE_INTERRUPT: | |
105 return blink::WebUSBDeviceInfo::Endpoint::Type::Interrupt; | |
106 case device::usb::ENDPOINT_TYPE_ISOCHRONOUS: | |
107 return blink::WebUSBDeviceInfo::Endpoint::Type::Isochronous; | |
108 default: | |
109 NOTREACHED(); | |
110 return blink::WebUSBDeviceInfo::Endpoint::Type::Bulk; | |
111 } | |
112 } | |
113 | |
114 // static | |
115 blink::WebUSBDeviceInfo::Endpoint | |
116 TypeConverter<blink::WebUSBDeviceInfo::Endpoint, device::usb::EndpointInfoPtr>:: | |
117 Convert(const device::usb::EndpointInfoPtr& info) { | |
118 blink::WebUSBDeviceInfo::Endpoint endpoint; | |
119 endpoint.endpointNumber = info->endpoint_number; | |
120 endpoint.direction = | |
121 mojo::ConvertTo<blink::WebUSBDevice::TransferDirection>(info->direction); | |
122 endpoint.type = | |
123 mojo::ConvertTo<blink::WebUSBDeviceInfo::Endpoint::Type>(info->type); | |
124 endpoint.packetSize = info->packet_size; | |
125 return endpoint; | |
126 } | |
127 | |
128 // static | |
129 blink::WebUSBDeviceInfo::AlternateInterface | |
130 TypeConverter<blink::WebUSBDeviceInfo::AlternateInterface, | |
131 device::usb::AlternateInterfaceInfoPtr>:: | |
132 Convert(const device::usb::AlternateInterfaceInfoPtr& info) { | |
133 blink::WebUSBDeviceInfo::AlternateInterface alternate; | |
134 alternate.alternateSetting = info->alternate_setting; | |
135 alternate.classCode = info->class_code; | |
136 alternate.subclassCode = info->subclass_code; | |
137 alternate.protocolCode = info->protocol_code; | |
138 if (!info->interface_name.is_null()) | |
139 alternate.interfaceName = blink::WebString::fromUTF8(info->interface_name); | |
140 alternate.endpoints = blink::WebVector<blink::WebUSBDeviceInfo::Endpoint>( | |
141 info->endpoints.size()); | |
142 for (size_t i = 0; i < info->endpoints.size(); ++i) { | |
143 alternate.endpoints[i] = | |
144 mojo::ConvertTo<blink::WebUSBDeviceInfo::Endpoint>(info->endpoints[i]); | |
145 } | |
146 return alternate; | |
147 } | |
148 | |
149 // static | |
150 blink::WebUSBDeviceInfo::Interface TypeConverter< | |
151 blink::WebUSBDeviceInfo::Interface, | |
152 device::usb::InterfaceInfoPtr>::Convert(const device::usb::InterfaceInfoPtr& | |
153 info) { | |
154 blink::WebUSBDeviceInfo::Interface interface; | |
155 interface.interfaceNumber = info->interface_number; | |
156 interface.alternates = | |
157 blink::WebVector<blink::WebUSBDeviceInfo::AlternateInterface>( | |
158 info->alternates.size()); | |
159 for (size_t i = 0; i < info->alternates.size(); ++i) { | |
160 interface.alternates[i] = | |
161 mojo::ConvertTo<blink::WebUSBDeviceInfo::AlternateInterface>( | |
162 info->alternates[i]); | |
163 } | |
164 return interface; | |
165 } | |
166 | |
167 // static | |
168 blink::WebUSBDeviceInfo::Configuration | |
169 TypeConverter<blink::WebUSBDeviceInfo::Configuration, | |
170 device::usb::ConfigurationInfoPtr>:: | |
171 Convert(const device::usb::ConfigurationInfoPtr& info) { | |
172 blink::WebUSBDeviceInfo::Configuration config; | |
173 config.configurationValue = info->configuration_value; | |
174 if (!info->configuration_name.is_null()) { | |
175 config.configurationName = | |
176 blink::WebString::fromUTF8(info->configuration_name); | |
177 } | |
178 config.interfaces = blink::WebVector<blink::WebUSBDeviceInfo::Interface>( | |
179 info->interfaces.size()); | |
180 for (size_t i = 0; i < info->interfaces.size(); ++i) { | |
181 config.interfaces[i] = mojo::ConvertTo<blink::WebUSBDeviceInfo::Interface>( | |
182 info->interfaces[i]); | |
183 } | |
184 return config; | |
185 } | |
186 | |
187 // static | |
188 blink::WebUSBDeviceInfo | |
189 TypeConverter<blink::WebUSBDeviceInfo, device::usb::DeviceInfoPtr>::Convert( | |
190 const device::usb::DeviceInfoPtr& info) { | |
191 blink::WebUSBDeviceInfo device; | |
192 device.guid = blink::WebString::fromUTF8(info->guid); | |
193 device.usbVersionMajor = info->usb_version_major; | |
194 device.usbVersionMinor = info->usb_version_minor; | |
195 device.usbVersionSubminor = info->usb_version_subminor; | |
196 device.deviceClass = info->class_code; | |
197 device.deviceSubclass = info->subclass_code; | |
198 device.deviceProtocol = info->protocol_code; | |
199 device.vendorID = info->vendor_id; | |
200 device.productID = info->product_id; | |
201 device.deviceVersionMajor = info->device_version_major; | |
202 device.deviceVersionMinor = info->device_version_minor; | |
203 device.deviceVersionSubminor = info->device_version_subminor; | |
204 if (!info->manufacturer_name.is_null()) { | |
205 device.manufacturerName = | |
206 blink::WebString::fromUTF8(info->manufacturer_name); | |
207 } | |
208 if (!info->product_name.is_null()) | |
209 device.productName = blink::WebString::fromUTF8(info->product_name); | |
210 if (!info->serial_number.is_null()) | |
211 device.serialNumber = blink::WebString::fromUTF8(info->serial_number); | |
212 device.configurations = | |
213 blink::WebVector<blink::WebUSBDeviceInfo::Configuration>( | |
214 info->configurations.size()); | |
215 for (size_t i = 0; i < info->configurations.size(); ++i) { | |
216 device.configurations[i] = | |
217 mojo::ConvertTo<blink::WebUSBDeviceInfo::Configuration>( | |
218 info->configurations[i]); | |
219 } | |
220 return device; | |
221 } | |
222 | |
223 // static | |
224 device::usb::DeviceFilterPtr | |
225 TypeConverter<device::usb::DeviceFilterPtr, blink::WebUSBDeviceFilter>::Convert( | |
226 const blink::WebUSBDeviceFilter& web_filter) { | |
227 device::usb::DeviceFilterPtr filter = device::usb::DeviceFilter::New(); | |
228 filter->has_vendor_id = web_filter.hasVendorID; | |
229 filter->vendor_id = web_filter.vendorID; | |
230 filter->has_product_id = web_filter.hasProductID; | |
231 filter->product_id = web_filter.productID; | |
232 filter->has_class_code = web_filter.hasClassCode; | |
233 filter->class_code = web_filter.classCode; | |
234 filter->has_subclass_code = web_filter.hasSubclassCode; | |
235 filter->subclass_code = web_filter.subclassCode; | |
236 filter->has_protocol_code = web_filter.hasProtocolCode; | |
237 filter->protocol_code = web_filter.protocolCode; | |
238 return filter.Pass(); | |
239 } | |
240 | |
241 // static | |
242 device::usb::EnumerationOptionsPtr | |
243 TypeConverter<device::usb::EnumerationOptionsPtr, | |
244 blink::WebUSBDeviceRequestOptions>:: | |
245 Convert(const blink::WebUSBDeviceRequestOptions& web_options) { | |
246 device::usb::EnumerationOptionsPtr options = | |
247 device::usb::EnumerationOptions::New(); | |
248 options->filters = mojo::Array<device::usb::DeviceFilterPtr>::New( | |
249 web_options.filters.size()); | |
250 for (size_t i = 0; i < web_options.filters.size(); ++i) { | |
251 options->filters[i] = | |
252 device::usb::DeviceFilter::From(web_options.filters[i]); | |
253 } | |
254 return options.Pass(); | |
255 } | |
256 | |
257 } // namespace mojo | |
OLD | NEW |