Remove ExtensionPrefs::SetDidExtensionEscalatePermissions.
[chromium-blink-merge.git] / extensions / shell / common / shell_extensions_client.cc
bloba26c95c2142ea9c8eab92f6bc257450614c8502d
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 PermissionMessageIDs GetLegacyPermissionMessageIDs(
46 const PermissionSet* permissions,
47 Manifest::Type extension_type) const override {
48 return PermissionMessageIDs();
51 CoalescedPermissionMessages GetCoalescedPermissionMessages(
52 const PermissionIDSet& permissions) const override {
53 return CoalescedPermissionMessages();
56 std::vector<base::string16> GetLegacyWarningMessages(
57 const PermissionSet* permissions,
58 Manifest::Type extension_type) const override {
59 return std::vector<base::string16>();
62 std::vector<base::string16> GetLegacyWarningMessagesDetails(
63 const PermissionSet* permissions,
64 Manifest::Type extension_type) const override {
65 return std::vector<base::string16>();
68 bool IsPrivilegeIncrease(const PermissionSet* old_permissions,
69 const PermissionSet* new_permissions,
70 Manifest::Type extension_type) const override {
71 // Ensure we implement this before shipping.
72 CHECK(false);
73 return false;
76 PermissionIDSet GetAllPermissionIDs(
77 const PermissionSet* permissions,
78 Manifest::Type extension_type) const override {
79 return PermissionIDSet();
82 private:
83 DISALLOW_COPY_AND_ASSIGN(ShellPermissionMessageProvider);
86 base::LazyInstance<ShellPermissionMessageProvider>
87 g_permission_message_provider = LAZY_INSTANCE_INITIALIZER;
89 } // namespace
91 ShellExtensionsClient::ShellExtensionsClient()
92 : extensions_api_permissions_(ExtensionsAPIPermissions()) {
95 ShellExtensionsClient::~ShellExtensionsClient() {
98 void ShellExtensionsClient::Initialize() {
99 RegisterCommonManifestHandlers();
100 ManifestHandler::FinalizeRegistration();
101 // TODO(jamescook): Do we need to whitelist any extensions?
103 PermissionsInfo::GetInstance()->AddProvider(extensions_api_permissions_);
106 const PermissionMessageProvider&
107 ShellExtensionsClient::GetPermissionMessageProvider() const {
108 NOTIMPLEMENTED();
109 return g_permission_message_provider.Get();
112 const std::string ShellExtensionsClient::GetProductName() {
113 return "app_shell";
116 scoped_ptr<FeatureProvider> ShellExtensionsClient::CreateFeatureProvider(
117 const std::string& name) const {
118 scoped_ptr<FeatureProvider> provider;
119 scoped_ptr<JSONFeatureProviderSource> source(
120 CreateFeatureProviderSource(name));
121 if (name == "api") {
122 provider.reset(new BaseFeatureProvider(source->dictionary(),
123 CreateFeature<APIFeature>));
124 } else if (name == "manifest") {
125 provider.reset(new BaseFeatureProvider(source->dictionary(),
126 CreateFeature<ManifestFeature>));
127 } else if (name == "permission") {
128 provider.reset(new BaseFeatureProvider(source->dictionary(),
129 CreateFeature<PermissionFeature>));
130 } else if (name == "behavior") {
131 provider.reset(new BaseFeatureProvider(source->dictionary(),
132 CreateFeature<BehaviorFeature>));
133 } else {
134 NOTREACHED();
136 return provider.Pass();
139 scoped_ptr<JSONFeatureProviderSource>
140 ShellExtensionsClient::CreateFeatureProviderSource(
141 const std::string& name) const {
142 scoped_ptr<JSONFeatureProviderSource> source(
143 new JSONFeatureProviderSource(name));
144 if (name == "api") {
145 source->LoadJSON(IDR_EXTENSION_API_FEATURES);
146 source->LoadJSON(IDR_SHELL_EXTENSION_API_FEATURES);
147 } else if (name == "manifest") {
148 source->LoadJSON(IDR_EXTENSION_MANIFEST_FEATURES);
149 } else if (name == "permission") {
150 source->LoadJSON(IDR_EXTENSION_PERMISSION_FEATURES);
151 } else if (name == "behavior") {
152 source->LoadJSON(IDR_EXTENSION_BEHAVIOR_FEATURES);
153 } else {
154 NOTREACHED();
155 source.reset();
157 return source.Pass();
160 void ShellExtensionsClient::FilterHostPermissions(
161 const URLPatternSet& hosts,
162 URLPatternSet* new_hosts,
163 std::set<PermissionMessage>* messages) const {
164 NOTIMPLEMENTED();
167 void ShellExtensionsClient::FilterHostPermissions(
168 const URLPatternSet& hosts,
169 URLPatternSet* new_hosts,
170 PermissionIDSet* permissions) const {
171 NOTIMPLEMENTED();
174 void ShellExtensionsClient::SetScriptingWhitelist(
175 const ScriptingWhitelist& whitelist) {
176 scripting_whitelist_ = whitelist;
179 const ExtensionsClient::ScriptingWhitelist&
180 ShellExtensionsClient::GetScriptingWhitelist() const {
181 // TODO(jamescook): Real whitelist.
182 return scripting_whitelist_;
185 URLPatternSet ShellExtensionsClient::GetPermittedChromeSchemeHosts(
186 const Extension* extension,
187 const APIPermissionSet& api_permissions) const {
188 NOTIMPLEMENTED();
189 return URLPatternSet();
192 bool ShellExtensionsClient::IsScriptableURL(const GURL& url,
193 std::string* error) const {
194 NOTIMPLEMENTED();
195 return true;
198 bool ShellExtensionsClient::IsAPISchemaGenerated(
199 const std::string& name) const {
200 return core_api::GeneratedSchemas::IsGenerated(name) ||
201 shell::api::GeneratedSchemas::IsGenerated(name);
204 base::StringPiece ShellExtensionsClient::GetAPISchema(
205 const std::string& name) const {
206 // Schema for app_shell-only APIs.
207 if (shell::api::GeneratedSchemas::IsGenerated(name))
208 return shell::api::GeneratedSchemas::Get(name);
210 // Core extensions APIs.
211 return core_api::GeneratedSchemas::Get(name);
214 void ShellExtensionsClient::RegisterAPISchemaResources(
215 ExtensionAPI* api) const {
218 bool ShellExtensionsClient::ShouldSuppressFatalErrors() const {
219 return true;
222 void ShellExtensionsClient::RecordDidSuppressFatalError() {
225 std::string ShellExtensionsClient::GetWebstoreBaseURL() const {
226 return extension_urls::kChromeWebstoreBaseURL;
229 std::string ShellExtensionsClient::GetWebstoreUpdateURL() const {
230 return extension_urls::kChromeWebstoreUpdateURL;
233 bool ShellExtensionsClient::IsBlacklistUpdateURL(const GURL& url) const {
234 // TODO(rockot): Maybe we want to do something else here. For now we accept
235 // any URL as a blacklist URL because we don't really care.
236 return true;
239 } // namespace extensions