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

Add feature flag to toggle dark mode blocking when fingerprinting=strict #9735

Merged
merged 1 commit into from
Aug 13, 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
5 changes: 4 additions & 1 deletion browser/brave_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "brave/components/brave_shields/browser/brave_shields_util.h"
#include "brave/components/brave_shields/browser/domain_block_navigation_throttle.h"
#include "brave/components/brave_shields/common/brave_shield_constants.h"
#include "brave/components/brave_shields/common/features.h"
#include "brave/components/brave_wallet/common/buildflags/buildflags.h"
#include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h"
#include "brave/components/cosmetic_filters/browser/cosmetic_filters_resources.h"
Expand Down Expand Up @@ -698,7 +699,9 @@ bool BraveContentBrowserClient::OverrideWebPreferencesAfterNavigation(
HostContentSettingsMapFactory::GetForProfile(profile), url);
// https://github.com/brave/brave-browser/issues/15265
// Always use color scheme Light if fingerprinting mode strict
if (shields_up && fingerprinting_type == ControlType::BLOCK) {
if (base::FeatureList::IsEnabled(
brave_shields::features::kBraveDarkModeBlock) &&
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 @@ -6,13 +6,15 @@
#include "base/path_service.h"
#include "base/strings/stringprintf.h"
#include "base/task/post_task.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/thread_test_helper.h"
#include "brave/browser/brave_content_browser_client.h"
#include "brave/browser/extensions/brave_base_local_data_files_browsertest.h"
#include "brave/common/brave_paths.h"
#include "brave/common/pref_names.h"
#include "brave/components/brave_component_updater/browser/local_data_files_service.h"
#include "brave/components/brave_shields/browser/brave_shields_util.h"
#include "brave/components/brave_shields/common/features.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_content_client.h"
Expand All @@ -25,13 +27,14 @@
#include "ui/native_theme/test_native_theme.h"

using brave_shields::ControlType;
using brave_shields::features::kBraveDarkModeBlock;

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

class BraveDarkModeFingerprintProtection : public InProcessBrowserTest {
class BraveDarkModeFingerprintProtectionTest : public InProcessBrowserTest {
public:
class BraveContentBrowserClientWithWebTheme
: public BraveContentBrowserClient {
Expand Down Expand Up @@ -106,7 +109,7 @@ class BraveDarkModeFingerprintProtection : public InProcessBrowserTest {
GURL dark_mode_url_;
};

IN_PROC_BROWSER_TEST_F(BraveDarkModeFingerprintProtection, DarkModeCheck) {
IN_PROC_BROWSER_TEST_F(BraveDarkModeFingerprintProtectionTest, DarkModeCheck) {
test_theme_.SetDarkMode(true);
// On fingerprinting off, should return dark mode
AllowFingerprinting();
Expand All @@ -126,7 +129,8 @@ IN_PROC_BROWSER_TEST_F(BraveDarkModeFingerprintProtection, DarkModeCheck) {
EXPECT_EQ(u"light", tab_title);
}

IN_PROC_BROWSER_TEST_F(BraveDarkModeFingerprintProtection, RegressionCheck) {
IN_PROC_BROWSER_TEST_F(BraveDarkModeFingerprintProtectionTest,
RegressionCheck) {
test_theme_.SetDarkMode(false);
// On all modes, should return light
// Fingerprinting off
Expand All @@ -147,7 +151,8 @@ IN_PROC_BROWSER_TEST_F(BraveDarkModeFingerprintProtection, RegressionCheck) {
EXPECT_EQ(u"light", tab_title);
}

IN_PROC_BROWSER_TEST_F(BraveDarkModeFingerprintProtection, SettingsPagesCheck) {
IN_PROC_BROWSER_TEST_F(BraveDarkModeFingerprintProtectionTest,
SettingsPagesCheck) {
// On settings page should get dark mode with fingerprinting strict
test_theme_.SetDarkMode(true);
BlockFingerprinting();
Expand All @@ -157,3 +162,35 @@ IN_PROC_BROWSER_TEST_F(BraveDarkModeFingerprintProtection, SettingsPagesCheck) {
&result));
EXPECT_TRUE(result);
}

class BraveDarkModeFingerprintProtectionFlagDisabledTest
: public BraveDarkModeFingerprintProtectionTest {
public:
BraveDarkModeFingerprintProtectionFlagDisabledTest() {
feature_list_.InitAndDisableFeature(kBraveDarkModeBlock);
}

private:
base::test::ScopedFeatureList feature_list_;
};

IN_PROC_BROWSER_TEST_F(BraveDarkModeFingerprintProtectionFlagDisabledTest,
WithFeatureDisabled) {
test_theme_.SetDarkMode(true);
// On fingerprinting off, should return dark mode
AllowFingerprinting();
NavigateToURLUntilLoadStop(dark_mode_url());
std::u16string tab_title;
ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &tab_title));
EXPECT_EQ(u"dark", tab_title);
// On fingerprinting default, should return dark mode
SetFingerprintingDefault();
NavigateToURLUntilLoadStop(dark_mode_url());
ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &tab_title));
EXPECT_EQ(u"dark", tab_title);
// On fingerprinting block, should still return dark
BlockFingerprinting();
NavigateToURLUntilLoadStop(dark_mode_url());
ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &tab_title));
EXPECT_EQ(u"dark", tab_title);
}
5 changes: 5 additions & 0 deletions chromium_src/chrome/browser/about_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ using brave_shields::features::kBraveAdblockCollapseBlockedElements;
using brave_shields::features::kBraveAdblockCosmeticFiltering;
using brave_shields::features::kBraveAdblockCosmeticFilteringNative;
using brave_shields::features::kBraveAdblockCspRules;
using brave_shields::features::kBraveDarkModeBlock;
using brave_shields::features::kBraveDomainBlock;
using brave_shields::features::kBraveExtensionNetworkBlocking;
using ntp_background_images::features::kBraveNTPBrandedWallpaper;
Expand Down Expand Up @@ -172,6 +173,10 @@ using ntp_background_images::features::kBraveNTPSuperReferralWallpaper;
flag_descriptions::kBraveExtensionNetworkBlockingName, \
flag_descriptions::kBraveExtensionNetworkBlockingDescription, kOsAll, \
FEATURE_VALUE_TYPE(kBraveExtensionNetworkBlocking)}, \
{"brave-dark-mode-block", \
flag_descriptions::kBraveDarkModeBlockName, \
flag_descriptions::kBraveDarkModeBlockDescription, kOsAll, \
FEATURE_VALUE_TYPE(kBraveDarkModeBlock)}, \
SPEEDREADER_FEATURE_ENTRIES \
BRAVE_SYNC_FEATURE_ENTRIES \
BRAVE_IPFS_FEATURE_ENTRIES \
Expand Down
4 changes: 4 additions & 0 deletions chromium_src/chrome/browser/flag_descriptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ const char kBraveExtensionNetworkBlockingName[] =
"Enable extension network blocking";
const char kBraveExtensionNetworkBlockingDescription[] =
"Enable blocking for network requests initiated by extensions";
const char kBraveDarkModeBlockName[] =
"Enable dark mode blocking fingerprinting protection";
const char kBraveDarkModeBlockDescription[] =
"Always report light mode when fingerprinting protections set to Strict";
const char kBraveSidebarName[] = "Enable Sidebar";
// TODO(simon): Use more better description.
const char kBraveSidebarDescription[] = "Enable Sidebar";
Expand Down
2 changes: 2 additions & 0 deletions chromium_src/chrome/browser/flag_descriptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ extern const char kBraveDomainBlockName[];
extern const char kBraveDomainBlockDescription[];
extern const char kBraveExtensionNetworkBlockingName[];
extern const char kBraveExtensionNetworkBlockingDescription[];
extern const char kBraveDarkModeBlockName[];
extern const char kBraveDarkModeBlockDescription[];
extern const char kBraveSidebarName[];
extern const char kBraveSidebarDescription[];
extern const char kBraveSpeedreaderName[];
Expand Down
4 changes: 3 additions & 1 deletion components/brave_shields/common/features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const base::Feature kBraveDomainBlock{"BraveDomainBlock",
// potentially blocked by Brave Shields.
const base::Feature kBraveExtensionNetworkBlocking{
"BraveExtensionNetworkBlocking", base::FEATURE_DISABLED_BY_DEFAULT};

// When enabled, Brave will always report Light in Fingerprinting: Strict mode
const base::Feature kBraveDarkModeBlock{"BraveDarkModeBlock",
base::FEATURE_ENABLED_BY_DEFAULT};
} // namespace features
} // namespace brave_shields
1 change: 1 addition & 0 deletions components/brave_shields/common/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ extern const base::Feature kBraveAdblockCosmeticFilteringNative;
extern const base::Feature kBraveAdblockCspRules;
extern const base::Feature kBraveDomainBlock;
extern const base::Feature kBraveExtensionNetworkBlocking;
extern const base::Feature kBraveDarkModeBlock;
} // namespace features
} // namespace brave_shields

Expand Down