#include "content/browser/usb/web_usb_service_impl.h"
#include <memory>
#include <utility>
#include <vector>
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "content/browser/renderer_host/render_frame_host_impl.h"
#include "content/browser/service_worker/service_worker_usb_delegate_observer.h"
#include "content/browser/service_worker/service_worker_version.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/document_service.h"
#include "content/public/browser/isolated_context_util.h"
#include "content/public/common/content_client.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "services/device/public/mojom/usb_device.mojom.h"
#include "services/device/public/mojom/usb_enumeration_options.mojom.h"
#include "services/device/public/mojom/usb_manager_client.mojom.h"
#include "third_party/blink/public/common/features_generated.h"
namespace content {
namespace {
class DocumentHelper : public DocumentService<blink::mojom::WebUsbService> { … };
}
class WebUsbServiceImpl::UsbDeviceClient
: public device::mojom::UsbDeviceClient { … };
WebUsbServiceImpl::WebUsbServiceImpl(
RenderFrameHostImpl* render_frame_host,
base::WeakPtr<ServiceWorkerVersion> service_worker_version,
const url::Origin& origin)
: … { … }
WebUsbServiceImpl::~WebUsbServiceImpl() { … }
void WebUsbServiceImpl::Create(
RenderFrameHostImpl& render_frame_host,
mojo::PendingReceiver<blink::mojom::WebUsbService> pending_receiver) { … }
void WebUsbServiceImpl::Create(
base::WeakPtr<ServiceWorkerVersion> service_worker_version,
const url::Origin& origin,
mojo::PendingReceiver<blink::mojom::WebUsbService> pending_receiver) { … }
BrowserContext* WebUsbServiceImpl::GetBrowserContext() const { … }
std::vector<uint8_t> WebUsbServiceImpl::GetProtectedInterfaceClasses() const { … }
void WebUsbServiceImpl::GetDevices(GetDevicesCallback callback) { … }
void WebUsbServiceImpl::OnGetDevices(
GetDevicesCallback callback,
std::vector<device::mojom::UsbDeviceInfoPtr> device_info_list) { … }
void WebUsbServiceImpl::GetDevice(
const std::string& guid,
mojo::PendingReceiver<device::mojom::UsbDevice> device_receiver) { … }
void WebUsbServiceImpl::GetPermission(
blink::mojom::WebUsbRequestDeviceOptionsPtr options,
GetPermissionCallback callback) { … }
void WebUsbServiceImpl::ForgetDevice(const std::string& guid,
ForgetDeviceCallback callback) { … }
void WebUsbServiceImpl::SetClient(
mojo::PendingAssociatedRemote<device::mojom::UsbDeviceManagerClient>
client) { … }
void WebUsbServiceImpl::OnPermissionRevoked(const url::Origin& origin) { … }
void WebUsbServiceImpl::OnDeviceAdded(
const device::mojom::UsbDeviceInfo& device_info) { … }
void WebUsbServiceImpl::OnDeviceRemoved(
const device::mojom::UsbDeviceInfo& device_info) { … }
void WebUsbServiceImpl::OnDeviceManagerConnectionError() { … }
void WebUsbServiceImpl::IncrementConnectionCount() { … }
void WebUsbServiceImpl::DecrementConnectionCount() { … }
void WebUsbServiceImpl::RemoveDeviceClient(const UsbDeviceClient* client) { … }
}