From c82b1dba34448950a154e78fd012573d5ac9cc6c Mon Sep 17 00:00:00 2001 From: "Brian R. Bondy" Date: Tue, 16 Jul 2019 14:24:05 -0400 Subject: [PATCH] Remove redundant obsolete brave/tracking-protection It's been moved inside of the rust ad-block lib --- DEPS | 7 +- ...ave_ad_block_tp_network_delegate_helper.cc | 11 -- browser/net/brave_network_delegate_base.cc | 3 +- browser/net/url_context.h | 1 - browser/ui/webui/brave_adblock_ui.cc | 3 +- .../ui/webui/brave_new_tab_message_handler.cc | 3 - browser/ui/webui/brave_new_tab_ui.cc | 6 +- common/pref_names.cc | 2 + .../containers/newTab/stats.tsx | 8 +- components/brave_new_tab_ui/storage.ts | 3 +- components/brave_shields/browser/BUILD.gn | 1 - .../browser/ad_block_service_browsertest.cc | 54 -------- .../brave_shields_web_contents_observer.cc | 3 - .../browser/tracking_protection_service.cc | 127 +----------------- .../browser/tracking_protection_service.h | 11 -- ...tracking_protection_service_browsertest.cc | 66 --------- components/definitions/newTab.d.ts | 1 - .../resources/brave_components_strings.grd | 2 +- components/test/testData.ts | 1 - test/data/tracking.html | 4 - 20 files changed, 15 insertions(+), 302 deletions(-) delete mode 100644 test/data/tracking.html diff --git a/DEPS b/DEPS index 2a2cd062942b..f1e32526553d 100644 --- a/DEPS +++ b/DEPS @@ -2,10 +2,9 @@ use_relative_paths = True deps = { "vendor/adblock_rust_ffi": "https://github.com/brave/adblock-rust-ffi.git@0e980ee0a63d837f3ecad666fabe1f50311baa81", - "vendor/autoplay-whitelist": "https://github.com/brave/autoplay-whitelist.git@f39d83788cd12b883bfe6561cc7166b176ab9d9d", - "vendor/extension-whitelist": "https://github.com/brave/extension-whitelist.git@aa74a1bc29ced176e50db9f54946f28d82dfc795", - "vendor/tracking-protection": "https://github.com/brave/tracking-protection.git@3de744d4698b2f8fac1f52579d39f9ad154d1ec2", - "vendor/hashset-cpp": "https://github.com/brave/hashset-cpp.git@4b55fe39bb25bb0d8b11a43d547d75f00c6c46fb", + "vendor/autoplay-whitelist": "https://github.com/brave/autoplay-whitelist.git@ea527a4d36051daedb34421e129c98eda06cb5d3", + "vendor/extension-whitelist": "https://github.com/brave/extension-whitelist.git@7843f62e26a23c51336330e220e9d7992680aae9", + "vendor/hashset-cpp": "https://github.com/brave/hashset-cpp.git@6eab0271d014ff09bd9f38abe1e0c117e13e9aa9", "vendor/bloom-filter-cpp": "https://github.com/brave/bloom-filter-cpp.git@9be5c63b14e094156e00c8b28f205e7794f0b92c", "vendor/requests": "https://github.com/kennethreitz/requests@e4d59bedfd3c7f4f254f4f5d036587bcd8152458", "vendor/boto": "https://github.com/boto/boto@f7574aa6cc2c819430c1f05e9a1a1a666ef8169b", diff --git a/browser/net/brave_ad_block_tp_network_delegate_helper.cc b/browser/net/brave_ad_block_tp_network_delegate_helper.cc index 436d238da9b5..74bd221966a3 100644 --- a/browser/net/brave_ad_block_tp_network_delegate_helper.cc +++ b/browser/net/brave_ad_block_tp_network_delegate_helper.cc @@ -19,7 +19,6 @@ #include "brave/components/brave_shields/browser/ad_block_service.h" #include "brave/components/brave_shields/browser/brave_shields_util.h" #include "brave/components/brave_shields/browser/brave_shields_web_contents_observer.h" -#include "brave/components/brave_shields/browser/tracking_protection_service.h" #include "brave/components/brave_shields/common/brave_shield_constants.h" #include "brave/grit/brave_generated_resources.h" #include "content/public/browser/browser_thread.h" @@ -133,22 +132,12 @@ void OnBeforeURLRequestAdBlockTP( tab_host, &did_match_exception, &ctx->cancel_request_explicitly)) { ctx->blocked_by = kAdBlocked; - } else if (!did_match_exception && - !g_brave_browser_process->tracking_protection_service() - ->ShouldStartRequest(ctx->request_url, ctx->resource_type, - tab_host, &did_match_exception, - &ctx->cancel_request_explicitly)) { - ctx->blocked_by = kTrackerBlocked; } if (ctx->blocked_by == kAdBlocked) { brave_shields::DispatchBlockedEventFromIO(ctx->request_url, ctx->render_frame_id, ctx->render_process_id, ctx->frame_tree_node_id, brave_shields::kAds); - } else if (ctx->blocked_by == kTrackerBlocked) { - brave_shields::DispatchBlockedEventFromIO(ctx->request_url, - ctx->render_frame_id, ctx->render_process_id, ctx->frame_tree_node_id, - brave_shields::kTrackers); } } diff --git a/browser/net/brave_network_delegate_base.cc b/browser/net/brave_network_delegate_base.cc index 1c3cedad3618..0cd96f028eae 100644 --- a/browser/net/brave_network_delegate_base.cc +++ b/browser/net/brave_network_delegate_base.cc @@ -335,8 +335,7 @@ void BraveNetworkDelegateBase::RunNextCallback( IsRequestIdentifierValid(ctx->request_identifier)) { *ctx->new_url = GURL(ctx->new_url_spec); } - if (ctx->blocked_by == brave::kAdBlocked || - ctx->blocked_by == brave::kTrackerBlocked) { + if (ctx->blocked_by == brave::kAdBlocked) { // We are going to intercept this request and block it later in the // network stack. if (ctx->cancel_request_explicitly) { diff --git a/browser/net/url_context.h b/browser/net/url_context.h index 556dc82d1098..20b68fd872b2 100644 --- a/browser/net/url_context.h +++ b/browser/net/url_context.h @@ -43,7 +43,6 @@ enum BraveNetworkDelegateEventType { enum BlockedBy { kNotBlocked , kAdBlocked, - kTrackerBlocked, kOtherBlocked }; diff --git a/browser/ui/webui/brave_adblock_ui.cc b/browser/ui/webui/brave_adblock_ui.cc index 830f6a83687b..6dec2ab54694 100644 --- a/browser/ui/webui/brave_adblock_ui.cc +++ b/browser/ui/webui/brave_adblock_ui.cc @@ -130,7 +130,8 @@ void BraveAdblockUI::CustomizeWebUIProperties( PrefService* prefs = profile->GetPrefs(); if (render_view_host) { render_view_host->SetWebUIProperty( - "adsBlockedStat", std::to_string(prefs->GetUint64(kAdsBlocked))); + "adsBlockedStat", std::to_string(prefs->GetUint64(kAdsBlocked) + + prefs->GetUint64(kTrackersBlocked))); } } diff --git a/browser/ui/webui/brave_new_tab_message_handler.cc b/browser/ui/webui/brave_new_tab_message_handler.cc index f0cf2c3b23ca..e9ec3eae86c1 100644 --- a/browser/ui/webui/brave_new_tab_message_handler.cc +++ b/browser/ui/webui/brave_new_tab_message_handler.cc @@ -29,9 +29,6 @@ void BraveNewTabMessageHandler::OnJavascriptAllowed() { pref_change_registrar_.Add(kAdsBlocked, base::Bind(&BraveNewTabMessageHandler::OnStatsChanged, base::Unretained(this))); - pref_change_registrar_.Add(kTrackersBlocked, - base::Bind(&BraveNewTabMessageHandler::OnStatsChanged, - base::Unretained(this))); pref_change_registrar_.Add(kHttpsUpgrades, base::Bind(&BraveNewTabMessageHandler::OnStatsChanged, base::Unretained(this))); diff --git a/browser/ui/webui/brave_new_tab_ui.cc b/browser/ui/webui/brave_new_tab_ui.cc index 2e38609add88..f38eb7a15566 100644 --- a/browser/ui/webui/brave_new_tab_ui.cc +++ b/browser/ui/webui/brave_new_tab_ui.cc @@ -49,10 +49,8 @@ void BraveNewTabUI::SetStatsWebUIProperties( if (render_view_host) { render_view_host->SetWebUIProperty( "adsBlockedStat", - std::to_string(prefs->GetUint64(kAdsBlocked))); - render_view_host->SetWebUIProperty( - "trackersBlockedStat", - std::to_string(prefs->GetUint64(kTrackersBlocked))); + std::to_string(prefs->GetUint64(kAdsBlocked) + + prefs->GetUint64(kTrackersBlocked))); render_view_host->SetWebUIProperty( "javascriptBlockedStat", std::to_string(prefs->GetUint64(kJavascriptBlocked))); diff --git a/common/pref_names.cc b/common/pref_names.cc index 48986a52e8ac..027de1c2ea50 100644 --- a/common/pref_names.cc +++ b/common/pref_names.cc @@ -6,6 +6,8 @@ #include "brave/common/pref_names.h" const char kAdsBlocked[] = "brave.stats.ads_blocked"; +// We no longer update this pref, but we keep it around for now because it's +// added to kAdsBlocked when being displayed. const char kTrackersBlocked[] = "brave.stats.trackers_blocked"; const char kJavascriptBlocked[] = "brave.stats.javascript_blocked"; const char kHttpsUpgrades[] = "brave.stats.https_upgrades"; diff --git a/components/brave_new_tab_ui/containers/newTab/stats.tsx b/components/brave_new_tab_ui/containers/newTab/stats.tsx index fbabd035b95e..c58bbbc40182 100644 --- a/components/brave_new_tab_ui/containers/newTab/stats.tsx +++ b/components/brave_new_tab_ui/containers/newTab/stats.tsx @@ -17,10 +17,6 @@ class Stats extends React.Component { return 50 } - get trackedBlockersCount () { - return this.props.stats.trackersBlockedStat || 0 - } - get adblockCount () { return this.props.stats.adsBlockedStat || 0 } @@ -30,7 +26,7 @@ class Stats extends React.Component { } get estimatedTimeSaved () { - const estimatedMillisecondsSaved = (this.adblockCount + this.trackedBlockersCount) * this.millisecondsPerItem || 0 + const estimatedMillisecondsSaved = this.adblockCount * this.millisecondsPerItem || 0 const hours = estimatedMillisecondsSaved < 1000 * 60 * 60 * 24 const minutes = estimatedMillisecondsSaved < 1000 * 60 * 60 const seconds = estimatedMillisecondsSaved < 1000 * 60 @@ -62,7 +58,7 @@ class Stats extends React.Component { } render () { - const trackedBlockersCount = (this.trackedBlockersCount + this.adblockCount).toLocaleString() + const trackedBlockersCount = this.adblockCount.toLocaleString() const httpsUpgradedCount = this.httpsUpgradedCount.toLocaleString() const timeSaved = this.estimatedTimeSaved diff --git a/components/brave_new_tab_ui/storage.ts b/components/brave_new_tab_ui/storage.ts index 0be4f5be603f..939688349c99 100644 --- a/components/brave_new_tab_ui/storage.ts +++ b/components/brave_new_tab_ui/storage.ts @@ -27,7 +27,6 @@ const defaultState: NewTab.State = { bookmarks: {}, stats: { adsBlockedStat: 0, - trackersBlockedStat: 0, javascriptBlockedStat: 0, httpsUpgradesStat: 0, fingerprintingBlockedStat: 0 @@ -37,7 +36,7 @@ const defaultState: NewTab.State = { export const getLoadTimeData = (state: NewTab.State) => { state = { ...state } state.stats = defaultState.stats - ;['adsBlockedStat', 'trackersBlockedStat', 'javascriptBlockedStat', + ;['adsBlockedStat', 'javascriptBlockedStat', 'httpsUpgradesStat', 'fingerprintingBlockedStat'].forEach((stat) => { state.stats[stat] = parseInt(chrome.getVariableValue(stat), 10) || 0 }) diff --git a/components/brave_shields/browser/BUILD.gn b/components/brave_shields/browser/BUILD.gn index db0396806720..e6a29a161e9b 100644 --- a/components/brave_shields/browser/BUILD.gn +++ b/components/brave_shields/browser/BUILD.gn @@ -52,7 +52,6 @@ source_set("browser") { "//brave/components/content_settings/core/browser", "//brave/content:common", "//brave/vendor/adblock_rust_ffi:adblock_ffi", - "//brave/vendor/tracking-protection/brave:tracking-protection", "//brave/vendor/autoplay-whitelist/brave:autoplay-whitelist", "//chrome/common", "//components/prefs", diff --git a/components/brave_shields/browser/ad_block_service_browsertest.cc b/components/brave_shields/browser/ad_block_service_browsertest.cc index 03361f1a5f89..30ee09950161 100644 --- a/components/brave_shields/browser/ad_block_service_browsertest.cc +++ b/components/brave_shields/browser/ad_block_service_browsertest.cc @@ -547,60 +547,6 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, EXPECT_EQ(browser()->profile()->GetPrefs()->GetUint64(kAdsBlocked), 0ULL); } -// Load a page that references a tracker from an untrusted domain, but -// has no specific exception rule in ad-block. -IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, - TrackerReferencedFromUntrustedDomain) { - SetDefaultComponentIdAndBase64PublicKeyForTest( - kDefaultAdBlockComponentTestId, - kDefaultAdBlockComponentTestBase64PublicKey); - InitTrackingProtectionService(); - ASSERT_TRUE(InstallTrackingProtectionExtension()); - EXPECT_EQ(browser()->profile()->GetPrefs()->GetUint64(kTrackersBlocked), - 0ULL); - GURL url = embedded_test_server()->GetURL("google.com", kAdBlockTestPage); - ui_test_utils::NavigateToURL(browser(), url); - content::WebContents* contents = - browser()->tab_strip_model()->GetActiveWebContents(); - GURL test_url = embedded_test_server()->GetURL("365dm.com", "/logo.png"); - bool as_expected = false; - ASSERT_TRUE(ExecuteScriptAndExtractBool(contents, - base::StringPrintf( - "setExpectations(0, 1, 0, 0, 0, 0);" - "addImage('%s')", - test_url.spec().c_str()), - &as_expected)); - EXPECT_TRUE(as_expected); - EXPECT_EQ(browser()->profile()->GetPrefs()->GetUint64(kTrackersBlocked), - 1ULL); -} - -// Load a page that references a tracker from an untrusted domain, but -// has a specific exception rule in ad-block. -IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, - TrackerReferencedFromUntrustedDomainWithException) { - InitTrackingProtectionService(); - UpdateAdBlockInstanceWithRules("||365dm.com\n@@logo.png"); - ASSERT_TRUE(InstallTrackingProtectionExtension()); - EXPECT_EQ(browser()->profile()->GetPrefs()->GetUint64(kTrackersBlocked), - 0ULL); - GURL url = embedded_test_server()->GetURL("google.com", kAdBlockTestPage); - ui_test_utils::NavigateToURL(browser(), url); - content::WebContents* contents = - browser()->tab_strip_model()->GetActiveWebContents(); - GURL test_url = embedded_test_server()->GetURL("365dm.com", "/logo.png"); - bool as_expected = false; - ASSERT_TRUE(ExecuteScriptAndExtractBool(contents, - base::StringPrintf( - "setExpectations(1, 0, 0, 0, 0, 0);" - "addImage('%s')", - test_url.spec().c_str()), - &as_expected)); - EXPECT_TRUE(as_expected); - EXPECT_EQ(browser()->profile()->GetPrefs()->GetUint64(kTrackersBlocked), - 0ULL); -} - // Make sure the third-party flag is passed into the ad-block library properly IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, AdBlockThirdPartyWorksByETLDP1) { UpdateAdBlockInstanceWithRules("||a.com$third-party"); diff --git a/components/brave_shields/browser/brave_shields_web_contents_observer.cc b/components/brave_shields/browser/brave_shields_web_contents_observer.cc index de32c8a932e6..0a657ee59c7c 100644 --- a/components/brave_shields/browser/brave_shields_web_contents_observer.cc +++ b/components/brave_shields/browser/brave_shields_web_contents_observer.cc @@ -245,9 +245,6 @@ void BraveShieldsWebContentsObserver::DispatchBlockedEvent( if (block_type == kAds) { prefs->SetUint64(kAdsBlocked, prefs->GetUint64(kAdsBlocked) + 1); - } else if (block_type == kTrackers) { - prefs->SetUint64(kTrackersBlocked, - prefs->GetUint64(kTrackersBlocked) + 1); } else if (block_type == kHTTPUpgradableResources) { prefs->SetUint64(kHttpsUpgrades, prefs->GetUint64(kHttpsUpgrades) + 1); } else if (block_type == kJavaScript) { diff --git a/components/brave_shields/browser/tracking_protection_service.cc b/components/brave_shields/browser/tracking_protection_service.cc index d3f52669f0cc..764e4f8e63cb 100644 --- a/components/brave_shields/browser/tracking_protection_service.cc +++ b/components/brave_shields/browser/tracking_protection_service.cc @@ -12,7 +12,6 @@ #include "base/task_runner_util.h" #include "brave/components/brave_component_updater/browser/local_data_files_service.h" #include "brave/components/content_settings/core/browser/brave_cookie_settings.h" -#include "brave/vendor/tracking-protection/TPParser.h" #include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_thread.h" @@ -29,26 +28,19 @@ using content_settings::BraveCookieSettings; namespace brave_shields { -const char kDatFileVersion[] = "1"; -const char kNavigationTrackersFile[] = "TrackingProtection.dat"; - #if BUILDFLAG(BRAVE_STP_ENABLED) +const char kDatFileVersion[] = "1"; const char kStorageTrackersFile[] = "StorageTrackingProtection.dat"; #endif -const int kThirdPartyHostsCacheSize = 20; - TrackingProtectionService::TrackingProtectionService( LocalDataFilesService* local_data_files_service) : LocalDataFilesObserver(local_data_files_service), - tracking_protection_client_(new CTPParser()), weak_factory_(this), weak_factory_io_thread_(this) { } TrackingProtectionService::~TrackingProtectionService() { - BrowserThread::DeleteSoon( - BrowserThread::IO, FROM_HERE, tracking_protection_client_.release()); } #if BUILDFLAG(BRAVE_STP_ENABLED) @@ -230,73 +222,13 @@ bool TrackingProtectionService::ShouldStartRequest( if (matching_exception_filter) { *matching_exception_filter = false; } - // Intentionally don't set cancel_request_explicitly - std::string host = url.host(); - if (!tracking_protection_client_->matchesTracker(tab_host.c_str(), - host.c_str())) { - return true; - } - - std::vector hosts(GetThirdPartyHosts(tab_host)); - for (size_t i = 0; i < hosts.size(); i++) { - if (host == hosts[i] || - host.find((std::string) "." + hosts[i]) != std::string::npos) { - return true; - } - size_t iPos = host.find((std::string) "." + hosts[i]); - if (iPos == std::string::npos) { - continue; - } - if (hosts[i].length() + ((std::string) ".").length() + iPos == - host.length()) { - return true; - } - } return false; } -void TrackingProtectionService::OnGetDATFileData(GetDATFileDataResult result) { - if (result.second.empty()) { - LOG(ERROR) << "Could not obtain tracking protection data"; - return; - } - if (!result.first.get()) { - LOG(ERROR) << "Failed to deserialize tracking protection data"; - return; - } - - base::PostTaskWithTraits( - FROM_HERE, {BrowserThread::IO}, - base::BindOnce(&TrackingProtectionService::UpdateTrackingProtectionClient, - weak_factory_io_thread_.GetWeakPtr(), - std::move(result.first), - std::move(result.second))); -} - -void TrackingProtectionService::UpdateTrackingProtectionClient( - std::unique_ptr tracking_protection_client, - brave_component_updater::DATFileDataBuffer buffer) { - DCHECK_CURRENTLY_ON(BrowserThread::IO); - tracking_protection_client_ = std::move(tracking_protection_client); - buffer_ = std::move(buffer); -} - void TrackingProtectionService::OnComponentReady( const std::string& component_id, const base::FilePath& install_dir, const std::string& manifest) { - base::FilePath navigation_tracking_protection_path = install_dir - .AppendASCII(kDatFileVersion) - .AppendASCII(kNavigationTrackersFile); - - base::PostTaskAndReplyWithResult( - local_data_files_service()->GetTaskRunner().get(), - FROM_HERE, - base::BindOnce(&brave_component_updater::LoadDATFileData, - navigation_tracking_protection_path), - base::BindOnce(&TrackingProtectionService::OnGetDATFileData, - weak_factory_.GetWeakPtr())); - #if BUILDFLAG(BRAVE_STP_ENABLED) if (!TrackingProtectionHelper::IsSmartTrackingProtectionEnabled()) { return; @@ -315,63 +247,6 @@ void TrackingProtectionService::OnComponentReady( #endif } -// Ported from Android: net/blockers/blockers_worker.cc -std::vector TrackingProtectionService::GetThirdPartyHosts( - const std::string& base_host) { - DCHECK_CURRENTLY_ON(BrowserThread::IO); - { - base::AutoLock guard(third_party_hosts_lock_); - std::map>::const_iterator iter = - third_party_hosts_cache_.find(base_host); - if (third_party_hosts_cache_.end() != iter) { - if (third_party_base_hosts_.size() != 0 && - third_party_base_hosts_[third_party_hosts_cache_.size() - 1] != - base_host) { - for (size_t i = 0; i < third_party_base_hosts_.size(); i++) { - if (third_party_base_hosts_[i] == base_host) { - third_party_base_hosts_.erase(third_party_base_hosts_.begin() + i); - third_party_base_hosts_.push_back(base_host); - break; - } - } - } - return iter->second; - } - } - - char* thirdPartyHosts = - tracking_protection_client_->findFirstPartyHosts(base_host.c_str()); - std::vector hosts; - if (nullptr != thirdPartyHosts) { - std::string strThirdPartyHosts = thirdPartyHosts; - size_t iPos = strThirdPartyHosts.find(","); - while (iPos != std::string::npos) { - std::string thirdParty = strThirdPartyHosts.substr(0, iPos); - strThirdPartyHosts = strThirdPartyHosts.substr(iPos + 1); - iPos = strThirdPartyHosts.find(","); - hosts.push_back(thirdParty); - } - if (0 != strThirdPartyHosts.length()) { - hosts.push_back(strThirdPartyHosts); - } - delete []thirdPartyHosts; - } - - { - base::AutoLock guard(third_party_hosts_lock_); - if (third_party_hosts_cache_.size() == kThirdPartyHostsCacheSize && - third_party_base_hosts_.size() == kThirdPartyHostsCacheSize) { - third_party_hosts_cache_.erase(third_party_base_hosts_[0]); - third_party_base_hosts_.erase(third_party_base_hosts_.begin()); - } - third_party_base_hosts_.push_back(base_host); - third_party_hosts_cache_.insert( - std::pair>(base_host, hosts)); - } - - return hosts; -} - /////////////////////////////////////////////////////////////////////////////// std::unique_ptr TrackingProtectionServiceFactory( diff --git a/components/brave_shields/browser/tracking_protection_service.h b/components/brave_shields/browser/tracking_protection_service.h index 7a3038bb0213..466d0df155e5 100644 --- a/components/brave_shields/browser/tracking_protection_service.h +++ b/components/brave_shields/browser/tracking_protection_service.h @@ -23,7 +23,6 @@ #include "content/public/common/resource_type.h" #include "url/gurl.h" -class CTPParser; class HostContentSettingsMap; class TrackingProtectionServiceTest; @@ -39,9 +38,6 @@ namespace brave_shields { // The brave shields service in charge of tracking protection and init. class TrackingProtectionService : public LocalDataFilesObserver { public: - using GetDATFileDataResult = - brave_component_updater::LoadDATFileDataResult; - explicit TrackingProtectionService( LocalDataFilesService* local_data_files_service); ~TrackingProtectionService() override; @@ -111,18 +107,11 @@ class TrackingProtectionService : public LocalDataFilesObserver { #endif private: - void OnGetDATFileData(GetDATFileDataResult result); - void UpdateTrackingProtectionClient( - std::unique_ptr tracking_protection_client, - brave_component_updater::DATFileDataBuffer); - std::vector GetThirdPartyHosts(const std::string& base_host); - #if BUILDFLAG(BRAVE_STP_ENABLED) base::flat_set first_party_storage_trackers_; std::map render_frame_key_to_starting_site_url; #endif - std::unique_ptr tracking_protection_client_; std::vector third_party_base_hosts_; std::map> third_party_hosts_cache_; base::Lock third_party_hosts_lock_; diff --git a/components/brave_shields/browser/tracking_protection_service_browsertest.cc b/components/brave_shields/browser/tracking_protection_service_browsertest.cc index 0d347b5b3c0a..2acd11b54494 100644 --- a/components/brave_shields/browser/tracking_protection_service_browsertest.cc +++ b/components/brave_shields/browser/tracking_protection_service_browsertest.cc @@ -37,17 +37,6 @@ const char kStoragePage[] = "/storage.html"; using content::BrowserThread; using extensions::ExtensionBrowserTest; -const char kTrackingPage[] = "/tracking.html"; - -const char kTrackingScript[] = - "const url = '%s';" - "const img = document.createElement('img');" - "img.src = url;" - "img.onload = function() { window.domAutomationController.send(img.complete" - " && (img.naturalHeight !== 1 || img.naturalWidth !== 1)); };" - "img.onerror = function() { window.domAutomationController.send(false); };" - "document.body.appendChild(img);"; - const std::string kTrackingProtectionComponentTestId( "eclbkhjphkhalklhipiicaldjbnhdfkc"); @@ -140,61 +129,6 @@ class TrackingProtectionServiceTest : public ExtensionBrowserTest { } }; -// Load a page that references a tracker from a trusted domain, and -// make sure it is not blocked. -IN_PROC_BROWSER_TEST_F(TrackingProtectionServiceTest, - TrackerReferencedFromTrustedDomainNotBlocked) { - ASSERT_TRUE(InstallTrackingProtectionExtension()); - - EXPECT_EQ(browser()->profile()->GetPrefs()->GetUint64(kTrackersBlocked), - 0ULL); - - GURL url = embedded_test_server()->GetURL("365media.com", kTrackingPage); - ui_test_utils::NavigateToURL(browser(), url); - content::WebContents* contents = - browser()->tab_strip_model()->GetActiveWebContents(); - ASSERT_TRUE(content::WaitForLoadStop(contents)); - EXPECT_EQ(url, contents->GetURL()); - - GURL test_url = embedded_test_server()->GetURL("365dm.com", "/logo.png"); - - bool img_loaded; - ASSERT_TRUE(ExecuteScriptAndExtractBool( - contents, base::StringPrintf(kTrackingScript, test_url.spec().c_str()), - &img_loaded)); - EXPECT_TRUE(img_loaded); - - EXPECT_EQ(browser()->profile()->GetPrefs()->GetUint64(kTrackersBlocked), - 0ULL); -} - -// Load a page that references a tracker from an untrusted domain, and -// make sure it is blocked. -IN_PROC_BROWSER_TEST_F(TrackingProtectionServiceTest, - TrackerReferencedFromUntrustedDomainGetsBlocked) { - ASSERT_TRUE(InstallTrackingProtectionExtension()); - EXPECT_EQ(browser()->profile()->GetPrefs()->GetUint64(kTrackersBlocked), - 0ULL); - - GURL url = embedded_test_server()->GetURL("google.com", kTrackingPage); - ui_test_utils::NavigateToURL(browser(), url); - content::WebContents* contents = - browser()->tab_strip_model()->GetActiveWebContents(); - ASSERT_TRUE(content::WaitForLoadStop(contents)); - EXPECT_EQ(url, contents->GetURL()); - - GURL test_url = embedded_test_server()->GetURL("365dm.com", "/logo.png"); - - bool img_loaded; - ASSERT_TRUE(ExecuteScriptAndExtractBool( - contents, base::StringPrintf(kTrackingScript, test_url.spec().c_str()), - &img_loaded)); - EXPECT_FALSE(img_loaded); - - EXPECT_EQ(browser()->profile()->GetPrefs()->GetUint64(kTrackersBlocked), - 1ULL); -} - #if BUILDFLAG(BRAVE_STP_ENABLED) IN_PROC_BROWSER_TEST_F(TrackingProtectionServiceTest, StorageTrackingBlocked) { ASSERT_TRUE(TrackingProtectionHelper::IsSmartTrackingProtectionEnabled()); diff --git a/components/definitions/newTab.d.ts b/components/definitions/newTab.d.ts index e6158c1f2ddf..bce67ffbbc2d 100644 --- a/components/definitions/newTab.d.ts +++ b/components/definitions/newTab.d.ts @@ -25,7 +25,6 @@ declare namespace NewTab { export interface Stats { adsBlockedStat: number - trackersBlockedStat: number javascriptBlockedStat: number httpsUpgradesStat: number fingerprintingBlockedStat: number diff --git a/components/resources/brave_components_strings.grd b/components/resources/brave_components_strings.grd index 4a080f72406a..eb1c941c231b 100644 --- a/components/resources/brave_components_strings.grd +++ b/components/resources/brave_components_strings.grd @@ -169,7 +169,7 @@ Additional Filters Warning: Turning on too many filters will degrade performance - Total Ads Blocked: + Total ads and trackers blocked: Custom Filters One per line, a filter is described in Adblock Plus filter syntax diff --git a/components/test/testData.ts b/components/test/testData.ts index e1a030e00eb9..93f5f2fb7a98 100644 --- a/components/test/testData.ts +++ b/components/test/testData.ts @@ -55,7 +55,6 @@ export const newTabInitialState: NewTab.ApplicationState = { bookmarks: {}, stats: { adsBlockedStat: 0, - trackersBlockedStat: 0, javascriptBlockedStat: 0, httpsUpgradesStat: 0, fingerprintingBlockedStat: 0 diff --git a/test/data/tracking.html b/test/data/tracking.html deleted file mode 100644 index efd381b1356d..000000000000 --- a/test/data/tracking.html +++ /dev/null @@ -1,4 +0,0 @@ - - -Tracking image inserted here: -