Chromium Code Reviews| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 // Danger type is (in order of preference): | 152 // Danger type is (in order of preference): |
| 153 // * DANGEROUS_URL, if the URL is a known malware site. | 153 // * DANGEROUS_URL, if the URL is a known malware site. |
| 154 // * MAYBE_DANGEROUS_CONTENT, if the content will be scanned for | 154 // * MAYBE_DANGEROUS_CONTENT, if the content will be scanned for |
| 155 // malware. I.e. |is_content_check_supported| is true. | 155 // malware. I.e. |is_content_check_supported| is true. |
| 156 // * NOT_DANGEROUS. | 156 // * NOT_DANGEROUS. |
| 157 void CheckDownloadUrlDone( | 157 void CheckDownloadUrlDone( |
| 158 const DownloadTargetDeterminerDelegate::CheckDownloadUrlCallback& callback, | 158 const DownloadTargetDeterminerDelegate::CheckDownloadUrlCallback& callback, |
| 159 bool is_content_check_supported, | 159 bool is_content_check_supported, |
| 160 DownloadProtectionService::DownloadCheckResult result) { | 160 DownloadProtectionService::DownloadCheckResult result) { |
| 161 content::DownloadDangerType danger_type; | 161 content::DownloadDangerType danger_type; |
| 162 if (result == DownloadProtectionService::SAFE) { | 162 if (result == DownloadProtectionService::SAFE || |
| 163 result == DownloadProtectionService::UNKNOWN) { | |
| 163 // If this type of files is handled by the enhanced SafeBrowsing download | 164 // If this type of files is handled by the enhanced SafeBrowsing download |
| 164 // protection, mark it as potentially dangerous content until we are done | 165 // protection, mark it as potentially dangerous content until we are done |
| 165 // with scanning it. | 166 // with scanning it. |
| 166 if (is_content_check_supported) | 167 if (is_content_check_supported) |
| 167 danger_type = content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT; | 168 danger_type = content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT; |
| 168 else | 169 else |
| 169 danger_type = content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS; | 170 danger_type = content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS; |
| 170 } else { | 171 } else { |
| 171 // If the URL is malicious, we'll use that as the danger type. The results | 172 // If the URL is malicious, we'll use that as the danger type. The results |
| 172 // of the content check, if one is performed, will be ignored. | 173 // of the content check, if one is performed, will be ignored. |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 bool ChromeDownloadManagerDelegate::IsDownloadReadyForCompletion( | 301 bool ChromeDownloadManagerDelegate::IsDownloadReadyForCompletion( |
| 301 DownloadItem* item, | 302 DownloadItem* item, |
| 302 const base::Closure& internal_complete_callback) { | 303 const base::Closure& internal_complete_callback) { |
| 303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 304 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 304 #if defined(FULL_SAFE_BROWSING) | 305 #if defined(FULL_SAFE_BROWSING) |
| 305 SafeBrowsingState* state = static_cast<SafeBrowsingState*>( | 306 SafeBrowsingState* state = static_cast<SafeBrowsingState*>( |
| 306 item->GetUserData(&kSafeBrowsingUserDataKey)); | 307 item->GetUserData(&kSafeBrowsingUserDataKey)); |
| 307 if (!state) { | 308 if (!state) { |
| 308 // Begin the safe browsing download protection check. | 309 // Begin the safe browsing download protection check. |
| 309 DownloadProtectionService* service = GetDownloadProtectionService(); | 310 DownloadProtectionService* service = GetDownloadProtectionService(); |
| 310 if (service) { | 311 if (service) { |
|
mattm
2014/09/12 02:52:39
I think there may be a minor race here if the file
| |
| 311 VLOG(2) << __FUNCTION__ << "() Start SB download check for download = " | 312 VLOG(2) << __FUNCTION__ << "() Start SB download check for download = " |
| 312 << item->DebugString(false); | 313 << item->DebugString(false); |
| 313 state = new SafeBrowsingState(); | 314 state = new SafeBrowsingState(); |
| 314 state->set_callback(internal_complete_callback); | 315 state->set_callback(internal_complete_callback); |
| 315 item->SetUserData(&kSafeBrowsingUserDataKey, state); | 316 item->SetUserData(&kSafeBrowsingUserDataKey, state); |
| 316 service->CheckClientDownload( | 317 service->CheckClientDownload( |
| 317 item, | 318 item, |
| 318 base::Bind( | 319 base::Bind( |
| 319 &ChromeDownloadManagerDelegate::CheckClientDownloadDone, | 320 &ChromeDownloadManagerDelegate::CheckClientDownloadDone, |
| 320 weak_ptr_factory_.GetWeakPtr(), | 321 weak_ptr_factory_.GetWeakPtr(), |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 629 VLOG(2) << __FUNCTION__ << "() download = " << item->DebugString(false) | 630 VLOG(2) << __FUNCTION__ << "() download = " << item->DebugString(false) |
| 630 << " verdict = " << result; | 631 << " verdict = " << result; |
| 631 // We only mark the content as being dangerous if the download's safety state | 632 // We only mark the content as being dangerous if the download's safety state |
| 632 // has not been set to DANGEROUS yet. We don't want to show two warnings. | 633 // has not been set to DANGEROUS yet. We don't want to show two warnings. |
| 633 if (item->GetDangerType() == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS || | 634 if (item->GetDangerType() == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS || |
| 634 item->GetDangerType() == | 635 item->GetDangerType() == |
| 635 content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT) { | 636 content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT) { |
| 636 content::DownloadDangerType danger_type = | 637 content::DownloadDangerType danger_type = |
| 637 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS; | 638 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS; |
| 638 switch (result) { | 639 switch (result) { |
| 640 case DownloadProtectionService::UNKNOWN: | |
| 641 // The check failed or was inconclusive. | |
| 642 if (DownloadItemModel(item).IsDangerousFileBasedOnType()) | |
| 643 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE; | |
| 644 break; | |
| 639 case DownloadProtectionService::SAFE: | 645 case DownloadProtectionService::SAFE: |
| 640 // Do nothing. | 646 // Do nothing. |
| 641 break; | 647 break; |
| 642 case DownloadProtectionService::DANGEROUS: | 648 case DownloadProtectionService::DANGEROUS: |
| 643 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT; | 649 danger_type = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT; |
| 644 break; | 650 break; |
| 645 case DownloadProtectionService::UNCOMMON: | 651 case DownloadProtectionService::UNCOMMON: |
| 646 danger_type = content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT; | 652 danger_type = content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT; |
| 647 break; | 653 break; |
| 648 case DownloadProtectionService::DANGEROUS_HOST: | 654 case DownloadProtectionService::DANGEROUS_HOST: |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 681 callback.Run(installer->did_handle_successfully()); | 687 callback.Run(installer->did_handle_successfully()); |
| 682 #endif | 688 #endif |
| 683 } | 689 } |
| 684 | 690 |
| 685 void ChromeDownloadManagerDelegate::OnDownloadTargetDetermined( | 691 void ChromeDownloadManagerDelegate::OnDownloadTargetDetermined( |
| 686 int32 download_id, | 692 int32 download_id, |
| 687 const content::DownloadTargetCallback& callback, | 693 const content::DownloadTargetCallback& callback, |
| 688 scoped_ptr<DownloadTargetInfo> target_info) { | 694 scoped_ptr<DownloadTargetInfo> target_info) { |
| 689 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 695 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 690 DownloadItem* item = download_manager_->GetDownload(download_id); | 696 DownloadItem* item = download_manager_->GetDownload(download_id); |
| 691 if (!target_info->target_path.empty() && item && | 697 if (item) { |
| 692 IsOpenInBrowserPreferreredForFile(target_info->target_path) && | 698 if (!target_info->target_path.empty() && |
| 693 target_info->is_filetype_handled_safely) | 699 IsOpenInBrowserPreferreredForFile(target_info->target_path) && |
| 694 DownloadItemModel(item).SetShouldPreferOpeningInBrowser(true); | 700 target_info->is_filetype_handled_safely) |
| 701 DownloadItemModel(item).SetShouldPreferOpeningInBrowser(true); | |
| 702 | |
| 703 if (target_info->is_dangerous_file) | |
| 704 DownloadItemModel(item).SetIsDangerousFileBasedOnType(true); | |
| 705 } | |
| 695 callback.Run(target_info->target_path, | 706 callback.Run(target_info->target_path, |
| 696 target_info->target_disposition, | 707 target_info->target_disposition, |
| 697 target_info->danger_type, | 708 target_info->danger_type, |
| 698 target_info->intermediate_path); | 709 target_info->intermediate_path); |
| 699 } | 710 } |
| 700 | 711 |
| 701 bool ChromeDownloadManagerDelegate::IsOpenInBrowserPreferreredForFile( | 712 bool ChromeDownloadManagerDelegate::IsOpenInBrowserPreferreredForFile( |
| 702 const base::FilePath& path) { | 713 const base::FilePath& path) { |
| 703 // On Windows, PDFs should open in Acrobat Reader if the user chooses. | 714 // On Windows, PDFs should open in Acrobat Reader if the user chooses. |
| 704 #if defined(OS_WIN) | 715 #if defined(OS_WIN) |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 722 path.MatchesExtension(FILE_PATH_LITERAL(".xht")) || | 733 path.MatchesExtension(FILE_PATH_LITERAL(".xht")) || |
| 723 path.MatchesExtension(FILE_PATH_LITERAL(".xhtm")) || | 734 path.MatchesExtension(FILE_PATH_LITERAL(".xhtm")) || |
| 724 path.MatchesExtension(FILE_PATH_LITERAL(".xhtml")) || | 735 path.MatchesExtension(FILE_PATH_LITERAL(".xhtml")) || |
| 725 path.MatchesExtension(FILE_PATH_LITERAL(".xsl")) || | 736 path.MatchesExtension(FILE_PATH_LITERAL(".xsl")) || |
| 726 path.MatchesExtension(FILE_PATH_LITERAL(".xslt"))) { | 737 path.MatchesExtension(FILE_PATH_LITERAL(".xslt"))) { |
| 727 return true; | 738 return true; |
| 728 } | 739 } |
| 729 #endif | 740 #endif |
| 730 return false; | 741 return false; |
| 731 } | 742 } |
| OLD | NEW |