Blink roll 25b6bd3a7a131ffe68d809546ad1a20707915cdc:3a503f41ae42e5b79cfcd2ff10e65afde...
[chromium-blink-merge.git] / extensions / common / permissions / manifest_permission.h
blobfdfb3f4b383bc72e8b0673a7f05eeaabffd98c6b
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 #ifndef EXTENSIONS_COMMON_PERMISSIONS_MANIFEST_PERMISSION_H_
6 #define EXTENSIONS_COMMON_PERMISSIONS_MANIFEST_PERMISSION_H_
8 #include <string>
10 #include "base/memory/scoped_ptr.h"
11 #include "base/pickle.h"
12 #include "extensions/common/permissions/permission_message.h"
14 class PickleIterator;
16 namespace base {
17 class Value;
18 class ListValue;
21 namespace IPC {
22 class Message;
25 namespace extensions {
27 // Represent the custom behavior of a top-level manifest entry contributing to
28 // permission messages and storage.
29 class ManifestPermission {
30 public:
31 ManifestPermission();
32 virtual ~ManifestPermission();
34 // The manifest key this permission applies to.
35 virtual std::string name() const = 0;
37 // Same as name(), needed for compatibility with APIPermission.
38 virtual std::string id() const = 0;
40 // Returns true if this permission has any PermissionMessages.
41 virtual bool HasMessages() const = 0;
43 // Returns the localized permission messages of this permission.
44 virtual PermissionMessages GetMessages() const = 0;
46 // Parses the ManifestPermission from |value|. Returns false if error happens.
47 virtual bool FromValue(const base::Value* value) = 0;
49 // Stores this into a new created Value.
50 virtual scoped_ptr<base::Value> ToValue() const = 0;
52 // Clones this.
53 ManifestPermission* Clone() const;
55 // Returns a new manifest permission which equals this - |rhs|.
56 virtual ManifestPermission* Diff(const ManifestPermission* rhs) const = 0;
58 // Returns a new manifest permission which equals the union of this and |rhs|.
59 virtual ManifestPermission* Union(const ManifestPermission* rhs) const = 0;
61 // Returns a new manifest permission which equals the intersect of this and
62 // |rhs|.
63 virtual ManifestPermission* Intersect(const ManifestPermission* rhs)
64 const = 0;
66 // Returns true if |rhs| is a subset of this.
67 bool Contains(const ManifestPermission* rhs) const;
69 // Returns true if |rhs| is equal to this.
70 bool Equal(const ManifestPermission* rhs) const;
72 // IPC functions
73 // Writes this into the given IPC message |m|.
74 void Write(IPC::Message* m) const;
76 // Reads from the given IPC message |m|.
77 bool Read(const IPC::Message* m, PickleIterator* iter);
79 // Logs this permission.
80 void Log(std::string* log) const;
82 private:
83 DISALLOW_COPY_AND_ASSIGN(ManifestPermission);
86 } // namespace extensions
88 #endif // EXTENSIONS_COMMON_PERMISSIONS_MANIFEST_PERMISSION_H_