Commit 8ded339f authored by Andreas Pehrson's avatar Andreas Pehrson Committed by clairehurst
Browse files

Bug 1971116 - For global mute events, iterate on copies of containers. r=dbaker

Mute/unmute events are fired synchronously to content, which if it stops an
(event target) track in the event handler, may call back into and mutate the
containers we're iterating over.

Differential Revision: https://phabricator.services.mozilla.com/D254352
parent 6b68acc0
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -3572,7 +3572,9 @@ void MediaManager::OnCameraMute(bool aMute) {
  mCamerasMuted = aMute;
  // This is safe since we're on main-thread, and the windowlist can only
  // be added to from the main-thread
  for (const auto& window : mActiveWindows.Values()) {
  for (const auto& window :
       ToTArray<AutoTArray<RefPtr<GetUserMediaWindowListener>, 2>>(
           mActiveWindows.Values())) {
    window->MuteOrUnmuteCameras(aMute);
  }
}
@@ -3583,7 +3585,9 @@ void MediaManager::OnMicrophoneMute(bool aMute) {
  mMicrophonesMuted = aMute;
  // This is safe since we're on main-thread, and the windowlist can only
  // be added to from the main-thread
  for (const auto& window : mActiveWindows.Values()) {
  for (const auto& window :
       ToTArray<AutoTArray<RefPtr<GetUserMediaWindowListener>, 2>>(
           mActiveWindows.Values())) {
    window->MuteOrUnmuteMicrophones(aMute);
  }
}
@@ -4771,7 +4775,7 @@ void GetUserMediaWindowListener::MuteOrUnmuteCameras(bool aMute) {
  }
  mCamerasAreMuted = aMute;

  for (auto& l : mActiveListeners) {
  for (auto& l : mActiveListeners.Clone()) {
    if (l->GetDevice()->Kind() == MediaDeviceKind::Videoinput) {
      l->MuteOrUnmuteCamera(aMute);
    }
@@ -4786,7 +4790,7 @@ void GetUserMediaWindowListener::MuteOrUnmuteMicrophones(bool aMute) {
  }
  mMicrophonesAreMuted = aMute;

  for (auto& l : mActiveListeners) {
  for (auto& l : mActiveListeners.Clone()) {
    if (l->GetDevice()->Kind() == MediaDeviceKind::Audioinput) {
      l->MuteOrUnmuteMicrophone(aMute);
    }