OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extension.h" | 5 #include "chrome/common/extensions/extension.h" |
6 | 6 |
7 #include <ostream> | 7 #include <ostream> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 | 261 |
262 const int Extension::kPageActionIconMaxSize = 19; | 262 const int Extension::kPageActionIconMaxSize = 19; |
263 const int Extension::kBrowserActionIconMaxSize = 19; | 263 const int Extension::kBrowserActionIconMaxSize = 19; |
264 | 264 |
265 const int Extension::kValidWebExtentSchemes = | 265 const int Extension::kValidWebExtentSchemes = |
266 URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS; | 266 URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS; |
267 | 267 |
268 const int Extension::kValidHostPermissionSchemes = | 268 const int Extension::kValidHostPermissionSchemes = |
269 UserScript::kValidUserScriptSchemes | URLPattern::SCHEME_CHROMEUI; | 269 UserScript::kValidUserScriptSchemes | URLPattern::SCHEME_CHROMEUI; |
270 | 270 |
| 271 Extension::Requirements::Requirements() |
| 272 : webgl(false), |
| 273 css3d(false), |
| 274 npapi(false) { |
| 275 } |
| 276 |
| 277 Extension::Requirements::~Requirements() {} |
| 278 |
271 Extension::InputComponentInfo::InputComponentInfo() | 279 Extension::InputComponentInfo::InputComponentInfo() |
272 : type(INPUT_COMPONENT_TYPE_NONE), | 280 : type(INPUT_COMPONENT_TYPE_NONE), |
273 shortcut_alt(false), | 281 shortcut_alt(false), |
274 shortcut_ctrl(false), | 282 shortcut_ctrl(false), |
275 shortcut_shift(false) { | 283 shortcut_shift(false) { |
276 } | 284 } |
277 | 285 |
278 Extension::InputComponentInfo::~InputComponentInfo() {} | 286 Extension::InputComponentInfo::~InputComponentInfo() {} |
279 | 287 |
280 Extension::TtsVoice::TtsVoice() {} | 288 Extension::TtsVoice::TtsVoice() {} |
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1301 string16* error) { | 1309 string16* error) { |
1302 if (!LoadDescription(error) || | 1310 if (!LoadDescription(error) || |
1303 !LoadHomepageURL(error) || | 1311 !LoadHomepageURL(error) || |
1304 !LoadUpdateURL(error) || | 1312 !LoadUpdateURL(error) || |
1305 !LoadIcons(error) || | 1313 !LoadIcons(error) || |
1306 !LoadCommands(error) || | 1314 !LoadCommands(error) || |
1307 !LoadPlugins(error) || | 1315 !LoadPlugins(error) || |
1308 !LoadNaClModules(error) || | 1316 !LoadNaClModules(error) || |
1309 !LoadWebAccessibleResources(error) || | 1317 !LoadWebAccessibleResources(error) || |
1310 !LoadSandboxedPages(error) || | 1318 !LoadSandboxedPages(error) || |
1311 !CheckRequirements(error) || | 1319 !LoadRequirements(error) || |
1312 !LoadDefaultLocale(error) || | 1320 !LoadDefaultLocale(error) || |
1313 !LoadOfflineEnabled(error) || | 1321 !LoadOfflineEnabled(error) || |
1314 !LoadOptionsPage(error) || | 1322 !LoadOptionsPage(error) || |
1315 // LoadBackgroundScripts() must be called before LoadBackgroundPage(). | 1323 // LoadBackgroundScripts() must be called before LoadBackgroundPage(). |
1316 !LoadBackgroundScripts(error) || | 1324 !LoadBackgroundScripts(error) || |
1317 !LoadBackgroundPage(api_permissions, error) || | 1325 !LoadBackgroundPage(api_permissions, error) || |
1318 !LoadBackgroundPersistent(api_permissions, error) || | 1326 !LoadBackgroundPersistent(api_permissions, error) || |
1319 !LoadBackgroundAllowJSAccess(api_permissions, error) || | 1327 !LoadBackgroundAllowJSAccess(api_permissions, error) || |
1320 !LoadWebIntentServices(error) || | 1328 !LoadWebIntentServices(error) || |
1321 !LoadOAuth2Info(error)) | 1329 !LoadOAuth2Info(error)) |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1676 } else { | 1684 } else { |
1677 sandboxed_pages_content_security_policy_ = | 1685 sandboxed_pages_content_security_policy_ = |
1678 kDefaultSandboxedPageContentSecurityPolicy; | 1686 kDefaultSandboxedPageContentSecurityPolicy; |
1679 CHECK(ContentSecurityPolicyIsSandboxed( | 1687 CHECK(ContentSecurityPolicyIsSandboxed( |
1680 sandboxed_pages_content_security_policy_, GetType())); | 1688 sandboxed_pages_content_security_policy_, GetType())); |
1681 } | 1689 } |
1682 | 1690 |
1683 return true; | 1691 return true; |
1684 } | 1692 } |
1685 | 1693 |
1686 // These are not actually persisted (they're only used by the store), but | 1694 bool Extension::LoadRequirements(string16* error) { |
1687 // still validated. | 1695 // If the extension has plugins, then |requirements_.npapi| defaults to true. |
1688 bool Extension::CheckRequirements(string16* error) { | 1696 if (plugins_.size() > 0) |
| 1697 requirements_.npapi = true; |
| 1698 |
1689 if (!manifest_->HasKey(keys::kRequirements)) | 1699 if (!manifest_->HasKey(keys::kRequirements)) |
1690 return true; | 1700 return true; |
| 1701 |
1691 DictionaryValue* requirements_value = NULL; | 1702 DictionaryValue* requirements_value = NULL; |
1692 if (!manifest_->GetDictionary(keys::kRequirements, &requirements_value)) { | 1703 if (!manifest_->GetDictionary(keys::kRequirements, &requirements_value)) { |
1693 *error = ASCIIToUTF16(errors::kInvalidRequirements); | 1704 *error = ASCIIToUTF16(errors::kInvalidRequirements); |
1694 return false; | 1705 return false; |
1695 } | 1706 } |
1696 | 1707 |
1697 for (DictionaryValue::key_iterator it = requirements_value->begin_keys(); | 1708 for (DictionaryValue::key_iterator it = requirements_value->begin_keys(); |
1698 it != requirements_value->end_keys(); ++it) { | 1709 it != requirements_value->end_keys(); ++it) { |
1699 DictionaryValue* requirement_value; | 1710 DictionaryValue* requirement_value; |
1700 if (!requirements_value->GetDictionaryWithoutPathExpansion( | 1711 if (!requirements_value->GetDictionaryWithoutPathExpansion( |
1701 *it, &requirement_value)) { | 1712 *it, &requirement_value)) { |
1702 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1713 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
1703 errors::kInvalidRequirement, *it); | 1714 errors::kInvalidRequirement, *it); |
1704 return false; | 1715 return false; |
1705 } | 1716 } |
| 1717 |
| 1718 if (*it == "plugins") { |
| 1719 for (DictionaryValue::key_iterator plugin_it = |
| 1720 requirement_value->begin_keys(); |
| 1721 plugin_it != requirement_value->end_keys(); ++plugin_it) { |
| 1722 bool plugin_required = false; |
| 1723 if (!requirement_value->GetBoolean(*plugin_it, &plugin_required)) { |
| 1724 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
| 1725 errors::kInvalidRequirement, *it); |
| 1726 return false; |
| 1727 } |
| 1728 if (*plugin_it == "npapi") { |
| 1729 requirements_.npapi = plugin_required; |
| 1730 } else { |
| 1731 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
| 1732 errors::kInvalidRequirement, *it); |
| 1733 return false; |
| 1734 } |
| 1735 } |
| 1736 } else if (*it == "3D") { |
| 1737 ListValue* features = NULL; |
| 1738 if (!requirement_value->GetListWithoutPathExpansion("features", |
| 1739 &features) || |
| 1740 !features) { |
| 1741 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
| 1742 errors::kInvalidRequirement, *it); |
| 1743 return false; |
| 1744 } |
| 1745 |
| 1746 for (base::ListValue::iterator feature_it = features->begin(); |
| 1747 feature_it != features->end(); |
| 1748 ++feature_it) { |
| 1749 std::string feature; |
| 1750 if ((*feature_it)->GetAsString(&feature)) { |
| 1751 if (feature == "webgl") { |
| 1752 requirements_.webgl = true; |
| 1753 } else if (feature == "css3d") { |
| 1754 requirements_.css3d = true; |
| 1755 } else { |
| 1756 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
| 1757 errors::kInvalidRequirement, *it); |
| 1758 return false; |
| 1759 } |
| 1760 } |
| 1761 } |
| 1762 } else { |
| 1763 *error = ASCIIToUTF16(errors::kInvalidRequirements); |
| 1764 return false; |
| 1765 } |
1706 } | 1766 } |
1707 return true; | 1767 return true; |
1708 } | 1768 } |
1709 | 1769 |
1710 bool Extension::LoadDefaultLocale(string16* error) { | 1770 bool Extension::LoadDefaultLocale(string16* error) { |
1711 if (!manifest_->HasKey(keys::kDefaultLocale)) | 1771 if (!manifest_->HasKey(keys::kDefaultLocale)) |
1712 return true; | 1772 return true; |
1713 if (!manifest_->GetString(keys::kDefaultLocale, &default_locale_) || | 1773 if (!manifest_->GetString(keys::kDefaultLocale, &default_locale_) || |
1714 !l10n_util::IsValidLocaleSyntax(default_locale_)) { | 1774 !l10n_util::IsValidLocaleSyntax(default_locale_)) { |
1715 *error = ASCIIToUTF16(errors::kInvalidDefaultLocale); | 1775 *error = ASCIIToUTF16(errors::kInvalidDefaultLocale); |
(...skipping 2211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3927 | 3987 |
3928 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 3988 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
3929 const Extension* extension, | 3989 const Extension* extension, |
3930 const PermissionSet* permissions, | 3990 const PermissionSet* permissions, |
3931 Reason reason) | 3991 Reason reason) |
3932 : reason(reason), | 3992 : reason(reason), |
3933 extension(extension), | 3993 extension(extension), |
3934 permissions(permissions) {} | 3994 permissions(permissions) {} |
3935 | 3995 |
3936 } // namespace extensions | 3996 } // namespace extensions |
OLD | NEW |