Skia roll 790ffe3:0b36e6b
[chromium-blink-merge.git] / extensions / common / permissions / usb_device_permission.cc
blobcd035d42061bbdf51e524ec889b13feb367b5480
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"
7 #include <set>
8 #include <string>
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"
19 #endif
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
38 // disabled.
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());
43 if (vendor) {
44 const char* product =
45 device::UsbIds::GetProductName(i->vendor_id(), i->product_id());
46 if (product) {
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))));
53 } else {
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))));
60 } else {
61 result.push_back(PermissionMessage(
62 PermissionMessage::kUsbDevice,
63 l10n_util::GetStringUTF16(
64 IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_MISSING_VENDOR)));
67 #else
68 NOTREACHED();
69 #endif // defined(ENABLE_EXTENSIONS)
71 return result;
74 } // namespace extensions