| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 #ifndef EXTENSIONS_COMMON_PERMISSIONS_USB_DEVICE_PERMISSION_DATA_H_ | 4 #ifndef EXTENSIONS_COMMON_PERMISSIONS_USB_DEVICE_PERMISSION_DATA_H_ |
| 5 #define EXTENSIONS_COMMON_PERMISSIONS_USB_DEVICE_PERMISSION_DATA_H_ | 5 #define EXTENSIONS_COMMON_PERMISSIONS_USB_DEVICE_PERMISSION_DATA_H_ |
| 6 | 6 |
| 7 #include <stdint.h> | |
| 8 | |
| 9 #include <memory> | 7 #include <memory> |
| 10 #include <string> | 8 #include <string> |
| 11 | 9 |
| 12 #include "extensions/common/permissions/api_permission.h" | 10 #include "extensions/common/permissions/api_permission.h" |
| 13 | 11 |
| 14 namespace base { | 12 namespace base { |
| 15 | 13 |
| 16 class Value; | 14 class Value; |
| 17 | 15 |
| 18 } // namespace base | 16 } // namespace base |
| 19 | 17 |
| 18 namespace device { |
| 19 class UsbDevice; |
| 20 } |
| 21 |
| 20 namespace extensions { | 22 namespace extensions { |
| 21 | 23 |
| 22 // A pattern that can be used to match a USB device permission. | 24 // A pattern that can be used to match a USB device permission. |
| 23 // Should be of the format: vendorId:productId, where both vendorId and | 25 // Should be of the format: vendorId:productId, where both vendorId and |
| 24 // productId are decimal strings representing uint16_t values. | 26 // productId are decimal strings representing uint16_t values. |
| 25 class UsbDevicePermissionData { | 27 class UsbDevicePermissionData { |
| 26 public: | 28 public: |
| 27 enum SpecialInterfaces { | 29 enum SpecialValues { |
| 28 // A special interface id for stating permissions for an entire USB device, | 30 // A special interface id for stating permissions for an entire USB device, |
| 29 // no specific interface. This value must match value of Rule::ANY_INTERFACE | 31 // no specific interface. This value must match value of Rule::ANY_INTERFACE |
| 30 // from ChromeOS permission_broker project. | 32 // from ChromeOS permission_broker project. |
| 31 ANY_INTERFACE = -1, | 33 SPECIAL_VALUE_ANY = -1, |
| 32 | 34 |
| 33 // A special interface id for |Check| to indicate that interface field is | 35 // A special interface id for |Check| to indicate that interface field is |
| 34 // not to be checked. Not used in manifest file. | 36 // not to be checked. Not used in manifest file. |
| 35 UNSPECIFIED_INTERFACE = -2 | 37 SPECIAL_VALUE_UNSPECIFIED = -2 |
| 36 }; | 38 }; |
| 37 | 39 |
| 38 UsbDevicePermissionData(); | 40 UsbDevicePermissionData(); |
| 39 UsbDevicePermissionData(uint16_t vendor_id, | 41 UsbDevicePermissionData(int vendor_id, |
| 40 uint16_t product_id, | 42 int product_id, |
| 41 int interface_id); | 43 int interface_id, |
| 44 int interface_class); |
| 42 | 45 |
| 43 // Check if |param| (which must be a UsbDevicePermissionData::CheckParam) | 46 // Check if |param| (which must be a UsbDevicePermissionData::CheckParam) |
| 44 // matches the vendor and product IDs associated with |this|. | 47 // matches the vendor and product IDs associated with |this|. |
| 45 bool Check(const APIPermission::CheckParam* param) const; | 48 bool Check(const APIPermission::CheckParam* param) const; |
| 46 | 49 |
| 47 // Convert |this| into a base::Value. | 50 // Convert |this| into a base::Value. |
| 48 std::unique_ptr<base::Value> ToValue() const; | 51 std::unique_ptr<base::Value> ToValue() const; |
| 49 | 52 |
| 50 // Populate |this| from a base::Value. | 53 // Populate |this| from a base::Value. |
| 51 bool FromValue(const base::Value* value); | 54 bool FromValue(const base::Value* value); |
| 52 | 55 |
| 53 bool operator<(const UsbDevicePermissionData& rhs) const; | 56 bool operator<(const UsbDevicePermissionData& rhs) const; |
| 54 bool operator==(const UsbDevicePermissionData& rhs) const; | 57 bool operator==(const UsbDevicePermissionData& rhs) const; |
| 55 | 58 |
| 56 const uint16_t& vendor_id() const { return vendor_id_; } | 59 const int& vendor_id() const { return vendor_id_; } |
| 57 const uint16_t& product_id() const { return product_id_; } | 60 const int& product_id() const { return product_id_; } |
| 61 const int& interface_class() const { return interface_class_; } |
| 58 | 62 |
| 59 // These accessors are provided for IPC_STRUCT_TRAITS_MEMBER. Please | 63 // These accessors are provided for IPC_STRUCT_TRAITS_MEMBER. Please |
| 60 // think twice before using them for anything else. | 64 // think twice before using them for anything else. |
| 61 uint16_t& vendor_id() { return vendor_id_; } | 65 int& vendor_id() { return vendor_id_; } |
| 62 uint16_t& product_id() { return product_id_; } | 66 int& product_id() { return product_id_; } |
| 67 int& interface_class() { return interface_class_; } |
| 63 | 68 |
| 64 private: | 69 private: |
| 65 uint16_t vendor_id_; | 70 int vendor_id_{SPECIAL_VALUE_ANY}; |
| 66 uint16_t product_id_; | 71 int product_id_{SPECIAL_VALUE_ANY}; |
| 67 int interface_id_; | 72 // Not useful anymore. Kept around not to trigger permission change warnings |
| 73 // for existing apps. |
| 74 int interface_id_{SPECIAL_VALUE_ANY}; |
| 75 int interface_class_{SPECIAL_VALUE_ANY}; |
| 68 }; | 76 }; |
| 69 | 77 |
| 70 } // namespace extensions | 78 } // namespace extensions |
| 71 | 79 |
| 72 #endif // EXTENSIONS_COMMON_PERMISSIONS_USB_DEVICE_PERMISSION_DATA_H_ | 80 #endif // EXTENSIONS_COMMON_PERMISSIONS_USB_DEVICE_PERMISSION_DATA_H_ |
| OLD | NEW |