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 <ostream> | 7 #include <ostream> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 DCHECK(StartsWithASCII(ret_val.spec(), extension_url.spec(), false)); | 512 DCHECK(StartsWithASCII(ret_val.spec(), extension_url.spec(), false)); |
513 | 513 |
514 return ret_val; | 514 return ret_val; |
515 } | 515 } |
516 | 516 |
517 bool Extension::ResourceMatches(const URLPatternSet& pattern_set, | 517 bool Extension::ResourceMatches(const URLPatternSet& pattern_set, |
518 const std::string& resource) const { | 518 const std::string& resource) const { |
519 return pattern_set.MatchesURL(extension_url_.Resolve(resource)); | 519 return pattern_set.MatchesURL(extension_url_.Resolve(resource)); |
520 } | 520 } |
521 | 521 |
522 bool Extension::IsResourceWebAccessible(const std::string& relative_path) | |
523 const { | |
524 // For old manifest versions which do not specify web_accessible_resources | |
525 // we always allow resource loads. | |
526 if (manifest_version_ < 2 && !HasWebAccessibleResources()) | |
527 return true; | |
528 | |
529 return ResourceMatches(web_accessible_resources_, relative_path); | |
530 } | |
531 | |
532 bool Extension::IsSandboxedPage(const std::string& relative_path) const { | 522 bool Extension::IsSandboxedPage(const std::string& relative_path) const { |
533 return ResourceMatches(sandboxed_pages_, relative_path); | 523 return ResourceMatches(sandboxed_pages_, relative_path); |
534 } | 524 } |
535 | 525 |
536 std::string Extension::GetResourceContentSecurityPolicy( | 526 std::string Extension::GetResourceContentSecurityPolicy( |
537 const std::string& relative_path) const { | 527 const std::string& relative_path) const { |
538 return IsSandboxedPage(relative_path) ? | 528 return IsSandboxedPage(relative_path) ? |
539 sandboxed_pages_content_security_policy_ : content_security_policy(); | 529 sandboxed_pages_content_security_policy_ : content_security_policy(); |
540 } | 530 } |
541 | 531 |
542 bool Extension::HasWebAccessibleResources() const { | |
543 return web_accessible_resources_.size() > 0; | |
544 } | |
545 | |
546 ExtensionResource Extension::GetResource( | 532 ExtensionResource Extension::GetResource( |
547 const std::string& relative_path) const { | 533 const std::string& relative_path) const { |
548 std::string new_path = relative_path; | 534 std::string new_path = relative_path; |
549 // We have some legacy data where resources have leading slashes. | 535 // We have some legacy data where resources have leading slashes. |
550 // See: http://crbug.com/121164 | 536 // See: http://crbug.com/121164 |
551 if (!new_path.empty() && new_path.at(0) == '/') | 537 if (!new_path.empty() && new_path.at(0) == '/') |
552 new_path.erase(0, 1); | 538 new_path.erase(0, 1); |
553 #if defined(OS_POSIX) | 539 #if defined(OS_POSIX) |
554 FilePath relative_file_path(new_path); | 540 FilePath relative_file_path(new_path); |
555 #elif defined(OS_WIN) | 541 #elif defined(OS_WIN) |
(...skipping 1368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1924 | 1910 |
1925 bool Extension::LoadSharedFeatures( | 1911 bool Extension::LoadSharedFeatures( |
1926 const APIPermissionSet& api_permissions, | 1912 const APIPermissionSet& api_permissions, |
1927 string16* error) { | 1913 string16* error) { |
1928 if (!LoadDescription(error) || | 1914 if (!LoadDescription(error) || |
1929 !LoadUpdateURL(error) || | 1915 !LoadUpdateURL(error) || |
1930 !LoadIcons(error) || | 1916 !LoadIcons(error) || |
1931 !LoadCommands(error) || | 1917 !LoadCommands(error) || |
1932 !LoadPlugins(error) || | 1918 !LoadPlugins(error) || |
1933 !LoadNaClModules(error) || | 1919 !LoadNaClModules(error) || |
1934 !LoadWebAccessibleResources(error) || | |
1935 !LoadSandboxedPages(error) || | 1920 !LoadSandboxedPages(error) || |
1936 !LoadRequirements(error) || | 1921 !LoadRequirements(error) || |
1937 !LoadDefaultLocale(error) || | 1922 !LoadDefaultLocale(error) || |
1938 !LoadOfflineEnabled(error) || | 1923 !LoadOfflineEnabled(error) || |
1939 !LoadOptionsPage(error) || | 1924 !LoadOptionsPage(error) || |
1940 // LoadBackgroundScripts() must be called before LoadBackgroundPage(). | 1925 // LoadBackgroundScripts() must be called before LoadBackgroundPage(). |
1941 !LoadBackgroundScripts(error) || | 1926 !LoadBackgroundScripts(error) || |
1942 !LoadBackgroundPage(api_permissions, error) || | 1927 !LoadBackgroundPage(api_permissions, error) || |
1943 !LoadBackgroundPersistent(api_permissions, error) || | 1928 !LoadBackgroundPersistent(api_permissions, error) || |
1944 !LoadBackgroundAllowJSAccess(api_permissions, error) || | 1929 !LoadBackgroundAllowJSAccess(api_permissions, error) || |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2163 } | 2148 } |
2164 | 2149 |
2165 nacl_modules_.push_back(NaClModuleInfo()); | 2150 nacl_modules_.push_back(NaClModuleInfo()); |
2166 nacl_modules_.back().url = GetResourceURL(path_str); | 2151 nacl_modules_.back().url = GetResourceURL(path_str); |
2167 nacl_modules_.back().mime_type = mime_type; | 2152 nacl_modules_.back().mime_type = mime_type; |
2168 } | 2153 } |
2169 | 2154 |
2170 return true; | 2155 return true; |
2171 } | 2156 } |
2172 | 2157 |
2173 bool Extension::LoadWebAccessibleResources(string16* error) { | |
2174 if (!manifest_->HasKey(keys::kWebAccessibleResources)) | |
2175 return true; | |
2176 ListValue* list_value = NULL; | |
2177 if (!manifest_->GetList(keys::kWebAccessibleResources, &list_value)) { | |
2178 *error = ASCIIToUTF16(errors::kInvalidWebAccessibleResourcesList); | |
2179 return false; | |
2180 } | |
2181 for (size_t i = 0; i < list_value->GetSize(); ++i) { | |
2182 std::string relative_path; | |
2183 if (!list_value->GetString(i, &relative_path)) { | |
2184 *error = ErrorUtils::FormatErrorMessageUTF16( | |
2185 errors::kInvalidWebAccessibleResource, base::IntToString(i)); | |
2186 return false; | |
2187 } | |
2188 URLPattern pattern(URLPattern::SCHEME_EXTENSION); | |
2189 if (pattern.Parse(extension_url_.spec()) != URLPattern::PARSE_SUCCESS) { | |
2190 *error = ErrorUtils::FormatErrorMessageUTF16( | |
2191 errors::kInvalidURLPatternError, extension_url_.spec()); | |
2192 return false; | |
2193 } | |
2194 while (relative_path[0] == '/') | |
2195 relative_path = relative_path.substr(1, relative_path.length() - 1); | |
2196 pattern.SetPath(pattern.path() + relative_path); | |
2197 web_accessible_resources_.AddPattern(pattern); | |
2198 } | |
2199 | |
2200 return true; | |
2201 } | |
2202 | |
2203 bool Extension::LoadSandboxedPages(string16* error) { | 2158 bool Extension::LoadSandboxedPages(string16* error) { |
2204 if (!manifest_->HasPath(keys::kSandboxedPages)) | 2159 if (!manifest_->HasPath(keys::kSandboxedPages)) |
2205 return true; | 2160 return true; |
2206 | 2161 |
2207 ListValue* list_value = NULL; | 2162 ListValue* list_value = NULL; |
2208 if (!manifest_->GetList(keys::kSandboxedPages, &list_value)) { | 2163 if (!manifest_->GetList(keys::kSandboxedPages, &list_value)) { |
2209 *error = ASCIIToUTF16(errors::kInvalidSandboxedPagesList); | 2164 *error = ASCIIToUTF16(errors::kInvalidSandboxedPagesList); |
2210 return false; | 2165 return false; |
2211 } | 2166 } |
2212 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 2167 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
(...skipping 1794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4007 | 3962 |
4008 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 3963 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
4009 const Extension* extension, | 3964 const Extension* extension, |
4010 const PermissionSet* permissions, | 3965 const PermissionSet* permissions, |
4011 Reason reason) | 3966 Reason reason) |
4012 : reason(reason), | 3967 : reason(reason), |
4013 extension(extension), | 3968 extension(extension), |
4014 permissions(permissions) {} | 3969 permissions(permissions) {} |
4015 | 3970 |
4016 } // namespace extensions | 3971 } // namespace extensions |
OLD | NEW |