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 "ui/base/l10n/l10n_util.h"
11 using extensions::APIPermission
;
12 using extensions::APIPermissionInfo
;
13 using extensions::PermissionMessage
;
14 using extensions::PermissionMessages
;
16 class SimpleAPIPermission
: public APIPermission
{
18 explicit SimpleAPIPermission(const APIPermissionInfo
* permission
)
19 : APIPermission(permission
) { }
21 ~SimpleAPIPermission() override
{}
23 bool HasMessages() const override
{
24 return info()->message_id() > PermissionMessage::kNone
;
27 PermissionMessages
GetMessages() const override
{
28 DCHECK(HasMessages());
29 PermissionMessages result
;
30 result
.push_back(GetMessage_());
34 bool Check(const APIPermission::CheckParam
* param
) const override
{
38 bool Contains(const APIPermission
* rhs
) const override
{
39 CHECK_EQ(info(), rhs
->info());
43 bool Equal(const APIPermission
* rhs
) const override
{
45 CHECK_EQ(info(), rhs
->info());
49 bool FromValue(const base::Value
* value
,
50 std::string
* /*error*/,
51 std::vector
<std::string
>* /*unhandled_permissions*/) override
{
52 return (value
== NULL
);
55 scoped_ptr
<base::Value
> ToValue() const override
{
56 return scoped_ptr
<base::Value
>();
59 APIPermission
* Clone() const override
{
60 return new SimpleAPIPermission(info());
63 APIPermission
* Diff(const APIPermission
* rhs
) const override
{
64 CHECK_EQ(info(), rhs
->info());
68 APIPermission
* Union(const APIPermission
* rhs
) const override
{
69 CHECK_EQ(info(), rhs
->info());
70 return new SimpleAPIPermission(info());
73 APIPermission
* Intersect(const APIPermission
* rhs
) const override
{
74 CHECK_EQ(info(), rhs
->info());
75 return new SimpleAPIPermission(info());
78 void Write(IPC::Message
* m
) const override
{}
80 bool Read(const IPC::Message
* m
, PickleIterator
* iter
) override
{
84 void Log(std::string
* log
) const override
{}
89 namespace extensions
{
91 APIPermission::APIPermission(const APIPermissionInfo
* info
)
96 APIPermission::~APIPermission() { }
98 APIPermission::ID
APIPermission::id() const {
102 const char* APIPermission::name() const {
103 return info()->name();
106 PermissionMessage
APIPermission::GetMessage_() const {
107 return info()->GetMessage_();
114 APIPermissionInfo::APIPermissionInfo(const APIPermissionInfo::InitInfo
& info
)
118 l10n_message_id_(info
.l10n_message_id
),
119 message_id_(info
.message_id
? info
.message_id
: PermissionMessage::kNone
),
120 api_permission_constructor_(info
.constructor
) {
123 APIPermissionInfo::~APIPermissionInfo() { }
125 APIPermission
* APIPermissionInfo::CreateAPIPermission() const {
126 return api_permission_constructor_
?
127 api_permission_constructor_(this) : new SimpleAPIPermission(this);
130 PermissionMessage
APIPermissionInfo::GetMessage_() const {
131 return PermissionMessage(
132 message_id_
, l10n_util::GetStringUTF16(l10n_message_id_
));
135 } // namespace extensions