Bug 1548923 - part2 : reset cues' active flag when media element's ready state becomes 'HAVE_NOTHING' r=jya
authoralwu <alwu@mozilla.com>
Wed, 08 May 2019 17:46:39 +0000
changeset 532073 894e0713977b72b7045412e8b70898723a9aacde
parent 532072 667010d35e3418a9b9b2a21086dd411cb931d6e9
child 532074 1a3bb9e678fe8a4d999dbf399d4c3f4d5a1aa6b5
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1548923
milestone68.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 1548923 - part2 : reset cues' active flag when media element's ready state becomes 'HAVE_NOTHING' r=jya According to the spec [1], whenever the media element's readyState is changed back to `HAVE_NOTHING`, we have to reset all cues' active flag and update cue display in order to hide them. [1] https://html.spec.whatwg.org/multipage/media.html#text-track-cue-active-flag Differential Revision: https://phabricator.services.mozilla.com/D30110
dom/html/HTMLMediaElement.cpp
dom/html/TextTrackManager.cpp
dom/media/TextTrack.cpp
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -1870,20 +1870,16 @@ void HTMLMediaElement::AbortExistingLoad
   }
 
   // We may have changed mPaused, mAutoplaying, and other
   // things which can affect AddRemoveSelfReference
   AddRemoveSelfReference();
 
   mIsRunningSelectResource = false;
 
-  if (mTextTrackManager) {
-    mTextTrackManager->NotifyReset();
-  }
-
   mEventDeliveryPaused = false;
   mPendingEvents.Clear();
   mCurrentLoadPlayTime.Reset();
 
   AssertReadyStateIsNothing();
 }
 
 void HTMLMediaElement::NoSupportedMediaSourceError(
@@ -5516,16 +5512,23 @@ void HTMLMediaElement::ChangeReadyState(
 
   nsMediaReadyState oldState = mReadyState;
   mReadyState = aState;
   LOG(LogLevel::Debug,
       ("%p Ready state changed to %s", this, gReadyStateToString[aState]));
 
   DDLOG(DDLogCategory::Property, "ready_state", gReadyStateToString[aState]);
 
+  // https://html.spec.whatwg.org/multipage/media.html#text-track-cue-active-flag
+  // The user agent must synchronously unset cues' active flag whenever the
+  // media element's readyState is changed back to HAVE_NOTHING.
+  if (mReadyState == HAVE_NOTHING && mTextTrackManager) {
+    mTextTrackManager->NotifyReset();
+  }
+
   if (mNetworkState == NETWORK_EMPTY) {
     return;
   }
 
   UpdateAudioChannelPlayingState();
 
   // Handle raising of "waiting" event during seek (see 4.8.10.9)
   // or
--- a/dom/html/TextTrackManager.cpp
+++ b/dom/html/TextTrackManager.cpp
@@ -819,18 +819,24 @@ void TextTrackManager::NotifyCueUpdated(
   TimeMarchesOn();
   // For the case "Texttrack.mode = hidden/showing", if the mode
   // changing between showing and hidden, TimeMarchesOn
   // doesn't render the cue. Call DispatchUpdateCueDisplay() explicitly.
   DispatchUpdateCueDisplay();
 }
 
 void TextTrackManager::NotifyReset() {
+  // https://html.spec.whatwg.org/multipage/media.html#text-track-cue-active-flag
+  // This will unset all cues' active flag and update the cue display.
   WEBVTT_LOG("NotifyReset");
   mLastTimeMarchesOnCalled = media::TimeUnit::Zero();
+  for (uint32_t idx = 0; idx < mTextTracks->Length(); ++idx) {
+    (*mTextTracks)[idx]->SetCuesInactive();
+  }
+  UpdateCueDisplay();
 }
 
 void TextTrackManager::ReportTelemetryForTrack(TextTrack* aTextTrack) const {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aTextTrack);
   MOZ_ASSERT(mTextTracks->Length() > 0);
 
   TextTrackKind kind = aTextTrack->Kind();
--- a/dom/media/TextTrack.cpp
+++ b/dom/media/TextTrack.cpp
@@ -217,17 +217,20 @@ void TextTrack::SetTextTrackList(TextTra
 }
 
 HTMLTrackElement* TextTrack::GetTrackElement() { return mTrackElement; }
 
 void TextTrack::SetTrackElement(HTMLTrackElement* aTrackElement) {
   mTrackElement = aTrackElement;
 }
 
-void TextTrack::SetCuesInactive() { mCueList->SetCuesInactive(); }
+void TextTrack::SetCuesInactive() {
+  WEBVTT_LOG("SetCuesInactive");
+  mCueList->SetCuesInactive();
+}
 
 void TextTrack::NotifyCueUpdated(TextTrackCue* aCue) {
   WEBVTT_LOG("NotifyCueUpdated, cue=%p", aCue);
   mCueList->NotifyCueUpdated(aCue);
   HTMLMediaElement* mediaElement = GetMediaElement();
   if (mediaElement) {
     mediaElement->NotifyCueUpdated(aCue);
   }