Merge pull request #8666 from brave/rip-out-tracking-protection-service
Remove TrackingProtectionService
This commit is contained in:
@@ -37,7 +37,6 @@ class AdBlockService;
|
||||
class AdBlockCustomFiltersService;
|
||||
class AdBlockRegionalServiceManager;
|
||||
class HTTPSEverywhereService;
|
||||
class TrackingProtectionService;
|
||||
} // namespace brave_shields
|
||||
|
||||
namespace brave_stats {
|
||||
@@ -86,8 +85,6 @@ class BraveBrowserProcess {
|
||||
virtual greaselion::GreaselionDownloadService*
|
||||
greaselion_download_service() = 0;
|
||||
#endif
|
||||
virtual brave_shields::TrackingProtectionService*
|
||||
tracking_protection_service() = 0;
|
||||
virtual brave_shields::HTTPSEverywhereService* https_everywhere_service() = 0;
|
||||
virtual brave_component_updater::LocalDataFilesService*
|
||||
local_data_files_service() = 0;
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include "brave/components/brave_shields/browser/ad_block_regional_service_manager.h"
|
||||
#include "brave/components/brave_shields/browser/ad_block_service.h"
|
||||
#include "brave/components/brave_shields/browser/https_everywhere_service.h"
|
||||
#include "brave/components/brave_shields/browser/tracking_protection_service.h"
|
||||
#include "brave/components/brave_sync/buildflags/buildflags.h"
|
||||
#include "brave/components/brave_sync/network_time_helper.h"
|
||||
#include "brave/components/ntp_background_images/browser/features.h"
|
||||
@@ -184,7 +183,6 @@ void BraveBrowserProcessImpl::StartBraveServices() {
|
||||
#if BUILDFLAG(ENABLE_EXTENSIONS)
|
||||
extension_whitelist_service();
|
||||
#endif
|
||||
tracking_protection_service();
|
||||
#if BUILDFLAG(ENABLE_GREASELION)
|
||||
greaselion_download_service();
|
||||
#endif
|
||||
@@ -260,16 +258,6 @@ BraveBrowserProcessImpl::greaselion_download_service() {
|
||||
}
|
||||
#endif
|
||||
|
||||
brave_shields::TrackingProtectionService*
|
||||
BraveBrowserProcessImpl::tracking_protection_service() {
|
||||
if (!tracking_protection_service_) {
|
||||
tracking_protection_service_ =
|
||||
brave_shields::TrackingProtectionServiceFactory(
|
||||
local_data_files_service());
|
||||
}
|
||||
return tracking_protection_service_.get();
|
||||
}
|
||||
|
||||
brave_shields::HTTPSEverywhereService*
|
||||
BraveBrowserProcessImpl::https_everywhere_service() {
|
||||
if (!https_everywhere_service_)
|
||||
|
||||
@@ -37,7 +37,6 @@ class AdBlockService;
|
||||
class AdBlockCustomFiltersService;
|
||||
class AdBlockRegionalServiceManager;
|
||||
class HTTPSEverywhereService;
|
||||
class TrackingProtectionService;
|
||||
} // namespace brave_shields
|
||||
|
||||
namespace brave_stats {
|
||||
@@ -96,8 +95,6 @@ class BraveBrowserProcessImpl : public BraveBrowserProcess,
|
||||
#if BUILDFLAG(ENABLE_GREASELION)
|
||||
greaselion::GreaselionDownloadService* greaselion_download_service() override;
|
||||
#endif
|
||||
brave_shields::TrackingProtectionService* tracking_protection_service()
|
||||
override;
|
||||
brave_shields::HTTPSEverywhereService* https_everywhere_service() override;
|
||||
brave_component_updater::LocalDataFilesService* local_data_files_service()
|
||||
override;
|
||||
@@ -152,8 +149,6 @@ class BraveBrowserProcessImpl : public BraveBrowserProcess,
|
||||
std::unique_ptr<greaselion::GreaselionDownloadService>
|
||||
greaselion_download_service_;
|
||||
#endif
|
||||
std::unique_ptr<brave_shields::TrackingProtectionService>
|
||||
tracking_protection_service_;
|
||||
std::unique_ptr<brave_shields::HTTPSEverywhereService>
|
||||
https_everywhere_service_;
|
||||
std::unique_ptr<brave_stats::BraveStatsUpdater> brave_stats_updater_;
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#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/common/buildflags/buildflags.h"
|
||||
#include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h"
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
#include "brave/browser/brave_browser_process.h"
|
||||
#include "brave/common/brave_paths.h"
|
||||
#include "brave/common/pref_names.h"
|
||||
#include "brave/components/brave_component_updater/browser/local_data_files_service.h"
|
||||
#include "brave/components/brave_shields/browser/ad_block_custom_filters_service.h"
|
||||
#include "brave/components/brave_shields/browser/ad_block_regional_service.h"
|
||||
#include "brave/components/brave_shields/browser/ad_block_regional_service_manager.h"
|
||||
#include "brave/components/brave_shields/browser/ad_block_service.h"
|
||||
#include "brave/components/brave_shields/browser/brave_shields_util.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_shields/common/features.h"
|
||||
#include "chrome/browser/browser_process.h"
|
||||
@@ -46,8 +46,6 @@ const char kDefaultAdBlockComponentTestId[] =
|
||||
"naccapggpomhlhoifnlebfoocegenbol";
|
||||
const char kRegionalAdBlockComponentTestId[] =
|
||||
"dlpmaigjliompnelofkljgcmlenklieh";
|
||||
const char kTrackingProtectionComponentTestId[] =
|
||||
"eclbkhjphkhalklhipiicaldjbnhdfkc";
|
||||
|
||||
const char kDefaultAdBlockComponentTest64PublicKey[] =
|
||||
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtV7Vr69kkvSvu2lhcMDh"
|
||||
@@ -65,14 +63,6 @@ const char kRegionalAdBlockComponentTest64PublicKey[] =
|
||||
"G8XBq/Y8FbBt+u+7skWQy3lVyRwFjeFu6cXVF4tcc06PNx5yLsbHQtSv8R+h1bWw"
|
||||
"ieMF3JB9CZPr+qDKIap+RZUfsraV47QebRi/JA17nbDMlXOmK7mILfFU7Jhjx04F"
|
||||
"LwIDAQAB";
|
||||
const char kTrackingProtectionComponentTest64PublicKey[] =
|
||||
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsleoSxQ3DN+6xym2P1uX"
|
||||
"mN6ArIWd9Oru5CSjS0SRE5upM2EnAl/C20TP8JdIlPi/3tk/SN6Y92K3xIhAby5F"
|
||||
"0rbPDSTXEWGy72tv2qb/WySGwDdvYQu9/J5sEDneVcMrSHcC0VWgcZR0eof4BfOy"
|
||||
"fKMEnHX98tyA3z+vW5ndHspR/Xvo78B3+6HX6tyVm/pNlCNOm8W8feyfDfPpK2Lx"
|
||||
"qRLB7PumyhR625txxolkGC6aC8rrxtT3oymdMfDYhB4BZBrzqdriyvu1NdygoEiF"
|
||||
"WhIYw/5zv1NyIsfUiG8wIs5+OwS419z7dlMKsg1FuB2aQcDyjoXx1habFfHQfQwL"
|
||||
"qwIDAQAB";
|
||||
|
||||
using brave_shields::features::kBraveAdblockCosmeticFiltering;
|
||||
using content::BrowserThread;
|
||||
@@ -131,13 +121,6 @@ void AdBlockServiceTest::GetTestDataDir(base::FilePath* test_data_dir) {
|
||||
base::PathService::Get(brave::DIR_TEST_DATA, test_data_dir);
|
||||
}
|
||||
|
||||
void AdBlockServiceTest::InitTrackingProtectionService() {
|
||||
brave_component_updater::LocalDataFilesService::
|
||||
SetComponentIdAndBase64PublicKeyForTest(
|
||||
kTrackingProtectionComponentTestId,
|
||||
kTrackingProtectionComponentTest64PublicKey);
|
||||
}
|
||||
|
||||
bool AdBlockServiceTest::InstallDefaultAdBlockExtension(
|
||||
const std::string& extension_dir,
|
||||
int expected_change) {
|
||||
@@ -210,22 +193,6 @@ bool AdBlockServiceTest::InstallRegionalAdBlockExtension(
|
||||
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();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AdBlockServiceTest::StartAdBlockRegionalServices() {
|
||||
g_brave_browser_process->ad_block_regional_service_manager()->Start();
|
||||
if (!g_brave_browser_process->ad_block_regional_service_manager()
|
||||
|
||||
@@ -29,13 +29,11 @@ class AdBlockServiceTest : public extensions::ExtensionBrowserTest {
|
||||
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();
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include "brave/components/brave_perf_predictor/browser/buildflags.h"
|
||||
#include "brave/components/brave_rewards/browser/buildflags/buildflags.h"
|
||||
#include "brave/components/brave_shields/browser/brave_shields_web_contents_observer.h"
|
||||
#include "brave/components/brave_shields/browser/buildflags/buildflags.h" // For STP
|
||||
#include "brave/components/brave_wayback_machine/buildflags.h"
|
||||
#include "brave/components/greaselion/browser/buildflags/buildflags.h"
|
||||
#include "brave/components/ipfs/buildflags/buildflags.h"
|
||||
@@ -38,11 +37,6 @@
|
||||
#include "brave/browser/brave_rewards/rewards_tab_helper.h"
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(BRAVE_STP_ENABLED)
|
||||
#include "brave/components/brave_shields/browser/tracking_protection_helper.h"
|
||||
#include "brave/components/brave_shields/browser/tracking_protection_service.h"
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(ENABLE_WIDEVINE)
|
||||
#include "brave/browser/brave_drm_tab_helper.h"
|
||||
#endif
|
||||
@@ -90,13 +84,6 @@ void AttachTabHelpers(content::WebContents* web_contents) {
|
||||
brave_rewards::RewardsTabHelper::CreateForWebContents(web_contents);
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(BRAVE_STP_ENABLED)
|
||||
if (brave_shields::TrackingProtectionService::
|
||||
IsSmartTrackingProtectionEnabled()) {
|
||||
brave_shields::TrackingProtectionHelper::CreateForWebContents(web_contents);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(ENABLE_WIDEVINE)
|
||||
BraveDrmTabHelper::CreateForWebContents(web_contents);
|
||||
#endif
|
||||
|
||||
@@ -4,25 +4,16 @@
|
||||
# You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
source_set("content_settings") {
|
||||
# Remove when https://github.com/brave/brave-browser/issues/10662 is resolved
|
||||
check_includes = false
|
||||
sources = [
|
||||
"brave_content_settings_manager_delegate.cc",
|
||||
"brave_content_settings_manager_delegate.h",
|
||||
"brave_global_value_map.cc",
|
||||
"brave_global_value_map.h",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//base",
|
||||
"//brave/components/brave_shields/browser",
|
||||
"//brave/components/content_settings/core/browser",
|
||||
|
||||
# "//chrome/browser" # dep cycle
|
||||
"//components/content_settings/common:mojom",
|
||||
"//components/content_settings/core/browser",
|
||||
"//components/content_settings/core/common",
|
||||
"//content/public/browser",
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
/* Copyright (c) 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/. */
|
||||
|
||||
#include "brave/browser/content_settings/brave_content_settings_manager_delegate.h"
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "brave/browser/brave_browser_process.h"
|
||||
#include "brave/components/brave_shields/browser/tracking_protection_service.h"
|
||||
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
|
||||
#include "chrome/browser/profiles/profile.h"
|
||||
#include "components/content_settings/common/content_settings_manager.mojom.h"
|
||||
#include "content/public/browser/render_frame_host.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
|
||||
namespace chrome {
|
||||
|
||||
namespace {
|
||||
|
||||
bool ShouldStoreState(int render_process_id,
|
||||
int render_frame_id,
|
||||
const GURL& url) {
|
||||
content::RenderFrameHost* frame =
|
||||
content::RenderFrameHost::FromID(render_process_id, render_frame_id);
|
||||
content::WebContents* web_contents =
|
||||
content::WebContents::FromRenderFrameHost(frame);
|
||||
if (!web_contents)
|
||||
return true;
|
||||
|
||||
HostContentSettingsMap* host_content_settings_map =
|
||||
HostContentSettingsMapFactory::GetForProfile(
|
||||
Profile::FromBrowserContext(web_contents->GetBrowserContext()));
|
||||
|
||||
return g_brave_browser_process->tracking_protection_service()
|
||||
->ShouldStoreState(host_content_settings_map, render_process_id,
|
||||
render_frame_id, url);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
BraveContentSettingsManagerDelegate::~BraveContentSettingsManagerDelegate() =
|
||||
default;
|
||||
|
||||
// content_settings::ContentSettingsManagerImpl::Delegate:
|
||||
bool BraveContentSettingsManagerDelegate::AllowStorageAccess(
|
||||
int render_process_id,
|
||||
int render_frame_id,
|
||||
content_settings::mojom::ContentSettingsManager::StorageType storage_type,
|
||||
const GURL& url,
|
||||
bool allowed,
|
||||
base::OnceCallback<void(bool)>* callback) {
|
||||
using StorageType =
|
||||
content_settings::mojom::ContentSettingsManager::StorageType;
|
||||
// LOCAL_STORAGE | SESSION_STORAGE == DOMStorage
|
||||
switch (storage_type) {
|
||||
case StorageType::DATABASE:
|
||||
case StorageType::LOCAL_STORAGE:
|
||||
case StorageType::SESSION_STORAGE:
|
||||
case StorageType::INDEXED_DB:
|
||||
if (!ShouldStoreState(render_process_id, render_frame_id, url)) {
|
||||
std::move(*callback).Run(false);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// FILE_SYSTEM, CACHE, WEB_LOCKS
|
||||
break;
|
||||
}
|
||||
|
||||
return ContentSettingsManagerDelegate::AllowStorageAccess(
|
||||
render_process_id, render_frame_id, storage_type, url, allowed, callback);
|
||||
}
|
||||
|
||||
std::unique_ptr<content_settings::ContentSettingsManagerImpl::Delegate>
|
||||
BraveContentSettingsManagerDelegate::Clone() {
|
||||
return std::make_unique<BraveContentSettingsManagerDelegate>();
|
||||
}
|
||||
|
||||
} // namespace chrome
|
||||
@@ -1,34 +0,0 @@
|
||||
/* Copyright (c) 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/. */
|
||||
|
||||
#ifndef BRAVE_BROWSER_CONTENT_SETTINGS_BRAVE_CONTENT_SETTINGS_MANAGER_DELEGATE_H_
|
||||
#define BRAVE_BROWSER_CONTENT_SETTINGS_BRAVE_CONTENT_SETTINGS_MANAGER_DELEGATE_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "chrome/browser/content_settings/content_settings_manager_delegate.h"
|
||||
|
||||
namespace chrome {
|
||||
|
||||
class BraveContentSettingsManagerDelegate
|
||||
: public ContentSettingsManagerDelegate {
|
||||
public:
|
||||
~BraveContentSettingsManagerDelegate() override;
|
||||
|
||||
private:
|
||||
// content_settings::ContentSettingsManagerImpl::Delegate:
|
||||
bool AllowStorageAccess(
|
||||
int render_process_id,
|
||||
int render_frame_id,
|
||||
content_settings::mojom::ContentSettingsManager::StorageType storage_type,
|
||||
const GURL& url,
|
||||
bool allowed,
|
||||
base::OnceCallback<void(bool)>* callback) override;
|
||||
std::unique_ptr<Delegate> Clone() override;
|
||||
};
|
||||
|
||||
} // namespace chrome
|
||||
|
||||
#endif // BRAVE_BROWSER_CONTENT_SETTINGS_BRAVE_CONTENT_SETTINGS_MANAGER_DELEGATE_H_
|
||||
@@ -51,9 +51,6 @@ const start = (passthroughArgs, buildConfig = config.defaultBuildConfig, options
|
||||
if (options.disable_doh) {
|
||||
braveArgs.push('--disable-doh')
|
||||
}
|
||||
if (options.enable_smart_tracking_protection) {
|
||||
braveArgs.push('--enable-smart-tracking-protection')
|
||||
}
|
||||
if (options.single_process) {
|
||||
braveArgs.push('--single-process')
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
/* Copyright (c) 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/. */
|
||||
|
||||
#include "brave/browser/content_settings/brave_content_settings_manager_delegate.h"
|
||||
#define ContentSettingsManagerDelegate BraveContentSettingsManagerDelegate
|
||||
#include "../../../../chrome/browser/chrome_content_browser_client_receiver_bindings.cc"
|
||||
#undef ContentSettingsManagerDelegate
|
||||
@@ -1,17 +0,0 @@
|
||||
/* Copyright (c) 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/. */
|
||||
|
||||
#ifndef BRAVE_CHROMIUM_SRC_CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_MANAGER_DELEGATE_H_
|
||||
#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_MANAGER_DELEGATE_H_
|
||||
|
||||
#define BRAVE_CONTENT_SETTINGS_MANAGER_DELEGATE_H_ \
|
||||
private: \
|
||||
friend class BraveContentSettingsManagerDelegate; \
|
||||
\
|
||||
public:
|
||||
#include "../../../../../chrome/browser/content_settings/content_settings_manager_delegate.h"
|
||||
#undef BRAVE_CONTENT_SETTINGS_MANAGER_DELEGATE_H_
|
||||
|
||||
#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_MANAGER_DELEGATE_H_
|
||||
@@ -39,10 +39,6 @@ const char kDisableMachineId[] = "disable-machine-id";
|
||||
// what you are doing.
|
||||
const char kDisableEncryptionWin[] = "disable-encryption-win";
|
||||
|
||||
// This enables smart tracking protection
|
||||
const char kEnableSmartTrackingProtection[] =
|
||||
"enable-smart-tracking-protection";
|
||||
|
||||
const char kFastWidevineBundleUpdate[] = "fast-widevine-bundle-update";
|
||||
|
||||
// Use custom update interval in sec
|
||||
|
||||
@@ -28,8 +28,6 @@ extern const char kDisableMachineId[];
|
||||
|
||||
extern const char kDisableEncryptionWin[];
|
||||
|
||||
extern const char kEnableSmartTrackingProtection[];
|
||||
|
||||
extern const char kFastWidevineBundleUpdate[];
|
||||
|
||||
extern const char kComponentUpdateIntervalInSec[];
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import(
|
||||
"//brave/components/brave_perf_predictor/browser/buildflags/buildflags.gni")
|
||||
import("//brave/components/brave_shields/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" ]
|
||||
|
||||
sources = [
|
||||
"ad_block_base_service.cc",
|
||||
@@ -44,21 +42,12 @@ source_set("browser") {
|
||||
"https_everywhere_recently_used_cache.h",
|
||||
"https_everywhere_service.cc",
|
||||
"https_everywhere_service.h",
|
||||
"tracking_protection_service.cc",
|
||||
"tracking_protection_service.h",
|
||||
]
|
||||
|
||||
if (is_android) {
|
||||
sources += [ "brave_shields_web_contents_observer_android.cc" ]
|
||||
}
|
||||
|
||||
if (brave_stp_enabled) {
|
||||
sources += [
|
||||
"tracking_protection_helper.cc",
|
||||
"tracking_protection_helper.h",
|
||||
]
|
||||
}
|
||||
|
||||
deps = [
|
||||
"//base",
|
||||
"//brave/components/adblock_rust_ffi",
|
||||
|
||||
@@ -47,10 +47,4 @@ specific_include_rules = {
|
||||
"+brave/browser/android/brave_shields_content_settings.h",
|
||||
"+chrome/browser/android/tab_android.h",
|
||||
],
|
||||
"tracking_protection_helper.cc": [
|
||||
"+brave/browser/brave_browser_process.h",
|
||||
],
|
||||
"tracking_protection_service.cc": [
|
||||
"+brave/common/brave_switches.h",
|
||||
],
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
import("//build/buildflag_header.gni")
|
||||
import("//brave/components/brave_shields/browser/buildflags/buildflags.gni")
|
||||
|
||||
buildflag_header("buildflags") {
|
||||
header = "buildflags.h"
|
||||
flags = [
|
||||
"BRAVE_STP_ENABLED=$brave_stp_enabled",
|
||||
]
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
declare_args() {
|
||||
brave_stp_enabled = false
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
/* Copyright (c) 2019 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/tracking_protection_helper.h"
|
||||
|
||||
#include "base/task/post_task.h"
|
||||
#include "brave/browser/brave_browser_process.h"
|
||||
#include "brave/components/brave_shields/browser/tracking_protection_service.h"
|
||||
#include "content/public/browser/browser_task_traits.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/navigation_handle.h"
|
||||
#include "content/public/browser/render_process_host.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "content/public/browser/web_contents_user_data.h"
|
||||
|
||||
using content::BrowserThread;
|
||||
using content::NavigationHandle;
|
||||
using content::RenderFrameHost;
|
||||
using content::WebContents;
|
||||
|
||||
namespace {
|
||||
|
||||
void SetStartingSiteForRenderFrame(GURL starting_site,
|
||||
int render_process_id,
|
||||
int render_frame_id) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||
g_brave_browser_process->tracking_protection_service()
|
||||
->SetStartingSiteForRenderFrame(starting_site, render_process_id,
|
||||
render_frame_id);
|
||||
}
|
||||
|
||||
void DeleteRenderFrameKey(int render_process_id, int render_frame_id) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||
g_brave_browser_process->tracking_protection_service()->DeleteRenderFrameKey(
|
||||
render_process_id, render_frame_id);
|
||||
}
|
||||
|
||||
void ModifyRenderFrameKey(int old_render_process_id,
|
||||
int old_render_frame_id,
|
||||
int new_render_process_id,
|
||||
int new_render_frame_id) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||
g_brave_browser_process->tracking_protection_service()->ModifyRenderFrameKey(
|
||||
old_render_process_id, old_render_frame_id, new_render_process_id,
|
||||
new_render_frame_id);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace brave_shields {
|
||||
|
||||
TrackingProtectionHelper::TrackingProtectionHelper(WebContents* web_contents)
|
||||
: WebContentsObserver(web_contents) {}
|
||||
|
||||
TrackingProtectionHelper::~TrackingProtectionHelper() {}
|
||||
|
||||
void TrackingProtectionHelper::ReadyToCommitNavigation(
|
||||
NavigationHandle* handle) {
|
||||
if (handle->IsInMainFrame() &&
|
||||
!ui::PageTransitionIsRedirect(handle->GetPageTransition())) {
|
||||
RenderFrameHost* rfh = web_contents()->GetMainFrame();
|
||||
|
||||
// Here we post to the IO thread to avoid locks in
|
||||
// tracking_protection_service to avoid race conditions when accessing the
|
||||
// starting_site map during navigations and accessing storage access apis
|
||||
base::PostTask(
|
||||
FROM_HERE, {BrowserThread::IO},
|
||||
base::BindOnce(&SetStartingSiteForRenderFrame, handle->GetURL(),
|
||||
rfh->GetProcess()->GetID(), rfh->GetRoutingID()));
|
||||
}
|
||||
}
|
||||
|
||||
void TrackingProtectionHelper::RenderFrameDeleted(
|
||||
RenderFrameHost* render_frame_host) {
|
||||
base::PostTask(FROM_HERE, {BrowserThread::IO},
|
||||
base::BindOnce(&DeleteRenderFrameKey,
|
||||
render_frame_host->GetProcess()->GetID(),
|
||||
render_frame_host->GetRoutingID()));
|
||||
}
|
||||
|
||||
void TrackingProtectionHelper::RenderFrameHostChanged(
|
||||
RenderFrameHost* old_host,
|
||||
RenderFrameHost* new_host) {
|
||||
if (!old_host || old_host->GetParent() || new_host->GetParent()) {
|
||||
return;
|
||||
}
|
||||
base::PostTask(
|
||||
FROM_HERE, {BrowserThread::IO},
|
||||
base::BindOnce(&ModifyRenderFrameKey, old_host->GetProcess()->GetID(),
|
||||
old_host->GetRoutingID(), new_host->GetProcess()->GetID(),
|
||||
new_host->GetRoutingID()));
|
||||
}
|
||||
|
||||
WEB_CONTENTS_USER_DATA_KEY_IMPL(TrackingProtectionHelper)
|
||||
|
||||
} // namespace brave_shields
|
||||
@@ -1,43 +0,0 @@
|
||||
/* Copyright 2019 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_TRACKING_PROTECTION_HELPER_H_
|
||||
#define BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_TRACKING_PROTECTION_HELPER_H_
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "base/strings/string16.h"
|
||||
#include "base/synchronization/lock.h"
|
||||
#include "content/public/browser/web_contents_observer.h"
|
||||
#include "content/public/browser/web_contents_user_data.h"
|
||||
|
||||
namespace content {
|
||||
class WebContents;
|
||||
class NavigationHandle;
|
||||
} // namespace content
|
||||
|
||||
namespace brave_shields {
|
||||
|
||||
class TrackingProtectionHelper
|
||||
: public content::WebContentsObserver,
|
||||
public content::WebContentsUserData<TrackingProtectionHelper> {
|
||||
public:
|
||||
explicit TrackingProtectionHelper(content::WebContents*);
|
||||
~TrackingProtectionHelper() override;
|
||||
void ReadyToCommitNavigation(
|
||||
content::NavigationHandle* navigation_handle) override;
|
||||
void RenderFrameHostChanged(content::RenderFrameHost* old_host,
|
||||
content::RenderFrameHost* new_host) override;
|
||||
void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
|
||||
WEB_CONTENTS_USER_DATA_KEY_DECL();
|
||||
|
||||
private:
|
||||
friend class content::WebContentsUserData<TrackingProtectionHelper>;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(TrackingProtectionHelper);
|
||||
};
|
||||
|
||||
} // namespace brave_shields
|
||||
|
||||
#endif // BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_TRACKING_PROTECTION_HELPER_H_
|
||||
@@ -1,241 +0,0 @@
|
||||
/* Copyright (c) 2019 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/tracking_protection_service.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/task/post_task.h"
|
||||
#include "base/task_runner_util.h"
|
||||
#include "brave/common/brave_switches.h"
|
||||
#include "brave/components/brave_component_updater/browser/local_data_files_service.h"
|
||||
#include "content/public/browser/browser_task_traits.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
|
||||
#if BUILDFLAG(BRAVE_STP_ENABLED)
|
||||
#include "base/strings/string_split.h"
|
||||
#include "brave/components/brave_shields/browser/brave_shields_util.h"
|
||||
#include "brave/components/brave_shields/browser/tracking_protection_helper.h"
|
||||
#include "brave/components/brave_shields/common/brave_shield_constants.h"
|
||||
#include "components/content_settings/core/browser/host_content_settings_map.h"
|
||||
#endif
|
||||
|
||||
using content::BrowserThread;
|
||||
|
||||
namespace brave_shields {
|
||||
|
||||
#if BUILDFLAG(BRAVE_STP_ENABLED)
|
||||
const char kDatFileVersion[] = "1";
|
||||
const char kStorageTrackersFile[] = "StorageTrackingProtection.dat";
|
||||
#endif
|
||||
|
||||
TrackingProtectionService::TrackingProtectionService(
|
||||
LocalDataFilesService* local_data_files_service)
|
||||
: LocalDataFilesObserver(local_data_files_service),
|
||||
weak_factory_(this),
|
||||
weak_factory_io_thread_(this) {
|
||||
}
|
||||
|
||||
TrackingProtectionService::~TrackingProtectionService() {
|
||||
}
|
||||
|
||||
bool TrackingProtectionService::IsSmartTrackingProtectionEnabled() {
|
||||
#if BUILDFLAG(BRAVE_STP_ENABLED)
|
||||
const base::CommandLine& command_line =
|
||||
*base::CommandLine::ForCurrentProcess();
|
||||
return command_line.HasSwitch(switches::kEnableSmartTrackingProtection);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if BUILDFLAG(BRAVE_STP_ENABLED)
|
||||
TrackingProtectionService::RenderFrameIdKey::RenderFrameIdKey()
|
||||
: render_process_id(content::ChildProcessHost::kInvalidUniqueID),
|
||||
frame_routing_id(MSG_ROUTING_NONE) {}
|
||||
|
||||
TrackingProtectionService::RenderFrameIdKey::RenderFrameIdKey(
|
||||
int render_process_id,
|
||||
int frame_routing_id)
|
||||
: render_process_id(render_process_id),
|
||||
frame_routing_id(frame_routing_id) {}
|
||||
|
||||
bool TrackingProtectionService::RenderFrameIdKey::operator<(
|
||||
const RenderFrameIdKey& other) const {
|
||||
return std::tie(render_process_id, frame_routing_id) <
|
||||
std::tie(other.render_process_id, other.frame_routing_id);
|
||||
}
|
||||
|
||||
bool TrackingProtectionService::RenderFrameIdKey::operator==(
|
||||
const RenderFrameIdKey& other) const {
|
||||
return render_process_id == other.render_process_id &&
|
||||
frame_routing_id == other.frame_routing_id;
|
||||
}
|
||||
|
||||
void TrackingProtectionService::SetStartingSiteForRenderFrame(
|
||||
GURL starting_site,
|
||||
int render_process_id,
|
||||
int render_frame_id) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||
const RenderFrameIdKey key(render_process_id, render_frame_id);
|
||||
render_frame_key_to_starting_site_url[key] = starting_site;
|
||||
}
|
||||
|
||||
GURL TrackingProtectionService::GetStartingSiteForRenderFrame(
|
||||
int render_process_id,
|
||||
int render_frame_id) const {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
const RenderFrameIdKey key(render_process_id, render_frame_id);
|
||||
auto iter = render_frame_key_to_starting_site_url.find(key);
|
||||
if (iter != render_frame_key_to_starting_site_url.end()) {
|
||||
return iter->second;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void TrackingProtectionService::ModifyRenderFrameKey(int old_render_process_id,
|
||||
int old_render_frame_id,
|
||||
int new_render_process_id,
|
||||
int new_render_frame_id) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||
const RenderFrameIdKey old_key(old_render_process_id, old_render_frame_id);
|
||||
auto iter = render_frame_key_to_starting_site_url.find(old_key);
|
||||
if (iter != render_frame_key_to_starting_site_url.end()) {
|
||||
const RenderFrameIdKey new_key(new_render_process_id, new_render_frame_id);
|
||||
render_frame_key_to_starting_site_url.insert(
|
||||
std::pair<RenderFrameIdKey, GURL>(new_key, iter->second));
|
||||
render_frame_key_to_starting_site_url.erase(old_key);
|
||||
}
|
||||
}
|
||||
|
||||
void TrackingProtectionService::DeleteRenderFrameKey(int render_process_id,
|
||||
int render_frame_id) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||
const RenderFrameIdKey key(render_process_id, render_frame_id);
|
||||
render_frame_key_to_starting_site_url.erase(key);
|
||||
}
|
||||
|
||||
bool TrackingProtectionService::ShouldStoreState(HostContentSettingsMap* map,
|
||||
int render_process_id,
|
||||
int render_frame_id,
|
||||
const GURL& origin_url) const {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
if (!IsSmartTrackingProtectionEnabled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (first_party_storage_trackers_.empty()) {
|
||||
LOG(INFO) << "First party storage trackers list is empty";
|
||||
return true;
|
||||
}
|
||||
|
||||
const std::string host = origin_url.host();
|
||||
const GURL starting_site =
|
||||
GetStartingSiteForRenderFrame(render_process_id, render_frame_id);
|
||||
|
||||
// If starting host is the current host, user-interaction has happened
|
||||
// so we allow storage
|
||||
if (starting_site.host() == host) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!brave_shields::GetBraveShieldsEnabled(map, starting_site))
|
||||
return true;
|
||||
|
||||
|
||||
if (brave_shields::GetCookieControlType(map, starting_site) !=
|
||||
ControlType::BLOCK)
|
||||
return true;
|
||||
|
||||
// deny storage if host is found in the tracker list
|
||||
return first_party_storage_trackers_.find(host) ==
|
||||
first_party_storage_trackers_.end();
|
||||
}
|
||||
|
||||
void TrackingProtectionService::OnGetSTPDATFileData(std::string contents) {
|
||||
if (contents.empty()) {
|
||||
LOG(ERROR) << "Could not obtain first party trackers data";
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<std::string> storage_trackers =
|
||||
base::SplitString(base::StringPiece(contents.data(), contents.size()),
|
||||
",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
|
||||
|
||||
if (storage_trackers.empty()) {
|
||||
LOG(ERROR) << "No first party trackers found";
|
||||
return;
|
||||
}
|
||||
|
||||
base::PostTask(
|
||||
FROM_HERE, {BrowserThread::IO},
|
||||
base::BindOnce(
|
||||
&TrackingProtectionService::UpdateFirstPartyStorageTrackers,
|
||||
weak_factory_io_thread_.GetWeakPtr(), std::move(storage_trackers)));
|
||||
}
|
||||
|
||||
void TrackingProtectionService::UpdateFirstPartyStorageTrackers(
|
||||
std::vector<std::string> storage_trackers) {
|
||||
first_party_storage_trackers_ =
|
||||
base::flat_set<std::string>(std::move(storage_trackers));
|
||||
}
|
||||
|
||||
#else // !BUILDFLAG(BRAVE_STP_ENABLED)
|
||||
bool TrackingProtectionService::ShouldStoreState(HostContentSettingsMap* map,
|
||||
int render_process_id,
|
||||
int render_frame_id,
|
||||
const GURL& origin_url) const {
|
||||
return true;
|
||||
}
|
||||
#endif // BUILDFLAG(BRAVE_STP_ENABLED)
|
||||
|
||||
bool TrackingProtectionService::ShouldStartRequest(
|
||||
const GURL& url,
|
||||
blink::mojom::ResourceType resource_type,
|
||||
const std::string& tab_host,
|
||||
bool* matching_exception_filter) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||
// There are no exceptions in the TP service, but exceptions are
|
||||
// combined with brave/ad-block.
|
||||
if (matching_exception_filter) {
|
||||
*matching_exception_filter = false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void TrackingProtectionService::OnComponentReady(
|
||||
const std::string& component_id,
|
||||
const base::FilePath& install_dir,
|
||||
const std::string& manifest) {
|
||||
#if BUILDFLAG(BRAVE_STP_ENABLED)
|
||||
if (!IsSmartTrackingProtectionEnabled()) {
|
||||
return;
|
||||
}
|
||||
base::FilePath storage_tracking_protection_path = install_dir
|
||||
.AppendASCII(kDatFileVersion)
|
||||
.AppendASCII(kStorageTrackersFile);
|
||||
|
||||
base::PostTaskAndReplyWithResult(
|
||||
local_data_files_service()->GetTaskRunner().get(),
|
||||
FROM_HERE,
|
||||
base::BindOnce(&brave_component_updater::GetDATFileAsString,
|
||||
storage_tracking_protection_path),
|
||||
base::BindOnce(&TrackingProtectionService::OnGetSTPDATFileData,
|
||||
weak_factory_.GetWeakPtr()));
|
||||
#endif
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::unique_ptr<TrackingProtectionService> TrackingProtectionServiceFactory(
|
||||
LocalDataFilesService* local_data_files_service) {
|
||||
std::unique_ptr<TrackingProtectionService> service =
|
||||
std::make_unique<TrackingProtectionService>(local_data_files_service);
|
||||
return service;
|
||||
}
|
||||
|
||||
} // namespace brave_shields
|
||||
@@ -1,118 +0,0 @@
|
||||
/* Copyright (c) 2019 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_TRACKING_PROTECTION_SERVICE_H_
|
||||
#define BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_TRACKING_PROTECTION_SERVICE_H_
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "base/containers/flat_set.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/sequenced_task_runner.h"
|
||||
#include "base/synchronization/lock.h"
|
||||
#include "brave/components/brave_component_updater/browser/dat_file_util.h"
|
||||
#include "brave/components/brave_component_updater/browser/local_data_files_observer.h"
|
||||
#include "brave/components/brave_shields/browser/buildflags/buildflags.h" // For STP
|
||||
#include "third_party/blink/public/mojom/loader/resource_load_info.mojom-shared.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
class HostContentSettingsMap;
|
||||
class TrackingProtectionServiceTest;
|
||||
|
||||
using brave_component_updater::LocalDataFilesObserver;
|
||||
using brave_component_updater::LocalDataFilesService;
|
||||
|
||||
namespace brave_shields {
|
||||
|
||||
// The brave shields service in charge of tracking protection and init.
|
||||
class TrackingProtectionService : public LocalDataFilesObserver {
|
||||
public:
|
||||
explicit TrackingProtectionService(
|
||||
LocalDataFilesService* local_data_files_service);
|
||||
~TrackingProtectionService() override;
|
||||
|
||||
static bool IsSmartTrackingProtectionEnabled();
|
||||
|
||||
bool ShouldStartRequest(const GURL& spec,
|
||||
blink::mojom::ResourceType resource_type,
|
||||
const std::string& tab_host,
|
||||
bool* matching_exception_filter);
|
||||
|
||||
// implementation of LocalDataFilesObserver
|
||||
void OnComponentReady(const std::string& component_id,
|
||||
const base::FilePath& install_dir,
|
||||
const std::string& manifest) override;
|
||||
|
||||
// ShouldStoreState returns false if the Storage API is being invoked
|
||||
// by a site in the tracker list, and tracking protection is enabled for the
|
||||
// site that initiated the redirect tracking
|
||||
bool ShouldStoreState(HostContentSettingsMap* map,
|
||||
int render_process_id,
|
||||
int render_frame_id,
|
||||
const GURL& origin_url) const;
|
||||
|
||||
#if BUILDFLAG(BRAVE_STP_ENABLED)
|
||||
void SetStartingSiteForRenderFrame(GURL starting_site,
|
||||
int render_process_id,
|
||||
int render_frame_id);
|
||||
GURL GetStartingSiteForRenderFrame(int render_process_id,
|
||||
int render_frame_id) const;
|
||||
|
||||
void DeleteRenderFrameKey(int render_process_id, int render_frame_id);
|
||||
void ModifyRenderFrameKey(int old_render_process_id,
|
||||
int old_render_frame_id,
|
||||
int new_render_process_id,
|
||||
int new_render_frame_id);
|
||||
#endif
|
||||
|
||||
protected:
|
||||
#if BUILDFLAG(BRAVE_STP_ENABLED)
|
||||
// ParseStorageTrackersData parses the storage trackers list provided by
|
||||
// the offline-crawler
|
||||
void OnGetSTPDATFileData(std::string contents);
|
||||
void UpdateFirstPartyStorageTrackers(std::vector<std::string>);
|
||||
|
||||
// For Smart Tracking Protection, we need to keep track of the starting site
|
||||
// that initiated the redirects. We use RenderFrameIdKey to determine the
|
||||
// starting site for a given render frame host.
|
||||
struct RenderFrameIdKey {
|
||||
RenderFrameIdKey();
|
||||
RenderFrameIdKey(int render_process_id, int frame_routing_id);
|
||||
|
||||
int render_process_id;
|
||||
int frame_routing_id;
|
||||
|
||||
bool operator<(const RenderFrameIdKey& other) const;
|
||||
bool operator==(const RenderFrameIdKey& other) const;
|
||||
};
|
||||
#endif
|
||||
|
||||
private:
|
||||
#if BUILDFLAG(BRAVE_STP_ENABLED)
|
||||
base::flat_set<std::string> first_party_storage_trackers_;
|
||||
std::map<RenderFrameIdKey, GURL> render_frame_key_to_starting_site_url;
|
||||
#endif
|
||||
|
||||
std::vector<std::string> third_party_base_hosts_;
|
||||
std::map<std::string, std::vector<std::string>> third_party_hosts_cache_;
|
||||
base::Lock third_party_hosts_lock_;
|
||||
|
||||
base::WeakPtrFactory<TrackingProtectionService> weak_factory_;
|
||||
base::WeakPtrFactory<TrackingProtectionService> weak_factory_io_thread_;
|
||||
DISALLOW_COPY_AND_ASSIGN(TrackingProtectionService);
|
||||
};
|
||||
|
||||
// Creates the TrackingProtectionService
|
||||
std::unique_ptr<TrackingProtectionService> TrackingProtectionServiceFactory(
|
||||
LocalDataFilesService* local_data_files_service);
|
||||
|
||||
} // namespace brave_shields
|
||||
|
||||
#endif // BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_TRACKING_PROTECTION_SERVICE_H_
|
||||
@@ -1,215 +0,0 @@
|
||||
/* Copyright (c) 2019 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 "base/path_service.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "base/task/post_task.h"
|
||||
#include "base/test/thread_test_helper.h"
|
||||
#include "brave/browser/brave_browser_process.h"
|
||||
#include "brave/browser/extensions/brave_base_local_data_files_browsertest.h"
|
||||
#include "brave/common/brave_paths.h"
|
||||
#include "brave/common/pref_names.h"
|
||||
#include "brave/components/brave_component_updater/browser/local_data_files_service.h"
|
||||
#include "brave/components/brave_shields/browser/buildflags/buildflags.h" // For STP
|
||||
#include "brave/components/brave_shields/browser/tracking_protection_service.h"
|
||||
#include "chrome/browser/extensions/extension_browsertest.h"
|
||||
#include "chrome/browser/ui/browser.h"
|
||||
#include "chrome/test/base/ui_test_utils.h"
|
||||
#include "components/prefs/pref_service.h"
|
||||
#include "content/public/browser/browser_task_traits.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/test/browser_test_utils.h"
|
||||
#include "net/dns/mock_host_resolver.h"
|
||||
|
||||
#if BUILDFLAG(BRAVE_STP_ENABLED)
|
||||
#include "brave/common/brave_switches.h"
|
||||
#include "brave/components/brave_shields/browser/tracking_protection_helper.h"
|
||||
|
||||
using brave_shields::TrackingProtectionHelper;
|
||||
|
||||
const char kCancelledNavigation[] = "/cancelled_navigation.html";
|
||||
const char kRedirectPage[] = "/client-redirect?";
|
||||
const char kStoragePage[] = "/storage.html";
|
||||
#endif
|
||||
|
||||
const char kTestDataDirectory[] = "tracking-protection-data";
|
||||
const char kEmbeddedTestServerDirectory[] = "tracking-protection-web";
|
||||
|
||||
class TrackingProtectionServiceTest : public BaseLocalDataFilesBrowserTest {
|
||||
public:
|
||||
#if BUILDFLAG(BRAVE_STP_ENABLED)
|
||||
void SetUpDefaultCommandLine(base::CommandLine* command_line) override {
|
||||
InProcessBrowserTest::SetUpDefaultCommandLine(command_line);
|
||||
command_line->AppendSwitch(switches::kEnableSmartTrackingProtection);
|
||||
}
|
||||
#endif
|
||||
|
||||
// BaseLocalDataFilesBrowserTest overrides
|
||||
const char* test_data_directory() override { return kTestDataDirectory; }
|
||||
const char* embedded_test_server_directory() override {
|
||||
return kEmbeddedTestServerDirectory;
|
||||
}
|
||||
LocalDataFilesObserver* service() override {
|
||||
return g_brave_browser_process->tracking_protection_service();
|
||||
}
|
||||
};
|
||||
|
||||
#if BUILDFLAG(BRAVE_STP_ENABLED)
|
||||
IN_PROC_BROWSER_TEST_F(TrackingProtectionServiceTest, StorageTrackingBlocked) {
|
||||
ASSERT_TRUE(TrackingProtectionHelper::IsSmartTrackingProtectionEnabled());
|
||||
ASSERT_TRUE(InstallMockExtension());
|
||||
|
||||
std::string message;
|
||||
content::DOMMessageQueue message_queue;
|
||||
|
||||
// tracker.com is in the StorageTrackingProtection list
|
||||
const GURL tracking_url =
|
||||
embedded_test_server()->GetURL("tracker.com", kStoragePage);
|
||||
|
||||
const GURL url = embedded_test_server()->GetURL(
|
||||
"social.com", std::string(kRedirectPage) + tracking_url.spec());
|
||||
|
||||
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), url, 2);
|
||||
|
||||
content::WebContents* contents =
|
||||
browser()->tab_strip_model()->GetActiveWebContents();
|
||||
EXPECT_EQ("tracker.com", contents->GetURL().host());
|
||||
|
||||
bool cookie_blocked;
|
||||
ASSERT_TRUE(ExecuteScriptAndExtractBool(
|
||||
contents, "window.domAutomationController.send(!IsCookieAvailable())",
|
||||
&cookie_blocked));
|
||||
EXPECT_TRUE(cookie_blocked);
|
||||
|
||||
bool session_blocked;
|
||||
ASSERT_TRUE(ExecuteScriptAndExtractBool(
|
||||
contents,
|
||||
"window.domAutomationController.send(!IsSessionStorageAvailable())",
|
||||
&session_blocked));
|
||||
EXPECT_TRUE(session_blocked);
|
||||
|
||||
bool local_blocked;
|
||||
ASSERT_TRUE(ExecuteScriptAndExtractBool(
|
||||
contents,
|
||||
"window.domAutomationController.send(!IsLocalStorageAvailable())",
|
||||
&local_blocked));
|
||||
EXPECT_TRUE(local_blocked);
|
||||
|
||||
EXPECT_TRUE(message_queue.WaitForMessage(&message));
|
||||
|
||||
bool db_blocked;
|
||||
ASSERT_TRUE(ExecuteScriptAndExtractBool(
|
||||
contents, "window.domAutomationController.send(!IsDBAvailable())",
|
||||
&db_blocked));
|
||||
EXPECT_TRUE(db_blocked);
|
||||
|
||||
bool indexeddb_blocked;
|
||||
ASSERT_TRUE(ExecuteScriptAndExtractBool(
|
||||
contents, "window.domAutomationController.send(!IsIndexedDBAvailable())",
|
||||
&indexeddb_blocked));
|
||||
EXPECT_TRUE(indexeddb_blocked);
|
||||
}
|
||||
|
||||
IN_PROC_BROWSER_TEST_F(TrackingProtectionServiceTest, StorageTrackingAllowed) {
|
||||
ASSERT_TRUE(TrackingProtectionHelper::IsSmartTrackingProtectionEnabled());
|
||||
ASSERT_TRUE(InstallMockExtension());
|
||||
|
||||
std::string message;
|
||||
content::DOMMessageQueue message_queue;
|
||||
|
||||
// example.com is not in the StorageTrackingProtection list
|
||||
const GURL redirect_url =
|
||||
embedded_test_server()->GetURL("example.com", kStoragePage);
|
||||
|
||||
const GURL url = embedded_test_server()->GetURL(
|
||||
"social.com", kRedirectPage + redirect_url.spec());
|
||||
|
||||
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), url, 2);
|
||||
content::WebContents* contents =
|
||||
browser()->tab_strip_model()->GetActiveWebContents();
|
||||
EXPECT_EQ("example.com", contents->GetURL().host());
|
||||
|
||||
bool cookie_allowed;
|
||||
ASSERT_TRUE(ExecuteScriptAndExtractBool(
|
||||
contents, "window.domAutomationController.send(IsCookieAvailable())",
|
||||
&cookie_allowed));
|
||||
EXPECT_TRUE(cookie_allowed);
|
||||
|
||||
bool session_allowed;
|
||||
ASSERT_TRUE(ExecuteScriptAndExtractBool(
|
||||
contents,
|
||||
"window.domAutomationController.send(IsSessionStorageAvailable())",
|
||||
&session_allowed));
|
||||
EXPECT_TRUE(session_allowed);
|
||||
|
||||
bool local_allowed;
|
||||
ASSERT_TRUE(ExecuteScriptAndExtractBool(
|
||||
contents,
|
||||
"window.domAutomationController.send(IsLocalStorageAvailable())",
|
||||
&local_allowed));
|
||||
EXPECT_TRUE(local_allowed);
|
||||
|
||||
EXPECT_TRUE(message_queue.WaitForMessage(&message));
|
||||
|
||||
bool db_allowed;
|
||||
ASSERT_TRUE(ExecuteScriptAndExtractBool(
|
||||
contents, "window.domAutomationController.send(IsDBAvailable())",
|
||||
&db_allowed));
|
||||
EXPECT_TRUE(db_allowed);
|
||||
|
||||
bool indexeddb_allowed;
|
||||
ASSERT_TRUE(ExecuteScriptAndExtractBool(
|
||||
contents, "window.domAutomationController.send(IsIndexedDBAvailable())",
|
||||
&indexeddb_allowed));
|
||||
}
|
||||
|
||||
IN_PROC_BROWSER_TEST_F(TrackingProtectionServiceTest, CancelledNavigation) {
|
||||
ASSERT_TRUE(TrackingProtectionHelper::IsSmartTrackingProtectionEnabled());
|
||||
ASSERT_TRUE(InstallMockExtension());
|
||||
|
||||
std::string message;
|
||||
content::DOMMessageQueue message_queue;
|
||||
|
||||
// tracker.com is in the StorageTrackingProtection list
|
||||
const GURL tracking_url =
|
||||
embedded_test_server()->GetURL("tracker.com", kCancelledNavigation);
|
||||
|
||||
const GURL url = embedded_test_server()->GetURL(
|
||||
"social.com", std::string(kRedirectPage) + tracking_url.spec());
|
||||
|
||||
ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), url, 2);
|
||||
content::WebContents* contents =
|
||||
browser()->tab_strip_model()->GetActiveWebContents();
|
||||
EXPECT_EQ("tracker.com", contents->GetURL().host());
|
||||
|
||||
bool cookie_blocked;
|
||||
ASSERT_TRUE(ExecuteScriptAndExtractBool(
|
||||
contents,
|
||||
"window.domAutomationController.send(!IsIntialCookieAvailable())",
|
||||
&cookie_blocked));
|
||||
EXPECT_TRUE(cookie_blocked);
|
||||
|
||||
ASSERT_TRUE(ExecuteScript(
|
||||
contents,
|
||||
base::StringPrintf(
|
||||
"window.domAutomationController.send(StartNavigation(\"%s\"))",
|
||||
tracking_url.spec().c_str())));
|
||||
|
||||
// Cancel Navigation
|
||||
ASSERT_TRUE(ExecuteScript(
|
||||
contents, base::StringPrintf(
|
||||
"window.domAutomationController.send(window.stop())")));
|
||||
|
||||
// If the starting site is updated to the tracking site, then cookies
|
||||
// will be allowed
|
||||
bool cookie_allowed;
|
||||
ASSERT_TRUE(
|
||||
ExecuteScriptAndExtractBool(contents,
|
||||
"window.domAutomationController.send("
|
||||
"TryCookiesAfterCancelledNavigation())",
|
||||
&cookie_allowed));
|
||||
EXPECT_FALSE(cookie_allowed);
|
||||
}
|
||||
#endif
|
||||
@@ -1,12 +0,0 @@
|
||||
diff --git a/chrome/browser/content_settings/content_settings_manager_delegate.h b/chrome/browser/content_settings/content_settings_manager_delegate.h
|
||||
index 4cb1418935c13b0c1f852db995429d004c522198..b544a2f83157bf786852c9e7e5c9c56576dd211b 100644
|
||||
--- a/chrome/browser/content_settings/content_settings_manager_delegate.h
|
||||
+++ b/chrome/browser/content_settings/content_settings_manager_delegate.h
|
||||
@@ -14,6 +14,7 @@ class ContentSettingsManagerDelegate
|
||||
public:
|
||||
ContentSettingsManagerDelegate();
|
||||
~ContentSettingsManagerDelegate() override;
|
||||
+ BRAVE_CONTENT_SETTINGS_MANAGER_DELEGATE_H_
|
||||
|
||||
private:
|
||||
// content_settings::ContentSettingsManagerImpl::Delegate:
|
||||
@@ -601,7 +601,6 @@ if (!is_android) {
|
||||
"//brave/chromium_src/third_party/blink/renderer/core/frame/reporting_observer_browsertest.cc",
|
||||
"//brave/common/brave_channel_info_browsertest.cc",
|
||||
"//brave/components/brave_shields/browser/https_everywhere_service_browsertest.cc",
|
||||
"//brave/components/brave_shields/browser/tracking_protection_service_browsertest.cc",
|
||||
"//brave/components/content_settings/renderer/brave_content_settings_agent_impl_autoplay_browsertest.cc",
|
||||
"//brave/components/content_settings/renderer/brave_content_settings_agent_impl_browsertest.cc",
|
||||
"//brave/components/l10n/browser/locale_helper_mock.cc",
|
||||
|
||||
Reference in New Issue
Block a user