Bug 1531863 - part1 : implement 'GetMediaElement()' function wrapper. r=jya
☠☠ backed out by b653c9d4de17 ☠ ☠
authorAlastor Wu <alwu@mozilla.com>
Mon, 04 Mar 2019 21:00:59 +0000
changeset 520915 c9628b2b89b23bbbf49d9854f9c1569c614558e2
parent 520914 8bd2ac7f5d09da448033c76425d4c3bb53481786
child 520916 21bafd01b4389ff72d26f78f28079a6585708b4c
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
bugs1531863
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 1531863 - part1 : implement 'GetMediaElement()' function wrapper. r=jya To create a function wrapper which would automatically check whether track list exists, in order to reduce unnecessary checking for TextTrackList. Differential Revision: https://phabricator.services.mozilla.com/D21809
dom/media/TextTrack.cpp
dom/media/TextTrack.h
--- a/dom/media/TextTrack.cpp
+++ b/dom/media/TextTrack.cpp
@@ -72,33 +72,29 @@ JSObject* TextTrack::WrapObject(JSContex
   return TextTrack_Binding::Wrap(aCx, this, aGivenProto);
 }
 
 void TextTrack::SetMode(TextTrackMode aValue) {
   if (mMode != aValue) {
     mMode = aValue;
     if (aValue == TextTrackMode::Disabled) {
       // Remove all the cues in MediaElement.
-      if (mTextTrackList) {
-        HTMLMediaElement* mediaElement = mTextTrackList->GetMediaElement();
-        if (mediaElement) {
-          for (size_t i = 0; i < mCueList->Length(); ++i) {
-            mediaElement->NotifyCueRemoved(*(*mCueList)[i]);
-          }
+      HTMLMediaElement* mediaElement = GetMediaElement();
+      if (mediaElement) {
+        for (size_t i = 0; i < mCueList->Length(); ++i) {
+          mediaElement->NotifyCueRemoved(*(*mCueList)[i]);
         }
       }
       SetCuesInactive();
     } else {
       // Add all the cues into MediaElement.
-      if (mTextTrackList) {
-        HTMLMediaElement* mediaElement = mTextTrackList->GetMediaElement();
-        if (mediaElement) {
-          for (size_t i = 0; i < mCueList->Length(); ++i) {
-            mediaElement->NotifyCueAdded(*(*mCueList)[i]);
-          }
+      HTMLMediaElement* mediaElement = GetMediaElement();
+      if (mediaElement) {
+        for (size_t i = 0; i < mCueList->Length(); ++i) {
+          mediaElement->NotifyCueAdded(*(*mCueList)[i]);
         }
       }
     }
     if (mTextTrackList) {
       mTextTrackList->CreateAndDispatchChangeEvent();
     }
     // Ensure the TimeMarchesOn is called in case that the mCueList
     // is empty.
@@ -117,54 +113,46 @@ void TextTrack::GetId(nsAString& aId) co
 void TextTrack::AddCue(TextTrackCue& aCue) {
   TextTrack* oldTextTrack = aCue.GetTrack();
   if (oldTextTrack) {
     ErrorResult dummy;
     oldTextTrack->RemoveCue(aCue, dummy);
   }
   mCueList->AddCue(aCue);
   aCue.SetTrack(this);
-  if (mTextTrackList) {
-    HTMLMediaElement* mediaElement = mTextTrackList->GetMediaElement();
-    if (mediaElement && (mMode != TextTrackMode::Disabled)) {
-      mediaElement->NotifyCueAdded(aCue);
-    }
+  HTMLMediaElement* mediaElement = GetMediaElement();
+  if (mediaElement && (mMode != TextTrackMode::Disabled)) {
+    mediaElement->NotifyCueAdded(aCue);
   }
   SetDirty();
 }
 
 void TextTrack::RemoveCue(TextTrackCue& aCue, ErrorResult& aRv) {
   // Bug1304948, check the aCue belongs to the TextTrack.
   mCueList->RemoveCue(aCue, aRv);
   if (aRv.Failed()) {
     return;
   }
   aCue.SetActive(false);
   aCue.SetTrack(nullptr);
-  if (mTextTrackList) {
-    HTMLMediaElement* mediaElement = mTextTrackList->GetMediaElement();
-    if (mediaElement) {
-      mediaElement->NotifyCueRemoved(aCue);
-    }
+  HTMLMediaElement* mediaElement = GetMediaElement();
+  if (mediaElement) {
+    mediaElement->NotifyCueRemoved(aCue);
   }
   SetDirty();
 }
 
 void TextTrack::SetCuesDirty() {
   for (uint32_t i = 0; i < mCueList->Length(); i++) {
     ((*mCueList)[i])->Reset();
   }
 }
 
 void TextTrack::UpdateActiveCueList() {
-  if (!mTextTrackList) {
-    return;
-  }
-
-  HTMLMediaElement* mediaElement = mTextTrackList->GetMediaElement();
+  HTMLMediaElement* mediaElement = GetMediaElement();
   if (!mediaElement) {
     return;
   }
 
   // If we are dirty, i.e. an event happened that may cause the sorted mCueList
   // to have changed like a seek or an insert for a cue, than we need to rebuild
   // the active cue list from scratch.
   if (mDirty) {
@@ -212,22 +200,17 @@ TextTrackReadyState TextTrack::ReadyStat
 void TextTrack::SetReadyState(uint32_t aReadyState) {
   if (aReadyState <= TextTrackReadyState::FailedToLoad) {
     SetReadyState(static_cast<TextTrackReadyState>(aReadyState));
   }
 }
 
 void TextTrack::SetReadyState(TextTrackReadyState aState) {
   mReadyState = aState;
-
-  if (!mTextTrackList) {
-    return;
-  }
-
-  HTMLMediaElement* mediaElement = mTextTrackList->GetMediaElement();
+  HTMLMediaElement* mediaElement = GetMediaElement();
   if (mediaElement && (mReadyState == TextTrackReadyState::Loaded ||
                        mReadyState == TextTrackReadyState::FailedToLoad)) {
     mediaElement->RemoveTextTrack(this, true);
     mediaElement->UpdateReadyState();
   }
 }
 
 TextTrackList* TextTrack::GetTextTrackList() { return mTextTrackList; }
@@ -241,21 +224,19 @@ HTMLTrackElement* TextTrack::GetTrackEle
 void TextTrack::SetTrackElement(HTMLTrackElement* aTrackElement) {
   mTrackElement = aTrackElement;
 }
 
 void TextTrack::SetCuesInactive() { mCueList->SetCuesInactive(); }
 
 void TextTrack::NotifyCueUpdated(TextTrackCue* aCue) {
   mCueList->NotifyCueUpdated(aCue);
-  if (mTextTrackList) {
-    HTMLMediaElement* mediaElement = mTextTrackList->GetMediaElement();
-    if (mediaElement) {
-      mediaElement->NotifyCueUpdated(aCue);
-    }
+  HTMLMediaElement* mediaElement = GetMediaElement();
+  if (mediaElement) {
+    mediaElement->NotifyCueUpdated(aCue);
   }
   SetDirty();
 }
 
 void TextTrack::GetLabel(nsAString& aLabel) const {
   if (mTrackElement) {
     mTrackElement->GetLabel(aLabel);
   } else {
@@ -293,10 +274,14 @@ bool TextTrack::IsLoaded() {
     nsAutoString src;
     if (!(mTrackElement->GetAttr(kNameSpaceID_None, nsGkAtoms::src, src))) {
       return true;
     }
   }
   return (mReadyState >= Loaded);
 }
 
+HTMLMediaElement* TextTrack::GetMediaElement() {
+  return mTextTrackList ? mTextTrackList->GetMediaElement() : nullptr;
+}
+
 }  // namespace dom
 }  // namespace mozilla
--- a/dom/media/TextTrack.h
+++ b/dom/media/TextTrack.h
@@ -15,16 +15,17 @@
 
 namespace mozilla {
 namespace dom {
 
 class TextTrackList;
 class TextTrackCue;
 class TextTrackCueList;
 class HTMLTrackElement;
+class HTMLMediaElement;
 
 enum TextTrackSource { Track, AddTextTrack, MediaResourceSpecific };
 
 // Constants for numeric readyState property values.
 enum TextTrackReadyState {
   NotLoaded = 0U,
   Loading = 1U,
   Loaded = 2U,
@@ -97,16 +98,18 @@ class TextTrack final : public DOMEventT
 
   void DispatchAsyncTrustedEvent(const nsString& aEventName);
 
   bool IsLoaded();
 
  private:
   ~TextTrack();
 
+  HTMLMediaElement* GetMediaElement();
+
   RefPtr<TextTrackList> mTextTrackList;
 
   TextTrackKind mKind;
   nsString mLabel;
   nsString mLanguage;
   nsString mType;
   TextTrackMode mMode;