Bug 1531101 - Fire UAWidget setup / change events when starting or stopping a visual clone of a <video> element. r=jya
authorMike Conley <mconley@mozilla.com>
Wed, 13 Mar 2019 01:43:24 +0000
changeset 524634 72e7ff2f90948e6a41dd4c9bf4756f68df69828c
parent 524633 dff00691b1576fe6d78b38c4b6934c9a9a6aac60
child 524635 54b6941ad622a603f1f79330023a73829b90e062
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1531101
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 1531101 - Fire UAWidget setup / change events when starting or stopping a visual clone of a <video> element. r=jya Differential Revision: https://phabricator.services.mozilla.com/D22161
dom/html/HTMLVideoElement.cpp
dom/media/test/cloneElementVisually_helpers.js
--- a/dom/html/HTMLVideoElement.cpp
+++ b/dom/html/HTMLVideoElement.cpp
@@ -46,16 +46,17 @@ nsGenericHTMLElement* NS_NewHTMLVideoEle
   element->Init();
   return element;
 }
 
 namespace mozilla {
 namespace dom {
 
 static bool sVideoStatsEnabled;
+static bool sCloneElementVisuallyTesting;
 
 nsresult HTMLVideoElement::Clone(mozilla::dom::NodeInfo* aNodeInfo,
                                  nsINode** aResult) const {
   *aResult = nullptr;
   RefPtr<mozilla::dom::NodeInfo> ni(aNodeInfo);
   HTMLVideoElement* it = new HTMLVideoElement(ni.forget());
   it->Init();
   nsCOMPtr<nsINode> kungFuDeathGrip = it;
@@ -129,17 +130,18 @@ nsresult HTMLVideoElement::GetVideoSize(
     }
   }
   return NS_OK;
 }
 
 void HTMLVideoElement::Invalidate(bool aImageSizeChanged,
                                   Maybe<nsIntSize>& aNewIntrinsicSize,
                                   bool aForceInvalidate) {
-  HTMLMediaElement::Invalidate(aImageSizeChanged, aNewIntrinsicSize, aForceInvalidate);
+  HTMLMediaElement::Invalidate(aImageSizeChanged, aNewIntrinsicSize,
+                               aForceInvalidate);
   if (mVisualCloneTarget) {
     VideoFrameContainer* container =
         mVisualCloneTarget->GetVideoFrameContainer();
     if (container) {
       container->Invalidate();
     }
   }
 }
@@ -379,49 +381,53 @@ void HTMLVideoElement::ReleaseVideoWakeL
     rv.SuppressException();
     mScreenWakeLock = nullptr;
     return;
   }
 }
 
 bool HTMLVideoElement::SetVisualCloneTarget(
     HTMLVideoElement* aVisualCloneTarget) {
-  MOZ_DIAGNOSTIC_ASSERT(!aVisualCloneTarget || !aVisualCloneTarget->mUnboundFromTree,
-                        "Can't set the clone target to a disconnected video "
-                        "element.");
+  MOZ_DIAGNOSTIC_ASSERT(
+      !aVisualCloneTarget || !aVisualCloneTarget->mUnboundFromTree,
+      "Can't set the clone target to a disconnected video "
+      "element.");
   MOZ_DIAGNOSTIC_ASSERT(!mVisualCloneSource,
                         "Can't clone a video element that is already a clone.");
   if (!aVisualCloneTarget ||
       (!aVisualCloneTarget->mUnboundFromTree && !mVisualCloneSource)) {
     mVisualCloneTarget = aVisualCloneTarget;
     return true;
   }
   return false;
 }
 
 bool HTMLVideoElement::SetVisualCloneSource(
     HTMLVideoElement* aVisualCloneSource) {
-  MOZ_DIAGNOSTIC_ASSERT(!aVisualCloneSource || !aVisualCloneSource->mUnboundFromTree,
-                        "Can't set the clone source to a disconnected video "
-                        "element.");
+  MOZ_DIAGNOSTIC_ASSERT(
+      !aVisualCloneSource || !aVisualCloneSource->mUnboundFromTree,
+      "Can't set the clone source to a disconnected video "
+      "element.");
   MOZ_DIAGNOSTIC_ASSERT(!mVisualCloneTarget,
                         "Can't clone a video element that is already a "
                         "clone.");
   if (!aVisualCloneSource ||
       (!aVisualCloneSource->mUnboundFromTree && !mVisualCloneTarget)) {
     mVisualCloneSource = aVisualCloneSource;
     return true;
   }
   return false;
 }
 
 /* static */
 void HTMLVideoElement::InitStatics() {
   Preferences::AddBoolVarCache(&sVideoStatsEnabled,
                                "media.video_stats.enabled");
+  Preferences::AddBoolVarCache(&sCloneElementVisuallyTesting,
+                               "media.cloneElementVisually.testing");
 }
 
 /* static */
 bool HTMLVideoElement::IsVideoStatsEnabled() { return sVideoStatsEnabled; }
 
 double HTMLVideoElement::TotalPlayTime() const {
   double total = 0.0;
 
@@ -476,16 +482,20 @@ void HTMLVideoElement::CloneElementVisua
   if (!aTargetVideo.SetVisualCloneSource(this)) {
     mVisualCloneTarget = nullptr;
     rv.Throw(NS_ERROR_FAILURE);
     return;
   }
 
   aTargetVideo.SetMediaInfo(mMediaInfo);
 
+  if (IsInComposedDoc() && !sCloneElementVisuallyTesting) {
+    NotifyUAWidgetSetupOrChange();
+  }
+
   MaybeBeginCloningVisually();
 }
 
 void HTMLVideoElement::StopCloningElementVisually() {
   if (mVisualCloneTarget) {
     EndCloningVisually();
   }
 }
@@ -527,12 +537,16 @@ void HTMLVideoElement::EndCloningVisuall
     if (container && mVisualCloneTarget->mSelectedVideoStreamTrack) {
       mVisualCloneTarget->mSelectedVideoStreamTrack->RemoveVideoOutput(
           container);
     }
   }
 
   Unused << mVisualCloneTarget->SetVisualCloneSource(nullptr);
   Unused << SetVisualCloneTarget(nullptr);
+
+  if (IsInComposedDoc() && !sCloneElementVisuallyTesting) {
+    NotifyUAWidgetSetupOrChange();
+  }
 }
 
 }  // namespace dom
 }  // namespace mozilla
--- a/dom/media/test/cloneElementVisually_helpers.js
+++ b/dom/media/test/cloneElementVisually_helpers.js
@@ -8,16 +8,17 @@ const LONG_VIDEO = "http://mochi.test:88
  */
 async function setup() {
   await SpecialPowers.pushPrefEnv({
     set: [
       [ "media.test.video-suspend", true ],
       [ "media.suspend-bkgnd-video.enabled", true ],
       [ "media.suspend-bkgnd-video.delay-ms", 500 ],
       [ "media.dormant-on-pause-timeout-ms", 0 ],
+      [ "media.cloneElementVisually.testing", true ],
     ],
   });
 
   let originalVideo = document.getElementById("original");
   await setVideoSrc(originalVideo, TEST_VIDEO_1);
 }
 
 /**