1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "extensions/test/test_extensions_client.h"
7 #include "extensions/common/api/generated_schemas.h"
8 #include "extensions/common/common_manifest_handlers.h"
9 #include "extensions/common/features/api_feature.h"
10 #include "extensions/common/features/base_feature_provider.h"
11 #include "extensions/common/features/feature_provider.h"
12 #include "extensions/common/features/json_feature_provider_source.h"
13 #include "extensions/common/features/manifest_feature.h"
14 #include "extensions/common/features/permission_feature.h"
15 #include "extensions/common/manifest_handler.h"
16 #include "extensions/common/url_pattern_set.h"
17 #include "extensions/test/test_permission_message_provider.h"
18 #include "grit/extensions_resources.h"
20 namespace extensions
{
24 template <class FeatureClass
>
25 SimpleFeature
* CreateFeature() {
26 return new FeatureClass
;
31 TestExtensionsClient::TestExtensionsClient() {
34 TestExtensionsClient::~TestExtensionsClient() {
37 void TestExtensionsClient::Initialize() {
38 // Registration could already be finalized in unit tests, where the utility
39 // thread runs in-process.
40 if (!ManifestHandler::IsRegistrationFinalized()) {
41 RegisterCommonManifestHandlers();
42 ManifestHandler::FinalizeRegistration();
46 const PermissionMessageProvider
&
47 TestExtensionsClient::GetPermissionMessageProvider() const {
48 static TestPermissionMessageProvider provider
;
52 scoped_ptr
<FeatureProvider
> TestExtensionsClient::CreateFeatureProvider(
53 const std::string
& name
) const {
54 scoped_ptr
<FeatureProvider
> provider
;
55 scoped_ptr
<JSONFeatureProviderSource
> source(
56 CreateFeatureProviderSource(name
));
58 provider
.reset(new BaseFeatureProvider(source
->dictionary(),
59 CreateFeature
<APIFeature
>));
60 } else if (name
== "manifest") {
61 provider
.reset(new BaseFeatureProvider(source
->dictionary(),
62 CreateFeature
<ManifestFeature
>));
63 } else if (name
== "permission") {
64 provider
.reset(new BaseFeatureProvider(source
->dictionary(),
65 CreateFeature
<PermissionFeature
>));
69 return provider
.Pass();
72 scoped_ptr
<JSONFeatureProviderSource
>
73 TestExtensionsClient::CreateFeatureProviderSource(
74 const std::string
& name
) const {
75 scoped_ptr
<JSONFeatureProviderSource
> source(
76 new JSONFeatureProviderSource(name
));
78 source
->LoadJSON(IDR_EXTENSION_API_FEATURES
);
79 } else if (name
== "manifest") {
80 source
->LoadJSON(IDR_EXTENSION_MANIFEST_FEATURES
);
81 } else if (name
== "permission") {
82 source
->LoadJSON(IDR_EXTENSION_PERMISSION_FEATURES
);
90 void TestExtensionsClient::FilterHostPermissions(
91 const URLPatternSet
& hosts
,
92 URLPatternSet
* new_hosts
,
93 std::set
<PermissionMessage
>* messages
) const {
96 void TestExtensionsClient::SetScriptingWhitelist(
97 const ExtensionsClient::ScriptingWhitelist
& whitelist
) {
98 scripting_whitelist_
= whitelist
;
101 const ExtensionsClient::ScriptingWhitelist
&
102 TestExtensionsClient::GetScriptingWhitelist() const {
103 return scripting_whitelist_
;
106 URLPatternSet
TestExtensionsClient::GetPermittedChromeSchemeHosts(
107 const Extension
* extension
,
108 const APIPermissionSet
& api_permissions
) const {
113 bool TestExtensionsClient::IsScriptableURL(const GURL
& url
,
114 std::string
* error
) const {
118 bool TestExtensionsClient::IsAPISchemaGenerated(
119 const std::string
& name
) const {
120 return core_api::GeneratedSchemas::IsGenerated(name
);
123 base::StringPiece
TestExtensionsClient::GetAPISchema(
124 const std::string
& name
) const {
125 return core_api::GeneratedSchemas::Get(name
);
128 void TestExtensionsClient::RegisterAPISchemaResources(ExtensionAPI
* api
) const {
131 bool TestExtensionsClient::ShouldSuppressFatalErrors() const {
135 } // namespace extensions