summaryrefslogtreecommitdiffstats
path: root/extensions
diff options
context:
space:
mode:
authoryoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-22 04:27:37 +0000
committeryoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-22 04:27:37 +0000
commitbc495a181abbd42debc3067b48d3092feec7ccee (patch)
treeb079b740643102b0ebce090b69811cb925c9f2a7 /extensions
parentf39efb923be05f39f300e2b4aa04afd3d4c0e532 (diff)
downloadchromium_src-bc495a181abbd42debc3067b48d3092feec7ccee.zip
chromium_src-bc495a181abbd42debc3067b48d3092feec7ccee.tar.gz
chromium_src-bc495a181abbd42debc3067b48d3092feec7ccee.tar.bz2
Clean up TestFeaturesNativeHandler to use the ExtensionsClient's JSON feature sources.
This makes TestFeaturesNativeHandler less Chrome-specific. Also add more const to FeatureProvider. Remove common_resources.h from extensions DEPS. BUG=368334 TBR=sky@chromium.org Review URL: https://codereview.chromium.org/293943002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272097 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions')
-rw-r--r--extensions/DEPS1
-rw-r--r--extensions/common/extension_api.cc3
-rw-r--r--extensions/common/extension_api.h4
-rw-r--r--extensions/common/extensions_client.h8
-rw-r--r--extensions/common/features/base_feature_provider_unittest.cc5
-rw-r--r--extensions/common/features/feature_provider.cc8
-rw-r--r--extensions/common/features/feature_provider.h8
-rw-r--r--extensions/common/manifest.cc2
-rw-r--r--extensions/common/permissions/permissions_data.cc2
-rw-r--r--extensions/renderer/api_definitions_natives.cc2
-rw-r--r--extensions/renderer/dispatcher.cc7
-rw-r--r--extensions/renderer/test_features_native_handler.cc12
-rw-r--r--extensions/test/test_extensions_client.cc12
-rw-r--r--extensions/test/test_extensions_client.h2
14 files changed, 45 insertions, 31 deletions
diff --git a/extensions/DEPS b/extensions/DEPS
index 9d6a6a0..0fc52ca 100644
--- a/extensions/DEPS
+++ b/extensions/DEPS
@@ -13,7 +13,6 @@ include_rules = [
#
# TODO(jamescook): Remove these. http://crbug.com/162530
"!chrome/browser/chrome_notification_types.h",
- "!grit/common_resources.h",
'!grit/extensions_api_resources.h',
# This is needed for renderer JS sources which should eventually move to
# the extensions_resources target.
diff --git a/extensions/common/extension_api.cc b/extensions/common/extension_api.cc
index f2483b9..4d6b6ec 100644
--- a/extensions/common/extension_api.cc
+++ b/extensions/common/extension_api.cc
@@ -22,7 +22,6 @@
#include "extensions/common/features/feature_provider.h"
#include "extensions/common/permissions/permission_set.h"
#include "extensions/common/permissions/permissions_data.h"
-#include "grit/common_resources.h"
#include "grit/extensions_api_resources.h"
#include "ui/base/resource/resource_bundle.h"
#include "url/gurl.h"
@@ -266,7 +265,7 @@ void ExtensionAPI::RegisterSchemaResource(const std::string& name,
}
void ExtensionAPI::RegisterDependencyProvider(const std::string& name,
- FeatureProvider* provider) {
+ const FeatureProvider* provider) {
dependency_providers_[name] = provider;
}
diff --git a/extensions/common/extension_api.h b/extensions/common/extension_api.h
index 53906fb..bd2e315 100644
--- a/extensions/common/extension_api.h
+++ b/extensions/common/extension_api.h
@@ -63,7 +63,7 @@ class ExtensionAPI {
void RegisterSchemaResource(const std::string& api_name, int resource_id);
void RegisterDependencyProvider(const std::string& name,
- FeatureProvider* provider);
+ const FeatureProvider* provider);
// Returns true if the API feature |api| and all of its dependencies are
// available in |context|.
@@ -139,7 +139,7 @@ class ExtensionAPI {
SchemaMap schemas_;
// FeatureProviders used for resolving dependencies.
- typedef std::map<std::string, FeatureProvider*> FeatureProviderMap;
+ typedef std::map<std::string, const FeatureProvider*> FeatureProviderMap;
FeatureProviderMap dependency_providers_;
DISALLOW_COPY_AND_ASSIGN(ExtensionAPI);
diff --git a/extensions/common/extensions_client.h b/extensions/common/extensions_client.h
index b3e9892..f0bdc8c 100644
--- a/extensions/common/extensions_client.h
+++ b/extensions/common/extensions_client.h
@@ -19,6 +19,7 @@ namespace extensions {
class APIPermissionSet;
class Extension;
class FeatureProvider;
+class JSONFeatureProviderSource;
class ManifestPermissionSet;
class PermissionMessage;
class PermissionMessageProvider;
@@ -47,6 +48,13 @@ class ExtensionsClient {
virtual scoped_ptr<FeatureProvider> CreateFeatureProvider(
const std::string& name) const = 0;
+ // Create a JSONFeatureProviderSource for a specific feature type,
+ // e.g. "permission". Currently, all features are loaded from
+ // JSONFeatureProviderSources.
+ // This is used primarily in CreateFeatureProvider, above.
+ virtual scoped_ptr<JSONFeatureProviderSource> CreateFeatureProviderSource(
+ const std::string& name) const = 0;
+
// Takes the list of all hosts and filters out those with special
// permission strings. Adds the regular hosts to |new_hosts|,
// and adds the special permission messages to |messages|.
diff --git a/extensions/common/features/base_feature_provider_unittest.cc b/extensions/common/features/base_feature_provider_unittest.cc
index 0d19fd4..28c8ded 100644
--- a/extensions/common/features/base_feature_provider_unittest.cc
+++ b/extensions/common/features/base_feature_provider_unittest.cc
@@ -27,7 +27,7 @@ SimpleFeature* CreateFeature() {
} // namespace
TEST(BaseFeatureProviderTest, ManifestFeatures) {
- FeatureProvider* provider = BaseFeatureProvider::GetByName("manifest");
+ const FeatureProvider* provider = BaseFeatureProvider::GetByName("manifest");
SimpleFeature* feature =
static_cast<SimpleFeature*>(provider->GetFeature("description"));
ASSERT_TRUE(feature);
@@ -70,7 +70,8 @@ TEST(BaseFeatureProviderTest, ManifestFeatures) {
}
TEST(BaseFeatureProviderTest, PermissionFeatures) {
- FeatureProvider* provider = BaseFeatureProvider::GetByName("permission");
+ const FeatureProvider* provider =
+ BaseFeatureProvider::GetByName("permission");
SimpleFeature* feature =
static_cast<SimpleFeature*>(provider->GetFeature("contextMenus"));
ASSERT_TRUE(feature);
diff --git a/extensions/common/features/feature_provider.cc b/extensions/common/features/feature_provider.cc
index b8f21f3..1923836 100644
--- a/extensions/common/features/feature_provider.cc
+++ b/extensions/common/features/feature_provider.cc
@@ -47,22 +47,22 @@ base::LazyInstance<Static> g_static = LAZY_INSTANCE_INITIALIZER;
} // namespace
// static
-FeatureProvider* FeatureProvider::GetByName(const std::string& name) {
+const FeatureProvider* FeatureProvider::GetByName(const std::string& name) {
return g_static.Get().GetFeatures(name);
}
// static
-FeatureProvider* FeatureProvider::GetAPIFeatures() {
+const FeatureProvider* FeatureProvider::GetAPIFeatures() {
return GetByName("api");
}
// static
-FeatureProvider* FeatureProvider::GetManifestFeatures() {
+const FeatureProvider* FeatureProvider::GetManifestFeatures() {
return GetByName("manifest");
}
// static
-FeatureProvider* FeatureProvider::GetPermissionFeatures() {
+const FeatureProvider* FeatureProvider::GetPermissionFeatures() {
return GetByName("permission");
}
diff --git a/extensions/common/features/feature_provider.h b/extensions/common/features/feature_provider.h
index 97f94c65..887cb22 100644
--- a/extensions/common/features/feature_provider.h
+++ b/extensions/common/features/feature_provider.h
@@ -31,12 +31,12 @@ class FeatureProvider {
virtual const std::vector<std::string>& GetAllFeatureNames() const = 0;
// Gets a feature provider for a specific feature type, like "permission".
- static FeatureProvider* GetByName(const std::string& name);
+ static const FeatureProvider* GetByName(const std::string& name);
// Directly access the common feature types.
- static FeatureProvider* GetAPIFeatures();
- static FeatureProvider* GetManifestFeatures();
- static FeatureProvider* GetPermissionFeatures();
+ static const FeatureProvider* GetAPIFeatures();
+ static const FeatureProvider* GetManifestFeatures();
+ static const FeatureProvider* GetPermissionFeatures();
};
} // namespace extensions
diff --git a/extensions/common/manifest.cc b/extensions/common/manifest.cc
index bbf2ff8..37880d4 100644
--- a/extensions/common/manifest.cc
+++ b/extensions/common/manifest.cc
@@ -146,7 +146,7 @@ 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* manifest_feature_provider =
+ const FeatureProvider* manifest_feature_provider =
FeatureProvider::GetManifestFeatures();
const std::vector<std::string>& feature_names =
manifest_feature_provider->GetAllFeatureNames();
diff --git a/extensions/common/permissions/permissions_data.cc b/extensions/common/permissions/permissions_data.cc
index 65359d9..ae3dd04 100644
--- a/extensions/common/permissions/permissions_data.cc
+++ b/extensions/common/permissions/permissions_data.cc
@@ -119,7 +119,7 @@ bool ParseHelper(Extension* extension,
// Verify feature availability of permissions.
std::vector<APIPermission::ID> to_remove;
- FeatureProvider* permission_features =
+ const FeatureProvider* permission_features =
FeatureProvider::GetPermissionFeatures();
for (APIPermissionSet::const_iterator iter = api_permissions->begin();
iter != api_permissions->end(); ++iter) {
diff --git a/extensions/renderer/api_definitions_natives.cc b/extensions/renderer/api_definitions_natives.cc
index c0dc699..61ea710 100644
--- a/extensions/renderer/api_definitions_natives.cc
+++ b/extensions/renderer/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::GetAPIFeatures();
+ const 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/extensions/renderer/dispatcher.cc b/extensions/renderer/dispatcher.cc
index a3014ed..bba2087 100644
--- a/extensions/renderer/dispatcher.cc
+++ b/extensions/renderer/dispatcher.cc
@@ -73,7 +73,6 @@
#include "extensions/renderer/user_script_slave.h"
#include "extensions/renderer/utils_native_handler.h"
#include "extensions/renderer/v8_context_native_handler.h"
-#include "grit/common_resources.h"
#include "grit/renderer_resources.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/platform/WebURLRequest.h"
@@ -867,7 +866,8 @@ void Dispatcher::UpdateBindingsForContext(ScriptContext* context) {
case Feature::CONTENT_SCRIPT_CONTEXT: {
// Extension context; iterate through all the APIs and bind the available
// ones.
- FeatureProvider* api_feature_provider = FeatureProvider::GetAPIFeatures();
+ const FeatureProvider* api_feature_provider =
+ FeatureProvider::GetAPIFeatures();
const std::vector<std::string>& apis =
api_feature_provider->GetAllFeatureNames();
for (std::vector<std::string>::const_iterator it = apis.begin();
@@ -1187,7 +1187,8 @@ 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* api_feature_provider = FeatureProvider::GetAPIFeatures();
+ const FeatureProvider* api_feature_provider =
+ FeatureProvider::GetAPIFeatures();
std::string ancestor_name;
bool only_ancestor_available = false;
diff --git a/extensions/renderer/test_features_native_handler.cc b/extensions/renderer/test_features_native_handler.cc
index 6e0423d..c27575c 100644
--- a/extensions/renderer/test_features_native_handler.cc
+++ b/extensions/renderer/test_features_native_handler.cc
@@ -6,10 +6,9 @@
#include "base/bind.h"
#include "content/public/renderer/v8_value_converter.h"
+#include "extensions/common/extensions_client.h"
#include "extensions/common/features/json_feature_provider_source.h"
#include "extensions/renderer/script_context.h"
-#include "grit/common_resources.h"
-#include "grit/extensions_resources.h"
namespace extensions {
@@ -22,15 +21,12 @@ TestFeaturesNativeHandler::TestFeaturesNativeHandler(ScriptContext* context)
void TestFeaturesNativeHandler::GetAPIFeatures(
const v8::FunctionCallbackInfo<v8::Value>& args) {
- JSONFeatureProviderSource source("api");
- // TODO(rockot): Only inlcude extensions features here. Chrome should add
- // its own native handler for Chrome features.
- source.LoadJSON(IDR_CHROME_EXTENSION_API_FEATURES);
- source.LoadJSON(IDR_EXTENSION_API_FEATURES);
+ scoped_ptr<JSONFeatureProviderSource> source(
+ ExtensionsClient::Get()->CreateFeatureProviderSource("api"));
scoped_ptr<content::V8ValueConverter> converter(
content::V8ValueConverter::create());
args.GetReturnValue().Set(
- converter->ToV8Value(&source.dictionary(), context()->v8_context()));
+ converter->ToV8Value(&source->dictionary(), context()->v8_context()));
}
} // namespace extensions
diff --git a/extensions/test/test_extensions_client.cc b/extensions/test/test_extensions_client.cc
index 90888a7..7ef0277 100644
--- a/extensions/test/test_extensions_client.cc
+++ b/extensions/test/test_extensions_client.cc
@@ -5,10 +5,11 @@
#include "extensions/test/test_extensions_client.h"
#include "extensions/common/common_manifest_handlers.h"
-#include "extensions/common/features/base_feature_provider.h"
+#include "extensions/common/features/feature_provider.h"
+#include "extensions/common/features/json_feature_provider_source.h"
#include "extensions/common/manifest_handler.h"
+#include "extensions/common/url_pattern_set.h"
#include "extensions/test/test_permission_message_provider.h"
-#include "extensions/test/test_permissions_provider.h"
namespace extensions {
@@ -39,6 +40,13 @@ scoped_ptr<FeatureProvider> TestExtensionsClient::CreateFeatureProvider(
return scoped_ptr<FeatureProvider>();
}
+// TODO(yoz): Implement something reasonable here.
+scoped_ptr<JSONFeatureProviderSource>
+TestExtensionsClient::CreateFeatureProviderSource(
+ const std::string& name) const {
+ return scoped_ptr<JSONFeatureProviderSource>();
+}
+
void TestExtensionsClient::FilterHostPermissions(
const URLPatternSet& hosts,
URLPatternSet* new_hosts,
diff --git a/extensions/test/test_extensions_client.h b/extensions/test/test_extensions_client.h
index 082c7ab..399f43f 100644
--- a/extensions/test/test_extensions_client.h
+++ b/extensions/test/test_extensions_client.h
@@ -21,6 +21,8 @@ class TestExtensionsClient : public ExtensionsClient {
OVERRIDE;
virtual scoped_ptr<FeatureProvider> CreateFeatureProvider(
const std::string& name) const OVERRIDE;
+ virtual scoped_ptr<JSONFeatureProviderSource> CreateFeatureProviderSource(
+ const std::string& name) const OVERRIDE;
virtual void FilterHostPermissions(
const URLPatternSet& hosts,
URLPatternSet* new_hosts,