OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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 if (danger_type_ == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) |
| 615 danger_type_ = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE; |
614 } | 616 } |
615 return CONTINUE; | 617 return CONTINUE; |
616 } | 618 } |
617 | 619 |
618 void DownloadTargetDeterminer::CheckVisitedReferrerBeforeDone( | 620 void DownloadTargetDeterminer::CheckVisitedReferrerBeforeDone( |
619 bool visited_referrer_before) { | 621 bool visited_referrer_before) { |
620 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 622 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
621 DCHECK_EQ(STATE_DETERMINE_INTERMEDIATE_PATH, next_state_); | 623 DCHECK_EQ(STATE_DETERMINE_INTERMEDIATE_PATH, next_state_); |
622 if (IsDangerousFile( | 624 if (IsDangerousFile(visited_referrer_before ? VISITED_REFERRER |
623 visited_referrer_before ? VISITED_REFERRER : NO_VISITS_TO_REFERRER)) | 625 : NO_VISITS_TO_REFERRER)) { |
624 danger_type_ = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE; | 626 is_dangerous_file_ = true; |
| 627 if (danger_type_ == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) |
| 628 danger_type_ = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE; |
| 629 } |
625 DoLoop(); | 630 DoLoop(); |
626 } | 631 } |
627 | 632 |
628 DownloadTargetDeterminer::Result | 633 DownloadTargetDeterminer::Result |
629 DownloadTargetDeterminer::DoDetermineIntermediatePath() { | 634 DownloadTargetDeterminer::DoDetermineIntermediatePath() { |
630 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 635 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
631 DCHECK(!virtual_path_.empty()); | 636 DCHECK(!virtual_path_.empty()); |
632 DCHECK(!local_path_.empty()); | 637 DCHECK(!local_path_.empty()); |
633 DCHECK(intermediate_path_.empty()); | 638 DCHECK(intermediate_path_.empty()); |
634 DCHECK(!virtual_path_.MatchesExtension(kCrdownloadSuffix)); | 639 DCHECK(!virtual_path_.MatchesExtension(kCrdownloadSuffix)); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 intermediate_path_ = local_path_.DirName().Append(file_name); | 705 intermediate_path_ = local_path_.DirName().Append(file_name); |
701 return COMPLETE; | 706 return COMPLETE; |
702 } | 707 } |
703 | 708 |
704 void DownloadTargetDeterminer::ScheduleCallbackAndDeleteSelf() { | 709 void DownloadTargetDeterminer::ScheduleCallbackAndDeleteSelf() { |
705 DCHECK(download_); | 710 DCHECK(download_); |
706 DVLOG(20) << "Scheduling callback. Virtual:" << virtual_path_.AsUTF8Unsafe() | 711 DVLOG(20) << "Scheduling callback. Virtual:" << virtual_path_.AsUTF8Unsafe() |
707 << " Local:" << local_path_.AsUTF8Unsafe() | 712 << " Local:" << local_path_.AsUTF8Unsafe() |
708 << " Intermediate:" << intermediate_path_.AsUTF8Unsafe() | 713 << " Intermediate:" << intermediate_path_.AsUTF8Unsafe() |
709 << " Should prompt:" << should_prompt_ | 714 << " Should prompt:" << should_prompt_ |
710 << " Danger type:" << danger_type_; | 715 << " Danger type:" << danger_type_ |
| 716 << " Is dangerous file:" << is_dangerous_file_; |
711 scoped_ptr<DownloadTargetInfo> target_info(new DownloadTargetInfo); | 717 scoped_ptr<DownloadTargetInfo> target_info(new DownloadTargetInfo); |
712 | 718 |
713 target_info->target_path = local_path_; | 719 target_info->target_path = local_path_; |
714 target_info->target_disposition = | 720 target_info->target_disposition = |
715 (HasPromptedForPath() || should_prompt_ | 721 (HasPromptedForPath() || should_prompt_ |
716 ? DownloadItem::TARGET_DISPOSITION_PROMPT | 722 ? DownloadItem::TARGET_DISPOSITION_PROMPT |
717 : DownloadItem::TARGET_DISPOSITION_OVERWRITE); | 723 : DownloadItem::TARGET_DISPOSITION_OVERWRITE); |
718 target_info->danger_type = danger_type_; | 724 target_info->danger_type = danger_type_; |
| 725 target_info->is_dangerous_file = is_dangerous_file_; |
719 target_info->intermediate_path = intermediate_path_; | 726 target_info->intermediate_path = intermediate_path_; |
720 target_info->mime_type = mime_type_; | 727 target_info->mime_type = mime_type_; |
721 target_info->is_filetype_handled_safely = is_filetype_handled_safely_; | 728 target_info->is_filetype_handled_safely = is_filetype_handled_safely_; |
722 | 729 |
723 base::MessageLoop::current()->PostTask( | 730 base::MessageLoop::current()->PostTask( |
724 FROM_HERE, base::Bind(completion_callback_, base::Passed(&target_info))); | 731 FROM_HERE, base::Bind(completion_callback_, base::Passed(&target_info))); |
725 completion_callback_.Reset(); | 732 completion_callback_.Reset(); |
726 delete this; | 733 delete this; |
727 } | 734 } |
728 | 735 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 const base::FilePath& suggested_path) { | 886 const base::FilePath& suggested_path) { |
880 return base::FilePath(suggested_path.value() + kCrdownloadSuffix); | 887 return base::FilePath(suggested_path.value() + kCrdownloadSuffix); |
881 } | 888 } |
882 | 889 |
883 #if defined(OS_WIN) | 890 #if defined(OS_WIN) |
884 // static | 891 // static |
885 bool DownloadTargetDeterminer::IsAdobeReaderUpToDate() { | 892 bool DownloadTargetDeterminer::IsAdobeReaderUpToDate() { |
886 return g_is_adobe_reader_up_to_date_; | 893 return g_is_adobe_reader_up_to_date_; |
887 } | 894 } |
888 #endif | 895 #endif |
OLD | NEW |