| 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 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 void ExtensionAPI::RegisterSchema(const std::string& name, | 402 void ExtensionAPI::RegisterSchema(const std::string& name, |
| 403 const base::StringPiece& source) { | 403 const base::StringPiece& source) { |
| 404 unloaded_schemas_[name] = source; | 404 unloaded_schemas_[name] = source; |
| 405 } | 405 } |
| 406 | 406 |
| 407 void ExtensionAPI::RegisterDependencyProvider(const std::string& name, | 407 void ExtensionAPI::RegisterDependencyProvider(const std::string& name, |
| 408 FeatureProvider* provider) { | 408 FeatureProvider* provider) { |
| 409 dependency_providers_[name] = provider; | 409 dependency_providers_[name] = provider; |
| 410 } | 410 } |
| 411 | 411 |
| 412 bool ExtensionAPI::IsPartAvailableToContext(const std::string& api_name, |
| 413 Feature::Context context, |
| 414 const GURL& url) { |
| 415 FeatureProviderMap::iterator provider = dependency_providers_.find("api"); |
| 416 CHECK(provider != dependency_providers_.end()); |
| 417 std::set<std::string> features = provider->second->GetAllFeatureNames(); |
| 418 |
| 419 // Check to see if there are any parts of this API that are allowed in this |
| 420 // context. |
| 421 for (std::set<std::string>::iterator i = features.begin(); |
| 422 i != features.end(); ++i) { |
| 423 const std::string& feature_name = *i; |
| 424 if (feature_name != api_name && feature_name.find(api_name + ".") == 0) { |
| 425 if (IsAvailable(feature_name, NULL, context, url).is_available()) |
| 426 return true; |
| 427 } |
| 428 } |
| 429 return IsAvailable(api_name, NULL, context, url).is_available(); |
| 430 } |
| 431 |
| 412 Feature::Availability ExtensionAPI::IsAvailable(const std::string& full_name, | 432 Feature::Availability ExtensionAPI::IsAvailable(const std::string& full_name, |
| 413 const Extension* extension, | 433 const Extension* extension, |
| 414 Feature::Context context, | 434 Feature::Context context, |
| 415 const GURL& url) { | 435 const GURL& url) { |
| 416 std::string feature_type; | 436 std::string feature_type; |
| 417 std::string feature_name; | 437 std::string feature_name; |
| 418 SplitDependencyName(full_name, &feature_type, &feature_name); | 438 SplitDependencyName(full_name, &feature_type, &feature_name); |
| 419 | 439 |
| 420 std::string child_name; | 440 std::string child_name; |
| 421 std::string api_name = GetAPINameFromFullName(feature_name, &child_name); | 441 std::string api_name = GetAPINameFromFullName(feature_name, &child_name); |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 return extension->required_permission_set()->HasAnyAccessToAPI(name) || | 661 return extension->required_permission_set()->HasAnyAccessToAPI(name) || |
| 642 extension->optional_permission_set()->HasAnyAccessToAPI(name); | 662 extension->optional_permission_set()->HasAnyAccessToAPI(name); |
| 643 } | 663 } |
| 644 | 664 |
| 645 bool ExtensionAPI::IsPrivilegedAPI(const std::string& name) { | 665 bool ExtensionAPI::IsPrivilegedAPI(const std::string& name) { |
| 646 return completely_unprivileged_apis_.count(name) || | 666 return completely_unprivileged_apis_.count(name) || |
| 647 partially_unprivileged_apis_.count(name); | 667 partially_unprivileged_apis_.count(name); |
| 648 } | 668 } |
| 649 | 669 |
| 650 } // namespace extensions | 670 } // namespace extensions |
| OLD | NEW |