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

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

Issue 10544059: Change the platform app manifest structure. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update for getDisplayPath, implement restrictions via _manifest_features.json Created 8 years, 6 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 | Annotate | Revision Log
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 "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
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
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 return LoadBackgroundScripts(keys::kPlatformAppBackgroundScripts, error);
1722 }
1723
1724 return LoadBackgroundScripts(keys::kBackgroundScripts, error);
1725 }
1726
1727 bool Extension::LoadBackgroundScripts(const std::string& key, string16* error) {
1722 Value* background_scripts_value = NULL; 1728 Value* background_scripts_value = NULL;
1723 if (!manifest_->Get(keys::kBackgroundScripts, &background_scripts_value)) 1729 if (!manifest_->Get(key, &background_scripts_value))
1724 return true; 1730 return true;
1725 1731
1726 CHECK(background_scripts_value); 1732 CHECK(background_scripts_value);
1727 if (background_scripts_value->GetType() != Value::TYPE_LIST) { 1733 if (background_scripts_value->GetType() != Value::TYPE_LIST) {
1728 *error = ASCIIToUTF16(errors::kInvalidBackgroundScripts); 1734 *error = ASCIIToUTF16(errors::kInvalidBackgroundScripts);
1729 return false; 1735 return false;
1730 } 1736 }
1731 1737
1732 ListValue* background_scripts = 1738 ListValue* background_scripts =
1733 static_cast<ListValue*>(background_scripts_value); 1739 static_cast<ListValue*>(background_scripts_value);
1734 for (size_t i = 0; i < background_scripts->GetSize(); ++i) { 1740 for (size_t i = 0; i < background_scripts->GetSize(); ++i) {
1735 std::string script; 1741 std::string script;
1736 if (!background_scripts->GetString(i, &script)) { 1742 if (!background_scripts->GetString(i, &script)) {
1737 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( 1743 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(
1738 errors::kInvalidBackgroundScript, base::IntToString(i)); 1744 errors::kInvalidBackgroundScript, base::IntToString(i));
1739 return false; 1745 return false;
1740 } 1746 }
1741 background_scripts_.push_back(script); 1747 background_scripts_.push_back(script);
1742 } 1748 }
1743 1749
1744 return true; 1750 return true;
1745 } 1751 }
1746 1752
1747 bool Extension::LoadBackgroundPage( 1753 bool Extension::LoadBackgroundPage(
1748 const ExtensionAPIPermissionSet& api_permissions, 1754 const ExtensionAPIPermissionSet& api_permissions,
1749 string16* error) { 1755 string16* error) {
1756 if (is_platform_app()) {
1757 return LoadBackgroundPage(
1758 keys::kPlatformAppBackgroundPage, api_permissions, error);
1759 }
1760
1761 if (!LoadBackgroundPage(keys::kBackgroundPage, api_permissions, error))
1762 return false;
1763 if (background_url_.is_empty())
1764 return LoadBackgroundPage(
1765 keys::kBackgroundPageLegacy, api_permissions, error);
1766 return true;
1767 }
1768
1769 bool Extension::LoadBackgroundPage(
1770 const std::string& key,
1771 const ExtensionAPIPermissionSet& api_permissions,
1772 string16* error) {
1750 base::Value* background_page_value = NULL; 1773 base::Value* background_page_value = NULL;
1751 if (!manifest_->Get(keys::kBackgroundPage, &background_page_value)) 1774 if (!manifest_->Get(key, &background_page_value))
1752 manifest_->Get(keys::kBackgroundPageLegacy, &background_page_value); 1775 return true;
1753 1776
1754 if (!background_page_value) 1777 if (!background_scripts_.empty()) {
1755 return true; 1778 *error = ASCIIToUTF16(errors::kInvalidBackgroundCombination);
1779 return false;
1780 }
1781
1756 1782
1757 std::string background_str; 1783 std::string background_str;
1758 if (!background_page_value->GetAsString(&background_str)) { 1784 if (!background_page_value->GetAsString(&background_str)) {
1759 *error = ASCIIToUTF16(errors::kInvalidBackground); 1785 *error = ASCIIToUTF16(errors::kInvalidBackground);
1760 return false; 1786 return false;
1761 } 1787 }
1762 1788
1763 if (!background_scripts_.empty()) { 1789 if (is_hosted_app()) {
1764 *error = ASCIIToUTF16(errors::kInvalidBackgroundCombination); 1790 background_url_ = GURL(background_str);
1765 return false;
1766 }
1767 1791
1768 if (is_hosted_app()) {
1769 // Make sure "background" permission is set. 1792 // Make sure "background" permission is set.
1770 if (!api_permissions.count(ExtensionAPIPermission::kBackground)) { 1793 if (!api_permissions.count(ExtensionAPIPermission::kBackground)) {
1771 *error = ASCIIToUTF16(errors::kBackgroundPermissionNeeded); 1794 *error = ASCIIToUTF16(errors::kBackgroundPermissionNeeded);
1772 return false; 1795 return false;
1773 } 1796 }
1774 // Hosted apps require an absolute URL. 1797 // Hosted apps require an absolute URL.
1775 GURL bg_page(background_str); 1798 if (!background_url_.is_valid()) {
1776 if (!bg_page.is_valid()) {
1777 *error = ASCIIToUTF16(errors::kInvalidBackgroundInHostedApp); 1799 *error = ASCIIToUTF16(errors::kInvalidBackgroundInHostedApp);
1778 return false; 1800 return false;
1779 } 1801 }
1780 1802
1781 if (!(bg_page.SchemeIs("https") || 1803 if (!(background_url_.SchemeIs("https") ||
1782 (CommandLine::ForCurrentProcess()->HasSwitch( 1804 (CommandLine::ForCurrentProcess()->HasSwitch(
1783 switches::kAllowHTTPBackgroundPage) && 1805 switches::kAllowHTTPBackgroundPage) &&
1784 bg_page.SchemeIs("http")))) { 1806 background_url_.SchemeIs("http")))) {
1785 *error = ASCIIToUTF16(errors::kInvalidBackgroundInHostedApp); 1807 *error = ASCIIToUTF16(errors::kInvalidBackgroundInHostedApp);
1786 return false; 1808 return false;
1787 } 1809 }
1788 background_url_ = bg_page;
1789 } else { 1810 } else {
1790 background_url_ = GetResourceURL(background_str); 1811 background_url_ = GetResourceURL(background_str);
1791 } 1812 }
1792 1813
1793 return true; 1814 return true;
1794 } 1815 }
1795 1816
1796 bool Extension::LoadBackgroundPersistent( 1817 bool Extension::LoadBackgroundPersistent(
1797 const ExtensionAPIPermissionSet& api_permissions, 1818 const ExtensionAPIPermissionSet& api_permissions,
1798 string16* error) { 1819 string16* error) {
(...skipping 1903 matching lines...) Expand 10 before | Expand all | Expand 10 after
3702 3723
3703 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 3724 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
3704 const Extension* extension, 3725 const Extension* extension,
3705 const ExtensionPermissionSet* permissions, 3726 const ExtensionPermissionSet* permissions,
3706 Reason reason) 3727 Reason reason)
3707 : reason(reason), 3728 : reason(reason),
3708 extension(extension), 3729 extension(extension),
3709 permissions(permissions) {} 3730 permissions(permissions) {}
3710 3731
3711 } // namespace extensions 3732 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_manifest_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698