blob: 5fd2e6dc4731da6b6df29a8ac8bb5de5b5d28c75 [file] [log] [blame]
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stdint.h>
#include "base/memory/weak_ptr.h"
#include "device/usb/mojo/permission_provider.h"
namespace content {
class RenderFrameHost;
class GURL;
class UsbChooserContext;
// This implementation of the permission provider interface enforces the rules
// of the WebUSB permission model. Devices are checked for WebUSB descriptors
// granting access to the render frame's current origin as well as permission
// granted by the user through a device chooser UI.
class WebUSBPermissionProvider : public device::usb::PermissionProvider {
static bool HasDevicePermission(
UsbChooserContext* chooser_context,
const GURL& requesting_origin,
const GURL& embedding_origin,
scoped_refptr<const device::UsbDevice> device);
explicit WebUSBPermissionProvider(
content::RenderFrameHost* render_frame_host);
~WebUSBPermissionProvider() override;
base::WeakPtr<PermissionProvider> GetWeakPtr();
// device::usb::PermissionProvider implementation.
bool HasDevicePermission(
scoped_refptr<const device::UsbDevice> device) const override;
void IncrementConnectionCount() override;
void DecrementConnectionCount() override;
content::RenderFrameHost* const render_frame_host_;
base::WeakPtrFactory<PermissionProvider> weak_factory_;