Skip to content

Commit

Permalink
works
Browse files Browse the repository at this point in the history
  • Loading branch information
pilgrim-brave committed Feb 14, 2022
1 parent c92bd4c commit 2b06f33
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 29 deletions.
25 changes: 12 additions & 13 deletions browser/farbling/brave_navigator_languages_farbling_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
#include "chrome/common/chrome_content_client.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/language/core/browser/pref_names.h"
#include "components/network_session_configurator/common/network_switches.h"
#include "components/permissions/permission_request.h"
#include "components/prefs/pref_service.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/test/browser_test.h"
Expand Down Expand Up @@ -109,6 +111,14 @@ class BraveNavigatorLanguagesFarblingBrowserTest : public InProcessBrowserTest {
return WaitForLoadStop(web_contents());
}

void SetAcceptLanguages(const std::string& accept_languages) {
content::BrowserContext* context =
static_cast<content::BrowserContext*>(browser()->profile());
PrefService* prefs = user_prefs::UserPrefs::Get(context);
prefs->Set(language::prefs::kSelectedLanguages,
base::Value(accept_languages));
}

private:
std::unique_ptr<ChromeContentClient> content_client_;
std::unique_ptr<BraveContentBrowserClient> browser_content_client_;
Expand All @@ -124,19 +134,8 @@ IN_PROC_BROWSER_TEST_F(BraveNavigatorLanguagesFarblingBrowserTest,
// Farbling level: off
AllowFingerprinting(domain1);
NavigateToURLUntilLoadStop(url1);
#if 0
//FIXME
blink::LocalFrameToken frame_token = web_contents()->GetMainFrame()->GetFrameToken();
blink::WebLocalFrame* web_local_frame = blink::WebLocalFrame::FromFrameToken(frame_token);
//int routing_id = web_contents()->GetMainFrame()->GetRoutingID();
//content::RenderFrame* render_frame = content::RenderFrame::FromRoutingID(routing_id);
//blink::WebLocalFrame* web_local_frame = render_frame->GetWebFrame();
//blink::LocalFrame* local_frame = blink::DynamicTo<blink::LocalFrame>(web_local_frame);
blink::LocalDOMWindow* local_dom_window = local_frame->DomWindow();
blink::Navigator* navigator = local_dom_window->navigator();
navigator->SetLanguagesForTesting("en-US,en,es,la");
#endif
std::string testing_languages = "en-US,en,es,la";
SetAcceptLanguages(testing_languages);
EXPECT_EQ(testing_languages,
EvalJs(web_contents(), kNavigatorLanguagesScript));
AllowFingerprinting(domain2);
Expand All @@ -161,7 +160,7 @@ IN_PROC_BROWSER_TEST_F(BraveNavigatorLanguagesFarblingBrowserTest,
std::string strict_languages = "en-US,en";
EXPECT_EQ(strict_languages,
EvalJs(web_contents(), kNavigatorLanguagesScript));
AllowFingerprinting(domain2);
BlockFingerprinting(domain2);
NavigateToURLUntilLoadStop(url2);
EXPECT_EQ(strict_languages,
EvalJs(web_contents(), kNavigatorLanguagesScript));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,35 @@

#include "third_party/blink/public/platform/web_content_settings_client.h"

#define EnsureUpdatedLanguage EnsureUpdatedLanguage_ChromiumImpl
#define NavigatorLanguage NavigatorLanguage_ChromiumImpl
#include "src/third_party/blink/renderer/core/frame/navigator_language.cc"
#undef EnsureUpdatedLanguage
#undef NavigatorLanguage

namespace blink {

NavigatorLanguage::NavigatorLanguage(ExecutionContext* execution_context)
: NavigatorLanguage_ChromiumImpl(execution_context) {}

void NavigatorLanguage::EnsureUpdatedLanguage() {
LOG(ERROR) << "1";
EnsureUpdatedLanguage_ChromiumImpl();
languages_.clear();
languages_.push_back("zuul");
#if 0
NavigatorLanguage_ChromiumImpl::EnsureUpdatedLanguage();
blink::WebContentSettingsClient* settings =
brave::GetContentSettingsClientFor(execution_context_);
// If Brave Shields are down or anti-fingerprinting is off for this site,
// do nothing.
LOG(ERROR) << "1";
if (!settings || settings->GetBraveFarblingLevel() == BraveFarblingLevel::OFF)
return;
LOG(ERROR) << "2";
if (settings->GetBraveFarblingLevel() == BraveFarblingLevel::MAXIMUM) {
languages_.resize(2);
languages_[0] = "en-US";
languages_[1] = "en";
// If anti-fingerprinting is at maximum, override the entire language list
// regardless of locale or other settings.
languages_.clear();
languages_.push_back("en-US");
languages_.push_back("en");
} else {
// If anti-fingerprinting is on at its default level, remove all but the
// first language. (Note: this method requires a non-empty list, which the
// upstream code guarantees.)
languages_.Shrink(1);
}
#endif
}

} // namespace blink
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,28 @@
#ifndef BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_NAVIGATOR_LANGUAGE_H_
#define BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_NAVIGATOR_LANGUAGE_H_

#define EnsureUpdatedLanguage \
EnsureUpdatedLanguage_ChromiumImpl(); \
void EnsureUpdatedLanguage
#define NavigatorLanguage NavigatorLanguage_ChromiumImpl
#define EnsureUpdatedLanguage \
UnusedMethod() {} \
\
protected: \
virtual void EnsureUpdatedLanguage

#include "src/third_party/blink/renderer/core/frame/navigator_language.h"

#undef EnsureUpdatedLanguage
#undef NavigatorLanguage

namespace blink {

class CORE_EXPORT NavigatorLanguage : public NavigatorLanguage_ChromiumImpl {
public:
explicit NavigatorLanguage(ExecutionContext*);

protected:
void EnsureUpdatedLanguage() override;
};

} // namespace blink

#endif // BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_NAVIGATOR_LANGUAGE_H_

0 comments on commit 2b06f33

Please sign in to comment.