Bug 1532682 - Make HTMLVideoElement::EndCloningVisually completely sever references between source and target video elements. r=jya
authorMike Conley <mconley@mozilla.com>
Thu, 07 Mar 2019 22:42:42 +0000
changeset 520941 b202d2f7c0cebbf53d64661ff5f1b1b51f76e79a
parent 520940 ea4a69b40a661069ff0d4e212cba859b0717f814
child 520942 3fd4a7b0872e76f8396355a1811676dcfbd86a79
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1532682
milestone67.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 1532682 - Make HTMLVideoElement::EndCloningVisually completely sever references between source and target video elements. r=jya Differential Revision: https://phabricator.services.mozilla.com/D22109
dom/html/HTMLVideoElement.cpp
--- a/dom/html/HTMLVideoElement.cpp
+++ b/dom/html/HTMLVideoElement.cpp
@@ -28,16 +28,17 @@
 #include "MediaDecoderStateMachine.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/dom/WakeLock.h"
 #include "mozilla/dom/power/PowerManagerService.h"
 #include "mozilla/dom/Performance.h"
 #include "mozilla/dom/TimeRanges.h"
 #include "mozilla/dom/VideoPlaybackQuality.h"
 #include "mozilla/dom/VideoStreamTrack.h"
+#include "mozilla/Unused.h"
 
 #include <algorithm>
 #include <limits>
 
 nsGenericHTMLElement* NS_NewHTMLVideoElement(
     already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
     mozilla::dom::FromParser aFromParser) {
   mozilla::dom::HTMLVideoElement* element =
@@ -175,19 +176,17 @@ HTMLVideoElement::IsAttributeMapped(cons
 nsMapRuleToAttributesFunc HTMLVideoElement::GetAttributeMappingFunction()
     const {
   return &MapAttributesIntoRule;
 }
 
 void HTMLVideoElement::UnbindFromTree(bool aDeep, bool aNullParent) {
   if (mVisualCloneSource) {
     mVisualCloneSource->EndCloningVisually();
-    SetVisualCloneSource(nullptr);
   } else if (mVisualCloneTarget) {
-    mVisualCloneTarget->SetVisualCloneSource(nullptr);
     EndCloningVisually();
   }
 
   HTMLMediaElement::UnbindFromTree(aDeep, aNullParent);
 }
 
 nsresult HTMLVideoElement::SetAcceptHeader(nsIHttpChannel* aChannel) {
   nsAutoCString value(
@@ -452,16 +451,21 @@ void HTMLVideoElement::CloneElementVisua
              "Can't clone a video that's not bound to a DOM tree.");
   MOZ_ASSERT(!aTargetVideo.mUnboundFromTree,
              "Can't clone to a video that's not bound to a DOM tree.");
   if (mUnboundFromTree || aTargetVideo.mUnboundFromTree) {
     rv.Throw(NS_ERROR_UNEXPECTED);
     return;
   }
 
+  // Do we already have a visual clone target? If so, shut it down.
+  if (mVisualCloneTarget) {
+    EndCloningVisually();
+  }
+
   if (!SetVisualCloneTarget(&aTargetVideo)) {
     rv.Throw(NS_ERROR_FAILURE);
     return;
   }
 
   if (!aTargetVideo.SetVisualCloneSource(this)) {
     mVisualCloneTarget = nullptr;
     rv.Throw(NS_ERROR_FAILURE);
@@ -508,13 +512,14 @@ void HTMLVideoElement::EndCloningVisuall
     VideoFrameContainer* container =
         mVisualCloneTarget->GetVideoFrameContainer();
     if (container && mVisualCloneTarget->mSelectedVideoStreamTrack) {
       mVisualCloneTarget->mSelectedVideoStreamTrack->RemoveVideoOutput(
           container);
     }
   }
 
-  mVisualCloneTarget = nullptr;
+  Unused << mVisualCloneTarget->SetVisualCloneSource(nullptr);
+  Unused << SetVisualCloneTarget(nullptr);
 }
 
 }  // namespace dom
 }  // namespace mozilla