| 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 "chrome/browser/download/chrome_download_manager_delegate.h" | 5 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 DownloadItem* item, | 316 DownloadItem* item, |
| 317 const base::Closure& internal_complete_callback) { | 317 const base::Closure& internal_complete_callback) { |
| 318 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 318 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 319 #if defined(FULL_SAFE_BROWSING) | 319 #if defined(FULL_SAFE_BROWSING) |
| 320 SafeBrowsingState* state = static_cast<SafeBrowsingState*>( | 320 SafeBrowsingState* state = static_cast<SafeBrowsingState*>( |
| 321 item->GetUserData(&kSafeBrowsingUserDataKey)); | 321 item->GetUserData(&kSafeBrowsingUserDataKey)); |
| 322 if (!state) { | 322 if (!state) { |
| 323 // Begin the safe browsing download protection check. | 323 // Begin the safe browsing download protection check. |
| 324 DownloadProtectionService* service = GetDownloadProtectionService(); | 324 DownloadProtectionService* service = GetDownloadProtectionService(); |
| 325 if (service) { | 325 if (service) { |
| 326 DVLOG(2) << __FUNCTION__ << "() Start SB download check for download = " | 326 DVLOG(2) << __func__ << "() Start SB download check for download = " |
| 327 << item->DebugString(false); | 327 << item->DebugString(false); |
| 328 state = new SafeBrowsingState(); | 328 state = new SafeBrowsingState(); |
| 329 state->set_callback(internal_complete_callback); | 329 state->set_callback(internal_complete_callback); |
| 330 item->SetUserData(&kSafeBrowsingUserDataKey, state); | 330 item->SetUserData(&kSafeBrowsingUserDataKey, state); |
| 331 service->CheckClientDownload( | 331 service->CheckClientDownload( |
| 332 item, | 332 item, |
| 333 base::Bind(&ChromeDownloadManagerDelegate::CheckClientDownloadDone, | 333 base::Bind(&ChromeDownloadManagerDelegate::CheckClientDownloadDone, |
| 334 weak_ptr_factory_.GetWeakPtr(), | 334 weak_ptr_factory_.GetWeakPtr(), |
| 335 item->GetId())); | 335 item->GetId())); |
| 336 return false; | 336 return false; |
| 337 } | 337 } |
| 338 | 338 |
| 339 // In case the service was disabled between the download starting and now, | 339 // In case the service was disabled between the download starting and now, |
| 340 // we need to restore the danger state. | 340 // we need to restore the danger state. |
| 341 content::DownloadDangerType danger_type = item->GetDangerType(); | 341 content::DownloadDangerType danger_type = item->GetDangerType(); |
| 342 if (DownloadItemModel(item).GetDangerLevel() != | 342 if (DownloadItemModel(item).GetDangerLevel() != |
| 343 DownloadFileType::NOT_DANGEROUS && | 343 DownloadFileType::NOT_DANGEROUS && |
| 344 (danger_type == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS || | 344 (danger_type == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS || |
| 345 danger_type == | 345 danger_type == |
| 346 content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT)) { | 346 content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT)) { |
| 347 DVLOG(2) << __FUNCTION__ | 347 DVLOG(2) << __func__ |
| 348 << "() SB service disabled. Marking download as DANGEROUS FILE"; | 348 << "() SB service disabled. Marking download as DANGEROUS FILE"; |
| 349 item->OnContentCheckCompleted( | 349 item->OnContentCheckCompleted( |
| 350 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); | 350 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); |
| 351 UMA_HISTOGRAM_ENUMERATION("Download.DangerousFile.Reason", | 351 UMA_HISTOGRAM_ENUMERATION("Download.DangerousFile.Reason", |
| 352 SB_NOT_AVAILABLE, DANGEROUS_FILE_REASON_MAX); | 352 SB_NOT_AVAILABLE, DANGEROUS_FILE_REASON_MAX); |
| 353 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 353 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| 354 internal_complete_callback); | 354 internal_complete_callback); |
| 355 return false; | 355 return false; |
| 356 } | 356 } |
| 357 } else if (!state->is_complete()) { | 357 } else if (!state->is_complete()) { |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 const base::FilePath& suggested_path, | 649 const base::FilePath& suggested_path, |
| 650 const CheckDownloadUrlCallback& callback) { | 650 const CheckDownloadUrlCallback& callback) { |
| 651 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 651 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 652 | 652 |
| 653 #if defined(FULL_SAFE_BROWSING) | 653 #if defined(FULL_SAFE_BROWSING) |
| 654 safe_browsing::DownloadProtectionService* service = | 654 safe_browsing::DownloadProtectionService* service = |
| 655 GetDownloadProtectionService(); | 655 GetDownloadProtectionService(); |
| 656 if (service) { | 656 if (service) { |
| 657 bool is_content_check_supported = | 657 bool is_content_check_supported = |
| 658 service->IsSupportedDownload(*download, suggested_path); | 658 service->IsSupportedDownload(*download, suggested_path); |
| 659 DVLOG(2) << __FUNCTION__ << "() Start SB URL check for download = " | 659 DVLOG(2) << __func__ << "() Start SB URL check for download = " |
| 660 << download->DebugString(false); | 660 << download->DebugString(false); |
| 661 service->CheckDownloadUrl(*download, | 661 service->CheckDownloadUrl(*download, |
| 662 base::Bind(&CheckDownloadUrlDone, | 662 base::Bind(&CheckDownloadUrlDone, |
| 663 callback, | 663 callback, |
| 664 is_content_check_supported)); | 664 is_content_check_supported)); |
| 665 return; | 665 return; |
| 666 } | 666 } |
| 667 #endif | 667 #endif |
| 668 callback.Run(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); | 668 callback.Run(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); |
| 669 } | 669 } |
| 670 | 670 |
| 671 void ChromeDownloadManagerDelegate::GetFileMimeType( | 671 void ChromeDownloadManagerDelegate::GetFileMimeType( |
| 672 const base::FilePath& path, | 672 const base::FilePath& path, |
| 673 const GetFileMimeTypeCallback& callback) { | 673 const GetFileMimeTypeCallback& callback) { |
| 674 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 674 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 675 base::PostTaskAndReplyWithResult(BrowserThread::GetBlockingPool(), | 675 base::PostTaskAndReplyWithResult(BrowserThread::GetBlockingPool(), |
| 676 FROM_HERE, | 676 FROM_HERE, |
| 677 base::Bind(&GetMimeType, path), | 677 base::Bind(&GetMimeType, path), |
| 678 callback); | 678 callback); |
| 679 } | 679 } |
| 680 | 680 |
| 681 #if defined(FULL_SAFE_BROWSING) | 681 #if defined(FULL_SAFE_BROWSING) |
| 682 void ChromeDownloadManagerDelegate::CheckClientDownloadDone( | 682 void ChromeDownloadManagerDelegate::CheckClientDownloadDone( |
| 683 uint32_t download_id, | 683 uint32_t download_id, |
| 684 DownloadProtectionService::DownloadCheckResult result) { | 684 DownloadProtectionService::DownloadCheckResult result) { |
| 685 DownloadItem* item = download_manager_->GetDownload(download_id); | 685 DownloadItem* item = download_manager_->GetDownload(download_id); |
| 686 if (!item || (item->GetState() != DownloadItem::IN_PROGRESS)) | 686 if (!item || (item->GetState() != DownloadItem::IN_PROGRESS)) |
| 687 return; | 687 return; |
| 688 | 688 |
| 689 DVLOG(2) << __FUNCTION__ << "() download = " << item->DebugString(false) | 689 DVLOG(2) << __func__ << "() download = " << item->DebugString(false) |
| 690 << " verdict = " << result; | 690 << " verdict = " << result; |
| 691 // We only mark the content as being dangerous if the download's safety state | 691 // We only mark the content as being dangerous if the download's safety state |
| 692 // has not been set to DANGEROUS yet. We don't want to show two warnings. | 692 // has not been set to DANGEROUS yet. We don't want to show two warnings. |
| 693 if (item->GetDangerType() == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS || | 693 if (item->GetDangerType() == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS || |
| 694 item->GetDangerType() == | 694 item->GetDangerType() == |
| 695 content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT) { | 695 content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT) { |
| 696 content::DownloadDangerType danger_type = | 696 content::DownloadDangerType danger_type = |
| 697 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS; | 697 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS; |
| 698 switch (result) { | 698 switch (result) { |
| 699 case DownloadProtectionService::UNKNOWN: | 699 case DownloadProtectionService::UNKNOWN: |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 path.MatchesExtension(FILE_PATH_LITERAL(".xht")) || | 809 path.MatchesExtension(FILE_PATH_LITERAL(".xht")) || |
| 810 path.MatchesExtension(FILE_PATH_LITERAL(".xhtm")) || | 810 path.MatchesExtension(FILE_PATH_LITERAL(".xhtm")) || |
| 811 path.MatchesExtension(FILE_PATH_LITERAL(".xhtml")) || | 811 path.MatchesExtension(FILE_PATH_LITERAL(".xhtml")) || |
| 812 path.MatchesExtension(FILE_PATH_LITERAL(".xsl")) || | 812 path.MatchesExtension(FILE_PATH_LITERAL(".xsl")) || |
| 813 path.MatchesExtension(FILE_PATH_LITERAL(".xslt"))) { | 813 path.MatchesExtension(FILE_PATH_LITERAL(".xslt"))) { |
| 814 return true; | 814 return true; |
| 815 } | 815 } |
| 816 #endif | 816 #endif |
| 817 return false; | 817 return false; |
| 818 } | 818 } |
| OLD | NEW |