| 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 "chrome/browser/download/download_item.h" | 5 #include "chrome/browser/download/download_item.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/i18n/case_conversion.h" | 10 #include "base/i18n/case_conversion.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 case DownloadItem::REMOVING: | 86 case DownloadItem::REMOVING: |
| 87 return "REMOVING"; | 87 return "REMOVING"; |
| 88 case DownloadItem::INTERRUPTED: | 88 case DownloadItem::INTERRUPTED: |
| 89 return "INTERRUPTED"; | 89 return "INTERRUPTED"; |
| 90 default: | 90 default: |
| 91 NOTREACHED() << "Unknown download state " << state; | 91 NOTREACHED() << "Unknown download state " << state; |
| 92 return "unknown"; | 92 return "unknown"; |
| 93 }; | 93 }; |
| 94 } | 94 } |
| 95 | 95 |
| 96 DownloadItem::SafetyState GetSafetyState(bool dangerous_file, | 96 DownloadItem::SafetyState GetSafetyState( |
| 97 bool dangerous_url) { | 97 bool dangerous_file, |
| 98 return (dangerous_url || dangerous_file) ? | 98 DownloadStateInfo::Tristate dangerous_url) { |
| 99 return ((dangerous_url == DownloadStateInfo::YES) || dangerous_file) ? |
| 99 DownloadItem::DANGEROUS : DownloadItem::SAFE; | 100 DownloadItem::DANGEROUS : DownloadItem::SAFE; |
| 100 } | 101 } |
| 101 | 102 |
| 102 // Note: When a download has both |dangerous_file| and |dangerous_url| set, | 103 // Note: When a download has both |dangerous_file| and |dangerous_url| set, |
| 103 // danger type is set to DANGEROUS_URL since the risk of dangerous URL | 104 // danger type is set to DANGEROUS_URL since the risk of dangerous URL |
| 104 // overweights that of dangerous file type. | 105 // overweights that of dangerous file type. |
| 105 DownloadItem::DangerType GetDangerType(bool dangerous_file, | 106 DownloadItem::DangerType GetDangerType( |
| 106 bool dangerous_url) { | 107 bool dangerous_file, |
| 107 if (dangerous_url) { | 108 DownloadStateInfo::Tristate dangerous_url) { |
| 109 if (dangerous_url == DownloadStateInfo::YES) { |
| 108 // dangerous URL overweights dangerous file. We check dangerous URL first. | 110 // dangerous URL overweights dangerous file. We check dangerous URL first. |
| 109 return DownloadItem::DANGEROUS_URL; | 111 return DownloadItem::DANGEROUS_URL; |
| 110 } | 112 } |
| 111 return dangerous_file ? | 113 return dangerous_file ? |
| 112 DownloadItem::DANGEROUS_FILE : DownloadItem::NOT_DANGEROUS; | 114 DownloadItem::DANGEROUS_FILE : DownloadItem::NOT_DANGEROUS; |
| 113 } | 115 } |
| 114 | 116 |
| 115 } // namespace | 117 } // namespace |
| 116 | 118 |
| 117 // Constructor for reading from the history service. | 119 // Constructor for reading from the history service. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 142 all_data_saved_ = true; | 144 all_data_saved_ = true; |
| 143 Init(false /* don't start progress timer */); | 145 Init(false /* don't start progress timer */); |
| 144 } | 146 } |
| 145 | 147 |
| 146 // Constructing for a regular download: | 148 // Constructing for a regular download: |
| 147 DownloadItem::DownloadItem(DownloadManager* download_manager, | 149 DownloadItem::DownloadItem(DownloadManager* download_manager, |
| 148 const DownloadCreateInfo& info, | 150 const DownloadCreateInfo& info, |
| 149 bool is_otr) | 151 bool is_otr) |
| 150 : state_info_(info.original_name, info.save_info.file_path, | 152 : state_info_(info.original_name, info.save_info.file_path, |
| 151 info.has_user_gesture, info.prompt_user_for_save_location, | 153 info.has_user_gesture, info.prompt_user_for_save_location, |
| 152 info.path_uniquifier, info.is_dangerous_file, | 154 info.path_uniquifier, false, DownloadStateInfo::UNKNOWN, |
| 153 info.is_dangerous_url, info.is_extension_install), | 155 DownloadStateInfo::UNKNOWN, info.is_extension_install), |
| 154 process_handle_(info.process_handle), | 156 process_handle_(info.process_handle), |
| 155 download_id_(info.download_id), | 157 download_id_(info.download_id), |
| 156 full_path_(info.path), | 158 full_path_(info.path), |
| 157 url_chain_(info.url_chain), | 159 url_chain_(info.url_chain), |
| 158 referrer_url_(info.referrer_url), | 160 referrer_url_(info.referrer_url), |
| 159 content_disposition_(info.content_disposition), | 161 content_disposition_(info.content_disposition), |
| 160 mime_type_(info.mime_type), | 162 mime_type_(info.mime_type), |
| 161 original_mime_type_(info.original_mime_type), | 163 original_mime_type_(info.original_mime_type), |
| 162 referrer_charset_(info.referrer_charset), | 164 referrer_charset_(info.referrer_charset), |
| 163 total_bytes_(info.total_bytes), | 165 total_bytes_(info.total_bytes), |
| 164 received_bytes_(0), | 166 received_bytes_(0), |
| 165 last_os_error_(0), | 167 last_os_error_(0), |
| 166 start_tick_(base::TimeTicks::Now()), | 168 start_tick_(base::TimeTicks::Now()), |
| 167 state_(IN_PROGRESS), | 169 state_(IN_PROGRESS), |
| 168 start_time_(info.start_time), | 170 start_time_(info.start_time), |
| 169 db_handle_(DownloadHistory::kUninitializedHandle), | 171 db_handle_(DownloadHistory::kUninitializedHandle), |
| 170 download_manager_(download_manager), | 172 download_manager_(download_manager), |
| 171 is_paused_(false), | 173 is_paused_(false), |
| 172 open_when_complete_(false), | 174 open_when_complete_(false), |
| 173 safety_state_(GetSafetyState(info.is_dangerous_file, | 175 safety_state_(SAFE), |
| 174 info.is_dangerous_url)), | |
| 175 auto_opened_(false), | 176 auto_opened_(false), |
| 176 is_otr_(is_otr), | 177 is_otr_(is_otr), |
| 177 is_temporary_(!info.save_info.file_path.empty()), | 178 is_temporary_(!info.save_info.file_path.empty()), |
| 178 all_data_saved_(false), | 179 all_data_saved_(false), |
| 179 opened_(false) { | 180 opened_(false) { |
| 180 Init(true /* start progress timer */); | 181 Init(true /* start progress timer */); |
| 181 } | 182 } |
| 182 | 183 |
| 183 // Constructing for the "Save Page As..." feature: | 184 // Constructing for the "Save Page As..." feature: |
| 184 DownloadItem::DownloadItem(DownloadManager* download_manager, | 185 DownloadItem::DownloadItem(DownloadManager* download_manager, |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 | 535 |
| 535 DownloadItem::DangerType DownloadItem::GetDangerType() const { | 536 DownloadItem::DangerType DownloadItem::GetDangerType() const { |
| 536 return ::GetDangerType(state_info_.is_dangerous_file, | 537 return ::GetDangerType(state_info_.is_dangerous_file, |
| 537 state_info_.is_dangerous_url); | 538 state_info_.is_dangerous_url); |
| 538 } | 539 } |
| 539 | 540 |
| 540 bool DownloadItem::IsDangerous() const { | 541 bool DownloadItem::IsDangerous() const { |
| 541 return GetDangerType() != DownloadItem::NOT_DANGEROUS; | 542 return GetDangerType() != DownloadItem::NOT_DANGEROUS; |
| 542 } | 543 } |
| 543 | 544 |
| 544 void DownloadItem::MarkUrlDangerous() { | 545 void DownloadItem::SetFileDangerous(bool dangerous) { |
| 545 state_info_.is_dangerous_url = true; | 546 state_info_.is_dangerous_file = dangerous; |
| 547 } |
| 548 |
| 549 void DownloadItem::SetUrlDangerous(bool dangerous) { |
| 550 state_info_.is_dangerous_url = |
| 551 dangerous ? DownloadStateInfo::YES : DownloadStateInfo::NO; |
| 552 } |
| 553 |
| 554 void DownloadItem::SetVisitedBefore(bool visited_referrer_before) { |
| 555 state_info_.visited_referrer_before = |
| 556 visited_referrer_before ? DownloadStateInfo::YES : DownloadStateInfo::NO; |
| 546 } | 557 } |
| 547 | 558 |
| 548 DownloadHistoryInfo DownloadItem::GetHistoryInfo() const { | 559 DownloadHistoryInfo DownloadItem::GetHistoryInfo() const { |
| 549 return DownloadHistoryInfo(full_path(), | 560 return DownloadHistoryInfo(full_path(), |
| 550 GetURL(), | 561 GetURL(), |
| 551 referrer_url(), | 562 referrer_url(), |
| 552 start_time(), | 563 start_time(), |
| 553 received_bytes(), | 564 received_bytes(), |
| 554 total_bytes(), | 565 total_bytes(), |
| 555 state(), | 566 state(), |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 state_info_.target_name.value().c_str(), | 662 state_info_.target_name.value().c_str(), |
| 652 full_path().value().c_str()); | 663 full_path().value().c_str()); |
| 653 } else { | 664 } else { |
| 654 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); | 665 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); |
| 655 } | 666 } |
| 656 | 667 |
| 657 description += " }"; | 668 description += " }"; |
| 658 | 669 |
| 659 return description; | 670 return description; |
| 660 } | 671 } |
| OLD | NEW |