Bug 1343799 - lable runnables in texttracklist.cpp. r=jwwang draft
authorbechen <bechen@mozilla.com>
Tue, 21 Mar 2017 16:16:08 +0800
changeset 502107 9630f72f1e0e44df551fdab42f10c4d02f5357e6
parent 501295 1b9293be51637f841275541d8991314ca56561a5
child 502764 069367fb120563d881f97eff8adaa8eea04a7c95
push id50179
push userbechen@mozilla.com
push dateTue, 21 Mar 2017 08:26:43 +0000
reviewersjwwang
bugs1343799
milestone55.0a1
Bug 1343799 - lable runnables in texttracklist.cpp. r=jwwang MozReview-Commit-ID: 39MmwAMaDdk
dom/media/TextTrackList.cpp
--- a/dom/media/TextTrackList.cpp
+++ b/dom/media/TextTrackList.cpp
@@ -2,16 +2,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/TextTrackList.h"
 #include "mozilla/dom/TextTrackListBinding.h"
 #include "mozilla/dom/TrackEvent.h"
 #include "nsThreadUtils.h"
+#include "nsGlobalWindow.h"
 #include "mozilla/dom/TextTrackCue.h"
 #include "mozilla/dom/TextTrackManager.h"
 
 namespace mozilla {
 namespace dom {
 
 NS_IMPL_CYCLE_COLLECTION_INHERITED(TextTrackList,
                                    DOMEventTargetHelper,
@@ -169,24 +170,31 @@ TextTrackList::DispatchTrackEvent(nsIDOM
   return DispatchTrustedEvent(aEvent);
 }
 
 void
 TextTrackList::CreateAndDispatchChangeEvent()
 {
   MOZ_ASSERT(NS_IsMainThread());
   if (!mPendingTextTrackChange) {
+    nsPIDOMWindowInner* win = GetOwner();
+    if (!win) {
+      return;
+    }
+
     mPendingTextTrackChange = true;
     RefPtr<Event> event = NS_NewDOMEvent(this, nullptr, nullptr);
 
     event->InitEvent(NS_LITERAL_STRING("change"), false, false);
     event->SetTrusted(true);
 
     nsCOMPtr<nsIRunnable> eventRunner = new ChangeEventRunner(this, event);
-    NS_DispatchToMainThread(eventRunner);
+    nsGlobalWindow::Cast(win)->Dispatch(
+      "TextTrackList::CreateAndDispatchChangeEvent", TaskCategory::Other,
+      eventRunner.forget());
   }
 }
 
 void
 TextTrackList::CreateAndDispatchTrackEventRunner(TextTrack* aTrack,
                                                  const nsAString& aEventName)
 {
   nsCOMPtr<nsIThread> thread;