Bug 1514762 - Delay modifying the observer list until we hit the event loop. r=smaug, a=RyanVM
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 19 Dec 2018 14:15:57 +0000
changeset 509084 34be2a107bd4c664f179518ef9f11036cd00418f
parent 509083 49a93d8ec9f9a1e9d4b3322bfbb77d86be5d71a8
child 509085 e78a2c5fe344989e9711c204ff38370cbf06d49c
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, RyanVM
bugs1514762
milestone65.0
Bug 1514762 - Delay modifying the observer list until we hit the event loop. r=smaug, a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D14830
dom/base/nsGlobalWindowOuter.cpp
--- a/dom/base/nsGlobalWindowOuter.cpp
+++ b/dom/base/nsGlobalWindowOuter.cpp
@@ -7269,17 +7269,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();
 }