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/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 DownloadItem* item, | 294 DownloadItem* item, |
295 const base::Closure& internal_complete_callback) { | 295 const base::Closure& internal_complete_callback) { |
296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
297 #if defined(FULL_SAFE_BROWSING) | 297 #if defined(FULL_SAFE_BROWSING) |
298 SafeBrowsingState* state = static_cast<SafeBrowsingState*>( | 298 SafeBrowsingState* state = static_cast<SafeBrowsingState*>( |
299 item->GetUserData(&kSafeBrowsingUserDataKey)); | 299 item->GetUserData(&kSafeBrowsingUserDataKey)); |
300 if (!state) { | 300 if (!state) { |
301 // Begin the safe browsing download protection check. | 301 // Begin the safe browsing download protection check. |
302 DownloadProtectionService* service = GetDownloadProtectionService(); | 302 DownloadProtectionService* service = GetDownloadProtectionService(); |
303 if (service) { | 303 if (service) { |
304 VLOG(2) << __FUNCTION__ << "() Start SB download check for download = " | 304 DVLOG(2) << __FUNCTION__ << "() Start SB download check for download = " |
305 << item->DebugString(false); | 305 << item->DebugString(false); |
306 state = new SafeBrowsingState(); | 306 state = new SafeBrowsingState(); |
307 state->set_callback(internal_complete_callback); | 307 state->set_callback(internal_complete_callback); |
308 item->SetUserData(&kSafeBrowsingUserDataKey, state); | 308 item->SetUserData(&kSafeBrowsingUserDataKey, state); |
309 service->CheckClientDownload( | 309 service->CheckClientDownload( |
310 item, | 310 item, |
311 base::Bind(&ChromeDownloadManagerDelegate::CheckClientDownloadDone, | 311 base::Bind(&ChromeDownloadManagerDelegate::CheckClientDownloadDone, |
312 weak_ptr_factory_.GetWeakPtr(), | 312 weak_ptr_factory_.GetWeakPtr(), |
313 item->GetId())); | 313 item->GetId())); |
314 return false; | 314 return false; |
315 } | 315 } |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 const base::FilePath& suggested_path, | 598 const base::FilePath& suggested_path, |
599 const CheckDownloadUrlCallback& callback) { | 599 const CheckDownloadUrlCallback& callback) { |
600 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 600 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
601 | 601 |
602 #if defined(FULL_SAFE_BROWSING) | 602 #if defined(FULL_SAFE_BROWSING) |
603 safe_browsing::DownloadProtectionService* service = | 603 safe_browsing::DownloadProtectionService* service = |
604 GetDownloadProtectionService(); | 604 GetDownloadProtectionService(); |
605 if (service) { | 605 if (service) { |
606 bool is_content_check_supported = | 606 bool is_content_check_supported = |
607 service->IsSupportedDownload(*download, suggested_path); | 607 service->IsSupportedDownload(*download, suggested_path); |
608 VLOG(2) << __FUNCTION__ << "() Start SB URL check for download = " | 608 DVLOG(2) << __FUNCTION__ << "() Start SB URL check for download = " |
609 << download->DebugString(false); | 609 << download->DebugString(false); |
610 service->CheckDownloadUrl(*download, | 610 service->CheckDownloadUrl(*download, |
611 base::Bind(&CheckDownloadUrlDone, | 611 base::Bind(&CheckDownloadUrlDone, |
612 callback, | 612 callback, |
613 is_content_check_supported)); | 613 is_content_check_supported)); |
614 return; | 614 return; |
615 } | 615 } |
616 #endif | 616 #endif |
617 callback.Run(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); | 617 callback.Run(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); |
618 } | 618 } |
619 | 619 |
620 void ChromeDownloadManagerDelegate::GetFileMimeType( | 620 void ChromeDownloadManagerDelegate::GetFileMimeType( |
621 const base::FilePath& path, | 621 const base::FilePath& path, |
622 const GetFileMimeTypeCallback& callback) { | 622 const GetFileMimeTypeCallback& callback) { |
623 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 623 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
624 base::PostTaskAndReplyWithResult(BrowserThread::GetBlockingPool(), | 624 base::PostTaskAndReplyWithResult(BrowserThread::GetBlockingPool(), |
625 FROM_HERE, | 625 FROM_HERE, |
626 base::Bind(&GetMimeType, path), | 626 base::Bind(&GetMimeType, path), |
627 callback); | 627 callback); |
628 } | 628 } |
629 | 629 |
630 #if defined(FULL_SAFE_BROWSING) | 630 #if defined(FULL_SAFE_BROWSING) |
631 void ChromeDownloadManagerDelegate::CheckClientDownloadDone( | 631 void ChromeDownloadManagerDelegate::CheckClientDownloadDone( |
632 uint32 download_id, | 632 uint32 download_id, |
633 DownloadProtectionService::DownloadCheckResult result) { | 633 DownloadProtectionService::DownloadCheckResult result) { |
634 DownloadItem* item = download_manager_->GetDownload(download_id); | 634 DownloadItem* item = download_manager_->GetDownload(download_id); |
635 if (!item || (item->GetState() != DownloadItem::IN_PROGRESS)) | 635 if (!item || (item->GetState() != DownloadItem::IN_PROGRESS)) |
636 return; | 636 return; |
637 | 637 |
638 VLOG(2) << __FUNCTION__ << "() download = " << item->DebugString(false) | 638 DVLOG(2) << __FUNCTION__ << "() download = " << item->DebugString(false) |
639 << " verdict = " << result; | 639 << " verdict = " << result; |
640 // We only mark the content as being dangerous if the download's safety state | 640 // We only mark the content as being dangerous if the download's safety state |
641 // has not been set to DANGEROUS yet. We don't want to show two warnings. | 641 // has not been set to DANGEROUS yet. We don't want to show two warnings. |
642 if (item->GetDangerType() == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS || | 642 if (item->GetDangerType() == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS || |
643 item->GetDangerType() == | 643 item->GetDangerType() == |
644 content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT) { | 644 content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT) { |
645 content::DownloadDangerType danger_type = | 645 content::DownloadDangerType danger_type = |
646 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS; | 646 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS; |
647 switch (result) { | 647 switch (result) { |
648 case DownloadProtectionService::UNKNOWN: | 648 case DownloadProtectionService::UNKNOWN: |
649 // The check failed or was inconclusive. | 649 // The check failed or was inconclusive. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 path.MatchesExtension(FILE_PATH_LITERAL(".xht")) || | 741 path.MatchesExtension(FILE_PATH_LITERAL(".xht")) || |
742 path.MatchesExtension(FILE_PATH_LITERAL(".xhtm")) || | 742 path.MatchesExtension(FILE_PATH_LITERAL(".xhtm")) || |
743 path.MatchesExtension(FILE_PATH_LITERAL(".xhtml")) || | 743 path.MatchesExtension(FILE_PATH_LITERAL(".xhtml")) || |
744 path.MatchesExtension(FILE_PATH_LITERAL(".xsl")) || | 744 path.MatchesExtension(FILE_PATH_LITERAL(".xsl")) || |
745 path.MatchesExtension(FILE_PATH_LITERAL(".xslt"))) { | 745 path.MatchesExtension(FILE_PATH_LITERAL(".xslt"))) { |
746 return true; | 746 return true; |
747 } | 747 } |
748 #endif | 748 #endif |
749 return false; | 749 return false; |
750 } | 750 } |
OLD | NEW |