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"
27 namespace extensions
{
29 // Represent the custom behavior of a top-level manifest entry contributing to
30 // permission messages and storage.
31 class ManifestPermission
{
34 virtual ~ManifestPermission();
36 // The manifest key this permission applies to.
37 virtual std::string
name() const = 0;
39 // Same as name(), needed for compatibility with APIPermission.
40 virtual std::string
id() const = 0;
42 // The set of permissions this manifest entry has. These permissions are used
43 // by PermissionMessageProvider to generate meaningful permission messages
45 virtual PermissionIDSet
GetPermissions() const = 0;
47 // Returns true if this permission has any PermissionMessages.
48 // TODO(sashab): Deprecate this, using GetPermissions() above and adding
49 // message rules to ChromePermissionMessageProvider.
50 virtual bool HasMessages() const = 0;
52 // Returns the localized permission messages of this permission.
53 // TODO(sashab): Deprecate this, using GetPermissions() above and adding
54 // message rules to ChromePermissionMessageProvider.
55 virtual PermissionMessages
GetMessages() const = 0;
57 // Parses the ManifestPermission from |value|. Returns false if error happens.
58 virtual bool FromValue(const base::Value
* value
) = 0;
60 // Stores this into a new created Value.
61 virtual scoped_ptr
<base::Value
> ToValue() const = 0;
64 ManifestPermission
* Clone() const;
66 // Returns a new manifest permission which equals this - |rhs|.
67 virtual ManifestPermission
* Diff(const ManifestPermission
* rhs
) const = 0;
69 // Returns a new manifest permission which equals the union of this and |rhs|.
70 virtual ManifestPermission
* Union(const ManifestPermission
* rhs
) const = 0;
72 // Returns a new manifest permission which equals the intersect of this and
74 virtual ManifestPermission
* Intersect(const ManifestPermission
* rhs
)
77 // Returns true if |rhs| is a subset of this.
78 bool Contains(const ManifestPermission
* rhs
) const;
80 // Returns true if |rhs| is equal to this.
81 bool Equal(const ManifestPermission
* rhs
) const;
84 // Writes this into the given IPC message |m|.
85 void Write(IPC::Message
* m
) const;
87 // Reads from the given IPC message |m|.
88 bool Read(const IPC::Message
* m
, PickleIterator
* iter
);
90 // Logs this permission.
91 void Log(std::string
* log
) const;
94 DISALLOW_COPY_AND_ASSIGN(ManifestPermission
);
97 } // namespace extensions
99 #endif // EXTENSIONS_COMMON_PERMISSIONS_MANIFEST_PERMISSION_H_