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

Side by Side 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, 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
« no previous file with comments | « no previous file | content/browser/download/base_file_win_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "content/browser/download/base_file.h" 5 #include "content/browser/download/base_file.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file.h" 10 #include "base/files/file.h"
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 DVLOG(1) << __func__ << "() operation:" << operation 367 DVLOG(1) << __func__ << "() operation:" << operation
368 << " os_error:" << os_error 368 << " os_error:" << os_error
369 << " reason:" << DownloadInterruptReasonToString(reason); 369 << " reason:" << DownloadInterruptReasonToString(reason);
370 net_log_.AddEvent( 370 net_log_.AddEvent(
371 net::NetLogEventType::DOWNLOAD_FILE_ERROR, 371 net::NetLogEventType::DOWNLOAD_FILE_ERROR,
372 base::Bind(&FileInterruptedNetLogCallback, operation, os_error, reason)); 372 base::Bind(&FileInterruptedNetLogCallback, operation, os_error, reason));
373 return reason; 373 return reason;
374 } 374 }
375 375
376 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) 376 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)
377
378 namespace {
379
380 // Given a source and a referrer, determines the "safest" URL that can be used
381 // to determine the authority of the download source. Returns an empty URL if no
382 // HTTP/S URL can be determined for the <|source_url|, |referrer_url|> pair.
383 GURL GetEffectiveAuthorityURL(const GURL& source_url,
384 const GURL& referrer_url) {
385 if (source_url.is_valid()) {
386 // http{,s} has an authority and are supported.
387 if (source_url.SchemeIsHTTPOrHTTPS())
388 return source_url;
389
390 // If the download source is file:// ideally we should copy the MOTW from
391 // the original file, but given that Chrome/Chromium places strict
392 // restrictions on which schemes can reference file:// URLs, this code is
393 // going to assume that at this point it's okay to treat this download as
394 // being from the local system.
395 if (source_url.SchemeIsFile())
396 return source_url;
397
398 // ftp:// has an authority.
399 if (source_url.SchemeIs(url::kFtpScheme))
400 return source_url;
401 }
402
403 if (referrer_url.is_valid() && referrer_url.SchemeIsHTTPOrHTTPS())
404 return referrer_url;
405
406 return GURL();
407 }
408
409 } // namespace
410
377 DownloadInterruptReason BaseFile::AnnotateWithSourceInformation( 411 DownloadInterruptReason BaseFile::AnnotateWithSourceInformation(
378 const std::string& client_guid, 412 const std::string& client_guid,
379 const GURL& source_url, 413 const GURL& source_url,
380 const GURL& referrer_url) { 414 const GURL& referrer_url) {
381 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 415 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
382 DCHECK(!detached_); 416 DCHECK(!detached_);
383 DCHECK(!full_path_.empty()); 417 DCHECK(!full_path_.empty());
384 418
385 net_log_.BeginEvent(net::NetLogEventType::DOWNLOAD_FILE_ANNOTATED); 419 net_log_.BeginEvent(net::NetLogEventType::DOWNLOAD_FILE_ANNOTATED);
386 QuarantineFileResult result = 420 QuarantineFileResult result = QuarantineFile(
387 QuarantineFile(full_path_, source_url, referrer_url, client_guid); 421 full_path_, GetEffectiveAuthorityURL(source_url, referrer_url),
422 referrer_url, client_guid);
388 net_log_.EndEvent(net::NetLogEventType::DOWNLOAD_FILE_ANNOTATED); 423 net_log_.EndEvent(net::NetLogEventType::DOWNLOAD_FILE_ANNOTATED);
389 switch (result) { 424 switch (result) {
390 case QuarantineFileResult::OK: 425 case QuarantineFileResult::OK:
391 return DOWNLOAD_INTERRUPT_REASON_NONE; 426 return DOWNLOAD_INTERRUPT_REASON_NONE;
392 case QuarantineFileResult::VIRUS_INFECTED: 427 case QuarantineFileResult::VIRUS_INFECTED:
393 return DOWNLOAD_INTERRUPT_REASON_FILE_VIRUS_INFECTED; 428 return DOWNLOAD_INTERRUPT_REASON_FILE_VIRUS_INFECTED;
394 case QuarantineFileResult::SECURITY_CHECK_FAILED: 429 case QuarantineFileResult::SECURITY_CHECK_FAILED:
395 return DOWNLOAD_INTERRUPT_REASON_FILE_SECURITY_CHECK_FAILED; 430 return DOWNLOAD_INTERRUPT_REASON_FILE_SECURITY_CHECK_FAILED;
396 case QuarantineFileResult::BLOCKED_BY_POLICY: 431 case QuarantineFileResult::BLOCKED_BY_POLICY:
397 return DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED; 432 return DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED;
(...skipping 26 matching lines...) Expand all
424 #else // !OS_WIN && !OS_MACOSX && !OS_LINUX 459 #else // !OS_WIN && !OS_MACOSX && !OS_LINUX
425 DownloadInterruptReason BaseFile::AnnotateWithSourceInformation( 460 DownloadInterruptReason BaseFile::AnnotateWithSourceInformation(
426 const std::string& client_guid, 461 const std::string& client_guid,
427 const GURL& source_url, 462 const GURL& source_url,
428 const GURL& referrer_url) { 463 const GURL& referrer_url) {
429 return DOWNLOAD_INTERRUPT_REASON_NONE; 464 return DOWNLOAD_INTERRUPT_REASON_NONE;
430 } 465 }
431 #endif 466 #endif
432 467
433 } // namespace content 468 } // namespace content
OLDNEW
« 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