summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/permissions/bluetooth_permission.cc
blob: 984c4a0d246001b6e0d1665cfa2073764e10dfe0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/common/extensions/permissions/bluetooth_permission.h"

#include <string>

#include "base/logging.h"
#include "base/strings/string16.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/common/extensions/permissions/bluetooth_permission_data.h"
#include "chrome/common/extensions/permissions/permissions_info.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"

namespace extensions {

BluetoothPermission::BluetoothPermission(const APIPermissionInfo* info)
  : SetDisjunctionPermission<BluetoothPermissionData,
                             BluetoothPermission>(info) {
}

BluetoothPermission::~BluetoothPermission() {
}

bool BluetoothPermission::FromValue(const base::Value* value) {
  // Value may be omitted to gain access to non-profile functions.
  if (!value)
    return true;

  // Value may be an empty list for the same reason.
  const base::ListValue* list = NULL;
  if (value->GetAsList(&list) && list->GetSize() == 0)
    return true;

  if (!SetDisjunctionPermission<BluetoothPermissionData,
                                BluetoothPermission>::FromValue(value)) {
    return false;
  }

  return true;
}

PermissionMessages BluetoothPermission::GetMessages() const {
  DCHECK(HasMessages());
  PermissionMessages result;

  result.push_back(PermissionMessage(
        PermissionMessage::kBluetooth,
        l10n_util::GetStringUTF16(
            IDS_EXTENSION_PROMPT_WARNING_BLUETOOTH)));

  if (!data_set_.empty()) {
    result.push_back(PermissionMessage(
          PermissionMessage::kBluetoothDevices,
          l10n_util::GetStringUTF16(
              IDS_EXTENSION_PROMPT_WARNING_BLUETOOTH_DEVICES)));
  }

  return result;
}

}  // namespace extensions