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

Side by Side Diff: chrome/browser/download/download_target_determiner.cc

Issue 565053002: [Downloads] Gracefully handle SafeBrowsing check failures. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_target_determiner.h" 5 #include "chrome/browser/download/download_target_determiner.h"
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/rand_util.h" 8 #include "base/rand_util.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 const base::FilePath& initial_virtual_path, 82 const base::FilePath& initial_virtual_path,
83 DownloadPrefs* download_prefs, 83 DownloadPrefs* download_prefs,
84 DownloadTargetDeterminerDelegate* delegate, 84 DownloadTargetDeterminerDelegate* delegate,
85 const CompletionCallback& callback) 85 const CompletionCallback& callback)
86 : next_state_(STATE_GENERATE_TARGET_PATH), 86 : next_state_(STATE_GENERATE_TARGET_PATH),
87 should_prompt_(false), 87 should_prompt_(false),
88 should_notify_extensions_(false), 88 should_notify_extensions_(false),
89 create_target_directory_(false), 89 create_target_directory_(false),
90 conflict_action_(DownloadPathReservationTracker::OVERWRITE), 90 conflict_action_(DownloadPathReservationTracker::OVERWRITE),
91 danger_type_(download->GetDangerType()), 91 danger_type_(download->GetDangerType()),
92 is_dangerous_file_(false),
92 virtual_path_(initial_virtual_path), 93 virtual_path_(initial_virtual_path),
93 is_filetype_handled_safely_(false), 94 is_filetype_handled_safely_(false),
94 download_(download), 95 download_(download),
95 is_resumption_(download_->GetLastReason() != 96 is_resumption_(download_->GetLastReason() !=
96 content::DOWNLOAD_INTERRUPT_REASON_NONE && 97 content::DOWNLOAD_INTERRUPT_REASON_NONE &&
97 !initial_virtual_path.empty()), 98 !initial_virtual_path.empty()),
98 download_prefs_(download_prefs), 99 download_prefs_(download_prefs),
99 delegate_(delegate), 100 delegate_(delegate),
100 completion_callback_(callback), 101 completion_callback_(callback),
101 weak_ptr_factory_(this) { 102 weak_ptr_factory_(this) {
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 DoLoop(); 570 DoLoop();
570 } 571 }
571 572
572 DownloadTargetDeterminer::Result 573 DownloadTargetDeterminer::Result
573 DownloadTargetDeterminer::DoCheckVisitedReferrerBefore() { 574 DownloadTargetDeterminer::DoCheckVisitedReferrerBefore() {
574 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 575 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
575 576
576 next_state_ = STATE_DETERMINE_INTERMEDIATE_PATH; 577 next_state_ = STATE_DETERMINE_INTERMEDIATE_PATH;
577 578
578 // Checking if there are prior visits to the referrer is only necessary if the 579 // Checking if there are prior visits to the referrer is only necessary if the
579 // danger level of the download depends on the file type. This excludes cases 580 // danger level of the download depends on the file type.
580 // where the download has already been deemed dangerous, or where the user is 581 if (danger_type_ != content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS &&
581 // going to be prompted or where this is a programmatic download. 582 danger_type_ != content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT)
582 if (danger_type_ != content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS)
583 return CONTINUE; 583 return CONTINUE;
584 584
585 // Assume that: 585 // Assume that:
586 // IsDangerousFile(VISITED_REFERRER) => IsDangerousFile(NO_VISITS_...) 586 // IsDangerousFile(VISITED_REFERRER) => IsDangerousFile(NO_VISITS_...)
587 // I.e. having visited a referrer only lowers a file's danger level. 587 // I.e. having visited a referrer only lowers a file's danger level.
588 if (IsDangerousFile(NO_VISITS_TO_REFERRER)) { 588 if (IsDangerousFile(NO_VISITS_TO_REFERRER)) {
589 // Only need to ping the history DB if the download would be considered safe 589 // Only need to ping the history DB if the download would be considered safe
590 // if there are prior visits and is considered dangerous otherwise. 590 // if there are prior visits and is considered dangerous otherwise.
591 if (!IsDangerousFile(VISITED_REFERRER)) { 591 if (!IsDangerousFile(VISITED_REFERRER)) {
592 // HistoryServiceFactory redirects incognito profiles to on-record 592 // HistoryServiceFactory redirects incognito profiles to on-record
(...skipping 10 matching lines...) Expand all
603 &DownloadTargetDeterminer::CheckVisitedReferrerBeforeDone, 603 &DownloadTargetDeterminer::CheckVisitedReferrerBeforeDone,
604 weak_ptr_factory_.GetWeakPtr())), 604 weak_ptr_factory_.GetWeakPtr())),
605 &history_tracker_); 605 &history_tracker_);
606 return QUIT_DOLOOP; 606 return QUIT_DOLOOP;
607 } 607 }
608 } 608 }
609 609
610 // If the danger level doesn't depend on having visited the refererrer URL 610 // If the danger level doesn't depend on having visited the refererrer URL
611 // or if original profile doesn't have a HistoryService or the referrer url 611 // or if original profile doesn't have a HistoryService or the referrer url
612 // is invalid, then assume the referrer has not been visited before. 612 // is invalid, then assume the referrer has not been visited before.
613 danger_type_ = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE; 613 is_dangerous_file_ = true;
614 } 614 }
615 return CONTINUE; 615 return CONTINUE;
616 } 616 }
617 617
618 void DownloadTargetDeterminer::CheckVisitedReferrerBeforeDone( 618 void DownloadTargetDeterminer::CheckVisitedReferrerBeforeDone(
619 bool visited_referrer_before) { 619 bool visited_referrer_before) {
620 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 620 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
621 DCHECK_EQ(STATE_DETERMINE_INTERMEDIATE_PATH, next_state_); 621 DCHECK_EQ(STATE_DETERMINE_INTERMEDIATE_PATH, next_state_);
622 if (IsDangerousFile( 622 if (IsDangerousFile(
623 visited_referrer_before ? VISITED_REFERRER : NO_VISITS_TO_REFERRER)) 623 visited_referrer_before ? VISITED_REFERRER : NO_VISITS_TO_REFERRER))
624 danger_type_ = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE; 624 is_dangerous_file_ = true;
625 DoLoop(); 625 DoLoop();
626 } 626 }
627 627
628 DownloadTargetDeterminer::Result 628 DownloadTargetDeterminer::Result
629 DownloadTargetDeterminer::DoDetermineIntermediatePath() { 629 DownloadTargetDeterminer::DoDetermineIntermediatePath() {
630 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 630 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
631 DCHECK(!virtual_path_.empty()); 631 DCHECK(!virtual_path_.empty());
632 DCHECK(!local_path_.empty()); 632 DCHECK(!local_path_.empty());
633 DCHECK(intermediate_path_.empty()); 633 DCHECK(intermediate_path_.empty());
634 DCHECK(!virtual_path_.MatchesExtension(kCrdownloadSuffix)); 634 DCHECK(!virtual_path_.MatchesExtension(kCrdownloadSuffix));
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 << " Intermediate:" << intermediate_path_.AsUTF8Unsafe() 708 << " Intermediate:" << intermediate_path_.AsUTF8Unsafe()
709 << " Should prompt:" << should_prompt_ 709 << " Should prompt:" << should_prompt_
710 << " Danger type:" << danger_type_; 710 << " Danger type:" << danger_type_;
711 scoped_ptr<DownloadTargetInfo> target_info(new DownloadTargetInfo); 711 scoped_ptr<DownloadTargetInfo> target_info(new DownloadTargetInfo);
712 712
713 target_info->target_path = local_path_; 713 target_info->target_path = local_path_;
714 target_info->target_disposition = 714 target_info->target_disposition =
715 (HasPromptedForPath() || should_prompt_ 715 (HasPromptedForPath() || should_prompt_
716 ? DownloadItem::TARGET_DISPOSITION_PROMPT 716 ? DownloadItem::TARGET_DISPOSITION_PROMPT
717 : DownloadItem::TARGET_DISPOSITION_OVERWRITE); 717 : DownloadItem::TARGET_DISPOSITION_OVERWRITE);
718 target_info->danger_type = danger_type_; 718 target_info->danger_type =
719 (is_dangerous_file_ &&
720 danger_type_ == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS)
721 ? content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE
722 : danger_type_;
723 target_info->is_dangerous_file = is_dangerous_file_;
719 target_info->intermediate_path = intermediate_path_; 724 target_info->intermediate_path = intermediate_path_;
720 target_info->mime_type = mime_type_; 725 target_info->mime_type = mime_type_;
721 target_info->is_filetype_handled_safely = is_filetype_handled_safely_; 726 target_info->is_filetype_handled_safely = is_filetype_handled_safely_;
722 727
723 base::MessageLoop::current()->PostTask( 728 base::MessageLoop::current()->PostTask(
724 FROM_HERE, base::Bind(completion_callback_, base::Passed(&target_info))); 729 FROM_HERE, base::Bind(completion_callback_, base::Passed(&target_info)));
725 completion_callback_.Reset(); 730 completion_callback_.Reset();
726 delete this; 731 delete this;
727 } 732 }
728 733
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 const base::FilePath& suggested_path) { 884 const base::FilePath& suggested_path) {
880 return base::FilePath(suggested_path.value() + kCrdownloadSuffix); 885 return base::FilePath(suggested_path.value() + kCrdownloadSuffix);
881 } 886 }
882 887
883 #if defined(OS_WIN) 888 #if defined(OS_WIN)
884 // static 889 // static
885 bool DownloadTargetDeterminer::IsAdobeReaderUpToDate() { 890 bool DownloadTargetDeterminer::IsAdobeReaderUpToDate() {
886 return g_is_adobe_reader_up_to_date_; 891 return g_is_adobe_reader_up_to_date_;
887 } 892 }
888 #endif 893 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698