Bug 1338446 Part 2 - Label FontFaceSet::CheckLoadingFinishedAfterDelay. r=heycam
authorTing-Yu Lin <tlin@mozilla.com>
Thu, 09 Mar 2017 18:02:01 +0800
changeset 348427 040783ed88b2959621beae9c7175f30ac0b0bd62
parent 348426 0165092dfacd36994a0744c30d94356cd531ce02
child 348428 c86e4966a1224fd6a66e23f686fcc0abd2ce8397
push id39160
push usertlin@mozilla.com
push dateMon, 20 Mar 2017 15:27:11 +0000
treeherderautoland@f018d6eefc41 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1338446
milestone55.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 1338446 Part 2 - Label FontFaceSet::CheckLoadingFinishedAfterDelay. r=heycam mDocument is always valid because we get mDocument from the argument of FontFaceSet's constructor, and FontFaceSet is always created in nsIDocument's methods. Delay giving checkTask a name until we dispatch it. No need to name it twice. MozReview-Commit-ID: 6nKYRcRqvQ0
layout/style/FontFaceSet.cpp
--- a/layout/style/FontFaceSet.cpp
+++ b/layout/style/FontFaceSet.cpp
@@ -99,16 +99,18 @@ FontFaceSet::FontFaceSet(nsPIDOMWindowIn
   , mDocument(aDocument)
   , mResolveLazilyCreatedReadyPromise(false)
   , mStatus(FontFaceSetLoadStatus::Loaded)
   , mNonRuleFacesDirty(false)
   , mHasLoadingFontFaces(false)
   , mHasLoadingFontFacesIsDirty(false)
   , mDelayedLoadCheck(false)
 {
+  MOZ_ASSERT(mDocument, "We should get a valid document from the caller!");
+
   nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aWindow);
 
   // If the pref is not set, don't create the Promise (which the page wouldn't
   // be able to get to anyway) as it causes the window.FontFaceSet constructor
   // to be created.
   if (global && PrefEnabled()) {
     mResolveLazilyCreatedReadyPromise = true;
   }
@@ -1468,19 +1470,19 @@ FontFaceSet::OnFontFaceStatusChanged(Fon
     // relevant elements in the document.  We want to wait until the reflow
     // request has been done before the FontFaceSet is marked as Loaded so
     // that we don't briefly set the FontFaceSet to Loaded and then Loading
     // again once the reflow is pending.  So we go around the event loop
     // and call CheckLoadingFinished() after the reflow has been queued.
     if (!mDelayedLoadCheck) {
       mDelayedLoadCheck = true;
       nsCOMPtr<nsIRunnable> checkTask =
-        NewRunnableMethod("FontFaceSet::CheckLoadingFinishedAfterDelay",
-                          this, &FontFaceSet::CheckLoadingFinishedAfterDelay);
-      NS_DispatchToMainThread(checkTask);
+        NewRunnableMethod(this, &FontFaceSet::CheckLoadingFinishedAfterDelay);
+      mDocument->Dispatch("FontFaceSet::CheckLoadingFinishedAfterDelay",
+                          TaskCategory::Other, checkTask.forget());
     }
   }
 }
 
 void
 FontFaceSet::DidRefresh()
 {
   CheckLoadingFinished();