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
;
15 class SimpleAPIPermission
: public APIPermission
{
17 explicit SimpleAPIPermission(const APIPermissionInfo
* permission
)
18 : APIPermission(permission
) { }
20 ~SimpleAPIPermission() override
{}
22 extensions::PermissionIDSet
GetPermissions() const override
{
23 extensions::PermissionIDSet permissions
;
24 permissions
.insert(id());
28 bool Check(const APIPermission::CheckParam
* param
) const override
{
32 bool Contains(const APIPermission
* rhs
) const override
{
33 CHECK_EQ(info(), rhs
->info());
37 bool Equal(const APIPermission
* rhs
) const override
{
39 CHECK_EQ(info(), rhs
->info());
43 bool FromValue(const base::Value
* value
,
44 std::string
* /*error*/,
45 std::vector
<std::string
>* /*unhandled_permissions*/) override
{
46 return (value
== NULL
);
49 scoped_ptr
<base::Value
> ToValue() const override
{
50 return scoped_ptr
<base::Value
>();
53 APIPermission
* Clone() const override
{
54 return new SimpleAPIPermission(info());
57 APIPermission
* Diff(const APIPermission
* rhs
) const override
{
58 CHECK_EQ(info(), rhs
->info());
62 APIPermission
* Union(const APIPermission
* rhs
) const override
{
63 CHECK_EQ(info(), rhs
->info());
64 return new SimpleAPIPermission(info());
67 APIPermission
* Intersect(const APIPermission
* rhs
) const override
{
68 CHECK_EQ(info(), rhs
->info());
69 return new SimpleAPIPermission(info());
72 void Write(IPC::Message
* m
) const override
{}
74 bool Read(const IPC::Message
* m
, base::PickleIterator
* iter
) override
{
78 void Log(std::string
* log
) const override
{}
83 namespace extensions
{
85 APIPermission::APIPermission(const APIPermissionInfo
* info
)
90 APIPermission::~APIPermission() { }
92 APIPermission::ID
APIPermission::id() const {
96 const char* APIPermission::name() const {
97 return info()->name();
104 APIPermissionInfo::APIPermissionInfo(const APIPermissionInfo::InitInfo
& info
)
108 api_permission_constructor_(info
.constructor
) {
111 APIPermissionInfo::~APIPermissionInfo() { }
113 APIPermission
* APIPermissionInfo::CreateAPIPermission() const {
114 return api_permission_constructor_
?
115 api_permission_constructor_(this) : new SimpleAPIPermission(this);
118 } // namespace extensions