Skip to content

Commit

Permalink
get URL differently, move DCHECK
Browse files Browse the repository at this point in the history
  • Loading branch information
pilgrim-brave committed Mar 30, 2022
1 parent 89145c4 commit fc7510c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
15 changes: 8 additions & 7 deletions browser/brave_shields/reduce_language_navigation_throttle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,30 @@ ReduceLanguageNavigationThrottle::~ReduceLanguageNavigationThrottle() {

content::NavigationThrottle::ThrottleCheckResult
ReduceLanguageNavigationThrottle::WillStartRequest() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
UpdateHeaders();
return content::NavigationThrottle::PROCEED;
}

content::NavigationThrottle::ThrottleCheckResult
ReduceLanguageNavigationThrottle::WillRedirectRequest() {
return WillStartRequest();
UpdateHeaders();
return content::NavigationThrottle::PROCEED;
}

void ReduceLanguageNavigationThrottle::UpdateHeaders() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
content::NavigationHandle* handle = navigation_handle();
GURL visible_url = handle->GetWebContents()->GetVisibleURL();
GURL url = handle->GetURL();
content::BrowserContext* context =
handle->GetWebContents()->GetBrowserContext();
PrefService* pref_service = user_prefs::UserPrefs::Get(context);

if (!brave_shields::ShouldDoReduceLanguage(content_settings_, visible_url,
if (!brave_shields::ShouldDoReduceLanguage(content_settings_, url,
pref_service))
return;

ControlType fingerprinting_control_type =
brave_shields::GetFingerprintingControlType(content_settings_,
visible_url);
brave_shields::GetFingerprintingControlType(content_settings_, url);

// If fingerprint blocking is maximum, set Accept-Language header to
// static value regardless of other preferences.
Expand All @@ -94,13 +94,14 @@ void ReduceLanguageNavigationThrottle::UpdateHeaders() {
std::string languages =
pref_service->Get(language::prefs::kAcceptLanguages)->GetString();
std::string first_language = language::GetFirstLanguage(languages);
// Potentially add a fake q value after the language code.
std::vector<std::string> q_values = {";q=0.5", ";q=0.6", ";q=0.7",
";q=0.8", ";q=0.9", ""};
std::mt19937_64 prng;
auto* profile = Profile::FromBrowserContext(context);
if (g_brave_browser_process->brave_farbling_service()
->MakePseudoRandomGeneratorForURL(
visible_url, profile && !profile->IsOffTheRecord(), &prng)) {
url, profile && !profile->IsOffTheRecord(), &prng)) {
first_language += q_values[prng() % q_values.size()];
}
handle->SetRequestHeader(net::HttpRequestHeaders::kAcceptLanguage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ IN_PROC_BROWSER_TEST_F(BraveNavigatorLanguagesFarblingBrowserTest,
FarbleLanguagesServiceWorker) {
std::u16string expected_title(u"pass");
std::string domain = "b.test";
GURL url = https_server_.GetURL(domain, "/navigator/service-workers-languages.html");
GURL url =
https_server_.GetURL(domain, "/navigator/service-workers-languages.html");
// Farbling level: default
SetFingerprintingDefault(domain);
NavigateToURLUntilLoadStop(url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "third_party/blink/renderer/bindings/core/v8/binding_security.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"

#define BindingSecurity brave::BraveSessionCache::Init(); BindingSecurity
#define BindingSecurity \
brave::BraveSessionCache::Init(); \
BindingSecurity

#include "src/third_party/blink/renderer/core/core_initializer.cc"
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_RENDERER_PLATFORM_FONTS_FONT_FALLBACK_LIST_H_
#define BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_RENDERER_PLATFORM_FONTS_FONT_FALLBACK_LIST_H_

#include "base/callback.h"
#include "src/third_party/blink/renderer/platform/fonts/font_fallback_list.h"
#include "third_party/blink/renderer/platform/platform_export.h"
Expand All @@ -22,3 +25,5 @@ PLATFORM_EXPORT void RegisterAllowFontFamilyCallback(
AllowFontFamilyCallback callback);

} // namespace brave

#endif // BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_RENDERER_PLATFORM_FONTS_FONT_FALLBACK_LIST_H_

0 comments on commit fc7510c

Please sign in to comment.