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 "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_path.h" | 10 #include "base/file_path.h" |
(...skipping 1575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1586 } | 1586 } |
1587 if (relative_path[0] != '/') | 1587 if (relative_path[0] != '/') |
1588 relative_path = '/' + relative_path; | 1588 relative_path = '/' + relative_path; |
1589 web_accessible_resources_.insert(relative_path); | 1589 web_accessible_resources_.insert(relative_path); |
1590 } | 1590 } |
1591 | 1591 |
1592 return true; | 1592 return true; |
1593 } | 1593 } |
1594 | 1594 |
1595 bool Extension::LoadSandboxedPages(string16* error) { | 1595 bool Extension::LoadSandboxedPages(string16* error) { |
1596 // Can't use HasKey, since it doesn't do path expansion. | 1596 if (!manifest_->HasPath(keys::kSandboxedPages)) |
1597 Value* ignored = NULL; | |
1598 if (!manifest_->Get(keys::kSandboxedPages, &ignored)) | |
1599 return true; | 1597 return true; |
1600 | 1598 |
1601 ListValue* list_value = NULL; | 1599 ListValue* list_value = NULL; |
1602 if (!manifest_->GetList(keys::kSandboxedPages, &list_value)) { | 1600 if (!manifest_->GetList(keys::kSandboxedPages, &list_value)) { |
1603 *error = ASCIIToUTF16(errors::kInvalidSandboxedPagesList); | 1601 *error = ASCIIToUTF16(errors::kInvalidSandboxedPagesList); |
1604 return false; | 1602 return false; |
1605 } | 1603 } |
1606 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 1604 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
1607 std::string relative_path; | 1605 std::string relative_path; |
1608 if (!list_value->GetString(i, &relative_path)) { | 1606 if (!list_value->GetString(i, &relative_path)) { |
1609 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1607 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
1610 errors::kInvalidSandboxedPage, base::IntToString(i)); | 1608 errors::kInvalidSandboxedPage, base::IntToString(i)); |
1611 return false; | 1609 return false; |
1612 } | 1610 } |
1613 if (relative_path[0] != '/') | 1611 if (relative_path[0] != '/') |
1614 relative_path = '/' + relative_path; | 1612 relative_path = '/' + relative_path; |
1615 sandboxed_pages_.insert(relative_path); | 1613 sandboxed_pages_.insert(relative_path); |
1616 } | 1614 } |
1617 | 1615 |
1618 if (manifest_->Get(keys::kSandboxedPagesCSP, &ignored)) { | 1616 if (manifest_->HasPath(keys::kSandboxedPagesCSP)) { |
1619 if (!manifest_->GetString( | 1617 if (!manifest_->GetString( |
1620 keys::kSandboxedPagesCSP, &sandboxed_pages_content_security_policy_)) { | 1618 keys::kSandboxedPagesCSP, &sandboxed_pages_content_security_policy_)) { |
1621 *error = ASCIIToUTF16(errors::kInvalidSandboxedPagesCSP); | 1619 *error = ASCIIToUTF16(errors::kInvalidSandboxedPagesCSP); |
1622 return false; | 1620 return false; |
1623 } | 1621 } |
1624 | 1622 |
1625 if (!ContentSecurityPolicyIsLegal( | 1623 if (!ContentSecurityPolicyIsLegal( |
1626 sandboxed_pages_content_security_policy_) || | 1624 sandboxed_pages_content_security_policy_) || |
1627 !ContentSecurityPolicyIsSandboxed( | 1625 !ContentSecurityPolicyIsSandboxed( |
1628 sandboxed_pages_content_security_policy_, GetType())) { | 1626 sandboxed_pages_content_security_policy_, GetType())) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1712 if (!options_url_.is_valid()) { | 1710 if (!options_url_.is_valid()) { |
1713 *error = ASCIIToUTF16(errors::kInvalidOptionsPage); | 1711 *error = ASCIIToUTF16(errors::kInvalidOptionsPage); |
1714 return false; | 1712 return false; |
1715 } | 1713 } |
1716 } | 1714 } |
1717 | 1715 |
1718 return true; | 1716 return true; |
1719 } | 1717 } |
1720 | 1718 |
1721 bool Extension::LoadBackgroundScripts(string16* error) { | 1719 bool Extension::LoadBackgroundScripts(string16* error) { |
| 1720 if (is_platform_app()) { |
| 1721 if (manifest_->HasPath(keys::kBackgroundScripts)) { |
| 1722 *error = ASCIIToUTF16(errors::kPlatformAppInvalidBackgroundScripts); |
| 1723 return false; |
| 1724 } |
| 1725 |
| 1726 return LoadBackgroundScripts(keys::kPlatformAppBackgroundScripts, error); |
| 1727 } |
| 1728 |
| 1729 return LoadBackgroundScripts(keys::kBackgroundScripts, error); |
| 1730 } |
| 1731 |
| 1732 bool Extension::LoadBackgroundScripts(const std::string& key, string16* error) { |
1722 Value* background_scripts_value = NULL; | 1733 Value* background_scripts_value = NULL; |
1723 if (!manifest_->Get(keys::kBackgroundScripts, &background_scripts_value)) | 1734 if (!manifest_->Get(key, &background_scripts_value)) |
1724 return true; | 1735 return true; |
1725 | 1736 |
1726 CHECK(background_scripts_value); | 1737 CHECK(background_scripts_value); |
1727 if (background_scripts_value->GetType() != Value::TYPE_LIST) { | 1738 if (background_scripts_value->GetType() != Value::TYPE_LIST) { |
1728 *error = ASCIIToUTF16(errors::kInvalidBackgroundScripts); | 1739 *error = ASCIIToUTF16(errors::kInvalidBackgroundScripts); |
1729 return false; | 1740 return false; |
1730 } | 1741 } |
1731 | 1742 |
1732 ListValue* background_scripts = | 1743 ListValue* background_scripts = |
1733 static_cast<ListValue*>(background_scripts_value); | 1744 static_cast<ListValue*>(background_scripts_value); |
1734 for (size_t i = 0; i < background_scripts->GetSize(); ++i) { | 1745 for (size_t i = 0; i < background_scripts->GetSize(); ++i) { |
1735 std::string script; | 1746 std::string script; |
1736 if (!background_scripts->GetString(i, &script)) { | 1747 if (!background_scripts->GetString(i, &script)) { |
1737 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1748 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
1738 errors::kInvalidBackgroundScript, base::IntToString(i)); | 1749 errors::kInvalidBackgroundScript, base::IntToString(i)); |
1739 return false; | 1750 return false; |
1740 } | 1751 } |
1741 background_scripts_.push_back(script); | 1752 background_scripts_.push_back(script); |
1742 } | 1753 } |
1743 | 1754 |
1744 return true; | 1755 return true; |
1745 } | 1756 } |
1746 | 1757 |
1747 bool Extension::LoadBackgroundPage( | 1758 bool Extension::LoadBackgroundPage( |
1748 const ExtensionAPIPermissionSet& api_permissions, | 1759 const ExtensionAPIPermissionSet& api_permissions, |
1749 string16* error) { | 1760 string16* error) { |
| 1761 if (is_platform_app()) { |
| 1762 if (manifest_->HasPath(keys::kBackgroundPage) || |
| 1763 manifest_->HasPath(keys::kBackgroundPageLegacy)) { |
| 1764 *error = ASCIIToUTF16(errors::kPlatformAppInvalidBackgroundPage); |
| 1765 return false; |
| 1766 } |
| 1767 |
| 1768 return LoadBackgroundPage( |
| 1769 keys::kPlatformAppBackgroundPage, api_permissions, error); |
| 1770 } |
| 1771 |
| 1772 |
| 1773 if (!LoadBackgroundPage(keys::kBackgroundPage, api_permissions, error)) |
| 1774 return false; |
| 1775 if (background_url_.is_empty()) |
| 1776 return LoadBackgroundPage( |
| 1777 keys::kBackgroundPageLegacy, api_permissions, error); |
| 1778 return true; |
| 1779 } |
| 1780 |
| 1781 bool Extension::LoadBackgroundPage( |
| 1782 const std::string& key, |
| 1783 const ExtensionAPIPermissionSet& api_permissions, |
| 1784 string16* error) { |
1750 base::Value* background_page_value = NULL; | 1785 base::Value* background_page_value = NULL; |
1751 if (!manifest_->Get(keys::kBackgroundPage, &background_page_value)) | 1786 if (!manifest_->Get(key, &background_page_value)) |
1752 manifest_->Get(keys::kBackgroundPageLegacy, &background_page_value); | 1787 return true; |
1753 | 1788 |
1754 if (!background_page_value) | 1789 if (!background_scripts_.empty()) { |
1755 return true; | 1790 *error = ASCIIToUTF16(errors::kInvalidBackgroundCombination); |
| 1791 return false; |
| 1792 } |
| 1793 |
1756 | 1794 |
1757 std::string background_str; | 1795 std::string background_str; |
1758 if (!background_page_value->GetAsString(&background_str)) { | 1796 if (!background_page_value->GetAsString(&background_str)) { |
1759 *error = ASCIIToUTF16(errors::kInvalidBackground); | 1797 *error = ASCIIToUTF16(errors::kInvalidBackground); |
1760 return false; | 1798 return false; |
1761 } | 1799 } |
1762 | 1800 |
1763 if (!background_scripts_.empty()) { | 1801 if (is_hosted_app()) { |
1764 *error = ASCIIToUTF16(errors::kInvalidBackgroundCombination); | 1802 background_url_ = GURL(background_str); |
1765 return false; | |
1766 } | |
1767 | 1803 |
1768 if (is_hosted_app()) { | |
1769 // Make sure "background" permission is set. | 1804 // Make sure "background" permission is set. |
1770 if (!api_permissions.count(ExtensionAPIPermission::kBackground)) { | 1805 if (!api_permissions.count(ExtensionAPIPermission::kBackground)) { |
1771 *error = ASCIIToUTF16(errors::kBackgroundPermissionNeeded); | 1806 *error = ASCIIToUTF16(errors::kBackgroundPermissionNeeded); |
1772 return false; | 1807 return false; |
1773 } | 1808 } |
1774 // Hosted apps require an absolute URL. | 1809 // Hosted apps require an absolute URL. |
1775 GURL bg_page(background_str); | 1810 if (!background_url_.is_valid()) { |
1776 if (!bg_page.is_valid()) { | |
1777 *error = ASCIIToUTF16(errors::kInvalidBackgroundInHostedApp); | 1811 *error = ASCIIToUTF16(errors::kInvalidBackgroundInHostedApp); |
1778 return false; | 1812 return false; |
1779 } | 1813 } |
1780 | 1814 |
1781 if (!(bg_page.SchemeIs("https") || | 1815 if (!(background_url_.SchemeIs("https") || |
1782 (CommandLine::ForCurrentProcess()->HasSwitch( | 1816 (CommandLine::ForCurrentProcess()->HasSwitch( |
1783 switches::kAllowHTTPBackgroundPage) && | 1817 switches::kAllowHTTPBackgroundPage) && |
1784 bg_page.SchemeIs("http")))) { | 1818 background_url_.SchemeIs("http")))) { |
1785 *error = ASCIIToUTF16(errors::kInvalidBackgroundInHostedApp); | 1819 *error = ASCIIToUTF16(errors::kInvalidBackgroundInHostedApp); |
1786 return false; | 1820 return false; |
1787 } | 1821 } |
1788 background_url_ = bg_page; | |
1789 } else { | 1822 } else { |
1790 background_url_ = GetResourceURL(background_str); | 1823 background_url_ = GetResourceURL(background_str); |
1791 } | 1824 } |
1792 | 1825 |
1793 return true; | 1826 return true; |
1794 } | 1827 } |
1795 | 1828 |
1796 bool Extension::LoadBackgroundPersistent( | 1829 bool Extension::LoadBackgroundPersistent( |
1797 const ExtensionAPIPermissionSet& api_permissions, | 1830 const ExtensionAPIPermissionSet& api_permissions, |
1798 string16* error) { | 1831 string16* error) { |
(...skipping 1903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3702 | 3735 |
3703 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 3736 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
3704 const Extension* extension, | 3737 const Extension* extension, |
3705 const ExtensionPermissionSet* permissions, | 3738 const ExtensionPermissionSet* permissions, |
3706 Reason reason) | 3739 Reason reason) |
3707 : reason(reason), | 3740 : reason(reason), |
3708 extension(extension), | 3741 extension(extension), |
3709 permissions(permissions) {} | 3742 permissions(permissions) {} |
3710 | 3743 |
3711 } // namespace extensions | 3744 } // namespace extensions |
OLD | NEW |