diff --git a/gfx/thebes/gfxFontSrcURI.cpp b/gfx/thebes/gfxFontSrcURI.cpp index 6e281a77d0f1..3153d2abce18 100644 --- a/gfx/thebes/gfxFontSrcURI.cpp +++ b/gfx/thebes/gfxFontSrcURI.cpp @@ -5,6 +5,7 @@ #include "gfxFontSrcURI.h" +#include "mozilla/ServoStyleSet.h" #include "nsIProtocolHandler.h" #include "nsProxyRelease.h" #include "nsNetUtil.h" @@ -18,12 +19,9 @@ static bool HasFlag(nsIURI* aURI, uint32_t aFlag) { return NS_SUCCEEDED(rv) && value; } -gfxFontSrcURI::gfxFontSrcURI(nsIURI* aURI) { - MOZ_ASSERT(NS_IsMainThread()); +gfxFontSrcURI::gfxFontSrcURI(nsIURI* aURI) : mURI(aURI) { MOZ_ASSERT(aURI); - mURI = aURI; - // If we have a data: URI, we know that it is backed by an nsSimpleURI, // and that we don't need to serialize it ahead of time. nsCString scheme; @@ -49,14 +47,21 @@ gfxFontSrcURI::gfxFontSrcURI(nsIURI* aURI) { } mHash = nsURIHashKey::HashKey(mURI); - - mInheritsSecurityContext = - HasFlag(aURI, nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT); - mSyncLoadIsOK = HasFlag(aURI, nsIProtocolHandler::URI_SYNC_LOAD_IS_OK); } -gfxFontSrcURI::~gfxFontSrcURI() { - NS_ReleaseOnMainThread("gfxFontSrcURI::mURI", mURI.forget()); +gfxFontSrcURI::~gfxFontSrcURI() = default; + +void gfxFontSrcURI::EnsureInitialized() { + MOZ_ASSERT(NS_IsMainThread() || mozilla::ServoStyleSet::IsInServoTraversal()); + + if (mInitialized) { + return; + } + + mInheritsSecurityContext = + HasFlag(mURI, nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT); + mSyncLoadIsOK = HasFlag(mURI, nsIProtocolHandler::URI_SYNC_LOAD_IS_OK); + mInitialized = true; } bool gfxFontSrcURI::Equals(gfxFontSrcURI* aOther) { diff --git a/gfx/thebes/gfxFontSrcURI.h b/gfx/thebes/gfxFontSrcURI.h index 226341e5fdd9..994575d7fc42 100644 --- a/gfx/thebes/gfxFontSrcURI.h +++ b/gfx/thebes/gfxFontSrcURI.h @@ -22,7 +22,7 @@ class nsSimpleURI; * A wrapper for an nsIURI that can be used OMT, which has cached information * useful for the gfxUserFontSet. */ -class gfxFontSrcURI { +class gfxFontSrcURI final { public: explicit gfxFontSrcURI(nsIURI* aURI); @@ -35,12 +35,22 @@ class gfxFontSrcURI { nsCString GetSpecOrDefault(); PLDHashNumber Hash() const { return mHash; } - bool InheritsSecurityContext() const { return mInheritsSecurityContext; } - bool SyncLoadIsOK() const { return mSyncLoadIsOK; } + + bool InheritsSecurityContext() { + EnsureInitialized(); + return mInheritsSecurityContext; + } + + bool SyncLoadIsOK() { + EnsureInitialized(); + return mSyncLoadIsOK; + } private: ~gfxFontSrcURI(); + void EnsureInitialized(); + // The URI. nsCOMPtr mURI; @@ -57,12 +67,15 @@ class gfxFontSrcURI { // Precomputed hash for mURI. PLDHashNumber mHash; + // Whether the font has been initialized on the main thread. + bool mInitialized = false; + // Whether the nsIURI's protocol handler has the URI_INHERITS_SECURITY_CONTEXT // flag. - bool mInheritsSecurityContext; + bool mInheritsSecurityContext = false; // Whether the nsIURI's protocol handler has teh URI_SYNC_LOAD_IS_OK flag. - bool mSyncLoadIsOK; + bool mSyncLoadIsOK = false; }; #endif // MOZILLA_GFX_FONTSRCURI_H diff --git a/gfx/thebes/gfxTextRun.cpp b/gfx/thebes/gfxTextRun.cpp index eba86541d8cf..5b6a90b0294e 100644 --- a/gfx/thebes/gfxTextRun.cpp +++ b/gfx/thebes/gfxTextRun.cpp @@ -2012,11 +2012,9 @@ void gfxFontGroup::AddFamilyToFontList(fontlist::Family* aFamily, StyleGenericFontFamily aGeneric) { gfxPlatformFontList* pfl = gfxPlatformFontList::PlatformFontList(); if (!aFamily->IsInitialized()) { - if (!NS_IsMainThread() && ServoStyleSet::Current()) { + if (ServoStyleSet* set = gfxFontUtils::CurrentServoStyleSet()) { // If we need to initialize a Family record, but we're on a style // worker thread, we have to defer it. - ServoStyleSet* set = ServoStyleSet::Current(); - MOZ_ASSERT(set); set->AppendTask(PostTraversalTask::InitializeFamily(aFamily)); set->AppendTask(PostTraversalTask::FontInfoUpdate(set)); return; diff --git a/gfx/thebes/gfxUserFontSet.cpp b/gfx/thebes/gfxUserFontSet.cpp index 516bc5e36ac2..3fdc7af65612 100644 --- a/gfx/thebes/gfxUserFontSet.cpp +++ b/gfx/thebes/gfxUserFontSet.cpp @@ -257,7 +257,8 @@ gfxUserFontFamily::~gfxUserFontFamily() { already_AddRefed gfxFontFaceSrc::LoadPrincipal( const gfxUserFontSet& aFontSet) const { MOZ_ASSERT(mSourceType == eSourceType_URL); - if (mUseOriginPrincipal && mOriginPrincipal) { + if (mUseOriginPrincipal) { + MOZ_ASSERT(mOriginPrincipal); return RefPtr{mOriginPrincipal}.forget(); } return aFontSet.GetStandardFontLoadPrincipal(); diff --git a/gfx/thebes/gfxUserFontSet.h b/gfx/thebes/gfxUserFontSet.h index c9ea8e161686..96441eae8690 100644 --- a/gfx/thebes/gfxUserFontSet.h +++ b/gfx/thebes/gfxUserFontSet.h @@ -75,17 +75,18 @@ struct gfxFontFaceSrc { SourceType mSourceType; // if url, whether to use the origin principal or not - bool mUseOriginPrincipal; + bool mUseOriginPrincipal = false; // format hint flags, union of all possible formats // (e.g. TrueType, EOT, SVG, etc.) // see FLAG_FORMAT_* enum values below uint32_t mFormatFlags; - nsCString mLocalName; // full font name if local - RefPtr mURI; // uri if url - nsCOMPtr mReferrerInfo; // referrer info if url - RefPtr mOriginPrincipal; // principal if url + nsCString mLocalName; // full font name if local + RefPtr mURI; // uri if url + nsCOMPtr mReferrerInfo; // referrer info if url + RefPtr + mOriginPrincipal; // principal if url and mUseOriginPrincipal RefPtr mBuffer; @@ -106,12 +107,18 @@ inline bool operator==(const gfxFontFaceSrc& a, const gfxFontFaceSrc& b) { case gfxFontFaceSrc::eSourceType_Local: return a.mLocalName == b.mLocalName; case gfxFontFaceSrc::eSourceType_URL: { + if (a.mUseOriginPrincipal != b.mUseOriginPrincipal) { + return false; + } + if (a.mUseOriginPrincipal && + !a.mOriginPrincipal->Equals(b.mOriginPrincipal)) { + return false; + } bool equals; - return a.mUseOriginPrincipal == b.mUseOriginPrincipal && - a.mFormatFlags == b.mFormatFlags && + return a.mFormatFlags == b.mFormatFlags && (a.mURI == b.mURI || a.mURI->Equals(b.mURI)) && NS_SUCCEEDED(a.mReferrerInfo->Equals(b.mReferrerInfo, &equals)) && - equals && a.mOriginPrincipal->Equals(b.mOriginPrincipal); + equals; } case gfxFontFaceSrc::eSourceType_Buffer: return a.mBuffer == b.mBuffer; diff --git a/layout/style/FontFaceSetImpl.cpp b/layout/style/FontFaceSetImpl.cpp index ba0a8f6c2a81..ad194c8d9636 100644 --- a/layout/style/FontFaceSetImpl.cpp +++ b/layout/style/FontFaceSetImpl.cpp @@ -513,15 +513,17 @@ FontFaceSetImpl::FindOrCreateUserFontEntryFromFontFace( face->mURI = uri ? new gfxFontSrcURI(uri) : nullptr; const URLExtraData& extraData = url->ExtraData(); face->mReferrerInfo = extraData.ReferrerInfo(); - face->mOriginPrincipal = new gfxFontSrcPrincipal( - extraData.Principal(), extraData.Principal()); // agent and user stylesheets are treated slightly differently, // the same-site origin check and access control headers are // enforced against the sheet principal rather than the document // principal to allow user stylesheets to include @font-face rules - face->mUseOriginPrincipal = - aOrigin == StyleOrigin::User || aOrigin == StyleOrigin::UserAgent; + if (aOrigin == StyleOrigin::User || + aOrigin == StyleOrigin::UserAgent) { + face->mUseOriginPrincipal = true; + face->mOriginPrincipal = new gfxFontSrcPrincipal( + extraData.Principal(), extraData.Principal()); + } face->mLocalName.Truncate(); face->mFormatFlags = 0;