| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/common/extensions/api/extension_api.h" | 5 #include "chrome/common/extensions/api/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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 void ExtensionAPI::RegisterSchema(const std::string& name, | 345 void ExtensionAPI::RegisterSchema(const std::string& name, |
| 346 const base::StringPiece& source) { | 346 const base::StringPiece& source) { |
| 347 unloaded_schemas_[name] = source; | 347 unloaded_schemas_[name] = source; |
| 348 } | 348 } |
| 349 | 349 |
| 350 void ExtensionAPI::RegisterDependencyProvider(const std::string& name, | 350 void ExtensionAPI::RegisterDependencyProvider(const std::string& name, |
| 351 FeatureProvider* provider) { | 351 FeatureProvider* provider) { |
| 352 dependency_providers_[name] = provider; | 352 dependency_providers_[name] = provider; |
| 353 } | 353 } |
| 354 | 354 |
| 355 bool ExtensionAPI::IsAnyFeatureAvailableToContext(const std::string& api_name, |
| 356 Feature::Context context, |
| 357 const GURL& url) { |
| 358 FeatureProviderMap::iterator provider = dependency_providers_.find("api"); |
| 359 CHECK(provider != dependency_providers_.end()); |
| 360 std::set<std::string> features = provider->second->GetAllFeatureNames(); |
| 361 |
| 362 // Check to see if there are any parts of this API that are allowed in this |
| 363 // context. |
| 364 for (std::set<std::string>::iterator i = features.begin(); |
| 365 i != features.end(); ++i) { |
| 366 const std::string& feature_name = *i; |
| 367 if (feature_name != api_name && feature_name.find(api_name + ".") == 0) { |
| 368 if (IsAvailable(feature_name, NULL, context, url).is_available()) |
| 369 return true; |
| 370 } |
| 371 } |
| 372 return IsAvailable(api_name, NULL, context, url).is_available(); |
| 373 } |
| 374 |
| 355 Feature::Availability ExtensionAPI::IsAvailable(const std::string& full_name, | 375 Feature::Availability ExtensionAPI::IsAvailable(const std::string& full_name, |
| 356 const Extension* extension, | 376 const Extension* extension, |
| 357 Feature::Context context, | 377 Feature::Context context, |
| 358 const GURL& url) { | 378 const GURL& url) { |
| 359 std::string feature_type; | 379 std::string feature_type; |
| 360 std::string feature_name; | 380 std::string feature_name; |
| 361 SplitDependencyName(full_name, &feature_type, &feature_name); | 381 SplitDependencyName(full_name, &feature_type, &feature_name); |
| 362 | 382 |
| 363 std::string child_name; | 383 std::string child_name; |
| 364 std::string api_name = GetAPINameFromFullName(feature_name, &child_name); | 384 std::string api_name = GetAPINameFromFullName(feature_name, &child_name); |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 return extension->required_permission_set()->HasAnyAccessToAPI(name) || | 599 return extension->required_permission_set()->HasAnyAccessToAPI(name) || |
| 580 extension->optional_permission_set()->HasAnyAccessToAPI(name); | 600 extension->optional_permission_set()->HasAnyAccessToAPI(name); |
| 581 } | 601 } |
| 582 | 602 |
| 583 bool ExtensionAPI::IsPrivilegedAPI(const std::string& name) { | 603 bool ExtensionAPI::IsPrivilegedAPI(const std::string& name) { |
| 584 return completely_unprivileged_apis_.count(name) || | 604 return completely_unprivileged_apis_.count(name) || |
| 585 partially_unprivileged_apis_.count(name); | 605 partially_unprivileged_apis_.count(name); |
| 586 } | 606 } |
| 587 | 607 |
| 588 } // namespace extensions | 608 } // namespace extensions |
| OLD | NEW |