Pepper: Fix PPB_TrueTypeFont GetFontsInFamily function.
[chromium-blink-merge.git] / extensions / common / permissions / api_permission.cc
blob862419f773271bb612043df1b8889ea3ef055369
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"
10 namespace {
12 using extensions::APIPermission;
13 using extensions::APIPermissionInfo;
14 using extensions::PermissionMessage;
15 using extensions::PermissionMessages;
17 class SimpleAPIPermission : public APIPermission {
18 public:
19 explicit SimpleAPIPermission(const APIPermissionInfo* permission)
20 : APIPermission(permission) { }
22 ~SimpleAPIPermission() override {}
24 extensions::PermissionIDSet GetPermissions() const override {
25 return extensions::PermissionIDSet(id());
28 bool HasMessages() const override {
29 return info()->message_id() > PermissionMessage::kNone;
32 PermissionMessages GetMessages() const override {
33 DCHECK(HasMessages());
34 PermissionMessages result;
35 result.push_back(GetMessage_());
36 return result;
39 bool Check(const APIPermission::CheckParam* param) const override {
40 return !param;
43 bool Contains(const APIPermission* rhs) const override {
44 CHECK_EQ(info(), rhs->info());
45 return true;
48 bool Equal(const APIPermission* rhs) const override {
49 if (this != rhs)
50 CHECK_EQ(info(), rhs->info());
51 return true;
54 bool FromValue(const base::Value* value,
55 std::string* /*error*/,
56 std::vector<std::string>* /*unhandled_permissions*/) override {
57 return (value == NULL);
60 scoped_ptr<base::Value> ToValue() const override {
61 return scoped_ptr<base::Value>();
64 APIPermission* Clone() const override {
65 return new SimpleAPIPermission(info());
68 APIPermission* Diff(const APIPermission* rhs) const override {
69 CHECK_EQ(info(), rhs->info());
70 return NULL;
73 APIPermission* Union(const APIPermission* rhs) const override {
74 CHECK_EQ(info(), rhs->info());
75 return new SimpleAPIPermission(info());
78 APIPermission* Intersect(const APIPermission* rhs) const override {
79 CHECK_EQ(info(), rhs->info());
80 return new SimpleAPIPermission(info());
83 void Write(IPC::Message* m) const override {}
85 bool Read(const IPC::Message* m, PickleIterator* iter) override {
86 return true;
89 void Log(std::string* log) const override {}
92 } // namespace
94 namespace extensions {
96 APIPermission::APIPermission(const APIPermissionInfo* info)
97 : info_(info) {
98 DCHECK(info_);
101 APIPermission::~APIPermission() { }
103 APIPermission::ID APIPermission::id() const {
104 return info()->id();
107 const char* APIPermission::name() const {
108 return info()->name();
111 PermissionMessage APIPermission::GetMessage_() const {
112 return info()->GetMessage_();
116 // APIPermissionInfo
119 APIPermissionInfo::APIPermissionInfo(const APIPermissionInfo::InitInfo& info)
120 : id_(info.id),
121 name_(info.name),
122 flags_(info.flags),
123 l10n_message_id_(info.l10n_message_id),
124 message_id_(info.message_id ? info.message_id : PermissionMessage::kNone),
125 api_permission_constructor_(info.constructor) {
128 APIPermissionInfo::~APIPermissionInfo() { }
130 APIPermission* APIPermissionInfo::CreateAPIPermission() const {
131 return api_permission_constructor_ ?
132 api_permission_constructor_(this) : new SimpleAPIPermission(this);
135 PermissionMessage APIPermissionInfo::GetMessage_() const {
136 return PermissionMessage(
137 message_id_, l10n_util::GetStringUTF16(l10n_message_id_));
140 } // namespace extensions