Chromium Code Reviews| Index: extensions/browser/content_verifier.cc |
| diff --git a/extensions/browser/content_verifier.cc b/extensions/browser/content_verifier.cc |
| index eaafe8f403bb2175063aa12d9ab6fe82cbceca63..69a56847161bd40853183db84fc246131fefb6ee 100644 |
| --- a/extensions/browser/content_verifier.cc |
| +++ b/extensions/browser/content_verifier.cc |
| @@ -62,6 +62,28 @@ void ContentVerifier::Shutdown() { |
| fetcher_.reset(); |
| } |
| +static base::FilePath MakePathRelative(const base::FilePath& path) { |
|
Ken Rockot(use gerrit already)
2015/09/09 16:56:10
nit since you're moving this, might as well nix th
asargent_no_longer_on_chrome
2015/09/09 17:42:39
Done. Renamed to "NormalizeRelativePath" also.
|
| + if (path.ReferencesParent()) |
| + return base::FilePath(); |
| + |
| + std::vector<base::FilePath::StringType> parts; |
| + path.GetComponents(&parts); |
| + if (parts.empty()) |
| + return base::FilePath(); |
| + |
| + // Remove the first component if it is '.' or '/' or '//'. |
| + const base::FilePath::StringType separators( |
| + base::FilePath::kSeparators, base::FilePath::kSeparatorsLength); |
| + if (!parts[0].empty() && |
| + (parts[0] == base::FilePath::kCurrentDirectory || |
| + parts[0].find_first_not_of(separators) == std::string::npos)) |
| + parts.erase(parts.begin()); |
| + |
| + // Note that elsewhere we always normalize path separators to '/' so this |
| + // should work for all platforms. |
| + return base::FilePath(base::JoinString(parts, "/")); |
| +} |
| + |
| ContentVerifyJob* ContentVerifier::CreateJobFor( |
| const std::string& extension_id, |
| const base::FilePath& extension_root, |
| @@ -73,8 +95,10 @@ ContentVerifyJob* ContentVerifier::CreateJobFor( |
| if (!data) |
| return NULL; |
| + base::FilePath actual_relative_path = MakePathRelative(relative_path); |
| + |
| std::set<base::FilePath> paths; |
| - paths.insert(relative_path); |
| + paths.insert(actual_relative_path); |
| if (!ShouldVerifyAnyPaths(extension_id, extension_root, paths)) |
| return NULL; |
| @@ -82,7 +106,7 @@ ContentVerifyJob* ContentVerifier::CreateJobFor( |
| // a cache of ContentHashReader's that we hold onto past the end of each job. |
| return new ContentVerifyJob( |
| new ContentHashReader(extension_id, data->version, extension_root, |
| - relative_path, delegate_->GetPublicKey()), |
| + actual_relative_path, delegate_->GetPublicKey()), |
| base::Bind(&ContentVerifier::VerifyFailed, this, extension_id)); |
| } |
| @@ -116,29 +140,6 @@ void ContentVerifier::VerifyFailed(const std::string& extension_id, |
| } |
| } |
| -static base::FilePath MakeImagePathRelative(const base::FilePath& path) { |
| - if (path.ReferencesParent()) |
| - return base::FilePath(); |
| - |
| - std::vector<base::FilePath::StringType> parts; |
| - path.GetComponents(&parts); |
| - if (parts.empty()) |
| - return base::FilePath(); |
| - |
| - // Remove the first component if it is '.' or '/' or '//'. |
| - const base::FilePath::StringType separators( |
| - base::FilePath::kSeparators, base::FilePath::kSeparatorsLength); |
| - if (!parts[0].empty() && |
| - (parts[0] == base::FilePath::kCurrentDirectory || |
| - parts[0].find_first_not_of(separators) == std::string::npos)) |
| - parts.erase(parts.begin()); |
| - |
| - // Note that elsewhere we always normalize path separators to '/' so this |
| - // should work for all platforms. |
| - return base::FilePath( |
| - base::JoinString(parts, base::FilePath::StringType(1, '/'))); |
| -} |
| - |
| void ContentVerifier::OnExtensionLoaded( |
| content::BrowserContext* browser_context, |
| const Extension* extension) { |
| @@ -156,7 +157,7 @@ void ContentVerifier::OnExtensionLoaded( |
| scoped_ptr<std::set<base::FilePath>> image_paths( |
| new std::set<base::FilePath>); |
| for (const auto& path : original_image_paths) { |
| - image_paths->insert(MakeImagePathRelative(path)); |
| + image_paths->insert(MakePathRelative(path)); |
| } |
| scoped_ptr<ContentVerifierIOData::ExtensionData> data( |