blob: 4d8286843ba983f3373238d310e10c0391a619d2 [file] [log] [blame]
Ben Murdocheb525c52013-07-10 11:40:50 +01001// 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"
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +010014#include "extensions/common/permissions/permissions_info.h"
Ben Murdocheb525c52013-07-10 11:40:50 +010015#include "grit/generated_resources.h"
16#include "ui/base/l10n/l10n_util.h"
17
18namespace extensions {
19
20BluetoothPermission::BluetoothPermission(const APIPermissionInfo* info)
21 : SetDisjunctionPermission<BluetoothPermissionData,
22 BluetoothPermission>(info) {
23}
24
25BluetoothPermission::~BluetoothPermission() {
26}
27
28bool 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
46PermissionMessages 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