Commit da7df0bc authored by Colin Blundell's avatar Colin Blundell Committed by Chromium LUCI CQ

[Subresource Filter] Move activation adjustment code to component

This CL moves the implementation of
ChromeSubresourceFilterClient::OnPageActivationDecision() to
ProfileInteractionManager, with the former now just calling through to
the latter. In subsequent work we will eliminate the callthrough to the
client altogether, thus having this logic be shared with WebLayer. In
this CL, however, there is no behavioral change.

Bug: 1116095
Change-Id: I75d36824906a9869c177481a8c7f844f2f813064
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2597314
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: default avatarCharlie Harrison <csharrison@chromium.org>
Cr-Commit-Position: refs/heads/master@{#839452}
parent b264ce95
......@@ -103,38 +103,11 @@ ChromeSubresourceFilterClient::OnPageActivationComputed(
content::NavigationHandle* navigation_handle,
subresource_filter::mojom::ActivationLevel initial_activation_level,
subresource_filter::ActivationDecision* decision) {
DCHECK(navigation_handle->IsInMainFrame());
subresource_filter::mojom::ActivationLevel effective_activation_level =
initial_activation_level;
if (profile_context_->ads_intervention_manager()->ShouldActivate(
navigation_handle)) {
effective_activation_level =
subresource_filter::mojom::ActivationLevel::kEnabled;
*decision = subresource_filter::ActivationDecision::ACTIVATED;
}
const GURL& url(navigation_handle->GetURL());
if (url.SchemeIsHTTPOrHTTPS()) {
profile_context_->settings_manager()->SetSiteMetadataBasedOnActivation(
url,
effective_activation_level ==
subresource_filter::mojom::ActivationLevel::kEnabled,
subresource_filter::SubresourceFilterContentSettingsManager::
ActivationSource::kSafeBrowsing);
}
if (profile_context_->settings_manager()->GetSitePermission(url) ==
CONTENT_SETTING_ALLOW) {
if (effective_activation_level ==
subresource_filter::mojom::ActivationLevel::kEnabled) {
*decision = subresource_filter::ActivationDecision::URL_ALLOWLISTED;
}
return subresource_filter::mojom::ActivationLevel::kDisabled;
}
return effective_activation_level;
// TODO(crbug.com/1116095): Once SafeBrowsingActivationThrottle knows about
// ProfileInteractionManager, it can invoke ProfileInteractionManager directly
// and SubresourceFilterClient::OnPageActivationComputed() can be eliminated.
return profile_interaction_manager_->OnPageActivationComputed(
navigation_handle, initial_activation_level, decision);
}
void ChromeSubresourceFilterClient::OnAdsViolationTriggered(
......
......@@ -83,4 +83,37 @@ void ProfileInteractionManager::OnAdsViolationTriggered(
ads_violation_triggered_for_last_committed_navigation_ = true;
}
mojom::ActivationLevel ProfileInteractionManager::OnPageActivationComputed(
content::NavigationHandle* navigation_handle,
mojom::ActivationLevel initial_activation_level,
ActivationDecision* decision) {
DCHECK(navigation_handle->IsInMainFrame());
mojom::ActivationLevel effective_activation_level = initial_activation_level;
if (profile_context_->ads_intervention_manager()->ShouldActivate(
navigation_handle)) {
effective_activation_level = mojom::ActivationLevel::kEnabled;
*decision = ActivationDecision::ACTIVATED;
}
const GURL& url(navigation_handle->GetURL());
if (url.SchemeIsHTTPOrHTTPS()) {
profile_context_->settings_manager()->SetSiteMetadataBasedOnActivation(
url, effective_activation_level == mojom::ActivationLevel::kEnabled,
SubresourceFilterContentSettingsManager::ActivationSource::
kSafeBrowsing);
}
if (profile_context_->settings_manager()->GetSitePermission(url) ==
CONTENT_SETTING_ALLOW) {
if (effective_activation_level == mojom::ActivationLevel::kEnabled) {
*decision = ActivationDecision::URL_ALLOWLISTED;
}
return mojom::ActivationLevel::kDisabled;
}
return effective_activation_level;
}
} // namespace subresource_filter
......@@ -5,6 +5,7 @@
#ifndef COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_PROFILE_INTERACTION_MANAGER_H_
#define COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_PROFILE_INTERACTION_MANAGER_H_
#include "components/subresource_filter/core/common/activation_decision.h"
#include "components/subresource_filter/core/mojom/subresource_filter.mojom.h"
#include "content/public/browser/web_contents_observer.h"
......@@ -42,6 +43,20 @@ class ProfileInteractionManager : public content::WebContentsObserver {
void OnAdsViolationTriggered(content::RenderFrameHost* rfh,
mojom::AdsViolation triggered_violation);
// Called when the initial activation decision has been computed by the
// safe browsing activation throttle. This object then applies any adjustments
// based on relevant state of the Profile (e.g., content settings). Returns
// the effective activation for this navigation.
//
// Note: |decision| is guaranteed to be non-nullptr, and can be modified by
// this method if any decision changes.
//
// Precondition: The navigation must be a main frame navigation.
mojom::ActivationLevel OnPageActivationComputed(
content::NavigationHandle* navigation_handle,
mojom::ActivationLevel initial_activation_level,
ActivationDecision* decision);
private:
// Unowned and must outlive this object.
SubresourceFilterProfileContext* profile_context_ = nullptr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment