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

Side by Side Diff: chrome/browser/safe_browsing/unverified_download_field_trial.cc

Issue 1409003002: [SafeBrowsing] Block dangerous unchecked downloads based on a Finch trial. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved. Use of this source
2 // code is governed by a BSD-style license that can be found in the LICENSE
3 // file.
4
5 #include "chrome/browser/safe_browsing/unverified_download_field_trial.h"
6
7 #include "base/command_line.h"
8 #include "base/files/file_path.h"
9 #include "base/metrics/field_trial.h"
10 #include "base/metrics/histogram.h"
11 #include "base/strings/string_split.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/safe_browsing/download_protection_util.h"
15 #include "components/variations/variations_associated_data.h"
16
17 namespace safe_browsing {
18
19 const char kUnverifiedDownloadFieldTrialName[] =
20 "SafeBrowsingUnverifiedDownloads";
21
22 const char kUnverifiedDownloadFieldTrialDisableAll[] = "DisableAll";
23 const char kUnverifiedDownloadFieldTrialDisableByParameter[] =
24 "DisableByParameter";
25 const char kUnverifiedDownloadFieldTrialDisableSBTypes[] = "DisableSBTypes";
26 const char kUnverifiedDownloadFieldTrialDisableSBTypesAndByParameter[] =
27 "DisableSBTypesAndByParameter";
28
29 const char kUnverifiedDownloadFieldTrialWhitelistParam[] = "whitelist";
30 const char kUnverifiedDownloadFieldTrialBlacklistParam[] = "blacklist";
31
32 namespace {
33
34 bool MatchesExtensionList(const base::FilePath& needle,
35 const std::string& haystack) {
36 #if defined(OS_WIN)
37 const base::FilePath::StringType file_type_comma_separated_list =
38 base::UTF8ToUTF16(haystack);
39 #else
40 const base::FilePath::StringType& file_type_comma_separated_list = haystack;
41 #endif
42 std::vector<base::FilePath::StringPieceType> file_type_list =
43 base::SplitStringPiece(file_type_comma_separated_list,
44 FILE_PATH_LITERAL(","), base::TRIM_WHITESPACE,
45 base::SPLIT_WANT_NONEMPTY);
46 for (const auto& file_type_in_list : file_type_list) {
47 DCHECK(file_type_in_list.size() > 0 &&
48 file_type_in_list[0] == base::FilePath::kExtensionSeparator);
49 if (needle.MatchesExtension(file_type_in_list))
50 return true;
51 }
52 return false;
53 }
54
55 } // namespace
56
57 bool IsUnverifiedDownloadAllowedByFieldTrial(const base::FilePath& file) {
58 std::string group_name =
59 base::FieldTrialList::FindFullName(kUnverifiedDownloadFieldTrialName);
60
61 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
62 switches::kAllowUncheckedDangerousDownloads))
63 return true;
64
65 if (group_name == kUnverifiedDownloadFieldTrialDisableAll)
66 return false;
67
68 if (group_name == kUnverifiedDownloadFieldTrialDisableByParameter ||
69 group_name == kUnverifiedDownloadFieldTrialDisableSBTypesAndByParameter) {
70 std::map<std::string, std::string> parameters;
71 variations::GetVariationParams(kUnverifiedDownloadFieldTrialName,
72 &parameters);
73
74 if (parameters.count(kUnverifiedDownloadFieldTrialBlacklistParam) &&
75 MatchesExtensionList(
76 file, parameters[kUnverifiedDownloadFieldTrialBlacklistParam]))
77 return false;
78
79 if (parameters.count(kUnverifiedDownloadFieldTrialWhitelistParam) &&
80 MatchesExtensionList(
81 file, parameters[kUnverifiedDownloadFieldTrialWhitelistParam]))
82 return true;
83 }
84
85 if (group_name == kUnverifiedDownloadFieldTrialDisableSBTypes ||
86 group_name == kUnverifiedDownloadFieldTrialDisableSBTypesAndByParameter ||
87 base::CommandLine::ForCurrentProcess()->HasSwitch(
88 switches::kDisallowUncheckedDangerousDownloads))
89 return !download_protection_util::IsSupportedBinaryFile(file);
90
91 return true;
92 }
93
94 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698