Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/permission/PermissionUtils.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5
 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "PermissionUtils.h"
8
9
namespace mozilla {
10
namespace dom {
11
12
const char* kPermissionTypes[] = {
13
  "geo",
14
  "desktop-notification",
15
  // Alias `push` to `desktop-notification`.
16
  "desktop-notification",
17
  "persistent-storage"
18
};
19
20
// `-1` for the last null entry.
21
const size_t kPermissionNameCount =
22
  MOZ_ARRAY_LENGTH(PermissionNameValues::strings) - 1;
23
24
static_assert(MOZ_ARRAY_LENGTH(kPermissionTypes) == kPermissionNameCount,
25
              "kPermissionTypes and PermissionName count should match");
26
27
const char*
28
PermissionNameToType(PermissionName aName)
29
0
{
30
0
  MOZ_ASSERT((size_t)aName < ArrayLength(kPermissionTypes));
31
0
  return kPermissionTypes[static_cast<size_t>(aName)];
32
0
}
33
34
Maybe<PermissionName>
35
TypeToPermissionName(const char* aType)
36
0
{
37
0
  for (size_t i = 0; i < ArrayLength(kPermissionTypes); ++i) {
38
0
    if (!strcmp(aType, kPermissionTypes[i])) {
39
0
      return Some(static_cast<PermissionName>(i));
40
0
    }
41
0
  }
42
0
43
0
  return Nothing();
44
0
}
45
46
PermissionState
47
ActionToPermissionState(uint32_t aAction)
48
{
49
  switch (aAction) {
50
    case nsIPermissionManager::ALLOW_ACTION:
51
      return PermissionState::Granted;
52
53
    case nsIPermissionManager::DENY_ACTION:
54
      return PermissionState::Denied;
55
56
    default:
57
    case nsIPermissionManager::PROMPT_ACTION:
58
      return PermissionState::Prompt;
59
  }
60
}
61
62
} // namespace dom
63
} // namespace mozilla