Bug 1285897 - Async dispatch cuechange event on TextTrack object. r=rillian
authorbechen <bechen@mozilla.com>
Tue, 12 Jul 2016 17:41:41 +0800
changeset 306809 7a7cab1878fce38a4909b3e8a19ffe62d097b821
parent 306808 83db605b772e7d7fe1e27d0bb3cea5e117ceafad
child 306810 0223eb6687f7bd84055a361e6bc0a672bc5306ec
push id30499
push usercbook@mozilla.com
push dateWed, 27 Jul 2016 14:35:59 +0000
treeherdermozilla-central@fef429fba4c6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrillian
bugs1285897
milestone50.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 1285897 - Async dispatch cuechange event on TextTrack object. r=rillian MozReview-Commit-ID: DKWCAEaT58J
dom/html/TextTrackManager.cpp
dom/media/TextTrack.cpp
dom/media/TextTrack.h
--- a/dom/html/TextTrackManager.cpp
+++ b/dom/html/TextTrackManager.cpp
@@ -735,17 +735,17 @@ TextTrackManager::TimeMarchesOn()
   for (uint32_t i = 0; i < eventList.Length(); ++i) {
     NS_DispatchToMainThread(eventList[i].forget());
   }
 
   // Step 16.
   for (uint32_t i = 0; i < affectedTracks.Length(); ++i) {
     TextTrack* ttrack = affectedTracks[i];
     if (ttrack) {
-      ttrack->DispatchTrustedEvent(NS_LITERAL_STRING("cuechange"));
+      ttrack->DispatchAsyncTrustedEvent(NS_LITERAL_STRING("cuechange"));
       HTMLTrackElement* trackElement = ttrack->GetTrackElement();
       if (trackElement) {
         trackElement->DispatchTrackRunnable(NS_LITERAL_STRING("cuechange"));
       }
     }
   }
 
   mLastTimeMarchesOnCalled = currentPlaybackTime;
--- a/dom/media/TextTrack.cpp
+++ b/dom/media/TextTrack.cpp
@@ -313,10 +313,21 @@ TextTrack::GetLanguage(nsAString& aLangu
 {
   if (mTrackElement) {
     mTrackElement->GetSrclang(aLanguage);
   } else {
     aLanguage = mLanguage;
   }
 }
 
+void
+TextTrack::DispatchAsyncTrustedEvent(const nsString& aEventName)
+{
+  RefPtr<TextTrack> self = this;
+  NS_DispatchToMainThread(
+    NS_NewRunnableFunction([self, aEventName]() {
+      self->DispatchTrustedEvent(aEventName);
+    })
+  );
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/dom/media/TextTrack.h
+++ b/dom/media/TextTrack.h
@@ -111,16 +111,18 @@ public:
   TextTrackSource GetTextTrackSource() {
     return mTextTrackSource;
   }
 
   void SetCuesInactive();
 
   void NotifyCueUpdated(TextTrackCue *aCue);
 
+  void DispatchAsyncTrustedEvent(const nsString& aEventName);
+
 private:
   ~TextTrack();
 
   RefPtr<TextTrackList> mTextTrackList;
 
   TextTrackKind mKind;
   nsString mLabel;
   nsString mLanguage;