Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(470)

Side by Side Diff: chrome/common/extensions/chrome_extensions_client.cc

Issue 246423002: Split feature definitions into extensions and chrome features. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: repack2 Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/common/extensions/chrome_extensions_client.h" 5 #include "chrome/common/extensions/chrome_extensions_client.h"
6 6
7 #include "apps/common/api/generated_schemas.h" 7 #include "apps/common/api/generated_schemas.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "chrome/common/chrome_version_info.h" 9 #include "chrome/common/chrome_version_info.h"
10 #include "chrome/common/extensions/api/generated_schemas.h" 10 #include "chrome/common/extensions/api/generated_schemas.h"
11 #include "chrome/common/extensions/chrome_manifest_handlers.h" 11 #include "chrome/common/extensions/chrome_manifest_handlers.h"
12 #include "chrome/common/extensions/extension_constants.h" 12 #include "chrome/common/extensions/extension_constants.h"
13 #include "chrome/common/extensions/features/chrome_channel_feature_filter.h" 13 #include "chrome/common/extensions/features/chrome_channel_feature_filter.h"
14 #include "chrome/common/extensions/features/feature_channel.h" 14 #include "chrome/common/extensions/features/feature_channel.h"
15 #include "chrome/common/url_constants.h" 15 #include "chrome/common/url_constants.h"
16 #include "content/public/common/url_constants.h" 16 #include "content/public/common/url_constants.h"
17 #include "extensions/common/api/generated_schemas.h" 17 #include "extensions/common/api/generated_schemas.h"
18 #include "extensions/common/common_manifest_handlers.h" 18 #include "extensions/common/common_manifest_handlers.h"
19 #include "extensions/common/extension.h" 19 #include "extensions/common/extension.h"
20 #include "extensions/common/features/api_feature.h"
20 #include "extensions/common/features/base_feature_provider.h" 21 #include "extensions/common/features/base_feature_provider.h"
22 #include "extensions/common/features/json_feature_provider_source.h"
23 #include "extensions/common/features/manifest_feature.h"
24 #include "extensions/common/features/permission_feature.h"
25 #include "extensions/common/features/simple_feature.h"
21 #include "extensions/common/manifest_constants.h" 26 #include "extensions/common/manifest_constants.h"
22 #include "extensions/common/manifest_handler.h" 27 #include "extensions/common/manifest_handler.h"
23 #include "extensions/common/permissions/api_permission_set.h" 28 #include "extensions/common/permissions/api_permission_set.h"
24 #include "extensions/common/permissions/permission_message.h" 29 #include "extensions/common/permissions/permission_message.h"
25 #include "extensions/common/switches.h" 30 #include "extensions/common/switches.h"
26 #include "extensions/common/url_pattern.h" 31 #include "extensions/common/url_pattern.h"
27 #include "extensions/common/url_pattern_set.h" 32 #include "extensions/common/url_pattern_set.h"
33 #include "grit/common_resources.h"
34 #include "grit/extensions_resources.h"
28 #include "grit/generated_resources.h" 35 #include "grit/generated_resources.h"
29 #include "ui/base/l10n/l10n_util.h" 36 #include "ui/base/l10n/l10n_util.h"
30 #include "url/gurl.h" 37 #include "url/gurl.h"
31 38
39 namespace extensions {
40
32 namespace { 41 namespace {
42
33 const char kThumbsWhiteListedExtension[] = "khopmbdjffemhegeeobelklnbglcdgfh"; 43 const char kThumbsWhiteListedExtension[] = "khopmbdjffemhegeeobelklnbglcdgfh";
44
45 template <class FeatureClass>
46 SimpleFeature* CreateFeature() {
47 SimpleFeature* feature = new FeatureClass;
48 feature->AddFilter(
49 scoped_ptr<SimpleFeatureFilter>(new ChromeChannelFeatureFilter(feature)));
50 return feature;
51 }
52
34 } // namespace 53 } // namespace
35 54
36 namespace extensions {
37
38 static base::LazyInstance<ChromeExtensionsClient> g_client = 55 static base::LazyInstance<ChromeExtensionsClient> g_client =
39 LAZY_INSTANCE_INITIALIZER; 56 LAZY_INSTANCE_INITIALIZER;
40 57
41 ChromeExtensionsClient::ChromeExtensionsClient() 58 ChromeExtensionsClient::ChromeExtensionsClient()
42 : chrome_api_permissions_(ChromeAPIPermissions()) { 59 : chrome_api_permissions_(ChromeAPIPermissions()) {
43 } 60 }
44 61
45 ChromeExtensionsClient::~ChromeExtensionsClient() { 62 ChromeExtensionsClient::~ChromeExtensionsClient() {
46 } 63 }
47 64
(...skipping 24 matching lines...) Expand all
72 const PermissionsProvider& 89 const PermissionsProvider&
73 ChromeExtensionsClient::GetPermissionsProvider() const { 90 ChromeExtensionsClient::GetPermissionsProvider() const {
74 return chrome_api_permissions_; 91 return chrome_api_permissions_;
75 } 92 }
76 93
77 const PermissionMessageProvider& 94 const PermissionMessageProvider&
78 ChromeExtensionsClient::GetPermissionMessageProvider() const { 95 ChromeExtensionsClient::GetPermissionMessageProvider() const {
79 return permission_message_provider_; 96 return permission_message_provider_;
80 } 97 }
81 98
82 FeatureProvider* ChromeExtensionsClient::GetFeatureProviderByName( 99 scoped_ptr<FeatureProvider> ChromeExtensionsClient::CreateFeatureProvider(
83 const std::string& name) const { 100 const std::string& name) const {
84 return BaseFeatureProvider::GetByName(name); 101 JSONFeatureProviderSource source(name);
102 if (name == "api") {
103 source.LoadJSON(IDR_EXTENSION_API_FEATURES);
104 source.LoadJSON(IDR_CHROME_EXTENSION_API_FEATURES);
105 return scoped_ptr<FeatureProvider>(new BaseFeatureProvider(
106 source.dictionary(), CreateFeature<APIFeature>));
107 } else if (name == "manifest") {
108 source.LoadJSON(IDR_EXTENSION_MANIFEST_FEATURES);
109 source.LoadJSON(IDR_CHROME_EXTENSION_MANIFEST_FEATURES);
110 return scoped_ptr<FeatureProvider>(new BaseFeatureProvider(
111 source.dictionary(), CreateFeature<ManifestFeature>));
112 } else if (name == "permission") {
113 source.LoadJSON(IDR_EXTENSION_PERMISSION_FEATURES);
114 source.LoadJSON(IDR_CHROME_EXTENSION_PERMISSION_FEATURES);
115 return scoped_ptr<FeatureProvider>(new BaseFeatureProvider(
116 source.dictionary(), CreateFeature<PermissionFeature>));
117 } else {
118 NOTREACHED();
119 }
120 return scoped_ptr<FeatureProvider>();
85 } 121 }
86 122
87 void ChromeExtensionsClient::FilterHostPermissions( 123 void ChromeExtensionsClient::FilterHostPermissions(
88 const URLPatternSet& hosts, 124 const URLPatternSet& hosts,
89 URLPatternSet* new_hosts, 125 URLPatternSet* new_hosts,
90 std::set<PermissionMessage>* messages) const { 126 std::set<PermissionMessage>* messages) const {
91 for (URLPatternSet::const_iterator i = hosts.begin(); 127 for (URLPatternSet::const_iterator i = hosts.begin();
92 i != hosts.end(); ++i) { 128 i != hosts.end(); ++i) {
93 // Filters out every URL pattern that matches chrome:// scheme. 129 // Filters out every URL pattern that matches chrome:// scheme.
94 if (i->scheme() == content::kChromeUIScheme) { 130 if (i->scheme() == content::kChromeUIScheme) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 if (error) 188 if (error)
153 *error = manifest_errors::kCannotScriptGallery; 189 *error = manifest_errors::kCannotScriptGallery;
154 return false; 190 return false;
155 } 191 }
156 return true; 192 return true;
157 } 193 }
158 194
159 bool ChromeExtensionsClient::IsAPISchemaGenerated( 195 bool ChromeExtensionsClient::IsAPISchemaGenerated(
160 const std::string& name) const { 196 const std::string& name) const {
161 // Test from most common to least common. 197 // Test from most common to least common.
162 return extensions::api::GeneratedSchemas::IsGenerated(name) || 198 return api::GeneratedSchemas::IsGenerated(name) ||
163 extensions::core_api::GeneratedSchemas::IsGenerated(name) || 199 core_api::GeneratedSchemas::IsGenerated(name) ||
164 apps::api::GeneratedSchemas::IsGenerated(name); 200 apps::api::GeneratedSchemas::IsGenerated(name);
165 } 201 }
166 202
167 base::StringPiece ChromeExtensionsClient::GetAPISchema( 203 base::StringPiece ChromeExtensionsClient::GetAPISchema(
168 const std::string& name) const { 204 const std::string& name) const {
169 // Test from most common to least common. 205 // Test from most common to least common.
170 if (extensions::api::GeneratedSchemas::IsGenerated(name)) 206 if (api::GeneratedSchemas::IsGenerated(name))
171 return extensions::api::GeneratedSchemas::Get(name); 207 return api::GeneratedSchemas::Get(name);
172 208
173 if (extensions::core_api::GeneratedSchemas::IsGenerated(name)) 209 if (core_api::GeneratedSchemas::IsGenerated(name))
174 return extensions::core_api::GeneratedSchemas::Get(name); 210 return core_api::GeneratedSchemas::Get(name);
175 211
176 return apps::api::GeneratedSchemas::Get(name); 212 return apps::api::GeneratedSchemas::Get(name);
177 } 213 }
178 214
179 void ChromeExtensionsClient::AddExtraFeatureFilters(
180 SimpleFeature* feature) const {
181 feature->AddFilter(
182 scoped_ptr<SimpleFeatureFilter>(new ChromeChannelFeatureFilter(feature)));
183 }
184
185 bool ChromeExtensionsClient::ShouldSuppressFatalErrors() const { 215 bool ChromeExtensionsClient::ShouldSuppressFatalErrors() const {
186 // <= dev means dev, canary, and trunk. 216 // <= dev means dev, canary, and trunk.
187 return GetCurrentChannel() <= chrome::VersionInfo::CHANNEL_DEV; 217 return GetCurrentChannel() <= chrome::VersionInfo::CHANNEL_DEV;
188 } 218 }
189 219
190 // static 220 // static
191 ChromeExtensionsClient* ChromeExtensionsClient::GetInstance() { 221 ChromeExtensionsClient* ChromeExtensionsClient::GetInstance() {
192 return g_client.Pointer(); 222 return g_client.Pointer();
193 } 223 }
194 224
195 } // namespace extensions 225 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/chrome_extensions_client.h ('k') | chrome/common/extensions/docs/server2/app.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698