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

[Subresource Filter] Add content settings-based adjustment to WebLayer

This CL incorporates Chrome's adjustment of subresource filter page
activation decisions based on content settings within WebLayer. To do
so, we have the shared SubresourceFilterSafeBrowsingActivationThrottle
directly invoke the logic in question rather than having
ChromeSubresourceFilterClient do so. That change necessitates some
others, also made in this CL:
- WebLayer brings up ProfileInteractionManager.
- SubresourceFilterClient provides an accessor for
  ProfileInteractionManager.
- SubresourceFilterSafeBrowsingActivationThrottle calls the adjustment
  logic via a new Delegate interface rather than doing so via
  SubresourceFilterClient. This interface is implemented by
  ProfileInteractionManager in production while allowing for porting of
  tests that provide custom (or nil) stub logic.

We also add browsertests of this interaction in //weblayer.

Note that this CL does not do any incorporation of the relevant *UI*
for content/site settings of ad blocking in WebLayer; that will be
followup work.

This CL is a reland. The original CL was reverted due to the introduced
tests failing on Win7. On inspection this turns out to be the issue
tracked in crbug.com/1152429. I'm continuing to investigate that issue,
but it's slow going so far. In the meantime this CL disables the
newly-added tests on Windows with a reference to that bug (see diff
between PS1, which is the original CL, and PS2).

