Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Side by Side Diff: extensions/browser/content_verifier.cc

Issue 647193005: Merge codereview.chromium.org/630243002 onto 2171 branch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/2171
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/browser/content_verifier.h" 5 #include "extensions/browser/content_verifier.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "base/strings/string_util.h"
11 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
12 #include "extensions/browser/content_hash_fetcher.h" 13 #include "extensions/browser/content_hash_fetcher.h"
13 #include "extensions/browser/content_hash_reader.h" 14 #include "extensions/browser/content_hash_reader.h"
14 #include "extensions/browser/content_verifier_delegate.h" 15 #include "extensions/browser/content_verifier_delegate.h"
15 #include "extensions/browser/content_verifier_io_data.h" 16 #include "extensions/browser/content_verifier_io_data.h"
16 #include "extensions/browser/extension_registry.h" 17 #include "extensions/browser/extension_registry.h"
17 #include "extensions/common/constants.h" 18 #include "extensions/common/constants.h"
18 #include "extensions/common/extension_l10n_util.h" 19 #include "extensions/common/extension_l10n_util.h"
19 20
20 namespace extensions { 21 namespace extensions {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 101
101 if (reason == ContentVerifyJob::MISSING_ALL_HASHES) { 102 if (reason == ContentVerifyJob::MISSING_ALL_HASHES) {
102 // If we failed because there were no hashes yet for this extension, just 103 // If we failed because there were no hashes yet for this extension, just
103 // request some. 104 // request some.
104 fetcher_->DoFetch(extension, true /* force */); 105 fetcher_->DoFetch(extension, true /* force */);
105 } else { 106 } else {
106 delegate_->VerifyFailed(extension_id, reason); 107 delegate_->VerifyFailed(extension_id, reason);
107 } 108 }
108 } 109 }
109 110
111 static base::FilePath MakeImagePathRelative(const base::FilePath& path) {
112 if (path.ReferencesParent())
113 return base::FilePath();
114
115 std::vector<base::FilePath::StringType> parts;
116 path.GetComponents(&parts);
117 if (parts.empty())
118 return base::FilePath();
119
120 // Remove the first component if it is '.' or '/' or '//'.
121 const base::FilePath::StringType separators(
122 base::FilePath::kSeparators, base::FilePath::kSeparatorsLength);
123 if (!parts[0].empty() &&
124 (parts[0] == base::FilePath::kCurrentDirectory ||
125 parts[0].find_first_not_of(separators) == std::string::npos))
126 parts.erase(parts.begin());
127
128 // Note that elsewhere we always normalize path separators to '/' so this
129 // should work for all platforms.
130 return base::FilePath(JoinString(parts, '/'));
131 }
132
110 void ContentVerifier::OnExtensionLoaded( 133 void ContentVerifier::OnExtensionLoaded(
111 content::BrowserContext* browser_context, 134 content::BrowserContext* browser_context,
112 const Extension* extension) { 135 const Extension* extension) {
113 if (shutdown_) 136 if (shutdown_)
114 return; 137 return;
115 138
116 ContentVerifierDelegate::Mode mode = delegate_->ShouldBeVerified(*extension); 139 ContentVerifierDelegate::Mode mode = delegate_->ShouldBeVerified(*extension);
117 if (mode != ContentVerifierDelegate::NONE) { 140 if (mode != ContentVerifierDelegate::NONE) {
141 // The browser image paths from the extension may not be relative (eg
142 // they might have leading '/' or './'), so we strip those to make
143 // comparing to actual relative paths work later on.
144 std::set<base::FilePath> original_image_paths =
145 delegate_->GetBrowserImagePaths(extension);
146
147 scoped_ptr<std::set<base::FilePath>> image_paths(
148 new std::set<base::FilePath>);
149 for (const auto& path : original_image_paths) {
150 image_paths->insert(MakeImagePathRelative(path));
151 }
152
118 scoped_ptr<ContentVerifierIOData::ExtensionData> data( 153 scoped_ptr<ContentVerifierIOData::ExtensionData> data(
119 new ContentVerifierIOData::ExtensionData( 154 new ContentVerifierIOData::ExtensionData(
120 delegate_->GetBrowserImagePaths(extension), 155 image_paths.Pass(),
121 extension->version() ? *extension->version() : base::Version())); 156 extension->version() ? *extension->version() : base::Version()));
122 content::BrowserThread::PostTask(content::BrowserThread::IO, 157 content::BrowserThread::PostTask(content::BrowserThread::IO,
123 FROM_HERE, 158 FROM_HERE,
124 base::Bind(&ContentVerifierIOData::AddData, 159 base::Bind(&ContentVerifierIOData::AddData,
125 io_data_, 160 io_data_,
126 extension->id(), 161 extension->id(),
127 base::Passed(&data))); 162 base::Passed(&data)));
128 fetcher_->ExtensionLoaded(extension); 163 fetcher_->ExtensionLoaded(extension);
129 } 164 }
130 } 165 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 bool ContentVerifier::ShouldVerifyAnyPaths( 224 bool ContentVerifier::ShouldVerifyAnyPaths(
190 const std::string& extension_id, 225 const std::string& extension_id,
191 const base::FilePath& extension_root, 226 const base::FilePath& extension_root,
192 const std::set<base::FilePath>& relative_paths) { 227 const std::set<base::FilePath>& relative_paths) {
193 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 228 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
194 const ContentVerifierIOData::ExtensionData* data = 229 const ContentVerifierIOData::ExtensionData* data =
195 io_data_->GetData(extension_id); 230 io_data_->GetData(extension_id);
196 if (!data) 231 if (!data)
197 return false; 232 return false;
198 233
199 const std::set<base::FilePath>& browser_images = data->browser_image_paths; 234 const std::set<base::FilePath>& browser_images = *(data->browser_image_paths);
200 235
201 base::FilePath locales_dir = extension_root.Append(kLocaleFolder); 236 base::FilePath locales_dir = extension_root.Append(kLocaleFolder);
202 scoped_ptr<std::set<std::string> > all_locales; 237 scoped_ptr<std::set<std::string> > all_locales;
203 238
204 for (std::set<base::FilePath>::const_iterator i = relative_paths.begin(); 239 for (std::set<base::FilePath>::const_iterator i = relative_paths.begin();
205 i != relative_paths.end(); 240 i != relative_paths.end();
206 ++i) { 241 ++i) {
207 const base::FilePath& relative_path = *i; 242 const base::FilePath& relative_path = *i;
208 243
209 if (relative_path == base::FilePath(kManifestFilename)) 244 if (relative_path == base::FilePath(kManifestFilename))
(...skipping 19 matching lines...) Expand all
229 !extension_l10n_util::ShouldSkipValidation( 264 !extension_l10n_util::ShouldSkipValidation(
230 locales_dir, full_path.DirName(), *all_locales)) 265 locales_dir, full_path.DirName(), *all_locales))
231 continue; 266 continue;
232 } 267 }
233 return true; 268 return true;
234 } 269 }
235 return false; 270 return false;
236 } 271 }
237 272
238 } // namespace extensions 273 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/test/data/extensions/content_verifier/dot_slash_paths/page2.js ('k') | extensions/browser/content_verifier_io_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698