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" |
| 6 |
5 #include <stddef.h> | 7 #include <stddef.h> |
6 | 8 |
7 #include <iterator> | 9 #include <iterator> |
8 #include <map> | 10 #include <map> |
9 #include <set> | 11 #include <set> |
10 | 12 |
11 #include "base/barrier_closure.h" | 13 #include "base/barrier_closure.h" |
12 #include "base/bind.h" | 14 #include "base/bind.h" |
13 #include "base/callback.h" | 15 #include "base/callback.h" |
14 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/stl_util.h" |
15 #include "components/device_event_log/device_event_log.h" | 18 #include "components/device_event_log/device_event_log.h" |
16 #include "device/usb/usb_device_handle.h" | 19 #include "device/usb/usb_device_handle.h" |
17 #include "device/usb/webusb_descriptors.h" | |
18 #include "net/base/io_buffer.h" | 20 #include "net/base/io_buffer.h" |
19 | 21 |
20 using net::IOBufferWithSize; | 22 using net::IOBufferWithSize; |
21 | 23 |
22 namespace device { | 24 namespace device { |
23 | 25 |
24 namespace { | 26 namespace { |
25 | 27 |
26 // These constants are defined by the Universal Serial Device 3.0 Specification | 28 // These constants are defined by the Universal Serial Device 3.0 Specification |
27 // Revision 1.0. | 29 // Revision 1.0. |
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 void ReadWebUsbDescriptors(scoped_refptr<UsbDeviceHandle> device_handle, | 562 void ReadWebUsbDescriptors(scoped_refptr<UsbDeviceHandle> device_handle, |
561 const ReadWebUsbDescriptorsCallback& callback) { | 563 const ReadWebUsbDescriptorsCallback& callback) { |
562 scoped_refptr<IOBufferWithSize> buffer = new IOBufferWithSize(5); | 564 scoped_refptr<IOBufferWithSize> buffer = new IOBufferWithSize(5); |
563 device_handle->ControlTransfer( | 565 device_handle->ControlTransfer( |
564 USB_DIRECTION_INBOUND, UsbDeviceHandle::STANDARD, UsbDeviceHandle::DEVICE, | 566 USB_DIRECTION_INBOUND, UsbDeviceHandle::STANDARD, UsbDeviceHandle::DEVICE, |
565 kGetDescriptorRequest, kBosDescriptorType << 8, 0, buffer, buffer->size(), | 567 kGetDescriptorRequest, kBosDescriptorType << 8, 0, buffer, buffer->size(), |
566 kControlTransferTimeout, | 568 kControlTransferTimeout, |
567 base::Bind(&OnReadBosDescriptorHeader, device_handle, callback)); | 569 base::Bind(&OnReadBosDescriptorHeader, device_handle, callback)); |
568 } | 570 } |
569 | 571 |
| 572 bool FindInWebUsbAllowedOrigins( |
| 573 const device::WebUsbAllowedOrigins* allowed_origins, |
| 574 const GURL& origin) { |
| 575 if (!allowed_origins) |
| 576 return false; |
| 577 |
| 578 if (ContainsValue(allowed_origins->origins, origin)) |
| 579 return true; |
| 580 |
| 581 for (const auto& config : allowed_origins->configurations) { |
| 582 if (ContainsValue(config.origins, origin)) |
| 583 return true; |
| 584 |
| 585 for (const auto& function : config.functions) { |
| 586 if (ContainsValue(function.origins, origin)) |
| 587 return true; |
| 588 } |
| 589 } |
| 590 |
| 591 return false; |
| 592 } |
| 593 |
570 } // namespace device | 594 } // namespace device |
OLD | NEW |