Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement first-party domain blocking #7952

Merged
merged 1 commit into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
58 changes: 28 additions & 30 deletions browser/brave_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -79,8 +80,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)
Expand Down Expand Up @@ -262,9 +263,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);
Expand Down Expand Up @@ -373,18 +373,18 @@ 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) {
return result;
}
auto* tab_helper =
speedreader::SpeedreaderTabHelper::FromWebContents(contents);
if (tab_helper && tab_helper->IsActiveForMainFrame()
&& request.resource_type
== static_cast<int>(blink::mojom::ResourceType::kMainFrame)) {
if (tab_helper && tab_helper->IsActiveForMainFrame() &&
request.resource_type ==
static_cast<int>(blink::mojom::ResourceType::kMainFrame)) {
result.push_back(std::make_unique<speedreader::SpeedReaderThrottle>(
g_brave_browser_process->speedreader_rewriter_service(),
base::ThreadTaskRunnerHandle::Get()));
Expand Down Expand Up @@ -436,20 +436,12 @@ void BraveContentBrowserClient::CreateWebSocket(
mojo::PendingRemote<network::mojom::WebSocketHandshakeClient>
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();
Expand All @@ -475,11 +467,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,
Expand Down Expand Up @@ -536,9 +526,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);
Expand All @@ -562,7 +552,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;
}
Expand Down Expand Up @@ -598,8 +588,8 @@ BraveContentBrowserClient::CreateThrottlesForNavigation(

#if BUILDFLAG(ENABLE_TOR)
std::unique_ptr<content::NavigationThrottle> 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<tor::OnionLocationNavigationThrottleDelegate>
Expand All @@ -617,8 +607,8 @@ BraveContentBrowserClient::CreateThrottlesForNavigation(

#if BUILDFLAG(IPFS_ENABLED)
std::unique_ptr<content::NavigationThrottle> 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));
Expand All @@ -634,5 +624,13 @@ BraveContentBrowserClient::CreateThrottlesForNavigation(
throttles.push_back(std::move(unstoppable_domains_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;
}
Loading