Bug 1778444 - Clear UISettings on shutdown. r=kaie

This should be the right fix.

Differential Revision: https://phabricator.services.mozilla.com/D151311
This commit is contained in:
Emilio Cobos Álvarez 2022-07-07 21:17:36 +00:00
parent aa49005e37
commit a4a6aa18d7

View File

@ -14,6 +14,7 @@
#include "nsIObserverService.h" #include "nsIObserverService.h"
#include "nsIAppShellService.h" #include "nsIAppShellService.h"
#include "nsAppShellCID.h" #include "nsAppShellCID.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/ResultVariant.h" #include "mozilla/ResultVariant.h"
#include "mozilla/Services.h" #include "mozilla/Services.h"
#include "mozilla/StaticPrefs_widget.h" #include "mozilla/StaticPrefs_widget.h"
@ -339,23 +340,25 @@ static IInspectable* GetUISettings() {
#ifndef __MINGW32__ #ifndef __MINGW32__
// We need to keep this alive for ~ever so that change callbacks work as // We need to keep this alive for ~ever so that change callbacks work as
// expected, sigh. // expected, sigh.
static ComPtr<IInspectable> sUiSettingsAsInspectable; static StaticRefPtr<IInspectable> sUiSettingsAsInspectable;
if (!IsWin10OrLater()) { if (!IsWin10OrLater()) {
// Windows.UI.ViewManagement.UISettings is Win10+ only. // Windows.UI.ViewManagement.UISettings is Win10+ only.
return nullptr; return nullptr;
} }
if (!sUiSettingsAsInspectable) { if (!sUiSettingsAsInspectable) {
ComPtr<IInspectable> uiSettingsAsInspectable;
::RoActivateInstance( ::RoActivateInstance(
HStringReference(RuntimeClass_Windows_UI_ViewManagement_UISettings) HStringReference(RuntimeClass_Windows_UI_ViewManagement_UISettings)
.Get(), .Get(),
&sUiSettingsAsInspectable); &uiSettingsAsInspectable);
if (NS_WARN_IF(!sUiSettingsAsInspectable)) { if (NS_WARN_IF(!uiSettingsAsInspectable)) {
return nullptr; return nullptr;
} }
ComPtr<IUISettings5> uiSettings5; ComPtr<IUISettings5> uiSettings5;
if (SUCCEEDED(sUiSettingsAsInspectable.As(&uiSettings5))) { if (SUCCEEDED(uiSettingsAsInspectable.As(&uiSettings5))) {
EventRegistrationToken unusedToken; EventRegistrationToken unusedToken;
auto callback = Callback<ITypedEventHandler< auto callback = Callback<ITypedEventHandler<
UISettings*, UISettingsAutoHideScrollBarsChangedEventArgs*>>( UISettings*, UISettingsAutoHideScrollBarsChangedEventArgs*>>(
@ -370,7 +373,7 @@ static IInspectable* GetUISettings() {
} }
ComPtr<IUISettings2> uiSettings2; ComPtr<IUISettings2> uiSettings2;
if (SUCCEEDED(sUiSettingsAsInspectable.As(&uiSettings2))) { if (SUCCEEDED(uiSettingsAsInspectable.As(&uiSettings2))) {
EventRegistrationToken unusedToken; EventRegistrationToken unusedToken;
auto callback = auto callback =
Callback<ITypedEventHandler<UISettings*, IInspectable*>>([](auto...) { Callback<ITypedEventHandler<UISettings*, IInspectable*>>([](auto...) {
@ -384,7 +387,7 @@ static IInspectable* GetUISettings() {
} }
ComPtr<IUISettings3> uiSettings3; ComPtr<IUISettings3> uiSettings3;
if (SUCCEEDED(sUiSettingsAsInspectable.As(&uiSettings3))) { if (SUCCEEDED(uiSettingsAsInspectable.As(&uiSettings3))) {
EventRegistrationToken unusedToken; EventRegistrationToken unusedToken;
auto callback = auto callback =
Callback<ITypedEventHandler<UISettings*, IInspectable*>>([](auto...) { Callback<ITypedEventHandler<UISettings*, IInspectable*>>([](auto...) {
@ -396,9 +399,12 @@ static IInspectable* GetUISettings() {
(void)NS_WARN_IF(FAILED( (void)NS_WARN_IF(FAILED(
uiSettings3->add_ColorValuesChanged(callback.Get(), &unusedToken))); uiSettings3->add_ColorValuesChanged(callback.Get(), &unusedToken)));
} }
sUiSettingsAsInspectable = dont_AddRef(uiSettingsAsInspectable.Detach());
ClearOnShutdown(&sUiSettingsAsInspectable);
} }
return sUiSettingsAsInspectable.Get(); return sUiSettingsAsInspectable.get();
#else #else
return nullptr; return nullptr;
#endif #endif