Skip to content

Commit

Permalink
Bug 847272 - avoid userfontset updates within font stream handling me…
Browse files Browse the repository at this point in the history
…thods. r=jkew
  • Loading branch information
John Daggett committed Mar 14, 2013
1 parent 609d3f9 commit 63fecfb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
4 changes: 3 additions & 1 deletion gfx/thebes/gfxUserFontSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ class gfxMixedFontFamily : public gfxFontFamily {
void ReplaceFontEntry(gfxFontEntry *aOldFontEntry,
gfxFontEntry *aNewFontEntry) {
uint32_t numFonts = mAvailableFonts.Length();
for (uint32_t i = 0; i < numFonts; i++) {
uint32_t i;
for (i = 0; i < numFonts; i++) {
gfxFontEntry *fe = mAvailableFonts[i];
if (fe == aOldFontEntry) {
// note that this may delete aOldFontEntry, if there's no
Expand All @@ -96,6 +97,7 @@ class gfxMixedFontFamily : public gfxFontFamily {
break;
}
}
NS_ASSERTION(i < numFonts, "font entry not found in family!");
ResetCharacterMap();
}

Expand Down
30 changes: 17 additions & 13 deletions layout/style/nsFontFaceLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ nsFontFaceLoader::LoadTimerCallback(nsITimer *aTimer, void *aClosure)
{
nsFontFaceLoader *loader = static_cast<nsFontFaceLoader*>(aClosure);

if (!loader->mFontSet) {
// We've been canceled
return;
}

gfxProxyFontEntry *pe = loader->mFontEntry.get();
bool updateUserFontSet = true;

Expand Down Expand Up @@ -136,10 +141,10 @@ nsFontFaceLoader::LoadTimerCallback(nsITimer *aTimer, void *aClosure)
// font will be used in the meantime, and tell the context to refresh.
if (updateUserFontSet) {
pe->mLoadingState = gfxProxyFontEntry::LOADING_SLOWLY;
gfxUserFontSet *fontSet = loader->mFontSet;
nsPresContext *ctx = loader->mFontSet->GetPresContext();
NS_ASSERTION(ctx, "fontSet doesn't have a presContext?");
gfxUserFontSet *fontSet;
if (ctx && (fontSet = ctx->GetUserFontSet()) != nullptr) {
NS_ASSERTION(ctx, "userfontset doesn't have a presContext?");
if (ctx) {
fontSet->IncrementGeneration();
ctx->UserFontSetUpdated();
LOG(("fontdownloader (%p) timeout reflow\n", loader));
Expand Down Expand Up @@ -181,12 +186,6 @@ nsFontFaceLoader::OnStreamComplete(nsIStreamLoader* aLoader,
NS_ASSERTION(ctx && !ctx->PresShell()->IsDestroying(),
"We should have been canceled already");

// whether an error occurred or not, notify the user font set of the completion
gfxUserFontSet *userFontSet = ctx->GetUserFontSet();
if (!userFontSet) {
return aStatus;
}

if (NS_SUCCEEDED(aStatus)) {
// for HTTP requests, check whether the request _actually_ succeeded;
// the "request status" in aStatus does not necessarily indicate this,
Expand All @@ -212,10 +211,8 @@ nsFontFaceLoader::OnStreamComplete(nsIStreamLoader* aLoader,
// This is called even in the case of a failed download (HTTP 404, etc),
// as there may still be data to be freed (e.g. an error page),
// and we need the fontSet to initiate loading the next source.
bool fontUpdate = userFontSet->OnLoadComplete(mFontFamily,
mFontEntry,
aString, aStringLen,
aStatus);
bool fontUpdate = mFontSet->OnLoadComplete(mFontFamily, mFontEntry, aString,
aStringLen, aStatus);

// when new font loaded, need to reflow
if (fontUpdate) {
Expand All @@ -225,6 +222,13 @@ nsFontFaceLoader::OnStreamComplete(nsIStreamLoader* aLoader,
LOG(("fontdownloader (%p) reflow\n", this));
}

// done with font set
mFontSet = nullptr;
if (mLoadTimer) {
mLoadTimer->Cancel();
mLoadTimer = nullptr;
}

return NS_SUCCESS_ADOPTED_DATA;
}

Expand Down

0 comments on commit 63fecfb

Please sign in to comment.