Bug: 1116095
Change-Id: I8dc8f3a2e08a58e91050cf9b484685ee4982f16f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2627166Reviewed-by: default avatarCharlie Harrison <csharrison@chromium.org>
Commit-Queue: Colin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843619}
parent 07eded85
......@@ -29,7 +29,6 @@
#include "components/subresource_filter/core/common/activation_decision.h"
#include "components/subresource_filter/core/common/activation_scope.h"
#include "components/subresource_filter/core/mojom/subresource_filter.mojom.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
......@@ -98,18 +97,6 @@ void ChromeSubresourceFilterClient::ShowNotification() {
}
}
subresource_filter::mojom::ActivationLevel
ChromeSubresourceFilterClient::OnPageActivationComputed(
content::NavigationHandle* navigation_handle,
subresource_filter::mojom::ActivationLevel initial_activation_level,
subresource_filter::ActivationDecision* decision) {
// 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(
content::RenderFrameHost* rfh,
subresource_filter::mojom::AdsViolation triggered_violation) {
......@@ -129,6 +116,11 @@ ChromeSubresourceFilterClient::GetSafeBrowsingDatabaseManager() {
: nullptr;
}
subresource_filter::ProfileInteractionManager*
ChromeSubresourceFilterClient::GetProfileInteractionManager() {
return profile_interaction_manager_.get();
}
void ChromeSubresourceFilterClient::ShowUI(const GURL& url) {
#if defined(OS_ANDROID)
InfoBarService* infobar_service =
......
......@@ -15,13 +15,11 @@
class GURL;
namespace content {
class NavigationHandle;
class WebContents;
} // namespace content
namespace subresource_filter {
class ContentSubresourceFilterThrottleManager;
class ProfileInteractionManager;
class SubresourceFilterProfileContext;
} // namespace subresource_filter
......@@ -47,15 +45,13 @@ class ChromeSubresourceFilterClient
// SubresourceFilterClient:
void ShowNotification() override;
subresource_filter::mojom::ActivationLevel OnPageActivationComputed(
content::NavigationHandle* navigation_handle,
subresource_filter::mojom::ActivationLevel initial_activation_level,
subresource_filter::ActivationDecision* decision) override;
void OnAdsViolationTriggered(
content::RenderFrameHost* rfh,
subresource_filter::mojom::AdsViolation triggered_violation) override;
const scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager>
GetSafeBrowsingDatabaseManager() override;
subresource_filter::ProfileInteractionManager* GetProfileInteractionManager()
override;
void OnReloadRequested() override;
private:
......
......@@ -22,7 +22,6 @@
#include "components/content_settings/browser/test_page_specific_content_settings_delegate.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/subresource_filter/content/browser/fake_safe_browsing_database_manager.h"
#include "components/subresource_filter/content/browser/subresource_filter_client.h"
#include "components/subresource_filter/content/browser/subresource_filter_observer_manager.h"
#include "components/subresource_filter/content/browser/subresource_filter_safe_browsing_activation_throttle.h"
#include "components/subresource_filter/content/browser/subresource_filter_safe_browsing_client.h"
......@@ -48,31 +47,13 @@ const char kNumBlockedHistogram[] =
"ContentSettings.Popups.StrongBlocker.NumBlocked";
class SafeBrowsingTriggeredPopupBlockerTest
: public content::RenderViewHostTestHarness,
public subresource_filter::SubresourceFilterClient {
: public content::RenderViewHostTestHarness {
public:
SafeBrowsingTriggeredPopupBlockerTest() = default;
~SafeBrowsingTriggeredPopupBlockerTest() override {
settings_map_->ShutdownOnUIThread();
}
// subresource_filter::SubresourceFilterClient:
void ShowNotification() override {}
subresource_filter::mojom::ActivationLevel OnPageActivationComputed(
content::NavigationHandle* navigation_handle,
subresource_filter::mojom::ActivationLevel initial_activation_level,
subresource_filter::ActivationDecision* decision) override {
return initial_activation_level;
}
void OnAdsViolationTriggered(
content::RenderFrameHost*,
subresource_filter::mojom::AdsViolation) override {}
const scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager>
GetSafeBrowsingDatabaseManager() override {
return nullptr;
}
void OnReloadRequested() override {}
// content::RenderViewHostTestHarness:
void SetUp() override {
content::RenderViewHostTestHarness::SetUp();
......@@ -161,7 +142,7 @@ class SafeBrowsingTriggeredPopupBlockerTest
content::NavigationHandle* handle) {
return std::make_unique<
subresource_filter::SubresourceFilterSafeBrowsingActivationThrottle>(
handle, this, content::GetIOThreadTaskRunner({}),
handle, /*delegate=*/nullptr, content::GetIOThreadTaskRunner({}),
fake_safe_browsing_database_);
}
......
......@@ -18,6 +18,7 @@
#include "components/subresource_filter/content/browser/activation_state_computing_navigation_throttle.h"
#include "components/subresource_filter/content/browser/async_document_subresource_filter.h"
#include "components/subresource_filter/content/browser/page_load_statistics.h"
#include "components/subresource_filter/content/browser/profile_interaction_manager.h"
#include "components/subresource_filter/content/browser/subresource_filter_client.h"
#include "components/subresource_filter/content/browser/subresource_filter_safe_browsing_activation_throttle.h"
#include "components/subresource_filter/content/common/subresource_filter_messages.h"
......@@ -438,7 +439,7 @@ void ContentSubresourceFilterThrottleManager::MaybeAppendNavigationThrottles(
client_->GetSafeBrowsingDatabaseManager()) {
throttles->push_back(
std::make_unique<SubresourceFilterSafeBrowsingActivationThrottle>(
navigation_handle, client_.get(),
navigation_handle, client_->GetProfileInteractionManager(),
content::GetIOThreadTaskRunner({}),
client_->GetSafeBrowsingDatabaseManager()));
}
......
......@@ -183,12 +183,6 @@ class TestSubresourceFilterClient : public SubresourceFilterClient {
// SubresourceFilterClient:
void ShowNotification() override { ++disallowed_notification_count_; }
mojom::ActivationLevel OnPageActivationComputed(
content::NavigationHandle* navigation_handle,
mojom::ActivationLevel effective_activation_level,
ActivationDecision* decision) override {
return effective_activation_level;
}
void OnAdsViolationTriggered(
content::RenderFrameHost* rfh,
mojom::AdsViolation triggered_violation) override {}
......@@ -196,6 +190,10 @@ class TestSubresourceFilterClient : public SubresourceFilterClient {
GetSafeBrowsingDatabaseManager() override {
return database_manager_;
}
subresource_filter::ProfileInteractionManager* GetProfileInteractionManager()
override {
return nullptr;
}
void OnReloadRequested() override {}
void CreateSafeBrowsingDatabaseManager() {
......
......@@ -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/content/browser/subresource_filter_safe_browsing_activation_throttle.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"
......@@ -21,7 +22,9 @@ 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 {
class ProfileInteractionManager
: public content::WebContentsObserver,
public SubresourceFilterSafeBrowsingActivationThrottle::Delegate {
public:
ProfileInteractionManager(content::WebContents* web_contents,
SubresourceFilterProfileContext* profile_context);
......@@ -43,19 +46,11 @@ 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.
// SubresourceFilterSafeBrowsingActivationThrottle::Delegate:
mojom::ActivationLevel OnPageActivationComputed(
content::NavigationHandle* navigation_handle,
mojom::ActivationLevel initial_activation_level,
ActivationDecision* decision);
ActivationDecision* decision) override;
private:
// Unowned and must outlive this object.
......
......@@ -6,15 +6,8 @@
#define COMPONENTS_SUBRESOURCE_FILTER_CONTENT_BROWSER_SUBRESOURCE_FILTER_CLIENT_H_
#include "base/memory/scoped_refptr.h"
#include "components/subresource_filter/content/browser/verified_ruleset_dealer.h"
#include "components/subresource_filter/core/common/activation_decision.h"
#include "components/subresource_filter/core/mojom/subresource_filter.mojom.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
namespace content {
class NavigationHandle;
} // namespace content
namespace safe_browsing {
class SafeBrowsingDatabaseManager;
......@@ -22,6 +15,8 @@ class SafeBrowsingDatabaseManager;
namespace subresource_filter {
class ProfileInteractionManager;
class SubresourceFilterClient {
public:
virtual ~SubresourceFilterClient() = default;
......@@ -30,20 +25,6 @@ class SubresourceFilterClient {
// blocked. This method will be called at most once per main-frame navigation.
virtual void ShowNotification() = 0;
// Called when the activation decision is otherwise completely computed by the
// subresource filter. At this point, the embedder still has a chance to
// alter the effective activation. Returns the effective activation for this
// navigation.
//
// Note: |decision| is guaranteed to be non-nullptr, and can be modified by
// the embedder if any decision changes.
//
// Precondition: The navigation must be a main frame navigation.
virtual mojom::ActivationLevel OnPageActivationComputed(
content::NavigationHandle* navigation_handle,
mojom::ActivationLevel initial_activation_level,
subresource_filter::ActivationDecision* decision) = 0;
// Called on the subresource filter client when an ads violation is detected.
virtual void OnAdsViolationTriggered(
content::RenderFrameHost* rfh,
......@@ -54,6 +35,14 @@ class SubresourceFilterClient {
virtual const scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager>
GetSafeBrowsingDatabaseManager() = 0;
// Returns the ProfileInteractionManager instance associated with this
// client, or null if there is no such instance.
// TODO(crbug.com/1116095): Have ContentSubresourceFilterThrottleManager
// create and own this object internally once ChromeSubresourceFilterClient no
// longer calls into it, replacing this method with a getter for
// SubresourceFilterProfileContext.
virtual ProfileInteractionManager* GetProfileInteractionManager() = 0;
// Invoked when the user has requested a reload of a page with blocked ads
// (e.g., via an infobar).
virtual void OnReloadRequested() = 0;
......
......@@ -17,7 +17,6 @@
#include "components/subresource_filter/content/browser/content_activation_list_utils.h"
#include "components/subresource_filter/content/browser/devtools_interaction_tracker.h"
#include "components/subresource_filter/content/browser/navigation_console_logger.h"
#include "components/subresource_filter/content/browser/subresource_filter_client.h"
#include "components/subresource_filter/content/browser/subresource_filter_observer_manager.h"
#include "components/subresource_filter/content/browser/subresource_filter_safe_browsing_client.h"
#include "components/subresource_filter/core/browser/subresource_filter_constants.h"
......@@ -64,7 +63,7 @@ base::Optional<RedirectPosition> GetEnforcementRedirectPosition(
SubresourceFilterSafeBrowsingActivationThrottle::
SubresourceFilterSafeBrowsingActivationThrottle(
content::NavigationHandle* handle,
SubresourceFilterClient* client,
Delegate* delegate,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager>
database_manager)
......@@ -76,7 +75,7 @@ SubresourceFilterSafeBrowsingActivationThrottle::
io_task_runner_,
base::ThreadTaskRunnerHandle::Get()),
base::OnTaskRunnerDeleter(io_task_runner_)),
client_(client) {
delegate_(delegate) {
DCHECK(handle->IsInMainFrame());
CheckCurrentUrl();
......@@ -205,9 +204,11 @@ void SubresourceFilterSafeBrowsingActivationThrottle::NotifyResult() {
activation_decision = ActivationDecision::FORCED_ACTIVATION;
}
// Let the embedder get the last word when it comes to activation level.
activation_level = client_->OnPageActivationComputed(
navigation_handle(), activation_level, &activation_decision);
// Let the delegate adjust the activation decision if present.
if (delegate_) {
activation_level = delegate_->OnPageActivationComputed(
navigation_handle(), activation_level, &activation_decision);
}
LogMetricsOnChecksComplete(selection.matched_list, activation_decision,
activation_level);
......
......@@ -26,8 +26,6 @@
namespace subresource_filter {
class SubresourceFilterClient;
// Enum representing a position in the redirect chain. These values are
// persisted to logs. Entries should not be renumbered and numeric values should
// never be reused.
......@@ -46,9 +44,32 @@ class SubresourceFilterSafeBrowsingActivationThrottle
public base::SupportsWeakPtr<
SubresourceFilterSafeBrowsingActivationThrottle> {
public:
// Interface that allows the client of this class to adjust activation
// decisions if/as desired.
class Delegate {
public:
virtual ~Delegate() = default;
// Called when the initial activation decision has been computed by the
// safe browsing activation throttle. 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.
virtual mojom::ActivationLevel OnPageActivationComputed(
content::NavigationHandle* navigation_handle,
mojom::ActivationLevel initial_activation_level,
ActivationDecision* decision) = 0;
};
// |delegate| is allowed to be null, in which case the client creating this
// throttle will not be able to adjust activation decisions made by the
// throttle.
SubresourceFilterSafeBrowsingActivationThrottle(
content::NavigationHandle* handle,
SubresourceFilterClient* client,
Delegate* delegate,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager>
database_manager);
......@@ -110,8 +131,8 @@ class SubresourceFilterSafeBrowsingActivationThrottle
base::OnTaskRunnerDeleter>
database_client_;
// Must outlive this class.
SubresourceFilterClient* client_;
// May be null. If non-null, must outlive this class.
Delegate* delegate_;
// Set to TimeTicks::Now() when the navigation is deferred in
// WillProcessResponse. If deferral was not necessary, will remain null.
......
......@@ -24,6 +24,7 @@
#include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h"
#include "components/subresource_filter/content/browser/devtools_interaction_tracker.h"
#include "components/subresource_filter/content/browser/fake_safe_browsing_database_manager.h"
#include "components/subresource_filter/content/browser/profile_interaction_manager.h"
#include "components/subresource_filter/content/browser/subresource_filter_client.h"
#include "components/subresource_filter/content/browser/subresource_filter_observer_test_utils.h"
#include "components/subresource_filter/content/browser/subresource_filter_safe_browsing_client.h"
......@@ -69,11 +70,17 @@ const char kActivationListHistogram[] =
"SubresourceFilter.PageLoad.ActivationList";
const char kSubresourceFilterActionsHistogram[] = "SubresourceFilter.Actions2";
class MockSubresourceFilterClient : public SubresourceFilterClient {
class TestSafeBrowsingActivationThrottleDelegate
: public SubresourceFilterSafeBrowsingActivationThrottle::Delegate {
public:
MockSubresourceFilterClient() = default;
~MockSubresourceFilterClient() override = default;
TestSafeBrowsingActivationThrottleDelegate() = default;
~TestSafeBrowsingActivationThrottleDelegate() override = default;
TestSafeBrowsingActivationThrottleDelegate(
const TestSafeBrowsingActivationThrottleDelegate&) = delete;
TestSafeBrowsingActivationThrottleDelegate& operator=(
const TestSafeBrowsingActivationThrottleDelegate&) = delete;
// SubresourceFilterSafeBrowsingActivationThrottle::Delegate:
mojom::ActivationLevel OnPageActivationComputed(
content::NavigationHandle* handle,
mojom::ActivationLevel effective_level,
......@@ -88,15 +95,6 @@ class MockSubresourceFilterClient : public SubresourceFilterClient {
return effective_level;
}
MOCK_METHOD0(ShowNotification, void());
MOCK_METHOD2(OnAdsViolationTriggered,
void(content::RenderFrameHost*,
subresource_filter::mojom::AdsViolation));
MOCK_METHOD0(
GetSafeBrowsingDatabaseManager,
const scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager>());
MOCK_METHOD0(OnReloadRequested, void());
void AllowlistInCurrentWebContents(const GURL& url) {
ASSERT_TRUE(url.SchemeIsHTTPOrHTTPS());
allowlisted_hosts_.insert(url.host());
......@@ -106,7 +104,25 @@ class MockSubresourceFilterClient : public SubresourceFilterClient {
private:
std::set<std::string> allowlisted_hosts_;
};
class MockSubresourceFilterClient : public SubresourceFilterClient {
public:
MockSubresourceFilterClient() = default;
~MockSubresourceFilterClient() override = default;
MOCK_METHOD0(ShowNotification, void());
MOCK_METHOD2(OnAdsViolationTriggered,
void(content::RenderFrameHost*,
subresource_filter::mojom::AdsViolation));
MOCK_METHOD0(
GetSafeBrowsingDatabaseManager,
const scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager>());
MOCK_METHOD0(GetProfileInteractionManager,
subresource_filter::ProfileInteractionManager*());
MOCK_METHOD0(OnReloadRequested, void());
private:
DISALLOW_COPY_AND_ASSIGN(MockSubresourceFilterClient);
};
......@@ -213,7 +229,7 @@ class SubresourceFilterSafeBrowsingActivationThrottleTest
if (navigation_handle->IsInMainFrame()) {
navigation_handle->RegisterThrottleForTesting(
std::make_unique<SubresourceFilterSafeBrowsingActivationThrottle>(
navigation_handle, client(), test_io_task_runner_,
navigation_handle, delegate(), test_io_task_runner_,
fake_safe_browsing_database_));
}
std::vector<std::unique_ptr<content::NavigationThrottle>> throttles;
......@@ -337,6 +353,7 @@ class SubresourceFilterSafeBrowsingActivationThrottleTest
MockSubresourceFilterClient* client() { return client_; }
TestSafeBrowsingActivationThrottleDelegate* delegate() { return &delegate_; }
base::TestMockTimeTaskRunner* test_io_task_runner() const {
return test_io_task_runner_.get();
}
......@@ -352,6 +369,7 @@ class SubresourceFilterSafeBrowsingActivationThrottleTest
testing::TestRulesetCreator test_ruleset_creator_;
testing::TestRulesetPair test_ruleset_pair_;
TestSafeBrowsingActivationThrottleDelegate delegate_;
std::unique_ptr<VerifiedRulesetDealer::Handle> ruleset_dealer_;
std::unique_ptr<ContentSubresourceFilterThrottleManager> throttle_manager_;
......@@ -519,7 +537,7 @@ TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest,
*observer()->GetPageActivationForLastCommittedLoad());
// Allowlisting occurs last, so the decision should still be DISABLED.
client()->AllowlistInCurrentWebContents(url);
delegate()->AllowlistInCurrentWebContents(url);
SimulateNavigateAndCommit({url}, main_rfh());
EXPECT_EQ(mojom::ActivationLevel::kDisabled,
*observer()->GetPageActivationForLastCommittedLoad());
......@@ -792,7 +810,7 @@ TEST_P(SubresourceFilterSafeBrowsingActivationThrottleScopeTest,
EXPECT_EQ(test_data.expected_activation_level,
*observer()->GetPageActivationForLastCommittedLoad());
if (test_data.url_matches_activation_list) {
client()->AllowlistInCurrentWebContents(test_url);
delegate()->AllowlistInCurrentWebContents(test_url);
SimulateNavigateAndCommit({test_url}, main_rfh());
EXPECT_EQ(mojom::ActivationLevel::kDisabled,
*observer()->GetPageActivationForLastCommittedLoad());
......
......@@ -4,6 +4,7 @@
#include "base/json/json_reader.h"
#include "build/build_config.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h"
#include "components/subresource_filter/content/browser/fake_safe_browsing_database_manager.h"
#include "components/subresource_filter/content/browser/ruleset_service.h"
......@@ -15,6 +16,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/resource/resource_bundle.h"
#include "weblayer/browser/browser_process.h"
#include "weblayer/browser/host_content_settings_map_factory.h"
#include "weblayer/browser/subresource_filter_client_impl.h"
#include "weblayer/browser/tab_impl.h"
#include "weblayer/grit/weblayer_resources.h"
......@@ -89,8 +91,7 @@ class SubresourceFilterBrowserTest : public WebLayerBrowserTest {
protected:
void SetRulesetToDisallowURLsWithPathSuffix(const std::string& suffix) {
subresource_filter::testing::TestRulesetPair test_ruleset_pair;
subresource_filter::testing::TestRulesetCreator test_ruleset_creator;
test_ruleset_creator.CreateRulesetToDisallowURLsWithPathSuffix(
test_ruleset_creator_.CreateRulesetToDisallowURLsWithPathSuffix(
suffix, &test_ruleset_pair);
subresource_filter::testing::TestRulesetPublisher test_ruleset_publisher(
......@@ -114,6 +115,9 @@ class SubresourceFilterBrowserTest : public WebLayerBrowserTest {
->client());
client_impl->set_database_manager_for_testing(std::move(database_manager));
}
private:
subresource_filter::testing::TestRulesetCreator test_ruleset_creator_;
};
// Tests that the ruleset service is available.
......@@ -294,6 +298,84 @@ IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest,
EXPECT_TRUE(WasParsedScriptElementLoaded(web_contents->GetMainFrame()));
}
// Flaky on Windows. See https://crbug.com/1152429
#if defined(OS_WIN)
#define MAYBE_ContentSettingsAllowlist_DoNotActivate \
DISABLED_ContentSettingsAllowlist_DoNotActivate
#else
#define MAYBE_ContentSettingsAllowlist_DoNotActivate \
ContentSettingsAllowlist_DoNotActivate
#endif
IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest,
MAYBE_ContentSettingsAllowlist_DoNotActivate) {
auto* web_contents = static_cast<TabImpl*>(shell()->tab())->web_contents();
GURL test_url(
embedded_test_server()->GetURL("/frame_with_included_script.html"));
ASSERT_NO_FATAL_FAILURE(
SetRulesetToDisallowURLsWithPathSuffix("included_script.js"));
ActivateSubresourceFilterInWebContentsForURL(web_contents, test_url);
NavigateAndWaitForCompletion(test_url, shell());
EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents->GetMainFrame()));
content::WebContentsConsoleObserver console_observer(web_contents);
console_observer.SetPattern(subresource_filter::kActivationConsoleMessage);
// Simulate explicitly allowlisting via content settings.
HostContentSettingsMap* settings_map =
HostContentSettingsMapFactory::GetForBrowserContext(
web_contents->GetBrowserContext());
settings_map->SetContentSettingDefaultScope(
test_url, test_url, ContentSettingsType::ADS, CONTENT_SETTING_ALLOW);
NavigateAndWaitForCompletion(test_url, shell());
EXPECT_TRUE(WasParsedScriptElementLoaded(web_contents->GetMainFrame()));
// No message for allowlisted url.
EXPECT_TRUE(console_observer.messages().empty());
}
// Flaky on Windows. See https://crbug.com/1152429
#if defined(OS_WIN)
#define MAYBE_ContentSettingsAllowlistGlobal_DoNotActivate \
DISABLED_ContentSettingsAllowlistGlobal_DoNotActivate
#else
#define MAYBE_ContentSettingsAllowlistGlobal_DoNotActivate \
ContentSettingsAllowlistGlobal_DoNotActivate
#endif
IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest,
MAYBE_ContentSettingsAllowlistGlobal_DoNotActivate) {
auto* web_contents = static_cast<TabImpl*>(shell()->tab())->web_contents();
GURL test_url(
embedded_test_server()->GetURL("/frame_with_included_script.html"));
ASSERT_NO_FATAL_FAILURE(
SetRulesetToDisallowURLsWithPathSuffix("included_script.js"));
ActivateSubresourceFilterInWebContentsForURL(web_contents, test_url);
NavigateAndWaitForCompletion(test_url, shell());
EXPECT_FALSE(WasParsedScriptElementLoaded(web_contents->GetMainFrame()));
content::WebContentsConsoleObserver console_observer(web_contents);
console_observer.SetPattern(subresource_filter::kActivationConsoleMessage);
// Simulate globally allowing ads via content settings.
HostContentSettingsMap* settings_map =
HostContentSettingsMapFactory::GetForBrowserContext(
web_contents->GetBrowserContext());
settings_map->SetDefaultContentSetting(ContentSettingsType::ADS,
CONTENT_SETTING_ALLOW);
NavigateAndWaitForCompletion(test_url, shell());
EXPECT_TRUE(WasParsedScriptElementLoaded(web_contents->GetMainFrame()));
// No message for loads that are not activated.
EXPECT_TRUE(console_observer.messages().empty());
}
#if defined(OS_ANDROID)
// Test that the ads blocked infobar is presented when visiting a page where the
// subresource filter blocks resources from being loaded and is removed when
......
......@@ -9,6 +9,7 @@
#include "base/macros.h"
#include "build/build_config.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/core/browser/subresource_filter_features.h"
#include "components/subresource_filter/core/common/activation_decision.h"
......@@ -18,6 +19,7 @@
#include "content/public/browser/render_frame_host.h"
#include "weblayer/browser/browser_process.h"
#include "weblayer/browser/safe_browsing/safe_browsing_service.h"
#include "weblayer/browser/subresource_filter_profile_context_factory.h"
#if defined(OS_ANDROID)
#include "components/safe_browsing/android/remote_database_manager.h"
......@@ -53,7 +55,12 @@ SubresourceFilterClientImpl::SubresourceFilterClientImpl(
#if defined(OS_ANDROID)
web_contents_(web_contents),
#endif
database_manager_(GetDatabaseManagerFromSafeBrowsingService()) {
database_manager_(GetDatabaseManagerFromSafeBrowsingService()),
profile_interaction_manager_(
std::make_unique<subresource_filter::ProfileInteractionManager>(
web_contents,
SubresourceFilterProfileContextFactory::GetForBrowserContext(
web_contents->GetBrowserContext()))) {
}
SubresourceFilterClientImpl::~SubresourceFilterClientImpl() = default;
......@@ -87,16 +94,6 @@ void SubresourceFilterClientImpl::ShowNotification() {
#endif
}
subresource_filter::mojom::ActivationLevel
SubresourceFilterClientImpl::OnPageActivationComputed(
content::NavigationHandle* navigation_handle,
subresource_filter::mojom::ActivationLevel initial_activation_level,
subresource_filter::ActivationDecision* decision) {
DCHECK(navigation_handle->IsInMainFrame());
return initial_activation_level;
}
void SubresourceFilterClientImpl::OnAdsViolationTriggered(
content::RenderFrameHost* rfh,
subresource_filter::mojom::AdsViolation triggered_violation) {}
......@@ -106,4 +103,9 @@ SubresourceFilterClientImpl::GetSafeBrowsingDatabaseManager() {
return database_manager_;
}
subresource_filter::ProfileInteractionManager*
SubresourceFilterClientImpl::GetProfileInteractionManager() {
return profile_interaction_manager_.get();
}
} // namespace weblayer
......@@ -43,15 +43,13 @@ class SubresourceFilterClientImpl
// SubresourceFilterClient:
void ShowNotification() override;
subresource_filter::mojom::ActivationLevel OnPageActivationComputed(
content::NavigationHandle* navigation_handle,
subresource_filter::mojom::ActivationLevel initial_activation_level,
subresource_filter::ActivationDecision* decision) override;
void OnAdsViolationTriggered(
content::RenderFrameHost* rfh,
subresource_filter::mojom::AdsViolation triggered_violation) override;
const scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager>
GetSafeBrowsingDatabaseManager() override;
subresource_filter::ProfileInteractionManager* GetProfileInteractionManager()
override;
void OnReloadRequested() override;
// Sets the SafeBrowsingDatabaseManager instance used to |database_manager|.
......@@ -70,6 +68,8 @@ class SubresourceFilterClientImpl
std::unique_ptr<subresource_filter::ContentSubresourceFilterThrottleManager>
throttle_manager_;
scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> database_manager_;
std::unique_ptr<subresource_filter::ProfileInteractionManager>
profile_interaction_manager_;
};
} // namespace weblayer
......
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