diff options
author | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-07 20:44:41 +0000 |
---|---|---|
committer | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-07 20:44:41 +0000 |
commit | 276f05aa5fc98df61d947ccaf7480bca9c021730 (patch) | |
tree | 39f71a9d3ea8be562d942b702172e5e6b6c56433 | |
parent | c6176da0f310db393db5f02269f2e83cbe17aacf (diff) | |
download | chromium_src-276f05aa5fc98df61d947ccaf7480bca9c021730.zip chromium_src-276f05aa5fc98df61d947ccaf7480bca9c021730.tar.gz chromium_src-276f05aa5fc98df61d947ccaf7480bca9c021730.tar.bz2 |
Add FeatureProvider::GetAPIFeatures, GetManifestFeatures, and
GetPermissionFeatures as shortcuts for FeatureProvider::GetByName.
R=yoz@chromium.org
Review URL: https://codereview.chromium.org/25943002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@227338 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/common/extensions/api/extension_api.cc | 9 | ||||
-rw-r--r-- | chrome/common/extensions/permissions/permissions_data.cc | 4 | ||||
-rw-r--r-- | chrome/renderer/extensions/api_definitions_natives.cc | 2 | ||||
-rw-r--r-- | chrome/renderer/extensions/dispatcher.cc | 14 | ||||
-rw-r--r-- | chrome/renderer/extensions/runtime_custom_bindings.cc | 2 | ||||
-rw-r--r-- | extensions/common/features/feature_provider.cc | 16 | ||||
-rw-r--r-- | extensions/common/features/feature_provider.h | 5 | ||||
-rw-r--r-- | extensions/common/manifest.cc | 11 |
8 files changed, 41 insertions, 22 deletions
diff --git a/chrome/common/extensions/api/extension_api.cc b/chrome/common/extensions/api/extension_api.cc index a609ac8..f28ab3c 100644 --- a/chrome/common/extensions/api/extension_api.cc +++ b/chrome/common/extensions/api/extension_api.cc @@ -224,12 +224,9 @@ ExtensionAPI::~ExtensionAPI() { } void ExtensionAPI::InitDefaultConfiguration() { - RegisterDependencyProvider( - "api", FeatureProvider::GetByName("api")); - RegisterDependencyProvider( - "manifest", FeatureProvider::GetByName("manifest")); - RegisterDependencyProvider( - "permission", FeatureProvider::GetByName("permission")); + const char* names[] = {"api", "manifest", "permission"}; + for (size_t i = 0; i < arraysize(names); ++i) + RegisterDependencyProvider(names[i], FeatureProvider::GetByName(names[i])); // Schemas to be loaded from resources. CHECK(unloaded_schemas_.empty()); diff --git a/chrome/common/extensions/permissions/permissions_data.cc b/chrome/common/extensions/permissions/permissions_data.cc index a05a2d8..0e8adc6 100644 --- a/chrome/common/extensions/permissions/permissions_data.cc +++ b/chrome/common/extensions/permissions/permissions_data.cc @@ -12,7 +12,6 @@ #include "base/strings/utf_string_conversions.h" #include "base/values.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/features/base_feature_provider.h" #include "chrome/common/extensions/permissions/api_permission_set.h" #include "chrome/common/extensions/permissions/chrome_scheme_hosts.h" #include "chrome/common/extensions/permissions/permission_set.h" @@ -21,6 +20,7 @@ #include "extensions/common/constants.h" #include "extensions/common/error_utils.h" #include "extensions/common/features/feature.h" +#include "extensions/common/features/feature_provider.h" #include "extensions/common/manifest.h" #include "extensions/common/manifest_constants.h" #include "extensions/common/manifest_constants.h" @@ -119,7 +119,7 @@ bool ParseHelper(Extension* extension, // Verify feature availability of permissions. std::vector<APIPermission::ID> to_remove; FeatureProvider* permission_features = - BaseFeatureProvider::GetByName("permission"); + FeatureProvider::GetPermissionFeatures(); for (APIPermissionSet::const_iterator iter = api_permissions->begin(); iter != api_permissions->end(); ++iter) { Feature* feature = permission_features->GetFeature(iter->name()); diff --git a/chrome/renderer/extensions/api_definitions_natives.cc b/chrome/renderer/extensions/api_definitions_natives.cc index 316daaa..37dc415 100644 --- a/chrome/renderer/extensions/api_definitions_natives.cc +++ b/chrome/renderer/extensions/api_definitions_natives.cc @@ -23,7 +23,7 @@ ApiDefinitionsNatives::ApiDefinitionsNatives(Dispatcher* dispatcher, void ApiDefinitionsNatives::GetExtensionAPIDefinitionsForTest( const v8::FunctionCallbackInfo<v8::Value>& args) { std::vector<std::string> apis; - FeatureProvider* feature_provider = FeatureProvider::GetByName("api"); + FeatureProvider* feature_provider = FeatureProvider::GetAPIFeatures(); const std::vector<std::string>& feature_names = feature_provider->GetAllFeatureNames(); for (std::vector<std::string>::const_iterator i = feature_names.begin(); diff --git a/chrome/renderer/extensions/dispatcher.cc b/chrome/renderer/extensions/dispatcher.cc index c139095..822d5e5 100644 --- a/chrome/renderer/extensions/dispatcher.cc +++ b/chrome/renderer/extensions/dispatcher.cc @@ -679,13 +679,13 @@ void Dispatcher::AddOrRemoveBindingsForContext(ChromeV8Context* context) { case Feature::CONTENT_SCRIPT_CONTEXT: { // Extension context; iterate through all the APIs and bind the available // ones. - FeatureProvider* feature_provider = FeatureProvider::GetByName("api"); + FeatureProvider* api_feature_provider = FeatureProvider::GetAPIFeatures(); const std::vector<std::string>& apis = - feature_provider->GetAllFeatureNames(); + api_feature_provider->GetAllFeatureNames(); for (std::vector<std::string>::const_iterator it = apis.begin(); it != apis.end(); ++it) { const std::string& api_name = *it; - Feature* feature = feature_provider->GetFeature(api_name); + Feature* feature = api_feature_provider->GetFeature(api_name); DCHECK(feature); // Internal APIs are included via require(api_name) from internal code @@ -696,8 +696,8 @@ void Dispatcher::AddOrRemoveBindingsForContext(ChromeV8Context* context) { // If this API name has parent features, then this must be a function or // event, so we should not register. bool parent_feature_available = false; - for (Feature* parent = feature_provider->GetParent(feature); - parent != NULL; parent = feature_provider->GetParent(parent)) { + for (Feature* parent = api_feature_provider->GetParent(feature); + parent != NULL; parent = api_feature_provider->GetParent(parent)) { if (context->IsAnyFeatureAvailableToContext(parent->name())) { parent_feature_available = true; break; @@ -733,13 +733,13 @@ v8::Handle<v8::Object> Dispatcher::GetOrCreateBindObjectIfAvailable( // If app is available and app.window is not, just install app. // If app.window is available and app is not, delete app and install // app.window on a new object so app does not have to be loaded. - FeatureProvider* feature_provider = FeatureProvider::GetByName("api"); + FeatureProvider* api_feature_provider = FeatureProvider::GetAPIFeatures(); std::string ancestor_name; bool only_ancestor_available = false; for (size_t i = 0; i < split.size() - 1; ++i) { ancestor_name += (i ? ".": "") + split[i]; - if (feature_provider->GetFeature(ancestor_name) && + if (api_feature_provider->GetFeature(ancestor_name) && context->GetAvailability(ancestor_name).is_available() && !context->GetAvailability(api_name).is_available()) { only_ancestor_available = true; diff --git a/chrome/renderer/extensions/runtime_custom_bindings.cc b/chrome/renderer/extensions/runtime_custom_bindings.cc index 45663f9..ea5f5bf 100644 --- a/chrome/renderer/extensions/runtime_custom_bindings.cc +++ b/chrome/renderer/extensions/runtime_custom_bindings.cc @@ -68,7 +68,7 @@ void RuntimeCustomBindings::OpenChannelToNativeApp( const v8::FunctionCallbackInfo<v8::Value>& args) { // Verify that the extension has permission to use native messaging. Feature::Availability availability = - FeatureProvider::GetByName("permission")-> + FeatureProvider::GetPermissionFeatures()-> GetFeature("nativeMessaging")->IsAvailableToContext( GetExtensionForRenderView(), context()->context_type(), diff --git a/extensions/common/features/feature_provider.cc b/extensions/common/features/feature_provider.cc index 8e15d4b..d5357f1 100644 --- a/extensions/common/features/feature_provider.cc +++ b/extensions/common/features/feature_provider.cc @@ -9,8 +9,24 @@ namespace extensions { +// static FeatureProvider* FeatureProvider::GetByName(const std::string& name) { return ExtensionsClient::Get()->GetFeatureProviderByName(name); } +// static +FeatureProvider* FeatureProvider::GetAPIFeatures() { + return GetByName("api"); +} + +// static +FeatureProvider* FeatureProvider::GetManifestFeatures() { + return GetByName("manifest"); +} + +// static +FeatureProvider* FeatureProvider::GetPermissionFeatures() { + return GetByName("permission"); +} + } // namespace extensions diff --git a/extensions/common/features/feature_provider.h b/extensions/common/features/feature_provider.h index c20e5d1..a295fe0 100644 --- a/extensions/common/features/feature_provider.h +++ b/extensions/common/features/feature_provider.h @@ -29,6 +29,11 @@ class FeatureProvider { // Gets a feature provider for a specific feature type, like "permission". static FeatureProvider* GetByName(const std::string& name); + + // Directly access the common feature types. + static FeatureProvider* GetAPIFeatures(); + static FeatureProvider* GetManifestFeatures(); + static FeatureProvider* GetPermissionFeatures(); }; } // namespace extensions diff --git a/extensions/common/manifest.cc b/extensions/common/manifest.cc index 39e6920..bbd8c32 100644 --- a/extensions/common/manifest.cc +++ b/extensions/common/manifest.cc @@ -145,9 +145,10 @@ bool Manifest::ValidateManifest( // TODO(aa): Consider having an error here in the case of strict error // checking to let developers know when they screw up. - FeatureProvider* provider = FeatureProvider::GetByName("manifest"); + FeatureProvider* manifest_feature_provider = + FeatureProvider::GetManifestFeatures(); const std::vector<std::string>& feature_names = - provider->GetAllFeatureNames(); + manifest_feature_provider->GetAllFeatureNames(); for (std::vector<std::string>::const_iterator feature_name = feature_names.begin(); feature_name != feature_names.end(); ++feature_name) { @@ -155,7 +156,7 @@ bool Manifest::ValidateManifest( if (!value_->Get(*feature_name, NULL)) continue; - Feature* feature = provider->GetFeature(*feature_name); + Feature* feature = manifest_feature_provider->GetFeature(*feature_name); Feature::Availability result = feature->IsAvailableToManifest( extension_id_, type_, Feature::ConvertLocation(location_), GetManifestVersion()); @@ -166,7 +167,7 @@ bool Manifest::ValidateManifest( // Also generate warnings for keys that are not features. for (base::DictionaryValue::Iterator it(*value_); !it.IsAtEnd(); it.Advance()) { - if (!provider->GetFeature(it.key())) { + if (!manifest_feature_provider->GetFeature(it.key())) { warnings->push_back(InstallWarning( ErrorUtils::FormatErrorMessage( manifest_errors::kUnrecognizedManifestKey, it.key()), @@ -253,7 +254,7 @@ bool Manifest::CanAccessPath(const std::string& path) const { } bool Manifest::CanAccessKey(const std::string& key) const { - Feature* feature = FeatureProvider::GetByName("manifest")->GetFeature(key); + Feature* feature = FeatureProvider::GetManifestFeatures()->GetFeature(key); if (!feature) return true; |