| 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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 DownloadItem* item, | 305 DownloadItem* item, |
| 306 const base::Closure& internal_complete_callback) { | 306 const base::Closure& internal_complete_callback) { |
| 307 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 307 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 308 #if defined(FULL_SAFE_BROWSING) | 308 #if defined(FULL_SAFE_BROWSING) |
| 309 SafeBrowsingState* state = static_cast<SafeBrowsingState*>( | 309 SafeBrowsingState* state = static_cast<SafeBrowsingState*>( |
| 310 item->GetUserData(&kSafeBrowsingUserDataKey)); | 310 item->GetUserData(&kSafeBrowsingUserDataKey)); |
| 311 if (!state) { | 311 if (!state) { |
| 312 // Begin the safe browsing download protection check. | 312 // Begin the safe browsing download protection check. |
| 313 DownloadProtectionService* service = GetDownloadProtectionService(); | 313 DownloadProtectionService* service = GetDownloadProtectionService(); |
| 314 if (service) { | 314 if (service) { |
| 315 DVLOG(2) << __FUNCTION__ << "() Start SB download check for download = " | 315 DVLOG(2) << __func__ << "() Start SB download check for download = " |
| 316 << item->DebugString(false); | 316 << item->DebugString(false); |
| 317 state = new SafeBrowsingState(); | 317 state = new SafeBrowsingState(); |
| 318 state->set_callback(internal_complete_callback); | 318 state->set_callback(internal_complete_callback); |
| 319 item->SetUserData(&kSafeBrowsingUserDataKey, state); | 319 item->SetUserData(&kSafeBrowsingUserDataKey, state); |
| 320 service->CheckClientDownload( | 320 service->CheckClientDownload( |
| 321 item, | 321 item, |
| 322 base::Bind(&ChromeDownloadManagerDelegate::CheckClientDownloadDone, | 322 base::Bind(&ChromeDownloadManagerDelegate::CheckClientDownloadDone, |
| 323 weak_ptr_factory_.GetWeakPtr(), | 323 weak_ptr_factory_.GetWeakPtr(), |
| 324 item->GetId())); | 324 item->GetId())); |
| 325 return false; | 325 return false; |
| 326 } | 326 } |
| 327 | 327 |
| 328 // In case the service was disabled between the download starting and now, | 328 // In case the service was disabled between the download starting and now, |
| 329 // we need to restore the danger state. | 329 // we need to restore the danger state. |
| 330 content::DownloadDangerType danger_type = item->GetDangerType(); | 330 content::DownloadDangerType danger_type = item->GetDangerType(); |
| 331 if (DownloadItemModel(item).GetDangerLevel() != | 331 if (DownloadItemModel(item).GetDangerLevel() != |
| 332 DownloadFileType::NOT_DANGEROUS && | 332 DownloadFileType::NOT_DANGEROUS && |
| 333 (danger_type == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS || | 333 (danger_type == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS || |
| 334 danger_type == | 334 danger_type == |
| 335 content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT)) { | 335 content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT)) { |
| 336 DVLOG(2) << __FUNCTION__ | 336 DVLOG(2) << __func__ |
| 337 << "() SB service disabled. Marking download as DANGEROUS FILE"; | 337 << "() SB service disabled. Marking download as DANGEROUS FILE"; |
| 338 item->OnContentCheckCompleted( | 338 item->OnContentCheckCompleted( |
| 339 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); | 339 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); |
| 340 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 340 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| 341 internal_complete_callback); | 341 internal_complete_callback); |
| 342 return false; | 342 return false; |
| 343 } | 343 } |
| 344 } else if (!state->is_complete()) { | 344 } else if (!state->is_complete()) { |
| 345 // Don't complete the download until we have an answer. | 345 // Don't complete the download until we have an answer. |
| 346 state->set_callback(internal_complete_callback); | 346 state->set_callback(internal_complete_callback); |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 const base::FilePath& suggested_path, | 636 const base::FilePath& suggested_path, |
| 637 const CheckDownloadUrlCallback& callback) { | 637 const CheckDownloadUrlCallback& callback) { |
| 638 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 638 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 639 | 639 |
| 640 #if defined(FULL_SAFE_BROWSING) | 640 #if defined(FULL_SAFE_BROWSING) |
| 641 safe_browsing::DownloadProtectionService* service = | 641 safe_browsing::DownloadProtectionService* service = |
| 642 GetDownloadProtectionService(); | 642 GetDownloadProtectionService(); |
| 643 if (service) { | 643 if (service) { |
| 644 bool is_content_check_supported = | 644 bool is_content_check_supported = |
| 645 service->IsSupportedDownload(*download, suggested_path); | 645 service->IsSupportedDownload(*download, suggested_path); |
| 646 DVLOG(2) << __FUNCTION__ << "() Start SB URL check for download = " | 646 DVLOG(2) << __func__ << "() Start SB URL check for download = " |
| 647 << download->DebugString(false); | 647 << download->DebugString(false); |
| 648 service->CheckDownloadUrl(*download, | 648 service->CheckDownloadUrl(*download, |
| 649 base::Bind(&CheckDownloadUrlDone, | 649 base::Bind(&CheckDownloadUrlDone, |
| 650 callback, | 650 callback, |
| 651 is_content_check_supported)); | 651 is_content_check_supported)); |
| 652 return; | 652 return; |
| 653 } | 653 } |
| 654 #endif | 654 #endif |
| 655 callback.Run(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); | 655 callback.Run(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); |
| 656 } | 656 } |
| 657 | 657 |
| 658 void ChromeDownloadManagerDelegate::GetFileMimeType( | 658 void ChromeDownloadManagerDelegate::GetFileMimeType( |
| 659 const base::FilePath& path, | 659 const base::FilePath& path, |
| 660 const GetFileMimeTypeCallback& callback) { | 660 const GetFileMimeTypeCallback& callback) { |
| 661 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 661 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 662 base::PostTaskAndReplyWithResult(BrowserThread::GetBlockingPool(), | 662 base::PostTaskAndReplyWithResult(BrowserThread::GetBlockingPool(), |
| 663 FROM_HERE, | 663 FROM_HERE, |
| 664 base::Bind(&GetMimeType, path), | 664 base::Bind(&GetMimeType, path), |
| 665 callback); | 665 callback); |
| 666 } | 666 } |
| 667 | 667 |
| 668 #if defined(FULL_SAFE_BROWSING) | 668 #if defined(FULL_SAFE_BROWSING) |
| 669 void ChromeDownloadManagerDelegate::CheckClientDownloadDone( | 669 void ChromeDownloadManagerDelegate::CheckClientDownloadDone( |
| 670 uint32_t download_id, | 670 uint32_t download_id, |
| 671 DownloadProtectionService::DownloadCheckResult result) { | 671 DownloadProtectionService::DownloadCheckResult result) { |
| 672 DownloadItem* item = download_manager_->GetDownload(download_id); | 672 DownloadItem* item = download_manager_->GetDownload(download_id); |
| 673 if (!item || (item->GetState() != DownloadItem::IN_PROGRESS)) | 673 if (!item || (item->GetState() != DownloadItem::IN_PROGRESS)) |
| 674 return; | 674 return; |
| 675 | 675 |
| 676 DVLOG(2) << __FUNCTION__ << "() download = " << item->DebugString(false) | 676 DVLOG(2) << __func__ << "() download = " << item->DebugString(false) |
| 677 << " verdict = " << result; | 677 << " verdict = " << result; |
| 678 // We only mark the content as being dangerous if the download's safety state | 678 // We only mark the content as being dangerous if the download's safety state |
| 679 // has not been set to DANGEROUS yet. We don't want to show two warnings. | 679 // has not been set to DANGEROUS yet. We don't want to show two warnings. |
| 680 if (item->GetDangerType() == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS || | 680 if (item->GetDangerType() == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS || |
| 681 item->GetDangerType() == | 681 item->GetDangerType() == |
| 682 content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT) { | 682 content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT) { |
| 683 content::DownloadDangerType danger_type = | 683 content::DownloadDangerType danger_type = |
| 684 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS; | 684 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS; |
| 685 switch (result) { | 685 switch (result) { |
| 686 case DownloadProtectionService::UNKNOWN: | 686 case DownloadProtectionService::UNKNOWN: |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 path.MatchesExtension(FILE_PATH_LITERAL(".xht")) || | 789 path.MatchesExtension(FILE_PATH_LITERAL(".xht")) || |
| 790 path.MatchesExtension(FILE_PATH_LITERAL(".xhtm")) || | 790 path.MatchesExtension(FILE_PATH_LITERAL(".xhtm")) || |
| 791 path.MatchesExtension(FILE_PATH_LITERAL(".xhtml")) || | 791 path.MatchesExtension(FILE_PATH_LITERAL(".xhtml")) || |
| 792 path.MatchesExtension(FILE_PATH_LITERAL(".xsl")) || | 792 path.MatchesExtension(FILE_PATH_LITERAL(".xsl")) || |
| 793 path.MatchesExtension(FILE_PATH_LITERAL(".xslt"))) { | 793 path.MatchesExtension(FILE_PATH_LITERAL(".xslt"))) { |
| 794 return true; | 794 return true; |
| 795 } | 795 } |
| 796 #endif | 796 #endif |
| 797 return false; | 797 return false; |
| 798 } | 798 } |
| OLD | NEW |