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, | 105 // Note: |dangerous_url| takes precedence over both |dangerous_content| and |
101 // danger type is set to DANGEROUS_URL since the risk of dangerous URL | 106 // |dangerous_content| and |dangerous_url| takes precedence over |
102 // overweights that of dangerous file type. | 107 // |dangerous_content|. |
103 DownloadItem::DangerType GetDangerType(bool dangerous_file, | 108 DownloadItem::DangerType GetDangerType(bool dangerous_file, |
104 bool dangerous_url) { | 109 bool dangerous_url, |
105 if (dangerous_url) { | 110 bool dangerous_content) { |
106 // dangerous URL overweights dangerous file. We check dangerous URL first. | 111 if (dangerous_url) |
107 return DownloadItem::DANGEROUS_URL; | 112 return DownloadItem::DANGEROUS_URL; |
108 } | 113 if (dangerous_content) |
| 114 return DownloadItem::DANGEROUS_CONTENT; |
109 return dangerous_file ? | 115 return dangerous_file ? |
110 DownloadItem::DANGEROUS_FILE : DownloadItem::NOT_DANGEROUS; | 116 DownloadItem::DANGEROUS_FILE : DownloadItem::NOT_DANGEROUS; |
111 } | 117 } |
112 | 118 |
113 } // namespace | 119 } // namespace |
114 | 120 |
115 // Our download table ID starts at 1, so we use 0 to represent a download that | 121 // Our download table ID starts at 1, so we use 0 to represent a download that |
116 // has started, but has not yet had its data persisted in the table. We use fake | 122 // has started, but has not yet had its data persisted in the table. We use fake |
117 // database handles in incognito mode starting at -1 and progressively getting | 123 // database handles in incognito mode starting at -1 and progressively getting |
118 // more negative. | 124 // more negative. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 } | 161 } |
156 | 162 |
157 // Constructing for a regular download: | 163 // Constructing for a regular download: |
158 DownloadItem::DownloadItem(DownloadManager* download_manager, | 164 DownloadItem::DownloadItem(DownloadManager* download_manager, |
159 const DownloadCreateInfo& info, | 165 const DownloadCreateInfo& info, |
160 DownloadRequestHandleInterface* request_handle, | 166 DownloadRequestHandleInterface* request_handle, |
161 bool is_otr) | 167 bool is_otr) |
162 : state_info_(info.original_name, info.save_info.file_path, | 168 : state_info_(info.original_name, info.save_info.file_path, |
163 info.has_user_gesture, info.transition_type, | 169 info.has_user_gesture, info.transition_type, |
164 info.prompt_user_for_save_location, info.path_uniquifier, | 170 info.prompt_user_for_save_location, info.path_uniquifier, |
165 false, false), | 171 false, false, false, false), |
166 request_handle_(request_handle), | 172 request_handle_(request_handle), |
167 download_id_(info.download_id), | 173 download_id_(info.download_id), |
168 full_path_(info.path), | 174 full_path_(info.path), |
169 url_chain_(info.url_chain), | 175 url_chain_(info.url_chain), |
170 referrer_url_(info.referrer_url), | 176 referrer_url_(info.referrer_url), |
171 suggested_filename_(UTF16ToUTF8(info.save_info.suggested_name)), | 177 suggested_filename_(UTF16ToUTF8(info.save_info.suggested_name)), |
172 content_disposition_(info.content_disposition), | 178 content_disposition_(info.content_disposition), |
173 mime_type_(info.mime_type), | 179 mime_type_(info.mime_type), |
174 original_mime_type_(info.original_mime_type), | 180 original_mime_type_(info.original_mime_type), |
175 referrer_charset_(info.referrer_charset), | 181 referrer_charset_(info.referrer_charset), |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 if (state_ == new_state) | 437 if (state_ == new_state) |
432 return; | 438 return; |
433 | 439 |
434 state_ = new_state; | 440 state_ = new_state; |
435 UpdateObservers(); | 441 UpdateObservers(); |
436 } | 442 } |
437 | 443 |
438 void DownloadItem::UpdateSafetyState() { | 444 void DownloadItem::UpdateSafetyState() { |
439 SafetyState updated_value( | 445 SafetyState updated_value( |
440 GetSafetyState(state_info_.is_dangerous_file, | 446 GetSafetyState(state_info_.is_dangerous_file, |
441 state_info_.is_dangerous_url)); | 447 state_info_.is_dangerous_url, |
| 448 state_info_.is_dangerous_content)); |
442 if (updated_value != safety_state_) { | 449 if (updated_value != safety_state_) { |
443 safety_state_ = updated_value; | 450 safety_state_ = updated_value; |
444 UpdateObservers(); | 451 UpdateObservers(); |
445 } | 452 } |
446 } | 453 } |
447 | 454 |
448 void DownloadItem::UpdateTarget() { | 455 void DownloadItem::UpdateTarget() { |
449 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 456 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
450 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 457 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
451 | 458 |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 | 647 |
641 VLOG(20) << " " << __FUNCTION__ << "()" << " this = " << DebugString(true); | 648 VLOG(20) << " " << __FUNCTION__ << "()" << " this = " << DebugString(true); |
642 state_info_ = state; | 649 state_info_ = state; |
643 VLOG(20) << " " << __FUNCTION__ << "()" << " this = " << DebugString(true); | 650 VLOG(20) << " " << __FUNCTION__ << "()" << " this = " << DebugString(true); |
644 | 651 |
645 UpdateSafetyState(); | 652 UpdateSafetyState(); |
646 } | 653 } |
647 | 654 |
648 DownloadItem::DangerType DownloadItem::GetDangerType() const { | 655 DownloadItem::DangerType DownloadItem::GetDangerType() const { |
649 return ::GetDangerType(state_info_.is_dangerous_file, | 656 return ::GetDangerType(state_info_.is_dangerous_file, |
650 state_info_.is_dangerous_url); | 657 state_info_.is_dangerous_url, |
| 658 state_info_.is_dangerous_content); |
651 } | 659 } |
652 | 660 |
653 bool DownloadItem::IsDangerous() const { | 661 bool DownloadItem::IsDangerous() const { |
654 return GetDangerType() != DownloadItem::NOT_DANGEROUS; | 662 return GetDangerType() != DownloadItem::NOT_DANGEROUS; |
655 } | 663 } |
656 | 664 |
657 void DownloadItem::MarkFileDangerous() { | 665 void DownloadItem::MarkFileDangerous() { |
658 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 666 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
659 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 667 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
660 | 668 |
661 state_info_.is_dangerous_file = true; | 669 state_info_.is_dangerous_file = true; |
662 UpdateSafetyState(); | 670 UpdateSafetyState(); |
663 } | 671 } |
664 | 672 |
665 void DownloadItem::MarkUrlDangerous() { | 673 void DownloadItem::MarkUrlDangerous() { |
666 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 674 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
667 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 675 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
668 | 676 |
669 state_info_.is_dangerous_url = true; | 677 state_info_.is_dangerous_url = true; |
670 UpdateSafetyState(); | 678 UpdateSafetyState(); |
671 } | 679 } |
672 | 680 |
| 681 void DownloadItem::MarkContentDangerous() { |
| 682 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
| 683 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 684 |
| 685 state_info_.is_dangerous_content = true; |
| 686 UpdateSafetyState(); |
| 687 } |
| 688 |
673 DownloadPersistentStoreInfo DownloadItem::GetPersistentStoreInfo() const { | 689 DownloadPersistentStoreInfo DownloadItem::GetPersistentStoreInfo() const { |
674 return DownloadPersistentStoreInfo(full_path(), | 690 return DownloadPersistentStoreInfo(full_path(), |
675 GetURL(), | 691 GetURL(), |
676 referrer_url(), | 692 referrer_url(), |
677 start_time(), | 693 start_time(), |
678 end_time(), | 694 end_time(), |
679 received_bytes(), | 695 received_bytes(), |
680 total_bytes(), | 696 total_bytes(), |
681 state(), | 697 state(), |
682 db_handle(), | 698 db_handle(), |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 state_info_.target_name.value().c_str(), | 813 state_info_.target_name.value().c_str(), |
798 full_path().value().c_str()); | 814 full_path().value().c_str()); |
799 } else { | 815 } else { |
800 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); | 816 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); |
801 } | 817 } |
802 | 818 |
803 description += " }"; | 819 description += " }"; |
804 | 820 |
805 return description; | 821 return description; |
806 } | 822 } |
OLD | NEW |