OLD | NEW |
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 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 DVLOG(1) << __FUNCTION__ << "() operation:" << operation | 363 DVLOG(1) << __FUNCTION__ << "() operation:" << operation |
364 << " os_error:" << os_error | 364 << " os_error:" << os_error |
365 << " reason:" << DownloadInterruptReasonToString(reason); | 365 << " reason:" << DownloadInterruptReasonToString(reason); |
366 bound_net_log_.AddEvent( | 366 bound_net_log_.AddEvent( |
367 net::NetLog::TYPE_DOWNLOAD_FILE_ERROR, | 367 net::NetLog::TYPE_DOWNLOAD_FILE_ERROR, |
368 base::Bind(&FileInterruptedNetLogCallback, operation, os_error, reason)); | 368 base::Bind(&FileInterruptedNetLogCallback, operation, os_error, reason)); |
369 return reason; | 369 return reason; |
370 } | 370 } |
371 | 371 |
372 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) | 372 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) |
| 373 |
| 374 namespace { |
| 375 |
| 376 // Given a source and a referrer, determines the "safest" URL that can be used |
| 377 // to determine the authority of the download source. Returns an empty URL if no |
| 378 // HTTP/S URL can be determined for the <|source_url|, |referrer_url|> pair. |
| 379 GURL GetEffectiveAuthorityURL(const GURL& source_url, |
| 380 const GURL& referrer_url) { |
| 381 if (source_url.is_valid()) { |
| 382 // http{,s} has an authority and are supported. |
| 383 if (source_url.SchemeIsHTTPOrHTTPS()) |
| 384 return source_url; |
| 385 |
| 386 // If the download source is file:// ideally we should copy the MOTW from |
| 387 // the original file, but given that Chrome/Chromium places strict |
| 388 // restrictions on which schemes can reference file:// URLs, this code is |
| 389 // going to assume that at this point it's okay to treat this download as |
| 390 // being from the local system. |
| 391 if (source_url.SchemeIsFile()) |
| 392 return source_url; |
| 393 |
| 394 // ftp:// has an authority. |
| 395 if (source_url.SchemeIs(url::kFtpScheme)) |
| 396 return source_url; |
| 397 } |
| 398 |
| 399 if (referrer_url.is_valid() && referrer_url.SchemeIsHTTPOrHTTPS()) |
| 400 return referrer_url; |
| 401 |
| 402 return GURL(); |
| 403 } |
| 404 |
| 405 } // namespace |
| 406 |
373 DownloadInterruptReason BaseFile::AnnotateWithSourceInformation( | 407 DownloadInterruptReason BaseFile::AnnotateWithSourceInformation( |
374 const std::string& client_guid, | 408 const std::string& client_guid, |
375 const GURL& source_url, | 409 const GURL& source_url, |
376 const GURL& referrer_url) { | 410 const GURL& referrer_url) { |
377 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 411 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
378 DCHECK(!detached_); | 412 DCHECK(!detached_); |
379 DCHECK(!full_path_.empty()); | 413 DCHECK(!full_path_.empty()); |
380 | 414 |
381 bound_net_log_.BeginEvent(net::NetLog::TYPE_DOWNLOAD_FILE_ANNOTATED); | 415 bound_net_log_.BeginEvent(net::NetLog::TYPE_DOWNLOAD_FILE_ANNOTATED); |
382 QuarantineFileResult result = | 416 QuarantineFileResult result = QuarantineFile( |
383 QuarantineFile(full_path_, source_url, referrer_url, client_guid); | 417 full_path_, GetEffectiveAuthorityURL(source_url, referrer_url), |
| 418 referrer_url, client_guid); |
384 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_FILE_ANNOTATED); | 419 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_FILE_ANNOTATED); |
385 switch (result) { | 420 switch (result) { |
386 case QuarantineFileResult::OK: | 421 case QuarantineFileResult::OK: |
387 return DOWNLOAD_INTERRUPT_REASON_NONE; | 422 return DOWNLOAD_INTERRUPT_REASON_NONE; |
388 case QuarantineFileResult::VIRUS_INFECTED: | 423 case QuarantineFileResult::VIRUS_INFECTED: |
389 return DOWNLOAD_INTERRUPT_REASON_FILE_VIRUS_INFECTED; | 424 return DOWNLOAD_INTERRUPT_REASON_FILE_VIRUS_INFECTED; |
390 case QuarantineFileResult::SECURITY_CHECK_FAILED: | 425 case QuarantineFileResult::SECURITY_CHECK_FAILED: |
391 return DOWNLOAD_INTERRUPT_REASON_FILE_SECURITY_CHECK_FAILED; | 426 return DOWNLOAD_INTERRUPT_REASON_FILE_SECURITY_CHECK_FAILED; |
392 case QuarantineFileResult::BLOCKED_BY_POLICY: | 427 case QuarantineFileResult::BLOCKED_BY_POLICY: |
393 return DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED; | 428 return DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED; |
(...skipping 26 matching lines...) Expand all Loading... |
420 #else // !OS_WIN && !OS_MACOSX && !OS_LINUX | 455 #else // !OS_WIN && !OS_MACOSX && !OS_LINUX |
421 DownloadInterruptReason BaseFile::AnnotateWithSourceInformation( | 456 DownloadInterruptReason BaseFile::AnnotateWithSourceInformation( |
422 const std::string& client_guid, | 457 const std::string& client_guid, |
423 const GURL& source_url, | 458 const GURL& source_url, |
424 const GURL& referrer_url) { | 459 const GURL& referrer_url) { |
425 return DOWNLOAD_INTERRUPT_REASON_NONE; | 460 return DOWNLOAD_INTERRUPT_REASON_NONE; |
426 } | 461 } |
427 #endif | 462 #endif |
428 | 463 |
429 } // namespace content | 464 } // namespace content |
OLD | NEW |