Bug 1514762 - Delay modifying the observer list until we hit the event loop; r=smaug
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 19 Dec 2018 14:15:57 +0000
changeset 451311 eddeea139dba1165867c563d0a117b5c0aaaeb18
parent 451310 5b1c8bfb5cd2f23306f5e6cdbc811789631a50bc
child 451312 0e2f7d9f5628c2f7a1bad01b371efab4b4f374c2
push id35234
push userrmaries@mozilla.com
push dateWed, 19 Dec 2018 21:56:37 +0000
treeherdermozilla-central@c8d73c84dc93 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1514762
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
--- a/dom/base/nsGlobalWindowOuter.cpp
+++ b/dom/base/nsGlobalWindowOuter.cpp
@@ -7260,17 +7260,22 @@ mozilla::dom::TabGroup* nsPIDOMWindowOut
   if (aIsChrome) {
     window->mIsChrome = true;
   }
   window->SetDocShell(aDocShell);
 
   window->InitWasOffline();
   nsCOMPtr<nsIObserverService> 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<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID);
   if (prefBranch) {
     prefBranch->AddObserver("network.cookie.cookieBehavior", window, true);
   }
   return window.forget();
 }