| 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 "device/usb/webusb_descriptors.h" | 5 #include "device/usb/webusb_descriptors.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <iterator> | 9 #include <iterator> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 uint8_t vendor_code, | 287 uint8_t vendor_code, |
| 288 UsbTransferStatus status, | 288 UsbTransferStatus status, |
| 289 scoped_refptr<net::IOBuffer> buffer, | 289 scoped_refptr<net::IOBuffer> buffer, |
| 290 size_t length) { | 290 size_t length) { |
| 291 if (status != USB_TRANSFER_COMPLETED || length != 4) { | 291 if (status != USB_TRANSFER_COMPLETED || length != 4) { |
| 292 USB_LOG(EVENT) << "Failed to read WebUSB allowed origins header."; | 292 USB_LOG(EVENT) << "Failed to read WebUSB allowed origins header."; |
| 293 callback.Run(nullptr); | 293 callback.Run(nullptr); |
| 294 return; | 294 return; |
| 295 } | 295 } |
| 296 | 296 |
| 297 uint16_t new_length = buffer->data()[2] | (buffer->data()[3] << 8); | 297 const uint8_t* data = reinterpret_cast<uint8_t*>(buffer->data()); |
| 298 uint16_t new_length = data[2] | (data[3] << 8); |
| 298 scoped_refptr<IOBufferWithSize> new_buffer = new IOBufferWithSize(new_length); | 299 scoped_refptr<IOBufferWithSize> new_buffer = new IOBufferWithSize(new_length); |
| 299 device_handle->ControlTransfer( | 300 device_handle->ControlTransfer( |
| 300 USB_DIRECTION_INBOUND, UsbDeviceHandle::VENDOR, UsbDeviceHandle::DEVICE, | 301 USB_DIRECTION_INBOUND, UsbDeviceHandle::VENDOR, UsbDeviceHandle::DEVICE, |
| 301 vendor_code, 0, kGetAllowedOriginsRequest, new_buffer, new_buffer->size(), | 302 vendor_code, 0, kGetAllowedOriginsRequest, new_buffer, new_buffer->size(), |
| 302 kControlTransferTimeout, | 303 kControlTransferTimeout, |
| 303 base::Bind(&OnReadWebUsbAllowedOrigins, callback)); | 304 base::Bind(&OnReadWebUsbAllowedOrigins, callback)); |
| 304 } | 305 } |
| 305 | 306 |
| 306 void ReadWebUsbAllowedOrigins( | 307 void ReadWebUsbAllowedOrigins( |
| 307 scoped_refptr<UsbDeviceHandle> device_handle, | 308 scoped_refptr<UsbDeviceHandle> device_handle, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 const ReadWebUsbDescriptorsCallback& callback, | 345 const ReadWebUsbDescriptorsCallback& callback, |
| 345 UsbTransferStatus status, | 346 UsbTransferStatus status, |
| 346 scoped_refptr<net::IOBuffer> buffer, | 347 scoped_refptr<net::IOBuffer> buffer, |
| 347 size_t length) { | 348 size_t length) { |
| 348 if (status != USB_TRANSFER_COMPLETED || length != 5) { | 349 if (status != USB_TRANSFER_COMPLETED || length != 5) { |
| 349 USB_LOG(EVENT) << "Failed to read BOS descriptor header."; | 350 USB_LOG(EVENT) << "Failed to read BOS descriptor header."; |
| 350 callback.Run(nullptr, GURL()); | 351 callback.Run(nullptr, GURL()); |
| 351 return; | 352 return; |
| 352 } | 353 } |
| 353 | 354 |
| 354 uint16_t new_length = buffer->data()[2] | (buffer->data()[3] << 8); | 355 const uint8_t* data = reinterpret_cast<uint8_t*>(buffer->data()); |
| 356 uint16_t new_length = data[2] | (data[3] << 8); |
| 355 scoped_refptr<IOBufferWithSize> new_buffer = new IOBufferWithSize(new_length); | 357 scoped_refptr<IOBufferWithSize> new_buffer = new IOBufferWithSize(new_length); |
| 356 device_handle->ControlTransfer( | 358 device_handle->ControlTransfer( |
| 357 USB_DIRECTION_INBOUND, UsbDeviceHandle::STANDARD, UsbDeviceHandle::DEVICE, | 359 USB_DIRECTION_INBOUND, UsbDeviceHandle::STANDARD, UsbDeviceHandle::DEVICE, |
| 358 kGetDescriptorRequest, kBosDescriptorType << 8, 0, new_buffer, | 360 kGetDescriptorRequest, kBosDescriptorType << 8, 0, new_buffer, |
| 359 new_buffer->size(), kControlTransferTimeout, | 361 new_buffer->size(), kControlTransferTimeout, |
| 360 base::Bind(&OnReadBosDescriptor, device_handle, callback)); | 362 base::Bind(&OnReadBosDescriptor, device_handle, callback)); |
| 361 } | 363 } |
| 362 | 364 |
| 363 } // namespace | 365 } // namespace |
| 364 | 366 |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 for (const auto& function : config.functions) { | 590 for (const auto& function : config.functions) { |
| 589 if (ContainsValue(function.origins, origin)) | 591 if (ContainsValue(function.origins, origin)) |
| 590 return true; | 592 return true; |
| 591 } | 593 } |
| 592 } | 594 } |
| 593 | 595 |
| 594 return false; | 596 return false; |
| 595 } | 597 } |
| 596 | 598 |
| 597 } // namespace device | 599 } // namespace device |
| OLD | NEW |