#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "services/device/usb/webusb_descriptors.h"
#include <limits>
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/logging.h"
#include "base/memory/ref_counted_memory.h"
#include "components/device_event_log/device_event_log.h"
#include "services/device/usb/usb_device_handle.h"
#include "url/gurl.h"
namespace device {
UsbControlTransferRecipient;
UsbControlTransferType;
UsbTransferDirection;
UsbTransferStatus;
namespace {
const uint8_t kGetDescriptorRequest = …;
const uint8_t kBosDescriptorType = …;
const uint8_t kDeviceCapabilityDescriptorType = …;
const uint8_t kPlatformDevCapabilityType = …;
const uint8_t kGetUrlRequest = …;
const uint8_t kWebUsbCapabilityUUID[16] = …;
const size_t kMaxControlTransferLength = …;
const int kControlTransferTimeoutMs = …;
ReadCompatabilityDescriptorCallback;
ReadLandingPageCallback;
void OnReadLandingPage(uint8_t landing_page_id,
ReadLandingPageCallback callback,
UsbTransferStatus status,
scoped_refptr<base::RefCountedBytes> buffer,
size_t length) { … }
void OnReadBosDescriptor(scoped_refptr<UsbDeviceHandle> device_handle,
ReadCompatabilityDescriptorCallback callback,
UsbTransferStatus status,
scoped_refptr<base::RefCountedBytes> buffer,
size_t length) { … }
void OnReadBosDescriptorHeader(scoped_refptr<UsbDeviceHandle> device_handle,
ReadCompatabilityDescriptorCallback callback,
UsbTransferStatus status,
scoped_refptr<base::RefCountedBytes> buffer,
size_t length) { … }
void OnReadWebUsbCapabilityDescriptor(
scoped_refptr<UsbDeviceHandle> device_handle,
ReadLandingPageCallback callback,
const std::optional<WebUsbPlatformCapabilityDescriptor>& descriptor) { … }
}
WebUsbPlatformCapabilityDescriptor::WebUsbPlatformCapabilityDescriptor()
: … { … }
WebUsbPlatformCapabilityDescriptor::~WebUsbPlatformCapabilityDescriptor() =
default;
bool WebUsbPlatformCapabilityDescriptor::ParseFromBosDescriptor(
base::span<const uint8_t> bytes) { … }
bool ParseWebUsbUrlDescriptor(base::span<const uint8_t> bytes, GURL* output) { … }
void ReadWebUsbLandingPage(uint8_t vendor_code,
uint8_t landing_page_id,
scoped_refptr<UsbDeviceHandle> device_handle,
ReadLandingPageCallback callback) { … }
void ReadWebUsbCapabilityDescriptor(
scoped_refptr<UsbDeviceHandle> device_handle,
ReadCompatabilityDescriptorCallback callback) { … }
void ReadWebUsbDescriptors(scoped_refptr<UsbDeviceHandle> device_handle,
ReadLandingPageCallback callback) { … }
}