Chromium Code Reviews| 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/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 Loading... | |
| 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 // * If the user navigated to the download URL via the omnibox (either by |
|
Peter Kasting
2016/06/29 23:35:01
Nit: Remove "If" from both of these bullets (you a
asanka
2016/06/30 15:48:52
Done.
| |
| 894 // typing the URL, pasting it, or using search). | |
| 895 // | |
| 896 // * If the navigation that initiated the download has a user gesture | |
| 897 // associated with it AND the user the user is familiar with the referring | |
| 898 // origin. | |
| 899 // | |
| 900 // A user is considered familiar with a referring origin if a visit for a page | |
|
Peter Kasting
2016/06/29 23:35:01
Nit: I'd move this to the end of the second bullet
asanka
2016/06/30 15:48:52
Done.
| |
| 901 // from the same origin was recorded on the previous day or earlier. | |
| 894 if (danger_level == DownloadFileType::ALLOW_ON_USER_GESTURE && | 902 if (danger_level == DownloadFileType::ALLOW_ON_USER_GESTURE && |
| 895 (ui::PageTransitionTypeIncludingQualifiersIs( | 903 ((download_->GetTransitionType() & |
| 896 download_->GetTransitionType(), | 904 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR) != 0 || |
| 897 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR) || | |
| 898 (download_->HasUserGesture() && visits == VISITED_REFERRER))) | 905 (download_->HasUserGesture() && visits == VISITED_REFERRER))) |
| 899 return DownloadFileType::NOT_DANGEROUS; | 906 return DownloadFileType::NOT_DANGEROUS; |
| 900 return danger_level; | 907 return danger_level; |
| 901 } | 908 } |
| 902 | 909 |
| 903 void DownloadTargetDeterminer::OnDownloadDestroyed( | 910 void DownloadTargetDeterminer::OnDownloadDestroyed( |
| 904 DownloadItem* download) { | 911 DownloadItem* download) { |
| 905 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 912 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 906 DCHECK_EQ(download_, download); | 913 DCHECK_EQ(download_, download); |
| 907 CancelOnFailureAndDeleteSelf(); | 914 CancelOnFailureAndDeleteSelf(); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 925 const base::FilePath& suggested_path) { | 932 const base::FilePath& suggested_path) { |
| 926 return base::FilePath(suggested_path.value() + kCrdownloadSuffix); | 933 return base::FilePath(suggested_path.value() + kCrdownloadSuffix); |
| 927 } | 934 } |
| 928 | 935 |
| 929 #if defined(OS_WIN) | 936 #if defined(OS_WIN) |
| 930 // static | 937 // static |
| 931 bool DownloadTargetDeterminer::IsAdobeReaderUpToDate() { | 938 bool DownloadTargetDeterminer::IsAdobeReaderUpToDate() { |
| 932 return g_is_adobe_reader_up_to_date_; | 939 return g_is_adobe_reader_up_to_date_; |
| 933 } | 940 } |
| 934 #endif | 941 #endif |
| OLD | NEW |