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/utf_string_conversions.h"
13 #include "extensions/common/permissions/permissions_info.h"
14 #include "grit/extensions_strings.h"
15 #include "ui/base/l10n/l10n_util.h"
17 #if defined(ENABLE_EXTENSIONS)
18 #include "device/usb/usb_ids.h"
21 namespace extensions
{
23 UsbDevicePermission::UsbDevicePermission(
24 const APIPermissionInfo
* info
)
25 : SetDisjunctionPermission
<UsbDevicePermissionData
,
26 UsbDevicePermission
>(info
) {
29 UsbDevicePermission::~UsbDevicePermission() {
32 PermissionMessages
UsbDevicePermission::GetMessages() const {
33 DCHECK(HasMessages());
34 PermissionMessages result
;
36 #if defined(ENABLE_EXTENSIONS)
37 // //device/usb/usb.gyp:device_usb is not available when extensions are
39 for (std::set
<UsbDevicePermissionData
>::const_iterator i
=
40 data_set_
.begin(); i
!= data_set_
.end(); ++i
) {
41 const char* vendor
= device::UsbIds::GetVendorName(i
->vendor_id());
45 device::UsbIds::GetProductName(i
->vendor_id(), i
->product_id());
47 result
.push_back(PermissionMessage(
48 PermissionMessage::kUsbDevice
,
49 l10n_util::GetStringFUTF16(
50 IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE
,
51 base::ASCIIToUTF16(product
),
52 base::ASCIIToUTF16(vendor
))));
54 result
.push_back(PermissionMessage(
55 PermissionMessage::kUsbDevice
,
56 l10n_util::GetStringFUTF16(
57 IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_MISSING_PRODUCT
,
58 base::ASCIIToUTF16(vendor
))));
61 result
.push_back(PermissionMessage(
62 PermissionMessage::kUsbDevice
,
63 l10n_util::GetStringUTF16(
64 IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_MISSING_VENDOR
)));
69 #endif // defined(ENABLE_EXTENSIONS)
74 } // namespace extensions