Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / extensions / common / permissions / manifest_permission.cc
bloba3ba98e17ca2f2975003c749d62d12351bd55048
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.
5 #include "extensions/common/permissions/manifest_permission.h"
7 #include "base/json/json_writer.h"
8 #include "extensions/common/manifest_handler.h"
9 #include "ipc/ipc_message.h"
10 #include "ipc/ipc_message_utils.h"
12 namespace extensions {
14 ManifestPermission::ManifestPermission() {}
16 ManifestPermission::~ManifestPermission() { }
18 ManifestPermission* ManifestPermission::Clone() const {
19 return Union(this);
22 bool ManifestPermission::Contains(const ManifestPermission* rhs) const {
23 return scoped_ptr<ManifestPermission>(Intersect(rhs))->Equal(rhs);
26 bool ManifestPermission::Equal(const ManifestPermission* rhs) const {
27 return ToValue()->Equals(rhs->ToValue().get());
30 void ManifestPermission::Write(IPC::Message* m) const {
31 base::ListValue singleton;
32 base::Value* value = ToValue().release();
33 singleton.Append(value);
34 IPC::WriteParam(m, singleton);
37 bool ManifestPermission::Read(const IPC::Message* m,
38 base::PickleIterator* iter) {
39 base::ListValue singleton;
40 if (!IPC::ReadParam(m, iter, &singleton))
41 return false;
42 if (singleton.GetSize() != 1)
43 return false;
44 base::Value* value = NULL;
45 if (!singleton.Get(0, &value))
46 return false;
47 return FromValue(value);
50 void ManifestPermission::Log(std::string* log) const {
51 base::JSONWriter::WriteWithOptions(
52 *ToValue(), base::JSONWriter::OPTIONS_PRETTY_PRINT, log);
55 } // namespace extensions