Backed out changeset b7b04703f99d (bug 1782710) for causing wpt failure.

This commit is contained in:
Sandor Molnar 2022-08-02 18:16:28 +03:00
parent ff4564db7e
commit b7bdd0938f
6 changed files with 31 additions and 56 deletions

View File

@ -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) {

View File

@ -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<nsIURI> 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

View File

@ -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;

View File

@ -257,8 +257,7 @@ gfxUserFontFamily::~gfxUserFontFamily() {
already_AddRefed<gfxFontSrcPrincipal> 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();

View File

@ -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<gfxFontSrcURI> mURI; // uri if url
nsCOMPtr<nsIReferrerInfo> mReferrerInfo; // referrer info if url
RefPtr<gfxFontSrcPrincipal>
mOriginPrincipal; // principal if url and mUseOriginPrincipal
nsCString mLocalName; // full font name if local
RefPtr<gfxFontSrcURI> mURI; // uri if url
nsCOMPtr<nsIReferrerInfo> mReferrerInfo; // referrer info if url
RefPtr<gfxFontSrcPrincipal> mOriginPrincipal; // principal if url
RefPtr<gfxFontFaceBufferSource> 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;

View File

@ -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;