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/permissions/extensions_api_permissions.h"
17 #include "extensions/common/permissions/permissions_info.h"
18 #include "extensions/common/url_pattern_set.h"
19 #include "extensions/test/test_permission_message_provider.h"
20 #include "grit/extensions_resources.h"
22 namespace extensions
{
26 template <class FeatureClass
>
27 SimpleFeature
* CreateFeature() {
28 return new FeatureClass
;
33 TestExtensionsClient::TestExtensionsClient() {
36 TestExtensionsClient::~TestExtensionsClient() {
39 void TestExtensionsClient::Initialize() {
40 // Registration could already be finalized in unit tests, where the utility
41 // thread runs in-process.
42 if (!ManifestHandler::IsRegistrationFinalized()) {
43 RegisterCommonManifestHandlers();
44 ManifestHandler::FinalizeRegistration();
47 // Allow the core API permissions.
48 static ExtensionsAPIPermissions extensions_api_permissions
;
49 PermissionsInfo::GetInstance()->AddProvider(extensions_api_permissions
);
52 const PermissionMessageProvider
&
53 TestExtensionsClient::GetPermissionMessageProvider() const {
54 static TestPermissionMessageProvider provider
;
58 const std::string
TestExtensionsClient::GetProductName() {
59 return "extensions_test";
62 scoped_ptr
<FeatureProvider
> TestExtensionsClient::CreateFeatureProvider(
63 const std::string
& name
) const {
64 scoped_ptr
<FeatureProvider
> provider
;
65 scoped_ptr
<JSONFeatureProviderSource
> source(
66 CreateFeatureProviderSource(name
));
68 provider
.reset(new BaseFeatureProvider(source
->dictionary(),
69 CreateFeature
<APIFeature
>));
70 } else if (name
== "manifest") {
71 provider
.reset(new BaseFeatureProvider(source
->dictionary(),
72 CreateFeature
<ManifestFeature
>));
73 } else if (name
== "permission") {
74 provider
.reset(new BaseFeatureProvider(source
->dictionary(),
75 CreateFeature
<PermissionFeature
>));
79 return provider
.Pass();
82 scoped_ptr
<JSONFeatureProviderSource
>
83 TestExtensionsClient::CreateFeatureProviderSource(
84 const std::string
& name
) const {
85 scoped_ptr
<JSONFeatureProviderSource
> source(
86 new JSONFeatureProviderSource(name
));
88 source
->LoadJSON(IDR_EXTENSION_API_FEATURES
);
89 } else if (name
== "manifest") {
90 source
->LoadJSON(IDR_EXTENSION_MANIFEST_FEATURES
);
91 } else if (name
== "permission") {
92 source
->LoadJSON(IDR_EXTENSION_PERMISSION_FEATURES
);
100 void TestExtensionsClient::FilterHostPermissions(
101 const URLPatternSet
& hosts
,
102 URLPatternSet
* new_hosts
,
103 std::set
<PermissionMessage
>* messages
) const {
106 void TestExtensionsClient::SetScriptingWhitelist(
107 const ExtensionsClient::ScriptingWhitelist
& whitelist
) {
108 scripting_whitelist_
= whitelist
;
111 const ExtensionsClient::ScriptingWhitelist
&
112 TestExtensionsClient::GetScriptingWhitelist() const {
113 return scripting_whitelist_
;
116 URLPatternSet
TestExtensionsClient::GetPermittedChromeSchemeHosts(
117 const Extension
* extension
,
118 const APIPermissionSet
& api_permissions
) const {
123 bool TestExtensionsClient::IsScriptableURL(const GURL
& url
,
124 std::string
* error
) const {
128 bool TestExtensionsClient::IsAPISchemaGenerated(
129 const std::string
& name
) const {
130 return core_api::GeneratedSchemas::IsGenerated(name
);
133 base::StringPiece
TestExtensionsClient::GetAPISchema(
134 const std::string
& name
) const {
135 return core_api::GeneratedSchemas::Get(name
);
138 void TestExtensionsClient::RegisterAPISchemaResources(ExtensionAPI
* api
) const {
141 bool TestExtensionsClient::ShouldSuppressFatalErrors() const {
145 } // namespace extensions