| 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 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 std::string feature_name; | 419 std::string feature_name; |
| 420 SplitDependencyName(full_name, &feature_type, &feature_name); | 420 SplitDependencyName(full_name, &feature_type, &feature_name); |
| 421 | 421 |
| 422 std::string child_name; | 422 std::string child_name; |
| 423 std::string api_name = GetAPINameFromFullName(feature_name, &child_name); | 423 std::string api_name = GetAPINameFromFullName(feature_name, &child_name); |
| 424 | 424 |
| 425 Feature* feature = GetFeatureDependency(full_name); | 425 Feature* feature = GetFeatureDependency(full_name); |
| 426 | 426 |
| 427 // Check APIs not using the feature system first. | 427 // Check APIs not using the feature system first. |
| 428 if (!feature) { | 428 if (!feature) { |
| 429 return IsNonFeatureAPIAvailable(api_name, context, extension, url) ? | 429 return IsNonFeatureAPIAvailable(api_name, context, extension, url) |
| 430 Feature::CreateAvailability(Feature::IS_AVAILABLE, "") : | 430 ? Feature::CreateAvailability(Feature::IS_AVAILABLE, |
| 431 Feature::CreateAvailability(Feature::INVALID_CONTEXT, | 431 std::string()) |
| 432 kUnavailableMessage); | 432 : Feature::CreateAvailability(Feature::INVALID_CONTEXT, |
| 433 kUnavailableMessage); |
| 433 } | 434 } |
| 434 | 435 |
| 435 Feature::Availability availability = | 436 Feature::Availability availability = |
| 436 feature->IsAvailableToContext(extension, context, url); | 437 feature->IsAvailableToContext(extension, context, url); |
| 437 if (!availability.is_available()) | 438 if (!availability.is_available()) |
| 438 return availability; | 439 return availability; |
| 439 | 440 |
| 440 for (std::set<std::string>::iterator iter = feature->dependencies().begin(); | 441 for (std::set<std::string>::iterator iter = feature->dependencies().begin(); |
| 441 iter != feature->dependencies().end(); ++iter) { | 442 iter != feature->dependencies().end(); ++iter) { |
| 442 Feature::Availability dependency_availability = | 443 Feature::Availability dependency_availability = |
| 443 IsAvailable(*iter, extension, context, url); | 444 IsAvailable(*iter, extension, context, url); |
| 444 if (!dependency_availability.is_available()) | 445 if (!dependency_availability.is_available()) |
| 445 return dependency_availability; | 446 return dependency_availability; |
| 446 } | 447 } |
| 447 | 448 |
| 448 return Feature::CreateAvailability(Feature::IS_AVAILABLE, ""); | 449 return Feature::CreateAvailability(Feature::IS_AVAILABLE, std::string()); |
| 449 } | 450 } |
| 450 | 451 |
| 451 bool ExtensionAPI::IsPrivileged(const std::string& full_name) { | 452 bool ExtensionAPI::IsPrivileged(const std::string& full_name) { |
| 452 std::string child_name; | 453 std::string child_name; |
| 453 std::string api_name = GetAPINameFromFullName(full_name, &child_name); | 454 std::string api_name = GetAPINameFromFullName(full_name, &child_name); |
| 454 Feature* feature = GetFeatureDependency(full_name); | 455 Feature* feature = GetFeatureDependency(full_name); |
| 455 | 456 |
| 456 // First try to use the feature system. | 457 // First try to use the feature system. |
| 457 if (feature) { | 458 if (feature) { |
| 458 // An API is 'privileged' if it can only be run in a blessed context. | 459 // An API is 'privileged' if it can only be run in a blessed context. |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 } | 628 } |
| 628 | 629 |
| 629 size_t last_dot_index = api_name_candidate.rfind('.'); | 630 size_t last_dot_index = api_name_candidate.rfind('.'); |
| 630 if (last_dot_index == std::string::npos) | 631 if (last_dot_index == std::string::npos) |
| 631 break; | 632 break; |
| 632 | 633 |
| 633 api_name_candidate = api_name_candidate.substr(0, last_dot_index); | 634 api_name_candidate = api_name_candidate.substr(0, last_dot_index); |
| 634 } | 635 } |
| 635 | 636 |
| 636 *child_name = ""; | 637 *child_name = ""; |
| 637 return ""; | 638 return std::string(); |
| 638 } | 639 } |
| 639 | 640 |
| 640 bool ExtensionAPI::IsAPIAllowed(const std::string& name, | 641 bool ExtensionAPI::IsAPIAllowed(const std::string& name, |
| 641 const Extension* extension) { | 642 const Extension* extension) { |
| 642 return extension->required_permission_set()->HasAnyAccessToAPI(name) || | 643 return extension->required_permission_set()->HasAnyAccessToAPI(name) || |
| 643 extension->optional_permission_set()->HasAnyAccessToAPI(name); | 644 extension->optional_permission_set()->HasAnyAccessToAPI(name); |
| 644 } | 645 } |
| 645 | 646 |
| 646 bool ExtensionAPI::IsPrivilegedAPI(const std::string& name) { | 647 bool ExtensionAPI::IsPrivilegedAPI(const std::string& name) { |
| 647 return completely_unprivileged_apis_.count(name) || | 648 return completely_unprivileged_apis_.count(name) || |
| 648 partially_unprivileged_apis_.count(name); | 649 partially_unprivileged_apis_.count(name); |
| 649 } | 650 } |
| 650 | 651 |
| 651 } // namespace extensions | 652 } // namespace extensions |
| OLD | NEW |