Bug 1953907 - Avoid reading from uninitialized mHighContrastInfo.

MANUAL PUSH: UBSan fix CLOSED TREE
This commit is contained in:
Emilio Cobos Álvarez
2025-03-28 02:28:02 +01:00
parent 829925fc2c
commit f7bde01fa9
2 changed files with 11 additions and 12 deletions

View File

@@ -157,10 +157,10 @@ sRGBColor ThemeAccentColor::GetDarker() const {
return sRGBColor::FromABGR(ColorPalette::GetDarker(*mAccentColor)); return sRGBColor::FromABGR(ColorPalette::GetDarker(*mAccentColor));
} }
auto ThemeColors::ShouldBeHighContrast(const nsPresContext& aPc, auto ThemeColors::ShouldBeHighContrast(const nsIFrame* aFrame)
bool aCustomAccentColor)
-> HighContrastInfo { -> HighContrastInfo {
if (!aPc.GetBackgroundColorDraw()) { auto* pc = aFrame->PresContext();
if (!pc->GetBackgroundColorDraw()) {
// We make sure that we're drawing backgrounds, since otherwise layout // We make sure that we're drawing backgrounds, since otherwise layout
// will darken our used text colors etc anyways, and that can cause // will darken our used text colors etc anyways, and that can cause
// contrast issues with dark high-contrast themes. // contrast issues with dark high-contrast themes.
@@ -177,18 +177,18 @@ auto ThemeColors::ShouldBeHighContrast(const nsPresContext& aPc,
// or in "requested" mode (chrome-only) with no custom accent color. // or in "requested" mode (chrome-only) with no custom accent color.
// Otherwise it causes issues when pages only override some of the system // Otherwise it causes issues when pages only override some of the system
// colors, specially in dark themes. // colors, specially in dark themes.
switch (aPc.ForcedColors()) { switch (pc->ForcedColors()) {
case StyleForcedColors::None: case StyleForcedColors::None:
break; break;
case StyleForcedColors::Requested: case StyleForcedColors::Requested:
return !aCustomAccentColor; return aFrame->StyleUI()->mAccentColor.IsAuto();
case StyleForcedColors::Active: case StyleForcedColors::Active:
return true; return true;
} }
return false; return false;
}(); }();
const bool mustUseLight = const bool mustUseLight =
PreferenceSheet::PrefsFor(*aPc.Document()).mMustUseLightSystemColors; PreferenceSheet::PrefsFor(*pc->Document()).mMustUseLightSystemColors;
return {highContrast, mustUseLight}; return {highContrast, mustUseLight};
} }

View File

@@ -55,18 +55,17 @@ class ThemeColors {
}; };
const Document& mDoc; const Document& mDoc;
const HighContrastInfo mHighContrastInfo;
const ColorScheme mColorScheme; const ColorScheme mColorScheme;
const AccentColor mAccentColor; const AccentColor mAccentColor;
const HighContrastInfo mHighContrastInfo;
public: public:
explicit ThemeColors(const nsIFrame* aFrame, StyleAppearance aAppearance) explicit ThemeColors(const nsIFrame* aFrame, StyleAppearance aAppearance)
: mDoc(*aFrame->PresContext()->Document()), : mDoc(*aFrame->PresContext()->Document()),
mHighContrastInfo(ShouldBeHighContrast(aFrame)),
mColorScheme( mColorScheme(
ColorSchemeForWidget(aFrame, aAppearance, mHighContrastInfo)), ColorSchemeForWidget(aFrame, aAppearance, mHighContrastInfo)),
mAccentColor(*aFrame->Style(), mColorScheme), mAccentColor(*aFrame->Style(), mColorScheme) {}
mHighContrastInfo(ShouldBeHighContrast(*aFrame->PresContext(),
mAccentColor.IsCustom())) {}
virtual ~ThemeColors() = default; virtual ~ThemeColors() = default;
[[nodiscard]] static float ScaleLuminanceBy(float aLuminance, float aFactor) { [[nodiscard]] static float ScaleLuminanceBy(float aLuminance, float aFactor) {
@@ -102,8 +101,8 @@ class ThemeColors {
} }
// Whether we should use system colors (for high contrast mode). // Whether we should use system colors (for high contrast mode).
static HighContrastInfo ShouldBeHighContrast(const nsPresContext&, static HighContrastInfo ShouldBeHighContrast(const nsIFrame*);
bool aCustomAccentColor);
static ColorScheme ColorSchemeForWidget(const nsIFrame*, StyleAppearance, static ColorScheme ColorSchemeForWidget(const nsIFrame*, StyleAppearance,
const HighContrastInfo&); const HighContrastInfo&);