From b7bdd0938fa2f0bdc91fc63b13246c4f096ddb30 Mon Sep 17 00:00:00 2001 From: Sandor Molnar Date: Tue, 2 Aug 2022 18:16:28 +0300 Subject: [PATCH] Backed out changeset b7b04703f99d (bug 1782710) for causing wpt failure. --- gfx/thebes/gfxFontSrcURI.cpp | 24 ++++++++++-------------- gfx/thebes/gfxFontSrcURI.h | 23 +++++------------------ gfx/thebes/gfxTextRun.cpp | 4 +++- gfx/thebes/gfxUserFontSet.cpp | 3 +-- gfx/thebes/gfxUserFontSet.h | 23 ++++++++--------------- layout/style/FontFaceSetImpl.cpp | 10 ++++------ 6 files changed, 31 insertions(+), 56 deletions(-) diff --git a/gfx/thebes/gfxFontSrcURI.cpp b/gfx/thebes/gfxFontSrcURI.cpp index a0d7f74179b5..6e281a77d0f1 100644 --- a/gfx/thebes/gfxFontSrcURI.cpp +++ b/gfx/thebes/gfxFontSrcURI.cpp @@ -18,9 +18,12 @@ static bool HasFlag(nsIURI* aURI, uint32_t aFlag) { return NS_SUCCEEDED(rv) && value; } -gfxFontSrcURI::gfxFontSrcURI(nsIURI* aURI) : mURI(aURI) { +gfxFontSrcURI::gfxFontSrcURI(nsIURI* aURI) { + MOZ_ASSERT(NS_IsMainThread()); 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; @@ -46,21 +49,14 @@ gfxFontSrcURI::gfxFontSrcURI(nsIURI* aURI) : mURI(aURI) { } mHash = nsURIHashKey::HashKey(mURI); -} - -gfxFontSrcURI::~gfxFontSrcURI() = default; - -void gfxFontSrcURI::EnsureInitialized() { - MOZ_ASSERT(NS_IsMainThread()); - - if (mInitialized) { - return; - } mInheritsSecurityContext = - HasFlag(mURI, nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT); - mSyncLoadIsOK = HasFlag(mURI, nsIProtocolHandler::URI_SYNC_LOAD_IS_OK); - mInitialized = true; + HasFlag(aURI, nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT); + mSyncLoadIsOK = HasFlag(aURI, nsIProtocolHandler::URI_SYNC_LOAD_IS_OK); +} + +gfxFontSrcURI::~gfxFontSrcURI() { + NS_ReleaseOnMainThread("gfxFontSrcURI::mURI", mURI.forget()); } bool gfxFontSrcURI::Equals(gfxFontSrcURI* aOther) { diff --git a/gfx/thebes/gfxFontSrcURI.h b/gfx/thebes/gfxFontSrcURI.h index 994575d7fc42..226341e5fdd9 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 final { +class gfxFontSrcURI { public: explicit gfxFontSrcURI(nsIURI* aURI); @@ -35,22 +35,12 @@ class gfxFontSrcURI final { nsCString GetSpecOrDefault(); PLDHashNumber Hash() const { return mHash; } - - bool InheritsSecurityContext() { - EnsureInitialized(); - return mInheritsSecurityContext; - } - - bool SyncLoadIsOK() { - EnsureInitialized(); - return mSyncLoadIsOK; - } + bool InheritsSecurityContext() const { return mInheritsSecurityContext; } + bool SyncLoadIsOK() const { return mSyncLoadIsOK; } private: ~gfxFontSrcURI(); - void EnsureInitialized(); - // The URI. nsCOMPtr mURI; @@ -67,15 +57,12 @@ class gfxFontSrcURI final { // 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 = false; + bool mInheritsSecurityContext; // Whether the nsIURI's protocol handler has teh URI_SYNC_LOAD_IS_OK flag. - bool mSyncLoadIsOK = false; + bool mSyncLoadIsOK; }; #endif // MOZILLA_GFX_FONTSRCURI_H diff --git a/gfx/thebes/gfxTextRun.cpp b/gfx/thebes/gfxTextRun.cpp index 5b6a90b0294e..eba86541d8cf 100644 --- a/gfx/thebes/gfxTextRun.cpp +++ b/gfx/thebes/gfxTextRun.cpp @@ -2012,9 +2012,11 @@ void gfxFontGroup::AddFamilyToFontList(fontlist::Family* aFamily, StyleGenericFontFamily aGeneric) { gfxPlatformFontList* pfl = gfxPlatformFontList::PlatformFontList(); if (!aFamily->IsInitialized()) { - if (ServoStyleSet* set = gfxFontUtils::CurrentServoStyleSet()) { + if (!NS_IsMainThread() && ServoStyleSet::Current()) { // 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 3fdc7af65612..516bc5e36ac2 100644 --- a/gfx/thebes/gfxUserFontSet.cpp +++ b/gfx/thebes/gfxUserFontSet.cpp @@ -257,8 +257,7 @@ gfxUserFontFamily::~gfxUserFontFamily() { already_AddRefed gfxFontFaceSrc::LoadPrincipal( const gfxUserFontSet& aFontSet) const { MOZ_ASSERT(mSourceType == eSourceType_URL); - if (mUseOriginPrincipal) { - MOZ_ASSERT(mOriginPrincipal); + if (mUseOriginPrincipal && mOriginPrincipal) { return RefPtr{mOriginPrincipal}.forget(); } return aFontSet.GetStandardFontLoadPrincipal(); diff --git a/gfx/thebes/gfxUserFontSet.h b/gfx/thebes/gfxUserFontSet.h index 96441eae8690..c9ea8e161686 100644 --- a/gfx/thebes/gfxUserFontSet.h +++ b/gfx/thebes/gfxUserFontSet.h @@ -75,18 +75,17 @@ struct gfxFontFaceSrc { SourceType mSourceType; // if url, whether to use the origin principal or not - bool mUseOriginPrincipal = false; + bool mUseOriginPrincipal; // 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 and mUseOriginPrincipal + nsCString mLocalName; // full font name if local + RefPtr mURI; // uri if url + nsCOMPtr mReferrerInfo; // referrer info if url + RefPtr mOriginPrincipal; // principal if url RefPtr mBuffer; @@ -107,18 +106,12 @@ 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.mFormatFlags == b.mFormatFlags && + return a.mUseOriginPrincipal == b.mUseOriginPrincipal && + a.mFormatFlags == b.mFormatFlags && (a.mURI == b.mURI || a.mURI->Equals(b.mURI)) && NS_SUCCEEDED(a.mReferrerInfo->Equals(b.mReferrerInfo, &equals)) && - equals; + equals && a.mOriginPrincipal->Equals(b.mOriginPrincipal); } case gfxFontFaceSrc::eSourceType_Buffer: return a.mBuffer == b.mBuffer; diff --git a/layout/style/FontFaceSetImpl.cpp b/layout/style/FontFaceSetImpl.cpp index ad194c8d9636..ba0a8f6c2a81 100644 --- a/layout/style/FontFaceSetImpl.cpp +++ b/layout/style/FontFaceSetImpl.cpp @@ -513,17 +513,15 @@ 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 - if (aOrigin == StyleOrigin::User || - aOrigin == StyleOrigin::UserAgent) { - face->mUseOriginPrincipal = true; - face->mOriginPrincipal = new gfxFontSrcPrincipal( - extraData.Principal(), extraData.Principal()); - } + face->mUseOriginPrincipal = + aOrigin == StyleOrigin::User || aOrigin == StyleOrigin::UserAgent; face->mLocalName.Truncate(); face->mFormatFlags = 0;