From 5fbe75cea296e0657faccb372bf99ca14cded3be Mon Sep 17 00:00:00 2001 From: Claudio DeSouza Date: Fri, 19 Sep 2025 17:53:36 +0100 Subject: [PATCH] [cr142] Fix cancelling dark mode for private Tor session Chromium changes: https://chromium.googlesource.com/chromium/src/+/382df26c0a6d79b5fe307be8470656fc09c9d122 commit 382df26c0a6d79b5fe307be8470656fc09c9d122 Author: Peter Kasting Date: Thu Sep 18 15:17:41 2025 -0700 Add OsSettingsProvider API for preferred color scheme. This is the last API I intend to add for the foreseeable future. It is the most sprawling because so many tests and test harnesses need updating, but it's not really more complex than other APIs. It enables cleaning up a lot of "last remaining bits" of various classes, tests, etc. that have been progressively hollowed out via the previous APIs, which contributes to the CL size. As with the preferred contrast API, this moves the Windows-specific code into the cross-platform provider, but it still only fires for Windows in practice because no other platform sets system colors. The rationale is the same: this isn't really Windows-specific code, and if we start plumbing system colors on other platforms, we probably also want this to fire there. Bug: 431953872 Change-Id: I4147f7e178cc7f2ab703d7f201de62be83cd5efb AX-Relnotes: n/a. Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6956986 Reviewed-by: Alex Moshchuk Reviewed-by: Thomas Anderson Reviewed-by: Tibor Goldschwendt Reviewed-by: Yiren Wang Reviewed-by: Tom Lukaszewicz Reviewed-by: Hidehiko Abe Auto-Submit: Peter Kasting Commit-Queue: Peter Kasting Reviewed-by: Jacques Newman Reviewed-by: Mitsuru Oshima Cr-Commit-Position: refs/heads/main@{#1517596} --- ...mode_fingerprint_protection_browsertest.cc | 22 +++---------------- .../ui/native_theme/native_theme_win.cc | 6 ----- .../ui-native_theme-native_theme_win.cc.patch | 12 ---------- 3 files changed, 3 insertions(+), 37 deletions(-) delete mode 100644 patches/ui-native_theme-native_theme_win.cc.patch diff --git a/browser/farbling/brave_dark_mode_fingerprint_protection_browsertest.cc b/browser/farbling/brave_dark_mode_fingerprint_protection_browsertest.cc index 37b88677c7b..e55e7591f61 100644 --- a/browser/farbling/brave_dark_mode_fingerprint_protection_browsertest.cc +++ b/browser/farbling/brave_dark_mode_fingerprint_protection_browsertest.cc @@ -30,7 +30,7 @@ #include "ui/color/color_provider_key.h" #include "ui/color/color_provider_manager.h" #include "ui/color/color_provider_source.h" -#include "ui/native_theme/test_native_theme.h" +#include "ui/native_theme/mock_os_settings_provider.h" using brave_shields::ControlType; using brave_shields::features::kBraveDarkModeBlock; @@ -46,19 +46,6 @@ class BraveDarkModeFingerprintProtectionTest : public InProcessBrowserTest { brave_shields::features::kBraveShowStrictFingerprintingMode); } - class BraveContentBrowserClientWithWebTheme - : public BraveContentBrowserClient { - public: - explicit BraveContentBrowserClientWithWebTheme(const ui::NativeTheme* theme) - : theme_(theme) {} - - protected: - const ui::NativeTheme* GetWebTheme() const override { return theme_; } - - private: - const raw_ptr theme_; - }; - class MockColorProviderSource : public ui::ColorProviderSource { public: explicit MockColorProviderSource(bool is_dark) { @@ -95,9 +82,6 @@ class BraveDarkModeFingerprintProtectionTest : public InProcessBrowserTest { void SetUpOnMainThread() override { InProcessBrowserTest::SetUpOnMainThread(); - content::SetBrowserClientForTesting( - new BraveContentBrowserClientWithWebTheme(&test_theme_)); - host_resolver()->AddRule("*", "127.0.0.1"); content::SetupCrossSiteRedirector(embedded_test_server()); @@ -135,7 +119,7 @@ class BraveDarkModeFingerprintProtectionTest : public InProcessBrowserTest { } void SetDarkMode(bool dark_mode) { - test_theme_.SetPreferredColorScheme( + os_settings_provider_.SetPreferredColorScheme( dark_mode ? ui::NativeTheme::PreferredColorScheme::kDark : ui::NativeTheme::PreferredColorScheme::kLight); browser() @@ -175,7 +159,7 @@ class BraveDarkModeFingerprintProtectionTest : public InProcessBrowserTest { } protected: - ui::TestNativeTheme test_theme_; + ui::MockOsSettingsProvider os_settings_provider_; MockColorProviderSource dark_color_provider_source_{true}; MockColorProviderSource light_color_provider_source_{false}; diff --git a/chromium_src/ui/native_theme/native_theme_win.cc b/chromium_src/ui/native_theme/native_theme_win.cc index 8e7f5b38925..d2101257073 100644 --- a/chromium_src/ui/native_theme/native_theme_win.cc +++ b/chromium_src/ui/native_theme/native_theme_win.cc @@ -7,13 +7,7 @@ namespace { bool s_ignore_system_dark_mode_change = false; } // namespace -#define BRAVE_NATIVETHEMEWIN_UPDATEDARKMODESTATUS \ - if (s_ignore_system_dark_mode_change) { \ - return; \ - } - #include -#undef BRAVE_NATIVETHEMEWIN_UPDATEDARKMODESTATUS namespace ui { diff --git a/patches/ui-native_theme-native_theme_win.cc.patch b/patches/ui-native_theme-native_theme_win.cc.patch deleted file mode 100644 index 80d38ce639c..00000000000 --- a/patches/ui-native_theme-native_theme_win.cc.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/ui/native_theme/native_theme_win.cc b/ui/native_theme/native_theme_win.cc -index 7468404c730c68bc8ba7565bf613aa69f13e3095..544b547ef365ad2eb8dc8c40e943bbaa3ad696ba 100644 ---- a/ui/native_theme/native_theme_win.cc -+++ b/ui/native_theme/native_theme_win.cc -@@ -1669,6 +1669,7 @@ void NativeThemeWin::UpdateDarkModeStatus() { - &apps_use_light_theme); - in_dark_mode_ = (apps_use_light_theme == 0); - } -+ BRAVE_NATIVETHEMEWIN_UPDATEDARKMODESTATUS - set_preferred_color_scheme(CalculatePreferredColorScheme()); - CloseHandlesInternal(); - NotifyOnNativeThemeUpdated();