Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_SUBRESOURCE_FILTER_FEATURES_H _ | 5 #ifndef COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_SUBRESOURCE_FILTER_FEATURES_H _ |
| 6 #define COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_SUBRESOURCE_FILTER_FEATURES_H _ | 6 #define COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_SUBRESOURCE_FILTER_FEATURES_H _ |
| 7 | 7 |
| 8 #include <iosfwd> | |
| 9 #include <vector> | |
| 10 | |
| 8 #include "base/feature_list.h" | 11 #include "base/feature_list.h" |
| 9 #include "base/macros.h" | 12 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 11 #include "components/subresource_filter/core/common/activation_level.h" | 14 #include "components/subresource_filter/core/common/activation_level.h" |
| 12 #include "components/subresource_filter/core/common/activation_list.h" | 15 #include "components/subresource_filter/core/common/activation_list.h" |
| 13 #include "components/subresource_filter/core/common/activation_scope.h" | 16 #include "components/subresource_filter/core/common/activation_scope.h" |
| 14 | 17 |
| 15 namespace subresource_filter { | 18 namespace subresource_filter { |
| 16 | 19 |
| 17 // Encapsulates all parameters that define how the subresource filter feature | 20 // Encapsulates a set of parameters that define how the subresource filter |
| 18 // should operate. | 21 // feature should operate. Each configuration consists of three parts as |
| 22 // described in detail below. | |
| 23 // | |
| 24 // There can be multiple configuration enabled at the same time. For each | |
| 25 // navigation, however, subresource filtering will be activated according to | |
| 26 // exactly one of these enabled configuration, if any. Namely, the configuration | |
| 27 // with the highest |priority| among those whose |activation_conditions| are | |
| 28 // otherwise satisfied for the navigation. | |
| 29 // | |
| 30 // Even when there are multiple enabled configurations, the RulesetService is | |
| 31 // currently only capable of fetching and indexing a single |ruleset_flavor|, | |
| 32 // which will be used for all navigations with subresource filtering activated, | |
| 33 // regardless of which configuration prescribed filtering for that navigation. | |
| 34 // This shared ruleset flavor will be the one lexicographically greatest. | |
| 35 // | |
| 36 // Experimenters wishing to use customized rulesets therefore must ensure that | |
| 37 // they set up the experimental state so that the ruleset chosen through this | |
| 38 // mechanism is compatible with all the enabled configurations (or disable some | |
| 39 // as needed). | |
| 19 struct Configuration { | 40 struct Configuration { |
| 41 // The conditions that determine whether subresource filtering should be | |
| 42 // activated for a given main frame navigation using this configuration. | |
| 43 struct ActivationConditions { | |
| 44 // The activation scope. That is, the subset of page loads where subresource | |
| 45 // filtering should be activated according to this configuration. When set | |
| 46 // to NO_SITES, this configuration will never be active. | |
| 47 ActivationScope activation_scope = ActivationScope::NO_SITES; | |
| 48 | |
| 49 // The activation list to use when the |activation_scope| is | |
| 50 // ACTIVATION_LIST, ignored otherwise. | |
| 51 ActivationList activation_list = ActivationList::NONE; | |
| 52 | |
| 53 // The activation priority of this configuration. Used to break ties when | |
| 54 // there are multiple configurations whose activation conditions are | |
| 55 // otherwise satisfied. A greater value indicates higher priority. | |
| 56 int priority = 0; | |
| 57 }; | |
| 58 | |
| 59 // The details of how subresource filtering should operate for a given main | |
| 60 // frame navigation when it is activated using this configuration. | |
| 61 struct ActivationOptions { | |
| 62 // The maximum degree to which subresource filtering should be activated on | |
| 63 // any RenderFrame. When set to DISABLED, this configuration will cause | |
| 64 // subresource filtering to be de-activated for a navigation if this is the | |
| 65 // highest priority configuration with its activation conditions met. | |
| 66 ActivationLevel activation_level = ActivationLevel::DISABLED; | |
| 67 | |
| 68 // A number in the range [0, 1], indicating the fraction of page loads that | |
| 69 // should have extended performance measurements enabled. | |
| 70 double performance_measurement_rate = 0.0; | |
| 71 | |
| 72 // Whether notifications indicating that a subresource was disallowed should | |
| 73 // be suppressed in the UI. | |
| 74 bool should_suppress_notifications = false; | |
| 75 | |
| 76 // Whether to whitelist a site when a page loaded from that site is | |
| 77 // reloaded. | |
| 78 bool should_whitelist_site_on_reload = false; | |
| 79 }; | |
| 80 | |
| 81 // General settings that apply outside of the scope of a navigation. | |
| 82 struct GeneralSettings { | |
| 83 // The ruleset flavor to download through the component updater. The empty | |
| 84 // string indicates that the default ruleset should be used. | |
| 85 std::string ruleset_flavor; | |
| 86 }; | |
| 87 | |
| 88 // Do not forget updating operator==, operator<<, and any other necessary | |
| 89 // methods when adding new fields here! | |
| 90 | |
| 20 Configuration(); | 91 Configuration(); |
| 21 Configuration(ActivationLevel activation_level, | 92 Configuration(ActivationLevel activation_level, |
| 22 ActivationScope activation_scope, | 93 ActivationScope activation_scope, |
| 23 ActivationList activation_list = ActivationList::NONE); | 94 ActivationList activation_list = ActivationList::NONE); |
| 95 Configuration(const Configuration&); | |
| 24 Configuration(Configuration&&); | 96 Configuration(Configuration&&); |
| 25 ~Configuration(); | 97 ~Configuration(); |
| 98 Configuration& operator=(const Configuration&); | |
| 26 Configuration& operator=(Configuration&&); | 99 Configuration& operator=(Configuration&&); |
| 27 | 100 |
| 28 // The maximum degree to which subresource filtering should be activated on | 101 bool operator==(const Configuration& rhs) const; |
| 29 // any RenderFrame. This will be ActivationLevel::DISABLED unless the feature | 102 bool operator!=(const Configuration& rhs) const; |
| 30 // is enabled and variation parameters prescribe a higher activation level. | |
| 31 ActivationLevel activation_level = ActivationLevel::DISABLED; | |
| 32 | 103 |
| 33 // The activation scope. That is, the subset of page loads where subresource | 104 // Factory methods for preset configurations. |
| 34 // filtering should be activated. This will be ActivationScope::NO_SITES | 105 // |
| 35 // unless the feature is =enabled and variation parameters prescribe a wider | 106 // To add a new preset: |
| 36 // activation scope. | 107 // 1.) Define a named factory method here. |
| 37 ActivationScope activation_scope = ActivationScope::NO_SITES; | 108 // 2.) Define a name for the configuration to be used in variation params. |
| 109 // 3.) Register it into |kAvailablePresetConfigurations| in the .cc file. | |
| 110 // 4.) Update unittests to cover the new preset. | |
| 111 static Configuration MakePresetForLiveRunOnPhishingSites(); | |
| 112 static Configuration MakePresetForPerformanceTestingDryRunOnAllSites(); | |
| 38 | 113 |
| 39 // The activation list to use when the |activation_scope| is ACTIVATION_LIST. | 114 ActivationConditions activation_conditions; |
| 40 // This will be ActivationList::NONE unless variation parameters prescribe a | 115 ActivationOptions activation_options; |
| 41 // recognized list. | 116 GeneralSettings general_settings; |
| 42 ActivationList activation_list = ActivationList::NONE; | |
| 43 | |
| 44 // A number in the range [0, 1], indicating the fraction of page loads that | |
| 45 // should have extended performance measurements enabled. The rate will | |
| 46 // be 0 unless a greater frequency is specified by variation parameters. | |
| 47 double performance_measurement_rate = 0.0; | |
| 48 | |
| 49 // Whether notifications indicating that a subresource was disallowed should | |
| 50 // be suppressed in the UI. | |
| 51 bool should_suppress_notifications = false; | |
| 52 | |
| 53 // The ruleset flavor to download through the component updater. This or the | |
| 54 // empty string if the default ruleset should be used. | |
| 55 std::string ruleset_flavor; | |
| 56 | |
| 57 // Whether to whitelist a site when a page loaded from that site is reloaded. | |
| 58 bool should_whitelist_site_on_reload = false; | |
| 59 }; | 117 }; |
| 60 | 118 |
| 61 // TODO(engedy): Make this an actual list once all call sites are prepared to | 119 // For logging in tests. |
| 62 // handle multiple simultaneous configurations. | 120 std::ostream& operator<<(std::ostream& os, const Configuration& config); |
| 121 | |
| 122 // Thread-safe, ref-counted wrapper around an immutable list of configurations. | |
| 63 class ConfigurationList : public base::RefCountedThreadSafe<ConfigurationList> { | 123 class ConfigurationList : public base::RefCountedThreadSafe<ConfigurationList> { |
| 64 public: | 124 public: |
| 65 explicit ConfigurationList(Configuration config); | 125 explicit ConfigurationList(std::vector<Configuration> configs); |
| 66 | 126 |
| 67 const Configuration& the_one_and_only() const { return config_; } | 127 // Returns the lexicographically greatest flavor string that is prescribed by |
| 128 // any of the configurations. | |
| 129 const std::string& lexicographically_greatest_ruleset_flavor() const { | |
| 130 return lexicographically_greatest_ruleset_flavor_; | |
| 131 } | |
| 132 | |
| 133 // Retrieves the configurations pre-sorted in decreasing order of their | |
| 134 // |activation_condition.priority|. | |
| 135 const std::vector<Configuration>& configs_by_decreasing_priority() const { | |
| 136 return configs_by_decreasing_priority_; | |
| 137 } | |
| 68 | 138 |
| 69 private: | 139 private: |
| 70 friend class base::RefCountedThreadSafe<ConfigurationList>; | 140 friend class base::RefCountedThreadSafe<ConfigurationList>; |
| 71 ~ConfigurationList(); | 141 ~ConfigurationList(); |
| 72 | 142 |
| 73 const Configuration config_; | 143 const std::string lexicographically_greatest_ruleset_flavor_; |
|
pkalinnikov
2017/05/08 11:48:43
optional nitty nit: This one is a copy of one of t
engedy
2017/05/08 14:40:20
Actually, from the perspective of the caller, it h
| |
| 144 const std::vector<Configuration> configs_by_decreasing_priority_; | |
| 74 | 145 |
| 75 DISALLOW_COPY_AND_ASSIGN(ConfigurationList); | 146 DISALLOW_COPY_AND_ASSIGN(ConfigurationList); |
| 76 }; | 147 }; |
| 77 | 148 |
| 78 // Retrieves all currently enabled subresource filtering configurations. The | 149 // Retrieves all currently enabled subresource filtering configurations. The |
| 79 // configurations are parsed on first access and then the result is cached. | 150 // configurations are parsed on first access and then the result is cached. |
| 80 // | 151 // |
| 81 // In tests, however, the config may be altered in-between navigations, so | 152 // In tests, however, the config may be changed in-between navigations, so |
| 82 // callers should not hold on to the result for long. | 153 // callers should not hold on to the result for long. |
| 83 scoped_refptr<ConfigurationList> GetActiveConfigurations(); | 154 scoped_refptr<ConfigurationList> GetEnabledConfigurations(); |
| 84 | 155 |
| 85 namespace testing { | 156 namespace testing { |
| 86 | 157 |
| 87 // Returns the currently cached active ConfigurationList, if any, and replaces | 158 // Returns the currently cached enabled ConfigurationList, if any, and replaces |
| 88 // it with |new_configs|, which may be nullptr to clear the cache. | 159 // it with |new_configs|, which may be nullptr to clear the cache. |
| 89 scoped_refptr<ConfigurationList> GetAndSetActivateConfigurations( | 160 scoped_refptr<ConfigurationList> GetAndSetActivateConfigurations( |
| 90 scoped_refptr<ConfigurationList> new_configs); | 161 scoped_refptr<ConfigurationList> new_configs); |
| 91 | 162 |
| 92 } // namespace testing | 163 } // namespace testing |
| 93 | 164 |
| 94 // Feature and variation parameter definitions ------------------------------- | 165 // Feature and variation parameter definitions ------------------------------- |
| 95 | 166 |
| 96 // The master toggle to enable/disable the Safe Browsing Subresource Filter. | 167 // The master toggle to enable/disable the Safe Browsing Subresource Filter. |
| 97 extern const base::Feature kSafeBrowsingSubresourceFilter; | 168 extern const base::Feature kSafeBrowsingSubresourceFilter; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 108 extern const char kActivationScopeParameterName[]; | 179 extern const char kActivationScopeParameterName[]; |
| 109 extern const char kActivationScopeAllSites[]; | 180 extern const char kActivationScopeAllSites[]; |
| 110 extern const char kActivationScopeActivationList[]; | 181 extern const char kActivationScopeActivationList[]; |
| 111 extern const char kActivationScopeNoSites[]; | 182 extern const char kActivationScopeNoSites[]; |
| 112 | 183 |
| 113 extern const char kActivationListsParameterName[]; | 184 extern const char kActivationListsParameterName[]; |
| 114 extern const char kActivationListSocialEngineeringAdsInterstitial[]; | 185 extern const char kActivationListSocialEngineeringAdsInterstitial[]; |
| 115 extern const char kActivationListPhishingInterstitial[]; | 186 extern const char kActivationListPhishingInterstitial[]; |
| 116 extern const char kActivationListSubresourceFilter[]; | 187 extern const char kActivationListSubresourceFilter[]; |
| 117 | 188 |
| 118 extern const char kRulesetFlavorParameterName[]; | 189 extern const char kActivationPriorityParameterName[]; |
| 119 | 190 |
| 120 extern const char kPerformanceMeasurementRateParameterName[]; | 191 extern const char kPerformanceMeasurementRateParameterName[]; |
| 121 | 192 |
| 122 extern const char kSuppressNotificationsParameterName[]; | 193 extern const char kSuppressNotificationsParameterName[]; |
| 123 | 194 |
| 124 extern const char kWhitelistSiteOnReloadParameterName[]; | 195 extern const char kWhitelistSiteOnReloadParameterName[]; |
| 125 | 196 |
| 197 extern const char kRulesetFlavorParameterName[]; | |
| 198 | |
| 199 extern const char kEnablePresetsParameterName[]; | |
| 200 extern const char kDisablePresetsParameterName[]; | |
| 201 extern const char kPresetLiveRunOnPhishingSites[]; | |
| 202 extern const char kPresetPerformanceTestingDryRunOnAllSites[]; | |
| 203 | |
| 126 } // namespace subresource_filter | 204 } // namespace subresource_filter |
| 127 | 205 |
| 128 #endif // COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_SUBRESOURCE_FILTER_FEATURE S_H_ | 206 #endif // COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_SUBRESOURCE_FILTER_FEATURE S_H_ |
| OLD | NEW |