OLD | NEW |
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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
10 #include "chrome/common/chrome_version_info.h" | 10 #include "chrome/common/chrome_version_info.h" |
| 11 #include "chrome/common/extensions/api/generated_schemas.h" |
11 #include "chrome/common/extensions/chrome_manifest_handlers.h" | 12 #include "chrome/common/extensions/chrome_manifest_handlers.h" |
12 #include "chrome/common/extensions/extension_constants.h" | 13 #include "chrome/common/extensions/extension_constants.h" |
13 #include "chrome/common/extensions/features/chrome_channel_feature_filter.h" | 14 #include "chrome/common/extensions/features/chrome_channel_feature_filter.h" |
14 #include "chrome/common/extensions/features/feature_channel.h" | 15 #include "chrome/common/extensions/features/feature_channel.h" |
15 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
16 #include "chrome/grit/chromium_strings.h" | 17 #include "chrome/grit/chromium_strings.h" |
17 #include "chrome/grit/common_resources.h" | 18 #include "chrome/grit/common_resources.h" |
| 19 #include "chrome/grit/extensions_api_resources.h" |
18 #include "chrome/grit/generated_resources.h" | 20 #include "chrome/grit/generated_resources.h" |
19 #include "content/public/common/url_constants.h" | 21 #include "content/public/common/url_constants.h" |
| 22 #include "extensions/common/api/generated_schemas.h" |
20 #include "extensions/common/common_manifest_handlers.h" | 23 #include "extensions/common/common_manifest_handlers.h" |
21 #include "extensions/common/extension.h" | 24 #include "extensions/common/extension.h" |
22 #include "extensions/common/extension_api.h" | 25 #include "extensions/common/extension_api.h" |
23 #include "extensions/common/extension_urls.h" | 26 #include "extensions/common/extension_urls.h" |
24 #include "extensions/common/features/api_feature.h" | 27 #include "extensions/common/features/api_feature.h" |
25 #include "extensions/common/features/base_feature_provider.h" | 28 #include "extensions/common/features/base_feature_provider.h" |
26 #include "extensions/common/features/feature_provider.h" | 29 #include "extensions/common/features/feature_provider.h" |
27 #include "extensions/common/features/json_feature_provider_source.h" | 30 #include "extensions/common/features/json_feature_provider_source.h" |
28 #include "extensions/common/features/manifest_feature.h" | 31 #include "extensions/common/features/manifest_feature.h" |
29 #include "extensions/common/features/permission_feature.h" | 32 #include "extensions/common/features/permission_feature.h" |
30 #include "extensions/common/features/simple_feature.h" | 33 #include "extensions/common/features/simple_feature.h" |
31 #include "extensions/common/manifest_constants.h" | 34 #include "extensions/common/manifest_constants.h" |
32 #include "extensions/common/manifest_handler.h" | 35 #include "extensions/common/manifest_handler.h" |
33 #include "extensions/common/permissions/api_permission_set.h" | 36 #include "extensions/common/permissions/api_permission_set.h" |
34 #include "extensions/common/permissions/permission_message.h" | 37 #include "extensions/common/permissions/permission_message.h" |
35 #include "extensions/common/permissions/permissions_info.h" | 38 #include "extensions/common/permissions/permissions_info.h" |
36 #include "extensions/common/url_pattern.h" | 39 #include "extensions/common/url_pattern.h" |
37 #include "extensions/common/url_pattern_set.h" | 40 #include "extensions/common/url_pattern_set.h" |
38 #include "extensions/grit/extensions_resources.h" | 41 #include "extensions/grit/extensions_resources.h" |
39 #include "ui/base/l10n/l10n_util.h" | 42 #include "ui/base/l10n/l10n_util.h" |
40 #include "url/gurl.h" | 43 #include "url/gurl.h" |
41 | 44 |
42 // TODO(thestig): Remove these #defines. This file should not be built when | |
43 // extensions are disabled. | |
44 #if defined(ENABLE_EXTENSIONS) | |
45 #include "chrome/common/extensions/api/generated_schemas.h" | |
46 #include "chrome/grit/extensions_api_resources.h" | |
47 #include "extensions/common/api/generated_schemas.h" | |
48 #endif | |
49 | |
50 namespace extensions { | 45 namespace extensions { |
51 | 46 |
52 namespace { | 47 namespace { |
53 | 48 |
54 // TODO(battre): Delete the HTTP URL once the blacklist is downloaded via HTTPS. | 49 // TODO(battre): Delete the HTTP URL once the blacklist is downloaded via HTTPS. |
55 const char kExtensionBlocklistUrlPrefix[] = | 50 const char kExtensionBlocklistUrlPrefix[] = |
56 "http://www.gstatic.com/chrome/extensions/blacklist"; | 51 "http://www.gstatic.com/chrome/extensions/blacklist"; |
57 const char kExtensionBlocklistHttpsUrlPrefix[] = | 52 const char kExtensionBlocklistHttpsUrlPrefix[] = |
58 "https://www.gstatic.com/chrome/extensions/blacklist"; | 53 "https://www.gstatic.com/chrome/extensions/blacklist"; |
59 | 54 |
(...skipping 18 matching lines...) Expand all Loading... |
78 } | 73 } |
79 | 74 |
80 ChromeExtensionsClient::~ChromeExtensionsClient() { | 75 ChromeExtensionsClient::~ChromeExtensionsClient() { |
81 } | 76 } |
82 | 77 |
83 void ChromeExtensionsClient::Initialize() { | 78 void ChromeExtensionsClient::Initialize() { |
84 // Registration could already be finalized in unit tests, where the utility | 79 // Registration could already be finalized in unit tests, where the utility |
85 // thread runs in-process. | 80 // thread runs in-process. |
86 if (!ManifestHandler::IsRegistrationFinalized()) { | 81 if (!ManifestHandler::IsRegistrationFinalized()) { |
87 RegisterCommonManifestHandlers(); | 82 RegisterCommonManifestHandlers(); |
88 #if defined(ENABLE_EXTENSIONS) | |
89 RegisterChromeManifestHandlers(); | 83 RegisterChromeManifestHandlers(); |
90 #endif | |
91 ManifestHandler::FinalizeRegistration(); | 84 ManifestHandler::FinalizeRegistration(); |
92 } | 85 } |
93 | 86 |
94 // Set up permissions. | 87 // Set up permissions. |
95 PermissionsInfo::GetInstance()->AddProvider(chrome_api_permissions_); | 88 PermissionsInfo::GetInstance()->AddProvider(chrome_api_permissions_); |
96 PermissionsInfo::GetInstance()->AddProvider(extensions_api_permissions_); | 89 PermissionsInfo::GetInstance()->AddProvider(extensions_api_permissions_); |
97 | 90 |
98 // Set up the scripting whitelist. | 91 // Set up the scripting whitelist. |
99 // Whitelist ChromeVox, an accessibility extension from Google that needs | 92 // Whitelist ChromeVox, an accessibility extension from Google that needs |
100 // the ability to script webui pages. This is temporary and is not | 93 // the ability to script webui pages. This is temporary and is not |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 if (url.host() == store_url.host()) { | 220 if (url.host() == store_url.host()) { |
228 if (error) | 221 if (error) |
229 *error = manifest_errors::kCannotScriptGallery; | 222 *error = manifest_errors::kCannotScriptGallery; |
230 return false; | 223 return false; |
231 } | 224 } |
232 return true; | 225 return true; |
233 } | 226 } |
234 | 227 |
235 bool ChromeExtensionsClient::IsAPISchemaGenerated( | 228 bool ChromeExtensionsClient::IsAPISchemaGenerated( |
236 const std::string& name) const { | 229 const std::string& name) const { |
237 #if defined(ENABLE_EXTENSIONS) | |
238 // Test from most common to least common. | 230 // Test from most common to least common. |
239 return api::GeneratedSchemas::IsGenerated(name) || | 231 return api::GeneratedSchemas::IsGenerated(name) || |
240 core_api::GeneratedSchemas::IsGenerated(name); | 232 core_api::GeneratedSchemas::IsGenerated(name); |
241 #else | |
242 return false; | |
243 #endif | |
244 } | 233 } |
245 | 234 |
246 base::StringPiece ChromeExtensionsClient::GetAPISchema( | 235 base::StringPiece ChromeExtensionsClient::GetAPISchema( |
247 const std::string& name) const { | 236 const std::string& name) const { |
248 #if defined(ENABLE_EXTENSIONS) | |
249 // Test from most common to least common. | 237 // Test from most common to least common. |
250 if (api::GeneratedSchemas::IsGenerated(name)) | 238 if (api::GeneratedSchemas::IsGenerated(name)) |
251 return api::GeneratedSchemas::Get(name); | 239 return api::GeneratedSchemas::Get(name); |
252 | 240 |
253 return core_api::GeneratedSchemas::Get(name); | 241 return core_api::GeneratedSchemas::Get(name); |
254 #else | |
255 return base::StringPiece(); | |
256 #endif | |
257 } | 242 } |
258 | 243 |
259 void ChromeExtensionsClient::RegisterAPISchemaResources( | 244 void ChromeExtensionsClient::RegisterAPISchemaResources( |
260 ExtensionAPI* api) const { | 245 ExtensionAPI* api) const { |
261 #if defined(ENABLE_EXTENSIONS) | |
262 api->RegisterSchemaResource("accessibilityPrivate", | 246 api->RegisterSchemaResource("accessibilityPrivate", |
263 IDR_EXTENSION_API_JSON_ACCESSIBILITYPRIVATE); | 247 IDR_EXTENSION_API_JSON_ACCESSIBILITYPRIVATE); |
264 api->RegisterSchemaResource("app", IDR_EXTENSION_API_JSON_APP); | 248 api->RegisterSchemaResource("app", IDR_EXTENSION_API_JSON_APP); |
265 api->RegisterSchemaResource("browserAction", | 249 api->RegisterSchemaResource("browserAction", |
266 IDR_EXTENSION_API_JSON_BROWSERACTION); | 250 IDR_EXTENSION_API_JSON_BROWSERACTION); |
267 api->RegisterSchemaResource("commands", IDR_EXTENSION_API_JSON_COMMANDS); | 251 api->RegisterSchemaResource("commands", IDR_EXTENSION_API_JSON_COMMANDS); |
268 api->RegisterSchemaResource("declarativeContent", | 252 api->RegisterSchemaResource("declarativeContent", |
269 IDR_EXTENSION_API_JSON_DECLARATIVE_CONTENT); | 253 IDR_EXTENSION_API_JSON_DECLARATIVE_CONTENT); |
270 api->RegisterSchemaResource("fileBrowserHandler", | 254 api->RegisterSchemaResource("fileBrowserHandler", |
271 IDR_EXTENSION_API_JSON_FILEBROWSERHANDLER); | 255 IDR_EXTENSION_API_JSON_FILEBROWSERHANDLER); |
272 api->RegisterSchemaResource("inputMethodPrivate", | 256 api->RegisterSchemaResource("inputMethodPrivate", |
273 IDR_EXTENSION_API_JSON_INPUTMETHODPRIVATE); | 257 IDR_EXTENSION_API_JSON_INPUTMETHODPRIVATE); |
274 api->RegisterSchemaResource("pageAction", IDR_EXTENSION_API_JSON_PAGEACTION); | 258 api->RegisterSchemaResource("pageAction", IDR_EXTENSION_API_JSON_PAGEACTION); |
275 api->RegisterSchemaResource("privacy", IDR_EXTENSION_API_JSON_PRIVACY); | 259 api->RegisterSchemaResource("privacy", IDR_EXTENSION_API_JSON_PRIVACY); |
276 api->RegisterSchemaResource("processes", IDR_EXTENSION_API_JSON_PROCESSES); | 260 api->RegisterSchemaResource("processes", IDR_EXTENSION_API_JSON_PROCESSES); |
277 api->RegisterSchemaResource("proxy", IDR_EXTENSION_API_JSON_PROXY); | 261 api->RegisterSchemaResource("proxy", IDR_EXTENSION_API_JSON_PROXY); |
278 api->RegisterSchemaResource("scriptBadge", | 262 api->RegisterSchemaResource("scriptBadge", |
279 IDR_EXTENSION_API_JSON_SCRIPTBADGE); | 263 IDR_EXTENSION_API_JSON_SCRIPTBADGE); |
280 api->RegisterSchemaResource("ttsEngine", IDR_EXTENSION_API_JSON_TTSENGINE); | 264 api->RegisterSchemaResource("ttsEngine", IDR_EXTENSION_API_JSON_TTSENGINE); |
281 api->RegisterSchemaResource("tts", IDR_EXTENSION_API_JSON_TTS); | 265 api->RegisterSchemaResource("tts", IDR_EXTENSION_API_JSON_TTS); |
282 api->RegisterSchemaResource("types", IDR_EXTENSION_API_JSON_TYPES); | 266 api->RegisterSchemaResource("types", IDR_EXTENSION_API_JSON_TYPES); |
283 api->RegisterSchemaResource("types.private", | 267 api->RegisterSchemaResource("types.private", |
284 IDR_EXTENSION_API_JSON_TYPES_PRIVATE); | 268 IDR_EXTENSION_API_JSON_TYPES_PRIVATE); |
285 api->RegisterSchemaResource("webstore", IDR_EXTENSION_API_JSON_WEBSTORE); | 269 api->RegisterSchemaResource("webstore", IDR_EXTENSION_API_JSON_WEBSTORE); |
286 #endif // defined(ENABLE_EXTENSIONS) | |
287 } | 270 } |
288 | 271 |
289 bool ChromeExtensionsClient::ShouldSuppressFatalErrors() const { | 272 bool ChromeExtensionsClient::ShouldSuppressFatalErrors() const { |
290 // Suppress fatal errors only on beta and stable channels. | 273 // Suppress fatal errors only on beta and stable channels. |
291 return GetCurrentChannel() > chrome::VersionInfo::CHANNEL_DEV; | 274 return GetCurrentChannel() > chrome::VersionInfo::CHANNEL_DEV; |
292 } | 275 } |
293 | 276 |
294 std::string ChromeExtensionsClient::GetWebstoreBaseURL() const { | 277 std::string ChromeExtensionsClient::GetWebstoreBaseURL() const { |
295 std::string gallery_prefix = extension_urls::kChromeWebstoreBaseURL; | 278 std::string gallery_prefix = extension_urls::kChromeWebstoreBaseURL; |
296 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAppsGalleryURL)) | 279 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAppsGalleryURL)) |
(...skipping 22 matching lines...) Expand all Loading... |
319 return StartsWithASCII(url.spec(), kExtensionBlocklistUrlPrefix, true) || | 302 return StartsWithASCII(url.spec(), kExtensionBlocklistUrlPrefix, true) || |
320 StartsWithASCII(url.spec(), kExtensionBlocklistHttpsUrlPrefix, true); | 303 StartsWithASCII(url.spec(), kExtensionBlocklistHttpsUrlPrefix, true); |
321 } | 304 } |
322 | 305 |
323 // static | 306 // static |
324 ChromeExtensionsClient* ChromeExtensionsClient::GetInstance() { | 307 ChromeExtensionsClient* ChromeExtensionsClient::GetInstance() { |
325 return g_client.Pointer(); | 308 return g_client.Pointer(); |
326 } | 309 } |
327 | 310 |
328 } // namespace extensions | 311 } // namespace extensions |
OLD | NEW |