mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-26 12:20:56 +00:00
Bug 1771493 - Part 2. Merge FontFaceSetImpl and gfxUserFontSet into a single class. r=emilio
This patch merges FontFaceSetImpl and gfxUserFontSet into the same class. This reduces the level of indirection and in theory makes it easier to manage future threading issues. Differential Revision: https://phabricator.services.mozilla.com/D147817
This commit is contained in:
parent
12b14bddea
commit
4dfc867556
@ -16103,7 +16103,7 @@ gfxUserFontSet* Document::GetUserFontSet() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return mFontFaceSet->GetUserFontSet();
|
||||
return mFontFaceSet->GetImpl();
|
||||
}
|
||||
|
||||
void Document::FlushUserFontSet() {
|
||||
|
@ -254,11 +254,11 @@ gfxUserFontFamily::~gfxUserFontFamily() {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
}
|
||||
|
||||
gfxFontSrcPrincipal* gfxFontFaceSrc::LoadPrincipal(
|
||||
already_AddRefed<gfxFontSrcPrincipal> gfxFontFaceSrc::LoadPrincipal(
|
||||
const gfxUserFontSet& aFontSet) const {
|
||||
MOZ_ASSERT(mSourceType == eSourceType_URL);
|
||||
if (mUseOriginPrincipal && mOriginPrincipal) {
|
||||
return mOriginPrincipal;
|
||||
return RefPtr{mOriginPrincipal}.forget();
|
||||
}
|
||||
return aFontSet.GetStandardFontLoadPrincipal();
|
||||
}
|
||||
@ -933,11 +933,15 @@ gfxUserFontSet::gfxUserFontSet()
|
||||
}
|
||||
}
|
||||
|
||||
gfxUserFontSet::~gfxUserFontSet() {
|
||||
gfxUserFontSet::~gfxUserFontSet() { Destroy(); }
|
||||
|
||||
void gfxUserFontSet::Destroy() {
|
||||
gfxPlatformFontList* fp = gfxPlatformFontList::PlatformFontList();
|
||||
if (fp) {
|
||||
fp->RemoveUserFontSet(this);
|
||||
}
|
||||
|
||||
mFontFamilies.Clear();
|
||||
}
|
||||
|
||||
already_AddRefed<gfxUserFontEntry> gfxUserFontSet::FindOrCreateUserFontEntry(
|
||||
@ -1259,7 +1263,7 @@ gfxFontEntry* gfxUserFontSet::UserFontCache::GetFont(
|
||||
}
|
||||
|
||||
// Ignore principal when looking up a data: URI.
|
||||
gfxFontSrcPrincipal* principal =
|
||||
RefPtr<gfxFontSrcPrincipal> principal =
|
||||
IgnorePrincipal(aSrc.mURI) ? nullptr
|
||||
: aSrc.LoadPrincipal(*aUserFontEntry.mFontSet);
|
||||
|
||||
|
@ -91,7 +91,8 @@ struct gfxFontFaceSrc {
|
||||
|
||||
// The principal that should be used for the load. Should only be used for
|
||||
// URL sources.
|
||||
gfxFontSrcPrincipal* LoadPrincipal(const gfxUserFontSet&) const;
|
||||
already_AddRefed<gfxFontSrcPrincipal> LoadPrincipal(
|
||||
const gfxUserFontSet&) const;
|
||||
};
|
||||
|
||||
inline bool operator==(const gfxFontFaceSrc& a, const gfxFontFaceSrc& b) {
|
||||
@ -225,10 +226,12 @@ class gfxUserFontSet {
|
||||
typedef mozilla::WeightRange WeightRange;
|
||||
typedef gfxFontEntry::RangeFlags RangeFlags;
|
||||
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(gfxUserFontSet)
|
||||
NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
|
||||
|
||||
gfxUserFontSet();
|
||||
|
||||
void Destroy();
|
||||
|
||||
enum {
|
||||
// no flags ==> no hint set
|
||||
// unknown ==> unknown format hint set
|
||||
@ -300,17 +303,13 @@ class gfxUserFontSet {
|
||||
// the given name
|
||||
gfxUserFontFamily* LookupFamily(const nsACString& aName) const;
|
||||
|
||||
virtual gfxFontSrcPrincipal* GetStandardFontLoadPrincipal() const = 0;
|
||||
virtual already_AddRefed<gfxFontSrcPrincipal> GetStandardFontLoadPrincipal()
|
||||
const = 0;
|
||||
virtual nsPresContext* GetPresContext() const = 0;
|
||||
|
||||
// check whether content policies allow the given URI to load.
|
||||
virtual bool IsFontLoadAllowed(const gfxFontFaceSrc&) = 0;
|
||||
|
||||
// Dispatches all of the specified runnables to the font face set's
|
||||
// document's event queue.
|
||||
virtual void DispatchFontLoadViolations(
|
||||
nsTArray<nsCOMPtr<nsIRunnable>>& aViolations) = 0;
|
||||
|
||||
// initialize the process that loads external font data, which upon
|
||||
// completion will call FontDataDownloadComplete method
|
||||
virtual nsresult StartLoad(gfxUserFontEntry* aUserFontEntry,
|
||||
|
@ -207,7 +207,7 @@ void nsPresContext::ForceReflowForFontInfoUpdate(bool aNeedsReframe) {
|
||||
// If there's a user font set, discard any src:local() faces it may have
|
||||
// loaded because their font entries may no longer be valid.
|
||||
if (auto* fonts = Document()->GetFonts()) {
|
||||
fonts->GetUserFontSet()->ForgetLocalFaces();
|
||||
fonts->GetImpl()->ForgetLocalFaces();
|
||||
}
|
||||
|
||||
FlushFontCache();
|
||||
|
@ -69,13 +69,10 @@ CSSFontFaceRule* InspectorFontFace::GetRule() {
|
||||
// in the relevant font group's user font set
|
||||
RawServoFontFaceRule* rule = nullptr;
|
||||
if (mFontEntry->IsUserFont()) {
|
||||
FontFaceSet::UserFontSet* fontSet =
|
||||
static_cast<FontFaceSet::UserFontSet*>(mFontGroup->GetUserFontSet());
|
||||
if (fontSet) {
|
||||
FontFaceSetImpl* fontFaceSet = fontSet->GetFontFaceSet();
|
||||
if (fontFaceSet) {
|
||||
rule = fontFaceSet->FindRuleForEntry(mFontEntry);
|
||||
}
|
||||
auto* fontFaceSet =
|
||||
static_cast<FontFaceSetImpl*>(mFontGroup->GetUserFontSet());
|
||||
if (fontFaceSet) {
|
||||
rule = fontFaceSet->FindRuleForEntry(mFontEntry);
|
||||
}
|
||||
}
|
||||
if (rule) {
|
||||
|
@ -517,10 +517,9 @@ void FontFaceImpl::SetUserFontEntry(gfxUserFontEntry* aEntry) {
|
||||
if (mUserFontEntry) {
|
||||
mUserFontEntry->mFontFaces.AppendElement(this);
|
||||
|
||||
MOZ_ASSERT(
|
||||
mUserFontEntry->GetUserFontSet() == mFontFaceSet->GetUserFontSet(),
|
||||
"user font entry must be associated with the same user font set "
|
||||
"as the FontFace");
|
||||
MOZ_ASSERT(mUserFontEntry->GetUserFontSet() == mFontFaceSet,
|
||||
"user font entry must be associated with the same user font set "
|
||||
"as the FontFace");
|
||||
|
||||
// Our newly assigned user font entry might be in the process of or
|
||||
// finished loading, so set our status accordingly. But only do so
|
||||
@ -744,10 +743,10 @@ void FontFaceImpl::Entry::GetUserFontSets(nsTArray<gfxUserFontSet*>& aResult) {
|
||||
|
||||
for (FontFaceImpl* f : mFontFaces) {
|
||||
if (f->mInFontFaceSet) {
|
||||
aResult.AppendElement(f->mFontFaceSet->GetUserFontSet());
|
||||
aResult.AppendElement(f->mFontFaceSet);
|
||||
}
|
||||
for (FontFaceSetImpl* s : f->mOtherFontFaceSets) {
|
||||
aResult.AppendElement(s->GetUserFontSet());
|
||||
aResult.AppendElement(s);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,13 +11,9 @@
|
||||
#include "mozilla/dom/FontFaceSetBinding.h"
|
||||
#include "mozilla/dom/FontFaceSetImpl.h"
|
||||
#include "mozilla/DOMEventTargetHelper.h"
|
||||
#include "gfxUserFontSet.h"
|
||||
#include "nsICSSLoaderObserver.h"
|
||||
#include "nsIDOMEventListener.h"
|
||||
|
||||
struct gfxFontFaceSrc;
|
||||
class gfxFontSrcPrincipal;
|
||||
class gfxUserFontEntry;
|
||||
class nsFontFaceLoader;
|
||||
class nsIPrincipal;
|
||||
class nsPIDOMWindowInner;
|
||||
@ -37,8 +33,6 @@ class FontFaceSet final : public DOMEventTargetHelper {
|
||||
friend class mozilla::PostTraversalTask;
|
||||
|
||||
public:
|
||||
using UserFontSet = FontFaceSetImpl::UserFontSet;
|
||||
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FontFaceSet, DOMEventTargetHelper)
|
||||
|
||||
@ -67,8 +61,6 @@ class FontFaceSet final : public DOMEventTargetHelper {
|
||||
|
||||
void CopyNonRuleFacesTo(FontFaceSet* aFontFaceSet) const;
|
||||
|
||||
UserFontSet* GetUserFontSet() const { return mImpl->GetUserFontSet(); }
|
||||
|
||||
void CacheFontLoadability() { mImpl->CacheFontLoadability(); }
|
||||
|
||||
FontFaceSetImpl* GetImpl() const { return mImpl; }
|
||||
|
@ -125,8 +125,6 @@ void FontFaceSetImpl::Initialize() {
|
||||
}
|
||||
|
||||
mDocument->CSSLoader()->AddObserver(this);
|
||||
|
||||
mUserFontSet = new UserFontSet(this);
|
||||
}
|
||||
|
||||
void FontFaceSetImpl::Destroy() {
|
||||
@ -150,10 +148,7 @@ void FontFaceSetImpl::Destroy() {
|
||||
mRuleFaces.Clear();
|
||||
mNonRuleFaces.Clear();
|
||||
|
||||
if (mUserFontSet) {
|
||||
mUserFontSet->mFontFaceSet = nullptr;
|
||||
mUserFontSet = nullptr;
|
||||
}
|
||||
gfxUserFontSet::Destroy();
|
||||
}
|
||||
|
||||
void FontFaceSetImpl::RemoveDOMContentLoadedListener() {
|
||||
@ -221,7 +216,7 @@ void FontFaceSetImpl::FindMatchingFontFaces(const nsACString& aFont,
|
||||
|
||||
const auto& name = fontFamilyName.AsFamilyName();
|
||||
RefPtr<gfxFontFamily> family =
|
||||
mUserFontSet->LookupFamily(nsAtomCString(name.name.AsAtom()));
|
||||
LookupFamily(nsAtomCString(name.name.AsAtom()));
|
||||
|
||||
if (!family) {
|
||||
continue;
|
||||
@ -473,8 +468,6 @@ nsresult FontFaceSetImpl::StartLoad(gfxUserFontEntry* aUserFontEntry,
|
||||
|
||||
bool FontFaceSetImpl::UpdateRules(
|
||||
const nsTArray<nsFontFaceRuleContainer>& aRules) {
|
||||
MOZ_ASSERT(mUserFontSet);
|
||||
|
||||
// If there was a change to the mNonRuleFaces array, then there could
|
||||
// have been a modification to the user font set.
|
||||
bool modified = mNonRuleFacesDirty;
|
||||
@ -503,7 +496,7 @@ bool FontFaceSetImpl::UpdateRules(
|
||||
// the same font entries as before. (The order can affect font selection
|
||||
// where multiple faces match the requested style, perhaps with overlapping
|
||||
// unicode-range coverage.)
|
||||
for (const auto& fontFamily : mUserFontSet->mFontFamilies.Values()) {
|
||||
for (const auto& fontFamily : mFontFamilies.Values()) {
|
||||
fontFamily->DetachFontEntries();
|
||||
}
|
||||
|
||||
@ -539,7 +532,7 @@ bool FontFaceSetImpl::UpdateRules(
|
||||
|
||||
// Remove any residual families that have no font entries (i.e., they were
|
||||
// not defined at all by the updated set of @font-face rules).
|
||||
for (auto it = mUserFontSet->mFontFamilies.Iter(); !it.Done(); it.Next()) {
|
||||
for (auto it = mFontFamilies.Iter(); !it.Done(); it.Next()) {
|
||||
if (!it.Data()->FontListLength()) {
|
||||
it.Remove();
|
||||
}
|
||||
@ -584,25 +577,19 @@ bool FontFaceSetImpl::UpdateRules(
|
||||
}
|
||||
|
||||
// if local rules needed to be rebuilt, they have been rebuilt at this point
|
||||
if (mUserFontSet->mRebuildLocalRules) {
|
||||
mUserFontSet->mLocalRulesUsed = false;
|
||||
mUserFontSet->mRebuildLocalRules = false;
|
||||
if (mRebuildLocalRules) {
|
||||
mLocalRulesUsed = false;
|
||||
mRebuildLocalRules = false;
|
||||
}
|
||||
|
||||
if (LOG_ENABLED() && !mRuleFaces.IsEmpty()) {
|
||||
LOG(("userfonts (%p) userfont rules update (%s) rule count: %d",
|
||||
mUserFontSet.get(), (modified ? "modified" : "not modified"),
|
||||
(int)(mRuleFaces.Length())));
|
||||
LOG(("userfonts (%p) userfont rules update (%s) rule count: %d", this,
|
||||
(modified ? "modified" : "not modified"), (int)(mRuleFaces.Length())));
|
||||
}
|
||||
|
||||
return modified;
|
||||
}
|
||||
|
||||
void FontFaceSetImpl::IncrementGeneration(bool aIsRebuild) {
|
||||
MOZ_ASSERT(mUserFontSet);
|
||||
mUserFontSet->IncrementGeneration(aIsRebuild);
|
||||
}
|
||||
|
||||
void FontFaceSetImpl::InsertNonRuleFontFace(FontFaceImpl* aFontFace,
|
||||
bool& aFontSetModified) {
|
||||
nsAtom* fontFamily = aFontFace->GetFamilyName();
|
||||
@ -616,8 +603,7 @@ void FontFaceSetImpl::InsertNonRuleFontFace(FontFaceImpl* aFontFace,
|
||||
|
||||
// Just create a new font entry if we haven't got one already.
|
||||
if (!aFontFace->GetUserFontEntry()) {
|
||||
// XXX Should we be checking mUserFontSet->mLocalRulesUsed like
|
||||
// InsertRuleFontFace does?
|
||||
// XXX Should we be checking mLocalRulesUsed like InsertRuleFontFace does?
|
||||
RefPtr<gfxUserFontEntry> entry = FindOrCreateUserFontEntryFromFontFace(
|
||||
family, aFontFace, StyleOrigin::Author);
|
||||
if (!entry) {
|
||||
@ -627,7 +613,7 @@ void FontFaceSetImpl::InsertNonRuleFontFace(FontFaceImpl* aFontFace,
|
||||
}
|
||||
|
||||
aFontSetModified = true;
|
||||
mUserFontSet->AddUserFontEntry(family, aFontFace->GetUserFontEntry());
|
||||
AddUserFontEntry(family, aFontFace->GetUserFontEntry());
|
||||
}
|
||||
|
||||
void FontFaceSetImpl::InsertRuleFontFace(FontFaceImpl* aFontFace,
|
||||
@ -656,7 +642,7 @@ void FontFaceSetImpl::InsertRuleFontFace(FontFaceImpl* aFontFace,
|
||||
if (rec.mFontFace == aFontFace && rec.mOrigin == Some(aSheetType)) {
|
||||
// if local rules were used, don't use the old font entry
|
||||
// for rules containing src local usage
|
||||
if (mUserFontSet->mLocalRulesUsed && mUserFontSet->mRebuildLocalRules) {
|
||||
if (mLocalRulesUsed && mRebuildLocalRules) {
|
||||
if (aFontFace->HasLocalSrc()) {
|
||||
// Remove the old record, but wait to see if we successfully create a
|
||||
// new user font entry below.
|
||||
@ -669,7 +655,7 @@ void FontFaceSetImpl::InsertRuleFontFace(FontFaceImpl* aFontFace,
|
||||
gfxUserFontEntry* entry = rec.mFontFace->GetUserFontEntry();
|
||||
MOZ_ASSERT(entry, "FontFace should have a gfxUserFontEntry by now");
|
||||
|
||||
mUserFontSet->AddUserFontEntry(family, entry);
|
||||
AddUserFontEntry(family, entry);
|
||||
|
||||
MOZ_ASSERT(!HasRuleFontFace(rec.mFontFace),
|
||||
"FontFace should not occur in mRuleFaces twice");
|
||||
@ -731,7 +717,7 @@ void FontFaceSetImpl::InsertRuleFontFace(FontFaceImpl* aFontFace,
|
||||
// on the family, gfxUserFontFamily::AddFontEntry(), which AddUserFontEntry
|
||||
// calls, will automatically remove the earlier occurrence of the same
|
||||
// userfont entry.
|
||||
mUserFontSet->AddUserFontEntry(family, entry);
|
||||
AddUserFontEntry(family, entry);
|
||||
}
|
||||
|
||||
/* static */
|
||||
@ -873,8 +859,7 @@ FontFaceSetImpl::FindOrCreateUserFontEntryFromFontFace(
|
||||
// family.
|
||||
if (!existingEntry->mFamilyName.IsEmpty() &&
|
||||
existingEntry->mFamilyName != aFamilyName) {
|
||||
gfxUserFontFamily* family =
|
||||
set->GetUserFontSet()->LookupFamily(existingEntry->mFamilyName);
|
||||
gfxUserFontFamily* family = set->LookupFamily(existingEntry->mFamilyName);
|
||||
if (family) {
|
||||
family->RemoveFontEntry(existingEntry);
|
||||
}
|
||||
@ -1000,7 +985,7 @@ FontFaceSetImpl::FindOrCreateUserFontEntryFromFontFace(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<gfxUserFontEntry> entry = set->mUserFontSet->FindOrCreateUserFontEntry(
|
||||
RefPtr<gfxUserFontEntry> entry = set->FindOrCreateUserFontEntry(
|
||||
aFamilyName, srcArray, weight, stretch, italicStyle, featureSettings,
|
||||
variationSettings, languageOverride, unicodeRanges, fontDisplay,
|
||||
rangeFlags, ascentOverride, descentOverride, lineGapOverride, sizeAdjust);
|
||||
@ -1077,7 +1062,7 @@ nsresult FontFaceSetImpl::LogMessage(gfxUserFontEntry* aUserFontEntry,
|
||||
message.AppendLiteral(" source: ");
|
||||
message.Append(fontURI);
|
||||
|
||||
LOG(("userfonts (%p) %s", mUserFontSet.get(), message.get()));
|
||||
LOG(("userfonts (%p) %s", this, message.get()));
|
||||
|
||||
// try to give the user an indication of where the rule came from
|
||||
RawServoFontFaceRule* rule = FindRuleForUserFontEntry(aUserFontEntry);
|
||||
@ -1125,12 +1110,8 @@ nsresult FontFaceSetImpl::LogMessage(gfxUserFontEntry* aUserFontEntry,
|
||||
}
|
||||
|
||||
void FontFaceSetImpl::CacheFontLoadability() {
|
||||
if (!mUserFontSet) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO(emilio): We could do it a bit more incrementally maybe?
|
||||
for (const auto& fontFamily : mUserFontSet->mFontFamilies.Values()) {
|
||||
for (const auto& fontFamily : mFontFamilies.Values()) {
|
||||
fontFamily->ReadLock();
|
||||
for (const gfxFontEntry* entry : fontFamily->GetFontList()) {
|
||||
if (!entry->mIsUserFontContainer) {
|
||||
@ -1162,17 +1143,13 @@ bool FontFaceSetImpl::IsFontLoadAllowed(const gfxFontFaceSrc& aSrc) {
|
||||
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (!mUserFontSet) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (aSrc.mUseOriginPrincipal) {
|
||||
return true;
|
||||
}
|
||||
|
||||
gfxFontSrcPrincipal* gfxPrincipal = aSrc.mURI->InheritsSecurityContext()
|
||||
? nullptr
|
||||
: aSrc.LoadPrincipal(*mUserFontSet);
|
||||
RefPtr<gfxFontSrcPrincipal> gfxPrincipal =
|
||||
aSrc.mURI->InheritsSecurityContext() ? nullptr
|
||||
: aSrc.LoadPrincipal(*this);
|
||||
|
||||
nsIPrincipal* principal =
|
||||
gfxPrincipal ? gfxPrincipal->NodePrincipal() : nullptr;
|
||||
@ -1192,21 +1169,6 @@ bool FontFaceSetImpl::IsFontLoadAllowed(const gfxFontFaceSrc& aSrc) {
|
||||
return NS_SUCCEEDED(rv) && NS_CP_ACCEPTED(shouldLoad);
|
||||
}
|
||||
|
||||
void FontFaceSetImpl::DispatchFontLoadViolations(
|
||||
nsTArray<nsCOMPtr<nsIRunnable>>& aViolations) {
|
||||
if (XRE_IsContentProcess()) {
|
||||
nsCOMPtr<nsIEventTarget> eventTarget =
|
||||
mDocument->EventTargetFor(TaskCategory::Other);
|
||||
for (nsIRunnable* runnable : aViolations) {
|
||||
eventTarget->Dispatch(do_AddRef(runnable), NS_DISPATCH_NORMAL);
|
||||
}
|
||||
} else {
|
||||
for (nsIRunnable* runnable : aViolations) {
|
||||
NS_DispatchToMainThread(do_AddRef(runnable));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsresult FontFaceSetImpl::SyncLoadFontData(gfxUserFontEntry* aFontToLoad,
|
||||
const gfxFontFaceSrc* aFontFaceSrc,
|
||||
uint8_t*& aBuffer,
|
||||
@ -1486,7 +1448,7 @@ void FontFaceSetImpl::MarkUserFontSetDirty() {
|
||||
}
|
||||
}
|
||||
|
||||
nsPresContext* FontFaceSetImpl::GetPresContext() {
|
||||
nsPresContext* FontFaceSetImpl::GetPresContext() const {
|
||||
if (!mDocument) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -1499,48 +1461,19 @@ void FontFaceSetImpl::RefreshStandardFontLoadPrincipal() {
|
||||
mStandardFontLoadPrincipal = new gfxFontSrcPrincipal(
|
||||
mDocument->NodePrincipal(), mDocument->PartitionedPrincipal());
|
||||
mAllowedFontLoads.Clear();
|
||||
if (mUserFontSet) {
|
||||
mUserFontSet->IncrementGeneration(false);
|
||||
}
|
||||
IncrementGeneration(false);
|
||||
}
|
||||
|
||||
// -- FontFaceSetImpl::UserFontSet
|
||||
// -- gfxUserFontSet
|
||||
// ------------------------------------------------
|
||||
|
||||
/* virtual */
|
||||
bool FontFaceSetImpl::UserFontSet::IsFontLoadAllowed(
|
||||
const gfxFontFaceSrc& aSrc) {
|
||||
return mFontFaceSet && mFontFaceSet->IsFontLoadAllowed(aSrc);
|
||||
}
|
||||
|
||||
/* virtual */
|
||||
void FontFaceSetImpl::UserFontSet::DispatchFontLoadViolations(
|
||||
nsTArray<nsCOMPtr<nsIRunnable>>& aViolations) {
|
||||
if (mFontFaceSet) {
|
||||
mFontFaceSet->DispatchFontLoadViolations(aViolations);
|
||||
}
|
||||
}
|
||||
|
||||
/* virtual */
|
||||
nsresult FontFaceSetImpl::UserFontSet::StartLoad(
|
||||
gfxUserFontEntry* aUserFontEntry, uint32_t aSrcIndex) {
|
||||
if (!mFontFaceSet) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
return mFontFaceSet->StartLoad(aUserFontEntry, aSrcIndex);
|
||||
}
|
||||
|
||||
void FontFaceSetImpl::UserFontSet::RecordFontLoadDone(uint32_t aFontSize,
|
||||
TimeStamp aDoneTime) {
|
||||
void FontFaceSetImpl::RecordFontLoadDone(uint32_t aFontSize,
|
||||
TimeStamp aDoneTime) {
|
||||
mDownloadCount++;
|
||||
mDownloadSize += aFontSize;
|
||||
Telemetry::Accumulate(Telemetry::WEBFONT_SIZE, aFontSize / 1024);
|
||||
|
||||
if (!mFontFaceSet) {
|
||||
return;
|
||||
}
|
||||
|
||||
TimeStamp navStart = mFontFaceSet->GetNavigationStartTimeStamp();
|
||||
TimeStamp navStart = GetNavigationStartTimeStamp();
|
||||
TimeStamp zero;
|
||||
if (navStart != zero) {
|
||||
Telemetry::AccumulateTimeDelta(Telemetry::WEBFONT_DOWNLOAD_TIME_AFTER_START,
|
||||
@ -1548,44 +1481,9 @@ void FontFaceSetImpl::UserFontSet::RecordFontLoadDone(uint32_t aFontSize,
|
||||
}
|
||||
}
|
||||
|
||||
/* virtual */
|
||||
nsresult FontFaceSetImpl::UserFontSet::LogMessage(
|
||||
gfxUserFontEntry* aUserFontEntry, uint32_t aSrcIndex, const char* aMessage,
|
||||
uint32_t aFlags, nsresult aStatus) {
|
||||
if (!mFontFaceSet) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
return mFontFaceSet->LogMessage(aUserFontEntry, aSrcIndex, aMessage, aFlags,
|
||||
aStatus);
|
||||
}
|
||||
void FontFaceSetImpl::DoRebuildUserFontSet() { MarkUserFontSetDirty(); }
|
||||
|
||||
/* virtual */
|
||||
nsresult FontFaceSetImpl::UserFontSet::SyncLoadFontData(
|
||||
gfxUserFontEntry* aFontToLoad, const gfxFontFaceSrc* aFontFaceSrc,
|
||||
uint8_t*& aBuffer, uint32_t& aBufferLength) {
|
||||
if (!mFontFaceSet) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
return mFontFaceSet->SyncLoadFontData(aFontToLoad, aFontFaceSrc, aBuffer,
|
||||
aBufferLength);
|
||||
}
|
||||
|
||||
/* virtual */
|
||||
bool FontFaceSetImpl::UserFontSet::GetPrivateBrowsing() {
|
||||
return mFontFaceSet && mFontFaceSet->mPrivateBrowsing;
|
||||
}
|
||||
|
||||
/* virtual */
|
||||
void FontFaceSetImpl::UserFontSet::DoRebuildUserFontSet() {
|
||||
if (!mFontFaceSet) {
|
||||
return;
|
||||
}
|
||||
mFontFaceSet->MarkUserFontSetDirty();
|
||||
}
|
||||
|
||||
/* virtual */
|
||||
already_AddRefed<gfxUserFontEntry>
|
||||
FontFaceSetImpl::UserFontSet::CreateUserFontEntry(
|
||||
already_AddRefed<gfxUserFontEntry> FontFaceSetImpl::CreateUserFontEntry(
|
||||
const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList, WeightRange aWeight,
|
||||
StretchRange aStretch, SlantStyleRange aStyle,
|
||||
const nsTArray<gfxFontFeature>& aFeatureSettings,
|
||||
|
@ -33,80 +33,54 @@ class FontFace;
|
||||
|
||||
namespace mozilla::dom {
|
||||
|
||||
class FontFaceSetImpl final : public nsIDOMEventListener,
|
||||
class FontFaceSetImpl final : public gfxUserFontSet,
|
||||
public nsIDOMEventListener,
|
||||
public nsICSSLoaderObserver {
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
|
||||
friend class UserFontSet;
|
||||
public:
|
||||
// gfxUserFontSet
|
||||
|
||||
already_AddRefed<gfxFontSrcPrincipal> GetStandardFontLoadPrincipal()
|
||||
const override {
|
||||
return RefPtr{mStandardFontLoadPrincipal}.forget();
|
||||
}
|
||||
|
||||
nsPresContext* GetPresContext() const override;
|
||||
|
||||
bool IsFontLoadAllowed(const gfxFontFaceSrc&) override;
|
||||
|
||||
nsresult StartLoad(gfxUserFontEntry* aUserFontEntry,
|
||||
uint32_t aSrcIndex) override;
|
||||
|
||||
void RecordFontLoadDone(uint32_t aFontSize, TimeStamp aDoneTime) override;
|
||||
|
||||
bool BypassCache() final { return mBypassCache; }
|
||||
|
||||
protected:
|
||||
// gfxUserFontSet
|
||||
|
||||
bool GetPrivateBrowsing() override { return mPrivateBrowsing; }
|
||||
nsresult SyncLoadFontData(gfxUserFontEntry* aFontToLoad,
|
||||
const gfxFontFaceSrc* aFontFaceSrc,
|
||||
uint8_t*& aBuffer,
|
||||
uint32_t& aBufferLength) override;
|
||||
nsresult LogMessage(gfxUserFontEntry* aUserFontEntry, uint32_t aSrcIndex,
|
||||
const char* aMessage,
|
||||
uint32_t aFlags = nsIScriptError::errorFlag,
|
||||
nsresult aStatus = NS_OK) override;
|
||||
void DoRebuildUserFontSet() override;
|
||||
already_AddRefed<gfxUserFontEntry> CreateUserFontEntry(
|
||||
const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList, WeightRange aWeight,
|
||||
StretchRange aStretch, SlantStyleRange aStyle,
|
||||
const nsTArray<gfxFontFeature>& aFeatureSettings,
|
||||
const nsTArray<gfxFontVariation>& aVariationSettings,
|
||||
uint32_t aLanguageOverride, gfxCharacterMap* aUnicodeRanges,
|
||||
StyleFontDisplay aFontDisplay, RangeFlags aRangeFlags,
|
||||
float aAscentOverride, float aDescentOverride, float aLineGapOverride,
|
||||
float aSizeAdjust) override;
|
||||
|
||||
public:
|
||||
/**
|
||||
* A gfxUserFontSet that integrates with the layout and style systems to
|
||||
* manage @font-face rules and handle network requests for font loading.
|
||||
*
|
||||
* We would combine this class and FontFaceSet into the one class if it were
|
||||
* possible; it's not because FontFaceSet is cycle collected and
|
||||
* gfxUserFontSet isn't (and can't be, as gfx classes don't use the cycle
|
||||
* collector). So UserFontSet exists just to override the needed virtual
|
||||
* methods from gfxUserFontSet and to forward them on FontFaceSet.
|
||||
*/
|
||||
class UserFontSet final : public gfxUserFontSet {
|
||||
friend class FontFaceSetImpl;
|
||||
|
||||
public:
|
||||
explicit UserFontSet(FontFaceSetImpl* aFontFaceSet)
|
||||
: mFontFaceSet(aFontFaceSet) {}
|
||||
|
||||
FontFaceSetImpl* GetFontFaceSet() { return mFontFaceSet; }
|
||||
|
||||
gfxFontSrcPrincipal* GetStandardFontLoadPrincipal() const final {
|
||||
return mFontFaceSet ? mFontFaceSet->mStandardFontLoadPrincipal.get()
|
||||
: nullptr;
|
||||
}
|
||||
|
||||
nsPresContext* GetPresContext() const final {
|
||||
return mFontFaceSet ? mFontFaceSet->GetPresContext() : nullptr;
|
||||
}
|
||||
|
||||
bool IsFontLoadAllowed(const gfxFontFaceSrc&) final;
|
||||
|
||||
void DispatchFontLoadViolations(
|
||||
nsTArray<nsCOMPtr<nsIRunnable>>& aViolations) override;
|
||||
|
||||
virtual nsresult StartLoad(gfxUserFontEntry* aUserFontEntry,
|
||||
uint32_t aSrcIndex) override;
|
||||
|
||||
void RecordFontLoadDone(uint32_t aFontSize, TimeStamp aDoneTime) override;
|
||||
|
||||
bool BypassCache() final {
|
||||
return mFontFaceSet && mFontFaceSet->mBypassCache;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual bool GetPrivateBrowsing() override;
|
||||
virtual nsresult SyncLoadFontData(gfxUserFontEntry* aFontToLoad,
|
||||
const gfxFontFaceSrc* aFontFaceSrc,
|
||||
uint8_t*& aBuffer,
|
||||
uint32_t& aBufferLength) override;
|
||||
virtual nsresult LogMessage(gfxUserFontEntry* aUserFontEntry,
|
||||
uint32_t aSrcIndex, const char* aMessage,
|
||||
uint32_t aFlags = nsIScriptError::errorFlag,
|
||||
nsresult aStatus = NS_OK) override;
|
||||
virtual void DoRebuildUserFontSet() override;
|
||||
already_AddRefed<gfxUserFontEntry> CreateUserFontEntry(
|
||||
const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList, WeightRange aWeight,
|
||||
StretchRange aStretch, SlantStyleRange aStyle,
|
||||
const nsTArray<gfxFontFeature>& aFeatureSettings,
|
||||
const nsTArray<gfxFontVariation>& aVariationSettings,
|
||||
uint32_t aLanguageOverride, gfxCharacterMap* aUnicodeRanges,
|
||||
StyleFontDisplay aFontDisplay, RangeFlags aRangeFlags,
|
||||
float aAscentOverride, float aDescentOverride, float aLineGapOverride,
|
||||
float aSizeAdjust) override;
|
||||
|
||||
private:
|
||||
RefPtr<FontFaceSetImpl> mFontFaceSet;
|
||||
};
|
||||
|
||||
NS_DECL_NSIDOMEVENTLISTENER
|
||||
|
||||
FontFaceSetImpl(FontFaceSet* aOwner, dom::Document* aDocument);
|
||||
@ -114,21 +88,15 @@ class FontFaceSetImpl final : public nsIDOMEventListener,
|
||||
void Initialize();
|
||||
void Destroy();
|
||||
|
||||
UserFontSet* GetUserFontSet() const { return mUserFontSet; }
|
||||
|
||||
// Called by nsFontFaceLoader when the loader has completed normally.
|
||||
// It's removed from the mLoaders set.
|
||||
void RemoveLoader(nsFontFaceLoader* aLoader);
|
||||
|
||||
bool UpdateRules(const nsTArray<nsFontFaceRuleContainer>& aRules);
|
||||
|
||||
nsPresContext* GetPresContext();
|
||||
|
||||
// search for @font-face rule that matches a platform font entry
|
||||
RawServoFontFaceRule* FindRuleForEntry(gfxFontEntry* aFontEntry);
|
||||
|
||||
void IncrementGeneration(bool aIsRebuild = false);
|
||||
|
||||
/**
|
||||
* Finds an existing entry in the user font cache or creates a new user
|
||||
* font entry for the given FontFace object.
|
||||
@ -161,8 +129,7 @@ class FontFaceSetImpl final : public nsIDOMEventListener,
|
||||
void FlushUserFontSet();
|
||||
|
||||
static nsPresContext* GetPresContextFor(gfxUserFontSet* aUserFontSet) {
|
||||
FontFaceSetImpl* set =
|
||||
static_cast<UserFontSet*>(aUserFontSet)->mFontFaceSet;
|
||||
const auto* set = static_cast<FontFaceSetImpl*>(aUserFontSet);
|
||||
return set ? set->GetPresContext() : nullptr;
|
||||
}
|
||||
|
||||
@ -239,18 +206,9 @@ class FontFaceSetImpl final : public nsIDOMEventListener,
|
||||
RawServoFontFaceRule* FindRuleForUserFontEntry(
|
||||
gfxUserFontEntry* aUserFontEntry);
|
||||
|
||||
nsresult StartLoad(gfxUserFontEntry* aUserFontEntry, uint32_t aSrcIndex);
|
||||
gfxFontSrcPrincipal* GetStandardFontLoadPrincipal();
|
||||
already_AddRefed<gfxFontSrcPrincipal> GetStandardFontLoadPrincipal();
|
||||
nsresult CheckFontLoad(const gfxFontFaceSrc* aFontFaceSrc,
|
||||
gfxFontSrcPrincipal** aPrincipal, bool* aBypassCache);
|
||||
bool IsFontLoadAllowed(const gfxFontFaceSrc& aSrc);
|
||||
|
||||
void DispatchFontLoadViolations(nsTArray<nsCOMPtr<nsIRunnable>>& aViolations);
|
||||
nsresult SyncLoadFontData(gfxUserFontEntry* aFontToLoad,
|
||||
const gfxFontFaceSrc* aFontFaceSrc,
|
||||
uint8_t*& aBuffer, uint32_t& aBufferLength);
|
||||
nsresult LogMessage(gfxUserFontEntry* aUserFontEntry, uint32_t aSrcIndex,
|
||||
const char* aMessage, uint32_t aFlags, nsresult aStatus);
|
||||
|
||||
void InsertRuleFontFace(FontFaceImpl* aFontFace, FontFace* aFontFaceOwner,
|
||||
StyleOrigin aOrigin,
|
||||
@ -282,8 +240,6 @@ class FontFaceSetImpl final : public nsIDOMEventListener,
|
||||
|
||||
FontFaceSet* MOZ_NON_OWNING_REF mOwner;
|
||||
|
||||
RefPtr<UserFontSet> mUserFontSet;
|
||||
|
||||
// The document this is a FontFaceSet for.
|
||||
RefPtr<dom::Document> mDocument;
|
||||
|
||||
|
@ -271,7 +271,7 @@ nsFontFaceLoader::OnStreamComplete(nsIStreamLoader* aLoader,
|
||||
}
|
||||
}
|
||||
|
||||
mFontFaceSet->GetUserFontSet()->RecordFontLoadDone(aStringLen, doneTime);
|
||||
mFontFaceSet->RecordFontLoadDone(aStringLen, doneTime);
|
||||
|
||||
// The userFontEntry is responsible for freeing the downloaded data
|
||||
// (aString) when finished with it; the pointer is no longer valid
|
||||
|
Loading…
x
Reference in New Issue
Block a user