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