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

[Subresource Filter] Introduce ProfileInteractionManager

Most of what ChromeSubresourceFilterClient is currently doing is
managing interaction between the per-navigation/per-tab objects (i.e.,
the throttles and throttle manager) and the now-componentized
per-profile objects (e.g., content settings). All of this management
is relevant for WebLayer as well.

While I it would be possible to pull all of this code directly into the
ThrottleManager, it lies outside the current core responsibilities of
ThrottleManager and risks making that class too fat. This CL introduces
a new ProfileInteractionManager class that lives next to the
ThrottleManager. All of the places within the component that currently
call into the client will call into the profile interaction manager
class instead (with the exception of the very few methods that are
actually on the client, e.g. actually showing the infobar). As a start,
this CL moves the implementation of OnReloadRequested() into
ProfileInteractionManager.

With respect to unittesting of the new class, my suspicion is that most
of the //chrome-level unittests are effectively going to end up being
tests of ProfileInteractionManager and will be suitable for
componentization as such once the dust has settled. During the process,
test coverage will remain via those //chrome-level unittests as well as
//chrome's browsertests.

Bug: 1116095
Change-Id: Id64ca19cd1844cdc76b959679f5ad6ca0808f2a6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2575077
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: default avatarCharlie Harrison <csharrison@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835649}
parent b6ac3575
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "components/safe_browsing/core/db/database_manager.h" #include "components/safe_browsing/core/db/database_manager.h"
#include "components/subresource_filter/content/browser/ads_intervention_manager.h" #include "components/subresource_filter/content/browser/ads_intervention_manager.h"
#include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h" #include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h"
#include "components/subresource_filter/content/browser/profile_interaction_manager.h"
#include "components/subresource_filter/content/browser/ruleset_service.h" #include "components/subresource_filter/content/browser/ruleset_service.h"
#include "components/subresource_filter/content/browser/subresource_filter_content_settings_manager.h" #include "components/subresource_filter/content/browser/subresource_filter_content_settings_manager.h"
#include "components/subresource_filter/content/browser/subresource_filter_profile_context.h" #include "components/subresource_filter/content/browser/subresource_filter_profile_context.h"
...@@ -43,6 +44,9 @@ ChromeSubresourceFilterClient::ChromeSubresourceFilterClient( ...@@ -43,6 +44,9 @@ ChromeSubresourceFilterClient::ChromeSubresourceFilterClient(
DCHECK(web_contents); DCHECK(web_contents);
profile_context_ = SubresourceFilterProfileContextFactory::GetForProfile( profile_context_ = SubresourceFilterProfileContextFactory::GetForProfile(
Profile::FromBrowserContext(web_contents->GetBrowserContext())); Profile::FromBrowserContext(web_contents->GetBrowserContext()));
profile_interaction_manager_ =
std::make_unique<subresource_filter::ProfileInteractionManager>(
web_contents, profile_context_);
} }
ChromeSubresourceFilterClient::~ChromeSubresourceFilterClient() = default; ChromeSubresourceFilterClient::~ChromeSubresourceFilterClient() = default;
...@@ -85,13 +89,10 @@ void ChromeSubresourceFilterClient::DidFinishNavigation( ...@@ -85,13 +89,10 @@ void ChromeSubresourceFilterClient::DidFinishNavigation(
void ChromeSubresourceFilterClient::OnReloadRequested() { void ChromeSubresourceFilterClient::OnReloadRequested() {
// TODO(crbug.com/1116095): Once ContentSubresourceFilterThrottleManager knows // TODO(crbug.com/1116095): Once ContentSubresourceFilterThrottleManager knows
// about content settings, this method can move entirely into // about ProfileInteractionManager, this method can move entirely into
// ContentSubresourceFilterThrottleManager::OnReloadRequested() and // ContentSubresourceFilterThrottleManager::OnReloadRequested() and
// SubresourceFilterClient::OnReloadRequested() can be eliminated. // SubresourceFilterClient::OnReloadRequested() can be eliminated.
subresource_filter::ContentSubresourceFilterThrottleManager::LogAction( profile_interaction_manager_->OnReloadRequested();
subresource_filter::SubresourceFilterAction::kAllowlistedSite);
AllowlistByContentSettings(web_contents()->GetLastCommittedURL());
web_contents()->GetController().Reload(content::ReloadType::NORMAL, true);
} }
void ChromeSubresourceFilterClient::ShowNotification() { void ChromeSubresourceFilterClient::ShowNotification() {
...@@ -191,11 +192,6 @@ void ChromeSubresourceFilterClient::OnAdsViolationTriggered( ...@@ -191,11 +192,6 @@ void ChromeSubresourceFilterClient::OnAdsViolationTriggered(
ads_violation_triggered_for_last_committed_navigation_ = true; ads_violation_triggered_for_last_committed_navigation_ = true;
} }
void ChromeSubresourceFilterClient::AllowlistByContentSettings(
const GURL& top_level_url) {
profile_context_->settings_manager()->AllowlistSite(top_level_url);
}
const scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> const scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager>
ChromeSubresourceFilterClient::GetSafeBrowsingDatabaseManager() { ChromeSubresourceFilterClient::GetSafeBrowsingDatabaseManager() {
safe_browsing::SafeBrowsingService* safe_browsing_service = safe_browsing::SafeBrowsingService* safe_browsing_service =
......
...@@ -22,6 +22,7 @@ class WebContents; ...@@ -22,6 +22,7 @@ class WebContents;
namespace subresource_filter { namespace subresource_filter {
class ContentSubresourceFilterThrottleManager; class ContentSubresourceFilterThrottleManager;
class ProfileInteractionManager;
class SubresourceFilterProfileContext; class SubresourceFilterProfileContext;
} // namespace subresource_filter } // namespace subresource_filter
...@@ -69,7 +70,6 @@ class ChromeSubresourceFilterClient ...@@ -69,7 +70,6 @@ class ChromeSubresourceFilterClient
void ToggleForceActivationInCurrentWebContents(bool force_activation); void ToggleForceActivationInCurrentWebContents(bool force_activation);
private: private:
void AllowlistByContentSettings(const GURL& url);
void ShowUI(const GURL& url); void ShowUI(const GURL& url);
std::unique_ptr<subresource_filter::ContentSubresourceFilterThrottleManager> std::unique_ptr<subresource_filter::ContentSubresourceFilterThrottleManager>
...@@ -79,6 +79,9 @@ class ChromeSubresourceFilterClient ...@@ -79,6 +79,9 @@ class ChromeSubresourceFilterClient
subresource_filter::SubresourceFilterProfileContext* profile_context_ = subresource_filter::SubresourceFilterProfileContext* profile_context_ =
nullptr; nullptr;
std::unique_ptr<subresource_filter::ProfileInteractionManager>
profile_interaction_manager_;
bool ads_violation_triggered_for_last_committed_navigation_ = false; bool ads_violation_triggered_for_last_committed_navigation_ = false;
// Corresponds to a devtools command which triggers filtering on all page // Corresponds to a devtools command which triggers filtering on all page
......
...@@ -18,6 +18,8 @@ static_library("browser") { ...@@ -18,6 +18,8 @@ static_library("browser") {
"navigation_console_logger.h", "navigation_console_logger.h",
"page_load_statistics.cc", "page_load_statistics.cc",
"page_load_statistics.h", "page_load_statistics.h",
"profile_interaction_manager.cc",
"profile_interaction_manager.h",
"ruleset_publisher.h", "ruleset_publisher.h",
"ruleset_publisher_impl.cc", "ruleset_publisher_impl.cc",
"ruleset_publisher_impl.h", "ruleset_publisher_impl.h",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/subresource_filter/content/browser/profile_interaction_manager.h"
#include "base/logging.h"
#include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h"
#include "components/subresource_filter/content/browser/subresource_filter_content_settings_manager.h"
#include "components/subresource_filter/content/browser/subresource_filter_profile_context.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/web_contents.h"
namespace subresource_filter {
ProfileInteractionManager::ProfileInteractionManager(
content::WebContents* web_contents,
SubresourceFilterProfileContext* profile_context)
: content::WebContentsObserver(web_contents),
profile_context_(profile_context) {
DCHECK(web_contents);
}
ProfileInteractionManager::~ProfileInteractionManager() = default;
void ProfileInteractionManager::OnReloadRequested() {
ContentSubresourceFilterThrottleManager::LogAction(
SubresourceFilterAction::kAllowlistedSite);
profile_context_->settings_manager()->AllowlistSite(
web_contents()->GetLastCommittedURL());
web_contents()->GetController().Reload(content::ReloadType::NORMAL, true);
}
} // namespace subresource_filter
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_PROFILE_INTERACTION_MANAGER_H_
#define COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_PROFILE_INTERACTION_MANAGER_H_
#include "content/public/browser/web_contents_observer.h"
namespace content {
class WebContents;
} // namespace content
namespace subresource_filter {
class SubresourceFilterProfileContext;
// Class that manages interaction between interaction between the
// per-navigation/per-tab subresource filter objects (i.e., the throttles and
// throttle manager) and the per-profile objects (e.g., content settings).
class ProfileInteractionManager : public content::WebContentsObserver {
public:
ProfileInteractionManager(content::WebContents* web_contents,
SubresourceFilterProfileContext* profile_context);
~ProfileInteractionManager() override;
ProfileInteractionManager(const ProfileInteractionManager&) = delete;
ProfileInteractionManager& operator=(const ProfileInteractionManager&) =
delete;
// Invoked when the user has requested a reload of a page with blocked ads
// (e.g., via an infobar).
void OnReloadRequested();
private:
// Unowned and must outlive this object.
SubresourceFilterProfileContext* profile_context_ = nullptr;
};
} // namespace subresource_filter
#endif // COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_PROFILE_INTERACTION_MANAGER_H_
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