Index: device/usb/webusb_descriptors.cc |
diff --git a/device/usb/webusb_descriptors.cc b/device/usb/webusb_descriptors.cc |
index de2309e1a10f98c2b678df3585c2db71789a7af5..bdd23a78b60779bdeb4f5f35b8aea192ea92d0a8 100644 |
--- a/device/usb/webusb_descriptors.cc |
+++ b/device/usb/webusb_descriptors.cc |
@@ -2,6 +2,8 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include "device/usb/webusb_descriptors.h" |
+ |
#include <stddef.h> |
#include <iterator> |
@@ -12,9 +14,9 @@ |
#include "base/bind.h" |
#include "base/callback.h" |
#include "base/logging.h" |
+#include "base/stl_util.h" |
#include "components/device_event_log/device_event_log.h" |
#include "device/usb/usb_device_handle.h" |
-#include "device/usb/webusb_descriptors.h" |
#include "net/base/io_buffer.h" |
using net::IOBufferWithSize; |
@@ -567,4 +569,26 @@ void ReadWebUsbDescriptors(scoped_refptr<UsbDeviceHandle> device_handle, |
base::Bind(&OnReadBosDescriptorHeader, device_handle, callback)); |
} |
+bool FindInWebUsbAllowedOrigins( |
+ const device::WebUsbAllowedOrigins* allowed_origins, |
+ const GURL& origin) { |
+ if (!allowed_origins) |
+ return false; |
+ |
+ if (ContainsValue(allowed_origins->origins, origin)) |
+ return true; |
+ |
+ for (const auto& config : allowed_origins->configurations) { |
+ if (ContainsValue(config.origins, origin)) |
+ return true; |
+ |
+ for (const auto& function : config.functions) { |
+ if (ContainsValue(function.origins, origin)) |
+ return true; |
+ } |
+ } |
+ |
+ return false; |
+} |
+ |
} // namespace device |