Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / extensions / test / test_extensions_client.cc
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.
4
5 #include "extensions/test/test_extensions_client.h"
6
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/feature_provider.h"
13 #include "extensions/common/features/json_feature_provider_source.h"
14 #include "extensions/common/features/manifest_feature.h"
15 #include "extensions/common/features/permission_feature.h"
16 #include "extensions/common/manifest_handler.h"
17 #include "extensions/common/permissions/extensions_api_permissions.h"
18 #include "extensions/common/permissions/permissions_info.h"
19 #include "extensions/common/url_pattern_set.h"
20 #include "extensions/test/test_permission_message_provider.h"
21 #include "grit/extensions_resources.h"
22
23 namespace extensions {
24
25 namespace {
26
27 template <class FeatureClass>
28 SimpleFeature* CreateFeature() {
29   return new FeatureClass;
30 }
31
32 }  // namespace
33
34 TestExtensionsClient::TestExtensionsClient() {
35 }
36
37 TestExtensionsClient::~TestExtensionsClient() {
38 }
39
40 void TestExtensionsClient::Initialize() {
41   // Registration could already be finalized in unit tests, where the utility
42   // thread runs in-process.
43   if (!ManifestHandler::IsRegistrationFinalized()) {
44     RegisterCommonManifestHandlers();
45     ManifestHandler::FinalizeRegistration();
46   }
47
48   // Allow the core API permissions.
49   static ExtensionsAPIPermissions extensions_api_permissions;
50   PermissionsInfo::GetInstance()->AddProvider(extensions_api_permissions);
51 }
52
53 const PermissionMessageProvider&
54 TestExtensionsClient::GetPermissionMessageProvider() const {
55   static TestPermissionMessageProvider provider;
56   return provider;
57 }
58
59 const std::string TestExtensionsClient::GetProductName() {
60   return "extensions_test";
61 }
62
63 scoped_ptr<FeatureProvider> TestExtensionsClient::CreateFeatureProvider(
64     const std::string& name) const {
65   scoped_ptr<FeatureProvider> provider;
66   scoped_ptr<JSONFeatureProviderSource> source(
67       CreateFeatureProviderSource(name));
68   if (name == "api") {
69     provider.reset(new BaseFeatureProvider(source->dictionary(),
70                                            CreateFeature<APIFeature>));
71   } else if (name == "manifest") {
72     provider.reset(new BaseFeatureProvider(source->dictionary(),
73                                            CreateFeature<ManifestFeature>));
74   } else if (name == "permission") {
75     provider.reset(new BaseFeatureProvider(source->dictionary(),
76                                            CreateFeature<PermissionFeature>));
77   } else {
78     NOTREACHED();
79   }
80   return provider.Pass();
81 }
82
83 scoped_ptr<JSONFeatureProviderSource>
84 TestExtensionsClient::CreateFeatureProviderSource(
85     const std::string& name) const {
86   scoped_ptr<JSONFeatureProviderSource> source(
87       new JSONFeatureProviderSource(name));
88   if (name == "api") {
89     source->LoadJSON(IDR_EXTENSION_API_FEATURES);
90   } else if (name == "manifest") {
91     source->LoadJSON(IDR_EXTENSION_MANIFEST_FEATURES);
92   } else if (name == "permission") {
93     source->LoadJSON(IDR_EXTENSION_PERMISSION_FEATURES);
94   } else {
95     NOTREACHED();
96     source.reset();
97   }
98   return source.Pass();
99 }
100
101 void TestExtensionsClient::FilterHostPermissions(
102     const URLPatternSet& hosts,
103     URLPatternSet* new_hosts,
104     std::set<PermissionMessage>* messages) const {
105 }
106
107 void TestExtensionsClient::SetScriptingWhitelist(
108     const ExtensionsClient::ScriptingWhitelist& whitelist) {
109   scripting_whitelist_ = whitelist;
110 }
111
112 const ExtensionsClient::ScriptingWhitelist&
113 TestExtensionsClient::GetScriptingWhitelist() const {
114   return scripting_whitelist_;
115 }
116
117 URLPatternSet TestExtensionsClient::GetPermittedChromeSchemeHosts(
118     const Extension* extension,
119     const APIPermissionSet& api_permissions) const {
120   URLPatternSet hosts;
121   return hosts;
122 }
123
124 bool TestExtensionsClient::IsScriptableURL(const GURL& url,
125                                            std::string* error) const {
126   return true;
127 }
128
129 bool TestExtensionsClient::IsAPISchemaGenerated(
130     const std::string& name) const {
131   return core_api::GeneratedSchemas::IsGenerated(name);
132 }
133
134 base::StringPiece TestExtensionsClient::GetAPISchema(
135     const std::string& name) const {
136   return core_api::GeneratedSchemas::Get(name);
137 }
138
139 void TestExtensionsClient::RegisterAPISchemaResources(ExtensionAPI* api) const {
140 }
141
142 bool TestExtensionsClient::ShouldSuppressFatalErrors() const {
143   return true;
144 }
145
146 std::string TestExtensionsClient::GetWebstoreBaseURL() const {
147   return extension_urls::kChromeWebstoreBaseURL;
148 }
149
150 std::string TestExtensionsClient::GetWebstoreUpdateURL() const {
151   return extension_urls::kChromeWebstoreUpdateURL;
152 }
153
154 bool TestExtensionsClient::IsBlacklistUpdateURL(const GURL& url) const {
155   return true;
156 }
157
158 }  // namespace extensions