Bug 1376964 - Part 10: Allow style worker threads to pick fonts out of the user font cache. r=jfkthame
MozReview-Commit-ID: FX0T5ltA2u4
--- a/gfx/thebes/gfxUserFontSet.cpp
+++ b/gfx/thebes/gfxUserFontSet.cpp
@@ -469,16 +469,22 @@ gfxUserFontEntry::ContinueLoad()
// cases as well if possible, so that we don't have an additional restyle.
// That doesn't work currently because nsIDocument::GetDocShell (called
// from FontFaceSet::CheckFontLoad) dereferences a weak pointer, which is
// not allowed in parallel traversal.
IncrementGeneration();
}
}
+static bool
+IgnorePrincipal(gfxFontSrcURI* aURI)
+{
+ return aURI->InheritsSecurityContext();
+}
+
void
gfxUserFontEntry::DoLoadNextSrc(bool aForceAsync)
{
uint32_t numSrc = mSrcList.Length();
// load each src entry in turn, until a local face is found
// or a download begins successfully
while (mSrcIndex < numSrc) {
@@ -530,19 +536,26 @@ gfxUserFontEntry::DoLoadNextSrc(bool aFo
}
// src url ==> start the load process
else if (currSrc.mSourceType == gfxFontFaceSrc::eSourceType_URL) {
if (gfxPlatform::GetPlatform()->IsFontFormatSupported(
currSrc.mFormatFlags)) {
if (ServoStyleSet* set = ServoStyleSet::Current()) {
- set->AppendTask(PostTraversalTask::LoadFontEntry(this));
- SetLoadState(STATUS_LOAD_PENDING);
- return;
+ // Only support style worker threads synchronously getting
+ // entries from the font cache when it's not a data: URI
+ // @font-face that came from UA or user sheets, since we
+ // were not able to call IsFontLoadAllowed ahead of time
+ // for these entries.
+ if (currSrc.mUseOriginPrincipal && IgnorePrincipal(currSrc.mURI)) {
+ set->AppendTask(PostTraversalTask::LoadFontEntry(this));
+ SetLoadState(STATUS_LOAD_PENDING);
+ return;
+ }
}
gfxFontSrcPrincipal* principal = nullptr;
bool bypassCache;
nsresult rv = mFontSet->CheckFontLoad(&currSrc, &principal,
&bypassCache);
if (NS_SUCCEEDED(rv) && principal != nullptr) {
@@ -562,16 +575,24 @@ gfxUserFontEntry::DoLoadNextSrc(bool aFo
mFontSet, mSrcIndex,
currSrc.mURI->GetSpecOrDefault().get(),
NS_ConvertUTF16toUTF8(mFamilyName).get()));
}
return;
}
}
+ if (ServoStyleSet* set = ServoStyleSet::Current()) {
+ // If we need to start a font load and we're on a style
+ // worker thread, we have to defer it.
+ set->AppendTask(PostTraversalTask::LoadFontEntry(this));
+ SetLoadState(STATUS_LOAD_PENDING);
+ return;
+ }
+
// record the principal returned by CheckFontLoad,
// for use when creating a channel
// and when caching the loaded entry
mPrincipal = principal;
bool loadDoesntSpin = false;
if (!aForceAsync) {
loadDoesntSpin = currSrc.mURI->SyncLoadIsOK();
@@ -1131,22 +1152,16 @@ gfxUserFontSet::UserFontCache::Flusher::
}
} else {
NS_NOTREACHED("unexpected topic");
}
return NS_OK;
}
-static bool
-IgnorePrincipal(gfxFontSrcURI* aURI)
-{
- return aURI->InheritsSecurityContext();
-}
-
bool
gfxUserFontSet::UserFontCache::Entry::KeyEquals(const KeyTypePointer aKey) const
{
const gfxFontEntry* fe = aKey->mFontEntry;
if (!mURI->Equals(aKey->mURI)) {
return false;
}