diff --git a/gfx/src/nsITheme.h b/gfx/src/nsITheme.h index b8e9de101f2e..aabc44681b10 100644 --- a/gfx/src/nsITheme.h +++ b/gfx/src/nsITheme.h @@ -222,6 +222,9 @@ class nsITheme : public nsISupports { NS_DEFINE_STATIC_IID_ACCESSOR(nsITheme, NS_ITHEME_IID) // Singleton accessor function -extern already_AddRefed do_GetNativeTheme(); +// +// Do not use directly, use nsPresContext::GetTheme instead. +extern already_AddRefed do_GetNativeThemeDoNotUseDirectly(); +extern already_AddRefed do_GetBasicNativeThemeDoNotUseDirectly(); #endif diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 9188b402a105..4d56810a6a7c 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -82,6 +82,7 @@ #include "mozilla/GlobalStyleSheetCache.h" #include "mozilla/ServoBindings.h" #include "mozilla/StaticPrefs_layout.h" +#include "mozilla/StaticPrefs_widget.h" #include "mozilla/StaticPrefs_zoom.h" #include "mozilla/StyleSheet.h" #include "mozilla/StyleSheetInlines.h" @@ -1275,7 +1276,12 @@ void nsPresContext::RecordInteractionTime(InteractionType aType, nsITheme* nsPresContext::GetTheme() { if (!sNoTheme && !mTheme) { - mTheme = do_GetNativeTheme(); + if (StaticPrefs::widget_disable_native_theme_for_content() && + (!IsChrome() || XRE_IsContentProcess())) { + mTheme = do_GetBasicNativeThemeDoNotUseDirectly(); + } else { + mTheme = do_GetNativeThemeDoNotUseDirectly(); + } if (!mTheme) sNoTheme = true; } diff --git a/widget/android/nsNativeThemeAndroid.cpp b/widget/android/nsNativeThemeAndroid.cpp index fbb2ec226063..8bab8e96d871 100644 --- a/widget/android/nsNativeThemeAndroid.cpp +++ b/widget/android/nsNativeThemeAndroid.cpp @@ -294,7 +294,7 @@ nsITheme::Transparency nsNativeThemeAndroid::GetWidgetTransparency( return eUnknownTransparency; } -already_AddRefed do_GetNativeTheme() { +already_AddRefed do_GetNativeThemeDoNotUseDirectly() { static nsCOMPtr inst; if (!inst) { diff --git a/widget/cocoa/nsNativeThemeCocoa.mm b/widget/cocoa/nsNativeThemeCocoa.mm index 148039130e81..8d5b2295bc0f 100644 --- a/widget/cocoa/nsNativeThemeCocoa.mm +++ b/widget/cocoa/nsNativeThemeCocoa.mm @@ -4370,15 +4370,11 @@ nsITheme::Transparency nsNativeThemeCocoa::GetWidgetTransparency(nsIFrame* aFram } } -already_AddRefed do_GetNativeTheme() { +already_AddRefed do_GetNativeThemeDoNotUseDirectly() { static nsCOMPtr inst; if (!inst) { - if (XRE_IsContentProcess() && StaticPrefs::widget_disable_native_theme_for_content()) { - inst = new nsNativeBasicTheme(); - } else { - inst = new nsNativeThemeCocoa(); - } + inst = new nsNativeThemeCocoa(); ClearOnShutdown(&inst); } diff --git a/widget/gtk/nsNativeThemeGTK.cpp b/widget/gtk/nsNativeThemeGTK.cpp index 107159dc3095..1cac433f3eda 100644 --- a/widget/gtk/nsNativeThemeGTK.cpp +++ b/widget/gtk/nsNativeThemeGTK.cpp @@ -2009,15 +2009,12 @@ bool nsNativeThemeGTK::WidgetAppearanceDependsOnWindowFocus( } } -already_AddRefed do_GetNativeTheme() { +already_AddRefed do_GetNativeThemeDoNotUseDirectly() { static nsCOMPtr inst; if (!inst) { if (gfxPlatform::IsHeadless()) { inst = new HeadlessThemeGTK(); - } else if (XRE_IsContentProcess() && - StaticPrefs::widget_disable_native_theme_for_content()) { - inst = new nsNativeBasicTheme(); } else { inst = new nsNativeThemeGTK(); } diff --git a/widget/nsNativeBasicTheme.cpp b/widget/nsNativeBasicTheme.cpp index 2ed1b9254f14..562b5b16374c 100644 --- a/widget/nsNativeBasicTheme.cpp +++ b/widget/nsNativeBasicTheme.cpp @@ -6,6 +6,7 @@ #include "nsNativeBasicTheme.h" #include "mozilla/StaticPrefs_layout.h" +#include "mozilla/ClearOnShutdown.h" #include "nsComboboxControlFrame.h" #include "nsCSSRendering.h" #include "nsDateTimeControlFrame.h" @@ -889,3 +890,12 @@ bool nsNativeBasicTheme::ThemeDrawsFocusForWidget(StyleAppearance aAppearance) { } bool nsNativeBasicTheme::ThemeNeedsComboboxDropmarker() { return true; } + +already_AddRefed do_GetBasicNativeThemeDoNotUseDirectly() { + static StaticRefPtr gInstance; + if (MOZ_UNLIKELY(!gInstance)) { + gInstance = new nsNativeBasicTheme(); + ClearOnShutdown(&gInstance); + } + return do_AddRef(gInstance); +} diff --git a/widget/windows/nsNativeThemeWin.cpp b/widget/windows/nsNativeThemeWin.cpp index d0926b1a1738..1378f465591d 100644 --- a/widget/windows/nsNativeThemeWin.cpp +++ b/widget/windows/nsNativeThemeWin.cpp @@ -4255,16 +4255,11 @@ bool nsNativeThemeWin::MayDrawCustomScrollbarPart(gfxContext* aContext, // Creation Routine /////////////////////////////////////////// -already_AddRefed do_GetNativeTheme() { +already_AddRefed do_GetNativeThemeDoNotUseDirectly() { static nsCOMPtr inst; if (!inst) { - if (XRE_IsContentProcess() && - StaticPrefs::widget_disable_native_theme_for_content()) { - inst = new nsNativeBasicTheme(); - } else { - inst = new nsNativeThemeWin(); - } + inst = new nsNativeThemeWin(); ClearOnShutdown(&inst); }