Bug 1420680: Rework how the loadability of font-faces is computed. r?jfkthame,bz draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Fri, 23 Mar 2018 16:06:56 +0100
changeset 771991 eacb92cb35175e0bbc9c9581aa4c96c6db06145e
parent 771987 d9cc89608cbdca2b3a113536d0478e7b909aa70f
child 771992 3a4199b30530b866ac5420bffab1e64a2113461a
push id103820
push userbmo:emilio@crisal.io
push dateSat, 24 Mar 2018 13:51:22 +0000
reviewersjfkthame, bz
bugs1420680, 1440561
milestone61.0a1
Bug 1420680: Rework how the loadability of font-faces is computed. r?jfkthame,bz This reworks bug 1440561 so that we only precompute loads that belong to our user font set, avoiding messing up with fonts in the cache that belong to other pages. The loadability of a font is precomputed in PreTraverse in the same way as we did, but only for the fonts that we may end up loading. This is stored in FontFaceSet now. Also, the principal shenanigans that this code did are reworked to be explicit about when the document principal changes in ResetToURI, instead of having a member around and a mutable variable. This makes the code easier to follow. MozReview-Commit-ID: 9ofTbaLDUF7
dom/base/nsDocument.cpp
gfx/thebes/gfxUserFontSet.cpp
gfx/thebes/gfxUserFontSet.h
layout/style/FontFaceSet.cpp
layout/style/FontFaceSet.h
layout/style/ServoStyleSet.cpp
layout/style/ServoStyleSet.h
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -2393,16 +2393,20 @@ nsIDocument::ResetToURI(nsIURI* aURI,
         GetLoadContextCodebasePrincipal(mDocumentURI, loadContext,
                                         getter_AddRefs(principal));
       if (NS_SUCCEEDED(rv)) {
         SetPrincipal(principal);
       }
     }
   }
 
+  if (mFontFaceSet) {
+    mFontFaceSet->RefreshStandardFontLoadPrincipal();
+  }
+
   // Refresh the principal on the compartment.
   if (nsPIDOMWindowInner* win = GetInnerWindow()) {
     nsGlobalWindowInner::Cast(win)->RefreshCompartmentPrincipal();
   }
 }
 
 already_AddRefed<nsIPrincipal>
 nsIDocument::MaybeDowngradePrincipal(nsIPrincipal* aPrincipal)
