1 // Copyright (c) 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/safe_browsing/core/features.h"
6
7 #include <stddef.h>
8 #include <algorithm>
9 #include <utility>
10 #include <vector>
11 #include "base/feature_list.h"
12 #include "base/metrics/field_trial_params.h"
13 #include "components/safe_browsing/buildflags.h"
14
15 #include "base/macros.h"
16 #include "base/values.h"
17 namespace safe_browsing {
18 // Please define any new SafeBrowsing related features in this file, and add
19 // them to the ExperimentalFeaturesList below to start displaying their status
20 // on the chrome://safe-browsing page.
21 const base::Feature kAdPopupTriggerFeature{"SafeBrowsingAdPopupTrigger",
22 base::FEATURE_DISABLED_BY_DEFAULT};
23
24 const base::Feature kAdRedirectTriggerFeature{
25 "SafeBrowsingAdRedirectTrigger", base::FEATURE_DISABLED_BY_DEFAULT};
26
27 // Controls various parameters related to occasionally collecting ad samples,
28 // for example to control how often collection should occur.
29 const base::Feature kAdSamplerTriggerFeature{"SafeBrowsingAdSamplerTrigger",
30 base::FEATURE_DISABLED_BY_DEFAULT};
31
32 const base::Feature kCaptureInlineJavascriptForGoogleAds{
33 "CaptureInlineJavascriptForGoogleAds", base::FEATURE_DISABLED_BY_DEFAULT};
34
35 const base::Feature kCaptureSafetyNetId{"SafeBrowsingCaptureSafetyNetId",
36 base::FEATURE_DISABLED_BY_DEFAULT};
37
38 const base::Feature kCommittedSBInterstitials{
39 "SafeBrowsingCommittedInterstitials", base::FEATURE_ENABLED_BY_DEFAULT};
40
41 const base::Feature kContentComplianceEnabled{
42 "SafeBrowsingContentComplianceEnabled", base::FEATURE_ENABLED_BY_DEFAULT};
43
44 const base::Feature kDelayedWarnings{"SafeBrowsingDelayedWarnings",
45 base::FEATURE_DISABLED_BY_DEFAULT};
46
47 const base::Feature kDownloadRequestWithToken{
48 "SafeBrowsingDownloadRequestWithToken", base::FEATURE_ENABLED_BY_DEFAULT};
49
50 const base::Feature kEnhancedProtection{"SafeBrowsingEnhancedProtection",
51 base::FEATURE_DISABLED_BY_DEFAULT};
52
53 const base::Feature kMalwareScanEnabled{"SafeBrowsingMalwareScanEnabled",
54 base::FEATURE_ENABLED_BY_DEFAULT};
55
56 // Enable saved password protection by default only on desktop.
57 #if BUILDFLAG(FULL_SAFE_BROWSING)
58 const base::Feature kPasswordProtectionForSavedPasswords{
59 "SafeBrowsingPasswordProtectionForSavedPasswords",
60 base::FEATURE_ENABLED_BY_DEFAULT};
61 #else
62 const base::Feature kPasswordProtectionForSavedPasswords{
63 "SafeBrowsingPasswordProtectionForSavedPasswords",
64 base::FEATURE_DISABLED_BY_DEFAULT};
65 #endif
66
67 // Enable saved password protection with domains by default only on desktop.
68 #if BUILDFLAG(FULL_SAFE_BROWSING)
69 const base::Feature kPasswordProtectionShowDomainsForSavedPasswords{
70 "SafeBrowsingPasswordProtectionShowDomainsForSavedPasswords",
71 base::FEATURE_ENABLED_BY_DEFAULT};
72 #else
73 const base::Feature kPasswordProtectionShowDomainsForSavedPasswords{
74 "SafeBrowsingPasswordProtectionShowDomainsForSavedPasswords",
75 base::FEATURE_DISABLED_BY_DEFAULT};
76 #endif
77
78 #if BUILDFLAG(FULL_SAFE_BROWSING)
79 const base::Feature kPasswordProtectionForSignedInUsers{
80 "SafeBrowsingPasswordProtectionForSignedInUsers",
81 base::FEATURE_ENABLED_BY_DEFAULT};
82 #else
83 const base::Feature kPasswordProtectionForSignedInUsers{
84 "SafeBrowsingPasswordProtectionForSignedInUsers",
85 base::FEATURE_DISABLED_BY_DEFAULT};
86 #endif
87
88 const base::Feature kPromptAppForDeepScanning{
89 "SafeBrowsingPromptAppForDeepScanning", base::FEATURE_DISABLED_BY_DEFAULT};
90
91 const base::Feature kRealTimeUrlLookupEnabled{
92 "SafeBrowsingRealTimeUrlLookupEnabled", base::FEATURE_DISABLED_BY_DEFAULT};
93
94 const base::Feature kRealTimeUrlLookupEnabledForAllAndroidDevices{
95 "SafeBrowsingRealTimeUrlLookupEnabledForAllAndroidDevices",
96 base::FEATURE_DISABLED_BY_DEFAULT};
97
98 const base::Feature kRealTimeUrlLookupEnabledForEP{
99 "SafeBrowsingRealTimeUrlLookupEnabledForEP",
100 base::FEATURE_ENABLED_BY_DEFAULT};
101
102 const base::Feature kRealTimeUrlLookupEnabledForEPWithToken{
103 "SafeBrowsingRealTimeUrlLookupEnabledForEPWithToken",
104 base::FEATURE_ENABLED_BY_DEFAULT};
105
106 const base::Feature kRealTimeUrlLookupEnabledWithToken{
107 "SafeBrowsingRealTimeUrlLookupEnabledWithToken",
108 base::FEATURE_DISABLED_BY_DEFAULT};
109
110 const base::Feature kRealTimeUrlLookupNonMainframeEnabledForEP{
111 "SafeBrowsingRealTimeUrlLookupNonMainframeEnabledForEP",
112 base::FEATURE_ENABLED_BY_DEFAULT};
113
114 const base::Feature kSafeBrowsingAvailableOnIOS{
115 "SafeBrowsingAvailableOnIOS", base::FEATURE_DISABLED_BY_DEFAULT};
116
117 const base::Feature kSafeBrowsingSeparateNetworkContexts{
118 "SafeBrowsingSeparateNetworkContexts", base::FEATURE_DISABLED_BY_DEFAULT};
119
120 constexpr base::FeatureParam<bool> kShouldFillOldPhishGuardProto{
121 &kPasswordProtectionForSignedInUsers, "DeprecateOldProto", false};
122
123 const base::Feature kSuspiciousSiteTriggerQuotaFeature{
124 "SafeBrowsingSuspiciousSiteTriggerQuota", base::FEATURE_ENABLED_BY_DEFAULT};
125
126 const base::Feature kThreatDomDetailsTagAndAttributeFeature{
127 "ThreatDomDetailsTagAttributes", base::FEATURE_DISABLED_BY_DEFAULT};
128
129 const base::Feature kTriggerThrottlerDailyQuotaFeature{
130 "SafeBrowsingTriggerThrottlerDailyQuota",
131 base::FEATURE_DISABLED_BY_DEFAULT};
132 const base::Feature kUseNewDownloadWarnings{"UseNewDownloadWarnings",
133 base::FEATURE_DISABLED_BY_DEFAULT};
134
135 namespace {
136 // List of Safe Browsing features. Boolean value for each list member should be
137 // set to true if the experiment state should be listed on
138 // chrome://safe-browsing. Features should be listed in alphabetical order.
139 constexpr struct {
140 const base::Feature* feature;
141 // True if the feature's state should be listed on chrome://safe-browsing.
142 bool show_state;
143 } kExperimentalFeatures[]{
144 {&kAdPopupTriggerFeature, true},
145 {&kAdRedirectTriggerFeature, true},
146 {&kAdSamplerTriggerFeature, false},
147 {&kCaptureInlineJavascriptForGoogleAds, true},
148 {&kCaptureSafetyNetId, true},
149 {&kCommittedSBInterstitials, true},
150 {&kContentComplianceEnabled, true},
151 {&kDelayedWarnings, true},
152 {&kDownloadRequestWithToken, true},
153 {&kEnhancedProtection, true},
154 {&kMalwareScanEnabled, true},
155 {&kPasswordProtectionForSavedPasswords, true},
156 {&kPasswordProtectionShowDomainsForSavedPasswords, true},
157 {&kPasswordProtectionForSignedInUsers, true},
158 {&kPromptAppForDeepScanning, true},
159 {&kRealTimeUrlLookupEnabled, true},
160 {&kRealTimeUrlLookupEnabledForAllAndroidDevices, true},
161 {&kRealTimeUrlLookupEnabledForEP, true},
162 {&kRealTimeUrlLookupEnabledForEPWithToken, true},
163 {&kRealTimeUrlLookupEnabledWithToken, true},
164 {&kRealTimeUrlLookupNonMainframeEnabledForEP, true},
165 {&kSafeBrowsingAvailableOnIOS, true},
166 {&kSafeBrowsingSeparateNetworkContexts, true},
167 {&kSuspiciousSiteTriggerQuotaFeature, true},
168 {&kThreatDomDetailsTagAndAttributeFeature, false},
169 {&kTriggerThrottlerDailyQuotaFeature, false},
170 };
171
172 // Adds the name and the enabled/disabled status of a given feature.
AddFeatureAndAvailability(const base::Feature * exp_feature,base::ListValue * param_list)173 void AddFeatureAndAvailability(const base::Feature* exp_feature,
174 base::ListValue* param_list) {
175 param_list->Append(base::Value(exp_feature->name));
176 if (base::FeatureList::IsEnabled(*exp_feature)) {
177 param_list->Append(base::Value("Enabled"));
178 } else {
179 param_list->Append(base::Value("Disabled"));
180 }
181 }
182 } // namespace
183
184 // Returns the list of the experimental features that are enabled or disabled,
185 // as part of currently running Safe Browsing experiments.
GetFeatureStatusList()186 base::ListValue GetFeatureStatusList() {
187 base::ListValue param_list;
188 for (const auto& feature_status : kExperimentalFeatures) {
189 if (feature_status.show_state)
190 AddFeatureAndAvailability(feature_status.feature, ¶m_list);
191 }
192 return param_list;
193 }
194
GetShouldFillOldPhishGuardProto()195 bool GetShouldFillOldPhishGuardProto() {
196 return kShouldFillOldPhishGuardProto.Get();
197 }
198
199 } // namespace safe_browsing
200