Bug 1376964 - Part 6: Use gfxFontSrcURI in the user font set and cache. r=jfkthame
MozReview-Commit-ID: 7eWOTs4kF4v
This commit is contained in:
@@ -531,7 +531,8 @@ gfxUserFontEntry::DoLoadNextSrc(bool aForceAsync)
|
|||||||
|
|
||||||
// src url ==> start the load process
|
// src url ==> start the load process
|
||||||
else if (currSrc.mSourceType == gfxFontFaceSrc::eSourceType_URL) {
|
else if (currSrc.mSourceType == gfxFontFaceSrc::eSourceType_URL) {
|
||||||
if (gfxPlatform::GetPlatform()->IsFontFormatSupported(currSrc.mURI,
|
if (gfxPlatform::GetPlatform()->IsFontFormatSupported(
|
||||||
|
currSrc.mURI->get(),
|
||||||
currSrc.mFormatFlags)) {
|
currSrc.mFormatFlags)) {
|
||||||
|
|
||||||
if (ServoStyleSet* set = ServoStyleSet::Current()) {
|
if (ServoStyleSet* set = ServoStyleSet::Current()) {
|
||||||
@@ -574,9 +575,7 @@ gfxUserFontEntry::DoLoadNextSrc(bool aForceAsync)
|
|||||||
|
|
||||||
bool loadDoesntSpin = false;
|
bool loadDoesntSpin = false;
|
||||||
if (!aForceAsync) {
|
if (!aForceAsync) {
|
||||||
rv = NS_URIChainHasFlags(currSrc.mURI,
|
loadDoesntSpin = currSrc.mURI->SyncLoadIsOK();
|
||||||
nsIProtocolHandler::URI_SYNC_LOAD_IS_OK,
|
|
||||||
&loadDoesntSpin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NS_SUCCEEDED(rv) && loadDoesntSpin) {
|
if (NS_SUCCEEDED(rv) && loadDoesntSpin) {
|
||||||
@@ -1139,14 +1138,9 @@ gfxUserFontSet::UserFontCache::Flusher::Observe(nsISupports* aSubject,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
IgnorePrincipal(nsIURI* aURI)
|
IgnorePrincipal(gfxFontSrcURI* aURI)
|
||||||
{
|
{
|
||||||
nsresult rv;
|
return aURI->InheritsSecurityContext();
|
||||||
bool inherits = false;
|
|
||||||
rv = NS_URIChainHasFlags(aURI,
|
|
||||||
nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT,
|
|
||||||
&inherits);
|
|
||||||
return NS_SUCCEEDED(rv) && inherits;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@@ -1154,8 +1148,7 @@ gfxUserFontSet::UserFontCache::Entry::KeyEquals(const KeyTypePointer aKey) const
|
|||||||
{
|
{
|
||||||
const gfxFontEntry* fe = aKey->mFontEntry;
|
const gfxFontEntry* fe = aKey->mFontEntry;
|
||||||
|
|
||||||
bool result;
|
if (!mURI->Equals(aKey->mURI)) {
|
||||||
if (NS_FAILED(mURI->Equals(aKey->mURI, &result)) || !result) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1163,6 +1156,7 @@ gfxUserFontSet::UserFontCache::Entry::KeyEquals(const KeyTypePointer aKey) const
|
|||||||
if (!IgnorePrincipal(mURI)) {
|
if (!IgnorePrincipal(mURI)) {
|
||||||
NS_ASSERTION(mPrincipal && aKey->mPrincipal,
|
NS_ASSERTION(mPrincipal && aKey->mPrincipal,
|
||||||
"only data: URIs are allowed to omit the principal");
|
"only data: URIs are allowed to omit the principal");
|
||||||
|
bool result;
|
||||||
if (NS_FAILED(mPrincipal->Equals(aKey->mPrincipal, &result)) ||
|
if (NS_FAILED(mPrincipal->Equals(aKey->mPrincipal, &result)) ||
|
||||||
!result) {
|
!result) {
|
||||||
return false;
|
return false;
|
||||||
@@ -1271,7 +1265,7 @@ gfxUserFontSet::UserFontCache::ForgetFont(gfxFontEntry* aFontEntry)
|
|||||||
}
|
}
|
||||||
|
|
||||||
gfxFontEntry*
|
gfxFontEntry*
|
||||||
gfxUserFontSet::UserFontCache::GetFont(nsIURI* aSrcURI,
|
gfxUserFontSet::UserFontCache::GetFont(gfxFontSrcURI* aSrcURI,
|
||||||
nsIPrincipal* aPrincipal,
|
nsIPrincipal* aPrincipal,
|
||||||
gfxUserFontEntry* aUserFontEntry,
|
gfxUserFontEntry* aUserFontEntry,
|
||||||
bool aPrivate)
|
bool aPrivate)
|
||||||
@@ -1305,7 +1299,7 @@ gfxUserFontSet::UserFontCache::GetFont(nsIURI* aSrcURI,
|
|||||||
} else {
|
} else {
|
||||||
// Call IsFontLoadAllowed directly, since we are on the main thread.
|
// Call IsFontLoadAllowed directly, since we are on the main thread.
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
allowed = aUserFontEntry->mFontSet->IsFontLoadAllowed(aSrcURI,
|
allowed = aUserFontEntry->mFontSet->IsFontLoadAllowed(aSrcURI->get(),
|
||||||
aPrincipal);
|
aPrincipal);
|
||||||
MOZ_ASSERT(!entry->IsFontSetAllowedKnown(aUserFontEntry->mFontSet) ||
|
MOZ_ASSERT(!entry->IsFontSetAllowedKnown(aUserFontEntry->mFontSet) ||
|
||||||
entry->IsFontSetAllowed(aUserFontEntry->mFontSet) == allowed,
|
entry->IsFontSetAllowed(aUserFontEntry->mFontSet) == allowed,
|
||||||
@@ -1342,7 +1336,8 @@ gfxUserFontSet::UserFontCache::UpdateAllowedFontSets(
|
|||||||
principal = aUserFontSet->GetStandardFontLoadPrincipal();
|
principal = aUserFontSet->GetStandardFontLoadPrincipal();
|
||||||
}
|
}
|
||||||
bool allowed =
|
bool allowed =
|
||||||
aUserFontSet->IsFontLoadAllowed(entry->GetURI(), principal);
|
aUserFontSet->IsFontLoadAllowed(entry->GetURI()->get(),
|
||||||
|
principal);
|
||||||
entry->SetIsFontSetAllowed(aUserFontSet, allowed);
|
entry->SetIsFontSetAllowed(aUserFontSet, allowed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1427,7 +1422,7 @@ gfxUserFontSet::UserFontCache::Entry::ReportMemory(
|
|||||||
// Some fonts are loaded using horrendously-long data: URIs;
|
// Some fonts are loaded using horrendously-long data: URIs;
|
||||||
// truncate those before reporting them.
|
// truncate those before reporting them.
|
||||||
bool isData;
|
bool isData;
|
||||||
if (NS_SUCCEEDED(mURI->SchemeIs("data", &isData)) && isData &&
|
if (NS_SUCCEEDED(mURI->get()->SchemeIs("data", &isData)) && isData &&
|
||||||
spec.Length() > 255) {
|
spec.Length() > 255) {
|
||||||
spec.Truncate(252);
|
spec.Truncate(252);
|
||||||
spec.Append("...");
|
spec.Append("...");
|
||||||
@@ -1513,7 +1508,7 @@ gfxUserFontSet::UserFontCache::Entry::Dump()
|
|||||||
printf("userfontcache fontEntry: %p fonturihash: %8.8x "
|
printf("userfontcache fontEntry: %p fonturihash: %8.8x "
|
||||||
"family: %s domainset: %s principal: [%s]\n",
|
"family: %s domainset: %s principal: [%s]\n",
|
||||||
mFontEntry,
|
mFontEntry,
|
||||||
nsURIHashKey::HashKey(mURI),
|
mURI->Hash(),
|
||||||
NS_ConvertUTF16toUTF8(mFontEntry->FamilyName()).get(),
|
NS_ConvertUTF16toUTF8(mFontEntry->FamilyName()).get(),
|
||||||
setDomain ? "true" : "false",
|
setDomain ? "true" : "false",
|
||||||
principalURISpec.get());
|
principalURISpec.get());
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "gfxFont.h"
|
#include "gfxFont.h"
|
||||||
#include "gfxFontFamilyList.h"
|
#include "gfxFontFamilyList.h"
|
||||||
|
#include "gfxFontSrcURI.h"
|
||||||
#include "nsRefPtrHashtable.h"
|
#include "nsRefPtrHashtable.h"
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
#include "nsIURI.h"
|
#include "nsIURI.h"
|
||||||
@@ -55,7 +56,7 @@ struct gfxFontFaceSrc {
|
|||||||
uint32_t mFormatFlags;
|
uint32_t mFormatFlags;
|
||||||
|
|
||||||
nsString mLocalName; // full font name if local
|
nsString mLocalName; // full font name if local
|
||||||
nsCOMPtr<nsIURI> mURI; // uri if url
|
RefPtr<gfxFontSrcURI> mURI; // uri if url
|
||||||
nsCOMPtr<nsIURI> mReferrer; // referrer url if url
|
nsCOMPtr<nsIURI> mReferrer; // referrer url if url
|
||||||
mozilla::net::ReferrerPolicy mReferrerPolicy;
|
mozilla::net::ReferrerPolicy mReferrerPolicy;
|
||||||
nsCOMPtr<nsIPrincipal> mOriginPrincipal; // principal if url
|
nsCOMPtr<nsIPrincipal> mOriginPrincipal; // principal if url
|
||||||
@@ -66,6 +67,9 @@ struct gfxFontFaceSrc {
|
|||||||
inline bool
|
inline bool
|
||||||
operator==(const gfxFontFaceSrc& a, const gfxFontFaceSrc& b)
|
operator==(const gfxFontFaceSrc& a, const gfxFontFaceSrc& b)
|
||||||
{
|
{
|
||||||
|
// The mReferrer and mOriginPrincipal comparisons aren't safe OMT.
|
||||||
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
|
||||||
if (a.mSourceType != b.mSourceType) {
|
if (a.mSourceType != b.mSourceType) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -76,7 +80,7 @@ operator==(const gfxFontFaceSrc& a, const gfxFontFaceSrc& b)
|
|||||||
bool equals;
|
bool equals;
|
||||||
return a.mUseOriginPrincipal == b.mUseOriginPrincipal &&
|
return a.mUseOriginPrincipal == b.mUseOriginPrincipal &&
|
||||||
a.mFormatFlags == b.mFormatFlags &&
|
a.mFormatFlags == b.mFormatFlags &&
|
||||||
NS_SUCCEEDED(a.mURI->Equals(b.mURI, &equals)) && equals &&
|
(a.mURI == b.mURI || a.mURI->Equals(b.mURI)) &&
|
||||||
NS_SUCCEEDED(a.mReferrer->Equals(b.mReferrer, &equals)) &&
|
NS_SUCCEEDED(a.mReferrer->Equals(b.mReferrer, &equals)) &&
|
||||||
equals &&
|
equals &&
|
||||||
a.mReferrerPolicy == b.mReferrerPolicy &&
|
a.mReferrerPolicy == b.mReferrerPolicy &&
|
||||||
@@ -107,7 +111,7 @@ public:
|
|||||||
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
||||||
|
|
||||||
nsTArray<uint8_t> mMetadata; // woff metadata block (compressed), if any
|
nsTArray<uint8_t> mMetadata; // woff metadata block (compressed), if any
|
||||||
nsCOMPtr<nsIURI> mURI; // URI of the source, if it was url()
|
RefPtr<gfxFontSrcURI> mURI; // URI of the source, if it was url()
|
||||||
nsCOMPtr<nsIPrincipal> mPrincipal; // principal for the download, if url()
|
nsCOMPtr<nsIPrincipal> mPrincipal; // principal for the download, if url()
|
||||||
nsString mLocalName; // font name used for the source, if local()
|
nsString mLocalName; // font name used for the source, if local()
|
||||||
nsString mRealName; // original fullname from the font resource
|
nsString mRealName; // original fullname from the font resource
|
||||||
@@ -298,7 +302,7 @@ public:
|
|||||||
// The aPrivate flag is set for requests coming from private windows,
|
// The aPrivate flag is set for requests coming from private windows,
|
||||||
// so we can avoid leaking fonts cached in private windows mode out to
|
// so we can avoid leaking fonts cached in private windows mode out to
|
||||||
// normal windows.
|
// normal windows.
|
||||||
static gfxFontEntry* GetFont(nsIURI* aSrcURI,
|
static gfxFontEntry* GetFont(gfxFontSrcURI* aSrcURI,
|
||||||
nsIPrincipal* aPrincipal,
|
nsIPrincipal* aPrincipal,
|
||||||
gfxUserFontEntry* aUserFontEntry,
|
gfxUserFontEntry* aUserFontEntry,
|
||||||
bool aPrivate);
|
bool aPrivate);
|
||||||
@@ -364,14 +368,14 @@ public:
|
|||||||
// or rendering, and that must match between a font-set's userfont
|
// or rendering, and that must match between a font-set's userfont
|
||||||
// entry and the corresponding "real" font entry.
|
// entry and the corresponding "real" font entry.
|
||||||
struct Key {
|
struct Key {
|
||||||
nsCOMPtr<nsIURI> mURI;
|
RefPtr<gfxFontSrcURI> mURI;
|
||||||
nsCOMPtr<nsIPrincipal> mPrincipal; // use nullptr with data: URLs
|
nsCOMPtr<nsIPrincipal> mPrincipal; // use nullptr with data: URLs
|
||||||
// The font entry MUST notify the cache when it is destroyed
|
// The font entry MUST notify the cache when it is destroyed
|
||||||
// (by calling ForgetFont()).
|
// (by calling ForgetFont()).
|
||||||
gfxFontEntry* MOZ_NON_OWNING_REF mFontEntry;
|
gfxFontEntry* MOZ_NON_OWNING_REF mFontEntry;
|
||||||
bool mPrivate;
|
bool mPrivate;
|
||||||
|
|
||||||
Key(nsIURI* aURI, nsIPrincipal* aPrincipal,
|
Key(gfxFontSrcURI* aURI, nsIPrincipal* aPrincipal,
|
||||||
gfxFontEntry* aFontEntry, bool aPrivate)
|
gfxFontEntry* aFontEntry, bool aPrivate)
|
||||||
: mURI(aURI),
|
: mURI(aURI),
|
||||||
mPrincipal(aPrincipal),
|
mPrincipal(aPrincipal),
|
||||||
@@ -411,7 +415,7 @@ public:
|
|||||||
aKey->mPrincipal->GetHashValue(&principalHash);
|
aKey->mPrincipal->GetHashValue(&principalHash);
|
||||||
}
|
}
|
||||||
return mozilla::HashGeneric(principalHash + int(aKey->mPrivate),
|
return mozilla::HashGeneric(principalHash + int(aKey->mPrivate),
|
||||||
nsURIHashKey::HashKey(aKey->mURI),
|
aKey->mURI->Hash(),
|
||||||
HashFeatures(aKey->mFontEntry->mFeatureSettings),
|
HashFeatures(aKey->mFontEntry->mFeatureSettings),
|
||||||
mozilla::HashString(aKey->mFontEntry->mFamilyName),
|
mozilla::HashString(aKey->mFontEntry->mFamilyName),
|
||||||
(aKey->mFontEntry->mStyle |
|
(aKey->mFontEntry->mStyle |
|
||||||
@@ -422,7 +426,7 @@ public:
|
|||||||
|
|
||||||
enum { ALLOW_MEMMOVE = false };
|
enum { ALLOW_MEMMOVE = false };
|
||||||
|
|
||||||
nsIURI* GetURI() const { return mURI; }
|
gfxFontSrcURI* GetURI() const { return mURI; }
|
||||||
nsIPrincipal* GetPrincipal() const { return mPrincipal; }
|
nsIPrincipal* GetPrincipal() const { return mPrincipal; }
|
||||||
gfxFontEntry* GetFontEntry() const { return mFontEntry; }
|
gfxFontEntry* GetFontEntry() const { return mFontEntry; }
|
||||||
bool IsPrivate() const { return mPrivate; }
|
bool IsPrivate() const { return mPrivate; }
|
||||||
@@ -460,7 +464,7 @@ public:
|
|||||||
// to remove entries from the mAllowedFontSets tables.
|
// to remove entries from the mAllowedFontSets tables.
|
||||||
nsDataHashtable<nsPtrHashKey<gfxUserFontSet>, bool> mAllowedFontSets;
|
nsDataHashtable<nsPtrHashKey<gfxUserFontSet>, bool> mAllowedFontSets;
|
||||||
|
|
||||||
nsCOMPtr<nsIURI> mURI;
|
RefPtr<gfxFontSrcURI> mURI;
|
||||||
nsCOMPtr<nsIPrincipal> mPrincipal; // or nullptr for data: URLs
|
nsCOMPtr<nsIPrincipal> mPrincipal; // or nullptr for data: URLs
|
||||||
|
|
||||||
// The "real" font entry corresponding to this downloaded font.
|
// The "real" font entry corresponding to this downloaded font.
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "FontFaceSet.h"
|
#include "FontFaceSet.h"
|
||||||
|
|
||||||
#include "gfxFontConstants.h"
|
#include "gfxFontConstants.h"
|
||||||
|
#include "gfxFontSrcURI.h"
|
||||||
#include "mozilla/css/Declaration.h"
|
#include "mozilla/css/Declaration.h"
|
||||||
#include "mozilla/css/Loader.h"
|
#include "mozilla/css/Loader.h"
|
||||||
#include "mozilla/dom/FontFaceSetBinding.h"
|
#include "mozilla/dom/FontFaceSetBinding.h"
|
||||||
@@ -631,7 +632,7 @@ FontFaceSet::StartLoad(gfxUserFontEntry* aUserFontEntry,
|
|||||||
// being loaded might have a different origin from the principal of the
|
// being loaded might have a different origin from the principal of the
|
||||||
// stylesheet that initiated the font load.
|
// stylesheet that initiated the font load.
|
||||||
rv = NS_NewChannelWithTriggeringPrincipal(getter_AddRefs(channel),
|
rv = NS_NewChannelWithTriggeringPrincipal(getter_AddRefs(channel),
|
||||||
aFontFaceSrc->mURI,
|
aFontFaceSrc->mURI->get(),
|
||||||
mDocument,
|
mDocument,
|
||||||
aUserFontEntry->GetPrincipal(),
|
aUserFontEntry->GetPrincipal(),
|
||||||
nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS,
|
nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS,
|
||||||
@@ -640,7 +641,8 @@ FontFaceSet::StartLoad(gfxUserFontEntry* aUserFontEntry,
|
|||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
RefPtr<nsFontFaceLoader> fontLoader =
|
RefPtr<nsFontFaceLoader> fontLoader =
|
||||||
new nsFontFaceLoader(aUserFontEntry, aFontFaceSrc->mURI, this, channel);
|
new nsFontFaceLoader(aUserFontEntry, aFontFaceSrc->mURI->get(), this,
|
||||||
|
channel);
|
||||||
|
|
||||||
if (LOG_ENABLED()) {
|
if (LOG_ENABLED()) {
|
||||||
LOG(("userfonts (%p) download start - font uri: (%s) "
|
LOG(("userfonts (%p) download start - font uri: (%s) "
|
||||||
@@ -682,7 +684,8 @@ FontFaceSet::StartLoad(gfxUserFontEntry* aUserFontEntry,
|
|||||||
rv = NS_NewStreamLoader(getter_AddRefs(streamLoader), fontLoader);
|
rv = NS_NewStreamLoader(getter_AddRefs(streamLoader), fontLoader);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
mozilla::net::PredictorLearn(aFontFaceSrc->mURI, mDocument->GetDocumentURI(),
|
mozilla::net::PredictorLearn(aFontFaceSrc->mURI->get(),
|
||||||
|
mDocument->GetDocumentURI(),
|
||||||
nsINetworkPredictor::LEARN_LOAD_SUBRESOURCE,
|
nsINetworkPredictor::LEARN_LOAD_SUBRESOURCE,
|
||||||
loadGroup);
|
loadGroup);
|
||||||
|
|
||||||
@@ -1119,7 +1122,8 @@ FontFaceSet::FindOrCreateUserFontEntryFromFontFace(const nsAString& aFamilyName,
|
|||||||
break;
|
break;
|
||||||
case eCSSUnit_URL: {
|
case eCSSUnit_URL: {
|
||||||
face->mSourceType = gfxFontFaceSrc::eSourceType_URL;
|
face->mSourceType = gfxFontFaceSrc::eSourceType_URL;
|
||||||
face->mURI = val.GetURLValue();
|
nsIURI* uri = val.GetURLValue();
|
||||||
|
face->mURI = uri ? new gfxFontSrcURI(uri) : nullptr;
|
||||||
URLValue* url = val.GetURLStructValue();
|
URLValue* url = val.GetURLStructValue();
|
||||||
face->mReferrer = url->mExtraData->GetReferrer();
|
face->mReferrer = url->mExtraData->GetReferrer();
|
||||||
face->mReferrerPolicy = mDocument->GetReferrerPolicy();
|
face->mReferrerPolicy = mDocument->GetReferrerPolicy();
|
||||||
@@ -1400,7 +1404,7 @@ FontFaceSet::SyncLoadFontData(gfxUserFontEntry* aFontToLoad,
|
|||||||
// whether we use SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS or not, to be more
|
// whether we use SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS or not, to be more
|
||||||
// restrictive we use SEC_REQUIRE_SAME_ORIGIN_DATA_INHERITS.
|
// restrictive we use SEC_REQUIRE_SAME_ORIGIN_DATA_INHERITS.
|
||||||
rv = NS_NewChannelWithTriggeringPrincipal(getter_AddRefs(channel),
|
rv = NS_NewChannelWithTriggeringPrincipal(getter_AddRefs(channel),
|
||||||
aFontFaceSrc->mURI,
|
aFontFaceSrc->mURI->get(),
|
||||||
mDocument,
|
mDocument,
|
||||||
aFontToLoad->GetPrincipal(),
|
aFontToLoad->GetPrincipal(),
|
||||||
nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_INHERITS,
|
nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_INHERITS,
|
||||||
|
|||||||
Reference in New Issue
Block a user