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
3 // found in the LICENSE file.
5 #include "extensions/common/permissions/usb_device_permission.h"
10 #include "base/logging.h"
11 #include "base/strings/string16.h"
12 #include "base/strings/string_util.h"
13 #include "base/strings/stringprintf.h"
14 #include "base/strings/utf_string_conversions.h"
15 #include "device/usb/usb_ids.h"
16 #include "extensions/common/permissions/permissions_info.h"
17 #include "grit/extensions_strings.h"
18 #include "ui/base/l10n/l10n_util.h"
20 namespace extensions
{
22 UsbDevicePermission::UsbDevicePermission(const APIPermissionInfo
* info
)
23 : SetDisjunctionPermission
<UsbDevicePermissionData
, UsbDevicePermission
>(
26 UsbDevicePermission::~UsbDevicePermission() {}
28 PermissionIDSet
UsbDevicePermission::GetPermissions() const {
31 std::set
<uint16
> unknown_product_vendors
;
32 bool found_unknown_vendor
= false;
34 for (const UsbDevicePermissionData
& data
: data_set_
) {
35 const char* vendor
= device::UsbIds::GetVendorName(data
.vendor_id());
38 device::UsbIds::GetProductName(data
.vendor_id(), data
.product_id());
40 base::string16 product_name_and_vendor
= l10n_util::GetStringFUTF16(
41 IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_PRODUCT_NAME_AND_VENDOR
,
42 base::UTF8ToUTF16(product
), base::UTF8ToUTF16(vendor
));
43 ids
.insert(APIPermission::kUsbDevice
, product_name_and_vendor
);
45 unknown_product_vendors
.insert(data
.vendor_id());
48 found_unknown_vendor
= true;
52 for (uint16 vendor_id
: unknown_product_vendors
) {
53 const char* vendor
= device::UsbIds::GetVendorName(vendor_id
);
55 ids
.insert(APIPermission::kUsbDeviceUnknownProduct
,
56 base::UTF8ToUTF16(vendor
));
59 if (found_unknown_vendor
)
60 ids
.insert(APIPermission::kUsbDeviceUnknownVendor
);
65 } // namespace extensions