From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samuel Attard <sattard@slack-corp.com>
Date: Mon, 26 Aug 2019 14:32:41 -0700
Subject: feat: add set_theme_source to allow apps to override chromiums
 internal theme choice

This patch is required as Chromium doesn't currently let folks using
//ui override the theme choice in NativeTheme.  It defaults to
respecting the OS theme choice and some apps don't always want to do
that.  With this patch we can override the theme value that Chromium
uses internally for things like menus and devtools.

We can remove this patch once it has in some shape been upstreamed.

diff --git a/ui/native_theme/native_theme.h b/ui/native_theme/native_theme.h
index 8e2849fc1e17fc55ad146134b7031538337c1f5c..dc50640eb88e65adb7ecbec36c9d887efb805bbf 100644
--- a/ui/native_theme/native_theme.h
+++ b/ui/native_theme/native_theme.h
@@ -503,6 +503,8 @@ class COMPONENT_EXPORT(NATIVE_THEME) NativeTheme {
   }
 
   PreferredColorScheme preferred_color_scheme() const {
+    if (theme_source() == ThemeSource::kForcedLight) return PreferredColorScheme::kLight;
+    if (theme_source() == ThemeSource::kForcedDark) return PreferredColorScheme::kDark;
     return preferred_color_scheme_;
   }
   void set_preferred_color_scheme(PreferredColorScheme preferred_color_scheme) {
@@ -534,6 +536,24 @@ class COMPONENT_EXPORT(NATIVE_THEME) NativeTheme {
     caret_blink_interval_ = caret_blink_interval;
   }
 
+  enum ThemeSource {
+    kSystem,
+    kForcedDark,
+    kForcedLight,
+  };
+
+  ThemeSource theme_source() const {
+    return theme_source_;
+  }
+
+  void set_theme_source(ThemeSource theme_source) {
+    bool was_dark = preferred_color_scheme() == PreferredColorScheme::kDark;
+    theme_source_ = theme_source;
+    if ((preferred_color_scheme() == PreferredColorScheme::kDark) != was_dark) {
+      NotifyOnNativeThemeUpdated();
+    }
+  }
+
  protected:
   explicit NativeTheme(SystemTheme system_theme = SystemTheme::kDefault);
   virtual ~NativeTheme();
@@ -607,6 +627,7 @@ class COMPONENT_EXPORT(NATIVE_THEME) NativeTheme {
   ColorProviderKey::UserColorSource preferred_color_source_ =
       ColorProviderKey::UserColorSource::kAccent;
   base::TimeDelta caret_blink_interval_;
+  ThemeSource theme_source_ = ThemeSource::kSystem;
 
   raw_ptr<NativeTheme> associated_web_instance_ = nullptr;
 