--- a/gfx/thebes/gfxUserFontSet.cpp
+++ b/gfx/thebes/gfxUserFontSet.cpp
@@ -328,16 +328,26 @@ gfxUserFontData::SizeOfIncludingThis(Mal
 
 /*virtual*/
 gfxUserFontFamily::~gfxUserFontFamily()
 {
   // Should not be dropped by stylo
   MOZ_ASSERT(NS_IsMainThread());
 }
 
+gfxFontSrcPrincipal*
+gfxFontFaceSrc::LoadPrincipal(const gfxUserFontSet& aFontSet) const
+{
+  MOZ_ASSERT(mSourceType == eSourceType_URL);
+  if (mUseOriginPrincipal && mOriginPrincipal) {
+    return mOriginPrincipal;
+  }
+  return aFontSet.GetStandardFontLoadPrincipal();
+}
+
 void
 gfxUserFontEntry::GetFamilyNameAndURIForLogging(nsACString& aFamilyName,
                                                 nsACString& aURI)
 {
   aFamilyName.Assign(NS_ConvertUTF16toUTF8(mFamilyName));
 
   aURI.Truncate();
   if (mSrcIndex == mSrcList.Length()) {
@@ -556,105 +566,87 @@ gfxUserFontEntry::DoLoadNextSrc(bool aFo
                     // for these entries.
                     if (currSrc.mUseOriginPrincipal && IgnorePrincipal(currSrc.mURI)) {
                         set->AppendTask(PostTraversalTask::LoadFontEntry(this));
                         SetLoadState(STATUS_LOAD_PENDING);
                         return;
                     }
                 }
 
-                gfxFontSrcPrincipal* principal = nullptr;
-                bool bypassCache;
-                nsresult rv = mFontSet->CheckFontLoad(&currSrc, &principal,
-                                                      &bypassCache);
+                // see if we have an existing entry for this source
+                gfxFontEntry* fe =
+                  gfxUserFontSet::UserFontCache::GetFont(currSrc, *this);
+                if (fe) {
+                    mPlatformFontEntry = fe;
+                    SetLoadState(STATUS_LOADED);
+                    if (LOG_ENABLED()) {
+                        LOG(("userfonts (%p) [src %d] "
+                             "loaded uri from cache: (%s) for (%s)\n",
+                             mFontSet, mSrcIndex,
+                             currSrc.mURI->GetSpecOrDefault().get(),
+                             NS_ConvertUTF16toUTF8(mFamilyName).get()));
+                    }
+                    return;
+                }
+
+                if (ServoStyleSet* set = ServoStyleSet::Current()) {
+                    // If we need to start a font load and we're on a style
+                    // worker thread, we have to defer it.
+                    set->AppendTask(PostTraversalTask::LoadFontEntry(this));
+                    SetLoadState(STATUS_LOAD_PENDING);
+                    return;
+                }
 
-                if (NS_SUCCEEDED(rv) && principal != nullptr) {
-                    if (!bypassCache) {
-                        // see if we have an existing entry for this source
-                        gfxFontEntry* fe = gfxUserFontSet::
-                            UserFontCache::GetFont(currSrc.mURI,
-                                                   principal,
-                                                   this,
-                                                   mFontSet->GetPrivateBrowsing());
-                        if (fe) {
-                            mPlatformFontEntry = fe;
-                            SetLoadState(STATUS_LOADED);
-                            if (LOG_ENABLED()) {
-                                LOG(("userfonts (%p) [src %d] "
-                                     "loaded uri from cache: (%s) for (%s)\n",
-                                     mFontSet, mSrcIndex,
-                                     currSrc.mURI->GetSpecOrDefault().get(),
-                                     NS_ConvertUTF16toUTF8(mFamilyName).get()));
-                            }
-                            return;
-                        }
-                    }
+                // record the principal we should use for the load for use when
+                // creating a channel and when caching the loaded entry.
+                mPrincipal = currSrc.LoadPrincipal(*mFontSet);
+
+                bool loadDoesntSpin =
+                  !aForceAsync && currSrc.mURI->SyncLoadIsOK();
+
+                if (loadDoesntSpin) {
+                    uint8_t* buffer = nullptr;
+                    uint32_t bufferLength = 0;
 
-                    if (ServoStyleSet* set = ServoStyleSet::Current()) {
-                        // If we need to start a font load and we're on a style
-                        // worker thread, we have to defer it.
-                        set->AppendTask(PostTraversalTask::LoadFontEntry(this));
-                        SetLoadState(STATUS_LOAD_PENDING);
-                        return;
-                    }
+                    // sync load font immediately
+                    nsresult rv = mFontSet->SyncLoadFontData(this, &currSrc, buffer,
+                                                    bufferLength);
 
-                    // record the principal returned by CheckFontLoad,
-                    // for use when creating a channel
-                    // and when caching the loaded entry
-                    mPrincipal = principal;
-
-                    bool loadDoesntSpin = false;
-                    if (!aForceAsync) {
-                        loadDoesntSpin = currSrc.mURI->SyncLoadIsOK();
+                    if (NS_SUCCEEDED(rv) &&
+                        LoadPlatformFont(buffer, bufferLength)) {
+                        SetLoadState(STATUS_LOADED);
+                        Telemetry::Accumulate(Telemetry::WEBFONT_SRCTYPE,
+                                              currSrc.mSourceType + 1);
+                        return;
+                    } else {
+                        mFontSet->LogMessage(this,
+                                             "font load failed",
+                                             nsIScriptError::errorFlag,
+                                             rv);
                     }
 
-                    if (NS_SUCCEEDED(rv) && loadDoesntSpin) {
-                        uint8_t* buffer = nullptr;
-                        uint32_t bufferLength = 0;
-
-                        // sync load font immediately
-                        rv = mFontSet->SyncLoadFontData(this, &currSrc, buffer,
-                                                        bufferLength);
+                } else {
+                    // otherwise load font async
+                    nsresult rv = mFontSet->StartLoad(this, &currSrc);
+                    bool loadOK = NS_SUCCEEDED(rv);
 
-                        if (NS_SUCCEEDED(rv) &&
-                            LoadPlatformFont(buffer, bufferLength)) {
-                            SetLoadState(STATUS_LOADED);
-                            Telemetry::Accumulate(Telemetry::WEBFONT_SRCTYPE,
-                                                  currSrc.mSourceType + 1);
-                            return;
-                        } else {
-                            mFontSet->LogMessage(this,
-                                                 "font load failed",
-                                                 nsIScriptError::errorFlag,
-                                                 rv);
+                    if (loadOK) {
+                        if (LOG_ENABLED()) {
+                            LOG(("userfonts (%p) [src %d] loading uri: (%s) for (%s)\n",
+                                 mFontSet, mSrcIndex,
+                                 currSrc.mURI->GetSpecOrDefault().get(),
+                                 NS_ConvertUTF16toUTF8(mFamilyName).get()));
                         }
-
+                        return;
                     } else {
-                        // otherwise load font async
-                        rv = mFontSet->StartLoad(this, &currSrc);
-                        bool loadOK = NS_SUCCEEDED(rv);
-
-                        if (loadOK) {
-                            if (LOG_ENABLED()) {
-                                LOG(("userfonts (%p) [src %d] loading uri: (%s) for (%s)\n",
-                                     mFontSet, mSrcIndex,
-                                     currSrc.mURI->GetSpecOrDefault().get(),
-                                     NS_ConvertUTF16toUTF8(mFamilyName).get()));
-                            }
-                            return;
-                        } else {
-                            mFontSet->LogMessage(this,
-                                                 "download failed",
-                                                 nsIScriptError::errorFlag,
-                                                 rv);
-                        }
+                        mFontSet->LogMessage(this,
+                                             "download failed",
+                                             nsIScriptError::errorFlag,
+                                             rv);
                     }
-                } else {
-                    mFontSet->LogMessage(this, "download not allowed",
-                                         nsIScriptError::errorFlag, rv);
                 }
             } else {
                 // We don't log a warning to the web console yet,
                 // as another source may load successfully
                 mUnsupportedFormat = true;
             }
         }
 
@@ -932,18 +924,16 @@ gfxUserFontSet::gfxUserFontSet()
 }
 
 gfxUserFontSet::~gfxUserFontSet()
 {
     gfxPlatformFontList* fp = gfxPlatformFontList::PlatformFontList();
     if (fp) {
         fp->RemoveUserFontSet(this);
     }
-
-    UserFontCache::ClearAllowedFontSets(this);
 }
 
 already_AddRefed<gfxUserFontEntry>
 gfxUserFontSet::FindOrCreateUserFontEntry(
                                const nsAString& aFamilyName,
                                const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList,
                                uint32_t aWeight,
                                int32_t aStretch,
@@ -1287,176 +1277,60 @@ gfxUserFontSet::UserFontCache::ForgetFon
 
 #ifdef DEBUG_USERFONT_CACHE
     printf("userfontcache removed fontentry: %p\n", aFontEntry);
     Dump();
 #endif
 }
 
 gfxFontEntry*
-gfxUserFontSet::UserFontCache::GetFont(gfxFontSrcURI* aSrcURI,
-                                       gfxFontSrcPrincipal* aPrincipal,
-                                       gfxUserFontEntry* aUserFontEntry,
-                                       bool aPrivate)
+gfxUserFontSet::UserFontCache::GetFont(const gfxFontFaceSrc& aSrc,
+                                       const gfxUserFontEntry& aUserFontEntry)
 {
     if (!sUserFonts ||
+        aUserFontEntry.mFontSet->BypassCache() ||
         Preferences::GetBool("gfx.downloadable_fonts.disable_cache")) {
         return nullptr;
     }
 
     // Ignore principal when looking up a data: URI.
-    gfxFontSrcPrincipal* principal;
-    if (IgnorePrincipal(aSrcURI)) {
-        principal = nullptr;
-    } else {
-        principal = aPrincipal;
-    }
+    gfxFontSrcPrincipal* principal = IgnorePrincipal(aSrc.mURI)
+      ? nullptr
+      : aSrc.LoadPrincipal(*aUserFontEntry.mFontSet);
 
-    Entry* entry = sUserFonts->GetEntry(Key(aSrcURI, principal, aUserFontEntry,
-                                            aPrivate));
+    Entry* entry = sUserFonts->GetEntry(
+      Key(aSrc.mURI,
+          principal,
+          const_cast<gfxUserFontEntry*>(&aUserFontEntry),
+          aUserFontEntry.mFontSet->GetPrivateBrowsing()));
     if (!entry) {
         return nullptr;
     }
 
     // We have to perform another content policy check here to prevent
     // cache poisoning. E.g. a.com loads a font into the cache but
     // b.com has a CSP not allowing any fonts to be loaded.
-    bool allowed = false;
-    if (ServoStyleSet::IsInServoTraversal()) {
-        // Use the cached IsFontLoadAllowed results in mAllowedFontSets.
-        allowed = entry->CheckIsFontSetAllowedAndDispatchViolations(
-            aUserFontEntry->mFontSet);
-    } else {
-        // Call IsFontLoadAllowed directly, since we are on the main thread.
-        MOZ_ASSERT(NS_IsMainThread());
-        nsIPrincipal* principal = aPrincipal ? aPrincipal->get() : nullptr;
-        allowed = aUserFontEntry->mFontSet->IsFontLoadAllowed(
-            aSrcURI->get(),
-            principal,
-            /* aViolations */ nullptr);
-        MOZ_ASSERT(!entry->IsFontSetAllowedKnown(aUserFontEntry->mFontSet) ||
-                   entry->CheckIsFontSetAllowed(aUserFontEntry->mFontSet) == allowed,
-                   "why does IsFontLoadAllowed return a different value from "
-                   "the cached value in mAllowedFontSets?");
-    }
-
-    if (!allowed) {
+    if (!aUserFontEntry.mFontSet->IsFontLoadAllowed(aSrc)) {
         return nullptr;
     }
 
     return entry->GetFontEntry();
 }
 
-/* static */ void
-gfxUserFontSet::UserFontCache::UpdateAllowedFontSets(
-    gfxUserFontSet* aUserFontSet)
-{
-    MOZ_ASSERT(NS_IsMainThread());
-
-    if (!sUserFonts) {
-        return;
-    }
-
-    for (auto iter = sUserFonts->Iter(); !iter.Done(); iter.Next()) {
-        Entry* entry = iter.Get();
-        if (!entry->IsFontSetAllowedKnown(aUserFontSet)) {
-            gfxFontSrcPrincipal* principal = entry->GetPrincipal();
-            if (!principal) {
-                // This is a data: URI.  Just get the standard principal the
-                // font set uses.  (For cases when mUseOriginPrincipal is true,
-                // we don't use the cached results of IsFontLoadAllowed, and
-                // instead just process the data: URI load async.)
-                principal = aUserFontSet->GetStandardFontLoadPrincipal();
-            }
-            nsTArray<nsCOMPtr<nsIRunnable>> violations;
-            bool allowed =
-                aUserFontSet->IsFontLoadAllowed(entry->GetURI()->get(),
-                                                principal->get(),
-                                                &violations);
-            entry->SetIsFontSetAllowed(aUserFontSet, allowed, Move(violations));
-        }
-    }
-}
-
-/* static */ void
-gfxUserFontSet::UserFontCache::ClearAllowedFontSets(
-    gfxUserFontSet* aUserFontSet)
-{
-    MOZ_ASSERT(NS_IsMainThread());
-
-    if (!sUserFonts) {
-        return;
-    }
-
-    for (auto iter = sUserFonts->Iter(); !iter.Done(); iter.Next()) {
-        Entry* entry = iter.Get();
-        entry->ClearIsFontSetAllowed(aUserFontSet);
-    }
-}
-
 void
 gfxUserFontSet::UserFontCache::Shutdown()
 {
     if (sUserFonts) {
         delete sUserFonts;
         sUserFonts = nullptr;
     }
 }
 
 MOZ_DEFINE_MALLOC_SIZE_OF(UserFontsMallocSizeOf)
 
-bool
-gfxUserFontSet::UserFontCache::Entry::CheckIsFontSetAllowed(
-    gfxUserFontSet* aUserFontSet) const
-{
-    LoadResultEntry* entry = mAllowedFontSets.GetEntry(aUserFontSet);
-    MOZ_ASSERT(entry, "UpdateAllowedFontSets should have been called and "
-                      "added an entry to mAllowedFontSets");
-    return entry->mAllowed;
-}
-
-bool
-gfxUserFontSet::UserFontCache::Entry::CheckIsFontSetAllowedAndDispatchViolations(
-    gfxUserFontSet* aUserFontSet) const
-{
-    LoadResultEntry* entry = mAllowedFontSets.GetEntry(aUserFontSet);
-    MOZ_ASSERT(entry, "UpdateAllowedFontSets should have been called and "
-                      "added an entry to mAllowedFontSets");
-    if (!entry->mViolations.IsEmpty()) {
-        aUserFontSet->DispatchFontLoadViolations(entry->mViolations);
-    }
-    return entry->mAllowed;
-}
-
-bool
-gfxUserFontSet::UserFontCache::Entry::IsFontSetAllowedKnown(
-    gfxUserFontSet* aUserFontSet) const
-{
-    return mAllowedFontSets.Contains(aUserFontSet);
-}
-
-void
-gfxUserFontSet::UserFontCache::Entry::SetIsFontSetAllowed(
-    gfxUserFontSet* aUserFontSet,
-    bool aAllowed,
-    nsTArray<nsCOMPtr<nsIRunnable>>&& aViolations)
-{
-    MOZ_ASSERT(!IsFontSetAllowedKnown(aUserFontSet));
-    LoadResultEntry* entry = mAllowedFontSets.PutEntry(aUserFontSet);
-    entry->mAllowed = aAllowed;
-    entry->mViolations.SwapElements(aViolations);
-}
-
-void
-gfxUserFontSet::UserFontCache::Entry::ClearIsFontSetAllowed(
-    gfxUserFontSet* aUserFontSet)
-{
-    mAllowedFontSets.RemoveEntry(aUserFontSet);
-}
-
 void
 gfxUserFontSet::UserFontCache::Entry::ReportMemory(
     nsIHandleReportCallback* aHandleReport, nsISupports* aData, bool aAnonymize)
 {
     MOZ_ASSERT(mFontEntry);
     nsAutoCString path("explicit/gfx/user-fonts/font(");
 
     if (aAnonymize) {
--- a/gfx/thebes/gfxUserFontSet.h
+++ b/gfx/thebes/gfxUserFontSet.h
@@ -58,16 +58,20 @@ struct gfxFontFaceSrc {
 
     nsString               mLocalName;     // full font name if local
     RefPtr<gfxFontSrcURI>  mURI;           // uri if url
     nsCOMPtr<nsIURI>       mReferrer;      // referrer url if url
     mozilla::net::ReferrerPolicy mReferrerPolicy;
     RefPtr<gfxFontSrcPrincipal> mOriginPrincipal; // principal if url
 
     RefPtr<gfxFontFaceBufferSource> mBuffer;
+
+    // The principal that should be used for the load. Should only be used for
+    // URL sources.
+    gfxFontSrcPrincipal* LoadPrincipal(const gfxUserFontSet&) const;
 };
 
 inline bool
 operator==(const gfxFontFaceSrc& a, const gfxFontFaceSrc& b)
 {
     // The mReferrer and mOriginPrincipal comparisons aren't safe OMT.
     MOZ_ASSERT(NS_IsMainThread());
 
@@ -260,29 +264,20 @@ public:
 
     // Look up and return the gfxUserFontFamily in mFontFamilies with
     // the given name
     gfxUserFontFamily* LookupFamily(const nsAString& aName) const;
 
     // Look up names in a fontlist and return true if any are in the set
     bool ContainsUserFontSetFonts(const mozilla::FontFamilyList& aFontList) const;
 
-    // check whether the given source is allowed to be loaded;
-    // returns the Principal (for use in the key when caching the loaded font),
-    // and whether the load should bypass the cache (force-reload).
-    virtual nsresult CheckFontLoad(const gfxFontFaceSrc* aFontFaceSrc,
-                                   gfxFontSrcPrincipal** aPrincipal,
-                                   bool* aBypassCache) = 0;
-
-    virtual gfxFontSrcPrincipal* GetStandardFontLoadPrincipal() = 0;
+    virtual gfxFontSrcPrincipal* GetStandardFontLoadPrincipal() const = 0;
 
     // check whether content policies allow the given URI to load.
-    virtual bool IsFontLoadAllowed(nsIURI* aFontLocation,
-                                   nsIPrincipal* aPrincipal,
-                                   nsTArray<nsCOMPtr<nsIRunnable>>* aViolations) = 0;
+    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
@@ -315,44 +310,22 @@ public:
         // refers to it.
         static void ForgetFont(gfxFontEntry* aFontEntry);
 
         // Return the gfxFontEntry corresponding to a given URI and principal,
         // and the features of the given userfont entry, or nullptr if none is available.
         // 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(gfxFontSrcURI* aSrcURI,
-                                     gfxFontSrcPrincipal* aPrincipal,
-                                     gfxUserFontEntry* aUserFontEntry,
-                                     bool              aPrivate);
+        static gfxFontEntry* GetFont(const gfxFontFaceSrc&, const gfxUserFontEntry&);
 
         // Generation number that is incremented whenever an entry is added to
         // the cache.  (Removals don't increment it.)
         static uint32_t Generation() { return sGeneration; }
 
-        // For each entry in the user font cache where we haven't recorded
-        // whether the given user font set is allowed to use the entry,
-        // call IsFontLoadAllowed and record it.
-        //
-        // This function should be called just before a Servo restyle, so
-        // that we can determine whether a given font load (using a cached
-        // font) would be allowed without having to call the non-OMT-safe
-        // IsFontLoadAllowed from the style worker threads.
-        static void UpdateAllowedFontSets(gfxUserFontSet* aUserFontSet);
-
-        // Clears all recorded IsFontLoadAllowed results for the given
-        // user font set.
-        //
-        // This function should be called just before the user font set is
-        // going away, or when we detect that a document's node principal
-        // has changed (and thus the already recorded IsFontLoadAllowed
-        // results are no longer valid).
-        static void ClearAllowedFontSets(gfxUserFontSet* aUserFontSet);
-
         // Clear everything so that we don't leak URIs and Principals.
         static void Shutdown();
 
         // Memory-reporting support.
         class MemoryReporter final : public nsIMemoryReporter
         {
         private:
             ~MemoryReporter() { }
@@ -410,21 +383,20 @@ public:
             explicit Entry(KeyTypePointer aKey)
                 : mURI(aKey->mURI),
                   mPrincipal(aKey->mPrincipal),
                   mFontEntry(aKey->mFontEntry),
                   mPrivate(aKey->mPrivate)
             { }
 
             Entry(Entry&& aOther)
-                : mAllowedFontSets(mozilla::Move(aOther.mAllowedFontSets)),
-                  mURI(mozilla::Move(aOther.mURI)),
-                  mPrincipal(mozilla::Move(aOther.mPrincipal)),
-                  mFontEntry(mozilla::Move(aOther.mFontEntry)),
-                  mPrivate(mozilla::Move(aOther.mPrivate))
+                : mURI(mozilla::Move(aOther.mURI))
+                , mPrincipal(mozilla::Move(aOther.mPrincipal))
+                , mFontEntry(mozilla::Move(aOther.mFontEntry))
+                , mPrivate(mozilla::Move(aOther.mPrivate))
             { }
 
             ~Entry() { }
 
             bool KeyEquals(const KeyTypePointer aKey) const;
 
             static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
 
@@ -444,24 +416,16 @@ public:
 
             enum { ALLOW_MEMMOVE = false };
 
             gfxFontSrcURI* GetURI() const { return mURI; }
             gfxFontSrcPrincipal* GetPrincipal() const { return mPrincipal; }
             gfxFontEntry* GetFontEntry() const { return mFontEntry; }
             bool IsPrivate() const { return mPrivate; }
 
-            bool CheckIsFontSetAllowed(gfxUserFontSet* aUserFontSet) const;
-            bool CheckIsFontSetAllowedAndDispatchViolations(gfxUserFontSet* aUserFontSet) const;
-            bool IsFontSetAllowedKnown(gfxUserFontSet* aUserFontSet) const;
-            void SetIsFontSetAllowed(gfxUserFontSet* aUserFontSet,
-                                     bool aAllowed,
-                                     nsTArray<nsCOMPtr<nsIRunnable>>&& aViolations);
-            void ClearIsFontSetAllowed(gfxUserFontSet* aUserFontSet);
-
             void ReportMemory(nsIHandleReportCallback* aHandleReport,
                               nsISupports* aData, bool aAnonymize);
 
 #ifdef DEBUG_USERFONT_CACHE
             void Dump();
 #endif
 
         private:
@@ -472,61 +436,16 @@ public:
             }
 
             static uint32_t
             HashVariations(const nsTArray<gfxFontVariation>& aVariations) {
                 return mozilla::HashBytes(aVariations.Elements(),
                                           aVariations.Length() * sizeof(gfxFontVariation));
             }
 
-            // An entry in mAllowedFontSets.
-            class LoadResultEntry : public nsPtrHashKey<gfxUserFontSet>
-            {
-            public:
-                explicit LoadResultEntry(KeyTypePointer aKey)
-                  : nsPtrHashKey(aKey)
-                  , mAllowed(false)
-                {
-                }
-
-                LoadResultEntry(LoadResultEntry&& aOther)
-                  : nsPtrHashKey(aOther.mKey)
-                  , mAllowed(aOther.mAllowed)
-                  , mViolations(mozilla::Move(aOther.mViolations))
-                {
-                }
-
-                ~LoadResultEntry() {}
-
-                // Whether the user font set (the key) is allowed to load this
-                // entry's font.
-                bool mAllowed;
-
-                // If the load is not allowed, the CSP violation reports that
-                // must be dispatched when we attempt to use the entry's font.
-                // (Should be empty if mAllowed is true.)
-                nsTArray<nsCOMPtr<nsIRunnable>> mViolations;
-
-                enum { ALLOW_MEMMOVE = false };
-            };
-
-            // Set of gfxUserFontSets that are allowed to use this cached font
-            // entry.
-            //
-            // This is basically a cache of results of calls to
-            // gfxUserFontSet::IsFontLoadAllowed for each font set to be used
-            // when using the cache from style worker threads (where calling
-            // IsFontLoadAllowed is not possible).  Whenever a new entry is
-            // added to the cache, sGeneration is bumped, and a FontFaceSet
-            // for a document about to be styled can call UpdateAllowedFontSets
-            // to record IsFontLoadAllowed results for the new entries.  When
-            // a FontFaceSet is going away, it calls ClearAllowedFontSets
-            // to remove entries from the mAllowedFontSets tables.
-            nsTHashtable<LoadResultEntry> mAllowedFontSets;
-
             RefPtr<gfxFontSrcURI>  mURI;
             RefPtr<gfxFontSrcPrincipal> mPrincipal; // or nullptr for data: URLs
 
             // The "real" font entry corresponding to this downloaded font.
             // The font entry MUST notify the cache when it is destroyed
             // (by calling ForgetFont()).
             gfxFontEntry* MOZ_NON_OWNING_REF mFontEntry;
 
@@ -556,16 +475,20 @@ public:
 
 protected:
     // Protected destructor, to discourage deletion outside of Release():
     virtual ~gfxUserFontSet();
 
     // Return whether the font set is associated with a private-browsing tab.
     virtual bool GetPrivateBrowsing() = 0;
 
+    // Return whether the font set is associated with a document that was
+    // shift-reloaded, for example, and thus should bypass the font cache.
+    virtual bool BypassCache() = 0;
+
     // parse data for a data URL
     virtual nsresult SyncLoadFontData(gfxUserFontEntry* aFontToLoad,
                                       const gfxFontFaceSrc* aFontFaceSrc,
                                       uint8_t* &aBuffer,
                                       uint32_t &aBufferLength) = 0;
 
     // report a problem of some kind (implemented in nsUserFontSet)
     virtual nsresult LogMessage(gfxUserFontEntry* aUserFontEntry,
@@ -699,16 +622,21 @@ public:
         MOZ_ASSERT_UNREACHABLE("cannot Clone user fonts");
         return nullptr;
     }
 
 #ifdef DEBUG
     gfxUserFontSet* GetUserFontSet() const { return mFontSet; }
 #endif
 
+    const nsTArray<gfxFontFaceSrc>& SourceList() const
+    {
+      return mSrcList;
+    }
+
 protected:
     const uint8_t* SanitizeOpenTypeData(const uint8_t* aData,
                                         uint32_t aLength,
                                         uint32_t& aSaneLength,
                                         gfxUserFontType aFontType);
 
     // attempt to load the next resource in the src list.
     void LoadNextSrc();
--- a/layout/style/FontFaceSet.cpp
+++ b/layout/style/FontFaceSet.cpp
@@ -99,28 +99,31 @@ NS_IMPL_RELEASE_INHERITED(FontFaceSet, D
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FontFaceSet)
   NS_INTERFACE_MAP_ENTRY(nsIDOMEventListener)
   NS_INTERFACE_MAP_ENTRY(nsICSSLoaderObserver)
 NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
 
 FontFaceSet::FontFaceSet(nsPIDOMWindowInner* aWindow, nsIDocument* aDocument)
   : DOMEventTargetHelper(aWindow)
   , mDocument(aDocument)
+  , mStandardFontLoadPrincipal(new gfxFontSrcPrincipal(mDocument->NodePrincipal()))
   , mResolveLazilyCreatedReadyPromise(false)
   , mStatus(FontFaceSetLoadStatus::Loaded)
   , mNonRuleFacesDirty(false)
   , mHasLoadingFontFaces(false)
   , mHasLoadingFontFacesIsDirty(false)
   , mDelayedLoadCheck(false)
   , mBypassCache(false)
   , mPrivateBrowsing(false)
-  , mHasStandardFontLoadPrincipalChanged(false)
 {
   MOZ_ASSERT(mDocument, "We should get a valid document from the caller!");
 
+  mStandardFontLoadPrincipal =
+    new gfxFontSrcPrincipal(mDocument->NodePrincipal());
+
   // If the pref is not set, don't create the Promise (which the page wouldn't
   // be able to get to anyway) as it causes the window.FontFaceSet constructor
   // to be created.
   if (aWindow && PrefEnabled()) {
     mResolveLazilyCreatedReadyPromise = true;
   }
 
   // Record the state of the "bypass cache" flags from the docshell now,
@@ -1323,84 +1326,76 @@ FontFaceSet::LogMessage(gfxUserFontEntry
                                      innerWindowID);
   if (NS_SUCCEEDED(rv)) {
     console->LogMessage(scriptError);
   }
 
   return NS_OK;
 }
 
-gfxFontSrcPrincipal*
-FontFaceSet::GetStandardFontLoadPrincipal()
+void
+FontFaceSet::CacheFontLoadability()
 {
-  if (!ServoStyleSet::IsInServoTraversal()) {
-    UpdateStandardFontLoadPrincipal();
+  if (!mUserFontSet) {
+    return;
   }
 
-  return mStandardFontLoadPrincipal;
+  // TODO(emilio): We could do it a bit more incrementally maybe?
+  for (auto iter = mUserFontSet->mFontFamilies.Iter(); !iter.Done(); iter.Next()) {
+    for (const gfxFontEntry* entry : iter.Data()->GetFontList()) {
+      if (!entry->mIsUserFontContainer) {
+        continue;
+      }
+
+      const auto& sourceList =
+        static_cast<const gfxUserFontEntry*>(entry)->SourceList();
+      for (const gfxFontFaceSrc& src : sourceList) {
+        if (src.mSourceType != gfxFontFaceSrc::eSourceType_URL) {
+          continue;
+        }
+        mAllowedFontLoads.LookupForAdd(&src).OrInsert([&] {
+          return IsFontLoadAllowed(src);
+        });
+      }
+    }
+  }
 }
 
-nsresult
-FontFaceSet::CheckFontLoad(const gfxFontFaceSrc* aFontFaceSrc,
-                           gfxFontSrcPrincipal** aPrincipal,
-                           bool* aBypassCache)
+bool
+FontFaceSet::IsFontLoadAllowed(const gfxFontFaceSrc& aSrc)
 {
-  NS_ASSERTION(aFontFaceSrc &&
-               aFontFaceSrc->mSourceType == gfxFontFaceSrc::eSourceType_URL,
-               "bad font face url passed to fontloader");
-
-  // check same-site origin
+  MOZ_ASSERT(aSrc.mSourceType == gfxFontFaceSrc::eSourceType_URL);
 
-  NS_ASSERTION(aFontFaceSrc->mURI, "null font uri");
-  if (!aFontFaceSrc->mURI)
-    return NS_ERROR_FAILURE;
-
-  // use document principal, original principal if flag set
-  // this enables user stylesheets to load font files via
-  // @font-face rules
-  *aPrincipal = GetStandardFontLoadPrincipal();
-
-  NS_ASSERTION(aFontFaceSrc->mOriginPrincipal,
-               "null origin principal in @font-face rule");
-  if (aFontFaceSrc->mUseOriginPrincipal) {
-    *aPrincipal = aFontFaceSrc->mOriginPrincipal;
+  if (ServoStyleSet::IsInServoTraversal()) {
+    bool* entry = mAllowedFontLoads.GetValue(&aSrc);
+    MOZ_DIAGNOSTIC_ASSERT(entry, "Missed an update?");
+    return entry ? *entry : false;
   }
 
-  *aBypassCache = mBypassCache;
-
-  return NS_OK;
-}
+  if (!mUserFontSet) {
+    return false;
+  }
 
-// @arg aPrincipal: generally this is mDocument->NodePrincipal() but
-// might also be the original principal which enables user stylesheets
-// to load font files via @font-face rules.
-bool
-FontFaceSet::IsFontLoadAllowed(nsIURI* aFontLocation,
-                               nsIPrincipal* aPrincipal,
-                               nsTArray<nsCOMPtr<nsIRunnable>>* aViolations)
-{
-  if (aViolations) {
-    mDocument->StartBufferingCSPViolations();
-  }
+  gfxFontSrcPrincipal* gfxPrincipal =
+    aSrc.mURI->InheritsSecurityContext()
+      ? nullptr : aSrc.LoadPrincipal(*mUserFontSet);
+
+  nsIPrincipal* principal = gfxPrincipal ? gfxPrincipal->get() : nullptr;
 
   int16_t shouldLoad = nsIContentPolicy::ACCEPT;
   nsresult rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_FONT,
-                                          aFontLocation,
-                                          aPrincipal, // loading principal
-                                          aPrincipal, // triggering principal
+                                          aSrc.mURI->get(),
+                                          principal, // loading principal
+                                          principal, // triggering principal
                                           mDocument,
                                           EmptyCString(), // mime type
                                           nullptr, // aExtra
                                           &shouldLoad,
                                           nsContentUtils::GetContentPolicy());
 
-  if (aViolations) {
-    mDocument->StopBufferingCSPViolations(*aViolations);
-  }
-
   return NS_SUCCEEDED(rv) && NS_CP_ACCEPTED(shouldLoad);
 }
 
 void
 FontFaceSet::DispatchFontLoadViolations(
     nsTArray<nsCOMPtr<nsIRunnable>>& aViolations)
 {
   if (XRE_IsContentProcess()) {
@@ -1825,63 +1820,33 @@ FontFaceSet::GetPresContext()
   if (!mDocument) {
     return nullptr;
   }
 
   return mDocument->GetPresContext();
 }
 
 void
-FontFaceSet::UpdateStandardFontLoadPrincipal()
+FontFaceSet::RefreshStandardFontLoadPrincipal()
 {
   MOZ_ASSERT(NS_IsMainThread());
-
-  nsIPrincipal* documentPrincipal = mDocument->NodePrincipal();
-
-  if (!mStandardFontLoadPrincipal ||
-      mStandardFontLoadPrincipal->get() != documentPrincipal) {
-    if (mStandardFontLoadPrincipal) {
-      mHasStandardFontLoadPrincipalChanged = true;
-    }
-    mStandardFontLoadPrincipal = new gfxFontSrcPrincipal(documentPrincipal);
+  mStandardFontLoadPrincipal =
+    new gfxFontSrcPrincipal(mDocument->NodePrincipal());
+  mAllowedFontLoads.Clear();
+  if (mUserFontSet) {
+    mUserFontSet->IncrementGeneration(false);
   }
 }
 
 // -- FontFaceSet::UserFontSet ------------------------------------------------
 
-/* virtual */ nsresult
-FontFaceSet::UserFontSet::CheckFontLoad(const gfxFontFaceSrc* aFontFaceSrc,
-                                        gfxFontSrcPrincipal** aPrincipal,
-                                        bool* aBypassCache)
-{
-  if (!mFontFaceSet) {
-    return NS_ERROR_FAILURE;
-  }
-  return mFontFaceSet->CheckFontLoad(aFontFaceSrc, aPrincipal, aBypassCache);
-}
-
-/* virtual */ gfxFontSrcPrincipal*
-FontFaceSet::UserFontSet::GetStandardFontLoadPrincipal()
+/* virtual */ bool
+FontFaceSet::UserFontSet::IsFontLoadAllowed(const gfxFontFaceSrc& aSrc)
 {
-  if (!mFontFaceSet) {
-    return nullptr;
-  }
-  return mFontFaceSet->GetStandardFontLoadPrincipal();
-}
-
-/* virtual */ bool
-FontFaceSet::UserFontSet::IsFontLoadAllowed(
-    nsIURI* aFontLocation,
-    nsIPrincipal* aPrincipal,
-    nsTArray<nsCOMPtr<nsIRunnable>>* aViolations)
-{
-  return mFontFaceSet &&
-         mFontFaceSet->IsFontLoadAllowed(aFontLocation,
-                                         aPrincipal,
-                                         aViolations);
+  return mFontFaceSet && mFontFaceSet->IsFontLoadAllowed(aSrc);
 }
 
 /* virtual */ void
 FontFaceSet::UserFontSet::DispatchFontLoadViolations(
     nsTArray<nsCOMPtr<nsIRunnable>>& aViolations)
 {
   if (mFontFaceSet) {
     mFontFaceSet->DispatchFontLoadViolations(aViolations);
--- a/layout/style/FontFaceSet.h
+++ b/layout/style/FontFaceSet.h
@@ -58,36 +58,37 @@ public:
   public:
     explicit UserFontSet(FontFaceSet* aFontFaceSet)
       : mFontFaceSet(aFontFaceSet)
     {
     }
 
     FontFaceSet* GetFontFaceSet() { return mFontFaceSet; }
 
-    gfxFontSrcPrincipal* GetStandardFontLoadPrincipal() override;
+    gfxFontSrcPrincipal* GetStandardFontLoadPrincipal() const final
+    {
+      return mFontFaceSet ? mFontFaceSet->mStandardFontLoadPrincipal.get() : nullptr;
+    }
 
-    virtual nsresult CheckFontLoad(const gfxFontFaceSrc* aFontFaceSrc,
-                                   gfxFontSrcPrincipal** aPrincipal,
-                                   bool* aBypassCache) override;
-
-    virtual bool IsFontLoadAllowed(nsIURI* aFontLocation,
-                                   nsIPrincipal* aPrincipal,
-                                   nsTArray<nsCOMPtr<nsIRunnable>>* aViolations)
-                                     override;
+    bool IsFontLoadAllowed(const gfxFontFaceSrc&) final;
 
     void DispatchFontLoadViolations(
 		  nsTArray<nsCOMPtr<nsIRunnable>>& aViolations) override;
 
     virtual nsresult StartLoad(gfxUserFontEntry* aUserFontEntry,
                                const gfxFontFaceSrc* aFontFaceSrc) override;
 
     void RecordFontLoadDone(uint32_t aFontSize,
                             mozilla::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,
                                 const char* aMessage,
@@ -167,24 +168,17 @@ public:
   void FlushUserFontSet();
 
   static nsPresContext* GetPresContextFor(gfxUserFontSet* aUserFontSet)
   {
     FontFaceSet* set = static_cast<UserFontSet*>(aUserFontSet)->mFontFaceSet;
     return set ? set->GetPresContext() : nullptr;
   }
 
-  void UpdateStandardFontLoadPrincipal();
-
-  bool HasStandardFontLoadPrincipalChanged()
-  {
-    bool changed = mHasStandardFontLoadPrincipalChanged;
-    mHasStandardFontLoadPrincipalChanged = false;
-    return changed;
-  }
+  void RefreshStandardFontLoadPrincipal();
 
   nsIDocument* Document() const { return mDocument; }
 
   // -- Web IDL --------------------------------------------------------------
 
   IMPL_EVENT_HANDLER(loading)
   IMPL_EVENT_HANDLER(loadingdone)
   IMPL_EVENT_HANDLER(loadingerror)
@@ -204,16 +198,19 @@ public:
   bool Has(FontFace& aFontFace);
   uint32_t Size();
   already_AddRefed<mozilla::dom::FontFaceSetIterator> Entries();
   already_AddRefed<mozilla::dom::FontFaceSetIterator> Values();
   void ForEach(JSContext* aCx, FontFaceSetForEachCallback& aCallback,
                JS::Handle<JS::Value> aThisArg,
                mozilla::ErrorResult& aRv);
 
+  // For ServoStyleSet to know ahead of time whether a font is loadable.
+  void CacheFontLoadability();
+
 private:
   ~FontFaceSet();
 
   /**
    * Returns whether the given FontFace is currently "in" the FontFaceSet.
    */
   bool HasAvailableFontFace(FontFace* aFontFace);
 
@@ -277,19 +274,18 @@ private:
   nsCSSFontFaceRule* FindRuleForUserFontEntry(gfxUserFontEntry* aUserFontEntry);
 
   nsresult StartLoad(gfxUserFontEntry* aUserFontEntry,
                      const gfxFontFaceSrc* aFontFaceSrc);
   gfxFontSrcPrincipal* GetStandardFontLoadPrincipal();
   nsresult CheckFontLoad(const gfxFontFaceSrc* aFontFaceSrc,
                          gfxFontSrcPrincipal** aPrincipal,
                          bool* aBypassCache);
-  bool IsFontLoadAllowed(nsIURI* aFontLocation,
-                         nsIPrincipal* aPrincipal,
-                         nsTArray<nsCOMPtr<nsIRunnable>>* aViolations);
+  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,
                       const char* aMessage,
                       uint32_t aFlags,
@@ -337,21 +333,20 @@ private:
 
   // The document's node principal, which is the principal font loads for
   // this FontFaceSet will generally use.  (This principal is not used for
   // @font-face rules in UA and user sheets, where the principal of the
   // sheet is used instead.)
   //
   // This field is used from GetStandardFontLoadPrincipal.  When on a
   // style worker thread, we use mStandardFontLoadPrincipal assuming
-  // it is up to date.  Because mDocument's principal can change over time,
-  // its value must be updated by a call to UpdateStandardFontLoadPrincipal
-  // before a restyle.  (When called while on the main thread,
-  // GetStandardFontLoadPrincipal will call UpdateStandardFontLoadPrincipal
-  // to ensure its value is up to date.)
+  // it is up to date.
+  //
+  // Because mDocument's principal can change over time,
+  // its value must be updated by a call to ResetStandardFontLoadPrincipal.
   RefPtr<gfxFontSrcPrincipal> mStandardFontLoadPrincipal;
 
   // A Promise that is fulfilled once all of the FontFace objects
   // in mRuleFaces and mNonRuleFaces that started or were loading at the
   // time the Promise was created have finished loading.  It is rejected if
   // any of those fonts failed to load.  mReady is replaced with
   // a new Promise object whenever mReady is settled and another
   // FontFace in mRuleFaces or mNonRuleFaces starts to load.
@@ -370,16 +365,24 @@ private:
 
   // The non rule backed FontFace objects that have been added to this
   // FontFaceSet.
   nsTArray<FontFaceRecord> mNonRuleFaces;
 
   // The overall status of the loading or loaded fonts in the FontFaceSet.
   mozilla::dom::FontFaceSetLoadStatus mStatus;
 
+  // A map from gfxFontFaceSrc pointer identity to whether the load is allowed
+  // by CSP or other checks. We store this here because querying CSP off the
+  // main thread is not a great idea.
+  //
+  // We could use just the pointer and use this as a hash set, but then we'd
+  // have no way to verify that we've checked all the loads we should.
+  nsDataHashtable<nsPtrHashKey<const gfxFontFaceSrc>, bool> mAllowedFontLoads;
+
   // Whether mNonRuleFaces has changed since last time UpdateRules ran.
   bool mNonRuleFacesDirty;
 
   // Whether any FontFace objects in mRuleFaces or mNonRuleFaces are
   // loading.  Only valid when mHasLoadingFontFacesIsDirty is false.  Don't use
   // this variable directly; call the HasLoadingFontFaces method instead.
   bool mHasLoadingFontFaces;
 
@@ -392,18 +395,14 @@ private:
 
   // Whether the docshell for our document indicated that loads should
   // bypass the cache.
   bool mBypassCache;
 
   // Whether the docshell for our document indicates that we are in private
   // browsing mode.
   bool mPrivateBrowsing;
-
-  // Whether mStandardFontLoadPrincipal has changed since the last call to
-  // HasStandardFontLoadPrincipalChanged.
-  bool mHasStandardFontLoadPrincipalChanged;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // !defined(mozilla_dom_FontFaceSet_h)
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -97,17 +97,16 @@ private:
 
 } // namespace mozilla
 
 ServoStyleSet::ServoStyleSet()
   : mDocument(nullptr)
   , mAuthorStyleDisabled(false)
   , mStylistState(StylistState::NotDirty)
   , mUserFontSetUpdateGeneration(0)
-  , mUserFontCacheUpdateGeneration(0)
   , mNeedsRestyleAfterEnsureUniqueInner(false)
 {
 }
 
 ServoStyleSet::~ServoStyleSet()
 {
   for (auto& sheetArray : mSheets) {
     for (auto& sheet : sheetArray) {
@@ -460,36 +459,20 @@ ServoStyleSet::PreTraverseSync()
 
   nsPresContext* presContext = GetPresContext();
   MOZ_ASSERT(presContext,
              "For now, we don't call into here without a pres context");
   if (gfxUserFontSet* userFontSet = mDocument->GetUserFontSet()) {
     // Ensure that the @font-face data is not stale
     uint64_t generation = userFontSet->GetGeneration();
     if (generation != mUserFontSetUpdateGeneration) {
+      mDocument->GetFonts()->CacheFontLoadability();
       presContext->DeviceContext()->UpdateFontCacheUserFonts(userFontSet);
       mUserFontSetUpdateGeneration = generation;
     }
-
-    // Ensure that the FontFaceSet's cached document principal is up to date.
-    FontFaceSet* fontFaceSet =
-      static_cast<FontFaceSet::UserFontSet*>(userFontSet)->GetFontFaceSet();
-    fontFaceSet->UpdateStandardFontLoadPrincipal();
-    bool principalChanged = fontFaceSet->HasStandardFontLoadPrincipalChanged();
-
-    // Ensure that the user font cache holds up-to-date data on whether
-    // our font set is allowed to re-use fonts from the cache.
-    uint32_t cacheGeneration = gfxUserFontSet::UserFontCache::Generation();
-    if (principalChanged) {
-      gfxUserFontSet::UserFontCache::ClearAllowedFontSets(userFontSet);
-    }
-    if (cacheGeneration != mUserFontCacheUpdateGeneration || principalChanged) {
-      gfxUserFontSet::UserFontCache::UpdateAllowedFontSets(userFontSet);
-      mUserFontCacheUpdateGeneration = cacheGeneration;
-    }
   }
 
   MOZ_ASSERT(!StylistNeedsUpdate());
   presContext->CacheAllLangs();
 }
 
 void
 ServoStyleSet::PreTraverse(ServoTraversalFlags aFlags, Element* aRoot)
--- a/layout/style/ServoStyleSet.h
+++ b/layout/style/ServoStyleSet.h
@@ -578,17 +578,16 @@ private:
   nsPresContext* GetPresContext();
 
   UniquePtr<RawServoStyleSet> mRawSet;
   EnumeratedArray<SheetType, SheetType::Count,
                   nsTArray<RefPtr<ServoStyleSheet>>> mSheets;
   bool mAuthorStyleDisabled;
   StylistState mStylistState;
   uint64_t mUserFontSetUpdateGeneration;
-  uint32_t mUserFontCacheUpdateGeneration;
 
   bool mNeedsRestyleAfterEnsureUniqueInner;
 
   // Stores pointers to our cached ComputedStyles for non-inheriting anonymous
   // boxes.
   EnumeratedArray<nsCSSAnonBoxes::NonInheriting,
                   nsCSSAnonBoxes::NonInheriting::_Count,
                   RefPtr<ComputedStyle>> mNonInheritingComputedStyles;