Chromium Code Reviews| Index: extensions/common/extension_api.cc |
| diff --git a/extensions/common/extension_api.cc b/extensions/common/extension_api.cc |
| index 44aa787ebcd85495e5d1b954bbf6bfe75c2272d0..6913f630e47b0749cca9777fde4d34d92fbb62e7 100644 |
| --- a/extensions/common/extension_api.cc |
| +++ b/extensions/common/extension_api.cc |
| @@ -170,10 +170,12 @@ void ExtensionAPI::RegisterDependencyProvider(const std::string& name, |
| dependency_providers_[name] = provider; |
| } |
| -bool ExtensionAPI::IsAnyFeatureAvailableToContext(const Feature& api, |
| - const Extension* extension, |
| - Feature::Context context, |
| - const GURL& url) { |
| +bool ExtensionAPI::IsAnyFeatureAvailableToContext( |
| + const Feature& api, |
| + const Extension* extension, |
| + Feature::Context context, |
| + const GURL& url, |
| + CheckAliasStatus alias_status) { |
| FeatureProviderMap::iterator provider = dependency_providers_.find("api"); |
| CHECK(provider != dependency_providers_.end()); |
| @@ -189,19 +191,40 @@ bool ExtensionAPI::IsAnyFeatureAvailableToContext(const Feature& api, |
| if ((*it)->IsAvailableToContext(extension, context, url).is_available()) |
| return true; |
| } |
| - return false; |
| + |
| + if (alias_status != CheckAliasStatus::ALLOWED) |
| + return false; |
| + |
| + const std::string& alias_name = api.alias(); |
| + if (alias_name.empty()) |
| + return false; |
| + |
| + const Feature* alias = provider->second->GetFeature(alias_name); |
| + CHECK(alias) << "Cannot find alias feature " << alias_name |
| + << " for API feature " << api.name(); |
| + return IsAnyFeatureAvailableToContext(*alias, extension, context, url, |
| + CheckAliasStatus::NOT_ALLOWED); |
| } |
| Feature::Availability ExtensionAPI::IsAvailable(const std::string& full_name, |
| const Extension* extension, |
| Feature::Context context, |
| - const GURL& url) { |
| + const GURL& url, |
| + CheckAliasStatus alias_status) { |
| Feature* feature = GetFeatureDependency(full_name); |
| if (!feature) { |
| return Feature::Availability(Feature::NOT_PRESENT, |
| std::string("Unknown feature: ") + full_name); |
| } |
| - return feature->IsAvailableToContext(extension, context, url); |
| + |
| + Feature::Availability availability = |
| + feature->IsAvailableToContext(extension, context, url); |
| + if (availability.is_available() || alias_status != CheckAliasStatus::ALLOWED) |
| + return availability; |
| + |
| + Feature::Availability alias_availability = |
| + IsAliasAvailable(full_name, feature, extension, context, url); |
| + return alias_availability.is_available() ? alias_availability : availability; |
| } |
| base::StringPiece ExtensionAPI::GetSchemaStringPiece( |
| @@ -304,4 +327,34 @@ bool ExtensionAPI::IsKnownAPI(const std::string& name, |
| client->IsAPISchemaGenerated(name); |
| } |
| +Feature::Availability ExtensionAPI::IsAliasAvailable( |
| + const std::string& full_name, |
| + Feature* api, |
|
Devlin
2016/11/17 01:11:15
s/api/feature
tbarzic
2016/11/17 18:12:13
Done.
|
| + const Extension* extension, |
| + Feature::Context context, |
| + const GURL& url) { |
| + const std::string& alias = api->alias(); |
| + if (alias.empty()) |
| + return Feature::Availability(Feature::NOT_PRESENT, "Alias not defined"); |
| + |
| + FeatureProviderMap::iterator provider = dependency_providers_.find("api"); |
| + CHECK(provider != dependency_providers_.end()); |
| + |
| + // Check if there is a child feature associated with full name for alias API. |
|
Devlin
2016/11/17 01:11:15
Can you give an example of when this would be the
tbarzic
2016/11/17 18:12:13
Done.
|
| + std::string child_name; |
| + GetAPINameFromFullName(full_name, &child_name); |
| + std::string full_alias_name = alias + "." + child_name; |
| + Feature* alias_feature = provider->second->GetFeature(full_alias_name); |
| + |
| + // If there is no child feature, use the alias API feature to check |
| + // availability. |
| + if (!alias_feature) |
| + alias_feature = provider->second->GetFeature(alias); |
| + |
| + CHECK(alias_feature) << "Cannot find alias feature " << alias |
| + << " for API feature " << api->name(); |
| + |
| + return alias_feature->IsAvailableToContext(extension, context, url); |
| +} |
| + |
| } // namespace extensions |