OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 4 |
5 #include "chrome/common/extensions/permissions/usb_device_permission_data.h" | 5 #include "chrome/common/extensions/permissions/usb_device_permission_data.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 interface_id_(interface_id) { | 37 interface_id_(interface_id) { |
38 } | 38 } |
39 | 39 |
40 bool UsbDevicePermissionData::Check( | 40 bool UsbDevicePermissionData::Check( |
41 const APIPermission::CheckParam* param) const { | 41 const APIPermission::CheckParam* param) const { |
42 if (!param) | 42 if (!param) |
43 return false; | 43 return false; |
44 const UsbDevicePermission::CheckParam& specific_param = | 44 const UsbDevicePermission::CheckParam& specific_param = |
45 *static_cast<const UsbDevicePermission::CheckParam*>(param); | 45 *static_cast<const UsbDevicePermission::CheckParam*>(param); |
46 return vendor_id_ == specific_param.vendor_id && | 46 return vendor_id_ == specific_param.vendor_id && |
47 product_id_ == specific_param.product_id && | 47 product_id_ == specific_param.product_id && |
48 interface_id_ == specific_param.interface_id; | 48 (specific_param.interface_id == UNSPECIFIED_INTERFACE || |
| 49 interface_id_ == specific_param.interface_id); |
49 } | 50 } |
50 | 51 |
51 scoped_ptr<base::Value> UsbDevicePermissionData::ToValue() const { | 52 scoped_ptr<base::Value> UsbDevicePermissionData::ToValue() const { |
52 base::DictionaryValue* result = new base::DictionaryValue(); | 53 base::DictionaryValue* result = new base::DictionaryValue(); |
53 result->SetInteger(kVendorIdKey, vendor_id_); | 54 result->SetInteger(kVendorIdKey, vendor_id_); |
54 result->SetInteger(kProductIdKey, product_id_); | 55 result->SetInteger(kProductIdKey, product_id_); |
55 result->SetInteger(kInterfaceIdKey, interface_id_); | 56 result->SetInteger(kInterfaceIdKey, interface_id_); |
56 return scoped_ptr<base::Value>(result); | 57 return scoped_ptr<base::Value>(result); |
57 } | 58 } |
58 | 59 |
(...skipping 13 matching lines...) Expand all Loading... |
72 vendor_id_ = temp; | 73 vendor_id_ = temp; |
73 | 74 |
74 if (!dict_value->GetInteger(kProductIdKey, &temp)) | 75 if (!dict_value->GetInteger(kProductIdKey, &temp)) |
75 return false; | 76 return false; |
76 if (temp < 0 || temp > kuint16max) | 77 if (temp < 0 || temp > kuint16max) |
77 return false; | 78 return false; |
78 product_id_ = temp; | 79 product_id_ = temp; |
79 | 80 |
80 if (!dict_value->GetInteger(kInterfaceIdKey, &temp)) | 81 if (!dict_value->GetInteger(kInterfaceIdKey, &temp)) |
81 interface_id_ = ANY_INTERFACE; | 82 interface_id_ = ANY_INTERFACE; |
| 83 else if (temp < ANY_INTERFACE || temp > kuint8max) |
| 84 return false; |
82 else | 85 else |
83 interface_id_ = temp; | 86 interface_id_ = temp; |
84 | 87 |
85 return true; | 88 return true; |
86 } | 89 } |
87 | 90 |
88 bool UsbDevicePermissionData::operator<( | 91 bool UsbDevicePermissionData::operator<( |
89 const UsbDevicePermissionData& rhs) const { | 92 const UsbDevicePermissionData& rhs) const { |
90 if (vendor_id_ == rhs.vendor_id_) { | 93 if (vendor_id_ == rhs.vendor_id_) { |
91 if (product_id_ == rhs.product_id_) | 94 if (product_id_ == rhs.product_id_) |
92 return interface_id_ < rhs.interface_id_; | 95 return interface_id_ < rhs.interface_id_; |
93 | 96 |
94 return product_id_ < rhs.product_id_; | 97 return product_id_ < rhs.product_id_; |
95 } | 98 } |
96 return vendor_id_ < rhs.vendor_id_; | 99 return vendor_id_ < rhs.vendor_id_; |
97 } | 100 } |
98 | 101 |
99 bool UsbDevicePermissionData::operator==( | 102 bool UsbDevicePermissionData::operator==( |
100 const UsbDevicePermissionData& rhs) const { | 103 const UsbDevicePermissionData& rhs) const { |
101 return vendor_id_ == rhs.vendor_id_ && | 104 return vendor_id_ == rhs.vendor_id_ && |
102 product_id_ == rhs.product_id_ && | 105 product_id_ == rhs.product_id_ && |
103 interface_id_ == rhs.interface_id_; | 106 interface_id_ == rhs.interface_id_; |
104 } | 107 } |
105 | 108 |
106 } // namespace extensions | 109 } // namespace extensions |
OLD | NEW |