Upstream version 5.34.98.0
[platform/framework/web/crosswalk.git] / src / chrome / common / extensions / permissions / bluetooth_permission.cc
1 // Copyright 2013 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.
4
5 #include "chrome/common/extensions/permissions/bluetooth_permission.h"
6
7 #include <string>
8
9 #include "base/logging.h"
10 #include "base/strings/string16.h"
11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/common/extensions/permissions/bluetooth_permission_data.h"
14 #include "extensions/common/permissions/permissions_info.h"
15 #include "grit/generated_resources.h"
16 #include "ui/base/l10n/l10n_util.h"
17
18 namespace extensions {
19
20 BluetoothPermission::BluetoothPermission(const APIPermissionInfo* info)
21   : SetDisjunctionPermission<BluetoothPermissionData,
22                              BluetoothPermission>(info) {
23 }
24
25 BluetoothPermission::~BluetoothPermission() {
26 }
27
28 bool BluetoothPermission::FromValue(const base::Value* value) {
29   // Value may be omitted to gain access to non-profile functions.
30   if (!value)
31     return true;
32
33   // Value may be an empty list for the same reason.
34   const base::ListValue* list = NULL;
35   if (value->GetAsList(&list) && list->GetSize() == 0)
36     return true;
37
38   if (!SetDisjunctionPermission<BluetoothPermissionData,
39                                 BluetoothPermission>::FromValue(value)) {
40     return false;
41   }
42
43   return true;
44 }
45
46 PermissionMessages BluetoothPermission::GetMessages() const {
47   DCHECK(HasMessages());
48   PermissionMessages result;
49
50   result.push_back(PermissionMessage(
51         PermissionMessage::kBluetooth,
52         l10n_util::GetStringUTF16(
53             IDS_EXTENSION_PROMPT_WARNING_BLUETOOTH)));
54
55   if (!data_set_.empty()) {
56     result.push_back(PermissionMessage(
57           PermissionMessage::kBluetoothDevices,
58           l10n_util::GetStringUTF16(
59               IDS_EXTENSION_PROMPT_WARNING_BLUETOOTH_DEVICES)));
60   }
61
62   return result;
63 }
64
65 }  // namespace extensions