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

Unified Diff: content/browser/download/base_file.cc

Issue 2025103002: Use better fallback URLs when calling AVScanFile(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Some cleanup Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/browser/download/base_file_win_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/download/base_file.cc
diff --git a/content/browser/download/base_file.cc b/content/browser/download/base_file.cc
index 1983b1599bb84e8252380513a8eb2206c6c5548d..e51f0f87aa1a0364337c9fbd0e88bd827a2c621b 100644
--- a/content/browser/download/base_file.cc
+++ b/content/browser/download/base_file.cc
@@ -374,6 +374,40 @@ DownloadInterruptReason BaseFile::LogInterruptReason(
}
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)
+
+namespace {
+
+// Given a source and a referrer, determines the "safest" URL that can be used
+// to determine the authority of the download source. Returns an empty URL if no
+// HTTP/S URL can be determined for the <|source_url|, |referrer_url|> pair.
+GURL GetEffectiveAuthorityURL(const GURL& source_url,
+ const GURL& referrer_url) {
+ if (source_url.is_valid()) {
+ // http{,s} has an authority and are supported.
+ if (source_url.SchemeIsHTTPOrHTTPS())
+ return source_url;
+
+ // If the download source is file:// ideally we should copy the MOTW from
+ // the original file, but given that Chrome/Chromium places strict
+ // restrictions on which schemes can reference file:// URLs, this code is
+ // going to assume that at this point it's okay to treat this download as
+ // being from the local system.
+ if (source_url.SchemeIsFile())
+ return source_url;
+
+ // ftp:// has an authority.
+ if (source_url.SchemeIs(url::kFtpScheme))
+ return source_url;
+ }
+
+ if (referrer_url.is_valid() && referrer_url.SchemeIsHTTPOrHTTPS())
+ return referrer_url;
+
+ return GURL();
+}
+
+} // namespace
+
DownloadInterruptReason BaseFile::AnnotateWithSourceInformation(
const std::string& client_guid,
const GURL& source_url,
@@ -383,8 +417,9 @@ DownloadInterruptReason BaseFile::AnnotateWithSourceInformation(
DCHECK(!full_path_.empty());
net_log_.BeginEvent(net::NetLogEventType::DOWNLOAD_FILE_ANNOTATED);
- QuarantineFileResult result =
- QuarantineFile(full_path_, source_url, referrer_url, client_guid);
+ QuarantineFileResult result = QuarantineFile(
+ full_path_, GetEffectiveAuthorityURL(source_url, referrer_url),
+ referrer_url, client_guid);
net_log_.EndEvent(net::NetLogEventType::DOWNLOAD_FILE_ANNOTATED);
switch (result) {
case QuarantineFileResult::OK:
« no previous file with comments | « no previous file | content/browser/download/base_file_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698