summaryrefslogtreecommitdiffstats
path: root/extensions/common/permissions/manifest_permission.cc
blob: 97421385169469bb5d807e7efa33e8b1ccc155e5 (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
// 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 "extensions/common/permissions/manifest_permission.h"

#include "base/json/json_writer.h"
#include "extensions/common/manifest_handler.h"
#include "ipc/ipc_message.h"
#include "ipc/ipc_message_utils.h"

namespace extensions {

ManifestPermission::ManifestPermission() {}

ManifestPermission::~ManifestPermission() { }

ManifestPermission* ManifestPermission::Clone() const {
  return Union(this);
}

bool ManifestPermission::Contains(const ManifestPermission* rhs) const {
  return scoped_ptr<ManifestPermission>(Intersect(rhs))->Equal(rhs);
}

bool ManifestPermission::Equal(const ManifestPermission* rhs) const {
  return ToValue()->Equals(rhs->ToValue().get());
}

void ManifestPermission::Write(base::Pickle* m) const {
  base::ListValue singleton;
  base::Value* value = ToValue().release();
  singleton.Append(value);
  IPC::WriteParam(m, singleton);
}

bool ManifestPermission::Read(const base::Pickle* m,
                              base::PickleIterator* iter) {
  base::ListValue singleton;
  if (!IPC::ReadParam(m, iter, &singleton))
    return false;
  if (singleton.GetSize() != 1)
    return false;
  base::Value* value = NULL;
  if (!singleton.Get(0, &value))
    return false;
  return FromValue(value);
}

void ManifestPermission::Log(std::string* log) const {
  base::JSONWriter::WriteWithOptions(
      *ToValue(), base::JSONWriter::OPTIONS_PRETTY_PRINT, log);
}

}  // namespace extensions