Bug 838105 - don't rely on key lookup to remove items from the user font cache, as the principal could have changed. r=jdaggett
authorJonathan Kew <jkew@mozilla.com>
Wed, 18 Sep 2013 11:48:38 +0100
changeset 147830 2d4f2df5356384095a3c594f675cae3e48e9cf0a
parent 147829 4ab3f6f9c004ba57cfc5bd7e6b5e19fcfeaac815
child 147831 aaa20750f69dc18f99b9dc09270851dc07202f63
push id25317
push useremorley@mozilla.com
push dateThu, 19 Sep 2013 14:37:38 +0000
treeherdermozilla-central@70a765607344 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdaggett
bugs838105
milestone27.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 838105 - don't rely on key lookup to remove items from the user font cache, as the principal could have changed. r=jdaggett
gfx/thebes/gfxUserFontSet.cpp
gfx/thebes/gfxUserFontSet.h
--- a/gfx/thebes/gfxUserFontSet.cpp
+++ b/gfx/thebes/gfxUserFontSet.cpp
@@ -806,16 +806,24 @@ NS_IMPL_ISUPPORTS1(gfxUserFontSet::UserF
 PLDHashOperator
 gfxUserFontSet::UserFontCache::Entry::RemoveIfPrivate(Entry* aEntry,
                                                       void* aUserData)
 {
     return aEntry->mPrivate ? PL_DHASH_REMOVE : PL_DHASH_NEXT;
 }
 
 PLDHashOperator
+gfxUserFontSet::UserFontCache::Entry::RemoveIfMatches(Entry* aEntry,
+                                                      void* aUserData)
+{
+    return aEntry->GetFontEntry() == static_cast<gfxFontEntry*>(aUserData) ?
+        PL_DHASH_REMOVE : PL_DHASH_NEXT;
+}
+
+PLDHashOperator
 gfxUserFontSet::UserFontCache::Entry::DisconnectSVG(Entry* aEntry,
                                                     void* aUserData)
 {
     aEntry->GetFontEntry()->DisconnectSVG();
     return PL_DHASH_NEXT;
 }
 
 NS_IMETHODIMP
@@ -897,21 +905,21 @@ void
 gfxUserFontSet::UserFontCache::ForgetFont(gfxFontEntry *aFontEntry)
 {
     if (!sUserFonts) {
         // if we've already deleted the cache (i.e. during shutdown),
         // just ignore this
         return;
     }
 
-    gfxUserFontData *data = aFontEntry->mUserFontData;
-    if (data) {
-        sUserFonts->RemoveEntry(Key(data->mURI, data->mPrincipal, aFontEntry,
-                                    data->mPrivate));
-    }
+    // We can't simply use RemoveEntry here because it's possible the principal
+    // may have changed since the font was cached, in which case the lookup
+    // would no longer find the entry (bug 838105).
+    sUserFonts->EnumerateEntries(
+        gfxUserFontSet::UserFontCache::Entry::RemoveIfMatches, aFontEntry);
 }
 
 gfxFontEntry*
 gfxUserFontSet::UserFontCache::GetFont(nsIURI            *aSrcURI,
                                        nsIPrincipal      *aPrincipal,
                                        gfxProxyFontEntry *aProxy,
                                        bool               aPrivate)
 {
--- a/gfx/thebes/gfxUserFontSet.h
+++ b/gfx/thebes/gfxUserFontSet.h
@@ -341,16 +341,17 @@ public:
                                              aKey->mFontEntry->mLanguageOverride);
             }
 
             enum { ALLOW_MEMMOVE = false };
 
             gfxFontEntry* GetFontEntry() const { return mFontEntry; }
 
             static PLDHashOperator RemoveIfPrivate(Entry* aEntry, void* aUserData);
+            static PLDHashOperator RemoveIfMatches(Entry* aEntry, void* aUserData);
             static PLDHashOperator DisconnectSVG(Entry* aEntry, void* aUserData);
 
         private:
             static uint32_t
             HashFeatures(const nsTArray<gfxFontFeature>& aFeatures) {
                 return mozilla::HashBytes(aFeatures.Elements(),
                                           aFeatures.Length() * sizeof(gfxFontFeature));
             }