Bug 1568169 - Remove SourceListener from window listener in all gUM failure paths. r=jib a=lizzard
authorAndreas Pehrson <apehrson@mozilla.com>
Thu, 03 Oct 2019 20:12:22 +0000
changeset 552263 1caac255d5174488fd593029f49e8d12b7158db0
parent 552262 6f220edd03c84782b8f7a54f6caf3a53d0ab9a0d
child 552264 a92487a991cfd18850c3aa1500f907b2cbf3e3f6
push id12117
push usernbeleuzu@mozilla.com
push dateSun, 06 Oct 2019 19:58:58 +0000
treeherdermozilla-beta@72f22c442fd7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjib, lizzard
bugs1568169
milestone70.0
Bug 1568169 - Remove SourceListener from window listener in all gUM failure paths. r=jib a=lizzard Differential Revision: https://phabricator.services.mozilla.com/D47901
dom/media/MediaManager.cpp
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -2752,51 +2752,55 @@ RefPtr<MediaManager::StreamPromise> Medi
 
             // Ensure that the window is still good.
             RefPtr<nsPIDOMWindowInner> window =
                 nsGlobalWindowInner::GetInnerWindowWithId(windowID);
             if (!window || !self->IsWindowListenerStillActive(windowListener)) {
               LOG("GetUserMedia: bad window (%" PRIu64
                   ") in post enumeration success callback 2!",
                   windowID);
+              windowListener->Remove(sourceListener);
               return StreamPromise::CreateAndReject(
                   MakeRefPtr<MediaMgrError>(MediaMgrError::Name::AbortError),
                   __func__);
             }
 
             if (badConstraint) {
               LOG("GetUserMedia: bad constraint found in post enumeration "
                   "promise2 success callback! Calling error handler!");
               nsString constraint;
               constraint.AssignASCII(badConstraint);
+              windowListener->Remove(sourceListener);
               return StreamPromise::CreateAndReject(
                   MakeRefPtr<MediaMgrError>(
                       MediaMgrError::Name::OverconstrainedError,
                       NS_LITERAL_STRING(""), constraint),
                   __func__);
             }
             if (!devices->Length()) {
               LOG("GetUserMedia: no devices found in post enumeration promise2 "
                   "success callback! Calling error handler!");
+              windowListener->Remove(sourceListener);
               // When privacy.resistFingerprinting = true, no
               // available device implies content script is requesting
               // a fake device, so report NotAllowedError.
               auto error = resistFingerprinting
                                ? MediaMgrError::Name::NotAllowedError
                                : MediaMgrError::Name::NotFoundError;
               return StreamPromise::CreateAndReject(
                   MakeRefPtr<MediaMgrError>(error), __func__);
             }
 
             // before we give up devices below
             nsCOMPtr<nsIMutableArray> devicesCopy = nsArray::Create();
             if (!askPermission) {
               for (auto& device : *devices) {
                 nsresult rv = devicesCopy->AppendElement(device);
                 if (NS_WARN_IF(NS_FAILED(rv))) {
+                  windowListener->Remove(sourceListener);
                   return StreamPromise::CreateAndReject(
                       MakeRefPtr<MediaMgrError>(
                           MediaMgrError::Name::AbortError),
                       __func__);
                 }
               }
             }
 
@@ -2845,19 +2849,20 @@ RefPtr<MediaManager::StreamPromise> Medi
                 obs->NotifyObservers(req, "getUserMedia:request", nullptr);
               }
             }
 #ifdef MOZ_WEBRTC
             EnableWebRtcLog();
 #endif
             return p;
           },
-          [](RefPtr<MediaMgrError>&& aError) {
+          [windowListener, sourceListener](RefPtr<MediaMgrError>&& aError) {
             LOG("GetUserMedia: post enumeration SelectSettings failure "
                 "callback called!");
+            windowListener->Remove(sourceListener);
             return StreamPromise::CreateAndReject(std::move(aError), __func__);
           });
 };
 
 RefPtr<MediaManager::StreamPromise> MediaManager::GetDisplayMedia(
     nsPIDOMWindowInner* aWindow,
     const DisplayMediaStreamConstraints& aConstraintsPassedIn,
     CallerType aCallerType) {