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

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

Issue 2090013006: [Downloads] Correctly test page transition when calculating danger level. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge with ToT Created 4 years, 5 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
« no previous file with comments | « no previous file | chrome/browser/download/download_target_determiner_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/location.h" 7 #include "base/location.h"
8 #include "base/rand_util.h" 8 #include "base/rand_util.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 877
878 // Anything the user has marked auto-open is OK if it's user-initiated. 878 // Anything the user has marked auto-open is OK if it's user-initiated.
879 if (download_prefs_->IsAutoOpenEnabledBasedOnExtension(virtual_path_) && 879 if (download_prefs_->IsAutoOpenEnabledBasedOnExtension(virtual_path_) &&
880 download_->HasUserGesture()) 880 download_->HasUserGesture())
881 return DownloadFileType::NOT_DANGEROUS; 881 return DownloadFileType::NOT_DANGEROUS;
882 882
883 DownloadFileType::DangerLevel danger_level = 883 DownloadFileType::DangerLevel danger_level =
884 safe_browsing::FileTypePolicies::GetInstance()->GetFileDangerLevel( 884 safe_browsing::FileTypePolicies::GetInstance()->GetFileDangerLevel(
885 virtual_path_.BaseName()); 885 virtual_path_.BaseName());
886 886
887 // If the danger level is ALLOW_ON_USER_GESTURE and we have a user gesture AND 887 // A danger level of ALLOW_ON_USER_GESTURE is used to label potentially
888 // there was a recorded visit to the referrer prior to today, then we are 888 // dangerous file types that have a high frequency of legitimate use. We would
889 // going to downgrade the danger_level to NOT_DANGEROUS. This prevents 889 // like to avoid prompting for the legitimate cases as much as possible. To
890 // spurious prompting for moderately dangerous files that are downloaded from 890 // that end, we consider a download to be legitimate if one of the following
891 // familiar sites. 891 // is true, and avoid prompting:
892 // TODO(asanka): Check PAGE_TRANSITION_FROM_ADDRESS_BAR bit instead of 892 //
893 // comparing all bits with PageTransitionTypeIncludingQualifiersIs(). 893 // * The user navigated to the download URL via the omnibox (either by typing
894 // the URL, pasting it, or using search).
895 //
896 // * The navigation that initiated the download has a user gesture associated
897 // with it AND the user the user is familiar with the referring origin. A
898 // user is considered familiar with a referring origin if a visit for a page
899 // from the same origin was recorded on the previous day or earlier.
894 if (danger_level == DownloadFileType::ALLOW_ON_USER_GESTURE && 900 if (danger_level == DownloadFileType::ALLOW_ON_USER_GESTURE &&
895 (ui::PageTransitionTypeIncludingQualifiersIs( 901 ((download_->GetTransitionType() &
896 download_->GetTransitionType(), 902 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR) != 0 ||
897 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR) ||
898 (download_->HasUserGesture() && visits == VISITED_REFERRER))) 903 (download_->HasUserGesture() && visits == VISITED_REFERRER)))
899 return DownloadFileType::NOT_DANGEROUS; 904 return DownloadFileType::NOT_DANGEROUS;
900 return danger_level; 905 return danger_level;
901 } 906 }
902 907
903 void DownloadTargetDeterminer::OnDownloadDestroyed( 908 void DownloadTargetDeterminer::OnDownloadDestroyed(
904 DownloadItem* download) { 909 DownloadItem* download) {
905 DCHECK_CURRENTLY_ON(BrowserThread::UI); 910 DCHECK_CURRENTLY_ON(BrowserThread::UI);
906 DCHECK_EQ(download_, download); 911 DCHECK_EQ(download_, download);
907 CancelOnFailureAndDeleteSelf(); 912 CancelOnFailureAndDeleteSelf();
(...skipping 17 matching lines...) Expand all
925 const base::FilePath& suggested_path) { 930 const base::FilePath& suggested_path) {
926 return base::FilePath(suggested_path.value() + kCrdownloadSuffix); 931 return base::FilePath(suggested_path.value() + kCrdownloadSuffix);
927 } 932 }
928 933
929 #if defined(OS_WIN) 934 #if defined(OS_WIN)
930 // static 935 // static
931 bool DownloadTargetDeterminer::IsAdobeReaderUpToDate() { 936 bool DownloadTargetDeterminer::IsAdobeReaderUpToDate() {
932 return g_is_adobe_reader_up_to_date_; 937 return g_is_adobe_reader_up_to_date_;
933 } 938 }
934 #endif 939 #endif
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/download/download_target_determiner_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698