summaryrefslogtreecommitdiffstats
path: root/device
diff options
context:
space:
mode:
authorjuncai <juncai@chromium.org>2016-03-25 13:40:35 -0700
committerCommit bot <commit-bot@chromium.org>2016-03-25 20:42:19 +0000
commit4cbad6ed5522e60cda2aa728c08e3aa80545e360 (patch)
treee6b54b14c22d141fc37623be9bfccdb4543e7bf4 /device
parentcf4acce2eb7d4b7fc83a444af5d0a038151a1fa7 (diff)
downloadchromium_src-4cbad6ed5522e60cda2aa728c08e3aa80545e360.zip
chromium_src-4cbad6ed5522e60cda2aa728c08e3aa80545e360.tar.gz
chromium_src-4cbad6ed5522e60cda2aa728c08e3aa80545e360.tar.bz2
WebUsb Android chooser UI
This patch added code to display a chooser UI on Android for WebUsb. BUG=591735 Review URL: https://codereview.chromium.org/1739523002 Cr-Commit-Position: refs/heads/master@{#383351}
Diffstat (limited to 'device')
-rw-r--r--device/usb/webusb_descriptors.cc26
-rw-r--r--device/usb/webusb_descriptors.h5
2 files changed, 30 insertions, 1 deletions
diff --git a/device/usb/webusb_descriptors.cc b/device/usb/webusb_descriptors.cc
index de2309e..bdd23a7 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
diff --git a/device/usb/webusb_descriptors.h b/device/usb/webusb_descriptors.h
index 516adfc..a13440c 100644
--- a/device/usb/webusb_descriptors.h
+++ b/device/usb/webusb_descriptors.h
@@ -67,6 +67,11 @@ void ReadWebUsbDescriptors(
const base::Callback<void(scoped_ptr<WebUsbAllowedOrigins> allowed_origins,
const GURL& landing_page)>& callback);
+// Check if the origin is allowed.
+bool FindInWebUsbAllowedOrigins(
+ const device::WebUsbAllowedOrigins* allowed_origins,
+ const GURL& origin);
+
} // device
#endif // DEVICE_USB_WEBUSB_DESCRIPTORS_H_