| 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 const size_t Extension::kIdSize = 16; | 213 const size_t Extension::kIdSize = 16; |
| 214 | 214 |
| 215 const char Extension::kMimeType[] = "application/x-chrome-extension"; | 215 const char Extension::kMimeType[] = "application/x-chrome-extension"; |
| 216 | 216 |
| 217 const int Extension::kValidWebExtentSchemes = | 217 const int Extension::kValidWebExtentSchemes = |
| 218 URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS; | 218 URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS; |
| 219 | 219 |
| 220 const int Extension::kValidHostPermissionSchemes = | 220 const int Extension::kValidHostPermissionSchemes = |
| 221 UserScript::kValidUserScriptSchemes | URLPattern::SCHEME_CHROMEUI; | 221 UserScript::kValidUserScriptSchemes | URLPattern::SCHEME_CHROMEUI; |
| 222 | 222 |
| 223 Extension::Requirements::Requirements() | |
| 224 : webgl(false), | |
| 225 css3d(false), | |
| 226 npapi(false) { | |
| 227 } | |
| 228 | |
| 229 Extension::Requirements::~Requirements() {} | |
| 230 | |
| 231 // | 223 // |
| 232 // Extension | 224 // Extension |
| 233 // | 225 // |
| 234 | 226 |
| 235 // static | 227 // static |
| 236 scoped_refptr<Extension> Extension::Create(const base::FilePath& path, | 228 scoped_refptr<Extension> Extension::Create(const base::FilePath& path, |
| 237 Manifest::Location location, | 229 Manifest::Location location, |
| 238 const DictionaryValue& value, | 230 const DictionaryValue& value, |
| 239 int flags, | 231 int flags, |
| 240 std::string* utf8_error) { | 232 std::string* utf8_error) { |
| (...skipping 1475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1716 } | 1708 } |
| 1717 | 1709 |
| 1718 return true; | 1710 return true; |
| 1719 } | 1711 } |
| 1720 | 1712 |
| 1721 bool Extension::LoadSharedFeatures(string16* error) { | 1713 bool Extension::LoadSharedFeatures(string16* error) { |
| 1722 if (!LoadDescription(error) || | 1714 if (!LoadDescription(error) || |
| 1723 !ManifestHandler::ParseExtension(this, error) || | 1715 !ManifestHandler::ParseExtension(this, error) || |
| 1724 !LoadNaClModules(error) || | 1716 !LoadNaClModules(error) || |
| 1725 !LoadSandboxedPages(error) || | 1717 !LoadSandboxedPages(error) || |
| 1726 !LoadRequirements(error) || | |
| 1727 !LoadOfflineEnabled(error)) | 1718 !LoadOfflineEnabled(error)) |
| 1728 return false; | 1719 return false; |
| 1729 | 1720 |
| 1730 return true; | 1721 return true; |
| 1731 } | 1722 } |
| 1732 | 1723 |
| 1733 bool Extension::LoadDescription(string16* error) { | 1724 bool Extension::LoadDescription(string16* error) { |
| 1734 if (manifest_->HasKey(keys::kDescription) && | 1725 if (manifest_->HasKey(keys::kDescription) && |
| 1735 !manifest_->GetString(keys::kDescription, &description_)) { | 1726 !manifest_->GetString(keys::kDescription, &description_)) { |
| 1736 *error = ASCIIToUTF16(errors::kInvalidDescription); | 1727 *error = ASCIIToUTF16(errors::kInvalidDescription); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1850 } else { | 1841 } else { |
| 1851 sandboxed_pages_content_security_policy_ = | 1842 sandboxed_pages_content_security_policy_ = |
| 1852 kDefaultSandboxedPageContentSecurityPolicy; | 1843 kDefaultSandboxedPageContentSecurityPolicy; |
| 1853 CHECK(ContentSecurityPolicyIsSandboxed( | 1844 CHECK(ContentSecurityPolicyIsSandboxed( |
| 1854 sandboxed_pages_content_security_policy_, GetType())); | 1845 sandboxed_pages_content_security_policy_, GetType())); |
| 1855 } | 1846 } |
| 1856 | 1847 |
| 1857 return true; | 1848 return true; |
| 1858 } | 1849 } |
| 1859 | 1850 |
| 1860 bool Extension::LoadRequirements(string16* error) { | |
| 1861 // Before parsing requirements from the manifest, automatically default the | |
| 1862 // NPAPI plugin requirement based on whether it includes NPAPI plugins. | |
| 1863 const ListValue* list_value = NULL; | |
| 1864 requirements_.npapi = | |
| 1865 manifest_->GetList(keys::kPlugins, &list_value) && !list_value->empty(); | |
| 1866 | |
| 1867 if (!manifest_->HasKey(keys::kRequirements)) | |
| 1868 return true; | |
| 1869 | |
| 1870 const DictionaryValue* requirements_value = NULL; | |
| 1871 if (!manifest_->GetDictionary(keys::kRequirements, &requirements_value)) { | |
| 1872 *error = ASCIIToUTF16(errors::kInvalidRequirements); | |
| 1873 return false; | |
| 1874 } | |
| 1875 | |
| 1876 for (DictionaryValue::Iterator it(*requirements_value); !it.IsAtEnd(); | |
| 1877 it.Advance()) { | |
| 1878 const DictionaryValue* requirement_value; | |
| 1879 if (!it.value().GetAsDictionary(&requirement_value)) { | |
| 1880 *error = ErrorUtils::FormatErrorMessageUTF16( | |
| 1881 errors::kInvalidRequirement, it.key()); | |
| 1882 return false; | |
| 1883 } | |
| 1884 | |
| 1885 if (it.key() == "plugins") { | |
| 1886 for (DictionaryValue::Iterator plugin_it(*requirement_value); | |
| 1887 !plugin_it.IsAtEnd(); plugin_it.Advance()) { | |
| 1888 bool plugin_required = false; | |
| 1889 if (!plugin_it.value().GetAsBoolean(&plugin_required)) { | |
| 1890 *error = ErrorUtils::FormatErrorMessageUTF16( | |
| 1891 errors::kInvalidRequirement, it.key()); | |
| 1892 return false; | |
| 1893 } | |
| 1894 if (plugin_it.key() == "npapi") { | |
| 1895 requirements_.npapi = plugin_required; | |
| 1896 } else { | |
| 1897 *error = ErrorUtils::FormatErrorMessageUTF16( | |
| 1898 errors::kInvalidRequirement, it.key()); | |
| 1899 return false; | |
| 1900 } | |
| 1901 } | |
| 1902 } else if (it.key() == "3D") { | |
| 1903 const ListValue* features = NULL; | |
| 1904 if (!requirement_value->GetListWithoutPathExpansion("features", | |
| 1905 &features) || | |
| 1906 !features) { | |
| 1907 *error = ErrorUtils::FormatErrorMessageUTF16( | |
| 1908 errors::kInvalidRequirement, it.key()); | |
| 1909 return false; | |
| 1910 } | |
| 1911 | |
| 1912 for (base::ListValue::const_iterator feature_it = features->begin(); | |
| 1913 feature_it != features->end(); | |
| 1914 ++feature_it) { | |
| 1915 std::string feature; | |
| 1916 if ((*feature_it)->GetAsString(&feature)) { | |
| 1917 if (feature == "webgl") { | |
| 1918 requirements_.webgl = true; | |
| 1919 } else if (feature == "css3d") { | |
| 1920 requirements_.css3d = true; | |
| 1921 } else { | |
| 1922 *error = ErrorUtils::FormatErrorMessageUTF16( | |
| 1923 errors::kInvalidRequirement, it.key()); | |
| 1924 return false; | |
| 1925 } | |
| 1926 } | |
| 1927 } | |
| 1928 } else { | |
| 1929 *error = ASCIIToUTF16(errors::kInvalidRequirements); | |
| 1930 return false; | |
| 1931 } | |
| 1932 } | |
| 1933 return true; | |
| 1934 } | |
| 1935 | |
| 1936 bool Extension::LoadOfflineEnabled(string16* error) { | 1851 bool Extension::LoadOfflineEnabled(string16* error) { |
| 1937 // Defaults to false, except for platform apps which are offline by default. | 1852 // Defaults to false, except for platform apps which are offline by default. |
| 1938 if (!manifest_->HasKey(keys::kOfflineEnabled)) { | 1853 if (!manifest_->HasKey(keys::kOfflineEnabled)) { |
| 1939 offline_enabled_ = is_platform_app(); | 1854 offline_enabled_ = is_platform_app(); |
| 1940 return true; | 1855 return true; |
| 1941 } | 1856 } |
| 1942 if (!manifest_->GetBoolean(keys::kOfflineEnabled, &offline_enabled_)) { | 1857 if (!manifest_->GetBoolean(keys::kOfflineEnabled, &offline_enabled_)) { |
| 1943 *error = ASCIIToUTF16(errors::kInvalidOfflineEnabled); | 1858 *error = ASCIIToUTF16(errors::kInvalidOfflineEnabled); |
| 1944 return false; | 1859 return false; |
| 1945 } | 1860 } |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2451 | 2366 |
| 2452 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 2367 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
| 2453 const Extension* extension, | 2368 const Extension* extension, |
| 2454 const PermissionSet* permissions, | 2369 const PermissionSet* permissions, |
| 2455 Reason reason) | 2370 Reason reason) |
| 2456 : reason(reason), | 2371 : reason(reason), |
| 2457 extension(extension), | 2372 extension(extension), |
| 2458 permissions(permissions) {} | 2373 permissions(permissions) {} |
| 2459 | 2374 |
| 2460 } // namespace extensions | 2375 } // namespace extensions |
| OLD | NEW |