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

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

Issue 377753003: Remove GetContexts() from the public interface of extensions::Feature. It was (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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/extension_api.h" 5 #include "extensions/common/extension_api.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 const FeatureProvider* provider) { 255 const FeatureProvider* provider) {
256 dependency_providers_[name] = provider; 256 dependency_providers_[name] = provider;
257 } 257 }
258 258
259 bool ExtensionAPI::IsAnyFeatureAvailableToContext(const Feature& api, 259 bool ExtensionAPI::IsAnyFeatureAvailableToContext(const Feature& api,
260 const Extension* extension, 260 const Extension* extension,
261 Feature::Context context, 261 Feature::Context context,
262 const GURL& url) { 262 const GURL& url) {
263 FeatureProviderMap::iterator provider = dependency_providers_.find("api"); 263 FeatureProviderMap::iterator provider = dependency_providers_.find("api");
264 CHECK(provider != dependency_providers_.end()); 264 CHECK(provider != dependency_providers_.end());
265
265 if (api.IsAvailableToContext(extension, context, url).is_available()) 266 if (api.IsAvailableToContext(extension, context, url).is_available())
266 return true; 267 return true;
267 268
268 // Check to see if there are any parts of this API that are allowed in this 269 // Check to see if there are any parts of this API that are allowed in this
269 // context. 270 // context.
270 const std::vector<Feature*> features = provider->second->GetChildren(api); 271 const std::vector<Feature*> features = provider->second->GetChildren(api);
271 for (std::vector<Feature*>::const_iterator it = features.begin(); 272 for (std::vector<Feature*>::const_iterator it = features.begin();
272 it != features.end(); 273 it != features.end();
273 ++it) { 274 ++it) {
274 if ((*it)->IsAvailableToContext(extension, context, url).is_available()) 275 if ((*it)->IsAvailableToContext(extension, context, url).is_available())
275 return true; 276 return true;
276 } 277 }
277 return false; 278 return false;
278 } 279 }
279 280
280 Feature::Availability ExtensionAPI::IsAvailable(const std::string& full_name, 281 Feature::Availability ExtensionAPI::IsAvailable(const std::string& full_name,
281 const Extension* extension, 282 const Extension* extension,
282 Feature::Context context, 283 Feature::Context context,
283 const GURL& url) { 284 const GURL& url) {
284 Feature* feature = GetFeatureDependency(full_name); 285 Feature* feature = GetFeatureDependency(full_name);
285 if (!feature) { 286 if (!feature) {
286 return Feature::CreateAvailability(Feature::NOT_PRESENT, 287 return Feature::CreateAvailability(Feature::NOT_PRESENT,
287 std::string("Unknown feature: ") + full_name); 288 std::string("Unknown feature: ") + full_name);
288 } 289 }
289 return feature->IsAvailableToContext(extension, context, url); 290 return feature->IsAvailableToContext(extension, context, url);
290 } 291 }
291 292
292 bool ExtensionAPI::IsPrivileged(const std::string& full_name) { 293 bool ExtensionAPI::IsAvailableInUntrustedContext(const std::string& name,
293 Feature* feature = GetFeatureDependency(full_name); 294 const Extension* extension) {
294 CHECK(feature) << full_name; 295 return IsAvailable(name, extension, Feature::CONTENT_SCRIPT_CONTEXT, GURL())
Ken Rockot(use gerrit already) 2014/07/09 16:24:15 Heh, this is a little awkward to read, but I reali
not at google - send to devlin 2014/07/09 16:26:26 I agree! I can rename in a follow up.
295 DCHECK(!feature->GetContexts()->empty()) << full_name; 296 .is_available() ||
296 // An API is 'privileged' if it can only be run in a blessed context. 297 IsAvailable(
297 return feature->GetContexts()->size() == 298 name, extension, Feature::UNBLESSED_EXTENSION_CONTEXT, GURL())
298 feature->GetContexts()->count(Feature::BLESSED_EXTENSION_CONTEXT); 299 .is_available() ||
300 IsAvailable(name, extension, Feature::BLESSED_WEB_PAGE_CONTEXT, GURL())
301 .is_available() ||
302 IsAvailable(name, extension, Feature::WEB_PAGE_CONTEXT, GURL())
303 .is_available();
299 } 304 }
300 305
301 const base::DictionaryValue* ExtensionAPI::GetSchema( 306 const base::DictionaryValue* ExtensionAPI::GetSchema(
302 const std::string& full_name) { 307 const std::string& full_name) {
303 std::string child_name; 308 std::string child_name;
304 std::string api_name = GetAPINameFromFullName(full_name, &child_name); 309 std::string api_name = GetAPINameFromFullName(full_name, &child_name);
305 310
306 const base::DictionaryValue* result = NULL; 311 const base::DictionaryValue* result = NULL;
307 SchemaMap::iterator maybe_schema = schemas_.find(api_name); 312 SchemaMap::iterator maybe_schema = schemas_.find(api_name);
308 if (maybe_schema != schemas_.end()) { 313 if (maybe_schema != schemas_.end()) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 break; 387 break;
383 388
384 api_name_candidate = api_name_candidate.substr(0, last_dot_index); 389 api_name_candidate = api_name_candidate.substr(0, last_dot_index);
385 } 390 }
386 391
387 *child_name = ""; 392 *child_name = "";
388 return std::string(); 393 return std::string();
389 } 394 }
390 395
391 } // namespace extensions 396 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698