-
Notifications
You must be signed in to change notification settings - Fork 920
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
Add social blocking options #1818
Changes from all commits
364de21
2f8ebe3
ec009bb
a547c23
136ef42
2220964
86e8ec6
404a406
cba5b16
9ddbcf4
2a45096
169c927
853394b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,7 +120,8 @@ bool HandleURLRewrite(GURL* url, | |
|
||
BraveContentBrowserClient::BraveContentBrowserClient( | ||
ChromeFeatureListCreator* chrome_feature_list_creator) | ||
: ChromeContentBrowserClient(chrome_feature_list_creator) {} | ||
: ChromeContentBrowserClient(chrome_feature_list_creator) { | ||
} | ||
|
||
BraveContentBrowserClient::~BraveContentBrowserClient() {} | ||
|
||
|
@@ -167,7 +168,8 @@ bool BraveContentBrowserClient::AllowAccessCookie( | |
content_settings::BraveCookieSettings* cookie_settings = | ||
(content_settings::BraveCookieSettings*)io_data->GetCookieSettings(); | ||
bool allow = !ShouldBlockCookie(allow_brave_shields, allow_1p_cookies, | ||
allow_3p_cookies, first_party, url) && | ||
allow_3p_cookies, first_party, url, | ||
cookie_settings->GetAllowGoogleAuth()) && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed on both counts |
||
cookie_settings->IsCookieAccessAllowed(url, first_party, tab_origin); | ||
return allow; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,10 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { | |
// Default Brave shields | ||
registry->RegisterBooleanPref(kHTTPSEVerywhereControlType, true); | ||
registry->RegisterBooleanPref(kNoScriptControlType, false); | ||
registry->RegisterBooleanPref(kGoogleLoginControlType, true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only thing that actually changes default behaviour in the context of this ticket. |
||
registry->RegisterBooleanPref(kFBEmbedControlType, true); | ||
registry->RegisterBooleanPref(kTwitterEmbedControlType, true); | ||
registry->RegisterBooleanPref(kLinkedInEmbedControlType, false); | ||
|
||
// WebTorrent | ||
registry->RegisterBooleanPref(kWebTorrentEnabled, true); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,12 +9,16 @@ | |
#include <utility> | ||
|
||
#include "base/task/post_task.h" | ||
#include "brave/browser/brave_browser_process_impl.h" | ||
#include "brave/common/pref_names.h" | ||
#include "brave/components/brave_shields/browser/ad_block_service.h" | ||
#include "brave/components/brave_shields/browser/ad_block_regional_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/common/brave_shield_constants.h" | ||
#include "chrome/browser/browser_process.h" | ||
#include "chrome/browser/content_settings/tab_specific_content_settings.h" | ||
#include "chrome/browser/profiles/profile_manager.h" | ||
#include "components/prefs/pref_change_registrar.h" | ||
#include "components/prefs/pref_service.h" | ||
#include "content/public/browser/browser_task_traits.h" | ||
|
@@ -42,6 +46,19 @@ content::WebContents* GetWebContentsFromProcessAndFrameId(int render_process_id, | |
return content::WebContents::FromFrameTreeNodeId(render_frame_id); | ||
} | ||
|
||
std::string GetTagFromPrefName(const std::string& pref_name) { | ||
if (pref_name == kFBEmbedControlType) { | ||
return brave_shields::kFacebookEmbeds; | ||
} | ||
if (pref_name == kTwitterEmbedControlType) { | ||
return brave_shields::kTwitterEmbeds; | ||
} | ||
if (pref_name == kLinkedInEmbedControlType) { | ||
return brave_shields::kLinkedInEmbeds; | ||
} | ||
return ""; | ||
} | ||
|
||
} // namespace | ||
|
||
base::flat_set<base::StringPiece>* TrackableSecurityHeaders() { | ||
|
@@ -81,7 +98,8 @@ void RemoveTrackableSecurityHeadersForThirdParty( | |
|
||
BraveNetworkDelegateBase::BraveNetworkDelegateBase( | ||
extensions::EventRouterForwarder* event_router) | ||
: ChromeNetworkDelegate(event_router), referral_headers_list_(nullptr) { | ||
: ChromeNetworkDelegate(event_router), referral_headers_list_(nullptr), | ||
allow_google_auth_(true) { | ||
// Initialize the preference change registrar. | ||
base::PostTaskWithTraits( | ||
FROM_HERE, {BrowserThread::UI}, | ||
|
@@ -102,6 +120,30 @@ void BraveNetworkDelegateBase::InitPrefChangeRegistrarOnUI() { | |
base::Unretained(this))); | ||
// Retrieve current referral headers, if any. | ||
OnReferralHeadersChanged(); | ||
|
||
PrefService* user_prefs = ProfileManager::GetActiveUserProfile()->GetPrefs(); | ||
user_pref_change_registrar_.reset(new PrefChangeRegistrar()); | ||
user_pref_change_registrar_->Init(user_prefs); | ||
user_pref_change_registrar_->Add( | ||
kGoogleLoginControlType, | ||
base::BindRepeating(&BraveNetworkDelegateBase::OnPreferenceChanged, | ||
base::Unretained(this), kGoogleLoginControlType)); | ||
user_pref_change_registrar_->Add( | ||
kFBEmbedControlType, | ||
base::BindRepeating(&BraveNetworkDelegateBase::OnPreferenceChanged, | ||
base::Unretained(this), kFBEmbedControlType)); | ||
user_pref_change_registrar_->Add( | ||
kTwitterEmbedControlType, | ||
base::BindRepeating(&BraveNetworkDelegateBase::OnPreferenceChanged, | ||
base::Unretained(this), kTwitterEmbedControlType)); | ||
user_pref_change_registrar_->Add( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I first tried adding these observers inside of the ad block base class but it caused problems because of threading, it doesn't work from the main thread which prefs needed to. |
||
kLinkedInEmbedControlType, | ||
base::BindRepeating(&BraveNetworkDelegateBase::OnPreferenceChanged, | ||
base::Unretained(this), kLinkedInEmbedControlType)); | ||
UpdateAdBlockFromPref(kFBEmbedControlType); | ||
UpdateAdBlockFromPref(kTwitterEmbedControlType); | ||
UpdateAdBlockFromPref(kLinkedInEmbedControlType); | ||
allow_google_auth_ = user_prefs->GetBoolean(kGoogleLoginControlType); | ||
} | ||
|
||
void BraveNetworkDelegateBase::OnReferralHeadersChanged() { | ||
|
@@ -195,6 +237,7 @@ bool BraveNetworkDelegateBase::OnCanGetCookies( | |
const net::CookieList& cookie_list, | ||
bool allowed_from_caller) { | ||
std::shared_ptr<brave::BraveRequestInfo> ctx(new brave::BraveRequestInfo()); | ||
ctx->allow_google_auth = allow_google_auth_; | ||
brave::BraveRequestInfo::FillCTXFromRequest(&request, ctx); | ||
ctx->event_type = brave::kOnCanGetCookies; | ||
bool allow = std::all_of(can_get_cookies_callbacks_.begin(), | ||
|
@@ -221,6 +264,7 @@ bool BraveNetworkDelegateBase::OnCanSetCookie( | |
net::CookieOptions* options, | ||
bool allowed_from_caller) { | ||
std::shared_ptr<brave::BraveRequestInfo> ctx(new brave::BraveRequestInfo()); | ||
ctx->allow_google_auth = allow_google_auth_; | ||
brave::BraveRequestInfo::FillCTXFromRequest(&request, ctx); | ||
ctx->event_type = brave::kOnCanSetCookies; | ||
|
||
|
@@ -367,3 +411,22 @@ bool BraveNetworkDelegateBase::IsRequestIdentifierValid( | |
uint64_t request_identifier) { | ||
return ContainsKey(callbacks_, request_identifier); | ||
} | ||
|
||
void BraveNetworkDelegateBase::OnPreferenceChanged( | ||
const std::string& pref_name) { | ||
UpdateAdBlockFromPref(pref_name); | ||
} | ||
|
||
void BraveNetworkDelegateBase::UpdateAdBlockFromPref( | ||
const std::string& pref_name) { | ||
DCHECK_CURRENTLY_ON(BrowserThread::UI); | ||
PrefService* user_prefs = ProfileManager::GetActiveUserProfile()->GetPrefs(); | ||
allow_google_auth_ = user_prefs->GetBoolean(kGoogleLoginControlType); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is not thread-safe to write |
||
std::string tag = GetTagFromPrefName(pref_name); | ||
if (tag.length() == 0) { | ||
return; | ||
} | ||
bool enabled = user_prefs->GetBoolean(pref_name); | ||
g_brave_browser_process->ad_block_service()->EnableTag(tag, enabled); | ||
g_brave_browser_process->ad_block_regional_service()->EnableTag(tag, enabled); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,26 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
/* 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/browser/net/cookie_network_delegate_helper.h" | ||
|
||
#include <memory> | ||
|
||
#include "brave/common/brave_cookie_blocking.h" | ||
|
||
namespace brave { | ||
|
||
bool OnCanGetCookiesForBraveShields(std::shared_ptr<BraveRequestInfo> ctx) { | ||
return !ShouldBlockCookie(ctx->allow_brave_shields, ctx->allow_1p_cookies, | ||
ctx->allow_3p_cookies, ctx->tab_origin, ctx->request_url); | ||
ctx->allow_3p_cookies, ctx->tab_origin, ctx->request_url, | ||
ctx->allow_google_auth); | ||
} | ||
|
||
bool OnCanSetCookiesForBraveShields(std::shared_ptr<BraveRequestInfo> ctx) { | ||
return !ShouldBlockCookie(ctx->allow_brave_shields, ctx->allow_1p_cookies, | ||
ctx->allow_3p_cookies, ctx->tab_origin, ctx->request_url); | ||
ctx->allow_3p_cookies, ctx->tab_origin, ctx->request_url, | ||
ctx->allow_google_auth); | ||
} | ||
|
||
} // namespace brave |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was needed otherwise a new unregistered pref error occurs only for 1 test in this file.