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

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

Issue 10689097: Enforce the 'requirements' field in manifests. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed UnpackedInstller issue Created 8 years, 3 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
OLDNEW
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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 258
259 const int Extension::kPageActionIconMaxSize = 19; 259 const int Extension::kPageActionIconMaxSize = 19;
260 const int Extension::kBrowserActionIconMaxSize = 19; 260 const int Extension::kBrowserActionIconMaxSize = 19;
261 261
262 const int Extension::kValidWebExtentSchemes = 262 const int Extension::kValidWebExtentSchemes =
263 URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS; 263 URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS;
264 264
265 const int Extension::kValidHostPermissionSchemes = 265 const int Extension::kValidHostPermissionSchemes =
266 UserScript::kValidUserScriptSchemes | URLPattern::SCHEME_CHROMEUI; 266 UserScript::kValidUserScriptSchemes | URLPattern::SCHEME_CHROMEUI;
267 267
268 Extension::Requirements::Requirements()
269 : webgl(false),
270 css3d(false),
271 npapi(false) {
272 }
273
274 Extension::Requirements::~Requirements() {}
275
268 Extension::InputComponentInfo::InputComponentInfo() 276 Extension::InputComponentInfo::InputComponentInfo()
269 : type(INPUT_COMPONENT_TYPE_NONE), 277 : type(INPUT_COMPONENT_TYPE_NONE),
270 shortcut_alt(false), 278 shortcut_alt(false),
271 shortcut_ctrl(false), 279 shortcut_ctrl(false),
272 shortcut_shift(false) { 280 shortcut_shift(false) {
273 } 281 }
274 282
275 Extension::InputComponentInfo::~InputComponentInfo() {} 283 Extension::InputComponentInfo::~InputComponentInfo() {}
276 284
277 Extension::TtsVoice::TtsVoice() {} 285 Extension::TtsVoice::TtsVoice() {}
(...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 string16* error) { 1261 string16* error) {
1254 if (!LoadDescription(error) || 1262 if (!LoadDescription(error) ||
1255 !LoadHomepageURL(error) || 1263 !LoadHomepageURL(error) ||
1256 !LoadUpdateURL(error) || 1264 !LoadUpdateURL(error) ||
1257 !LoadIcons(error) || 1265 !LoadIcons(error) ||
1258 !LoadCommands(error) || 1266 !LoadCommands(error) ||
1259 !LoadPlugins(error) || 1267 !LoadPlugins(error) ||
1260 !LoadNaClModules(error) || 1268 !LoadNaClModules(error) ||
1261 !LoadWebAccessibleResources(error) || 1269 !LoadWebAccessibleResources(error) ||
1262 !LoadSandboxedPages(error) || 1270 !LoadSandboxedPages(error) ||
1263 !CheckRequirements(error) || 1271 !LoadRequirements(error) ||
1264 !LoadDefaultLocale(error) || 1272 !LoadDefaultLocale(error) ||
1265 !LoadOfflineEnabled(error) || 1273 !LoadOfflineEnabled(error) ||
1266 !LoadOptionsPage(error) || 1274 !LoadOptionsPage(error) ||
1267 // LoadBackgroundScripts() must be called before LoadBackgroundPage(). 1275 // LoadBackgroundScripts() must be called before LoadBackgroundPage().
1268 !LoadBackgroundScripts(error) || 1276 !LoadBackgroundScripts(error) ||
1269 !LoadBackgroundPage(api_permissions, error) || 1277 !LoadBackgroundPage(api_permissions, error) ||
1270 !LoadBackgroundPersistent(api_permissions, error) || 1278 !LoadBackgroundPersistent(api_permissions, error) ||
1271 !LoadBackgroundAllowJSAccess(api_permissions, error) || 1279 !LoadBackgroundAllowJSAccess(api_permissions, error) ||
1272 !LoadWebIntentServices(error) || 1280 !LoadWebIntentServices(error) ||
1273 !LoadOAuth2Info(error)) 1281 !LoadOAuth2Info(error))
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
1617 } else { 1625 } else {
1618 sandboxed_pages_content_security_policy_ = 1626 sandboxed_pages_content_security_policy_ =
1619 kDefaultSandboxedPageContentSecurityPolicy; 1627 kDefaultSandboxedPageContentSecurityPolicy;
1620 CHECK(ContentSecurityPolicyIsSandboxed( 1628 CHECK(ContentSecurityPolicyIsSandboxed(
1621 sandboxed_pages_content_security_policy_, GetType())); 1629 sandboxed_pages_content_security_policy_, GetType()));
1622 } 1630 }
1623 1631
1624 return true; 1632 return true;
1625 } 1633 }
1626 1634
1635 bool Extension::LoadRequirements(string16* error) {
1636 // If the extension has plugins, then |requirements_.npapi| defaults to true.
1637 if (plugins_.size() > 0)
1638 requirements_.npapi = true;
1639
1640 if (!manifest_->HasKey(keys::kRequirements))
1641 return true;
1642
1643 DictionaryValue* requirements_value = NULL;
1644 if (!manifest_->GetDictionary(keys::kRequirements, &requirements_value)) {
1645 *error = ASCIIToUTF16(errors::kInvalidRequirements);
1646 return false;
1647 }
1648
1649 for (DictionaryValue::key_iterator it = requirements_value->begin_keys();
1650 it != requirements_value->end_keys(); ++it) {
1651 DictionaryValue* requirement_value;
1652 if (!requirements_value->GetDictionaryWithoutPathExpansion(
1653 *it, &requirement_value)) {
1654 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
1655 errors::kInvalidRequirement, *it);
1656 return false;
1657 }
1658
1659 if (*it == "plugins") {
1660 for (DictionaryValue::key_iterator plugin_it =
1661 requirement_value->begin_keys();
1662 plugin_it != requirement_value->end_keys(); ++plugin_it) {
1663 bool plugin_required = false;
1664 if (!requirement_value->GetBoolean(*plugin_it, &plugin_required)) {
1665 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
1666 errors::kInvalidRequirement, *it);
1667 return false;
1668 }
1669 if (*plugin_it == "npapi") {
1670 requirements_.npapi = plugin_required;
1671 } else {
1672 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
1673 errors::kInvalidRequirement, *it);
1674 return false;
1675 }
1676 }
1677 } else if (*it == "3D") {
1678 ListValue* features = NULL;
1679 if (!requirement_value->GetListWithoutPathExpansion("features",
1680 &features) ||
1681 !features) {
1682 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
1683 errors::kInvalidRequirement, *it);
1684 return false;
1685 }
1686
1687 for (base::ListValue::iterator feature_it = features->begin();
1688 feature_it != features->end();
1689 ++feature_it) {
1690 std::string feature;
1691 if ((*feature_it)->GetAsString(&feature)) {
1692 if (feature == "webgl") {
1693 requirements_.webgl = true;
1694 } else if (feature == "css3d") {
1695 requirements_.css3d = true;
1696 } else {
1697 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
1698 errors::kInvalidRequirement, *it);
1699 return false;
1700 }
1701 }
1702 }
1703 } else {
1704 *error = ASCIIToUTF16(errors::kInvalidRequirements);
1705 return false;
1706 }
1707 }
1708 return true;
1709 }
1710
1627 bool Extension::LoadDefaultLocale(string16* error) { 1711 bool Extension::LoadDefaultLocale(string16* error) {
1628 if (!manifest_->HasKey(keys::kDefaultLocale)) 1712 if (!manifest_->HasKey(keys::kDefaultLocale))
1629 return true; 1713 return true;
1630 if (!manifest_->GetString(keys::kDefaultLocale, &default_locale_) || 1714 if (!manifest_->GetString(keys::kDefaultLocale, &default_locale_) ||
1631 !l10n_util::IsValidLocaleSyntax(default_locale_)) { 1715 !l10n_util::IsValidLocaleSyntax(default_locale_)) {
1632 *error = ASCIIToUTF16(errors::kInvalidDefaultLocale); 1716 *error = ASCIIToUTF16(errors::kInvalidDefaultLocale);
1633 return false; 1717 return false;
1634 } 1718 }
1635 return true; 1719 return true;
1636 } 1720 }
(...skipping 2164 matching lines...) Expand 10 before | Expand all | Expand 10 after
3801 if (current_version.CompareTo(minimum_version) < 0) { 3885 if (current_version.CompareTo(minimum_version) < 0) {
3802 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( 3886 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
3803 errors::kChromeVersionTooLow, 3887 errors::kChromeVersionTooLow,
3804 l10n_util::GetStringUTF8(IDS_PRODUCT_NAME), 3888 l10n_util::GetStringUTF8(IDS_PRODUCT_NAME),
3805 minimum_version_string); 3889 minimum_version_string);
3806 return false; 3890 return false;
3807 } 3891 }
3808 return true; 3892 return true;
3809 } 3893 }
3810 3894
3811 // These are not actually persisted (they're only used by the store), but
3812 // still validated.
3813 bool Extension::CheckRequirements(string16* error) const {
3814 if (!manifest_->HasKey(keys::kRequirements))
3815 return true;
3816 DictionaryValue* requirements_value = NULL;
3817 if (!manifest_->GetDictionary(keys::kRequirements, &requirements_value)) {
3818 *error = ASCIIToUTF16(errors::kInvalidRequirements);
3819 return false;
3820 }
3821
3822 for (DictionaryValue::key_iterator it = requirements_value->begin_keys();
3823 it != requirements_value->end_keys(); ++it) {
3824 DictionaryValue* requirement_value;
3825 if (!requirements_value->GetDictionaryWithoutPathExpansion(
3826 *it, &requirement_value)) {
3827 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
3828 errors::kInvalidRequirement, *it);
3829 return false;
3830 }
3831 }
3832 return true;
3833 }
3834
3835 bool Extension::CheckPlatformAppFeatures(std::string* utf8_error) const { 3895 bool Extension::CheckPlatformAppFeatures(std::string* utf8_error) const {
3836 if (!is_platform_app()) 3896 if (!is_platform_app())
3837 return true; 3897 return true;
3838 3898
3839 if (!has_background_page()) { 3899 if (!has_background_page()) {
3840 *utf8_error = errors::kBackgroundRequiredForPlatformApps; 3900 *utf8_error = errors::kBackgroundRequiredForPlatformApps;
3841 return false; 3901 return false;
3842 } 3902 }
3843 3903
3844 return true; 3904 return true;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
3905 3965
3906 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 3966 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
3907 const Extension* extension, 3967 const Extension* extension,
3908 const PermissionSet* permissions, 3968 const PermissionSet* permissions,
3909 Reason reason) 3969 Reason reason)
3910 : reason(reason), 3970 : reason(reason),
3911 extension(extension), 3971 extension(extension),
3912 permissions(permissions) {} 3972 permissions(permissions) {}
3913 3973
3914 } // namespace extensions 3974 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698