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/api_permission.h"
7 #include "extensions/common/permissions/api_permission_set.h"
8 #include "ui/base/l10n/l10n_util.h"
12 using extensions::APIPermission
;
13 using extensions::APIPermissionInfo
;
14 using extensions::PermissionMessage
;
15 using extensions::PermissionMessages
;
17 class SimpleAPIPermission
: public APIPermission
{
19 explicit SimpleAPIPermission(const APIPermissionInfo
* permission
)
20 : APIPermission(permission
) { }
22 ~SimpleAPIPermission() override
{}
24 extensions::PermissionIDSet
GetPermissions() const override
{
25 extensions::PermissionIDSet permissions
;
26 permissions
.insert(id());
30 bool Check(const APIPermission::CheckParam
* param
) const override
{
34 bool Contains(const APIPermission
* rhs
) const override
{
35 CHECK_EQ(info(), rhs
->info());
39 bool Equal(const APIPermission
* rhs
) const override
{
41 CHECK_EQ(info(), rhs
->info());
45 bool FromValue(const base::Value
* value
,
46 std::string
* /*error*/,
47 std::vector
<std::string
>* /*unhandled_permissions*/) override
{
48 return (value
== NULL
);
51 scoped_ptr
<base::Value
> ToValue() const override
{
52 return scoped_ptr
<base::Value
>();
55 APIPermission
* Clone() const override
{
56 return new SimpleAPIPermission(info());
59 APIPermission
* Diff(const APIPermission
* rhs
) const override
{
60 CHECK_EQ(info(), rhs
->info());
64 APIPermission
* Union(const APIPermission
* rhs
) const override
{
65 CHECK_EQ(info(), rhs
->info());
66 return new SimpleAPIPermission(info());
69 APIPermission
* Intersect(const APIPermission
* rhs
) const override
{
70 CHECK_EQ(info(), rhs
->info());
71 return new SimpleAPIPermission(info());
74 void Write(IPC::Message
* m
) const override
{}
76 bool Read(const IPC::Message
* m
, base::PickleIterator
* iter
) override
{
80 void Log(std::string
* log
) const override
{}
85 namespace extensions
{
87 APIPermission::APIPermission(const APIPermissionInfo
* info
)
92 APIPermission::~APIPermission() { }
94 APIPermission::ID
APIPermission::id() const {
98 const char* APIPermission::name() const {
99 return info()->name();
106 APIPermissionInfo::APIPermissionInfo(const APIPermissionInfo::InitInfo
& info
)
110 api_permission_constructor_(info
.constructor
) {
113 APIPermissionInfo::~APIPermissionInfo() { }
115 APIPermission
* APIPermissionInfo::CreateAPIPermission() const {
116 return api_permission_constructor_
?
117 api_permission_constructor_(this) : new SimpleAPIPermission(this);
120 } // namespace extensions