Bug 1161413 - Part 5: Cancel font loads on FontFaceSet destruction. r=jdaggett
authorCameron McCormack <cam@mcc.id.au>
Sat, 27 Jun 2015 11:39:54 +1000
changeset 281242 09a4d8018a6fca4d85c30ce1de10d46413825d8a
parent 281241 cd5c33b5e95594b3bd8b91c71bc13ae8e48abd99
child 281243 2d52317b1e54bde9ddf8700817e7e32ad297fb39
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdaggett
bugs1161413
milestone41.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 1161413 - Part 5: Cancel font loads on FontFaceSet destruction. r=jdaggett
layout/style/FontFaceSet.cpp
layout/style/FontFaceSet.h
--- a/layout/style/FontFaceSet.cpp
+++ b/layout/style/FontFaceSet.cpp
@@ -113,23 +113,29 @@ FontFaceSet::FontFaceSet(nsPIDOMWindow* 
                                       this, false, false);
   }
 
   mDocument->CSSLoader()->AddObserver(this);
 
   mUserFontSet = new UserFontSet(this);
 }
 
+static PLDHashOperator DestroyIterator(nsPtrHashKey<nsFontFaceLoader>* aKey,
+                                       void* aUserArg)
+{
+  aKey->GetKey()->Cancel();
+  return PL_DHASH_REMOVE;
+}
+
 FontFaceSet::~FontFaceSet()
 {
   MOZ_COUNT_DTOR(FontFaceSet);
 
-  NS_ASSERTION(mLoaders.Count() == 0, "mLoaders should have been emptied");
-
   Disconnect();
+  mLoaders.EnumerateEntries(DestroyIterator, nullptr);
 }
 
 JSObject*
 FontFaceSet::WrapObject(JSContext* aContext, JS::Handle<JSObject*> aGivenProto)
 {
   return FontFaceSetBinding::Wrap(aContext, this, aGivenProto);
 }
 
@@ -382,49 +388,16 @@ FontFaceSet::ForEach(JSContext* aCx,
     FontFace* face = GetFontFaceAt(i);
     aCallback.Call(thisArg, *face, *face, *this, aRv);
     if (aRv.Failed()) {
       return;
     }
   }
 }
 
-static PLDHashOperator DestroyIterator(nsPtrHashKey<nsFontFaceLoader>* aKey,
-                                       void* aUserArg)
-{
-  aKey->GetKey()->Cancel();
-  return PL_DHASH_REMOVE;
-}
-
-void
-FontFaceSet::DestroyUserFontSet()
-{
-  Disconnect();
-  mDocument = nullptr;
-  mLoaders.EnumerateEntries(DestroyIterator, nullptr);
-  for (size_t i = 0; i < mRuleFaces.Length(); i++) {
-    mRuleFaces[i].mFontFace->DisconnectFromRule();
-    mRuleFaces[i].mFontFace->SetUserFontEntry(nullptr);
-  }
-  for (size_t i = 0; i < mNonRuleFaces.Length(); i++) {
-    mNonRuleFaces[i].mFontFace->SetUserFontEntry(nullptr);
-  }
-  for (size_t i = 0; i < mUnavailableFaces.Length(); i++) {
-    mUnavailableFaces[i]->SetUserFontEntry(nullptr);
-  }
-  mRuleFaces.Clear();
-  mNonRuleFaces.Clear();
-  mUnavailableFaces.Clear();
-  mReady = nullptr;
-  if (mUserFontSet) {
-    mUserFontSet->mFontFaceSet = nullptr;
-  }
-  mUserFontSet = nullptr;
-}
-
 void
 FontFaceSet::RemoveLoader(nsFontFaceLoader* aLoader)
 {
   mLoaders.RemoveEntry(aLoader);
 }
 
 nsresult
 FontFaceSet::StartLoad(gfxUserFontEntry* aUserFontEntry,
--- a/layout/style/FontFaceSet.h
+++ b/layout/style/FontFaceSet.h
@@ -94,19 +94,16 @@ public:
   NS_DECL_NSIDOMEVENTLISTENER
 
   FontFaceSet(nsPIDOMWindow* aWindow, nsIDocument* aDocument);
 
   virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
   UserFontSet* GetUserFontSet() { return mUserFontSet; }
 
-  // Called when this font set is no longer associated with a presentation.
-  void DestroyUserFontSet();
-
   // Called by nsFontFaceLoader when the loader has completed normally.
   // It's removed from the mLoaders set.
   void RemoveLoader(nsFontFaceLoader* aLoader);
 
   bool UpdateRules(const nsTArray<nsFontFaceRuleContainer>& aRules);
 
   nsPresContext* GetPresContext();