Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / extensions / shell / common / shell_extensions_client.cc
blobcd0b9faa7de09a186c5dcd84774fb0a54daedc34
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/shell/common/shell_extensions_client.h"
7 #include "base/lazy_instance.h"
8 #include "base/logging.h"
9 #include "extensions/common/api/generated_schemas.h"
10 #include "extensions/common/common_manifest_handlers.h"
11 #include "extensions/common/extension_urls.h"
12 #include "extensions/common/features/api_feature.h"
13 #include "extensions/common/features/base_feature_provider.h"
14 #include "extensions/common/features/behavior_feature.h"
15 #include "extensions/common/features/json_feature_provider_source.h"
16 #include "extensions/common/features/manifest_feature.h"
17 #include "extensions/common/features/permission_feature.h"
18 #include "extensions/common/features/simple_feature.h"
19 #include "extensions/common/manifest_handler.h"
20 #include "extensions/common/permissions/permission_message_provider.h"
21 #include "extensions/common/permissions/permissions_info.h"
22 #include "extensions/common/permissions/permissions_provider.h"
23 #include "extensions/common/url_pattern_set.h"
24 #include "extensions/shell/common/api/generated_schemas.h"
25 #include "grit/app_shell_resources.h"
26 #include "grit/extensions_resources.h"
28 namespace extensions {
30 namespace {
32 template <class FeatureClass>
33 SimpleFeature* CreateFeature() {
34 return new FeatureClass;
37 // TODO(jamescook): Refactor ChromePermissionsMessageProvider so we can share
38 // code. For now, this implementation does nothing.
39 class ShellPermissionMessageProvider : public PermissionMessageProvider {
40 public:
41 ShellPermissionMessageProvider() {}
42 ~ShellPermissionMessageProvider() override {}
44 // PermissionMessageProvider implementation.
45 PermissionMessages GetPermissionMessages(
46 const PermissionIDSet& permissions) const override {
47 return PermissionMessages();
50 bool IsPrivilegeIncrease(const PermissionSet* old_permissions,
51 const PermissionSet* new_permissions,
52 Manifest::Type extension_type) const override {
53 // Ensure we implement this before shipping.
54 CHECK(false);
55 return false;
58 PermissionIDSet GetAllPermissionIDs(
59 const PermissionSet* permissions,
60 Manifest::Type extension_type) const override {
61 return PermissionIDSet();
64 private:
65 DISALLOW_COPY_AND_ASSIGN(ShellPermissionMessageProvider);
68 base::LazyInstance<ShellPermissionMessageProvider>
69 g_permission_message_provider = LAZY_INSTANCE_INITIALIZER;
71 } // namespace
73 ShellExtensionsClient::ShellExtensionsClient()
74 : extensions_api_permissions_(ExtensionsAPIPermissions()) {
77 ShellExtensionsClient::~ShellExtensionsClient() {
80 void ShellExtensionsClient::Initialize() {
81 RegisterCommonManifestHandlers();
82 ManifestHandler::FinalizeRegistration();
83 // TODO(jamescook): Do we need to whitelist any extensions?
85 PermissionsInfo::GetInstance()->AddProvider(extensions_api_permissions_);
88 const PermissionMessageProvider&
89 ShellExtensionsClient::GetPermissionMessageProvider() const {
90 NOTIMPLEMENTED();
91 return g_permission_message_provider.Get();
94 const std::string ShellExtensionsClient::GetProductName() {
95 return "app_shell";
98 scoped_ptr<FeatureProvider> ShellExtensionsClient::CreateFeatureProvider(
99 const std::string& name) const {
100 scoped_ptr<FeatureProvider> provider;
101 scoped_ptr<JSONFeatureProviderSource> source(
102 CreateFeatureProviderSource(name));
103 if (name == "api") {
104 provider.reset(new BaseFeatureProvider(source->dictionary(),
105 CreateFeature<APIFeature>));
106 } else if (name == "manifest") {
107 provider.reset(new BaseFeatureProvider(source->dictionary(),
108 CreateFeature<ManifestFeature>));
109 } else if (name == "permission") {
110 provider.reset(new BaseFeatureProvider(source->dictionary(),
111 CreateFeature<PermissionFeature>));
112 } else if (name == "behavior") {
113 provider.reset(new BaseFeatureProvider(source->dictionary(),
114 CreateFeature<BehaviorFeature>));
115 } else {
116 NOTREACHED();
118 return provider.Pass();
121 scoped_ptr<JSONFeatureProviderSource>
122 ShellExtensionsClient::CreateFeatureProviderSource(
123 const std::string& name) const {
124 scoped_ptr<JSONFeatureProviderSource> source(
125 new JSONFeatureProviderSource(name));
126 if (name == "api") {
127 source->LoadJSON(IDR_EXTENSION_API_FEATURES);
128 source->LoadJSON(IDR_SHELL_EXTENSION_API_FEATURES);
129 } else if (name == "manifest") {
130 source->LoadJSON(IDR_EXTENSION_MANIFEST_FEATURES);
131 } else if (name == "permission") {
132 source->LoadJSON(IDR_EXTENSION_PERMISSION_FEATURES);
133 } else if (name == "behavior") {
134 source->LoadJSON(IDR_EXTENSION_BEHAVIOR_FEATURES);
135 } else {
136 NOTREACHED();
137 source.reset();
139 return source.Pass();
142 void ShellExtensionsClient::FilterHostPermissions(
143 const URLPatternSet& hosts,
144 URLPatternSet* new_hosts,
145 PermissionIDSet* permissions) const {
146 NOTIMPLEMENTED();
149 void ShellExtensionsClient::SetScriptingWhitelist(
150 const ScriptingWhitelist& whitelist) {
151 scripting_whitelist_ = whitelist;
154 const ExtensionsClient::ScriptingWhitelist&
155 ShellExtensionsClient::GetScriptingWhitelist() const {
156 // TODO(jamescook): Real whitelist.
157 return scripting_whitelist_;
160 URLPatternSet ShellExtensionsClient::GetPermittedChromeSchemeHosts(
161 const Extension* extension,
162 const APIPermissionSet& api_permissions) const {
163 NOTIMPLEMENTED();
164 return URLPatternSet();
167 bool ShellExtensionsClient::IsScriptableURL(const GURL& url,
168 std::string* error) const {
169 NOTIMPLEMENTED();
170 return true;
173 bool ShellExtensionsClient::IsAPISchemaGenerated(
174 const std::string& name) const {
175 return api::GeneratedSchemas::IsGenerated(name) ||
176 shell::api::ShellGeneratedSchemas::IsGenerated(name);
179 base::StringPiece ShellExtensionsClient::GetAPISchema(
180 const std::string& name) const {
181 // Schema for app_shell-only APIs.
182 if (shell::api::ShellGeneratedSchemas::IsGenerated(name))
183 return shell::api::ShellGeneratedSchemas::Get(name);
185 // Core extensions APIs.
186 return api::GeneratedSchemas::Get(name);
189 void ShellExtensionsClient::RegisterAPISchemaResources(
190 ExtensionAPI* api) const {
193 bool ShellExtensionsClient::ShouldSuppressFatalErrors() const {
194 return true;
197 void ShellExtensionsClient::RecordDidSuppressFatalError() {
200 std::string ShellExtensionsClient::GetWebstoreBaseURL() const {
201 return extension_urls::kChromeWebstoreBaseURL;
204 std::string ShellExtensionsClient::GetWebstoreUpdateURL() const {
205 return extension_urls::kChromeWebstoreUpdateURL;
208 bool ShellExtensionsClient::IsBlacklistUpdateURL(const GURL& url) const {
209 // TODO(rockot): Maybe we want to do something else here. For now we accept
210 // any URL as a blacklist URL because we don't really care.
211 return true;
214 } // namespace extensions