| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/extension.h" | 5 #include "chrome/common/extensions/extension.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 26 #include "chrome/common/chrome_version_info.h" | 26 #include "chrome/common/chrome_version_info.h" |
| 27 // TODO(rdevlin.cronin): Remove these once all references have been removed as | 27 // TODO(rdevlin.cronin): Remove these once all references have been removed as |
| 28 // part of crbug.com/159265. | 28 // part of crbug.com/159265. |
| 29 #include "chrome/common/extensions/api/extension_action/action_info.h" | 29 #include "chrome/common/extensions/api/extension_action/action_info.h" |
| 30 #include "chrome/common/extensions/api/extension_action/page_action_handler.h" | 30 #include "chrome/common/extensions/api/extension_action/page_action_handler.h" |
| 31 #include "chrome/common/extensions/api/icons/icons_handler.h" | 31 #include "chrome/common/extensions/api/icons/icons_handler.h" |
| 32 #include "chrome/common/extensions/api/plugins/plugins_handler.h" | 32 #include "chrome/common/extensions/api/plugins/plugins_handler.h" |
| 33 #include "chrome/common/extensions/api/themes/theme_handler.h" | 33 #include "chrome/common/extensions/api/themes/theme_handler.h" |
| 34 #include "chrome/common/extensions/background_info.h" | 34 #include "chrome/common/extensions/background_info.h" |
| 35 #include "chrome/common/extensions/csp_handler.h" | |
| 36 #include "chrome/common/extensions/csp_validator.h" | |
| 37 #include "chrome/common/extensions/extension_icon_set.h" | 35 #include "chrome/common/extensions/extension_icon_set.h" |
| 38 #include "chrome/common/extensions/extension_manifest_constants.h" | 36 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 39 #include "chrome/common/extensions/feature_switch.h" | 37 #include "chrome/common/extensions/feature_switch.h" |
| 40 #include "chrome/common/extensions/features/base_feature_provider.h" | 38 #include "chrome/common/extensions/features/base_feature_provider.h" |
| 41 #include "chrome/common/extensions/features/feature.h" | 39 #include "chrome/common/extensions/features/feature.h" |
| 42 #include "chrome/common/extensions/incognito_handler.h" | 40 #include "chrome/common/extensions/incognito_handler.h" |
| 43 #include "chrome/common/extensions/manifest.h" | 41 #include "chrome/common/extensions/manifest.h" |
| 44 #include "chrome/common/extensions/manifest_handler.h" | 42 #include "chrome/common/extensions/manifest_handler.h" |
| 45 #include "chrome/common/extensions/manifest_handler_helpers.h" | 43 #include "chrome/common/extensions/manifest_handler_helpers.h" |
| 46 #include "chrome/common/extensions/manifest_url_handler.h" | 44 #include "chrome/common/extensions/manifest_url_handler.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 61 | 59 |
| 62 #if defined(OS_WIN) | 60 #if defined(OS_WIN) |
| 63 #include "grit/generated_resources.h" | 61 #include "grit/generated_resources.h" |
| 64 #endif | 62 #endif |
| 65 | 63 |
| 66 namespace keys = extension_manifest_keys; | 64 namespace keys = extension_manifest_keys; |
| 67 namespace values = extension_manifest_values; | 65 namespace values = extension_manifest_values; |
| 68 namespace errors = extension_manifest_errors; | 66 namespace errors = extension_manifest_errors; |
| 69 namespace info_keys = extension_info_keys; | 67 namespace info_keys = extension_info_keys; |
| 70 | 68 |
| 71 using extensions::csp_validator::ContentSecurityPolicyIsLegal; | |
| 72 using extensions::csp_validator::ContentSecurityPolicyIsSandboxed; | |
| 73 | |
| 74 namespace extensions { | 69 namespace extensions { |
| 75 | 70 |
| 76 namespace { | 71 namespace { |
| 77 | 72 |
| 78 const int kModernManifestVersion = 2; | 73 const int kModernManifestVersion = 2; |
| 79 const int kPEMOutputColumns = 65; | 74 const int kPEMOutputColumns = 65; |
| 80 | 75 |
| 81 // The maximum number of commands (including page action/browser actions) an | 76 // The maximum number of commands (including page action/browser actions) an |
| 82 // extension can have. | 77 // extension can have. |
| 83 const size_t kMaxCommandsPerExtension = 4; | 78 const size_t kMaxCommandsPerExtension = 4; |
| 84 | 79 |
| 85 // KEY MARKERS | 80 // KEY MARKERS |
| 86 const char kKeyBeginHeaderMarker[] = "-----BEGIN"; | 81 const char kKeyBeginHeaderMarker[] = "-----BEGIN"; |
| 87 const char kKeyBeginFooterMarker[] = "-----END"; | 82 const char kKeyBeginFooterMarker[] = "-----END"; |
| 88 const char kKeyInfoEndMarker[] = "KEY-----"; | 83 const char kKeyInfoEndMarker[] = "KEY-----"; |
| 89 const char kPublic[] = "PUBLIC"; | 84 const char kPublic[] = "PUBLIC"; |
| 90 const char kPrivate[] = "PRIVATE"; | 85 const char kPrivate[] = "PRIVATE"; |
| 91 | 86 |
| 92 const int kRSAKeySize = 1024; | 87 const int kRSAKeySize = 1024; |
| 93 | 88 |
| 94 const char kDefaultSandboxedPageContentSecurityPolicy[] = | |
| 95 "sandbox allow-scripts allow-forms allow-popups"; | |
| 96 | |
| 97 const char kThumbsWhiteListedExtension[] = "khopmbdjffemhegeeobelklnbglcdgfh"; | 89 const char kThumbsWhiteListedExtension[] = "khopmbdjffemhegeeobelklnbglcdgfh"; |
| 98 | 90 |
| 99 // A singleton object containing global data needed by the extension objects. | 91 // A singleton object containing global data needed by the extension objects. |
| 100 class ExtensionConfig { | 92 class ExtensionConfig { |
| 101 public: | 93 public: |
| 102 static ExtensionConfig* GetInstance() { | 94 static ExtensionConfig* GetInstance() { |
| 103 return Singleton<ExtensionConfig>::get(); | 95 return Singleton<ExtensionConfig>::get(); |
| 104 } | 96 } |
| 105 | 97 |
| 106 Extension::ScriptingWhitelist* whitelist() { return &scripting_whitelist_; } | 98 Extension::ScriptingWhitelist* whitelist() { return &scripting_whitelist_; } |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 DCHECK(StartsWithASCII(ret_val.spec(), extension_url.spec(), false)); | 301 DCHECK(StartsWithASCII(ret_val.spec(), extension_url.spec(), false)); |
| 310 | 302 |
| 311 return ret_val; | 303 return ret_val; |
| 312 } | 304 } |
| 313 | 305 |
| 314 bool Extension::ResourceMatches(const URLPatternSet& pattern_set, | 306 bool Extension::ResourceMatches(const URLPatternSet& pattern_set, |
| 315 const std::string& resource) const { | 307 const std::string& resource) const { |
| 316 return pattern_set.MatchesURL(extension_url_.Resolve(resource)); | 308 return pattern_set.MatchesURL(extension_url_.Resolve(resource)); |
| 317 } | 309 } |
| 318 | 310 |
| 319 bool Extension::IsSandboxedPage(const std::string& relative_path) const { | |
| 320 return ResourceMatches(sandboxed_pages_, relative_path); | |
| 321 } | |
| 322 | |
| 323 std::string Extension::GetResourceContentSecurityPolicy( | |
| 324 const std::string& relative_path) const { | |
| 325 return IsSandboxedPage(relative_path) ? | |
| 326 sandboxed_pages_content_security_policy_ : | |
| 327 CSPInfo::GetContentSecurityPolicy(this); | |
| 328 } | |
| 329 | |
| 330 ExtensionResource Extension::GetResource( | 311 ExtensionResource Extension::GetResource( |
| 331 const std::string& relative_path) const { | 312 const std::string& relative_path) const { |
| 332 std::string new_path = relative_path; | 313 std::string new_path = relative_path; |
| 333 // We have some legacy data where resources have leading slashes. | 314 // We have some legacy data where resources have leading slashes. |
| 334 // See: http://crbug.com/121164 | 315 // See: http://crbug.com/121164 |
| 335 if (!new_path.empty() && new_path.at(0) == '/') | 316 if (!new_path.empty() && new_path.at(0) == '/') |
| 336 new_path.erase(0, 1); | 317 new_path.erase(0, 1); |
| 337 #if defined(OS_POSIX) | 318 #if defined(OS_POSIX) |
| 338 base::FilePath relative_file_path(new_path); | 319 base::FilePath relative_file_path(new_path); |
| 339 #elif defined(OS_WIN) | 320 #elif defined(OS_WIN) |
| (...skipping 1309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1649 extent_.ClearPatterns(); | 1630 extent_.ClearPatterns(); |
| 1650 } | 1631 } |
| 1651 | 1632 |
| 1652 return true; | 1633 return true; |
| 1653 } | 1634 } |
| 1654 | 1635 |
| 1655 bool Extension::LoadSharedFeatures(string16* error) { | 1636 bool Extension::LoadSharedFeatures(string16* error) { |
| 1656 if (!LoadDescription(error) || | 1637 if (!LoadDescription(error) || |
| 1657 !ManifestHandler::ParseExtension(this, error) || | 1638 !ManifestHandler::ParseExtension(this, error) || |
| 1658 !LoadNaClModules(error) || | 1639 !LoadNaClModules(error) || |
| 1659 !LoadSandboxedPages(error) || | |
| 1660 !LoadKioskEnabled(error) || | 1640 !LoadKioskEnabled(error) || |
| 1661 !LoadOfflineEnabled(error)) | 1641 !LoadOfflineEnabled(error)) |
| 1662 return false; | 1642 return false; |
| 1663 | 1643 |
| 1664 return true; | 1644 return true; |
| 1665 } | 1645 } |
| 1666 | 1646 |
| 1667 bool Extension::LoadDescription(string16* error) { | 1647 bool Extension::LoadDescription(string16* error) { |
| 1668 if (manifest_->HasKey(keys::kDescription) && | 1648 if (manifest_->HasKey(keys::kDescription) && |
| 1669 !manifest_->GetString(keys::kDescription, &description_)) { | 1649 !manifest_->GetString(keys::kDescription, &description_)) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1732 } | 1712 } |
| 1733 | 1713 |
| 1734 nacl_modules_.push_back(NaClModuleInfo()); | 1714 nacl_modules_.push_back(NaClModuleInfo()); |
| 1735 nacl_modules_.back().url = GetResourceURL(path_str); | 1715 nacl_modules_.back().url = GetResourceURL(path_str); |
| 1736 nacl_modules_.back().mime_type = mime_type; | 1716 nacl_modules_.back().mime_type = mime_type; |
| 1737 } | 1717 } |
| 1738 | 1718 |
| 1739 return true; | 1719 return true; |
| 1740 } | 1720 } |
| 1741 | 1721 |
| 1742 bool Extension::LoadSandboxedPages(string16* error) { | |
| 1743 if (!manifest_->HasPath(keys::kSandboxedPages)) | |
| 1744 return true; | |
| 1745 | |
| 1746 const ListValue* list_value = NULL; | |
| 1747 if (!manifest_->GetList(keys::kSandboxedPages, &list_value)) { | |
| 1748 *error = ASCIIToUTF16(errors::kInvalidSandboxedPagesList); | |
| 1749 return false; | |
| 1750 } | |
| 1751 for (size_t i = 0; i < list_value->GetSize(); ++i) { | |
| 1752 std::string relative_path; | |
| 1753 if (!list_value->GetString(i, &relative_path)) { | |
| 1754 *error = ErrorUtils::FormatErrorMessageUTF16( | |
| 1755 errors::kInvalidSandboxedPage, base::IntToString(i)); | |
| 1756 return false; | |
| 1757 } | |
| 1758 URLPattern pattern(URLPattern::SCHEME_EXTENSION); | |
| 1759 if (pattern.Parse(extension_url_.spec()) != URLPattern::PARSE_SUCCESS) { | |
| 1760 *error = ErrorUtils::FormatErrorMessageUTF16( | |
| 1761 errors::kInvalidURLPatternError, extension_url_.spec()); | |
| 1762 return false; | |
| 1763 } | |
| 1764 while (relative_path[0] == '/') | |
| 1765 relative_path = relative_path.substr(1, relative_path.length() - 1); | |
| 1766 pattern.SetPath(pattern.path() + relative_path); | |
| 1767 sandboxed_pages_.AddPattern(pattern); | |
| 1768 } | |
| 1769 | |
| 1770 if (manifest_->HasPath(keys::kSandboxedPagesCSP)) { | |
| 1771 if (!manifest_->GetString( | |
| 1772 keys::kSandboxedPagesCSP, &sandboxed_pages_content_security_policy_)) { | |
| 1773 *error = ASCIIToUTF16(errors::kInvalidSandboxedPagesCSP); | |
| 1774 return false; | |
| 1775 } | |
| 1776 | |
| 1777 if (!ContentSecurityPolicyIsLegal( | |
| 1778 sandboxed_pages_content_security_policy_) || | |
| 1779 !ContentSecurityPolicyIsSandboxed( | |
| 1780 sandboxed_pages_content_security_policy_, GetType())) { | |
| 1781 *error = ASCIIToUTF16(errors::kInvalidSandboxedPagesCSP); | |
| 1782 return false; | |
| 1783 } | |
| 1784 } else { | |
| 1785 sandboxed_pages_content_security_policy_ = | |
| 1786 kDefaultSandboxedPageContentSecurityPolicy; | |
| 1787 CHECK(ContentSecurityPolicyIsSandboxed( | |
| 1788 sandboxed_pages_content_security_policy_, GetType())); | |
| 1789 } | |
| 1790 | |
| 1791 return true; | |
| 1792 } | |
| 1793 | |
| 1794 bool Extension::LoadKioskEnabled(string16* error) { | 1722 bool Extension::LoadKioskEnabled(string16* error) { |
| 1795 if (!manifest_->HasKey(keys::kKioskEnabled)) | 1723 if (!manifest_->HasKey(keys::kKioskEnabled)) |
| 1796 return true; | 1724 return true; |
| 1797 | 1725 |
| 1798 if (!manifest_->GetBoolean(keys::kKioskEnabled, &kiosk_enabled_)) { | 1726 if (!manifest_->GetBoolean(keys::kKioskEnabled, &kiosk_enabled_)) { |
| 1799 *error = ASCIIToUTF16(errors::kInvalidKioskEnabled); | 1727 *error = ASCIIToUTF16(errors::kInvalidKioskEnabled); |
| 1800 return false; | 1728 return false; |
| 1801 } | 1729 } |
| 1802 | 1730 |
| 1803 // All other use cases should be already filtered out by manifest feature | 1731 // All other use cases should be already filtered out by manifest feature |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2001 | 1929 |
| 2002 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 1930 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
| 2003 const Extension* extension, | 1931 const Extension* extension, |
| 2004 const PermissionSet* permissions, | 1932 const PermissionSet* permissions, |
| 2005 Reason reason) | 1933 Reason reason) |
| 2006 : reason(reason), | 1934 : reason(reason), |
| 2007 extension(extension), | 1935 extension(extension), |
| 2008 permissions(permissions) {} | 1936 permissions(permissions) {} |
| 2009 | 1937 |
| 2010 } // namespace extensions | 1938 } // namespace extensions |
| OLD | NEW |