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 <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 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 DCHECK(StartsWithASCII(ret_val.spec(), extension_url.spec(), false)); | 494 DCHECK(StartsWithASCII(ret_val.spec(), extension_url.spec(), false)); |
495 | 495 |
496 return ret_val; | 496 return ret_val; |
497 } | 497 } |
498 | 498 |
499 bool Extension::ResourceMatches(const URLPatternSet& pattern_set, | 499 bool Extension::ResourceMatches(const URLPatternSet& pattern_set, |
500 const std::string& resource) const { | 500 const std::string& resource) const { |
501 return pattern_set.MatchesURL(extension_url_.Resolve(resource)); | 501 return pattern_set.MatchesURL(extension_url_.Resolve(resource)); |
502 } | 502 } |
503 | 503 |
504 bool Extension::IsResourceWebAccessible(const std::string& relative_path) | |
505 const { | |
506 // For old manifest versions which do not specify web_accessible_resources | |
507 // we always allow resource loads. | |
508 if (manifest_version_ < 2 && !HasWebAccessibleResources()) | |
509 return true; | |
510 | |
511 return ResourceMatches(web_accessible_resources_, relative_path); | |
512 } | |
513 | |
514 bool Extension::IsSandboxedPage(const std::string& relative_path) const { | 504 bool Extension::IsSandboxedPage(const std::string& relative_path) const { |
515 return ResourceMatches(sandboxed_pages_, relative_path); | 505 return ResourceMatches(sandboxed_pages_, relative_path); |
516 } | 506 } |
517 | 507 |
518 std::string Extension::GetResourceContentSecurityPolicy( | 508 std::string Extension::GetResourceContentSecurityPolicy( |
519 const std::string& relative_path) const { | 509 const std::string& relative_path) const { |
520 return IsSandboxedPage(relative_path) ? | 510 return IsSandboxedPage(relative_path) ? |
521 sandboxed_pages_content_security_policy_ : content_security_policy(); | 511 sandboxed_pages_content_security_policy_ : content_security_policy(); |
522 } | 512 } |
523 | 513 |
524 bool Extension::HasWebAccessibleResources() const { | |
525 return web_accessible_resources_.size() > 0; | |
526 } | |
527 | |
528 ExtensionResource Extension::GetResource( | 514 ExtensionResource Extension::GetResource( |
529 const std::string& relative_path) const { | 515 const std::string& relative_path) const { |
530 std::string new_path = relative_path; | 516 std::string new_path = relative_path; |
531 // We have some legacy data where resources have leading slashes. | 517 // We have some legacy data where resources have leading slashes. |
532 // See: http://crbug.com/121164 | 518 // See: http://crbug.com/121164 |
533 if (!new_path.empty() && new_path.at(0) == '/') | 519 if (!new_path.empty() && new_path.at(0) == '/') |
534 new_path.erase(0, 1); | 520 new_path.erase(0, 1); |
535 #if defined(OS_POSIX) | 521 #if defined(OS_POSIX) |
536 FilePath relative_file_path(new_path); | 522 FilePath relative_file_path(new_path); |
537 #elif defined(OS_WIN) | 523 #elif defined(OS_WIN) |
(...skipping 1422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1960 } | 1946 } |
1961 | 1947 |
1962 bool Extension::LoadSharedFeatures( | 1948 bool Extension::LoadSharedFeatures( |
1963 const APIPermissionSet& api_permissions, | 1949 const APIPermissionSet& api_permissions, |
1964 string16* error) { | 1950 string16* error) { |
1965 if (!LoadDescription(error) || | 1951 if (!LoadDescription(error) || |
1966 !LoadIcons(error) || | 1952 !LoadIcons(error) || |
1967 !LoadCommands(error) || | 1953 !LoadCommands(error) || |
1968 !LoadPlugins(error) || | 1954 !LoadPlugins(error) || |
1969 !LoadNaClModules(error) || | 1955 !LoadNaClModules(error) || |
1970 !LoadWebAccessibleResources(error) || | |
1971 !LoadSandboxedPages(error) || | 1956 !LoadSandboxedPages(error) || |
1972 !LoadRequirements(error) || | 1957 !LoadRequirements(error) || |
1973 !LoadDefaultLocale(error) || | 1958 !LoadDefaultLocale(error) || |
1974 !LoadOfflineEnabled(error) || | 1959 !LoadOfflineEnabled(error) || |
1975 // LoadBackgroundScripts() must be called before LoadBackgroundPage(). | 1960 // LoadBackgroundScripts() must be called before LoadBackgroundPage(). |
1976 !LoadBackgroundScripts(error) || | 1961 !LoadBackgroundScripts(error) || |
1977 !LoadBackgroundPage(api_permissions, error) || | 1962 !LoadBackgroundPage(api_permissions, error) || |
1978 !LoadBackgroundPersistent(api_permissions, error) || | 1963 !LoadBackgroundPersistent(api_permissions, error) || |
1979 !LoadBackgroundAllowJSAccess(api_permissions, error) || | 1964 !LoadBackgroundAllowJSAccess(api_permissions, error) || |
1980 !LoadOAuth2Info(error)) | 1965 !LoadOAuth2Info(error)) |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2178 } | 2163 } |
2179 | 2164 |
2180 nacl_modules_.push_back(NaClModuleInfo()); | 2165 nacl_modules_.push_back(NaClModuleInfo()); |
2181 nacl_modules_.back().url = GetResourceURL(path_str); | 2166 nacl_modules_.back().url = GetResourceURL(path_str); |
2182 nacl_modules_.back().mime_type = mime_type; | 2167 nacl_modules_.back().mime_type = mime_type; |
2183 } | 2168 } |
2184 | 2169 |
2185 return true; | 2170 return true; |
2186 } | 2171 } |
2187 | 2172 |
2188 bool Extension::LoadWebAccessibleResources(string16* error) { | |
2189 if (!manifest_->HasKey(keys::kWebAccessibleResources)) | |
2190 return true; | |
2191 ListValue* list_value = NULL; | |
2192 if (!manifest_->GetList(keys::kWebAccessibleResources, &list_value)) { | |
2193 *error = ASCIIToUTF16(errors::kInvalidWebAccessibleResourcesList); | |
2194 return false; | |
2195 } | |
2196 for (size_t i = 0; i < list_value->GetSize(); ++i) { | |
2197 std::string relative_path; | |
2198 if (!list_value->GetString(i, &relative_path)) { | |
2199 *error = ErrorUtils::FormatErrorMessageUTF16( | |
2200 errors::kInvalidWebAccessibleResource, base::IntToString(i)); | |
2201 return false; | |
2202 } | |
2203 URLPattern pattern(URLPattern::SCHEME_EXTENSION); | |
2204 if (pattern.Parse(extension_url_.spec()) != URLPattern::PARSE_SUCCESS) { | |
2205 *error = ErrorUtils::FormatErrorMessageUTF16( | |
2206 errors::kInvalidURLPatternError, extension_url_.spec()); | |
2207 return false; | |
2208 } | |
2209 while (relative_path[0] == '/') | |
2210 relative_path = relative_path.substr(1, relative_path.length() - 1); | |
2211 pattern.SetPath(pattern.path() + relative_path); | |
2212 web_accessible_resources_.AddPattern(pattern); | |
2213 } | |
2214 | |
2215 return true; | |
2216 } | |
2217 | |
2218 bool Extension::LoadSandboxedPages(string16* error) { | 2173 bool Extension::LoadSandboxedPages(string16* error) { |
2219 if (!manifest_->HasPath(keys::kSandboxedPages)) | 2174 if (!manifest_->HasPath(keys::kSandboxedPages)) |
2220 return true; | 2175 return true; |
2221 | 2176 |
2222 ListValue* list_value = NULL; | 2177 ListValue* list_value = NULL; |
2223 if (!manifest_->GetList(keys::kSandboxedPages, &list_value)) { | 2178 if (!manifest_->GetList(keys::kSandboxedPages, &list_value)) { |
2224 *error = ASCIIToUTF16(errors::kInvalidSandboxedPagesList); | 2179 *error = ASCIIToUTF16(errors::kInvalidSandboxedPagesList); |
2225 return false; | 2180 return false; |
2226 } | 2181 } |
2227 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 2182 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
(...skipping 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3480 | 3435 |
3481 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 3436 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
3482 const Extension* extension, | 3437 const Extension* extension, |
3483 const PermissionSet* permissions, | 3438 const PermissionSet* permissions, |
3484 Reason reason) | 3439 Reason reason) |
3485 : reason(reason), | 3440 : reason(reason), |
3486 extension(extension), | 3441 extension(extension), |
3487 permissions(permissions) {} | 3442 permissions(permissions) {} |
3488 | 3443 |
3489 } // namespace extensions | 3444 } // namespace extensions |
OLD | NEW |