Index: components/subresource_filter/content/browser/content_subresource_filter_driver_factory.cc |
diff --git a/components/subresource_filter/content/browser/content_subresource_filter_driver_factory.cc b/components/subresource_filter/content/browser/content_subresource_filter_driver_factory.cc |
index 90c0cb1883d1e5745533ad1ee9340bd526de8d57..926f4c25ceb1d41da3cb8f77409011ffdf9ec0a4 100644 |
--- a/components/subresource_filter/content/browser/content_subresource_filter_driver_factory.cc |
+++ b/components/subresource_filter/content/browser/content_subresource_filter_driver_factory.cc |
@@ -91,10 +91,7 @@ ContentSubresourceFilterDriverFactory::ContentSubresourceFilterDriverFactory( |
base::MakeUnique<ContentSubresourceFilterThrottleManager>( |
this, |
client_->GetRulesetDealer(), |
- web_contents)), |
- activation_level_(ActivationLevel::DISABLED), |
- activation_decision_(ActivationDecision::UNKNOWN), |
- measure_performance_(false) {} |
+ web_contents)) {} |
ContentSubresourceFilterDriverFactory:: |
~ContentSubresourceFilterDriverFactory() {} |
@@ -109,30 +106,47 @@ void ContentSubresourceFilterDriverFactory:: |
url, GetListForThreatTypeAndMetadata(threat_type, threat_type_metadata)); |
} |
+void ContentSubresourceFilterDriverFactory:: |
+ ComputeActivationDecisionForMainFrameNavigation( |
+ content::NavigationHandle* navigation_handle) { |
+ activation_decision_ = ActivationDecision::ACTIVATION_DISABLED; |
+ const auto active_configs = GetActiveConfigurations(); |
+ for (const auto& config : active_configs->ordered_configs()) { |
+ ActivationDecision decision = |
+ ComputePerConfigActivationDecisionForMainFrameNavigation( |
+ navigation_handle, config); |
+ if (decision != ActivationDecision::ACTIVATION_DISABLED) |
+ activation_decision_ = decision; |
+ if (activation_decision_ == ActivationDecision::ACTIVATED) { |
+ configuration_owner_ = active_configs; |
+ configuration_ = &config; |
+ break; |
+ } |
+ } |
+} |
+ |
ContentSubresourceFilterDriverFactory::ActivationDecision |
ContentSubresourceFilterDriverFactory:: |
- ComputeActivationDecisionForMainFrameNavigation( |
- content::NavigationHandle* navigation_handle) const { |
+ ComputePerConfigActivationDecisionForMainFrameNavigation( |
+ content::NavigationHandle* navigation_handle, |
+ const Configuration& configuration) const { |
const GURL& url(navigation_handle->GetURL()); |
- |
- const auto configurations = GetActiveConfigurations(); |
- if (configurations->the_one_and_only().activation_level == |
- ActivationLevel::DISABLED) |
+ if (configuration.activation_level == ActivationLevel::DISABLED) |
return ActivationDecision::ACTIVATION_DISABLED; |
- if (configurations->the_one_and_only().activation_scope == |
- ActivationScope::NO_SITES) |
+ if (configuration.activation_scope == ActivationScope::NO_SITES) |
return ActivationDecision::ACTIVATION_DISABLED; |
if (!url.SchemeIsHTTPOrHTTPS()) |
return ActivationDecision::UNSUPPORTED_SCHEME; |
+ |
// TODO(csharrison): The throttle manager also performs this check. Remove |
// this one when the activation decision is sent directly to the throttle |
// manager. |
if (client_->ShouldSuppressActivation(navigation_handle)) |
return ActivationDecision::URL_WHITELISTED; |
- switch (configurations->the_one_and_only().activation_scope) { |
+ switch (configuration.activation_scope) { |
case ActivationScope::ALL_SITES: |
return ActivationDecision::ACTIVATED; |
case ActivationScope::ACTIVATION_LIST: { |
@@ -140,11 +154,10 @@ ContentSubresourceFilterDriverFactory:: |
// AddActivationListMatch to ensure the activation list only has relevant |
// entries. |
DCHECK(url.SchemeIsHTTPOrHTTPS() || |
- !DidURLMatchActivationList( |
- url, configurations->the_one_and_only().activation_list)); |
- bool should_activate = DidURLMatchActivationList( |
- url, configurations->the_one_and_only().activation_list); |
- if (configurations->the_one_and_only().activation_list == |
+ !DidURLMatchActivationList(url, configuration.activation_list)); |
+ bool should_activate = |
+ DidURLMatchActivationList(url, configuration.activation_list); |
+ if (configuration.activation_list == |
ActivationList::PHISHING_INTERSTITIAL) { |
// Handling special case, where activation on the phishing sites also |
// mean the activation on the sites with social engineering metadata. |
@@ -189,37 +202,37 @@ void ContentSubresourceFilterDriverFactory::WillProcessResponse( |
RecordRedirectChainMatchPattern(); |
- const auto configurations = GetActiveConfigurations(); |
- if (configurations->the_one_and_only().should_whitelist_site_on_reload && |
+ ComputeActivationDecisionForMainFrameNavigation(navigation_handle); |
+ DCHECK(activation_decision_ != ActivationDecision::UNKNOWN); |
+ |
+ if (configuration_ && configuration_->should_whitelist_site_on_reload && |
NavigationIsPageReload(url, referrer, transition)) { |
// Whitelist this host for the current as well as subsequent navigations. |
+ activation_decision_ = ActivationDecision::URL_WHITELISTED; |
client_->WhitelistInCurrentWebContents(url); |
} |
- activation_decision_ = |
- ComputeActivationDecisionForMainFrameNavigation(navigation_handle); |
- DCHECK(activation_decision_ != ActivationDecision::UNKNOWN); |
if (activation_decision_ != ActivationDecision::ACTIVATED) { |
ResetActivationState(); |
return; |
} |
- activation_level_ = configurations->the_one_and_only().activation_level; |
+ DCHECK(configuration_); |
measure_performance_ = |
- activation_level_ != ActivationLevel::DISABLED && |
+ configuration_->activation_level != ActivationLevel::DISABLED && |
ShouldMeasurePerformanceForPageLoad( |
- configurations->the_one_and_only().performance_measurement_rate); |
- ActivationState state = ActivationState(activation_level_); |
+ configuration_->performance_measurement_rate); |
+ ActivationState state = ActivationState(configuration_->activation_level); |
state.measure_performance = measure_performance_; |
throttle_manager_->NotifyPageActivationComputed(navigation_handle, state); |
} |
void ContentSubresourceFilterDriverFactory::OnFirstSubresourceLoadDisallowed() { |
- const auto configurations = GetActiveConfigurations(); |
- if (configurations->the_one_and_only().should_suppress_notifications) |
+ if (!configuration_) |
return; |
- |
- client_->ToggleNotificationVisibility(activation_level_ == |
+ if (configuration_->should_suppress_notifications) |
+ return; |
+ client_->ToggleNotificationVisibility(configuration_->activation_level == |
ActivationLevel::ENABLED); |
} |
@@ -231,7 +244,8 @@ bool ContentSubresourceFilterDriverFactory::ShouldSuppressActivation( |
void ContentSubresourceFilterDriverFactory::ResetActivationState() { |
navigation_chain_.clear(); |
activation_list_matches_.clear(); |
- activation_level_ = ActivationLevel::DISABLED; |
+ configuration_ = nullptr; |
+ configuration_owner_ = nullptr; |
measure_performance_ = false; |
} |