Bug 1285897 - Async dispatch cuechange event on TextTrack object. r=rillian
☠☠ backed out by fab0848f52e7 ☠ ☠
authorbechen <bechen@mozilla.com>
Tue, 12 Jul 2016 17:41:41 +0800
changeset 331067 5c7dda18ec0299ffd4059624eca09338e5124116
parent 331066 69ed8adfc7b8bc1bbcbb6ac873514baef5004ba3
child 331068 5695eb78dcdc60cc7c8ecef3592a175129e9cee1
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrillian
bugs1285897
milestone50.0a1
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;