Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: extensions/common/manifest_handler.cc

Issue 51433002: Enable permission warnings from ManifestHandlers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unit test and clang presubmit errors. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/manifest_permission.h"
13 #include "extensions/common/permissions/manifest_permission_set.h"
12 14
13 namespace extensions { 15 namespace extensions {
14 16
15 namespace { 17 namespace {
16 18
17 static base::LazyInstance<ManifestHandlerRegistry> g_registry = 19 static base::LazyInstance<ManifestHandlerRegistry> g_registry =
18 LAZY_INSTANCE_INITIALIZER; 20 LAZY_INSTANCE_INITIALIZER;
19 static ManifestHandlerRegistry* g_registry_override = NULL; 21 static ManifestHandlerRegistry* g_registry_override = NULL;
20 22
21 ManifestHandlerRegistry* GetRegistry() { 23 ManifestHandlerRegistry* GetRegistry() {
(...skipping 28 matching lines...) Expand all
50 return std::vector<std::string>(); 52 return std::vector<std::string>();
51 } 53 }
52 54
53 void ManifestHandler::Register() { 55 void ManifestHandler::Register() {
54 linked_ptr<ManifestHandler> this_linked(this); 56 linked_ptr<ManifestHandler> this_linked(this);
55 const std::vector<std::string> keys = Keys(); 57 const std::vector<std::string> keys = Keys();
56 for (size_t i = 0; i < keys.size(); ++i) 58 for (size_t i = 0; i < keys.size(); ++i)
57 GetRegistry()->RegisterManifestHandler(keys[i], this_linked); 59 GetRegistry()->RegisterManifestHandler(keys[i], this_linked);
58 } 60 }
59 61
62 ManifestPermission* ManifestHandler::CreatePermission() {
63 return NULL;
64 }
65
66 ManifestPermission* ManifestHandler::CreateInitialRequiredPermission(
67 const Extension* extension) {
68 return NULL;
69 }
70
60 // static 71 // static
61 void ManifestHandler::FinalizeRegistration() { 72 void ManifestHandler::FinalizeRegistration() {
62 GetRegistry()->Finalize(); 73 GetRegistry()->Finalize();
63 } 74 }
64 75
65 // static 76 // static
66 bool ManifestHandler::IsRegistrationFinalized() { 77 bool ManifestHandler::IsRegistrationFinalized() {
67 return GetRegistry()->is_finalized_; 78 return GetRegistry()->is_finalized_;
68 } 79 }
69 80
70 // static 81 // static
71 bool ManifestHandler::ParseExtension(Extension* extension, string16* error) { 82 bool ManifestHandler::ParseExtension(Extension* extension, string16* error) {
72 return GetRegistry()->ParseExtension(extension, error); 83 return GetRegistry()->ParseExtension(extension, error);
73 } 84 }
74 85
75 // static 86 // static
76 bool ManifestHandler::ValidateExtension(const Extension* extension, 87 bool ManifestHandler::ValidateExtension(const Extension* extension,
77 std::string* error, 88 std::string* error,
78 std::vector<InstallWarning>* warnings) { 89 std::vector<InstallWarning>* warnings) {
79 return GetRegistry()->ValidateExtension(extension, error, warnings); 90 return GetRegistry()->ValidateExtension(extension, error, warnings);
80 } 91 }
81 92
82 // static 93 // static
94 ManifestPermission* ManifestHandler::CreatePermission(const std::string& name) {
95 return GetRegistry()->CreatePermission(name);
96 }
97
98 // static
99 void ManifestHandler::AddExtensionInitialRequiredPermissions(
100 const Extension* extension, ManifestPermissionSet* permission_set) {
101 return GetRegistry()->AddExtensionInitialRequiredPermissions(extension,
102 permission_set);
103 }
104
105 // static
83 const std::vector<std::string> ManifestHandler::SingleKey( 106 const std::vector<std::string> ManifestHandler::SingleKey(
84 const std::string& key) { 107 const std::string& key) {
85 return std::vector<std::string>(1, key); 108 return std::vector<std::string>(1, key);
86 } 109 }
87 110
88 ManifestHandlerRegistry::ManifestHandlerRegistry() : is_finalized_(false) { 111 ManifestHandlerRegistry::ManifestHandlerRegistry() : is_finalized_(false) {
89 } 112 }
90 113
91 ManifestHandlerRegistry::~ManifestHandlerRegistry() { 114 ManifestHandlerRegistry::~ManifestHandlerRegistry() {
92 } 115 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 } 160 }
138 } 161 }
139 for (std::set<ManifestHandler*>::iterator iter = handlers.begin(); 162 for (std::set<ManifestHandler*>::iterator iter = handlers.begin();
140 iter != handlers.end(); ++iter) { 163 iter != handlers.end(); ++iter) {
141 if (!(*iter)->Validate(extension, error, warnings)) 164 if (!(*iter)->Validate(extension, error, warnings))
142 return false; 165 return false;
143 } 166 }
144 return true; 167 return true;
145 } 168 }
146 169
170 ManifestPermission* ManifestHandlerRegistry::CreatePermission(
171 const std::string& name) {
172 ManifestHandlerMap::const_iterator it = handlers_.find(name);
173 if (it == handlers_.end())
174 return NULL;
175
176 return it->second->CreatePermission();
177 }
178
179 void ManifestHandlerRegistry::AddExtensionInitialRequiredPermissions(
180 const Extension* extension, ManifestPermissionSet* permission_set) {
181 for (ManifestHandlerMap::const_iterator it = handlers_.begin();
182 it != handlers_.end(); ++it) {
183 ManifestPermission* permission =
184 it->second->CreateInitialRequiredPermission(extension);
185 if (permission) {
186 permission_set->insert(permission);
187 }
188 }
189 }
190
147 // static 191 // static
148 ManifestHandlerRegistry* ManifestHandlerRegistry::SetForTesting( 192 ManifestHandlerRegistry* ManifestHandlerRegistry::SetForTesting(
149 ManifestHandlerRegistry* new_registry) { 193 ManifestHandlerRegistry* new_registry) {
150 ManifestHandlerRegistry* old_registry = GetRegistry(); 194 ManifestHandlerRegistry* old_registry = GetRegistry();
151 if (new_registry != g_registry.Pointer()) 195 if (new_registry != g_registry.Pointer())
152 g_registry_override = new_registry; 196 g_registry_override = new_registry;
153 else 197 else
154 g_registry_override = NULL; 198 g_registry_override = NULL;
155 return old_registry; 199 return old_registry;
156 } 200 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 unsorted_handlers.swap(next_unsorted_handlers); 240 unsorted_handlers.swap(next_unsorted_handlers);
197 } 241 }
198 242
199 // If there are any leftover unsorted handlers, they must have had 243 // If there are any leftover unsorted handlers, they must have had
200 // circular dependencies. 244 // circular dependencies.
201 CHECK(unsorted_handlers.size() == 0) << "Extension manifest handlers have " 245 CHECK(unsorted_handlers.size() == 0) << "Extension manifest handlers have "
202 << "circular dependencies!"; 246 << "circular dependencies!";
203 } 247 }
204 248
205 } // namespace extensions 249 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/manifest_handler.h ('k') | extensions/common/permissions/api_permission_set.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698