Skip to content

Commit

Permalink
Merge pull request #9215 from brave/bugfix/fingerprinting/dark-mode-s…
Browse files Browse the repository at this point in the history
…ettings

Bugfix: dark mode broken for settings when strict fingerprinting
  • Loading branch information
ShivanKaul authored Jun 23, 2021
2 parents 7ad07ad + ae6e455 commit 7f729f1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
8 changes: 5 additions & 3 deletions browser/brave_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -691,12 +691,14 @@ bool BraveContentBrowserClient::OverrideWebPreferencesAfterNavigation(
web_contents, prefs);
Profile* profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext());
const GURL url = web_contents->GetLastCommittedURL();
const bool shields_up = brave_shields::GetBraveShieldsEnabled(
HostContentSettingsMapFactory::GetForProfile(profile), url);
auto fingerprinting_type = brave_shields::GetFingerprintingControlType(
HostContentSettingsMapFactory::GetForProfile(profile),
web_contents->GetLastCommittedURL());
HostContentSettingsMapFactory::GetForProfile(profile), url);
// https://github.com/brave/brave-browser/issues/15265
// Always use color scheme Light if fingerprinting mode strict
if (fingerprinting_type == ControlType::BLOCK) {
if (shields_up && fingerprinting_type == ControlType::BLOCK) {
prefs->preferred_color_scheme = blink::mojom::PreferredColorScheme::kLight;
changed = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
using brave_shields::ControlType;

const char kEmbeddedTestServerDirectory[] = "dark_mode_block";
const char kMatchDarkMode[] =
"window.domAutomationController.send(window.matchMedia('(prefers-color-"
"scheme: dark)').matches)";

class BraveDarkModeFingerprintProtection : public InProcessBrowserTest {
public:
Expand Down Expand Up @@ -143,3 +146,14 @@ IN_PROC_BROWSER_TEST_F(BraveDarkModeFingerprintProtection, RegressionCheck) {
ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &tab_title));
EXPECT_EQ(base::ASCIIToUTF16("light"), tab_title);
}

IN_PROC_BROWSER_TEST_F(BraveDarkModeFingerprintProtection, SettingsPagesCheck) {
// On settings page should get dark mode with fingerprinting strict
test_theme_.SetDarkMode(true);
BlockFingerprinting();
NavigateToURLUntilLoadStop(GURL("brave://settings"));
bool result;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(contents(), kMatchDarkMode,
&result));
EXPECT_TRUE(result);
}

0 comments on commit 7f729f1

Please sign in to comment.