diff --git a/dom/html/TextTrackManager.cpp b/dom/html/TextTrackManager.cpp
index 3190afce7669..18f8c5782de1 100644
--- a/dom/html/TextTrackManager.cpp
+++ b/dom/html/TextTrackManager.cpp
@@ -848,5 +848,12 @@ TextTrackManager::ReportTelemetryForCue()
}
}
+bool
+TextTrackManager::IsLoaded()
+{
+ return mTextTracks ? mTextTracks->AreTextTracksLoaded() : true;
+}
+
+
} // namespace dom
} // namespace mozilla
diff --git a/dom/html/TextTrackManager.h b/dom/html/TextTrackManager.h
index d20707346b22..2c32e68dfc2c 100644
--- a/dom/html/TextTrackManager.h
+++ b/dom/html/TextTrackManager.h
@@ -103,6 +103,8 @@ public:
void NotifyReset();
+ bool IsLoaded();
+
private:
/**
* Converts the TextTrackCue's cuetext into a tree of DOM objects
diff --git a/dom/media/TextTrack.cpp b/dom/media/TextTrack.cpp
index 0adff192028a..afc24ef1053d 100644
--- a/dom/media/TextTrack.cpp
+++ b/dom/media/TextTrack.cpp
@@ -337,5 +337,22 @@ TextTrack::DispatchAsyncTrustedEvent(const nsString& aEventName)
);
}
+bool
+TextTrack::IsLoaded()
+{
+ if (mMode == TextTrackMode::Disabled) {
+ return true;
+ }
+ // If the TrackElement's src is null, we can not block the
+ // MediaElement.
+ if (mTrackElement) {
+ nsAutoString src;
+ if (!(mTrackElement->GetAttr(kNameSpaceID_None, nsGkAtoms::src, src))) {
+ return true;
+ }
+ }
+ return (mReadyState >= Loaded);
+}
+
} // namespace dom
} // namespace mozilla
diff --git a/dom/media/TextTrack.h b/dom/media/TextTrack.h
index 06b24da5dab8..c8d84f4d53fa 100644
--- a/dom/media/TextTrack.h
+++ b/dom/media/TextTrack.h
@@ -118,6 +118,8 @@ public:
void DispatchAsyncTrustedEvent(const nsString& aEventName);
+ bool IsLoaded();
+
private:
~TextTrack();
diff --git a/dom/media/TextTrackList.cpp b/dom/media/TextTrackList.cpp
index e557d97f5561..9d8d3de12723 100644
--- a/dom/media/TextTrackList.cpp
+++ b/dom/media/TextTrackList.cpp
@@ -232,5 +232,17 @@ TextTrackList::SetCuesInactive()
}
}
+
+bool TextTrackList::AreTextTracksLoaded()
+{
+ // Return false if any texttrack is not loaded.
+ for (uint32_t i = 0; i < Length(); i++) {
+ if (!mTextTracks[i]->IsLoaded()) {
+ return false;
+ }
+ }
+ return true;
+}
+
} // namespace dom
} // namespace mozilla
diff --git a/dom/media/TextTrackList.h b/dom/media/TextTrackList.h
index 607717137d36..56b97d4ad011 100644
--- a/dom/media/TextTrackList.h
+++ b/dom/media/TextTrackList.h
@@ -63,6 +63,8 @@ public:
void CreateAndDispatchChangeEvent();
void SetCuesInactive();
+ bool AreTextTracksLoaded();
+
IMPL_EVENT_HANDLER(change)
IMPL_EVENT_HANDLER(addtrack)
IMPL_EVENT_HANDLER(removetrack)