OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "extensions/common/manifest_handler.h" | 5 #include "extensions/common/manifest_handler.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "chrome/common/extensions/extension.h" | 11 #include "chrome/common/extensions/extension.h" |
| 12 #include "extensions/common/permissions/api_permission_set.h" |
12 | 13 |
13 namespace extensions { | 14 namespace extensions { |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 static base::LazyInstance<ManifestHandlerRegistry> g_registry = | 18 static base::LazyInstance<ManifestHandlerRegistry> g_registry = |
18 LAZY_INSTANCE_INITIALIZER; | 19 LAZY_INSTANCE_INITIALIZER; |
19 static ManifestHandlerRegistry* g_registry_override = NULL; | 20 static ManifestHandlerRegistry* g_registry_override = NULL; |
20 | 21 |
21 ManifestHandlerRegistry* GetRegistry() { | 22 ManifestHandlerRegistry* GetRegistry() { |
(...skipping 28 matching lines...) Expand all Loading... |
50 return std::vector<std::string>(); | 51 return std::vector<std::string>(); |
51 } | 52 } |
52 | 53 |
53 void ManifestHandler::Register() { | 54 void ManifestHandler::Register() { |
54 linked_ptr<ManifestHandler> this_linked(this); | 55 linked_ptr<ManifestHandler> this_linked(this); |
55 const std::vector<std::string> keys = Keys(); | 56 const std::vector<std::string> keys = Keys(); |
56 for (size_t i = 0; i < keys.size(); ++i) | 57 for (size_t i = 0; i < keys.size(); ++i) |
57 GetRegistry()->RegisterManifestHandler(keys[i], this_linked); | 58 GetRegistry()->RegisterManifestHandler(keys[i], this_linked); |
58 } | 59 } |
59 | 60 |
| 61 ManifestPermission* ManifestHandler::CreatePermission() { |
| 62 return NULL; |
| 63 } |
| 64 |
| 65 ManifestPermission* ManifestHandler::CreateInitialRequiredPermission( |
| 66 const Extension* extension) { |
| 67 return NULL; |
| 68 } |
| 69 |
60 // static | 70 // static |
61 void ManifestHandler::FinalizeRegistration() { | 71 void ManifestHandler::FinalizeRegistration() { |
62 GetRegistry()->Finalize(); | 72 GetRegistry()->Finalize(); |
63 } | 73 } |
64 | 74 |
65 // static | 75 // static |
66 bool ManifestHandler::IsRegistrationFinalized() { | 76 bool ManifestHandler::IsRegistrationFinalized() { |
67 return GetRegistry()->is_finalized_; | 77 return GetRegistry()->is_finalized_; |
68 } | 78 } |
69 | 79 |
70 // static | 80 // static |
71 bool ManifestHandler::ParseExtension(Extension* extension, string16* error) { | 81 bool ManifestHandler::ParseExtension(Extension* extension, string16* error) { |
72 return GetRegistry()->ParseExtension(extension, error); | 82 return GetRegistry()->ParseExtension(extension, error); |
73 } | 83 } |
74 | 84 |
75 // static | 85 // static |
76 bool ManifestHandler::ValidateExtension(const Extension* extension, | 86 bool ManifestHandler::ValidateExtension(const Extension* extension, |
77 std::string* error, | 87 std::string* error, |
78 std::vector<InstallWarning>* warnings) { | 88 std::vector<InstallWarning>* warnings) { |
79 return GetRegistry()->ValidateExtension(extension, error, warnings); | 89 return GetRegistry()->ValidateExtension(extension, error, warnings); |
80 } | 90 } |
81 | 91 |
82 // static | 92 // static |
| 93 ManifestPermission* ManifestHandler::CreatePermission(const std::string& name) { |
| 94 return GetRegistry()->CreatePermission(name); |
| 95 } |
| 96 |
| 97 // static |
| 98 void ManifestHandler::AddExtensionRequiredPermissions( |
| 99 const Extension* extension, ManifestPermissionSet* permission_set) { |
| 100 return GetRegistry()->AddExtensionRequiredPermissions(extension, |
| 101 permission_set); |
| 102 } |
| 103 |
| 104 // static |
83 const std::vector<std::string> ManifestHandler::SingleKey( | 105 const std::vector<std::string> ManifestHandler::SingleKey( |
84 const std::string& key) { | 106 const std::string& key) { |
85 return std::vector<std::string>(1, key); | 107 return std::vector<std::string>(1, key); |
86 } | 108 } |
87 | 109 |
88 ManifestHandlerRegistry::ManifestHandlerRegistry() : is_finalized_(false) { | 110 ManifestHandlerRegistry::ManifestHandlerRegistry() : is_finalized_(false) { |
89 } | 111 } |
90 | 112 |
91 ManifestHandlerRegistry::~ManifestHandlerRegistry() { | 113 ManifestHandlerRegistry::~ManifestHandlerRegistry() { |
92 } | 114 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 } | 159 } |
138 } | 160 } |
139 for (std::set<ManifestHandler*>::iterator iter = handlers.begin(); | 161 for (std::set<ManifestHandler*>::iterator iter = handlers.begin(); |
140 iter != handlers.end(); ++iter) { | 162 iter != handlers.end(); ++iter) { |
141 if (!(*iter)->Validate(extension, error, warnings)) | 163 if (!(*iter)->Validate(extension, error, warnings)) |
142 return false; | 164 return false; |
143 } | 165 } |
144 return true; | 166 return true; |
145 } | 167 } |
146 | 168 |
| 169 ManifestPermission* ManifestHandlerRegistry::CreatePermission( |
| 170 const std::string& name) { |
| 171 ManifestHandlerMap::const_iterator it = handlers_.find(name); |
| 172 if (it == handlers_.end()) |
| 173 return NULL; |
| 174 |
| 175 return it->second->CreatePermission(); |
| 176 } |
| 177 |
| 178 void ManifestHandlerRegistry::AddExtensionRequiredPermissions( |
| 179 const Extension* extension, ManifestPermissionSet* permission_set) { |
| 180 for (ManifestHandlerMap::const_iterator it = handlers_.begin(); |
| 181 it != handlers_.end(); ++it) { |
| 182 ManifestPermission* permission = |
| 183 it->second->CreateInitialRequiredPermission(extension); |
| 184 if (permission) { |
| 185 permission_set->insert(permission); |
| 186 } |
| 187 } |
| 188 } |
| 189 |
147 // static | 190 // static |
148 ManifestHandlerRegistry* ManifestHandlerRegistry::SetForTesting( | 191 ManifestHandlerRegistry* ManifestHandlerRegistry::SetForTesting( |
149 ManifestHandlerRegistry* new_registry) { | 192 ManifestHandlerRegistry* new_registry) { |
150 ManifestHandlerRegistry* old_registry = GetRegistry(); | 193 ManifestHandlerRegistry* old_registry = GetRegistry(); |
151 if (new_registry != g_registry.Pointer()) | 194 if (new_registry != g_registry.Pointer()) |
152 g_registry_override = new_registry; | 195 g_registry_override = new_registry; |
153 else | 196 else |
154 g_registry_override = NULL; | 197 g_registry_override = NULL; |
155 return old_registry; | 198 return old_registry; |
156 } | 199 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 unsorted_handlers.swap(next_unsorted_handlers); | 239 unsorted_handlers.swap(next_unsorted_handlers); |
197 } | 240 } |
198 | 241 |
199 // If there are any leftover unsorted handlers, they must have had | 242 // If there are any leftover unsorted handlers, they must have had |
200 // circular dependencies. | 243 // circular dependencies. |
201 CHECK(unsorted_handlers.size() == 0) << "Extension manifest handlers have " | 244 CHECK(unsorted_handlers.size() == 0) << "Extension manifest handlers have " |
202 << "circular dependencies!"; | 245 << "circular dependencies!"; |
203 } | 246 } |
204 | 247 |
205 } // namespace extensions | 248 } // namespace extensions |
OLD | NEW |