Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: content/browser/download/download_item.cc

Issue 8468020: Propagate the SafeBrowsing download protection verdict to the DownloadItem. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Add danger state to the download extension API. I couldn't find any static docs for that API. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
benjhayden 2011/11/16 15:57:22 Thank you for fixing the incorrect use of the verb
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 // Classes to null out request handle calls (for SavePage DownloadItems, which 119 // Classes to null out request handle calls (for SavePage DownloadItems, which
114 // may have, e.g., Cancel() called on them without it doing anything) 120 // 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 121 // 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 122 // any operation that implies an off-thread component, since they don't
117 // have any). 123 // have any).
118 class NullDownloadRequestHandle : public DownloadRequestHandleInterface { 124 class NullDownloadRequestHandle : public DownloadRequestHandleInterface {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 } 186 }
181 187
182 // Constructing for a regular download: 188 // Constructing for a regular download:
183 DownloadItem::DownloadItem(DownloadManager* download_manager, 189 DownloadItem::DownloadItem(DownloadManager* download_manager,
184 const DownloadCreateInfo& info, 190 const DownloadCreateInfo& info,
185 DownloadRequestHandleInterface* request_handle, 191 DownloadRequestHandleInterface* request_handle,
186 bool is_otr) 192 bool is_otr)
187 : state_info_(info.original_name, info.save_info.file_path, 193 : state_info_(info.original_name, info.save_info.file_path,
188 info.has_user_gesture, info.transition_type, 194 info.has_user_gesture, info.transition_type,
189 info.prompt_user_for_save_location, info.path_uniquifier, 195 info.prompt_user_for_save_location, info.path_uniquifier,
190 false, false), 196 false, false, false, false),
191 request_handle_(request_handle), 197 request_handle_(request_handle),
192 download_id_(info.download_id), 198 download_id_(info.download_id),
193 full_path_(info.path), 199 full_path_(info.path),
194 url_chain_(info.url_chain), 200 url_chain_(info.url_chain),
195 referrer_url_(info.referrer_url), 201 referrer_url_(info.referrer_url),
196 suggested_filename_(UTF16ToUTF8(info.save_info.suggested_name)), 202 suggested_filename_(UTF16ToUTF8(info.save_info.suggested_name)),
197 content_disposition_(info.content_disposition), 203 content_disposition_(info.content_disposition),
198 mime_type_(info.mime_type), 204 mime_type_(info.mime_type),
199 original_mime_type_(info.original_mime_type), 205 original_mime_type_(info.original_mime_type),
200 referrer_charset_(info.referrer_charset), 206 referrer_charset_(info.referrer_charset),
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 if (state_ == new_state) 463 if (state_ == new_state)
458 return; 464 return;
459 465
460 state_ = new_state; 466 state_ = new_state;
461 UpdateObservers(); 467 UpdateObservers();
462 } 468 }
463 469
464 void DownloadItem::UpdateSafetyState() { 470 void DownloadItem::UpdateSafetyState() {
465 SafetyState updated_value( 471 SafetyState updated_value(
466 GetSafetyState(state_info_.is_dangerous_file, 472 GetSafetyState(state_info_.is_dangerous_file,
467 state_info_.is_dangerous_url)); 473 state_info_.is_dangerous_url,
474 state_info_.is_dangerous_content));
468 if (updated_value != safety_state_) { 475 if (updated_value != safety_state_) {
469 safety_state_ = updated_value; 476 safety_state_ = updated_value;
470 UpdateObservers(); 477 UpdateObservers();
471 } 478 }
472 } 479 }
473 480
474 void DownloadItem::UpdateTarget() { 481 void DownloadItem::UpdateTarget() {
475 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 482 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
476 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 483 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
477 484
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 673
667 VLOG(20) << " " << __FUNCTION__ << "()" << " this = " << DebugString(true); 674 VLOG(20) << " " << __FUNCTION__ << "()" << " this = " << DebugString(true);
668 state_info_ = state; 675 state_info_ = state;
669 VLOG(20) << " " << __FUNCTION__ << "()" << " this = " << DebugString(true); 676 VLOG(20) << " " << __FUNCTION__ << "()" << " this = " << DebugString(true);
670 677
671 UpdateSafetyState(); 678 UpdateSafetyState();
672 } 679 }
673 680
674 DownloadItem::DangerType DownloadItem::GetDangerType() const { 681 DownloadItem::DangerType DownloadItem::GetDangerType() const {
675 return ::GetDangerType(state_info_.is_dangerous_file, 682 return ::GetDangerType(state_info_.is_dangerous_file,
676 state_info_.is_dangerous_url); 683 state_info_.is_dangerous_url,
684 state_info_.is_dangerous_content);
677 } 685 }
678 686
679 bool DownloadItem::IsDangerous() const { 687 bool DownloadItem::IsDangerous() const {
680 return GetDangerType() != DownloadItem::NOT_DANGEROUS; 688 return GetDangerType() != DownloadItem::NOT_DANGEROUS;
681 } 689 }
682 690
683 void DownloadItem::MarkFileDangerous() { 691 void DownloadItem::MarkFileDangerous() {
684 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 692 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
685 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 693 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
686 694
687 state_info_.is_dangerous_file = true; 695 state_info_.is_dangerous_file = true;
688 UpdateSafetyState(); 696 UpdateSafetyState();
689 } 697 }
690 698
691 void DownloadItem::MarkUrlDangerous() { 699 void DownloadItem::MarkUrlDangerous() {
692 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 700 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
693 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 701 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
694 702
695 state_info_.is_dangerous_url = true; 703 state_info_.is_dangerous_url = true;
696 UpdateSafetyState(); 704 UpdateSafetyState();
697 } 705 }
698 706
707 void DownloadItem::MarkContentDangerous() {
708 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
709 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
710
711 state_info_.is_dangerous_content = true;
712 UpdateSafetyState();
713 }
714
699 DownloadPersistentStoreInfo DownloadItem::GetPersistentStoreInfo() const { 715 DownloadPersistentStoreInfo DownloadItem::GetPersistentStoreInfo() const {
700 return DownloadPersistentStoreInfo(full_path(), 716 return DownloadPersistentStoreInfo(full_path(),
701 GetURL(), 717 GetURL(),
702 referrer_url(), 718 referrer_url(),
703 start_time(), 719 start_time(),
704 end_time(), 720 end_time(),
705 received_bytes(), 721 received_bytes(),
706 total_bytes(), 722 total_bytes(),
707 state(), 723 state(),
708 db_handle(), 724 db_handle(),
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 state_info_.target_name.value().c_str(), 843 state_info_.target_name.value().c_str(),
828 full_path().value().c_str()); 844 full_path().value().c_str());
829 } else { 845 } else {
830 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); 846 description += base::StringPrintf(" url = \"%s\"", url_list.c_str());
831 } 847 }
832 848
833 description += " }"; 849 description += " }";
834 850
835 return description; 851 return description;
836 } 852 }
OLDNEW
« no previous file with comments | « content/browser/download/download_item.h ('k') | content/browser/download/download_state_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698