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_
10 #include "base/memory/scoped_ptr.h"
11 #include "base/pickle.h"
12 #include "extensions/common/permissions/api_permission_set.h"
13 #include "extensions/common/permissions/coalesced_permission_message.h"
14 #include "extensions/common/permissions/permission_message.h"
26 namespace extensions
{
28 // Represent the custom behavior of a top-level manifest entry contributing to
29 // permission messages and storage.
30 class ManifestPermission
{
33 virtual ~ManifestPermission();
35 // The manifest key this permission applies to.
36 virtual std::string
name() const = 0;
38 // Same as name(), needed for compatibility with APIPermission.
39 virtual std::string
id() const = 0;
41 // The set of permissions this manifest entry has. These permissions are used
42 // by PermissionMessageProvider to generate meaningful permission messages
44 virtual PermissionIDSet
GetPermissions() const = 0;
46 // Returns true if this permission has any PermissionMessages.
47 // TODO(sashab): Deprecate this, using GetPermissions() above and adding
48 // message rules to ChromePermissionMessageProvider.
49 virtual bool HasMessages() const = 0;
51 // Returns the localized permission messages of this permission.
52 // TODO(sashab): Deprecate this, using GetPermissions() above and adding
53 // message rules to ChromePermissionMessageProvider.
54 virtual PermissionMessages
GetMessages() const = 0;
56 // Parses the ManifestPermission from |value|. Returns false if error happens.
57 virtual bool FromValue(const base::Value
* value
) = 0;
59 // Stores this into a new created Value.
60 virtual scoped_ptr
<base::Value
> ToValue() const = 0;
63 ManifestPermission
* Clone() const;
65 // Returns a new manifest permission which equals this - |rhs|.
66 virtual ManifestPermission
* Diff(const ManifestPermission
* rhs
) const = 0;
68 // Returns a new manifest permission which equals the union of this and |rhs|.
69 virtual ManifestPermission
* Union(const ManifestPermission
* rhs
) const = 0;
71 // Returns a new manifest permission which equals the intersect of this and
73 virtual ManifestPermission
* Intersect(const ManifestPermission
* rhs
)
76 // Returns true if |rhs| is a subset of this.
77 bool Contains(const ManifestPermission
* rhs
) const;
79 // Returns true if |rhs| is equal to this.
80 bool Equal(const ManifestPermission
* rhs
) const;
83 // Writes this into the given IPC message |m|.
84 void Write(IPC::Message
* m
) const;
86 // Reads from the given IPC message |m|.
87 bool Read(const IPC::Message
* m
, base::PickleIterator
* iter
);
89 // Logs this permission.
90 void Log(std::string
* log
) const;
93 DISALLOW_COPY_AND_ASSIGN(ManifestPermission
);
96 } // namespace extensions
98 #endif // EXTENSIONS_COMMON_PERMISSIONS_MANIFEST_PERMISSION_H_