OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/download_item.h" | 5 #include "content/browser/download/download_item.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 return "REMOVING"; | 85 return "REMOVING"; |
86 case DownloadItem::INTERRUPTED: | 86 case DownloadItem::INTERRUPTED: |
87 return "INTERRUPTED"; | 87 return "INTERRUPTED"; |
88 default: | 88 default: |
89 NOTREACHED() << "Unknown download state " << state; | 89 NOTREACHED() << "Unknown download state " << state; |
90 return "unknown"; | 90 return "unknown"; |
91 }; | 91 }; |
92 } | 92 } |
93 | 93 |
94 DownloadItem::SafetyState GetSafetyState(bool dangerous_file, | 94 DownloadItem::SafetyState GetSafetyState(bool dangerous_file, |
95 bool dangerous_url) { | 95 bool dangerous_url, |
| 96 bool dangerous_content) { |
| 97 // TODO(noelutz): At this point we can't mark the download as dangerous |
| 98 // if it's content is dangerous because the UI doesn't yet support it. |
| 99 // Once the UI has been changed we should return DANGEROUS when |
| 100 // |dangerous_content| is true. |
96 return (dangerous_url || dangerous_file) ? | 101 return (dangerous_url || dangerous_file) ? |
97 DownloadItem::DANGEROUS : DownloadItem::SAFE; | 102 DownloadItem::DANGEROUS : DownloadItem::SAFE; |
98 } | 103 } |
99 | 104 |
100 // Note: When a download has both |dangerous_file| and |dangerous_url| set, | |
101 // danger type is set to DANGEROUS_URL since the risk of dangerous URL | |
102 // overweights that of dangerous file type. | |
103 DownloadItem::DangerType GetDangerType(bool dangerous_file, | 105 DownloadItem::DangerType GetDangerType(bool dangerous_file, |
104 bool dangerous_url) { | 106 bool dangerous_url, |
105 if (dangerous_url) { | 107 bool dangerous_content) { |
106 // dangerous URL overweights dangerous file. We check dangerous URL first. | 108 if (dangerous_url) |
107 return DownloadItem::DANGEROUS_URL; | 109 return DownloadItem::DANGEROUS_URL; |
108 } | 110 if (dangerous_content) |
| 111 return DownloadItem::DANGEROUS_CONTENT; |
109 return dangerous_file ? | 112 return dangerous_file ? |
110 DownloadItem::DANGEROUS_FILE : DownloadItem::NOT_DANGEROUS; | 113 DownloadItem::DANGEROUS_FILE : DownloadItem::NOT_DANGEROUS; |
111 } | 114 } |
112 | 115 |
113 // Classes to null out request handle calls (for SavePage DownloadItems, which | 116 // Classes to null out request handle calls (for SavePage DownloadItems, which |
114 // may have, e.g., Cancel() called on them without it doing anything) | 117 // may have, e.g., Cancel() called on them without it doing anything) |
115 // and to DCHECK on them (for history DownloadItems, which should never have | 118 // and to DCHECK on them (for history DownloadItems, which should never have |
116 // any operation that implies an off-thread component, since they don't | 119 // any operation that implies an off-thread component, since they don't |
117 // have any). | 120 // have any). |
118 class NullDownloadRequestHandle : public DownloadRequestHandleInterface { | 121 class NullDownloadRequestHandle : public DownloadRequestHandleInterface { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 } | 183 } |
181 | 184 |
182 // Constructing for a regular download: | 185 // Constructing for a regular download: |
183 DownloadItem::DownloadItem(DownloadManager* download_manager, | 186 DownloadItem::DownloadItem(DownloadManager* download_manager, |
184 const DownloadCreateInfo& info, | 187 const DownloadCreateInfo& info, |
185 DownloadRequestHandleInterface* request_handle, | 188 DownloadRequestHandleInterface* request_handle, |
186 bool is_otr) | 189 bool is_otr) |
187 : state_info_(info.original_name, info.save_info.file_path, | 190 : state_info_(info.original_name, info.save_info.file_path, |
188 info.has_user_gesture, info.transition_type, | 191 info.has_user_gesture, info.transition_type, |
189 info.prompt_user_for_save_location, info.path_uniquifier, | 192 info.prompt_user_for_save_location, info.path_uniquifier, |
190 false, false), | 193 false, false, false, false), |
191 request_handle_(request_handle), | 194 request_handle_(request_handle), |
192 download_id_(info.download_id), | 195 download_id_(info.download_id), |
193 full_path_(info.path), | 196 full_path_(info.path), |
194 url_chain_(info.url_chain), | 197 url_chain_(info.url_chain), |
195 referrer_url_(info.referrer_url), | 198 referrer_url_(info.referrer_url), |
196 suggested_filename_(UTF16ToUTF8(info.save_info.suggested_name)), | 199 suggested_filename_(UTF16ToUTF8(info.save_info.suggested_name)), |
197 content_disposition_(info.content_disposition), | 200 content_disposition_(info.content_disposition), |
198 mime_type_(info.mime_type), | 201 mime_type_(info.mime_type), |
199 original_mime_type_(info.original_mime_type), | 202 original_mime_type_(info.original_mime_type), |
200 referrer_charset_(info.referrer_charset), | 203 referrer_charset_(info.referrer_charset), |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 if (state_ == new_state) | 460 if (state_ == new_state) |
458 return; | 461 return; |
459 | 462 |
460 state_ = new_state; | 463 state_ = new_state; |
461 UpdateObservers(); | 464 UpdateObservers(); |
462 } | 465 } |
463 | 466 |
464 void DownloadItem::UpdateSafetyState() { | 467 void DownloadItem::UpdateSafetyState() { |
465 SafetyState updated_value( | 468 SafetyState updated_value( |
466 GetSafetyState(state_info_.is_dangerous_file, | 469 GetSafetyState(state_info_.is_dangerous_file, |
467 state_info_.is_dangerous_url)); | 470 state_info_.is_dangerous_url, |
| 471 state_info_.is_dangerous_content)); |
468 if (updated_value != safety_state_) { | 472 if (updated_value != safety_state_) { |
469 safety_state_ = updated_value; | 473 safety_state_ = updated_value; |
470 UpdateObservers(); | 474 UpdateObservers(); |
471 } | 475 } |
472 } | 476 } |
473 | 477 |
474 void DownloadItem::UpdateTarget() { | 478 void DownloadItem::UpdateTarget() { |
475 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 479 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
476 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 480 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
477 | 481 |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 | 670 |
667 VLOG(20) << " " << __FUNCTION__ << "()" << " this = " << DebugString(true); | 671 VLOG(20) << " " << __FUNCTION__ << "()" << " this = " << DebugString(true); |
668 state_info_ = state; | 672 state_info_ = state; |
669 VLOG(20) << " " << __FUNCTION__ << "()" << " this = " << DebugString(true); | 673 VLOG(20) << " " << __FUNCTION__ << "()" << " this = " << DebugString(true); |
670 | 674 |
671 UpdateSafetyState(); | 675 UpdateSafetyState(); |
672 } | 676 } |
673 | 677 |
674 DownloadItem::DangerType DownloadItem::GetDangerType() const { | 678 DownloadItem::DangerType DownloadItem::GetDangerType() const { |
675 return ::GetDangerType(state_info_.is_dangerous_file, | 679 return ::GetDangerType(state_info_.is_dangerous_file, |
676 state_info_.is_dangerous_url); | 680 state_info_.is_dangerous_url, |
| 681 state_info_.is_dangerous_content); |
677 } | 682 } |
678 | 683 |
679 bool DownloadItem::IsDangerous() const { | 684 bool DownloadItem::IsDangerous() const { |
680 return GetDangerType() != DownloadItem::NOT_DANGEROUS; | 685 return GetDangerType() != DownloadItem::NOT_DANGEROUS; |
681 } | 686 } |
682 | 687 |
683 void DownloadItem::MarkFileDangerous() { | 688 void DownloadItem::MarkFileDangerous() { |
684 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 689 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
685 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 690 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
686 | 691 |
687 state_info_.is_dangerous_file = true; | 692 state_info_.is_dangerous_file = true; |
688 UpdateSafetyState(); | 693 UpdateSafetyState(); |
689 } | 694 } |
690 | 695 |
691 void DownloadItem::MarkUrlDangerous() { | 696 void DownloadItem::MarkUrlDangerous() { |
692 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 697 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
693 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 698 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
694 | 699 |
695 state_info_.is_dangerous_url = true; | 700 state_info_.is_dangerous_url = true; |
696 UpdateSafetyState(); | 701 UpdateSafetyState(); |
697 } | 702 } |
698 | 703 |
| 704 void DownloadItem::MarkContentDangerous() { |
| 705 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
| 706 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 707 |
| 708 state_info_.is_dangerous_content = true; |
| 709 UpdateSafetyState(); |
| 710 } |
| 711 |
699 DownloadPersistentStoreInfo DownloadItem::GetPersistentStoreInfo() const { | 712 DownloadPersistentStoreInfo DownloadItem::GetPersistentStoreInfo() const { |
700 return DownloadPersistentStoreInfo(full_path(), | 713 return DownloadPersistentStoreInfo(full_path(), |
701 GetURL(), | 714 GetURL(), |
702 referrer_url(), | 715 referrer_url(), |
703 start_time(), | 716 start_time(), |
704 end_time(), | 717 end_time(), |
705 received_bytes(), | 718 received_bytes(), |
706 total_bytes(), | 719 total_bytes(), |
707 state(), | 720 state(), |
708 db_handle(), | 721 db_handle(), |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 state_info_.target_name.value().c_str(), | 840 state_info_.target_name.value().c_str(), |
828 full_path().value().c_str()); | 841 full_path().value().c_str()); |
829 } else { | 842 } else { |
830 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); | 843 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); |
831 } | 844 } |
832 | 845 |
833 description += " }"; | 846 description += " }"; |
834 | 847 |
835 return description; | 848 return description; |
836 } | 849 } |
OLD | NEW |