From 469982216d5177e1ce539465b86e2bf0b888b826 Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Thu, 19 Nov 2020 16:16:34 -0500 Subject: [PATCH] Implement first-party domain blocking --- DEPS | 2 +- browser/brave_content_browser_client.cc | 60 ++- .../ad_block_service_browsertest.cc | 479 ++++++++---------- .../ad_block_service_browsertest.h | 44 ++ .../domain_block_page_browsertest.cc | 283 +++++++++++ build/rust/Cargo.lock | 330 +++++++----- components/brave_shields/browser/BUILD.gn | 19 +- .../brave_shields/browser/ad_block_service.h | 2 + .../browser/domain_block_controller_client.cc | 69 +++ .../browser/domain_block_controller_client.h | 59 +++ .../domain_block_navigation_throttle.cc | 165 ++++++ .../domain_block_navigation_throttle.h | 62 +++ .../browser/domain_block_page.cc | 102 ++++ .../brave_shields/browser/domain_block_page.h | 63 +++ .../browser/domain_block_tab_storage.cc | 32 ++ .../browser/domain_block_tab_storage.h | 47 ++ .../resources/domain_block_interstitial.css | 36 ++ .../resources/domain_block_interstitial.html | 34 ++ .../resources/domain_block_interstitial.js | 20 + .../resources/brave_components_resources.grd | 1 + .../resources/brave_components_strings.grd | 1 + .../resources/domain_block_resources.grdp | 6 + .../resources/domain_block_strings.grdp | 24 + test/BUILD.gn | 3 + 24 files changed, 1516 insertions(+), 427 deletions(-) create mode 100644 browser/brave_shields/ad_block_service_browsertest.h create mode 100644 browser/brave_shields/domain_block_page_browsertest.cc create mode 100644 components/brave_shields/browser/domain_block_controller_client.cc create mode 100644 components/brave_shields/browser/domain_block_controller_client.h create mode 100644 components/brave_shields/browser/domain_block_navigation_throttle.cc create mode 100644 components/brave_shields/browser/domain_block_navigation_throttle.h create mode 100644 components/brave_shields/browser/domain_block_page.cc create mode 100644 components/brave_shields/browser/domain_block_page.h create mode 100644 components/brave_shields/browser/domain_block_tab_storage.cc create mode 100644 components/brave_shields/browser/domain_block_tab_storage.h create mode 100644 components/brave_shields/resources/domain_block_interstitial.css create mode 100644 components/brave_shields/resources/domain_block_interstitial.html create mode 100644 components/brave_shields/resources/domain_block_interstitial.js create mode 100644 components/resources/domain_block_resources.grdp create mode 100644 components/resources/domain_block_strings.grdp diff --git a/DEPS b/DEPS index edb5d5b152b9..ebbfbe088926 100644 --- a/DEPS +++ b/DEPS @@ -1,7 +1,7 @@ use_relative_paths = True deps = { - "vendor/adblock_rust_ffi": "https://github.com/brave/adblock-rust-ffi.git@3d6aa901b4442ad6bbeb108b5ae5b980e9756a71", + "vendor/adblock_rust_ffi": "https://github.com/brave/adblock-rust-ffi.git@f4e194e86288b8c8ffbcc53876cf2e7a6aea142b", "vendor/extension-whitelist": "https://github.com/brave/extension-whitelist.git@b4d059c73042cacf3a5e9156d4b1698e7bc18678", "vendor/hashset-cpp": "https://github.com/brave/hashset-cpp.git@6eab0271d014ff09bd9f38abe1e0c117e13e9aa9", "vendor/requests": "https://github.com/kennethreitz/requests@e4d59bedfd3c7f4f254f4f5d036587bcd8152458", diff --git a/browser/brave_content_browser_client.cc b/browser/brave_content_browser_client.cc index 123c3d79ad66..9f7ca329e063 100644 --- a/browser/brave_content_browser_client.cc +++ b/browser/brave_content_browser_client.cc @@ -25,6 +25,7 @@ #include "brave/components/brave_rewards/browser/buildflags/buildflags.h" #include "brave/components/brave_shields/browser/brave_shields_util.h" #include "brave/components/brave_shields/browser/brave_shields_web_contents_observer.h" +#include "brave/components/brave_shields/browser/domain_block_navigation_throttle.h" #include "brave/components/brave_shields/browser/tracking_protection_service.h" #include "brave/components/brave_shields/common/brave_shield_constants.h" #include "brave/components/brave_wallet/buildflags/buildflags.h" @@ -78,8 +79,8 @@ using extensions::ChromeContentBrowserClientExtensionsPart; #endif #if BUILDFLAG(ENABLE_BRAVE_WEBTORRENT) -#include "brave/components/brave_webtorrent/browser/content_browser_client_helper.h" #include "brave/browser/extensions/brave_webtorrent_navigation_throttle.h" +#include "brave/components/brave_webtorrent/browser/content_browser_client_helper.h" #endif #if BUILDFLAG(IPFS_ENABLED) @@ -257,9 +258,8 @@ void BraveContentBrowserClient::BrowserURLHandlerCreated( &webtorrent::HandleTorrentURLReverseRewrite); #endif #if BUILDFLAG(IPFS_ENABLED) - handler->AddHandlerPair( - &ipfs::HandleIPFSURLRewrite, - &ipfs::HandleIPFSURLReverseRewrite); + handler->AddHandlerPair(&ipfs::HandleIPFSURLRewrite, + &ipfs::HandleIPFSURLReverseRewrite); #endif handler->AddHandlerPair(&HandleURLRewrite, &HandleURLReverseOverrideRewrite); ChromeContentBrowserClient::BrowserURLHandlerCreated(handler); @@ -368,8 +368,8 @@ BraveContentBrowserClient::CreateURLLoaderThrottles( content::NavigationUIData* navigation_ui_data, int frame_tree_node_id) { auto result = ChromeContentBrowserClient::CreateURLLoaderThrottles( - request, browser_context, wc_getter, navigation_ui_data, - frame_tree_node_id); + request, browser_context, wc_getter, navigation_ui_data, + frame_tree_node_id); #if BUILDFLAG(ENABLE_SPEEDREADER) content::WebContents* contents = wc_getter.Run(); if (!contents) { @@ -377,9 +377,9 @@ BraveContentBrowserClient::CreateURLLoaderThrottles( } auto* tab_helper = speedreader::SpeedreaderTabHelper::FromWebContents(contents); - if (tab_helper && tab_helper->IsActiveForMainFrame() - && request.resource_type - == static_cast(blink::mojom::ResourceType::kMainFrame)) { + if (tab_helper && tab_helper->IsActiveForMainFrame() && + request.resource_type == + static_cast(blink::mojom::ResourceType::kMainFrame)) { result.push_back(std::make_unique( g_brave_browser_process->speedreader_rewriter_service(), base::ThreadTaskRunnerHandle::Get())); @@ -431,20 +431,12 @@ void BraveContentBrowserClient::CreateWebSocket( mojo::PendingRemote handshake_client) { auto* proxy = BraveProxyingWebSocket::ProxyWebSocket( - frame, - std::move(factory), - url, - site_for_cookies, - user_agent, + frame, std::move(factory), url, site_for_cookies, user_agent, std::move(handshake_client)); if (ChromeContentBrowserClient::WillInterceptWebSocket(frame)) { ChromeContentBrowserClient::CreateWebSocket( - frame, - proxy->web_socket_factory(), - url, - site_for_cookies, - user_agent, + frame, proxy->web_socket_factory(), url, site_for_cookies, user_agent, proxy->handshake_client().Unbind()); } else { proxy->Start(); @@ -470,11 +462,9 @@ void BraveContentBrowserClient::MaybeHideReferrer( Profile* profile = Profile::FromBrowserContext(browser_context); const bool allow_referrers = brave_shields::AllowReferrers( - HostContentSettingsMapFactory::GetForProfile(profile), - document_url); + HostContentSettingsMapFactory::GetForProfile(profile), document_url); const bool shields_up = brave_shields::GetBraveShieldsEnabled( - HostContentSettingsMapFactory::GetForProfile(profile), - document_url); + HostContentSettingsMapFactory::GetForProfile(profile), document_url); content::Referrer new_referrer; if (brave_shields::MaybeChangeReferrer(allow_referrers, shields_up, @@ -531,9 +521,9 @@ GURL BraveContentBrowserClient::GetEffectiveURL( } // [static] -bool BraveContentBrowserClient::HandleURLOverrideRewrite(GURL* url, +bool BraveContentBrowserClient::HandleURLOverrideRewrite( + GURL* url, content::BrowserContext* browser_context) { - if (url->host() == chrome::kChromeUISyncHost) { GURL::Replacements replacements; replacements.SetHostStr(chrome::kChromeUISettingsHost); @@ -557,7 +547,7 @@ bool BraveContentBrowserClient::HandleURLOverrideRewrite(GURL* url, url->host() == ethereum_remote_client_host) { auto* registry = extensions::ExtensionRegistry::Get(browser_context); if (registry->ready_extensions().GetByID( - ethereum_remote_client_extension_id)) { + ethereum_remote_client_extension_id)) { *url = GURL(ethereum_remote_client_base_url); return true; } @@ -585,15 +575,15 @@ BraveContentBrowserClient::CreateThrottlesForNavigation( std::make_unique(handle)); #endif -#if BUILDFLAG(ENABLE_TOR) ||BUILDFLAG(IPFS_ENABLED) +#if BUILDFLAG(ENABLE_TOR) || BUILDFLAG(IPFS_ENABLED) content::BrowserContext* context = handle->GetWebContents()->GetBrowserContext(); #endif #if BUILDFLAG(ENABLE_TOR) std::unique_ptr tor_navigation_throttle = - tor::TorNavigationThrottle::MaybeCreateThrottleFor(handle, - context->IsTor()); + tor::TorNavigationThrottle::MaybeCreateThrottleFor(handle, + context->IsTor()); if (tor_navigation_throttle) throttles.push_back(std::move(tor_navigation_throttle)); std::unique_ptr @@ -611,12 +601,20 @@ BraveContentBrowserClient::CreateThrottlesForNavigation( #if BUILDFLAG(IPFS_ENABLED) std::unique_ptr ipfs_navigation_throttle = - ipfs::IpfsNavigationThrottle::MaybeCreateThrottleFor(handle, - ipfs::IpfsServiceFactory::GetForContext(context), + ipfs::IpfsNavigationThrottle::MaybeCreateThrottleFor( + handle, ipfs::IpfsServiceFactory::GetForContext(context), g_brave_browser_process->GetApplicationLocale()); if (ipfs_navigation_throttle) throttles.push_back(std::move(ipfs_navigation_throttle)); #endif + if (std::unique_ptr< + content::NavigationThrottle> domain_block_navigation_throttle = + brave_shields::DomainBlockNavigationThrottle::MaybeCreateThrottleFor( + handle, g_brave_browser_process->ad_block_service(), + g_brave_browser_process->ad_block_custom_filters_service(), + g_brave_browser_process->GetApplicationLocale())) + throttles.push_back(std::move(domain_block_navigation_throttle)); + return throttles; } diff --git a/browser/brave_shields/ad_block_service_browsertest.cc b/browser/brave_shields/ad_block_service_browsertest.cc index 14ef90f79bd9..b9175be06f78 100644 --- a/browser/brave_shields/ad_block_service_browsertest.cc +++ b/browser/brave_shields/ad_block_service_browsertest.cc @@ -3,6 +3,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "brave/browser/brave_shields/ad_block_service_browsertest.h" + +#include +#include + #include "base/base64.h" #include "base/path_service.h" #include "base/task/post_task.h" @@ -31,10 +36,6 @@ #include "extensions/test/extension_test_message_listener.h" #include "net/dns/mock_host_resolver.h" -using brave_shields::features::kBraveAdblockCosmeticFiltering; -using content::BrowserThread; -using extensions::ExtensionBrowserTest; - const char kAdBlockTestPage[] = "/blocking.html"; const char kAdBlockEasyListFranceUUID[] = @@ -47,7 +48,7 @@ const char kRegionalAdBlockComponentTestId[] = const char kTrackingProtectionComponentTestId[] = "eclbkhjphkhalklhipiicaldjbnhdfkc"; -const char kDefaultAdBlockComponentTestBase64PublicKey[] = +const char kDefaultAdBlockComponentTest64PublicKey[] = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtV7Vr69kkvSvu2lhcMDh" "j4Jm3FKU1zpUkALaum5719/cccVvGpMKKFyy4WYXsmAfcIONmGO4ThK/q6jkgC5v" "8HrkjPOf7HHebKEnsJJucz/Z1t6dq0CE+UA2IWfbGfFM4nJ8AKIv2gqiw2d4ydAs" @@ -55,7 +56,7 @@ const char kDefaultAdBlockComponentTestBase64PublicKey[] = "Qdk+dZ9r8NRQnpjChQzwhMAkxyrdjT1N7NcfTufiYQTOyiFvxPAC9D7vAzkpGgxU" "Ikylk7cYRxqkRGS/AayvfipJ/HOkoBd0yKu1MRk4YcKGd/EahDAhUtd9t4+v33Qv" "uwIDAQAB"; -const char kRegionalAdBlockComponentTestBase64PublicKey[] = +const char kRegionalAdBlockComponentTest64PublicKey[] = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoKYkdDM8vWZXBbDJXTP6" "1m9yLuH9iL/TvqAqu1zOd91VJu4bpcCMZjfGPC1g+O+pZrCaFVv5NJeZxGqT6DUB" "RZUdXPkGGUC1ebS4LLJbggNQb152LFk8maR0/ItvMOW8eTcV8VFKHk4UrVhPTggf" @@ -63,7 +64,7 @@ const char kRegionalAdBlockComponentTestBase64PublicKey[] = "G8XBq/Y8FbBt+u+7skWQy3lVyRwFjeFu6cXVF4tcc06PNx5yLsbHQtSv8R+h1bWw" "ieMF3JB9CZPr+qDKIap+RZUfsraV47QebRi/JA17nbDMlXOmK7mILfFU7Jhjx04F" "LwIDAQAB"; -const char kTrackingProtectionComponentTestBase64PublicKey[] = +const char kTrackingProtectionComponentTest64PublicKey[] = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsleoSxQ3DN+6xym2P1uX" "mN6ArIWd9Oru5CSjS0SRE5upM2EnAl/C20TP8JdIlPi/3tk/SN6Y92K3xIhAby5F" "0rbPDSTXEWGy72tv2qb/WySGwDdvYQu9/J5sEDneVcMrSHcC0VWgcZR0eof4BfOy" @@ -72,197 +73,185 @@ const char kTrackingProtectionComponentTestBase64PublicKey[] = "WhIYw/5zv1NyIsfUiG8wIs5+OwS419z7dlMKsg1FuB2aQcDyjoXx1habFfHQfQwL" "qwIDAQAB"; -class AdBlockServiceTest : public ExtensionBrowserTest { - public: - AdBlockServiceTest() {} - - void SetUpOnMainThread() override { - ExtensionBrowserTest::SetUpOnMainThread(); - host_resolver()->AddRule("*", "127.0.0.1"); - } +using brave_shields::features::kBraveAdblockCosmeticFiltering; +using content::BrowserThread; - void SetUp() override { - InitEmbeddedTestServer(); - ExtensionBrowserTest::SetUp(); - } +void AdBlockServiceTest::SetUpOnMainThread() { + ExtensionBrowserTest::SetUpOnMainThread(); + host_resolver()->AddRule("*", "127.0.0.1"); +} - void PreRunTestOnMainThread() override { - ExtensionBrowserTest::PreRunTestOnMainThread(); - WaitForAdBlockServiceThreads(); - ASSERT_TRUE(g_brave_browser_process->ad_block_service()->IsInitialized()); - } +void AdBlockServiceTest::SetUp() { + InitEmbeddedTestServer(); + ExtensionBrowserTest::SetUp(); +} - HostContentSettingsMap* content_settings() { - return HostContentSettingsMapFactory::GetForProfile(browser()->profile()); - } +void AdBlockServiceTest::PreRunTestOnMainThread() { + ExtensionBrowserTest::PreRunTestOnMainThread(); + WaitForAdBlockServiceThreads(); + ASSERT_TRUE(g_brave_browser_process->ad_block_service()->IsInitialized()); +} - void UpdateAdBlockInstanceWithRules(const std::string& rules, - const std::string& resources = "") { - g_brave_browser_process->ad_block_service()->ResetForTest(rules, resources); - } +HostContentSettingsMap* AdBlockServiceTest::content_settings() { + return HostContentSettingsMapFactory::GetForProfile(browser()->profile()); +} - void AssertTagExists(const std::string& tag, bool expected_exists) const { - bool exists_default = - g_brave_browser_process->ad_block_service()->TagExists(tag); - ASSERT_EQ(exists_default, expected_exists); - - for (const auto& regional_service : - g_brave_browser_process->ad_block_regional_service_manager() - ->regional_services_) { - bool exists_regional = regional_service.second->TagExists(tag); - ASSERT_EQ(exists_regional, expected_exists); - } - } +void AdBlockServiceTest::UpdateAdBlockInstanceWithRules( + const std::string& rules, + const std::string& resources) { + g_brave_browser_process->ad_block_service()->ResetForTest(rules, resources); +} - void InitEmbeddedTestServer() { - brave::RegisterPathProvider(); - base::FilePath test_data_dir; - base::PathService::Get(brave::DIR_TEST_DATA, &test_data_dir); - embedded_test_server()->ServeFilesFromDirectory(test_data_dir); - content::SetupCrossSiteRedirector(embedded_test_server()); - ASSERT_TRUE(embedded_test_server()->Start()); +void AdBlockServiceTest::AssertTagExists(const std::string& tag, + bool expected_exists) const { + bool exists_default = + g_brave_browser_process->ad_block_service()->TagExists(tag); + ASSERT_EQ(exists_default, expected_exists); + + for (const auto& regional_service : + g_brave_browser_process->ad_block_regional_service_manager() + ->regional_services_) { + bool exists_regional = regional_service.second->TagExists(tag); + ASSERT_EQ(exists_regional, expected_exists); } +} - void GetTestDataDir(base::FilePath* test_data_dir) { - base::ScopedAllowBlockingForTesting allow_blocking; - base::PathService::Get(brave::DIR_TEST_DATA, test_data_dir); - } +void AdBlockServiceTest::InitEmbeddedTestServer() { + brave::RegisterPathProvider(); + base::FilePath test_data_dir; + base::PathService::Get(brave::DIR_TEST_DATA, &test_data_dir); + embedded_test_server()->ServeFilesFromDirectory(test_data_dir); + content::SetupCrossSiteRedirector(embedded_test_server()); + ASSERT_TRUE(embedded_test_server()->Start()); +} - void SetDefaultComponentIdAndBase64PublicKeyForTest( - const std::string& component_id, - const std::string& component_base64_public_key) { - brave_shields::AdBlockService::SetComponentIdAndBase64PublicKeyForTest( - component_id, component_base64_public_key); - } +void AdBlockServiceTest::GetTestDataDir(base::FilePath* test_data_dir) { + base::ScopedAllowBlockingForTesting allow_blocking; + base::PathService::Get(brave::DIR_TEST_DATA, test_data_dir); +} - void InitTrackingProtectionService() { - brave_component_updater::LocalDataFilesService:: - SetComponentIdAndBase64PublicKeyForTest( - kTrackingProtectionComponentTestId, - kTrackingProtectionComponentTestBase64PublicKey); - } +void AdBlockServiceTest::InitTrackingProtectionService() { + brave_component_updater::LocalDataFilesService:: + SetComponentIdAndBase64PublicKeyForTest( + kTrackingProtectionComponentTestId, + kTrackingProtectionComponentTest64PublicKey); +} - void SetRegionalComponentIdAndBase64PublicKeyForTest( - const std::string& component_id, - const std::string& component_base64_public_key) { - brave_shields::AdBlockRegionalService:: - SetComponentIdAndBase64PublicKeyForTest(component_id, - component_base64_public_key); - } +bool AdBlockServiceTest::InstallDefaultAdBlockExtension( + const std::string& extension_dir, + int expected_change) { + brave_shields::AdBlockService::SetComponentIdAndBase64PublicKeyForTest( + kDefaultAdBlockComponentTestId, kDefaultAdBlockComponentTest64PublicKey); + base::FilePath test_data_dir; + GetTestDataDir(&test_data_dir); + const extensions::Extension* ad_block_extension = InstallExtension( + test_data_dir.AppendASCII("adblock-data").AppendASCII(extension_dir), + expected_change); + if (!ad_block_extension) + return false; + + g_brave_browser_process->ad_block_service()->OnComponentReady( + ad_block_extension->id(), ad_block_extension->path(), ""); + WaitForAdBlockServiceThreads(); - bool InstallDefaultAdBlockExtension( - const std::string& extension_dir = "adblock-default", - int expected_change = 1) { - base::FilePath test_data_dir; - GetTestDataDir(&test_data_dir); - const extensions::Extension* ad_block_extension = InstallExtension( - test_data_dir.AppendASCII("adblock-data").AppendASCII(extension_dir), - expected_change); - if (!ad_block_extension) - return false; - - g_brave_browser_process->ad_block_service()->OnComponentReady( - ad_block_extension->id(), ad_block_extension->path(), ""); - WaitForAdBlockServiceThreads(); - - return true; - } + return true; +} - bool InstallRegionalAdBlockExtension(const std::string& uuid) { - base::FilePath test_data_dir; - GetTestDataDir(&test_data_dir); - const std::vector regional_catalog = { +bool AdBlockServiceTest::InstallRegionalAdBlockExtension( + const std::string& uuid) { + brave_shields::AdBlockRegionalService:: + SetComponentIdAndBase64PublicKeyForTest( + kRegionalAdBlockComponentTestId, + kRegionalAdBlockComponentTest64PublicKey); + base::FilePath test_data_dir; + GetTestDataDir(&test_data_dir); + const std::vector regional_catalog = { adblock::FilterList( - uuid, - "https://easylist-downloads.adblockplus.org/liste_fr.txt", - "EasyList Liste FR", - { "fr" }, - "https://forums.lanik.us/viewforum.php?f=91", - "emaecjinaegfkoklcdafkiocjhoeilao", - "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsbqIWuMS7r2OPXCsIPbbLG1H/" - "d3NM9uzCMscw7R9ZV3TwhygvMOpZrNp4Y4hImy2H+HE0OniCqzuOAaq7+SHXcdHwItvLK" - "tnRmeWgdqxgEdzJ8rZMWnfi+dODTbA4QvxI6itU5of8trDFbLzFqgnEOBk8ZxtjM/M5v3" - "UeYh+EYHSEyHnDSJKbKevlXC931xlbdca0q0Ps3Ln6w/pJFByGbOh212mD/PvwS6jIH3L" - "YjrMVUMefKC/ywn/AAdnwM5mGirm1NflQCJQOpTjIhbRIXBlACfV/hwI1lqfKbFnyr4aP" - "Odg3JcOZZVoyi+ko3rKG3vH9JPWEy24Ys9A3SYpTwIDAQAB", - "Removes advertisements from French websites" - ) - }; - g_brave_browser_process->ad_block_regional_service_manager()-> - SetRegionalCatalog(regional_catalog); - const extensions::Extension* ad_block_extension = - InstallExtension(test_data_dir.AppendASCII("adblock-data") - .AppendASCII("adblock-regional") - .AppendASCII(uuid), - 1); - if (!ad_block_extension) - return false; - - g_brave_browser_process->ad_block_regional_service_manager() - ->EnableFilterList(uuid, true); - EXPECT_EQ(g_brave_browser_process->ad_block_regional_service_manager() - ->regional_services_.size(), - 1ULL); - - auto regional_service = - g_brave_browser_process->ad_block_regional_service_manager() - ->regional_services_.find(uuid); - regional_service->second->OnComponentReady(ad_block_extension->id(), - ad_block_extension->path(), ""); - WaitForAdBlockServiceThreads(); - - return true; - } + uuid, "https://easylist-downloads.adblockplus.org/liste_fr.txt", + "EasyList Liste FR", {"fr"}, + "https://forums.lanik.us/viewforum.php?f=91", + "emaecjinaegfkoklcdafkiocjhoeilao", + "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsbqIWuMS7r2OPXCsIPbbLG1H" + "/" + "d3NM9uzCMscw7R9ZV3TwhygvMOpZrNp4Y4hImy2H+HE0OniCqzuOAaq7+" + "SHXcdHwItvLK" + "tnRmeWgdqxgEdzJ8rZMWnfi+dODTbA4QvxI6itU5of8trDFbLzFqgnEOBk8ZxtjM/" + "M5v3" + "UeYh+EYHSEyHnDSJKbKevlXC931xlbdca0q0Ps3Ln6w/pJFByGbOh212mD/" + "PvwS6jIH3L" + "YjrMVUMefKC/ywn/AAdnwM5mGirm1NflQCJQOpTjIhbRIXBlACfV/" + "hwI1lqfKbFnyr4aP" + "Odg3JcOZZVoyi+ko3rKG3vH9JPWEy24Ys9A3SYpTwIDAQAB", + "Removes advertisements from French websites")}; + g_brave_browser_process->ad_block_regional_service_manager() + ->SetRegionalCatalog(regional_catalog); + const extensions::Extension* ad_block_extension = + InstallExtension(test_data_dir.AppendASCII("adblock-data") + .AppendASCII("adblock-regional") + .AppendASCII(uuid), + 1); + if (!ad_block_extension) + return false; + + g_brave_browser_process->ad_block_regional_service_manager() + ->EnableFilterList(uuid, true); + EXPECT_EQ(g_brave_browser_process->ad_block_regional_service_manager() + ->regional_services_.size(), + 1ULL); + + auto regional_service = + g_brave_browser_process->ad_block_regional_service_manager() + ->regional_services_.find(uuid); + regional_service->second->OnComponentReady(ad_block_extension->id(), + ad_block_extension->path(), ""); + WaitForAdBlockServiceThreads(); - bool InstallTrackingProtectionExtension() { - base::FilePath test_data_dir; - GetTestDataDir(&test_data_dir); - const extensions::Extension* tracking_protection_extension = - InstallExtension(test_data_dir.AppendASCII("tracking-protection-data"), - 1); - if (!tracking_protection_extension) - return false; - - g_brave_browser_process->tracking_protection_service()->OnComponentReady( - tracking_protection_extension->id(), - tracking_protection_extension->path(), ""); - WaitForAdBlockServiceThreads(); - - return true; - } + return true; +} - bool StartAdBlockRegionalServices() { - g_brave_browser_process->ad_block_regional_service_manager()->Start(); - if (!g_brave_browser_process->ad_block_regional_service_manager() - ->IsInitialized()) - return false; - return true; - } +bool AdBlockServiceTest::InstallTrackingProtectionExtension() { + base::FilePath test_data_dir; + GetTestDataDir(&test_data_dir); + const extensions::Extension* tracking_protection_extension = InstallExtension( + test_data_dir.AppendASCII("tracking-protection-data"), 1); + if (!tracking_protection_extension) + return false; + + g_brave_browser_process->tracking_protection_service()->OnComponentReady( + tracking_protection_extension->id(), + tracking_protection_extension->path(), ""); + WaitForAdBlockServiceThreads(); - void WaitForAdBlockServiceThreads() { - scoped_refptr tr_helper(new base::ThreadTestHelper( - g_brave_browser_process->local_data_files_service()->GetTaskRunner())); - ASSERT_TRUE(tr_helper->Run()); - scoped_refptr io_helper(new base::ThreadTestHelper( - base::CreateSingleThreadTaskRunner({BrowserThread::IO}).get())); - ASSERT_TRUE(io_helper->Run()); - } + return true; +} - void WaitForBraveExtensionShieldsDataReady() { - // Sometimes, the page can start loading before the Shields panel has - // received information about the window and tab it's loaded in. - ExtensionTestMessageListener extension_listener( - "brave-extension-shields-data-ready", - false); - ASSERT_TRUE(extension_listener.WaitUntilSatisfied()); - } -}; +bool AdBlockServiceTest::StartAdBlockRegionalServices() { + g_brave_browser_process->ad_block_regional_service_manager()->Start(); + if (!g_brave_browser_process->ad_block_regional_service_manager() + ->IsInitialized()) + return false; + return true; +} + +void AdBlockServiceTest::WaitForAdBlockServiceThreads() { + scoped_refptr tr_helper(new base::ThreadTestHelper( + g_brave_browser_process->local_data_files_service()->GetTaskRunner())); + ASSERT_TRUE(tr_helper->Run()); + scoped_refptr io_helper(new base::ThreadTestHelper( + base::CreateSingleThreadTaskRunner({BrowserThread::IO}).get())); + ASSERT_TRUE(io_helper->Run()); +} + +void AdBlockServiceTest::WaitForBraveExtensionShieldsDataReady() { + // Sometimes, the page can start loading before the Shields panel has + // received information about the window and tab it's loaded in. + ExtensionTestMessageListener extension_listener( + "brave-extension-shields-data-ready", false); + ASSERT_TRUE(extension_listener.WaitUntilSatisfied()); +} // Load a page with an ad image, and make sure it is blocked. IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, AdsGetBlockedByDefaultBlocker) { - SetDefaultComponentIdAndBase64PublicKeyForTest( - kDefaultAdBlockComponentTestId, - kDefaultAdBlockComponentTestBase64PublicKey); ASSERT_TRUE(InstallDefaultAdBlockExtension()); EXPECT_EQ(browser()->profile()->GetPrefs()->GetUint64(kAdsBlocked), 0ULL); @@ -357,9 +346,6 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, CustomBlockDefaultException) { // blocked. IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, NotAdsDoNotGetBlockedByDefaultBlocker) { - SetDefaultComponentIdAndBase64PublicKeyForTest( - kDefaultAdBlockComponentTestId, - kDefaultAdBlockComponentTestBase64PublicKey); ASSERT_TRUE(InstallDefaultAdBlockExtension()); EXPECT_EQ(browser()->profile()->GetPrefs()->GetUint64(kAdsBlocked), 0ULL); @@ -382,9 +368,6 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, AdsGetBlockedByRegionalBlocker) { EXPECT_EQ(browser()->profile()->GetPrefs()->GetUint64(kAdsBlocked), 0ULL); - SetRegionalComponentIdAndBase64PublicKeyForTest( - kRegionalAdBlockComponentTestId, - kRegionalAdBlockComponentTestBase64PublicKey); ASSERT_TRUE(InstallRegionalAdBlockExtension(kAdBlockEasyListFranceUUID)); ASSERT_TRUE(StartAdBlockRegionalServices()); @@ -408,9 +391,6 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, EXPECT_EQ(browser()->profile()->GetPrefs()->GetUint64(kAdsBlocked), 0ULL); - SetRegionalComponentIdAndBase64PublicKeyForTest( - kRegionalAdBlockComponentTestId, - kRegionalAdBlockComponentTestBase64PublicKey); ASSERT_TRUE(InstallRegionalAdBlockExtension(kAdBlockEasyListFranceUUID)); ASSERT_TRUE(StartAdBlockRegionalServices()); @@ -429,10 +409,6 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, // is blocked. IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, AdsGetBlockedAfterDataFileVersionUpgrade) { - SetDefaultComponentIdAndBase64PublicKeyForTest( - kDefaultAdBlockComponentTestId, - kDefaultAdBlockComponentTestBase64PublicKey); - // Install AdBlock extension with a version 3 format data file and // expect a new install ASSERT_TRUE(InstallDefaultAdBlockExtension("adblock-v3", 1)); @@ -457,9 +433,6 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, // Load a page with several of the same adblocked xhr requests, it should only // count 1. IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, TwoSameAdsGetCountedAsOne) { - SetDefaultComponentIdAndBase64PublicKeyForTest( - kDefaultAdBlockComponentTestId, - kDefaultAdBlockComponentTestBase64PublicKey); ASSERT_TRUE(InstallDefaultAdBlockExtension()); EXPECT_EQ(browser()->profile()->GetPrefs()->GetUint64(kAdsBlocked), 0ULL); @@ -482,9 +455,6 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, TwoSameAdsGetCountedAsOne) { // Load a page with different adblocked xhr requests, it should count each. IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, TwoDiffAdsGetCountedAsTwo) { - SetDefaultComponentIdAndBase64PublicKeyForTest( - kDefaultAdBlockComponentTestId, - kDefaultAdBlockComponentTestBase64PublicKey); ASSERT_TRUE(InstallDefaultAdBlockExtension()); EXPECT_EQ(browser()->profile()->GetPrefs()->GetUint64(kAdsBlocked), 0ULL); @@ -507,9 +477,6 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, TwoDiffAdsGetCountedAsTwo) { // New tab continues to count blocking the same resource IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, NewTabContinuesToBlock) { - SetDefaultComponentIdAndBase64PublicKeyForTest( - kDefaultAdBlockComponentTestId, - kDefaultAdBlockComponentTestBase64PublicKey); ASSERT_TRUE(InstallDefaultAdBlockExtension()); EXPECT_EQ(browser()->profile()->GetPrefs()->GetUint64(kAdsBlocked), 0ULL); @@ -536,9 +503,6 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, NewTabContinuesToBlock) { // XHRs and ads in a cross-site iframe are blocked as well. IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, SubFrame) { - SetDefaultComponentIdAndBase64PublicKeyForTest( - kDefaultAdBlockComponentTestId, - kDefaultAdBlockComponentTestBase64PublicKey); ASSERT_TRUE(InstallDefaultAdBlockExtension()); EXPECT_EQ(browser()->profile()->GetPrefs()->GetUint64(kAdsBlocked), 0ULL); @@ -597,9 +561,6 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, EXPECT_EQ(browser()->profile()->GetPrefs()->GetUint64(kAdsBlocked), 0ULL); - SetRegionalComponentIdAndBase64PublicKeyForTest( - kRegionalAdBlockComponentTestId, - kRegionalAdBlockComponentTestBase64PublicKey); ASSERT_TRUE(InstallRegionalAdBlockExtension(kAdBlockEasyListFranceUUID)); ASSERT_TRUE(StartAdBlockRegionalServices()); @@ -624,10 +585,10 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, AdBlockThirdPartyWorksByETLDP1) { ui_test_utils::NavigateToURL(browser(), tab_url); content::WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); - ASSERT_EQ(true, EvalJs(contents, - base::StringPrintf("setExpectations(1, 0, 0, 0);" - "addImage('%s')", - resource_url.spec().c_str()))); + ASSERT_EQ(true, + EvalJs(contents, base::StringPrintf("setExpectations(1, 0, 0, 0);" + "addImage('%s')", + resource_url.spec().c_str()))); EXPECT_EQ(browser()->profile()->GetPrefs()->GetUint64(kAdsBlocked), 0ULL); } @@ -641,10 +602,10 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, ui_test_utils::NavigateToURL(browser(), tab_url); content::WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); - ASSERT_EQ(true, EvalJs(contents, - base::StringPrintf("setExpectations(0, 1, 0, 0);" - "addImage('%s')", - resource_url.spec().c_str()))); + ASSERT_EQ(true, + EvalJs(contents, base::StringPrintf("setExpectations(0, 1, 0, 0);" + "addImage('%s')", + resource_url.spec().c_str()))); EXPECT_EQ(browser()->profile()->GetPrefs()->GetUint64(kAdsBlocked), 1ULL); } @@ -658,10 +619,10 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, BlockNYP) { ui_test_utils::NavigateToURL(browser(), tab_url); content::WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); - ASSERT_EQ(true, EvalJs(contents, - base::StringPrintf("setExpectations(0, 1, 0, 0);" - "addImage('%s')", - resource_url.spec().c_str()))); + ASSERT_EQ(true, + EvalJs(contents, base::StringPrintf("setExpectations(0, 1, 0, 0);" + "addImage('%s')", + resource_url.spec().c_str()))); EXPECT_EQ(browser()->profile()->GetPrefs()->GetUint64(kAdsBlocked), 1ULL); } @@ -705,10 +666,10 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, SocialButttonAdBlockTagTest) { ui_test_utils::NavigateToURL(browser(), tab_url); content::WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); - ASSERT_EQ(true, EvalJs(contents, - base::StringPrintf("setExpectations(0, 1, 0, 0);" - "addImage('%s')", - resource_url.spec().c_str()))); + ASSERT_EQ(true, + EvalJs(contents, base::StringPrintf("setExpectations(0, 1, 0, 0);" + "addImage('%s')", + resource_url.spec().c_str()))); EXPECT_EQ(browser()->profile()->GetPrefs()->GetUint64(kAdsBlocked), 1ULL); } @@ -725,10 +686,10 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, SocialButttonAdBlockDiffTagTest) { ui_test_utils::NavigateToURL(browser(), tab_url); content::WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); - ASSERT_EQ(true, EvalJs(contents, - base::StringPrintf("setExpectations(1, 0, 0, 0);" - "addImage('%s')", - resource_url.spec().c_str()))); + ASSERT_EQ(true, + EvalJs(contents, base::StringPrintf("setExpectations(1, 0, 0, 0);" + "addImage('%s')", + resource_url.spec().c_str()))); EXPECT_EQ(browser()->profile()->GetPrefs()->GetUint64(kAdsBlocked), 0ULL); } @@ -791,9 +752,8 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, TagPrefsControlTags) { // Load a page with a script which uses a redirect data URL. IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, RedirectRulesAreRespected) { - UpdateAdBlockInstanceWithRules( - "js_mock_me.js$redirect=noopjs", - R"( + UpdateAdBlockInstanceWithRules("js_mock_me.js$redirect=noopjs", + R"( [ { "name": "noop.js", @@ -1035,8 +995,8 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, CosmeticFilteringGenerichide) { WaitForBraveExtensionShieldsDataReady(); - GURL tab_url = embedded_test_server()->GetURL("b.com", - "/cosmetic_filtering.html"); + GURL tab_url = + embedded_test_server()->GetURL("b.com", "/cosmetic_filtering.html"); ui_test_utils::NavigateToURL(browser(), tab_url); content::WebContents* contents = @@ -1053,14 +1013,13 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, CosmeticFilteringGenerichide) { } // Test custom style rules -IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, - CosmeticFilteringCustomStyle) { +IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, CosmeticFilteringCustomStyle) { UpdateAdBlockInstanceWithRules("b.com##.ad:style(padding-bottom: 10px)"); WaitForBraveExtensionShieldsDataReady(); - GURL tab_url = embedded_test_server()->GetURL("b.com", - "/cosmetic_filtering.html"); + GURL tab_url = + embedded_test_server()->GetURL("b.com", "/cosmetic_filtering.html"); ui_test_utils::NavigateToURL(browser(), tab_url); content::WebContents* contents = @@ -1089,8 +1048,8 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, CosmeticFilteringUnhide) { WaitForBraveExtensionShieldsDataReady(); - GURL tab_url = embedded_test_server()->GetURL("b.com", - "/cosmetic_filtering.html"); + GURL tab_url = + embedded_test_server()->GetURL("b.com", "/cosmetic_filtering.html"); ui_test_utils::NavigateToURL(browser(), tab_url); content::WebContents* contents = @@ -1122,8 +1081,7 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, CosmeticFilteringUnhide) { } // Test scriptlet injection that modifies window attributes -IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, - CosmeticFilteringWindowScriptlet) { +IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, CosmeticFilteringWindowScriptlet) { /* "content" below corresponds to the following scriptlet: * ``` * (function() { @@ -1134,19 +1092,21 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, * })(); * ``` */ - UpdateAdBlockInstanceWithRules("b.com##+js(hjt)", "[{" - "\"name\": \"hijacktest\"," - "\"aliases\": [\"hjt\"]," - "\"kind\": {\"mime\": \"application/javascript\"}," - "\"content\": \"KGZ1bmN0aW9uKCkgewogIGNvbnN0IHNlbmQgPSB3aW5kb3cuZ2V0" - "Q29tcHV0ZWRTdHlsZTsKICB3aW5kb3cuZ2V0Q29tcHV0ZWRTdHlsZSA9IGZ1bmN0aW9" - "uKHNlbGVjdG9yKSB7CiAgICByZXR1cm4geyAnY29sb3InOiAnSW1wb3NzaWJsZSB2YW" - "x1ZScgfTsKICB9Cn0pKCk7Cg==\"}]"); + UpdateAdBlockInstanceWithRules( + "b.com##+js(hjt)", + "[{" + "\"name\": \"hijacktest\"," + "\"aliases\": [\"hjt\"]," + "\"kind\": {\"mime\": \"application/javascript\"}," + "\"content\": \"KGZ1bmN0aW9uKCkgewogIGNvbnN0IHNlbmQgPSB3aW5kb3cuZ2V0" + "Q29tcHV0ZWRTdHlsZTsKICB3aW5kb3cuZ2V0Q29tcHV0ZWRTdHlsZSA9IGZ1bmN0aW9" + "uKHNlbGVjdG9yKSB7CiAgICByZXR1cm4geyAnY29sb3InOiAnSW1wb3NzaWJsZSB2YW" + "x1ZScgfTsKICB9Cn0pKCk7Cg==\"}]"); WaitForBraveExtensionShieldsDataReady(); - GURL tab_url = embedded_test_server()->GetURL("b.com", - "/cosmetic_filtering.html"); + GURL tab_url = + embedded_test_server()->GetURL("b.com", "/cosmetic_filtering.html"); ui_test_utils::NavigateToURL(browser(), tab_url); content::WebContents* contents = @@ -1166,23 +1126,26 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, } // Test scriptlet injection that modifies window attributes -IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, - CosmeticFilteringIframeScriptlet) { - std::string scriptlet = "(function() {" +IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, CosmeticFilteringIframeScriptlet) { + std::string scriptlet = + "(function() {" " window.JSON.parse = function() { return {} }" "})();"; std::string scriptlet_base64; base::Base64Encode(scriptlet, &scriptlet_base64); - UpdateAdBlockInstanceWithRules("b.com##+js(hjt)", "[{" - "\"name\": \"hijacktest\"," - "\"aliases\": [\"hjt\"]," - "\"kind\": {\"mime\": \"application/javascript\"}," - "\"content\": \"" + scriptlet_base64 + "\"}]"); + UpdateAdBlockInstanceWithRules( + "b.com##+js(hjt)", + "[{" + "\"name\": \"hijacktest\"," + "\"aliases\": [\"hjt\"]," + "\"kind\": {\"mime\": \"application/javascript\"}," + "\"content\": \"" + + scriptlet_base64 + "\"}]"); WaitForBraveExtensionShieldsDataReady(); - GURL tab_url = embedded_test_server()->GetURL("b.com", - "/iframe_messenger.html"); + GURL tab_url = + embedded_test_server()->GetURL("b.com", "/iframe_messenger.html"); ui_test_utils::NavigateToURL(browser(), tab_url); content::WebContents* contents = diff --git a/browser/brave_shields/ad_block_service_browsertest.h b/browser/brave_shields/ad_block_service_browsertest.h new file mode 100644 index 000000000000..711679388309 --- /dev/null +++ b/browser/brave_shields/ad_block_service_browsertest.h @@ -0,0 +1,44 @@ +/* Copyright (c) 2021 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_BROWSER_BRAVE_SHIELDS_AD_BLOCK_SERVICE_BROWSERTEST_H_ +#define BRAVE_BROWSER_BRAVE_SHIELDS_AD_BLOCK_SERVICE_BROWSERTEST_H_ + +#include + +#include "chrome/browser/extensions/extension_browsertest.h" + +class HostContentSettingsMap; + +class AdBlockServiceTest : public extensions::ExtensionBrowserTest { + public: + AdBlockServiceTest() {} + + // ExtensionBrowserTest overrides + void SetUpOnMainThread() override; + void SetUp() override; + void PreRunTestOnMainThread() override; + + protected: + HostContentSettingsMap* content_settings(); + void UpdateAdBlockInstanceWithRules(const std::string& rules, + const std::string& resources = ""); + void AssertTagExists(const std::string& tag, bool expected_exists) const; + void InitEmbeddedTestServer(); + void GetTestDataDir(base::FilePath* test_data_dir); + void SetDefaultComponentIdAndBase64PublicKeyForTest(); + void InitTrackingProtectionService(); + void SetRegionalComponentIdAndBase64PublicKeyForTest(); + bool InstallDefaultAdBlockExtension( + const std::string& extension_dir = "adblock-default", + int expected_change = 1); + bool InstallRegionalAdBlockExtension(const std::string& uuid); + bool InstallTrackingProtectionExtension(); + bool StartAdBlockRegionalServices(); + void WaitForAdBlockServiceThreads(); + void WaitForBraveExtensionShieldsDataReady(); +}; + +#endif // BRAVE_BROWSER_BRAVE_SHIELDS_AD_BLOCK_SERVICE_BROWSERTEST_H_ diff --git a/browser/brave_shields/domain_block_page_browsertest.cc b/browser/brave_shields/domain_block_page_browsertest.cc new file mode 100644 index 000000000000..452ed46e7cd1 --- /dev/null +++ b/browser/brave_shields/domain_block_page_browsertest.cc @@ -0,0 +1,283 @@ +/* Copyright (c) 2021 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/browser/brave_shields/ad_block_service_browsertest.h" + +#include "base/strings/utf_string_conversions.h" +#include "brave/browser/brave_browser_process_impl.h" +#include "brave/components/brave_shields/browser/ad_block_custom_filters_service.h" +#include "chrome/browser/extensions/extension_browsertest.h" +#include "chrome/browser/interstitials/security_interstitial_page_test_utils.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/test/base/testing_browser_process.h" +#include "chrome/test/base/ui_test_utils.h" +#include "components/security_interstitials/content/security_interstitial_tab_helper.h" +#include "content/public/browser/render_frame_host.h" +#include "content/public/browser/web_contents.h" +#include "content/public/test/browser_test.h" +#include "content/public/test/browser_test_utils.h" +#include "content/public/test/test_navigation_observer.h" +#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h" +#include "services/network/test/test_url_loader_factory.h" +#include "url/gurl.h" + +class DomainBlockTest : public AdBlockServiceTest { + public: + DomainBlockTest() {} + + void BlockDomainByURL(const GURL& url) { + UpdateAdBlockInstanceWithRules("||" + url.host() + "^"); + } + + content::WebContents* web_contents() { + content::WebContents* web_contents = + browser()->tab_strip_model()->GetActiveWebContents(); + DCHECK(web_contents); + return web_contents; + } + + bool IsShowingInterstitial() { + return chrome_browser_interstitials::IsShowingInterstitial(web_contents()); + } + + void NavigateTo(const GURL& url) { + ui_test_utils::NavigateToURL(browser(), url); + content::RenderFrameHost* frame = web_contents()->GetMainFrame(); + ASSERT_TRUE(WaitForRenderFrameReady(frame)); + } + + void Click(const std::string& id) { + content::RenderFrameHost* frame = web_contents()->GetMainFrame(); + frame->ExecuteJavaScriptForTests( + base::ASCIIToUTF16("document.getElementById('" + id + "').click();\n"), + base::NullCallback()); + } + + void ClickAndWaitForNavigation(const std::string& id) { + content::TestNavigationObserver observer(web_contents()); + Click(id); + observer.WaitForNavigationFinished(); + } + + protected: + network::TestURLLoaderFactory test_url_loader_factory_; + + private: + DISALLOW_COPY_AND_ASSIGN(DomainBlockTest); +}; + +IN_PROC_BROWSER_TEST_F(DomainBlockTest, ShowInterstitial) { + ASSERT_TRUE(InstallDefaultAdBlockExtension()); + GURL url = embedded_test_server()->GetURL("a.com", "/simple.html"); + + // Navigate to a page on a.com. This should work normally. + NavigateTo(url); + ASSERT_FALSE(IsShowingInterstitial()); + + // Block a.com, then attempt to navigate to a page on a.com. This should be + // interrupted by the domain block interstitial. + BlockDomainByURL(url); + NavigateTo(url); + ASSERT_TRUE(IsShowingInterstitial()); +} + +IN_PROC_BROWSER_TEST_F(DomainBlockTest, ShowInterstitialAndProceed) { + ASSERT_TRUE(InstallDefaultAdBlockExtension()); + GURL url = embedded_test_server()->GetURL("a.com", "/simple.html"); + + // Navigate to a page on a.com. This should work normally. + NavigateTo(url); + ASSERT_FALSE(IsShowingInterstitial()); + + // Block a.com, then attempt to navigate to a page on a.com. This should be + // interrupted by the domain block interstitial. + BlockDomainByURL(url); + NavigateTo(url); + ASSERT_TRUE(IsShowingInterstitial()); + + // Simulate click on "Proceed anyway" button. This should navigate to the + // originally requested page. + ClickAndWaitForNavigation("proceed-button"); + ASSERT_FALSE(IsShowingInterstitial()); + base::string16 expected_title = base::ASCIIToUTF16("OK"); + content::TitleWatcher watcher(web_contents(), expected_title); + EXPECT_EQ(expected_title, watcher.WaitAndGetTitle()); +} + +IN_PROC_BROWSER_TEST_F(DomainBlockTest, ShowInterstitialAndReload) { + ASSERT_TRUE(InstallDefaultAdBlockExtension()); + GURL url = embedded_test_server()->GetURL("a.com", "/simple.html"); + + // Navigate to a page on a.com. This should work normally. + NavigateTo(url); + ASSERT_FALSE(IsShowingInterstitial()); + + // Block a.com, then attempt to navigate to a page on a.com. This should be + // interrupted by the domain block interstitial. + BlockDomainByURL(url); + NavigateTo(url); + ASSERT_TRUE(IsShowingInterstitial()); + + // Attempt to reload page, which should again be interrupted by the + // interstitial. + web_contents()->GetController().Reload(content::ReloadType::NORMAL, true); + ASSERT_TRUE(IsShowingInterstitial()); +} + +IN_PROC_BROWSER_TEST_F(DomainBlockTest, ProceedAndReload) { + ASSERT_TRUE(InstallDefaultAdBlockExtension()); + GURL url = embedded_test_server()->GetURL("a.com", "/simple.html"); + + // Navigate to a page on a.com. This should work normally. + NavigateTo(url); + ASSERT_FALSE(IsShowingInterstitial()); + + // Block a.com, then attempt to navigate to a page on a.com. This should be + // interrupted by the domain block interstitial. + BlockDomainByURL(url); + NavigateTo(url); + ASSERT_TRUE(IsShowingInterstitial()); + + // Simulate click on "Proceed anyway" button. This should navigate to the + // originally requested page. + ClickAndWaitForNavigation("proceed-button"); + ASSERT_FALSE(IsShowingInterstitial()); + base::string16 expected_title = base::ASCIIToUTF16("OK"); + content::TitleWatcher watcher(web_contents(), expected_title); + EXPECT_EQ(expected_title, watcher.WaitAndGetTitle()); + + // Reload page. This should work normally and not by interrupted by the + // interstitial, because we chose to proceed in this tab, and that decision + // should persist for the lifetime of the tab. + web_contents()->GetController().Reload(content::ReloadType::NORMAL, true); + ASSERT_FALSE(IsShowingInterstitial()); + content::TitleWatcher watcher2(web_contents(), expected_title); + EXPECT_EQ(expected_title, watcher2.WaitAndGetTitle()); + EXPECT_EQ(web_contents()->GetURL().host(), "a.com"); +} + +IN_PROC_BROWSER_TEST_F(DomainBlockTest, ProceedDoesNotAffectNewTabs) { + ASSERT_TRUE(InstallDefaultAdBlockExtension()); + GURL url = embedded_test_server()->GetURL("a.com", "/simple.html"); + + // Navigate to a page on a.com. This should work normally. + NavigateTo(url); + ASSERT_FALSE(IsShowingInterstitial()); + + // Block a.com, then attempt to navigate to a page on a.com. This should be + // interrupted by the domain block interstitial. + BlockDomainByURL(url); + NavigateTo(url); + ASSERT_TRUE(IsShowingInterstitial()); + + // Simulate click on "Proceed anyway" button. This should navigate to the + // originally requested page. + ClickAndWaitForNavigation("proceed-button"); + ASSERT_FALSE(IsShowingInterstitial()); + base::string16 expected_title = base::ASCIIToUTF16("OK"); + content::TitleWatcher watcher(web_contents(), expected_title); + EXPECT_EQ(expected_title, watcher.WaitAndGetTitle()); + + // Open a new tab and navigate to a page on a.com. This should be interrupted + // by the domain block interstitial, because the permission we gave by + // clicking "Proceed anyway" in the other tab is tab-specific. + ui_test_utils::AllBrowserTabAddedWaiter new_tab; + ui_test_utils::NavigateToURLWithDisposition( + browser(), url, WindowOpenDisposition::NEW_FOREGROUND_TAB, + ui_test_utils::BROWSER_TEST_WAIT_FOR_LOAD_STOP); + new_tab.Wait(); + ASSERT_TRUE(IsShowingInterstitial()); +} + +IN_PROC_BROWSER_TEST_F(DomainBlockTest, DontWarnAgainAndProceed) { + ASSERT_TRUE(InstallDefaultAdBlockExtension()); + GURL url = embedded_test_server()->GetURL("a.com", "/simple.html"); + + // Navigate to a page on a.com. This should work normally. + NavigateTo(url); + ASSERT_FALSE(IsShowingInterstitial()); + + // Block a.com, then attempt to navigate to a page on a.com. This should be + // interrupted by the domain block interstitial. + BlockDomainByURL(url); + NavigateTo(url); + ASSERT_TRUE(IsShowingInterstitial()); + + // Simulate click on "Don't warn again" checkbox. This should not navigate. + // We should still be on the interstitial page. + Click("dont-warn-again-checkbox"); + ASSERT_TRUE(IsShowingInterstitial()); + + // Simulate click on "Proceed anyway" button. This should save the "don't warn + // again" choice and navigate to the originally requested page. + ClickAndWaitForNavigation("proceed-button"); + WaitForAdBlockServiceThreads(); + ASSERT_FALSE(IsShowingInterstitial()); + base::string16 expected_title = base::ASCIIToUTF16("OK"); + content::TitleWatcher watcher(web_contents(), expected_title); + EXPECT_EQ(expected_title, watcher.WaitAndGetTitle()); + + // Open a new tab and navigate to a page on a.com. This should navigate + // directly, because we previously saved the "don't warn again" choice for + // this domain and are now respecting that choice. + ui_test_utils::AllBrowserTabAddedWaiter new_tab; + ui_test_utils::NavigateToURLWithDisposition( + browser(), url, WindowOpenDisposition::NEW_FOREGROUND_TAB, + ui_test_utils::BROWSER_TEST_WAIT_FOR_LOAD_STOP); + new_tab.Wait(); + ASSERT_FALSE(IsShowingInterstitial()); + EXPECT_EQ(web_contents()->GetURL().host(), "a.com"); +} + +IN_PROC_BROWSER_TEST_F(DomainBlockTest, ShowInterstitialAndGoBack) { + ASSERT_TRUE(InstallDefaultAdBlockExtension()); + GURL url_a = embedded_test_server()->GetURL("a.com", "/simple.html"); + GURL url_b = embedded_test_server()->GetURL("b.com", "/simple.html"); + + // Navigate to a page on a.com. This should work normally. + NavigateTo(url_a); + ASSERT_FALSE(IsShowingInterstitial()); + + // Block b.com, then attempt to navigate to a page on b.com, which should be + // interrupted by the domain block interstitial + BlockDomainByURL(url_b); + NavigateTo(url_b); + ASSERT_TRUE(IsShowingInterstitial()); + + // Simulate click on "Go back" button. This should return to previous page on + // a.com. + ClickAndWaitForNavigation("primary-button"); + ASSERT_FALSE(IsShowingInterstitial()); + EXPECT_EQ(web_contents()->GetURL().host(), "a.com"); +} + +IN_PROC_BROWSER_TEST_F(DomainBlockTest, NoFetch) { + ASSERT_TRUE(InstallDefaultAdBlockExtension()); + GURL url = embedded_test_server()->GetURL("a.com", "/simple.html"); + + // Navigate to a page on a.com. This should work normally. + NavigateTo(url); + ASSERT_FALSE(IsShowingInterstitial()); + + // Block a.com, then attempt to navigate to a page on a.com. This should be + // interrupted by the domain block interstitial. + BlockDomainByURL(url); + + // Temporarily swap out the global URL loader factory and replace it with + // our own so we can monitor all outgoing network traffic by the entire + // browser. + scoped_refptr old_factory = + TestingBrowserProcess::GetGlobal()->shared_url_loader_factory(); + TestingBrowserProcess::GetGlobal()->SetSharedURLLoaderFactory( + test_url_loader_factory_.GetSafeWeakWrapper()); + NavigateTo(url); + ASSERT_TRUE(IsShowingInterstitial()); + + // Should be zero network traffic since we started monitoring. + ASSERT_EQ(test_url_loader_factory_.NumPending(), 0); + + // Restore URL loader factory so test environment can clean up properly. + TestingBrowserProcess::GetGlobal()->SetSharedURLLoaderFactory(old_factory); +} diff --git a/build/rust/Cargo.lock b/build/rust/Cargo.lock index 2a2b28c1e00f..0d0d288432d0 100644 --- a/build/rust/Cargo.lock +++ b/build/rust/Cargo.lock @@ -11,7 +11,7 @@ dependencies = [ "bitflags", "flate2", "hashbrown", - "idna 0.2.0", + "idna 0.2.2", "itertools 0.8.2", "lazy_static", "lifeguard", @@ -24,18 +24,18 @@ dependencies = [ "seahash", "serde", "twoway", - "url 2.1.1", + "url 2.2.1", ] [[package]] name = "adblock" -version = "0.3.4" -source = "git+https://github.com/brave/adblock-rust?rev=c647890b6d065daf98cba540d2232c100698c498#c647890b6d065daf98cba540d2232c100698c498" +version = "0.3.5" +source = "git+https://github.com/brave/adblock-rust?rev=732994bf57f4a5c7f3a2a7b873a97571737def42#732994bf57f4a5c7f3a2a7b873a97571737def42" dependencies = [ "base64 0.13.0", "bitflags", "flate2", - "idna 0.2.0", + "idna 0.2.2", "itertools 0.9.0", "lifeguard", "once_cell", @@ -45,14 +45,14 @@ dependencies = [ "seahash", "serde", "twoway", - "url 2.1.1", + "url 2.2.1", ] [[package]] name = "adblock-ffi" version = "0.1.0" dependencies = [ - "adblock 0.3.4", + "adblock 0.3.5", "libc", "serde_json", ] @@ -73,9 +73,9 @@ dependencies = [ [[package]] name = "addr2line" -version = "0.13.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b6a2d3371669ab3ca9797670853d61402b03d0b4b9ebf33d677dfa720203072" +checksum = "a55f82cfe485775d02112886f4169bde0c5894d75e79ead7eafe7e40a25e45f7" dependencies = [ "gimli", ] @@ -97,9 +97,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "0.7.13" +version = "0.7.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "043164d8ba5c4c3035fec9bbee8647c0261d788f3474306f93bb65901cae0e86" +checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5" dependencies = [ "memchr", ] @@ -112,18 +112,18 @@ checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" [[package]] name = "autocfg" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "backtrace" -version = "0.3.50" +version = "0.3.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46254cf2fdcdf1badb5934448c1bcbe046a56537b3987d96c51a7afc5d03f293" +checksum = "9d117600f438b1707d4e4ae15d3595657288f8235a0eb593e80ecc98ab34e1bc" dependencies = [ "addr2line", - "cfg-if 0.1.10", + "cfg-if 1.0.0", "libc", "miniz_oxide", "object", @@ -199,15 +199,15 @@ checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" [[package]] name = "byteorder" -version = "1.3.4" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" +checksum = "ae44d1a3d5a19df61dd0c8beb138458ac2a53a7ac09eba97d55592540004306b" [[package]] name = "cc" -version = "1.0.58" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a06fb2e53271d7c279ec1efea6ab691c35a2ae67ec0d91d7acec0caf13b518" +checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" [[package]] name = "cfg-if" @@ -290,9 +290,9 @@ dependencies = [ [[package]] name = "core-foundation" -version = "0.7.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171" +checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62" dependencies = [ "core-foundation-sys", "libc", @@ -300,17 +300,17 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.7.0" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" +checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" [[package]] name = "crc32fast" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" +checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", ] [[package]] @@ -343,7 +343,7 @@ dependencies = [ "phf 0.7.24", "proc-macro2 1.0.24", "procedural-masquerade", - "quote 1.0.7", + "quote 1.0.9", "smallvec", "syn 1.0.60", ] @@ -356,21 +356,21 @@ dependencies = [ "phf_codegen 0.7.24", "proc-macro2 1.0.24", "procedural-masquerade", - "quote 1.0.7", + "quote 1.0.9", "syn 1.0.60", ] [[package]] name = "curve25519-dalek" -version = "1.2.4" +version = "1.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "405681bfe2b7b25ad8660dfd90b6e8be9e470e224ff49e36b587d43f29a22601" +checksum = "57c0d59fed08e452f286b251f88b2fc64a01f50a7b263aa09557ad7285d9e7fa" dependencies = [ "byteorder", "clear_on_drop", "digest", "rand_core 0.3.1", - "subtle 2.2.3", + "subtle 2.4.0", ] [[package]] @@ -384,32 +384,32 @@ dependencies = [ [[package]] name = "dtoa" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134951f4028bdadb9b84baf4232681efbf277da25144b9b0ad65df75946c422b" +checksum = "88d7ed2934d741c6b37e33e3832298e8850b53fd2d2bea03873375596c7cea4e" [[package]] name = "dtoa-short" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59020b8513b76630c49d918c33db9f4c91638e7d3404a28084083b87e33f76f2" +checksum = "bde03329ae10e79ede66c9ce4dc930aa8599043b0743008548680f25b91502d6" dependencies = [ "dtoa", ] [[package]] name = "either" -version = "1.6.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd56b59865bce947ac5958779cfa508f6c3b9497cc762b7e24a12d11ccde2c4f" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" [[package]] name = "encoding_rs" -version = "0.8.23" +version = "0.8.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8ac63f94732332f44fe654443c46f6375d1939684c17b0afb6cb56b0456e171" +checksum = "80df024fbc5ac80f87dfef0d9f5209a252f2a497f7f42944cff24d8253cac065" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", ] [[package]] @@ -455,6 +455,16 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" +[[package]] +name = "form_urlencoded" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +dependencies = [ + "matches", + "percent-encoding 2.1.0", +] + [[package]] name = "fuchsia-cprng" version = "0.1.1" @@ -491,11 +501,11 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.1.14" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "libc", "wasi 0.9.0+wasi-snapshot-preview1", ] @@ -508,14 +518,14 @@ checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" dependencies = [ "cfg-if 1.0.0", "libc", - "wasi 0.10.1+wasi-snapshot-preview1", + "wasi 0.10.2+wasi-snapshot-preview1", ] [[package]] name = "gimli" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724" +checksum = "f6503fe142514ca4799d4c26297c4248239fe8838d827db6bd6065c6ed29a6ce" [[package]] name = "hashbrown" @@ -548,7 +558,7 @@ dependencies = [ "mac", "markup5ever", "proc-macro2 1.0.24", - "quote 1.0.7", + "quote 1.0.9", "syn 1.0.60", ] @@ -565,9 +575,9 @@ dependencies = [ [[package]] name = "idna" -version = "0.2.0" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" +checksum = "89829a5d69c23d348314a7ac337fe39173b61149a9864deabd260983aed48c21" dependencies = [ "matches", "unicode-bidi", @@ -594,9 +604,9 @@ dependencies = [ [[package]] name = "itoa" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" +checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" [[package]] name = "lazy_static" @@ -606,9 +616,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "lazycell" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" @@ -630,11 +640,11 @@ checksum = "89be94dbd775db37b46ca4f4bf5cf89adfb13ba197bfbcb69b2122848ee73c26" [[package]] name = "log" -version = "0.4.11" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", ] [[package]] @@ -704,24 +714,25 @@ checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" [[package]] name = "memchr" -version = "2.3.3" +version = "2.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" +checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" [[package]] name = "miniz_oxide" -version = "0.4.0" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be0f75932c1f6cfae3c04000e40114adf955636e19040f9c0a2c380702aa1c7f" +checksum = "0f2d26ec3309788e423cfbf68ad1800f061638098d76a83681af979dc4eda19d" dependencies = [ "adler", + "autocfg 1.0.1", ] [[package]] name = "native-tls" -version = "0.2.4" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b0d88c06fe90d5ee94048ba40409ef1d9315d86f6f38c2efdaad4fb50c58b2d" +checksum = "b8d96b2e1c8da3957d58100b09f102c6d9cfdfced01b7ec5a8974044bb09dbd4" dependencies = [ "lazy_static", "libc", @@ -749,18 +760,18 @@ checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" [[package]] name = "num-traits" -version = "0.2.12" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" dependencies = [ - "autocfg 1.0.0", + "autocfg 1.0.1", ] [[package]] name = "object" -version = "0.20.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ab52be62400ca80aa00285d25253d7f7c437b7375c4de678f5405d3afe82ca5" +checksum = "a9a7ab5d64814df0fe4a4b5ead45ed6c5f181ee3ff04ba344313a6c80446c5d4" [[package]] name = "once_cell" @@ -776,12 +787,12 @@ checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" [[package]] name = "openssl" -version = "0.10.30" +version = "0.10.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d575eff3665419f9b83678ff2815858ad9d11567e082f5ac1814baba4e2bcb4" +checksum = "038d43985d1ddca7a9900630d8cd031b56e4794eecc2e9ea39dd17aa04399a70" dependencies = [ "bitflags", - "cfg-if 0.1.10", + "cfg-if 1.0.0", "foreign-types", "lazy_static", "libc", @@ -796,11 +807,11 @@ checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" [[package]] name = "openssl-sys" -version = "0.9.58" +version = "0.9.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a842db4709b604f0fe5d1170ae3565899be2ad3d9cbc72dedc789ac0511f78de" +checksum = "921fc71883267538946025deffb622905ecad223c28efbfdef9bb59a0175f3e6" dependencies = [ - "autocfg 1.0.0", + "autocfg 1.0.1", "cc", "libc", "pkg-config", @@ -897,15 +908,15 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.18" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33" +checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" [[package]] name = "ppv-lite86" -version = "0.2.8" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea" +checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" [[package]] name = "precomputed-hash" @@ -915,9 +926,9 @@ checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" [[package]] name = "proc-macro-hack" -version = "0.5.18" +version = "0.5.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99c605b9a0adc77b7211c6b1f722dcb613d68d66859a44f3d485a6da332b0598" +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" [[package]] name = "proc-macro2" @@ -989,9 +1000,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.7" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" dependencies = [ "proc-macro2 1.0.24", ] @@ -1021,7 +1032,7 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ - "getrandom 0.1.14", + "getrandom 0.1.16", "libc", "rand_chacha 0.2.2", "rand_core 0.5.1", @@ -1029,6 +1040,18 @@ dependencies = [ "rand_pcg 0.2.1", ] +[[package]] +name = "rand" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" +dependencies = [ + "libc", + "rand_chacha 0.3.0", + "rand_core 0.6.2", + "rand_hc 0.3.0", +] + [[package]] name = "rand_chacha" version = "0.1.1" @@ -1049,6 +1072,16 @@ dependencies = [ "rand_core 0.5.1", ] +[[package]] +name = "rand_chacha" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.2", +] + [[package]] name = "rand_core" version = "0.3.1" @@ -1070,7 +1103,16 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" dependencies = [ - "getrandom 0.1.14", + "getrandom 0.1.16", +] + +[[package]] +name = "rand_core" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" +dependencies = [ + "getrandom 0.2.2", ] [[package]] @@ -1091,6 +1133,15 @@ dependencies = [ "rand_core 0.5.1", ] +[[package]] +name = "rand_hc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" +dependencies = [ + "rand_core 0.6.2", +] + [[package]] name = "rand_isaac" version = "0.1.1" @@ -1175,15 +1226,18 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.1.57" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" +checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9" +dependencies = [ + "bitflags", +] [[package]] name = "regex" -version = "1.4.2" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38cf2c13ed4745de91a5eb834e11c00bcc3709e773173b2ce4c56c9fbde04b9c" +checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a" dependencies = [ "aho-corasick", "memchr", @@ -1193,9 +1247,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.21" +version = "0.6.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189" +checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581" [[package]] name = "remove_dir_all" @@ -1223,15 +1277,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "475e68978dc5b743f2f40d8e0a8fdc83f1c5e78cbf4b8fa5e74e73beebc340de" dependencies = [ "proc-macro2 1.0.24", - "quote 1.0.7", + "quote 1.0.9", "syn 1.0.60", ] [[package]] name = "rmp" -version = "0.8.9" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f10b46df14cf1ee1ac7baa4d2fbc2c52c0622a4b82fa8740e37bc452ac0184f" +checksum = "4f55e5fa1446c4d5dd1f5daeed2a4fe193071771a2636274d0d7a3b082aa7ad6" dependencies = [ "byteorder", "num-traits", @@ -1250,9 +1304,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.16" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" +checksum = "6e3bad0ee36814ca07d7968269dd4b7ec89ec2da10c4bb613928d3077083c232" [[package]] name = "rustc_version" @@ -1293,9 +1347,9 @@ checksum = "58f57ca1d128a43733fd71d583e837b1f22239a37ebea09cde11d8d9a9080f47" [[package]] name = "security-framework" -version = "0.4.4" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64808902d7d99f78eaddd2b4e2509713babc3dc3c85ad6f4c447680f3c01e535" +checksum = "c1759c2e3c8580017a484a7ac56d3abc5a6c1feadf88db2f3633f12ae4268c69" dependencies = [ "bitflags", "core-foundation", @@ -1306,9 +1360,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "0.4.3" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17bf11d99252f512695eb468de5516e5cf75455521e69dfe343f3b74e4748405" +checksum = "f99b9d5e26d2a71633cc4f2ebae7cc9f874044e0c351a27e17892d76dce5678b" dependencies = [ "core-foundation-sys", "libc", @@ -1370,7 +1424,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9391c295d64fc0abb2c556bad848f33cb8296276b1ad2677d1ae1ace4f258f31" dependencies = [ "proc-macro2 1.0.24", - "quote 1.0.7", + "quote 1.0.9", "syn 1.0.60", ] @@ -1464,9 +1518,9 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "string_cache" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2940c75beb4e3bf3a494cef919a747a2cb81e52571e212bfbd185074add7208a" +checksum = "8ddb1139b5353f96e429e1a5e19fbaf663bddedaa06d1dbd49f82e352601209a" dependencies = [ "lazy_static", "new_debug_unreachable", @@ -1484,7 +1538,7 @@ dependencies = [ "phf_generator 0.8.0", "phf_shared 0.8.0", "proc-macro2 1.0.24", - "quote 1.0.7", + "quote 1.0.9", ] [[package]] @@ -1495,9 +1549,9 @@ checksum = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" [[package]] name = "subtle" -version = "2.2.3" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "502d53007c02d7605a05df1c1a73ee436952781653da5d0bf57ad608f66932c1" +checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" [[package]] name = "syn" @@ -1517,19 +1571,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081" dependencies = [ "proc-macro2 1.0.24", - "quote 1.0.7", + "quote 1.0.9", "unicode-xid 0.2.1", ] [[package]] name = "tempfile" -version = "3.1.0" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" +checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "libc", - "rand 0.7.3", + "rand 0.8.3", "redox_syscall", "remove_dir_all", "winapi", @@ -1537,9 +1591,9 @@ dependencies = [ [[package]] name = "tendril" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707feda9f2582d5d680d733e38755547a3e8fb471e7ba11452ecfd9ce93a5d3b" +checksum = "a9ef557cb397a4f0a5a3a628f06515f78563f2209e64d47055d9dc6052bf5e33" dependencies = [ "futf", "mac", @@ -1554,31 +1608,31 @@ checksum = "8eaa81235c7058867fa8c0e7314f33dcce9c215f535d1913822a2b3f5e289f3c" [[package]] name = "thiserror" -version = "1.0.23" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76cc616c6abf8c8928e2fdcc0dbfab37175edd8fb49a4641066ad1364fdab146" +checksum = "e0f4a65597094d4483ddaed134f409b2cb7c1beccf25201a9f73c719254fa98e" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.23" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9be73a2caec27583d0046ef3796c3794f868a5bc813db689eed00c7631275cd1" +checksum = "7765189610d8241a44529806d6fd1f2e0a08734313a35d5b3a556f92b381f3c0" dependencies = [ "proc-macro2 1.0.24", - "quote 1.0.7", + "quote 1.0.9", "syn 1.0.60", ] [[package]] name = "thread_local" -version = "1.0.1" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" +checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd" dependencies = [ - "lazy_static", + "once_cell", ] [[package]] @@ -1600,6 +1654,21 @@ dependencies = [ "crunchy", ] +[[package]] +name = "tinyvec" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "317cca572a0e89c3ce0ca1f1bdc9369547fe318a683418e42ac8f59d14701023" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + [[package]] name = "twoway" version = "0.2.1" @@ -1633,11 +1702,11 @@ dependencies = [ [[package]] name = "unicode-normalization" -version = "0.1.8" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426" +checksum = "07fbfce1c8a97d547e8b5334978438d9d6ec8c20e38f56d4a4374d181493eaef" dependencies = [ - "smallvec", + "tinyvec", ] [[package]] @@ -1665,11 +1734,12 @@ dependencies = [ [[package]] name = "url" -version = "2.1.1" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb" +checksum = "9ccd964113622c8e9322cfac19eb1004a07e636c545f325da085d5cdde6f1f8b" dependencies = [ - "idna 0.2.0", + "form_urlencoded", + "idna 0.2.2", "matches", "percent-encoding 2.1.0", ] @@ -1682,9 +1752,9 @@ checksum = "05e42f7c18b8f902290b009cde6d651262f956c98bc51bca4cd1d511c9cd85c7" [[package]] name = "vcpkg" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c" +checksum = "b00bca6106a5e23f3eee943593759b7fcddb00554332e856d990c893966879fb" [[package]] name = "version_check" @@ -1700,9 +1770,9 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasi" -version = "0.10.1+wasi-snapshot-preview1" +version = "0.10.2+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93c6c3420963c5c64bca373b25e77acb562081b9bb4dd5bb864187742186cea9" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "winapi" diff --git a/components/brave_shields/browser/BUILD.gn b/components/brave_shields/browser/BUILD.gn index 87156116d0a2..66ff785bb268 100644 --- a/components/brave_shields/browser/BUILD.gn +++ b/components/brave_shields/browser/BUILD.gn @@ -1,13 +1,12 @@ +import( + "//brave/components/brave_perf_predictor/browser/buildflags/buildflags.gni") import("//brave/components/brave_shields/browser/buildflags/buildflags.gni") -import("//brave/components/brave_perf_predictor/browser/buildflags/buildflags.gni") import("//extensions/buildflags/buildflags.gni") source_set("browser") { # Remove when https://github.com/brave/brave-browser/issues/10643 is resolved check_includes = false - public_deps = [ - "buildflags", - ] + public_deps = [ "buildflags" ] sources = [ "ad_block_base_service.cc", @@ -34,6 +33,14 @@ source_set("browser") { "brave_shields_web_contents_observer.h", "cookie_pref_service.cc", "cookie_pref_service.h", + "domain_block_controller_client.cc", + "domain_block_controller_client.h", + "domain_block_navigation_throttle.cc", + "domain_block_navigation_throttle.h", + "domain_block_page.cc", + "domain_block_page.h", + "domain_block_tab_storage.cc", + "domain_block_tab_storage.h", "https_everywhere_recently_used_cache.h", "https_everywhere_service.cc", "https_everywhere_service.h", @@ -75,8 +82,6 @@ source_set("browser") { ] if (enable_brave_perf_predictor) { - deps += [ - "//brave/components/brave_perf_predictor/browser", - ] + deps += [ "//brave/components/brave_perf_predictor/browser" ] } } diff --git a/components/brave_shields/browser/ad_block_service.h b/components/brave_shields/browser/ad_block_service.h index 02dbc7dc8eeb..8707eeaf3a62 100644 --- a/components/brave_shields/browser/ad_block_service.h +++ b/components/brave_shields/browser/ad_block_service.h @@ -20,6 +20,7 @@ #include "content/public/browser/browser_thread.h" class AdBlockServiceTest; +class DomainBlockTest; class PrefChangeRegistrar; class PrefService; @@ -75,6 +76,7 @@ class AdBlockService : public AdBlockBaseService { private: friend class ::AdBlockServiceTest; + friend class ::DomainBlockTest; static std::string g_ad_block_component_id_; static std::string g_ad_block_component_base64_public_key_; static std::string g_ad_block_dat_file_version_; diff --git a/components/brave_shields/browser/domain_block_controller_client.cc b/components/brave_shields/browser/domain_block_controller_client.cc new file mode 100644 index 000000000000..58f354ca597a --- /dev/null +++ b/components/brave_shields/browser/domain_block_controller_client.cc @@ -0,0 +1,69 @@ +/* Copyright (c) 2021 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/components/brave_shields/browser/domain_block_controller_client.h" + +#include "brave/components/brave_shields/browser/ad_block_custom_filters_service.h" +#include "brave/components/brave_shields/browser/domain_block_tab_storage.h" +#include "components/prefs/pref_service.h" +#include "components/security_interstitials/content/settings_page_helper.h" +#include "components/security_interstitials/core/metrics_helper.h" +#include "content/public/browser/page_navigator.h" +#include "content/public/browser/web_contents.h" +#include "content/public/common/referrer.h" +#include "ui/base/page_transition_types.h" +#include "ui/base/window_open_disposition.h" + +namespace brave_shields { + +// static +std::unique_ptr +DomainBlockControllerClient::GetMetricsHelper(const GURL& url) { + security_interstitials::MetricsHelper::ReportDetails report_details; + report_details.metric_prefix = "domain_block"; + + return std::make_unique( + url, report_details, nullptr); +} + +DomainBlockControllerClient::DomainBlockControllerClient( + content::WebContents* web_contents, + const GURL& request_url, + AdBlockCustomFiltersService* ad_block_custom_filters_service, + PrefService* prefs, + const std::string& locale) + : security_interstitials::SecurityInterstitialControllerClient( + web_contents, + GetMetricsHelper(request_url), + prefs, + locale, + GURL("about:blank") /* default_safe_page */, + nullptr /* settings_page_helper */), + request_url_(request_url), + ad_block_custom_filters_service_(ad_block_custom_filters_service), + dont_warn_again_(false) {} + +void DomainBlockControllerClient::GoBack() { + SecurityInterstitialControllerClient::GoBackAfterNavigationCommitted(); +} + +void DomainBlockControllerClient::Proceed() { + DomainBlockTabStorage* tab_storage = + DomainBlockTabStorage::GetOrCreate(web_contents_); + tab_storage->SetIsProceeding(true); + if (dont_warn_again_) { + std::string custom_filters = + ad_block_custom_filters_service_->GetCustomFilters(); + ad_block_custom_filters_service_->UpdateCustomFilters( + "@@||" + request_url_.host() + "^\n" + custom_filters); + } + web_contents_->GetController().Reload(content::ReloadType::NORMAL, false); +} + +void DomainBlockControllerClient::SetDontWarnAgain(bool value) { + dont_warn_again_ = value; +} + +} // namespace brave_shields diff --git a/components/brave_shields/browser/domain_block_controller_client.h b/components/brave_shields/browser/domain_block_controller_client.h new file mode 100644 index 000000000000..27403c8eb039 --- /dev/null +++ b/components/brave_shields/browser/domain_block_controller_client.h @@ -0,0 +1,59 @@ +/* Copyright (c) 2021 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_DOMAIN_BLOCK_CONTROLLER_CLIENT_H_ +#define BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_DOMAIN_BLOCK_CONTROLLER_CLIENT_H_ + +#include +#include + +#include "components/security_interstitials/content/security_interstitial_controller_client.h" +#include "url/gurl.h" + +namespace content { +class WebContents; +} // namespace content + +namespace security_interstitials { +class MetricsHelper; +} // namespace security_interstitials + +namespace brave_shields { + +class AdBlockCustomFiltersService; + +class DomainBlockControllerClient + : public security_interstitials::SecurityInterstitialControllerClient { + public: + static std::unique_ptr + GetMetricsHelper(const GURL& url); + + DomainBlockControllerClient( + content::WebContents* web_contents, + const GURL& request_url, + AdBlockCustomFiltersService* ad_block_custom_filters_service, + PrefService* prefs, + const std::string& locale); + ~DomainBlockControllerClient() override = default; + + DomainBlockControllerClient(const DomainBlockControllerClient&) = delete; + DomainBlockControllerClient& operator=(const DomainBlockControllerClient&) = + delete; + + void SetDontWarnAgain(bool value); + + // security_interstitials::SecurityInterstitialControllerClient: + void GoBack() override; + void Proceed() override; + + private: + const GURL request_url_; + AdBlockCustomFiltersService* ad_block_custom_filters_service_; + bool dont_warn_again_; +}; + +} // namespace brave_shields + +#endif // BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_DOMAIN_BLOCK_CONTROLLER_CLIENT_H_ diff --git a/components/brave_shields/browser/domain_block_navigation_throttle.cc b/components/brave_shields/browser/domain_block_navigation_throttle.cc new file mode 100644 index 000000000000..38d21a23bb3e --- /dev/null +++ b/components/brave_shields/browser/domain_block_navigation_throttle.cc @@ -0,0 +1,165 @@ +/* Copyright (c) 2021 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/components/brave_shields/browser/domain_block_navigation_throttle.h" + +#include +#include + +#include "base/bind.h" +#include "base/task/post_task.h" +#include "base/threading/thread_task_runner_handle.h" +#include "brave/components/brave_shields/browser/ad_block_custom_filters_service.h" +#include "brave/components/brave_shields/browser/ad_block_service.h" +#include "brave/components/brave_shields/browser/domain_block_controller_client.h" +#include "brave/components/brave_shields/browser/domain_block_page.h" +#include "brave/components/brave_shields/browser/domain_block_tab_storage.h" +#include "components/prefs/pref_service.h" +#include "components/security_interstitials/content/security_interstitial_tab_helper.h" +#include "components/user_prefs/user_prefs.h" +#include "content/public/browser/browser_context.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/browser/navigation_handle.h" +#include "content/public/browser/web_contents.h" +#include "content/public/browser/web_contents_user_data.h" +#include "net/base/net_errors.h" + +namespace { + +bool ShouldBlockDomainOnTaskRunner( + brave_shields::AdBlockService* ad_block_service, + const GURL& url) { + if (!ad_block_service->IsInitialized()) + return false; + bool did_match_exception = false; + bool did_match_rule = false; + bool did_match_important = false; + std::string mock_data_url; + ad_block_service->ShouldStartRequest( + url, blink::mojom::ResourceType::kMainFrame, url.host(), &did_match_rule, + &did_match_exception, &did_match_important, &mock_data_url); + return (did_match_important || (did_match_rule && !did_match_exception)); +} + +} // namespace + +namespace brave_shields { + +// static +std::unique_ptr +DomainBlockNavigationThrottle::MaybeCreateThrottleFor( + content::NavigationHandle* navigation_handle, + AdBlockService* ad_block_service, + AdBlockCustomFiltersService* ad_block_custom_filters_service, + const std::string& locale) { + if (!ad_block_service || !ad_block_custom_filters_service) + return nullptr; + return std::make_unique( + navigation_handle, ad_block_service, ad_block_custom_filters_service, + locale); +} + +DomainBlockNavigationThrottle::DomainBlockNavigationThrottle( + content::NavigationHandle* navigation_handle, + AdBlockService* ad_block_service, + AdBlockCustomFiltersService* ad_block_custom_filters_service, + const std::string& locale) + : content::NavigationThrottle(navigation_handle), + ad_block_service_(ad_block_service), + ad_block_custom_filters_service_(ad_block_custom_filters_service), + locale_(locale) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); +} + +DomainBlockNavigationThrottle::~DomainBlockNavigationThrottle() { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); +} + +content::NavigationThrottle::ThrottleCheckResult +DomainBlockNavigationThrottle::WillStartRequest() { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + + // Don't bother checking non-HTTP(S) pages + content::NavigationHandle* handle = navigation_handle(); + GURL request_url = handle->GetURL(); + if (!request_url.SchemeIsHTTPOrHTTPS()) + return content::NavigationThrottle::PROCEED; + + // If user has just chosen to proceed on our interstitial, don't show + // another one. + content::WebContents* web_contents = handle->GetWebContents(); + DomainBlockTabStorage* tab_storage = + DomainBlockTabStorage::GetOrCreate(web_contents); + if (tab_storage->IsProceeding()) + return content::NavigationThrottle::PROCEED; + + // Otherwise, call the ad block service on a task runner to determine whether + // this domain should be blocked. + ad_block_service_->GetTaskRunner()->PostTaskAndReplyWithResult( + FROM_HERE, + base::BindOnce(&ShouldBlockDomainOnTaskRunner, ad_block_service_, + request_url), + base::BindOnce(&DomainBlockNavigationThrottle::OnShouldBlockDomain, + weak_ptr_factory_.GetWeakPtr())); + + // Since the call to the ad block service is asynchronous, we defer the final + // decision of whether to allow or block this navigation. The callback from + // the task runner will call a method to give our final answer. + return content::NavigationThrottle::DEFER; +} + +void DomainBlockNavigationThrottle::OnShouldBlockDomain( + bool should_block_domain) { + if (should_block_domain) { + ShowInterstitial(); + } else { + // Navigation was deferred while we called the ad block service on a task + // runner, but now we know that we want to allow navigation to continue. + Resume(); + } +} + +void DomainBlockNavigationThrottle::ShowInterstitial() { + content::NavigationHandle* handle = navigation_handle(); + content::WebContents* web_contents = handle->GetWebContents(); + const GURL& request_url = handle->GetURL(); + content::BrowserContext* context = + handle->GetWebContents()->GetBrowserContext(); + PrefService* pref_service = user_prefs::UserPrefs::Get(context); + + // The controller client implements the actual logic to "go back" or "proceed" + // from the interstitial. + auto controller_client = std::make_unique( + web_contents, request_url, ad_block_custom_filters_service_, pref_service, + locale_); + + // This handles populating the HTML template of the interstitial page with + // localized strings and other information we only know at runtime, + // including the URL of the page we're blocking. Once the user interacts with + // the interstitial, this translates those actions into method calls on the + // controller client. + auto blocked_page = std::make_unique( + web_contents, request_url, std::move(controller_client)); + + // Get the page content before giving up ownership of |blocked_page|. + std::string blocked_page_content = blocked_page->GetHTMLContents(); + + // Replace the tab contents with our interstitial page. + security_interstitials::SecurityInterstitialTabHelper::AssociateBlockingPage( + web_contents, handle->GetNavigationId(), std::move(blocked_page)); + + // Navigation was deferred rather than canceled outright because the + // call to the ad blocking service happens on a task runner, but now we + // know that we definitely want to cancel the navigation. + CancelDeferredNavigation(content::NavigationThrottle::ThrottleCheckResult( + content::NavigationThrottle::CANCEL, net::ERR_BLOCKED_BY_CLIENT, + blocked_page_content)); +} + +const char* DomainBlockNavigationThrottle::GetNameForLogging() { + return "DomainBlockNavigationThrottle"; +} + +} // namespace brave_shields diff --git a/components/brave_shields/browser/domain_block_navigation_throttle.h b/components/brave_shields/browser/domain_block_navigation_throttle.h new file mode 100644 index 000000000000..0640d5694fb6 --- /dev/null +++ b/components/brave_shields/browser/domain_block_navigation_throttle.h @@ -0,0 +1,62 @@ +/* Copyright (c) 2021 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_DOMAIN_BLOCK_NAVIGATION_THROTTLE_H_ +#define BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_DOMAIN_BLOCK_NAVIGATION_THROTTLE_H_ + +#include +#include +#include + +#include "base/memory/weak_ptr.h" +#include "content/public/browser/navigation_throttle.h" +#include "url/gurl.h" + +namespace content { +class NavigationHandle; +class WebContents; +} // namespace content + +namespace brave_shields { + +class AdBlockService; +class AdBlockCustomFiltersService; + +class DomainBlockNavigationThrottle : public content::NavigationThrottle { + public: + explicit DomainBlockNavigationThrottle( + content::NavigationHandle* navigation_handle, + AdBlockService* ad_block_service, + AdBlockCustomFiltersService* ad_block_custom_filters_service, + const std::string& locale); + ~DomainBlockNavigationThrottle() override; + + DomainBlockNavigationThrottle(const DomainBlockNavigationThrottle&) = delete; + DomainBlockNavigationThrottle& operator=( + const DomainBlockNavigationThrottle&) = delete; + + static std::unique_ptr MaybeCreateThrottleFor( + content::NavigationHandle* navigation_handle, + AdBlockService* ad_block_service, + AdBlockCustomFiltersService* ad_block_custom_filters_service, + const std::string& locale); + + // content::NavigationThrottle implementation: + content::NavigationThrottle::ThrottleCheckResult WillStartRequest() override; + const char* GetNameForLogging() override; + + private: + void OnShouldBlockDomain(bool should_block_domain); + void ShowInterstitial(); + + AdBlockService* ad_block_service_ = nullptr; + AdBlockCustomFiltersService* ad_block_custom_filters_service_ = nullptr; + std::string locale_; + base::WeakPtrFactory weak_ptr_factory_{this}; +}; + +} // namespace brave_shields + +#endif // BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_DOMAIN_BLOCK_NAVIGATION_THROTTLE_H_ diff --git a/components/brave_shields/browser/domain_block_page.cc b/components/brave_shields/browser/domain_block_page.cc new file mode 100644 index 000000000000..99b3197a61f0 --- /dev/null +++ b/components/brave_shields/browser/domain_block_page.cc @@ -0,0 +1,102 @@ +/* Copyright (c) 2021 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/components/brave_shields/browser/domain_block_page.h" + +#include + +#include "base/notreached.h" +#include "base/strings/string_number_conversions.h" +#include "brave/components/brave_shields/browser/domain_block_controller_client.h" +#include "components/grit/brave_components_resources.h" +#include "components/grit/brave_components_strings.h" +#include "components/security_interstitials/content/security_interstitial_controller_client.h" +#include "ui/base/l10n/l10n_util.h" + +namespace brave_shields { + +// static +const security_interstitials::SecurityInterstitialPage::TypeID + DomainBlockPage::kTypeForTesting = &DomainBlockPage::kTypeForTesting; + +DomainBlockPage::DomainBlockPage( + content::WebContents* web_contents, + const GURL& request_url, + std::unique_ptr< + security_interstitials::SecurityInterstitialControllerClient> + controller) + : security_interstitials::SecurityInterstitialPage(web_contents, + request_url, + std::move(controller)) {} + +DomainBlockPage::~DomainBlockPage() = default; + +void DomainBlockPage::CommandReceived(const std::string& command) { + if (command == "\"pageLoadComplete\"") { + // content::WaitForRenderFrameReady sends this message when the page + // load completes. Ignore it. + return; + } + + int cmd = 0; + bool retval = base::StringToInt(command, &cmd); + DCHECK(retval); + DomainBlockControllerClient* domain_block_controller = + static_cast(controller()); + + switch (cmd) { + case security_interstitials::CMD_DONT_PROCEED: + domain_block_controller->GoBack(); + break; + case security_interstitials::CMD_PROCEED: + domain_block_controller->Proceed(); + break; + case security_interstitials::CMD_DO_REPORT: + domain_block_controller->SetDontWarnAgain(true); + break; + case security_interstitials::CMD_DONT_REPORT: + domain_block_controller->SetDontWarnAgain(false); + break; + default: + NOTREACHED() << "Unsupported command: " << command; + } +} + +void DomainBlockPage::PopulateInterstitialStrings( + base::DictionaryValue* load_time_data) { + load_time_data->SetString("tabTitle", + l10n_util::GetStringUTF16(IDS_DOMAIN_BLOCK_TITLE)); + load_time_data->SetString( + "heading", l10n_util::GetStringUTF16(IDS_DOMAIN_BLOCK_HEADING)); + + load_time_data->SetString( + "primaryParagraph", + l10n_util::GetStringUTF16(IDS_DOMAIN_BLOCK_PRIMARY_PARAGRAPH)); + load_time_data->SetString("domain", request_url().GetOrigin().spec()); + load_time_data->SetString( + "explanationParagraph", + l10n_util::GetStringUTF16(IDS_DOMAIN_BLOCK_EXPLANATION)); + + load_time_data->SetString( + "dontWarnAgainText", + l10n_util::GetStringUTF16(IDS_DOMAIN_BLOCK_DONT_WARN_AGAIN_BUTTON)); + + load_time_data->SetString( + "proceedAnywayText", + l10n_util::GetStringUTF16(IDS_DOMAIN_BLOCK_PROCEED_ANYWAY_BUTTON)); + load_time_data->SetString( + "goBackText", l10n_util::GetStringUTF16(IDS_DOMAIN_BLOCK_GO_BACK_BUTTON)); +} + +int DomainBlockPage::GetHTMLTemplateId() { + return IDR_DOMAIN_BLOCK_INTERSTITIAL_HTML; +} + +security_interstitials::SecurityInterstitialPage::TypeID +DomainBlockPage::GetTypeForTesting() { + return DomainBlockPage::kTypeForTesting; +} + +} // namespace brave_shields diff --git a/components/brave_shields/browser/domain_block_page.h b/components/brave_shields/browser/domain_block_page.h new file mode 100644 index 000000000000..e98c0f360a0c --- /dev/null +++ b/components/brave_shields/browser/domain_block_page.h @@ -0,0 +1,63 @@ +/* Copyright (c) 2021 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_DOMAIN_BLOCK_PAGE_H_ +#define BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_DOMAIN_BLOCK_PAGE_H_ + +#include +#include + +#include "base/values.h" +#include "components/security_interstitials/content/security_interstitial_page.h" +#include "url/gurl.h" + +namespace content { +class WebContents; +} // namespace content + +namespace security_interstitials { +class SecurityInterstitialControllerClient; +} // namespace security_interstitials + +namespace brave_shields { + +// DomainBlockPage is the interstitial page which will be shown when the +// browser blocks a top-level, first-party request. A proceed button is +// provided in the page, along with a checkbox to whitelist the domain and +// bypass this interstitial for this domain in the future. +class DomainBlockPage + : public security_interstitials::SecurityInterstitialPage { + public: + // Interstitial type, used in tests. + static const security_interstitials::SecurityInterstitialPage::TypeID + kTypeForTesting; + + DomainBlockPage( + content::WebContents* web_contents, + const GURL& request_url, + std::unique_ptr< + security_interstitials::SecurityInterstitialControllerClient> + controller); + ~DomainBlockPage() override; + + DomainBlockPage(const DomainBlockPage&) = delete; + DomainBlockPage& operator=(const DomainBlockPage&) = delete; + + // SecurityInterstitialPage:: overrides + void OnInterstitialClosing() override {} + void CommandReceived(const std::string& command) override; + security_interstitials::SecurityInterstitialPage::TypeID GetTypeForTesting() + override; + + protected: + // SecurityInterstitialPage:: overrides + void PopulateInterstitialStrings( + base::DictionaryValue* load_time_data) override; + int GetHTMLTemplateId() override; +}; + +} // namespace brave_shields + +#endif // BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_DOMAIN_BLOCK_PAGE_H_ diff --git a/components/brave_shields/browser/domain_block_tab_storage.cc b/components/brave_shields/browser/domain_block_tab_storage.cc new file mode 100644 index 000000000000..1d1de96db96b --- /dev/null +++ b/components/brave_shields/browser/domain_block_tab_storage.cc @@ -0,0 +1,32 @@ +/* Copyright (c) 2021 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/components/brave_shields/browser/domain_block_tab_storage.h" + +#include "base/memory/ptr_util.h" +#include "content/public/browser/web_contents.h" + +namespace brave_shields { + +// Arbitrary but unique key required for SupportsUserData. +// Upstream does this too. +const void* const kDomainBlockTabStorageKey = &kDomainBlockTabStorageKey; + +DomainBlockTabStorage::~DomainBlockTabStorage() = default; + +// static +DomainBlockTabStorage* DomainBlockTabStorage::GetOrCreate( + content::WebContents* web_contents) { + DomainBlockTabStorage* storage = FromWebContents(web_contents); + if (!storage) { + CreateForWebContents(web_contents); + storage = FromWebContents(web_contents); + } + return storage; +} + +WEB_CONTENTS_USER_DATA_KEY_IMPL(DomainBlockTabStorage) + +} // namespace brave_shields diff --git a/components/brave_shields/browser/domain_block_tab_storage.h b/components/brave_shields/browser/domain_block_tab_storage.h new file mode 100644 index 000000000000..35099a81388f --- /dev/null +++ b/components/brave_shields/browser/domain_block_tab_storage.h @@ -0,0 +1,47 @@ +/* Copyright (c) 2021 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_DOMAIN_BLOCK_TAB_STORAGE_H_ +#define BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_DOMAIN_BLOCK_TAB_STORAGE_H_ + +#include "base/macros.h" +#include "content/public/browser/web_contents_user_data.h" + +namespace content { +class WebContents; +} // namespace content + +namespace brave_shields { + +// A short-lived, per tab storage for mixed form interstitials, that stores a +// flag while proceeding, so a new interstitial is not shown immediately. +class DomainBlockTabStorage + : public content::WebContentsUserData { + public: + ~DomainBlockTabStorage() override; + + // Disallow copy and assign. + DomainBlockTabStorage(const DomainBlockTabStorage&) = delete; + DomainBlockTabStorage& operator=(const DomainBlockTabStorage&) = delete; + + // Returns the DomainBlockTabStorage associated to |web_contents|, or + // creates one if there is none. + static DomainBlockTabStorage* GetOrCreate(content::WebContents* web_contents); + + void SetIsProceeding(bool is_proceeding) { is_proceeding_ = is_proceeding; } + bool IsProceeding() const { return is_proceeding_; } + + private: + explicit DomainBlockTabStorage(content::WebContents* contents) {} + friend class content::WebContentsUserData; + WEB_CONTENTS_USER_DATA_KEY_DECL(); + + // Flag stores whether we are in the middle of a proceed action. + bool is_proceeding_ = false; +}; + +} // namespace brave_shields + +#endif // BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_DOMAIN_BLOCK_TAB_STORAGE_H_ diff --git a/components/brave_shields/resources/domain_block_interstitial.css b/components/brave_shields/resources/domain_block_interstitial.css new file mode 100644 index 000000000000..499bd6bfa6cc --- /dev/null +++ b/components/brave_shields/resources/domain_block_interstitial.css @@ -0,0 +1,36 @@ +.domainblock #main-content a { + color: var(--google-blue-700); + text-decoration: none; +} + +.domainblock .icon { + background-image: -webkit-image-set( + url(../../../../components/security_interstitials/core/browser/resources/images/1x/triangle_red.png) 1x, + url(../../../../components/security_interstitials/core/browser/resources/images/2x/triangle_red.png) 2x); +} + +.domainblock #domain { + background-color: white; + color: #fb542b; +} + +.domainblock #dont-warn-again { + padding-top: 1em; +} + +.domainblock input#dont-warn-again-checkbox { + opacity: 1; +} + +.domainblock label { + font-size: 110%; +} +.domainblock button#primary-button { + background-color: #fb524b; + border-color: #fb524b; + color: white; +} + +.domainblock button { + border-radius: 28px; +} diff --git a/components/brave_shields/resources/domain_block_interstitial.html b/components/brave_shields/resources/domain_block_interstitial.html new file mode 100644 index 000000000000..e6fc357cfee9 --- /dev/null +++ b/components/brave_shields/resources/domain_block_interstitial.html @@ -0,0 +1,34 @@ + + + + + $i18n{tabTitle} + + + + + + + + + +
+
+
+
+

$i18nRaw{heading}

+

$i18nRaw{primaryParagraph}

+
$i18nRaw{domain}
+

$i18nRaw{explanationParagraph}

+
+
+ + +
+
+ +
+ diff --git a/components/brave_shields/resources/domain_block_interstitial.js b/components/brave_shields/resources/domain_block_interstitial.js new file mode 100644 index 000000000000..475e1ecc276f --- /dev/null +++ b/components/brave_shields/resources/domain_block_interstitial.js @@ -0,0 +1,20 @@ +// Copyright 2020 The Brave Authors. All rights reserved. +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this file, +// you can obtain one at http://mozilla.org/MPL/2.0/. + +function setupEvents() { + $('primary-button').addEventListener('click', function() { + sendCommand(SecurityInterstitialCommandId.CMD_DONT_PROCEED); + }); + $('proceed-button').addEventListener('click', function() { + sendCommand(SecurityInterstitialCommandId.CMD_PROCEED); + }); + $('dont-warn-again-checkbox').addEventListener('click', function() { + sendCommand($('dont-warn-again-checkbox').checked ? + SecurityInterstitialCommandId.CMD_DO_REPORT : + SecurityInterstitialCommandId.CMD_DONT_REPORT); + }); +} + +document.addEventListener('DOMContentLoaded', setupEvents); diff --git a/components/resources/brave_components_resources.grd b/components/resources/brave_components_resources.grd index 89f2c529fa05..8dc06d95219c 100644 --- a/components/resources/brave_components_resources.grd +++ b/components/resources/brave_components_resources.grd @@ -63,6 +63,7 @@ + diff --git a/components/resources/brave_components_strings.grd b/components/resources/brave_components_strings.grd index cb9a68408f13..a8d32ff7c190 100644 --- a/components/resources/brave_components_strings.grd +++ b/components/resources/brave_components_strings.grd @@ -1072,6 +1072,7 @@ I understand + diff --git a/components/resources/domain_block_resources.grdp b/components/resources/domain_block_resources.grdp new file mode 100644 index 000000000000..48695747a65c --- /dev/null +++ b/components/resources/domain_block_resources.grdp @@ -0,0 +1,6 @@ + + + + + + diff --git a/components/resources/domain_block_strings.grdp b/components/resources/domain_block_strings.grdp new file mode 100644 index 000000000000..221e4d925597 --- /dev/null +++ b/components/resources/domain_block_strings.grdp @@ -0,0 +1,24 @@ + + + + Domain Blocked + + + Suspicious site ahead + + + Brave has prevented the following site from loading: + + + This site may be fraudulent, bounce you between various sites to set tracking cookies, or perform other privacy invasive actions. + + + Don't warn me about this site again + + + Proceed + + + Go back + + diff --git a/test/BUILD.gn b/test/BUILD.gn index 7caa755ba07f..987d306cd64c 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -537,7 +537,9 @@ if (!is_android) { "//brave/browser/brave_resources_browsertest.cc", "//brave/browser/brave_scheme_load_browsertest.cc", "//brave/browser/brave_shields/ad_block_service_browsertest.cc", + "//brave/browser/brave_shields/ad_block_service_browsertest.h", "//brave/browser/brave_shields/cookie_pref_service_browsertest.cc", + "//brave/browser/brave_shields/domain_block_page_browsertest.cc", "//brave/browser/brave_stats/brave_stats_updater_browsertest.cc", "//brave/browser/devtools/brave_devtools_ui_bindings_browsertest.cc", "//brave/browser/extensions/api/brave_shields_api_browsertest.cc", @@ -624,6 +626,7 @@ if (!is_android) { "//brave/chromium_src/third_party/blink/renderer/modules:browser_tests", "//brave/components/ipfs/test:brave_ipfs_browser_tests", "//brave/renderer/test:browser_tests", + "//components/security_interstitials/content:security_interstitial_page", "//media:test_support", "//testing/gmock", ]