From 330e68161e08b832824dd33c5f87cb92ef963786 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Wed, 19 Dec 2018 14:15:57 +0000 Subject: [PATCH] Bug 1514762 - Delay modifying the observer list until we hit the event loop; r=smaug Differential Revision: https://phabricator.services.mozilla.com/D14830 --- dom/base/nsGlobalWindowOuter.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dom/base/nsGlobalWindowOuter.cpp b/dom/base/nsGlobalWindowOuter.cpp index 0a5aa7e3cbc8e..f972d4830ca01 100644 --- a/dom/base/nsGlobalWindowOuter.cpp +++ b/dom/base/nsGlobalWindowOuter.cpp @@ -7265,7 +7265,12 @@ mozilla::dom::TabGroup* nsPIDOMWindowOuter::TabGroup() { window->InitWasOffline(); nsCOMPtr obs = mozilla::services::GetObserverService(); if (obs) { - obs->AddObserver(window, PERM_CHANGE_NOTIFICATION, true); + // Delay calling AddObserver until we hit the event loop, in case we may be + // in the middle of modifying the observer list somehow. + NS_DispatchToMainThread( + NS_NewRunnableFunction("PermChangeDelayRunnable", [obs, window] { + obs->AddObserver(window, PERM_CHANGE_NOTIFICATION, true); + })); } nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); if (prefBranch) {