Bug 1568169 - Remove SourceListener from window listener in all gUM failure paths. r=jib
authorAndreas Pehrson <apehrson@mozilla.com>
Thu, 03 Oct 2019 20:12:22 +0000
changeset 496226 f4dd9d524447fc0c34020e12d4f6a05fd42a6754
parent 496225 cdeda4226ef5bc59d1e8f9e03932d9b47635f222
child 496227 973cd615817e91f1249dc19d2c1774e154031c85
push id36647
push usernerli@mozilla.com
push dateFri, 04 Oct 2019 04:09:18 +0000
treeherdermozilla-central@678d4d2c3c4d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjib
bugs1568169
milestone71.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 1568169 - Remove SourceListener from window listener in all gUM failure paths. r=jib Differential Revision: https://phabricator.services.mozilla.com/D47901
dom/media/MediaManager.cpp
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -2749,51 +2749,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__);
                 }
               }
             }
 
@@ -2842,19 +2846,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) {