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/extension_urls.h"
10 #include "extensions/common/features/api_feature.h"
11 #include "extensions/common/features/base_feature_provider.h"
12 #include "extensions/common/features/behavior_feature.h"
13 #include "extensions/common/features/feature_provider.h"
14 #include "extensions/common/features/json_feature_provider_source.h"
15 #include "extensions/common/features/manifest_feature.h"
16 #include "extensions/common/features/permission_feature.h"
17 #include "extensions/common/manifest_handler.h"
18 #include "extensions/common/permissions/extensions_api_permissions.h"
19 #include "extensions/common/permissions/permissions_info.h"
20 #include "extensions/common/url_pattern_set.h"
21 #include "extensions/test/test_permission_message_provider.h"
22 #include "grit/extensions_resources.h"
24 namespace extensions
{
28 template <class FeatureClass
>
29 SimpleFeature
* CreateFeature() {
30 return new FeatureClass
;
35 TestExtensionsClient::TestExtensionsClient() {
38 TestExtensionsClient::~TestExtensionsClient() {
41 void TestExtensionsClient::Initialize() {
42 // Registration could already be finalized in unit tests, where the utility
43 // thread runs in-process.
44 if (!ManifestHandler::IsRegistrationFinalized()) {
45 RegisterCommonManifestHandlers();
46 ManifestHandler::FinalizeRegistration();
49 // Allow the core API permissions.
50 static ExtensionsAPIPermissions extensions_api_permissions
;
51 PermissionsInfo::GetInstance()->AddProvider(extensions_api_permissions
);
54 const PermissionMessageProvider
&
55 TestExtensionsClient::GetPermissionMessageProvider() const {
56 static TestPermissionMessageProvider provider
;
60 const std::string
TestExtensionsClient::GetProductName() {
61 return "extensions_test";
64 scoped_ptr
<FeatureProvider
> TestExtensionsClient::CreateFeatureProvider(
65 const std::string
& name
) const {
66 scoped_ptr
<FeatureProvider
> provider
;
67 scoped_ptr
<JSONFeatureProviderSource
> source(
68 CreateFeatureProviderSource(name
));
70 provider
.reset(new BaseFeatureProvider(source
->dictionary(),
71 CreateFeature
<APIFeature
>));
72 } else if (name
== "manifest") {
73 provider
.reset(new BaseFeatureProvider(source
->dictionary(),
74 CreateFeature
<ManifestFeature
>));
75 } else if (name
== "permission") {
76 provider
.reset(new BaseFeatureProvider(source
->dictionary(),
77 CreateFeature
<PermissionFeature
>));
78 } else if (name
== "behavior") {
79 provider
.reset(new BaseFeatureProvider(source
->dictionary(),
80 CreateFeature
<BehaviorFeature
>));
84 return provider
.Pass();
87 scoped_ptr
<JSONFeatureProviderSource
>
88 TestExtensionsClient::CreateFeatureProviderSource(
89 const std::string
& name
) const {
90 scoped_ptr
<JSONFeatureProviderSource
> source(
91 new JSONFeatureProviderSource(name
));
93 source
->LoadJSON(IDR_EXTENSION_API_FEATURES
);
94 } else if (name
== "manifest") {
95 source
->LoadJSON(IDR_EXTENSION_MANIFEST_FEATURES
);
96 } else if (name
== "permission") {
97 source
->LoadJSON(IDR_EXTENSION_PERMISSION_FEATURES
);
98 } else if (name
== "behavior") {
99 source
->LoadJSON(IDR_EXTENSION_BEHAVIOR_FEATURES
);
104 return source
.Pass();
107 void TestExtensionsClient::FilterHostPermissions(
108 const URLPatternSet
& hosts
,
109 URLPatternSet
* new_hosts
,
110 std::set
<PermissionMessage
>* messages
) const {
113 void TestExtensionsClient::FilterHostPermissions(
114 const URLPatternSet
& hosts
,
115 URLPatternSet
* new_hosts
,
116 PermissionIDSet
* permissions
) const {
119 void TestExtensionsClient::SetScriptingWhitelist(
120 const ExtensionsClient::ScriptingWhitelist
& whitelist
) {
121 scripting_whitelist_
= whitelist
;
124 const ExtensionsClient::ScriptingWhitelist
&
125 TestExtensionsClient::GetScriptingWhitelist() const {
126 return scripting_whitelist_
;
129 URLPatternSet
TestExtensionsClient::GetPermittedChromeSchemeHosts(
130 const Extension
* extension
,
131 const APIPermissionSet
& api_permissions
) const {
136 bool TestExtensionsClient::IsScriptableURL(const GURL
& url
,
137 std::string
* error
) const {
141 bool TestExtensionsClient::IsAPISchemaGenerated(
142 const std::string
& name
) const {
143 return core_api::GeneratedSchemas::IsGenerated(name
);
146 base::StringPiece
TestExtensionsClient::GetAPISchema(
147 const std::string
& name
) const {
148 return core_api::GeneratedSchemas::Get(name
);
151 void TestExtensionsClient::RegisterAPISchemaResources(ExtensionAPI
* api
) const {
154 bool TestExtensionsClient::ShouldSuppressFatalErrors() const {
158 std::string
TestExtensionsClient::GetWebstoreBaseURL() const {
159 return extension_urls::kChromeWebstoreBaseURL
;
162 std::string
TestExtensionsClient::GetWebstoreUpdateURL() const {
163 return extension_urls::kChromeWebstoreUpdateURL
;
166 bool TestExtensionsClient::IsBlacklistUpdateURL(const GURL
& url
) const {
170 std::set
<base::FilePath
> TestExtensionsClient::GetBrowserImagePaths(
171 const Extension
* extension
) {
172 return std::set
<base::FilePath
>();
175 } // namespace extensions