diff options
author | treib <treib@chromium.org> | 2015-08-21 02:53:46 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-21 09:54:24 +0000 |
commit | 7a1bde6edae7b421b1115cb6c792189d2d846963 (patch) | |
tree | 9ba9d0f983e04375281f0de56345f8d3e491b71b /extensions/common/permissions | |
parent | 4127e216b0a532ee627897cf86ca8294e94537aa (diff) | |
download | chromium_src-7a1bde6edae7b421b1115cb6c792189d2d846963.zip chromium_src-7a1bde6edae7b421b1115cb6c792189d2d846963.tar.gz chromium_src-7a1bde6edae7b421b1115cb6c792189d2d846963.tar.bz2 |
Make USB permissions work in the new permission message system
Skipping presubmit because of renamed histogram entry. Also TBRing the histograms.xml change.
NOPRESUBMIT=true
TBR=asvitkine@chromium.org
BUG=522842
Review URL: https://codereview.chromium.org/1300353002
Cr-Commit-Position: refs/heads/master@{#344729}
Diffstat (limited to 'extensions/common/permissions')
4 files changed, 50 insertions, 71 deletions
diff --git a/extensions/common/permissions/api_permission.h b/extensions/common/permissions/api_permission.h index 01e075e..b2c6d46 100644 --- a/extensions/common/permissions/api_permission.h +++ b/extensions/common/permissions/api_permission.h @@ -234,7 +234,7 @@ class APIPermission { kSocketAnyHost, kSocketDomainHosts, kSocketSpecificHosts, - kUsbDeviceList, + kDeleted_UsbDeviceList, kUsbDeviceUnknownProduct, kUsbDeviceUnknownVendor, kUsersPrivate, diff --git a/extensions/common/permissions/api_permission_set.cc b/extensions/common/permissions/api_permission_set.cc index 82d2faa..74a3e66 100644 --- a/extensions/common/permissions/api_permission_set.cc +++ b/extensions/common/permissions/api_permission_set.cc @@ -254,6 +254,26 @@ bool PermissionIDSet::ContainsAllIDs( }); } +bool PermissionIDSet::ContainsAnyID( + const std::set<APIPermission::ID>& permission_ids) const { + for (APIPermission::ID id : permission_ids) { + if (ContainsID(id)) + return true; + } + return false; +} + +PermissionIDSet PermissionIDSet::GetAllPermissionsWithID( + APIPermission::ID permission_id) const { + PermissionIDSet subset; + auto it = permissions_.lower_bound(PermissionID(permission_id)); + while (it != permissions_.end() && it->id() == permission_id) { + subset.permissions_.insert(*it); + ++it; + } + return subset; +} + PermissionIDSet PermissionIDSet::GetAllPermissionsWithIDs( const std::set<APIPermission::ID>& permission_ids) const { PermissionIDSet subset; diff --git a/extensions/common/permissions/api_permission_set.h b/extensions/common/permissions/api_permission_set.h index 476ad13..43b97ec 100644 --- a/extensions/common/permissions/api_permission_set.h +++ b/extensions/common/permissions/api_permission_set.h @@ -136,6 +136,13 @@ class PermissionIDSet { // Check if the set contains permissions with all the given IDs. bool ContainsAllIDs(const std::set<APIPermission::ID>& permission_ids) const; + // Check if the set contains any permission with one of the given IDs. + bool ContainsAnyID(const std::set<APIPermission::ID>& permission_ids) const; + + // Returns all the permissions in this set with the given ID. + PermissionIDSet GetAllPermissionsWithID( + APIPermission::ID permission_id) const; + // Returns all the permissions in this set with one of the given IDs. PermissionIDSet GetAllPermissionsWithIDs( const std::set<APIPermission::ID>& permission_ids) const; diff --git a/extensions/common/permissions/usb_device_permission.cc b/extensions/common/permissions/usb_device_permission.cc index bedf6b0..a79d47f 100644 --- a/extensions/common/permissions/usb_device_permission.cc +++ b/extensions/common/permissions/usb_device_permission.cc @@ -19,19 +19,19 @@ namespace extensions { -namespace { +UsbDevicePermission::UsbDevicePermission(const APIPermissionInfo* info) + : SetDisjunctionPermission<UsbDevicePermissionData, UsbDevicePermission>( + info) {} -// Adds the permissions from the |data_set| to |ids|. -void AddPermissionsToLists(const std::set<UsbDevicePermissionData>& data_set, - PermissionIDSet* ids) { - // TODO(sashab): Once GetMessages() is deprecated, move this logic back into - // GetPermissions(). - // TODO(sashab, reillyg): Once GetMessages() is deprecated, rework the - // permission message logic for USB devices to generate more meaningful - // messages and better fit the current rules system. - if (data_set.size() == 1) { - const UsbDevicePermissionData& data = *data_set.begin(); +UsbDevicePermission::~UsbDevicePermission() {} +PermissionIDSet UsbDevicePermission::GetPermissions() const { + PermissionIDSet ids; + + std::set<uint16> unknown_product_vendors; + bool found_unknown_vendor = false; + + for (const UsbDevicePermissionData& data : data_set_) { const char* vendor = device::UsbIds::GetVendorName(data.vendor_id()); if (vendor) { const char* product = @@ -40,73 +40,25 @@ void AddPermissionsToLists(const std::set<UsbDevicePermissionData>& data_set, base::string16 product_name_and_vendor = l10n_util::GetStringFUTF16( IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_PRODUCT_NAME_AND_VENDOR, base::UTF8ToUTF16(product), base::UTF8ToUTF16(vendor)); - - ids->insert(APIPermission::kUsbDevice, product_name_and_vendor); + ids.insert(APIPermission::kUsbDevice, product_name_and_vendor); } else { - ids->insert(APIPermission::kUsbDeviceUnknownProduct, - base::UTF8ToUTF16(vendor)); + unknown_product_vendors.insert(data.vendor_id()); } } else { - ids->insert(APIPermission::kUsbDeviceUnknownVendor); - } - } else if (data_set.size() > 1) { - std::vector<base::string16> details; - std::set<uint16> unknown_product_vendors; - bool found_unknown_vendor = false; - - for (const UsbDevicePermissionData& data : data_set) { - const char* vendor = device::UsbIds::GetVendorName(data.vendor_id()); - if (vendor) { - const char* product = - device::UsbIds::GetProductName(data.vendor_id(), data.product_id()); - if (product) { - base::string16 product_name_and_vendor = l10n_util::GetStringFUTF16( - IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_PRODUCT_NAME_AND_VENDOR, - base::UTF8ToUTF16(product), base::UTF8ToUTF16(vendor)); - details.push_back(l10n_util::GetStringFUTF16( - IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_LIST_ITEM, - product_name_and_vendor)); - } else { - unknown_product_vendors.insert(data.vendor_id()); - } - } else { - found_unknown_vendor = true; - } - } - - // List generic "devices from this vendor" entries after specific devices. - for (const uint16& vendor_id : unknown_product_vendors) { - const char* vendor = device::UsbIds::GetVendorName(vendor_id); - DCHECK(vendor); - details.push_back(l10n_util::GetStringFUTF16( - IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_LIST_ITEM_UNKNOWN_PRODUCT, - base::UTF8ToUTF16(vendor))); + found_unknown_vendor = true; } - - // Display the catch all "device from an unknown vendor" last. - if (found_unknown_vendor) { - details.push_back(l10n_util::GetStringUTF16( - IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_LIST_ITEM_UNKNOWN_VENDOR)); - } - - for (const auto& detail : details) - ids->insert(APIPermission::kUsbDeviceList, detail); } -} - -} // namespace -UsbDevicePermission::UsbDevicePermission(const APIPermissionInfo* info) - : SetDisjunctionPermission<UsbDevicePermissionData, UsbDevicePermission>( - info) { -} + for (uint16 vendor_id : unknown_product_vendors) { + const char* vendor = device::UsbIds::GetVendorName(vendor_id); + DCHECK(vendor); + ids.insert(APIPermission::kUsbDeviceUnknownProduct, + base::UTF8ToUTF16(vendor)); + } -UsbDevicePermission::~UsbDevicePermission() { -} + if (found_unknown_vendor) + ids.insert(APIPermission::kUsbDeviceUnknownVendor); -PermissionIDSet UsbDevicePermission::GetPermissions() const { - PermissionIDSet ids; - AddPermissionsToLists(data_set_, &ids); return ids; } |