• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef EXTENSIONS_COMMON_PERMISSIONS_MANIFEST_PERMISSION_H_
6 #define EXTENSIONS_COMMON_PERMISSIONS_MANIFEST_PERMISSION_H_
7 
8 #include <string>
9 
10 #include "base/memory/scoped_ptr.h"
11 #include "base/pickle.h"
12 #include "extensions/common/permissions/permission_message.h"
13 
14 class PickleIterator;
15 
16 namespace base {
17 class Value;
18 class ListValue;
19 }
20 
21 namespace IPC {
22 class Message;
23 }
24 
25 namespace extensions {
26 
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();
33 
34   // The manifest key this permission applies to.
35   virtual std::string name() const = 0;
36 
37   // Same as name(), needed for compatibility with APIPermission.
38   virtual std::string id() const = 0;
39 
40   // Returns true if this permission has any PermissionMessages.
41   virtual bool HasMessages() const = 0;
42 
43   // Returns the localized permission messages of this permission.
44   virtual PermissionMessages GetMessages() const = 0;
45 
46   // Parses the ManifestPermission from |value|. Returns false if error happens.
47   virtual bool FromValue(const base::Value* value) = 0;
48 
49   // Stores this into a new created Value.
50   virtual scoped_ptr<base::Value> ToValue() const = 0;
51 
52   // Clones this.
53   ManifestPermission* Clone() const;
54 
55   // Returns a new manifest permission which equals this - |rhs|.
56   virtual ManifestPermission* Diff(const ManifestPermission* rhs) const = 0;
57 
58   // Returns a new manifest permission which equals the union of this and |rhs|.
59   virtual ManifestPermission* Union(const ManifestPermission* rhs) const = 0;
60 
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;
65 
66   // Returns true if |rhs| is a subset of this.
67   bool Contains(const ManifestPermission* rhs) const;
68 
69   // Returns true if |rhs| is equal to this.
70   bool Equal(const ManifestPermission* rhs) const;
71 
72   // IPC functions
73   // Writes this into the given IPC message |m|.
74   void Write(IPC::Message* m) const;
75 
76   // Reads from the given IPC message |m|.
77   bool Read(const IPC::Message* m, PickleIterator* iter);
78 
79   // Logs this permission.
80   void Log(std::string* log) const;
81 
82  private:
83   DISALLOW_COPY_AND_ASSIGN(ManifestPermission);
84 };
85 
86 }  // namespace extensions
87 
88 #endif  // EXTENSIONS_COMMON_PERMISSIONS_MANIFEST_PERMISSION_H_
89