| 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 | 179 |
| 180 const int Extension::kValidWebExtentSchemes = | 180 const int Extension::kValidWebExtentSchemes = |
| 181 URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS; | 181 URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS; |
| 182 | 182 |
| 183 const int Extension::kValidHostPermissionSchemes = URLPattern::SCHEME_CHROMEUI | | 183 const int Extension::kValidHostPermissionSchemes = URLPattern::SCHEME_CHROMEUI | |
| 184 URLPattern::SCHEME_HTTP | | 184 URLPattern::SCHEME_HTTP | |
| 185 URLPattern::SCHEME_HTTPS | | 185 URLPattern::SCHEME_HTTPS | |
| 186 URLPattern::SCHEME_FILE | | 186 URLPattern::SCHEME_FILE | |
| 187 URLPattern::SCHEME_FTP; | 187 URLPattern::SCHEME_FTP; |
| 188 | 188 |
| 189 Extension::Requirements::Requirements() | |
| 190 : webgl(false), | |
| 191 css3d(false), | |
| 192 npapi(false) { | |
| 193 } | |
| 194 | |
| 195 Extension::Requirements::~Requirements() {} | |
| 196 | |
| 197 // | 189 // |
| 198 // Extension | 190 // Extension |
| 199 // | 191 // |
| 200 | 192 |
| 201 // static | 193 // static |
| 202 scoped_refptr<Extension> Extension::Create(const base::FilePath& path, | 194 scoped_refptr<Extension> Extension::Create(const base::FilePath& path, |
| 203 Manifest::Location location, | 195 Manifest::Location location, |
| 204 const DictionaryValue& value, | 196 const DictionaryValue& value, |
| 205 int flags, | 197 int flags, |
| 206 std::string* utf8_error) { | 198 std::string* utf8_error) { |
| (...skipping 1449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1656 } | 1648 } |
| 1657 | 1649 |
| 1658 return true; | 1650 return true; |
| 1659 } | 1651 } |
| 1660 | 1652 |
| 1661 bool Extension::LoadSharedFeatures(string16* error) { | 1653 bool Extension::LoadSharedFeatures(string16* error) { |
| 1662 if (!LoadDescription(error) || | 1654 if (!LoadDescription(error) || |
| 1663 !ManifestHandler::ParseExtension(this, error) || | 1655 !ManifestHandler::ParseExtension(this, error) || |
| 1664 !LoadNaClModules(error) || | 1656 !LoadNaClModules(error) || |
| 1665 !LoadSandboxedPages(error) || | 1657 !LoadSandboxedPages(error) || |
| 1666 !LoadRequirements(error) || | |
| 1667 !LoadKioskEnabled(error) || | 1658 !LoadKioskEnabled(error) || |
| 1668 !LoadOfflineEnabled(error)) | 1659 !LoadOfflineEnabled(error)) |
| 1669 return false; | 1660 return false; |
| 1670 | 1661 |
| 1671 return true; | 1662 return true; |
| 1672 } | 1663 } |
| 1673 | 1664 |
| 1674 bool Extension::LoadDescription(string16* error) { | 1665 bool Extension::LoadDescription(string16* error) { |
| 1675 if (manifest_->HasKey(keys::kDescription) && | 1666 if (manifest_->HasKey(keys::kDescription) && |
| 1676 !manifest_->GetString(keys::kDescription, &description_)) { | 1667 !manifest_->GetString(keys::kDescription, &description_)) { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1791 } else { | 1782 } else { |
| 1792 sandboxed_pages_content_security_policy_ = | 1783 sandboxed_pages_content_security_policy_ = |
| 1793 kDefaultSandboxedPageContentSecurityPolicy; | 1784 kDefaultSandboxedPageContentSecurityPolicy; |
| 1794 CHECK(ContentSecurityPolicyIsSandboxed( | 1785 CHECK(ContentSecurityPolicyIsSandboxed( |
| 1795 sandboxed_pages_content_security_policy_, GetType())); | 1786 sandboxed_pages_content_security_policy_, GetType())); |
| 1796 } | 1787 } |
| 1797 | 1788 |
| 1798 return true; | 1789 return true; |
| 1799 } | 1790 } |
| 1800 | 1791 |
| 1801 bool Extension::LoadRequirements(string16* error) { | |
| 1802 // Before parsing requirements from the manifest, automatically default the | |
| 1803 // NPAPI plugin requirement based on whether it includes NPAPI plugins. | |
| 1804 const ListValue* list_value = NULL; | |
| 1805 requirements_.npapi = | |
| 1806 manifest_->GetList(keys::kPlugins, &list_value) && !list_value->empty(); | |
| 1807 | |
| 1808 if (!manifest_->HasKey(keys::kRequirements)) | |
| 1809 return true; | |
| 1810 | |
| 1811 const DictionaryValue* requirements_value = NULL; | |
| 1812 if (!manifest_->GetDictionary(keys::kRequirements, &requirements_value)) { | |
| 1813 *error = ASCIIToUTF16(errors::kInvalidRequirements); | |
| 1814 return false; | |
| 1815 } | |
| 1816 | |
| 1817 for (DictionaryValue::Iterator it(*requirements_value); !it.IsAtEnd(); | |
| 1818 it.Advance()) { | |
| 1819 const DictionaryValue* requirement_value; | |
| 1820 if (!it.value().GetAsDictionary(&requirement_value)) { | |
| 1821 *error = ErrorUtils::FormatErrorMessageUTF16( | |
| 1822 errors::kInvalidRequirement, it.key()); | |
| 1823 return false; | |
| 1824 } | |
| 1825 | |
| 1826 if (it.key() == "plugins") { | |
| 1827 for (DictionaryValue::Iterator plugin_it(*requirement_value); | |
| 1828 !plugin_it.IsAtEnd(); plugin_it.Advance()) { | |
| 1829 bool plugin_required = false; | |
| 1830 if (!plugin_it.value().GetAsBoolean(&plugin_required)) { | |
| 1831 *error = ErrorUtils::FormatErrorMessageUTF16( | |
| 1832 errors::kInvalidRequirement, it.key()); | |
| 1833 return false; | |
| 1834 } | |
| 1835 if (plugin_it.key() == "npapi") { | |
| 1836 requirements_.npapi = plugin_required; | |
| 1837 } else { | |
| 1838 *error = ErrorUtils::FormatErrorMessageUTF16( | |
| 1839 errors::kInvalidRequirement, it.key()); | |
| 1840 return false; | |
| 1841 } | |
| 1842 } | |
| 1843 } else if (it.key() == "3D") { | |
| 1844 const ListValue* features = NULL; | |
| 1845 if (!requirement_value->GetListWithoutPathExpansion("features", | |
| 1846 &features) || | |
| 1847 !features) { | |
| 1848 *error = ErrorUtils::FormatErrorMessageUTF16( | |
| 1849 errors::kInvalidRequirement, it.key()); | |
| 1850 return false; | |
| 1851 } | |
| 1852 | |
| 1853 for (base::ListValue::const_iterator feature_it = features->begin(); | |
| 1854 feature_it != features->end(); | |
| 1855 ++feature_it) { | |
| 1856 std::string feature; | |
| 1857 if ((*feature_it)->GetAsString(&feature)) { | |
| 1858 if (feature == "webgl") { | |
| 1859 requirements_.webgl = true; | |
| 1860 } else if (feature == "css3d") { | |
| 1861 requirements_.css3d = true; | |
| 1862 } else { | |
| 1863 *error = ErrorUtils::FormatErrorMessageUTF16( | |
| 1864 errors::kInvalidRequirement, it.key()); | |
| 1865 return false; | |
| 1866 } | |
| 1867 } | |
| 1868 } | |
| 1869 } else { | |
| 1870 *error = ASCIIToUTF16(errors::kInvalidRequirements); | |
| 1871 return false; | |
| 1872 } | |
| 1873 } | |
| 1874 return true; | |
| 1875 } | |
| 1876 | |
| 1877 bool Extension::LoadKioskEnabled(string16* error) { | 1792 bool Extension::LoadKioskEnabled(string16* error) { |
| 1878 if (!manifest_->HasKey(keys::kKioskEnabled)) | 1793 if (!manifest_->HasKey(keys::kKioskEnabled)) |
| 1879 return true; | 1794 return true; |
| 1880 | 1795 |
| 1881 if (!manifest_->GetBoolean(keys::kKioskEnabled, &kiosk_enabled_)) { | 1796 if (!manifest_->GetBoolean(keys::kKioskEnabled, &kiosk_enabled_)) { |
| 1882 *error = ASCIIToUTF16(errors::kInvalidKioskEnabled); | 1797 *error = ASCIIToUTF16(errors::kInvalidKioskEnabled); |
| 1883 return false; | 1798 return false; |
| 1884 } | 1799 } |
| 1885 | 1800 |
| 1886 // All other use cases should be already filtered out by manifest feature | 1801 // All other use cases should be already filtered out by manifest feature |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2078 | 1993 |
| 2079 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 1994 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
| 2080 const Extension* extension, | 1995 const Extension* extension, |
| 2081 const PermissionSet* permissions, | 1996 const PermissionSet* permissions, |
| 2082 Reason reason) | 1997 Reason reason) |
| 2083 : reason(reason), | 1998 : reason(reason), |
| 2084 extension(extension), | 1999 extension(extension), |
| 2085 permissions(permissions) {} | 2000 permissions(permissions) {} |
| 2086 | 2001 |
| 2087 } // namespace extensions | 2002 } // namespace extensions |
| OLD | NEW |