From bdfea7f41fb2d390d564676addd9242289990a85 Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Wed, 18 Sep 2013 11:48:38 +0100 Subject: [PATCH] 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 | 18 +++++++++++++----- gfx/thebes/gfxUserFontSet.h | 1 + 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/gfx/thebes/gfxUserFontSet.cpp b/gfx/thebes/gfxUserFontSet.cpp index c02a5c943da2..1b461d3e08f6 100644 --- a/gfx/thebes/gfxUserFontSet.cpp +++ b/gfx/thebes/gfxUserFontSet.cpp @@ -810,6 +810,14 @@ gfxUserFontSet::UserFontCache::Entry::RemoveIfPrivate(Entry* aEntry, return aEntry->mPrivate ? PL_DHASH_REMOVE : PL_DHASH_NEXT; } +PLDHashOperator +gfxUserFontSet::UserFontCache::Entry::RemoveIfMatches(Entry* aEntry, + void* aUserData) +{ + return aEntry->GetFontEntry() == static_cast(aUserData) ? + PL_DHASH_REMOVE : PL_DHASH_NEXT; +} + PLDHashOperator gfxUserFontSet::UserFontCache::Entry::DisconnectSVG(Entry* aEntry, void* aUserData) @@ -902,11 +910,11 @@ gfxUserFontSet::UserFontCache::ForgetFont(gfxFontEntry *aFontEntry) 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* diff --git a/gfx/thebes/gfxUserFontSet.h b/gfx/thebes/gfxUserFontSet.h index 6395505dca2c..40ad9fb5ac2e 100644 --- a/gfx/thebes/gfxUserFontSet.h +++ b/gfx/thebes/gfxUserFontSet.h @@ -346,6 +346,7 @@ public: 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: