[email protected] | 91add6a | 2014-03-21 11:48:22 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | ad46f22 | 2012-12-11 07:18:15 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 91add6a | 2014-03-21 11:48:22 | [diff] [blame] | 5 | #ifndef EXTENSIONS_COMMON_PERMISSIONS_USB_DEVICE_PERMISSION_H_ |
| 6 | #define EXTENSIONS_COMMON_PERMISSIONS_USB_DEVICE_PERMISSION_H_ |
[email protected] | ad46f22 | 2012-12-11 07:18:15 | [diff] [blame] | 7 | |
avi | 2d124c0 | 2015-12-23 06:36:42 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
tbarzic | 2d0dff8d | 2016-10-27 22:09:00 | [diff] [blame] | 10 | #include <memory> |
| 11 | #include <set> |
Donna Wu | 72336f1 | 2019-01-23 06:25:11 | [diff] [blame] | 12 | #include <string> |
| 13 | #include <vector> |
tbarzic | 2d0dff8d | 2016-10-27 22:09:00 | [diff] [blame] | 14 | |
[email protected] | 793964a | 2013-10-08 00:47:19 | [diff] [blame] | 15 | #include "extensions/common/permissions/api_permission.h" |
[email protected] | 91add6a | 2014-03-21 11:48:22 | [diff] [blame] | 16 | #include "extensions/common/permissions/set_disjunction_permission.h" |
| 17 | #include "extensions/common/permissions/usb_device_permission_data.h" |
Donna Wu | 4dc9df3 | 2019-05-20 03:56:21 | [diff] [blame^] | 18 | #include "services/device/public/mojom/usb_device.mojom.h" |
[email protected] | ad46f22 | 2012-12-11 07:18:15 | [diff] [blame] | 19 | |
| 20 | namespace extensions { |
| 21 | |
tbarzic | 2d0dff8d | 2016-10-27 22:09:00 | [diff] [blame] | 22 | class Extension; |
| 23 | |
[email protected] | ad46f22 | 2012-12-11 07:18:15 | [diff] [blame] | 24 | class UsbDevicePermission |
| 25 | : public SetDisjunctionPermission<UsbDevicePermissionData, |
| 26 | UsbDevicePermission> { |
| 27 | public: |
| 28 | struct CheckParam : public APIPermission::CheckParam { |
tbarzic | 2d0dff8d | 2016-10-27 22:09:00 | [diff] [blame] | 29 | static std::unique_ptr<CheckParam> ForUsbDevice( |
| 30 | const Extension* extension, |
Donna Wu | 72336f1 | 2019-01-23 06:25:11 | [diff] [blame] | 31 | const device::mojom::UsbDeviceInfo& device_info); |
tbarzic | 2d0dff8d | 2016-10-27 22:09:00 | [diff] [blame] | 32 | // 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 Wu | 72336f1 | 2019-01-23 06:25:11 | [diff] [blame] | 52 | const device::mojom::UsbDeviceInfo& device_info, |
tbarzic | 2d0dff8d | 2016-10-27 22:09:00 | [diff] [blame] | 53 | 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 | |
avi | 2d124c0 | 2015-12-23 06:36:42 | [diff] [blame] | 65 | const uint16_t vendor_id; |
| 66 | const uint16_t product_id; |
tbarzic | 2d0dff8d | 2016-10-27 22:09:00 | [diff] [blame] | 67 | const std::unique_ptr<std::set<int>> interface_classes; |
[email protected] | 8e4e567 | 2013-06-05 07:52:17 | [diff] [blame] | 68 | const int interface_id; |
tbarzic | 2d0dff8d | 2016-10-27 22:09:00 | [diff] [blame] | 69 | const bool interface_class_allowed; |
| 70 | |
| 71 | private: |
| 72 | DISALLOW_COPY_AND_ASSIGN(CheckParam); |
[email protected] | ad46f22 | 2012-12-11 07:18:15 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | explicit UsbDevicePermission(const APIPermissionInfo* info); |
dcheng | 9168b2f | 2014-10-21 12:38:24 | [diff] [blame] | 76 | ~UsbDevicePermission() override; |
[email protected] | ad46f22 | 2012-12-11 07:18:15 | [diff] [blame] | 77 | |
ryoh | f207679 | 2016-02-15 02:14:19 | [diff] [blame] | 78 | // SetDisjunctionPermission overrides. |
| 79 | bool FromValue(const base::Value* value, |
| 80 | std::string* error, |
| 81 | std::vector<std::string>* unhandled_permissions) override; |
| 82 | |
[email protected] | ad46f22 | 2012-12-11 07:18:15 | [diff] [blame] | 83 | // APIPermission overrides |
sashab | 3dd05ac | 2014-12-12 02:46:12 | [diff] [blame] | 84 | PermissionIDSet GetPermissions() const override; |
[email protected] | ad46f22 | 2012-12-11 07:18:15 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | } // namespace extensions |
| 88 | |
[email protected] | 91add6a | 2014-03-21 11:48:22 | [diff] [blame] | 89 | #endif // EXTENSIONS_COMMON_PERMISSIONS_USB_DEVICE_PERMISSION_H_ |