blob: 47b685ce5bb78dabda7a7230937e135abcf6f2c4 [file] [log] [blame]
[email protected]91add6a2014-03-21 11:48:221// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]ad46f222012-12-11 07:18:152// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]91add6a2014-03-21 11:48:225#ifndef EXTENSIONS_COMMON_PERMISSIONS_USB_DEVICE_PERMISSION_H_
6#define EXTENSIONS_COMMON_PERMISSIONS_USB_DEVICE_PERMISSION_H_
[email protected]ad46f222012-12-11 07:18:157
avi2d124c02015-12-23 06:36:428#include <stdint.h>
9
tbarzic2d0dff8d2016-10-27 22:09:0010#include <memory>
11#include <set>
Donna Wu72336f12019-01-23 06:25:1112#include <string>
13#include <vector>
tbarzic2d0dff8d2016-10-27 22:09:0014
[email protected]793964a2013-10-08 00:47:1915#include "extensions/common/permissions/api_permission.h"
[email protected]91add6a2014-03-21 11:48:2216#include "extensions/common/permissions/set_disjunction_permission.h"
17#include "extensions/common/permissions/usb_device_permission_data.h"
Donna Wu4dc9df32019-05-20 03:56:2118#include "services/device/public/mojom/usb_device.mojom.h"
[email protected]ad46f222012-12-11 07:18:1519
20namespace extensions {
21
tbarzic2d0dff8d2016-10-27 22:09:0022class Extension;
23
[email protected]ad46f222012-12-11 07:18:1524class UsbDevicePermission
25 : public SetDisjunctionPermission<UsbDevicePermissionData,
26 UsbDevicePermission> {
27 public:
28 struct CheckParam : public APIPermission::CheckParam {
tbarzic2d0dff8d2016-10-27 22:09:0029 static std::unique_ptr<CheckParam> ForUsbDevice(
30 const Extension* extension,
Donna Wu72336f12019-01-23 06:25:1131 const device::mojom::UsbDeviceInfo& device_info);
tbarzic2d0dff8d2016-10-27 22:09:0032 // Creates check param that only checks vendor, product and interface ID
33 // permission properties. It will accept all interfaceClass properties. For
34 // example, created param would always accept {"intefaceClass": 3}
35 // permission, and it would accept {"vendorId": 2, "interfaceClass": 4} iff
36 // |vendor_id| is 2.
37 // Created check param failing means there are no permissions allowing
38 // access to the USB device. On the other hand, created check param passing
39 // does not necessarily mean there is a permission allowing access to the
40 // USB device - one should recheck the permission when complete USB device
41 // info is known.
42 // This is useful when trying to discard devices that do not match any
43 // usbDevice permission when complete USB device info is not known, without
44 // having to fetch available USB devices.
45 static std::unique_ptr<CheckParam> ForDeviceWithAnyInterfaceClass(
46 const Extension* extension,
47 uint16_t vendor_id,
48 uint16_t product_id,
49 int interface_id);
50 static std::unique_ptr<CheckParam> ForUsbDeviceAndInterface(
51 const Extension* extension,
Donna Wu72336f12019-01-23 06:25:1152 const device::mojom::UsbDeviceInfo& device_info,
tbarzic2d0dff8d2016-10-27 22:09:0053 int interface_id);
54 static std::unique_ptr<CheckParam> ForHidDevice(const Extension* extension,
55 uint16_t vendor_id,
56 uint16_t product_id);
57
58 CheckParam(const Extension* extension,
59 uint16_t vendor_id,
60 uint16_t product_id,
61 std::unique_ptr<std::set<int>> interface_classes,
62 int interface_id);
63 ~CheckParam();
64
avi2d124c02015-12-23 06:36:4265 const uint16_t vendor_id;
66 const uint16_t product_id;
tbarzic2d0dff8d2016-10-27 22:09:0067 const std::unique_ptr<std::set<int>> interface_classes;
[email protected]8e4e5672013-06-05 07:52:1768 const int interface_id;
tbarzic2d0dff8d2016-10-27 22:09:0069 const bool interface_class_allowed;
70
71 private:
72 DISALLOW_COPY_AND_ASSIGN(CheckParam);
[email protected]ad46f222012-12-11 07:18:1573 };
74
75 explicit UsbDevicePermission(const APIPermissionInfo* info);
dcheng9168b2f2014-10-21 12:38:2476 ~UsbDevicePermission() override;
[email protected]ad46f222012-12-11 07:18:1577
ryohf2076792016-02-15 02:14:1978 // SetDisjunctionPermission overrides.
79 bool FromValue(const base::Value* value,
80 std::string* error,
81 std::vector<std::string>* unhandled_permissions) override;
82
[email protected]ad46f222012-12-11 07:18:1583 // APIPermission overrides
sashab3dd05ac2014-12-12 02:46:1284 PermissionIDSet GetPermissions() const override;
[email protected]ad46f222012-12-11 07:18:1585};
86
87} // namespace extensions
88
[email protected]91add6a2014-03-21 11:48:2289#endif // EXTENSIONS_COMMON_PERMISSIONS_USB_DEVICE_PERMISSION_H_