Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / extensions / common / permissions / api_permission.cc
blob89eaea5b25678e0b25764f6b08305ae8fe37a865
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;
15 class SimpleAPIPermission : public APIPermission {
16 public:
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());
25 return permissions;
28 bool Check(const APIPermission::CheckParam* param) const override {
29 return !param;
32 bool Contains(const APIPermission* rhs) const override {
33 CHECK_EQ(info(), rhs->info());
34 return true;
37 bool Equal(const APIPermission* rhs) const override {
38 if (this != rhs)
39 CHECK_EQ(info(), rhs->info());
40 return true;
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());
59 return NULL;
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 {
75 return true;
78 void Log(std::string* log) const override {}
81 } // namespace
83 namespace extensions {
85 APIPermission::APIPermission(const APIPermissionInfo* info)
86 : info_(info) {
87 DCHECK(info_);
90 APIPermission::~APIPermission() { }
92 APIPermission::ID APIPermission::id() const {
93 return info()->id();
96 const char* APIPermission::name() const {
97 return info()->name();
101 // APIPermissionInfo
104 APIPermissionInfo::APIPermissionInfo(const APIPermissionInfo::InitInfo& info)
105 : id_(info.id),
106 name_(info.name),
107 flags_(info.flags),
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