Skip to content

Commit

Permalink
Merge pull request #19946 from brave/unified-adblock-catalog
Browse files Browse the repository at this point in the history
Implement unified adblock catalog
  • Loading branch information
antonok-edm authored Sep 19, 2023
2 parents 13c48d9 + cfe8a82 commit 2e17608
Show file tree
Hide file tree
Showing 48 changed files with 740 additions and 600 deletions.
1 change: 0 additions & 1 deletion browser/brave_browser_process_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "brave/components/brave_component_updater/browser/brave_on_demand_updater.h"
#include "brave/components/brave_component_updater/browser/local_data_files_service.h"
#include "brave/components/brave_referrals/browser/brave_referrals_service.h"
#include "brave/components/brave_shields/browser/ad_block_regional_service_manager.h"
#include "brave/components/brave_shields/browser/ad_block_service.h"
#include "brave/components/brave_shields/browser/ad_block_subscription_service_manager.h"
#include "brave/components/brave_shields/browser/brave_farbling_service.h"
Expand Down
336 changes: 202 additions & 134 deletions browser/brave_shields/ad_block_service_browsertest.cc

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions browser/brave_shields/ad_block_service_browsertest.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class AdBlockServiceTest : public extensions::ExtensionBrowserTest {

HostContentSettingsMap* content_settings();
void UpdateAdBlockInstanceWithRules(const std::string& rules,
const std::string& resources = "[]");
const std::string& resources = "[]",
uint8_t permission_mask = 0);
void UpdateAdBlockInstanceWithDAT(const base::FilePath& dat_location,
const std::string& resources = "[]");
void UpdateCustomAdBlockInstanceWithRules(
Expand All @@ -51,9 +52,9 @@ class AdBlockServiceTest : public extensions::ExtensionBrowserTest {
void GetTestDataDir(base::FilePath* test_data_dir);
void SetDefaultComponentIdAndBase64PublicKeyForTest();
void SetRegionalComponentIdAndBase64PublicKeyForTest();
bool InstallDefaultAdBlockExtension(
bool InstallDefaultAdBlockComponent(
const std::string& extension_dir = "adblock-default");
bool InstallRegionalAdBlockExtension(const std::string& uuid,
bool InstallRegionalAdBlockComponent(const std::string& uuid,
bool enable_list = true);
void SetSubscriptionIntervals();
void WaitForAdBlockServiceThreads();
Expand Down
26 changes: 13 additions & 13 deletions browser/brave_shields/domain_block_page_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class DomainBlockDisabledTest : public DomainBlockTestBase {
};

IN_PROC_BROWSER_TEST_F(DomainBlockTest, ShowInterstitial) {
ASSERT_TRUE(InstallDefaultAdBlockExtension());
ASSERT_TRUE(InstallDefaultAdBlockComponent());
GURL url = embedded_test_server()->GetURL("a.com", "/simple.html");
SetCosmeticFilteringControlType(content_settings(), ControlType::BLOCK, url);

Expand All @@ -121,7 +121,7 @@ IN_PROC_BROWSER_TEST_F(DomainBlockTest, ShowInterstitial) {
}

IN_PROC_BROWSER_TEST_F(DomainBlockTest, ShowInterstitialAndProceed) {
ASSERT_TRUE(InstallDefaultAdBlockExtension());
ASSERT_TRUE(InstallDefaultAdBlockComponent());
GURL url = embedded_test_server()->GetURL("a.com", "/simple.html");
SetCosmeticFilteringControlType(content_settings(), ControlType::BLOCK, url);

Expand All @@ -145,7 +145,7 @@ IN_PROC_BROWSER_TEST_F(DomainBlockTest, ShowInterstitialAndProceed) {
}

IN_PROC_BROWSER_TEST_F(DomainBlockTest, ShowInterstitialAndReload) {
ASSERT_TRUE(InstallDefaultAdBlockExtension());
ASSERT_TRUE(InstallDefaultAdBlockComponent());
GURL url = embedded_test_server()->GetURL("a.com", "/simple.html");
SetCosmeticFilteringControlType(content_settings(), ControlType::BLOCK, url);

Expand All @@ -166,7 +166,7 @@ IN_PROC_BROWSER_TEST_F(DomainBlockTest, ShowInterstitialAndReload) {
}

IN_PROC_BROWSER_TEST_F(DomainBlockTest, ProceedAndReload) {
ASSERT_TRUE(InstallDefaultAdBlockExtension());
ASSERT_TRUE(InstallDefaultAdBlockComponent());
GURL url = embedded_test_server()->GetURL("a.com", "/simple.html");
SetCosmeticFilteringControlType(content_settings(), ControlType::BLOCK, url);

Expand Down Expand Up @@ -199,7 +199,7 @@ IN_PROC_BROWSER_TEST_F(DomainBlockTest, ProceedAndReload) {
}

IN_PROC_BROWSER_TEST_F(DomainBlockTest, ProceedDoesNotAffectNewTabs) {
ASSERT_TRUE(InstallDefaultAdBlockExtension());
ASSERT_TRUE(InstallDefaultAdBlockComponent());
GURL url = embedded_test_server()->GetURL("a.com", "/simple.html");
SetCosmeticFilteringControlType(content_settings(), ControlType::BLOCK, url);

Expand Down Expand Up @@ -233,7 +233,7 @@ IN_PROC_BROWSER_TEST_F(DomainBlockTest, ProceedDoesNotAffectNewTabs) {
}

IN_PROC_BROWSER_TEST_F(DomainBlockTest, DontWarnAgainAndProceed) {
ASSERT_TRUE(InstallDefaultAdBlockExtension());
ASSERT_TRUE(InstallDefaultAdBlockComponent());
GURL url = embedded_test_server()->GetURL("a.com", "/simple.html");
SetCosmeticFilteringControlType(content_settings(), ControlType::BLOCK, url);

Expand Down Expand Up @@ -274,7 +274,7 @@ IN_PROC_BROWSER_TEST_F(DomainBlockTest, DontWarnAgainAndProceed) {
}

IN_PROC_BROWSER_TEST_F(DomainBlockTest, ShowInterstitialAndGoBack) {
ASSERT_TRUE(InstallDefaultAdBlockExtension());
ASSERT_TRUE(InstallDefaultAdBlockComponent());
GURL url_a = embedded_test_server()->GetURL("a.com", "/simple.html");
SetCosmeticFilteringControlType(content_settings(), ControlType::BLOCK,
url_a);
Expand All @@ -300,7 +300,7 @@ IN_PROC_BROWSER_TEST_F(DomainBlockTest, ShowInterstitialAndGoBack) {
}

IN_PROC_BROWSER_TEST_F(DomainBlockTest, NoFetch) {
ASSERT_TRUE(InstallDefaultAdBlockExtension());
ASSERT_TRUE(InstallDefaultAdBlockComponent());
ASSERT_EQ(0, request_count_);
GURL url = embedded_test_server()->GetURL("a.com", "/simple.html");
SetCosmeticFilteringControlType(content_settings(), ControlType::BLOCK, url);
Expand All @@ -319,7 +319,7 @@ IN_PROC_BROWSER_TEST_F(DomainBlockTest, NoFetch) {
}

IN_PROC_BROWSER_TEST_F(DomainBlockTest, NoThirdPartyInterstitial) {
ASSERT_TRUE(InstallDefaultAdBlockExtension());
ASSERT_TRUE(InstallDefaultAdBlockComponent());
ASSERT_TRUE(g_brave_browser_process->ad_block_service()
->custom_filters_provider()
->UpdateCustomFilters("||b.com^$third-party"));
Expand Down Expand Up @@ -354,7 +354,7 @@ IN_PROC_BROWSER_TEST_F(DomainBlockTest, NoThirdPartyInterstitial) {
}

IN_PROC_BROWSER_TEST_F(DomainBlockTest, NoInterstitialUnlessAggressive) {
ASSERT_TRUE(InstallDefaultAdBlockExtension());
ASSERT_TRUE(InstallDefaultAdBlockComponent());
GURL url = embedded_test_server()->GetURL("a.com", "/simple.html");
SetCosmeticFilteringControlType(content_settings(), ControlType::BLOCK, url);

Expand Down Expand Up @@ -387,7 +387,7 @@ IN_PROC_BROWSER_TEST_F(DomainBlockTest, NoInterstitialUnlessAggressive) {
}

IN_PROC_BROWSER_TEST_F(DomainBlockDisabledTest, NoInterstitial) {
ASSERT_TRUE(InstallDefaultAdBlockExtension());
ASSERT_TRUE(InstallDefaultAdBlockComponent());
GURL url = embedded_test_server()->GetURL("a.com", "/simple.html");
SetCosmeticFilteringControlType(content_settings(), ControlType::BLOCK, url);

Expand All @@ -409,7 +409,7 @@ IN_PROC_BROWSER_TEST_F(DomainBlockDisabledTest, NoInterstitial) {
}

IN_PROC_BROWSER_TEST_F(DomainBlockTest, ProceedDoesNotAffectOtherDomains) {
ASSERT_TRUE(InstallDefaultAdBlockExtension());
ASSERT_TRUE(InstallDefaultAdBlockComponent());
GURL url_a = embedded_test_server()->GetURL("a.com", "/simple.html");
SetCosmeticFilteringControlType(content_settings(), ControlType::BLOCK,
url_a);
Expand Down Expand Up @@ -450,7 +450,7 @@ IN_PROC_BROWSER_TEST_F(DomainBlockTest, ProceedDoesNotAffectOtherDomains) {

IN_PROC_BROWSER_TEST_F(DomainBlockTest,
DontWarnAgainDoesNotAffectOtherDomains) {
ASSERT_TRUE(InstallDefaultAdBlockExtension());
ASSERT_TRUE(InstallDefaultAdBlockComponent());
GURL url_a = embedded_test_server()->GetURL("a.com", "/simple.html");
SetCosmeticFilteringControlType(content_settings(), ControlType::BLOCK,
url_a);
Expand Down
22 changes: 2 additions & 20 deletions browser/debounce/debounce_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,29 @@

#include "base/base64url.h"
#include "base/memory/raw_ptr.h"
#include "base/path_service.h"
#include "base/scoped_observation.h"
#include "base/strings/stringprintf.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/thread_test_helper.h"
#include "brave/browser/brave_browser_process.h"
#include "brave/browser/brave_content_browser_client.h"
#include "brave/browser/extensions/brave_base_local_data_files_browsertest.h"
#include "brave/components/brave_shields/browser/ad_block_component_filters_provider.h"
#include "brave/components/brave_shields/browser/ad_block_service.h"
#include "brave/components/brave_shields/browser/brave_shields_util.h"
#include "brave/components/brave_shields/browser/test_filters_provider.h"
#include "brave/components/constants/brave_paths.h"
#include "brave/components/debounce/browser/debounce_component_installer.h"
#include "brave/components/debounce/common/features.h"
#include "brave/components/debounce/common/pref_names.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/interstitials/security_interstitial_page_test_utils.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/network_session_configurator/common/network_switches.h"
#include "content/public/browser/notification_service.h"
#include "content/public/common/content_client.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "net/base/url_util.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/default_handlers.h"
#include "third_party/blink/public/common/loader/url_loader_throttle.h"

namespace {
Expand Down Expand Up @@ -181,19 +175,7 @@ class DebounceBrowserTest : public BaseLocalDataFilesBrowserTest {
EXPECT_EQ(web_contents()->GetLastCommittedURL(), landing_url);
}

bool InstallAdBlockForDebounce() {
base::FilePath test_data_dir;
GetTestDataDir(&test_data_dir);
const extensions::Extension* ad_block_extension =
InstallExtension(test_data_dir.AppendASCII("adblock-data")
.AppendASCII("adblock-default"),
1);
if (!ad_block_extension) {
return false;
}
g_brave_browser_process->ad_block_service()
->default_filters_provider()
->OnComponentReady(ad_block_extension->path());
bool InitAdBlockForDebounce() {
auto source_provider = std::make_unique<brave_shields::TestFiltersProvider>(
"||blocked.com^", "[]");
g_brave_browser_process->ad_block_service()->UseSourceProvidersForTest(
Expand Down Expand Up @@ -439,7 +421,7 @@ IN_PROC_BROWSER_TEST_F(DebounceBrowserTest, DebounceBeforeDomainBlock) {
// Install adblock, turn on aggressive blocking for this URL, then attempt to
// navigate to it. This should be interrupted by the domain block
// interstitial.
ASSERT_TRUE(InstallAdBlockForDebounce());
ASSERT_TRUE(InitAdBlockForDebounce());
SetCosmeticFilteringControlType(content_settings(), ControlType::BLOCK,
original_url);
NavigateTo(original_url);
Expand Down
14 changes: 7 additions & 7 deletions browser/perf/brave_perf_features_processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "brave/components/brave_ads/core/public/prefs/pref_names.h"
#include "brave/components/brave_news/common/pref_names.h"
#include "brave/components/brave_rewards/browser/rewards_service.h"
#include "brave/components/brave_shields/browser/ad_block_regional_service_manager.h"
#include "brave/components/brave_shields/browser/ad_block_component_service_manager.h"
#include "brave/components/brave_shields/browser/ad_block_service.h"
#include "brave/components/brave_shields/common/brave_shield_constants.h"
#include "chrome/browser/profiles/profile.h"
Expand All @@ -33,19 +33,19 @@ void EnableAdblockCookieList(base::WeakPtr<Profile> profile) {
}

// Obtrusive cookie notices list in cosmetic filters.
auto* regional_service_manager =
g_brave_browser_process->ad_block_service()->regional_service_manager();
if (!regional_service_manager ||
!regional_service_manager->IsFilterListAvailable(
auto* component_service_manager =
g_brave_browser_process->ad_block_service()->component_service_manager();
if (!component_service_manager ||
!component_service_manager->IsFilterListAvailable(
brave_shields::kCookieListUuid)) {
base::SequencedTaskRunner::GetCurrentDefault()->PostDelayedTask(
FROM_HERE, base::BindOnce(&EnableAdblockCookieList, profile),
base::Seconds(1));
return;
}

regional_service_manager->EnableFilterList(brave_shields::kCookieListUuid,
true);
component_service_manager->EnableFilterList(brave_shields::kCookieListUuid,
true);
}

} // namespace
Expand Down
18 changes: 9 additions & 9 deletions browser/ui/views/brave_shields/cookie_list_opt_in_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "brave/browser/brave_browser_process.h"
#include "brave/browser/perf/brave_perf_switches.h"
#include "brave/browser/ui/views/brave_shields/cookie_list_opt_in_bubble_host.h"
#include "brave/components/brave_shields/browser/ad_block_regional_service_manager.h"
#include "brave/components/brave_shields/browser/ad_block_component_service_manager.h"
#include "brave/components/brave_shields/browser/ad_block_service.h"
#include "brave/components/brave_shields/browser/filter_list_catalog_entry.h"
#include "brave/components/brave_shields/common/brave_shield_constants.h"
Expand All @@ -38,13 +38,13 @@ namespace brave_shields {

namespace {

auto* GetRegionalServiceManager() {
auto* GetComponentServiceManager() {
return g_brave_browser_process->ad_block_service()
->regional_service_manager();
->component_service_manager();
}

bool IsCookieListFilterEnabled() {
return GetRegionalServiceManager()->IsFilterListEnabled(kCookieListUuid);
return GetComponentServiceManager()->IsFilterListEnabled(kCookieListUuid);
}

class CookieListFilterEnabledObserver {
Expand Down Expand Up @@ -127,10 +127,10 @@ class CookieListOptInBrowserTest : public InProcessBrowserTest {
kCookieListUuid,
"https://secure.fanboy.co.nz/fanboy-cookiemonster_ubo.txt",
"Easylist-Cookie List - Filter Obtrusive Cookie Notices", {},
"https://forums.lanik.us/", kRegionalAdBlockComponentTestId,
kRegionalAdBlockComponentTest64PublicKey,
"Removes obtrusive cookie law notices", "", "")};
GetRegionalServiceManager()->SetFilterListCatalog(filter_list_catalog);
"https://forums.lanik.us/", "Removes obtrusive cookie law notices",
false, false, false, 0, kRegionalAdBlockComponentTestId,
kRegionalAdBlockComponentTest64PublicKey, "", "")};
GetComponentServiceManager()->SetFilterListCatalog(filter_list_catalog);
}

base::test::ScopedFeatureList scoped_feature_list_;
Expand Down Expand Up @@ -248,7 +248,7 @@ class CookieListOptInPreEnabledBrowserTest : public CookieListOptInBrowserTest {
void SetUpLocalState() override {
CookieListOptInBrowserTest::SetUpLocalState();

GetRegionalServiceManager()->EnableFilterList(kCookieListUuid, true);
GetComponentServiceManager()->EnableFilterList(kCookieListUuid, true);

// Since `AdBlockRegionalServiceManager::EnableFilterList` modifies local
// state asynchronously in a posted task, waiting for the update to complete
Expand Down
20 changes: 10 additions & 10 deletions browser/ui/views/brave_shields/cookie_list_opt_in_bubble_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "base/metrics/histogram_functions.h"
#include "brave/browser/brave_browser_process.h"
#include "brave/browser/ui/webui/brave_shields/cookie_list_opt_in_ui.h"
#include "brave/components/brave_shields/browser/ad_block_regional_service_manager.h"
#include "brave/components/brave_shields/browser/ad_block_component_service_manager.h"
#include "brave/components/brave_shields/browser/ad_block_service.h"
#include "brave/components/brave_shields/common/brave_shield_constants.h"
#include "brave/components/brave_shields/common/features.h"
Expand Down Expand Up @@ -61,10 +61,10 @@ bool ShouldEventuallyShowBubble() {

base::UmaHistogramExactLinear(kCookieListPromptHistogram, 0, 4);

auto* regional_service_manager =
g_brave_browser_process->ad_block_service()->regional_service_manager();
DCHECK(regional_service_manager);
if (regional_service_manager->IsFilterListEnabled(kCookieListUuid)) {
auto* component_service_manager =
g_brave_browser_process->ad_block_service()->component_service_manager();
DCHECK(component_service_manager);
if (component_service_manager->IsFilterListEnabled(kCookieListUuid)) {
return false;
}

Expand Down Expand Up @@ -146,11 +146,11 @@ void CookieListOptInBubbleHost::ShowBubble() {
}

// Do not show the bubble if the filter list is not yet available, likely
// because the regional filter list has not yet been donwloaded.
auto* regional_service_manager =
g_brave_browser_process->ad_block_service()->regional_service_manager();
DCHECK(regional_service_manager);
if (!regional_service_manager->IsFilterListAvailable(kCookieListUuid)) {
// because the filter list component has not yet been donwloaded.
auto* component_service_manager =
g_brave_browser_process->ad_block_service()->component_service_manager();
DCHECK(component_service_manager);
if (!component_service_manager->IsFilterListAvailable(kCookieListUuid)) {
return;
}

Expand Down
6 changes: 3 additions & 3 deletions browser/ui/webui/brave_adblock_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#include "brave/browser/brave_browser_process.h"
#include "brave/browser/ui/webui/brave_webui_source.h"
#include "brave/components/brave_adblock/resources/grit/brave_adblock_generated_map.h"
#include "brave/components/brave_shields/browser/ad_block_component_service_manager.h"
#include "brave/components/brave_shields/browser/ad_block_custom_filters_provider.h"
#include "brave/components/brave_shields/browser/ad_block_regional_service_manager.h"
#include "brave/components/brave_shields/browser/ad_block_service.h"
#include "brave/components/brave_shields/browser/ad_block_service_helper.h"
#include "brave/components/brave_shields/browser/ad_block_subscription_service_manager.h"
Expand Down Expand Up @@ -144,7 +144,7 @@ void AdblockDOMHandler::HandleEnableFilterList(const base::Value::List& args) {
std::string uuid = args[0].GetString();
bool enabled = args[1].GetBool();
g_brave_browser_process->ad_block_service()
->regional_service_manager()
->component_service_manager()
->EnableFilterList(uuid, enabled);
}

Expand All @@ -162,7 +162,7 @@ void AdblockDOMHandler::HandleGetRegionalLists(const base::Value::List& args) {
DCHECK_EQ(args.size(), 0U);
AllowJavascript();
auto regional_lists = g_brave_browser_process->ad_block_service()
->regional_service_manager()
->component_service_manager()
->GetRegionalLists();
CallJavascriptFunction("brave_adblock.onGetRegionalLists", regional_lists);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include "base/metrics/histogram_functions.h"
#include "brave/browser/brave_browser_process.h"
#include "brave/components/brave_shields/browser/ad_block_regional_service_manager.h"
#include "brave/components/brave_shields/browser/ad_block_component_service_manager.h"
#include "brave/components/brave_shields/browser/ad_block_service.h"
#include "brave/components/brave_shields/common/brave_shield_constants.h"

Expand Down Expand Up @@ -43,7 +43,7 @@ void CookieListOptInPageHandler::CloseUI() {

void CookieListOptInPageHandler::EnableFilter() {
g_brave_browser_process->ad_block_service()
->regional_service_manager()
->component_service_manager()
->EnableFilterList(brave_shields::kCookieListUuid, true);
}

Expand Down
Loading

0 comments on commit 2e17608

Please sign in to comment.