[cr142] Fix cancelling dark mode for private Tor session

Chromium changes:
https://chromium.googlesource.com/chromium/src/+/382df26c0a6d79b5fe307be8470656fc09c9d122

commit 382df26c0a6d79b5fe307be8470656fc09c9d122
Author: Peter Kasting <pkasting@chromium.org>
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 <alexmos@chromium.org>
    Reviewed-by: Thomas Anderson <thomasanderson@chromium.org>
    Reviewed-by: Tibor Goldschwendt <tiborg@chromium.org>
    Reviewed-by: Yiren Wang <yrw@chromium.org>
    Reviewed-by: Tom Lukaszewicz <tluk@chromium.org>
    Reviewed-by: Hidehiko Abe <hidehiko@chromium.org>
    Auto-Submit: Peter Kasting <pkasting@chromium.org>
    Commit-Queue: Peter Kasting <pkasting@chromium.org>
    Reviewed-by: Jacques Newman <janewman@microsoft.com>
    Reviewed-by: Mitsuru Oshima <oshima@chromium.org>
    Cr-Commit-Position: refs/heads/main@{#1517596}
This commit is contained in:
Claudio DeSouza
2025-10-15 20:31:01 -04:00
committed by Emerick Rogul
parent f9eef7917c
commit 5fbe75cea2
3 changed files with 3 additions and 37 deletions
@@ -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<const ui::NativeTheme, DanglingUntriaged> 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};
@@ -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 <ui/native_theme/native_theme_win.cc>
#undef BRAVE_NATIVETHEMEWIN_UPDATEDARKMODESTATUS
namespace ui {
@@ -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();