Bug 1440356 - Only call the window callback for found listeners. r=johannh
authorAndreas Pehrson <pehrsons@mozilla.com>
Fri, 23 Feb 2018 16:34:32 +0100
changeset 461345 c1c554a925540610b7f37146581b2166c6edf8b9
parent 461344 71c5ae05d2ab65b9fdd07a9234ccc01c53b70e56
child 461346 20e29db472c7043e74e73feb2329cbdb15630a71
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1440356
milestone60.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 1440356 - Only call the window callback for found listeners. r=johannh
dom/media/MediaManager.cpp
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -3111,19 +3111,16 @@ MediaManager::OnNavigation(uint64_t aWin
     IterateWindowListeners(window->AsInner(),
         [self = RefPtr<MediaManager>(this),
          windowID = DebugOnly<decltype(aWindowID)>(aWindowID)]
         (GetUserMediaWindowListener* aListener)
         {
           // Grab a strong ref since RemoveAll() might destroy the listener
           // mid-way when clearing the mActiveWindows reference.
           RefPtr<GetUserMediaWindowListener> listener(aListener);
-          if (!listener) {
-            return;
-          }
 
           listener->Stop();
           listener->RemoveAll();
           MOZ_ASSERT(!self->GetWindowListener(windowID));
         });
   } else {
     RemoveWindowID(aWindowID);
   }
@@ -3660,36 +3657,34 @@ MediaManager::StopScreensharing(uint64_t
 
   auto* window = nsGlobalWindowInner::GetInnerWindowWithId(aWindowID);
   if (!window) {
     return;
   }
   IterateWindowListeners(window->AsInner(),
     [](GetUserMediaWindowListener* aListener)
     {
-      if (!aListener) {
-        return;
-      }
-
       aListener->StopSharing();
     });
 }
 
 template<typename FunctionType>
 void
 MediaManager::IterateWindowListeners(nsPIDOMWindowInner* aWindow,
                                      const FunctionType& aCallback)
 {
   // Iterate the docshell tree to find all the child windows, and for each
   // invoke the callback
   if (aWindow) {
     {
       uint64_t windowID = aWindow->WindowID();
       GetUserMediaWindowListener* listener = GetWindowListener(windowID);
-      aCallback(listener);
+      if (listener) {
+        aCallback(listener);
+      }
       // NB: `listener` might have been destroyed.
     }
 
     // iterate any children of *this* window (iframes, etc)
     nsCOMPtr<nsIDocShell> docShell = aWindow->GetDocShell();
     if (docShell) {
       int32_t i, count;
       docShell->GetChildCount(&count);