From 417725510764c2eca7e9738e10d14eeceaa90e30 Mon Sep 17 00:00:00 2001 From: "Carsten \"Tomcat\" Book" Date: Wed, 12 Jul 2017 12:41:25 +0200 Subject: [PATCH] Backed out changeset 041b34959d76 (bug 1376964) --- gfx/thebes/gfxUserFontSet.cpp | 25 ++++++++++---------- gfx/thebes/gfxUserFontSet.h | 29 +++++++++++------------ layout/style/FontFaceSet.cpp | 42 +++++++--------------------------- layout/style/FontFaceSet.h | 36 ++++------------------------- layout/style/ServoStyleSet.cpp | 12 +--------- 5 files changed, 41 insertions(+), 103 deletions(-) diff --git a/gfx/thebes/gfxUserFontSet.cpp b/gfx/thebes/gfxUserFontSet.cpp index 0aaa86a5bde7..ad3c3b55e76f 100644 --- a/gfx/thebes/gfxUserFontSet.cpp +++ b/gfx/thebes/gfxUserFontSet.cpp @@ -540,7 +540,7 @@ gfxUserFontEntry::DoLoadNextSrc(bool aForceAsync) return; } - gfxFontSrcPrincipal* principal = nullptr; + nsIPrincipal* principal = nullptr; bool bypassCache; nsresult rv = mFontSet->CheckFontLoad(&currSrc, &principal, &bypassCache); @@ -1155,7 +1155,9 @@ 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"); - if (!mPrincipal->Equals(aKey->mPrincipal)) { + bool result; + if (NS_FAILED(mPrincipal->Equals(aKey->mPrincipal, &result)) || + !result) { return false; } } @@ -1220,7 +1222,7 @@ gfxUserFontSet::UserFontCache::CacheFont(gfxFontEntry* aFontEntry) // For data: URIs, the principal is ignored; anyone who has the same // data: URI is able to load it and get an equivalent font. // Otherwise, the principal is used as part of the cache key. - gfxFontSrcPrincipal* principal; + nsIPrincipal* principal; if (IgnorePrincipal(data->mURI)) { principal = nullptr; } else { @@ -1263,7 +1265,7 @@ gfxUserFontSet::UserFontCache::ForgetFont(gfxFontEntry* aFontEntry) gfxFontEntry* gfxUserFontSet::UserFontCache::GetFont(gfxFontSrcURI* aSrcURI, - gfxFontSrcPrincipal* aPrincipal, + nsIPrincipal* aPrincipal, gfxUserFontEntry* aUserFontEntry, bool aPrivate) { @@ -1273,7 +1275,7 @@ gfxUserFontSet::UserFontCache::GetFont(gfxFontSrcURI* aSrcURI, } // Ignore principal when looking up a data: URI. - gfxFontSrcPrincipal* principal; + nsIPrincipal* principal; if (IgnorePrincipal(aSrcURI)) { principal = nullptr; } else { @@ -1296,9 +1298,8 @@ gfxUserFontSet::UserFontCache::GetFont(gfxFontSrcURI* aSrcURI, } 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); + aPrincipal); MOZ_ASSERT(!entry->IsFontSetAllowedKnown(aUserFontEntry->mFontSet) || entry->IsFontSetAllowed(aUserFontEntry->mFontSet) == allowed, "why does IsFontLoadAllowed return a different value from " @@ -1325,7 +1326,7 @@ gfxUserFontSet::UserFontCache::UpdateAllowedFontSets( for (auto iter = sUserFonts->Iter(); !iter.Done(); iter.Next()) { Entry* entry = iter.Get(); if (!entry->IsFontSetAllowedKnown(aUserFontSet)) { - gfxFontSrcPrincipal* principal = entry->GetPrincipal(); + nsIPrincipal* 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, @@ -1335,7 +1336,7 @@ gfxUserFontSet::UserFontCache::UpdateAllowedFontSets( } bool allowed = aUserFontSet->IsFontLoadAllowed(entry->GetURI()->get(), - principal->get()); + principal); entry->SetIsFontSetAllowed(aUserFontSet, allowed); } } @@ -1429,7 +1430,7 @@ gfxUserFontSet::UserFontCache::Entry::ReportMemory( } if (mPrincipal) { nsCOMPtr uri; - mPrincipal->get()->GetURI(getter_AddRefs(uri)); + mPrincipal->GetURI(getter_AddRefs(uri)); if (uri) { nsCString spec = uri->GetSpecOrDefault(); if (!spec.IsEmpty()) { @@ -1489,13 +1490,13 @@ gfxUserFontSet::UserFontCache::Entry::Dump() if (mPrincipal) { nsCOMPtr principalURI; - rv = mPrincipal->get()->GetURI(getter_AddRefs(principalURI)); + rv = mPrincipal->GetURI(getter_AddRefs(principalURI)); if (NS_SUCCEEDED(rv)) { principalURI->GetSpec(principalURISpec); } nsCOMPtr domainURI; - mPrincipal->get()->GetDomain(getter_AddRefs(domainURI)); + mPrincipal->GetDomain(getter_AddRefs(domainURI)); if (domainURI) { setDomain = true; } diff --git a/gfx/thebes/gfxUserFontSet.h b/gfx/thebes/gfxUserFontSet.h index c0bf2a3a4247..58b962b4f163 100644 --- a/gfx/thebes/gfxUserFontSet.h +++ b/gfx/thebes/gfxUserFontSet.h @@ -8,7 +8,6 @@ #include "gfxFont.h" #include "gfxFontFamilyList.h" -#include "gfxFontSrcPrincipal.h" #include "gfxFontSrcURI.h" #include "nsRefPtrHashtable.h" #include "nsCOMPtr.h" @@ -60,7 +59,7 @@ struct gfxFontFaceSrc { RefPtr mURI; // uri if url nsCOMPtr mReferrer; // referrer url if url mozilla::net::ReferrerPolicy mReferrerPolicy; - RefPtr mOriginPrincipal; // principal if url + nsCOMPtr mOriginPrincipal; // principal if url RefPtr mBuffer; }; @@ -113,7 +112,7 @@ public: nsTArray mMetadata; // woff metadata block (compressed), if any RefPtr mURI; // URI of the source, if it was url() - RefPtr mPrincipal; // principal for the download, if url() + nsCOMPtr 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 uint32_t mSrcIndex; // index in the rule's source list @@ -258,10 +257,10 @@ public: // 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, + nsIPrincipal** aPrincipal, bool* aBypassCache) = 0; - virtual gfxFontSrcPrincipal* GetStandardFontLoadPrincipal() = 0; + virtual nsIPrincipal* GetStandardFontLoadPrincipal() = 0; // check whether content policies allow the given URI to load. virtual bool IsFontLoadAllowed(nsIURI* aFontLocation, @@ -304,7 +303,7 @@ public: // so we can avoid leaking fonts cached in private windows mode out to // normal windows. static gfxFontEntry* GetFont(gfxFontSrcURI* aSrcURI, - gfxFontSrcPrincipal* aPrincipal, + nsIPrincipal* aPrincipal, gfxUserFontEntry* aUserFontEntry, bool aPrivate); @@ -370,13 +369,13 @@ public: // entry and the corresponding "real" font entry. struct Key { RefPtr mURI; - RefPtr mPrincipal; // use nullptr with data: URLs + nsCOMPtr 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(gfxFontSrcURI* aURI, gfxFontSrcPrincipal* aPrincipal, + Key(gfxFontSrcURI* aURI, nsIPrincipal* aPrincipal, gfxFontEntry* aFontEntry, bool aPrivate) : mURI(aURI), mPrincipal(aPrincipal), @@ -411,8 +410,10 @@ public: static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; } static PLDHashNumber HashKey(const KeyTypePointer aKey) { - PLDHashNumber principalHash = - aKey->mPrincipal ? aKey->mPrincipal->Hash() : 0; + uint32_t principalHash = 0; + if (aKey->mPrincipal) { + aKey->mPrincipal->GetHashValue(&principalHash); + } return mozilla::HashGeneric(principalHash + int(aKey->mPrivate), aKey->mURI->Hash(), HashFeatures(aKey->mFontEntry->mFeatureSettings), @@ -426,7 +427,7 @@ public: enum { ALLOW_MEMMOVE = false }; gfxFontSrcURI* GetURI() const { return mURI; } - gfxFontSrcPrincipal* GetPrincipal() const { return mPrincipal; } + nsIPrincipal* GetPrincipal() const { return mPrincipal; } gfxFontEntry* GetFontEntry() const { return mFontEntry; } bool IsPrivate() const { return mPrivate; } @@ -464,7 +465,7 @@ public: nsDataHashtable, bool> mAllowedFontSets; RefPtr mURI; - RefPtr mPrincipal; // or nullptr for data: URLs + nsCOMPtr 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 @@ -628,7 +629,7 @@ public: // since we can't make that class a friend void SetLoader(nsFontFaceLoader* aLoader) { mLoader = aLoader; } nsFontFaceLoader* GetLoader() { return mLoader; } - gfxFontSrcPrincipal* GetPrincipal() { return mPrincipal; } + nsIPrincipal* GetPrincipal() { return mPrincipal; } uint32_t GetSrcIndex() { return mSrcIndex; } void GetFamilyNameAndURIForLogging(nsACString& aFamilyName, nsACString& aURI); @@ -707,7 +708,7 @@ protected: // methods of nsFontFaceLoader this reference is nulled out. nsFontFaceLoader* MOZ_NON_OWNING_REF mLoader; // current loader for this entry, if any gfxUserFontSet* mFontSet; // font-set which owns this userfont entry - RefPtr mPrincipal; + nsCOMPtr mPrincipal; }; diff --git a/layout/style/FontFaceSet.cpp b/layout/style/FontFaceSet.cpp index 651d2678838d..39dcfe0dbe54 100644 --- a/layout/style/FontFaceSet.cpp +++ b/layout/style/FontFaceSet.cpp @@ -7,7 +7,6 @@ #include "FontFaceSet.h" #include "gfxFontConstants.h" -#include "gfxFontSrcPrincipal.h" #include "gfxFontSrcURI.h" #include "mozilla/css/Declaration.h" #include "mozilla/css/Loader.h" @@ -110,7 +109,6 @@ FontFaceSet::FontFaceSet(nsPIDOMWindowInner* aWindow, nsIDocument* aDocument) , mDelayedLoadCheck(false) , mBypassCache(false) , mPrivateBrowsing(false) - , mHasStandardFontLoadPrincipalChanged(false) { MOZ_ASSERT(mDocument, "We should get a valid document from the caller!"); @@ -627,7 +625,6 @@ FontFaceSet::StartLoad(gfxUserFontEntry* aUserFontEntry, nsCOMPtr streamLoader; nsCOMPtr loadGroup(mDocument->GetDocumentLoadGroup()); - gfxFontSrcPrincipal* principal = aUserFontEntry->GetPrincipal(); nsCOMPtr channel; // Note we are calling NS_NewChannelWithTriggeringPrincipal() with both a @@ -637,7 +634,7 @@ FontFaceSet::StartLoad(gfxUserFontEntry* aUserFontEntry, rv = NS_NewChannelWithTriggeringPrincipal(getter_AddRefs(channel), aFontFaceSrc->mURI->get(), mDocument, - principal ? principal->get() : nullptr, + aUserFontEntry->GetPrincipal(), nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS, nsIContentPolicy::TYPE_FONT, loadGroup); @@ -1130,8 +1127,7 @@ FontFaceSet::FindOrCreateUserFontEntryFromFontFace(const nsAString& aFamilyName, URLValue* url = val.GetURLStructValue(); face->mReferrer = url->mExtraData->GetReferrer(); face->mReferrerPolicy = mDocument->GetReferrerPolicy(); - face->mOriginPrincipal = - new gfxFontSrcPrincipal(url->mExtraData->GetPrincipal()); + face->mOriginPrincipal = url->mExtraData->GetPrincipal(); NS_ASSERTION(face->mOriginPrincipal, "null origin principal in @font-face rule"); // agent and user stylesheets are treated slightly differently, @@ -1334,19 +1330,15 @@ FontFaceSet::LogMessage(gfxUserFontEntry* aUserFontEntry, return NS_OK; } -gfxFontSrcPrincipal* +nsIPrincipal* FontFaceSet::GetStandardFontLoadPrincipal() { - if (!ServoStyleSet::IsInServoTraversal()) { - UpdateStandardFontLoadPrincipal(); - } - - return mStandardFontLoadPrincipal; + return mDocument->NodePrincipal(); } nsresult FontFaceSet::CheckFontLoad(const gfxFontFaceSrc* aFontFaceSrc, - gfxFontSrcPrincipal** aPrincipal, + nsIPrincipal** aPrincipal, bool* aBypassCache) { NS_ASSERTION(aFontFaceSrc && @@ -1403,8 +1395,6 @@ FontFaceSet::SyncLoadFontData(gfxUserFontEntry* aFontToLoad, { nsresult rv; - gfxFontSrcPrincipal* principal = aFontToLoad->GetPrincipal(); - nsCOMPtr channel; // Note we are calling NS_NewChannelWithTriggeringPrincipal() with both a // node and a principal. This is because the document where the font is @@ -1416,7 +1406,7 @@ FontFaceSet::SyncLoadFontData(gfxUserFontEntry* aFontToLoad, rv = NS_NewChannelWithTriggeringPrincipal(getter_AddRefs(channel), aFontFaceSrc->mURI->get(), mDocument, - principal ? principal->get() : nullptr, + aFontToLoad->GetPrincipal(), nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_INHERITS, nsIContentPolicy::TYPE_FONT); @@ -1804,27 +1794,11 @@ FontFaceSet::GetPresContext() return shell ? shell->GetPresContext() : nullptr; } -void -FontFaceSet::UpdateStandardFontLoadPrincipal() -{ - MOZ_ASSERT(NS_IsMainThread()); - - nsIPrincipal* documentPrincipal = mDocument->NodePrincipal(); - - if (!mStandardFontLoadPrincipal || - mStandardFontLoadPrincipal->get() != documentPrincipal) { - if (mStandardFontLoadPrincipal) { - mHasStandardFontLoadPrincipalChanged = true; - } - mStandardFontLoadPrincipal = new gfxFontSrcPrincipal(documentPrincipal); - } -} - // -- FontFaceSet::UserFontSet ------------------------------------------------ /* virtual */ nsresult FontFaceSet::UserFontSet::CheckFontLoad(const gfxFontFaceSrc* aFontFaceSrc, - gfxFontSrcPrincipal** aPrincipal, + nsIPrincipal** aPrincipal, bool* aBypassCache) { if (!mFontFaceSet) { @@ -1833,7 +1807,7 @@ FontFaceSet::UserFontSet::CheckFontLoad(const gfxFontFaceSrc* aFontFaceSrc, return mFontFaceSet->CheckFontLoad(aFontFaceSrc, aPrincipal, aBypassCache); } -/* virtual */ gfxFontSrcPrincipal* +/* virtual */ nsIPrincipal* FontFaceSet::UserFontSet::GetStandardFontLoadPrincipal() { if (!mFontFaceSet) { diff --git a/layout/style/FontFaceSet.h b/layout/style/FontFaceSet.h index 051bd53d5a08..24beb90f777f 100644 --- a/layout/style/FontFaceSet.h +++ b/layout/style/FontFaceSet.h @@ -14,7 +14,6 @@ #include "nsICSSLoaderObserver.h" struct gfxFontFaceSrc; -class gfxFontSrcPrincipal; class gfxUserFontEntry; class nsFontFaceLoader; class nsIPrincipal; @@ -64,10 +63,10 @@ public: FontFaceSet* GetFontFaceSet() { return mFontFaceSet; } - gfxFontSrcPrincipal* GetStandardFontLoadPrincipal() override; + nsIPrincipal* GetStandardFontLoadPrincipal() override; virtual nsresult CheckFontLoad(const gfxFontFaceSrc* aFontFaceSrc, - gfxFontSrcPrincipal** aPrincipal, + nsIPrincipal** aPrincipal, bool* aBypassCache) override; virtual bool IsFontLoadAllowed(nsIURI* aFontLocation, @@ -167,15 +166,6 @@ public: return set ? set->GetPresContext() : nullptr; } - void UpdateStandardFontLoadPrincipal(); - - bool HasStandardFontLoadPrincipalChanged() - { - bool changed = mHasStandardFontLoadPrincipalChanged; - mHasStandardFontLoadPrincipalChanged = false; - return changed; - } - nsIDocument* Document() const { return mDocument; } // -- Web IDL -------------------------------------------------------------- @@ -273,9 +263,9 @@ private: nsresult StartLoad(gfxUserFontEntry* aUserFontEntry, const gfxFontFaceSrc* aFontFaceSrc); - gfxFontSrcPrincipal* GetStandardFontLoadPrincipal(); + nsIPrincipal* GetStandardFontLoadPrincipal(); nsresult CheckFontLoad(const gfxFontFaceSrc* aFontFaceSrc, - gfxFontSrcPrincipal** aPrincipal, + nsIPrincipal** aPrincipal, bool* aBypassCache); bool IsFontLoadAllowed(nsIURI* aFontLocation, nsIPrincipal* aPrincipal); nsresult SyncLoadFontData(gfxUserFontEntry* aFontToLoad, @@ -327,20 +317,6 @@ private: // The document this is a FontFaceSet for. nsCOMPtr mDocument; - // 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.) - RefPtr 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 @@ -389,10 +365,6 @@ private: // 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 diff --git a/layout/style/ServoStyleSet.cpp b/layout/style/ServoStyleSet.cpp index 1f183b355f51..22b0598e23f6 100644 --- a/layout/style/ServoStyleSet.cpp +++ b/layout/style/ServoStyleSet.cpp @@ -15,7 +15,6 @@ #include "mozilla/css/Loader.h" #include "mozilla/dom/AnonymousContent.h" #include "mozilla/dom/ChildIterator.h" -#include "mozilla/dom/FontFaceSet.h" #include "mozilla/dom/Element.h" #include "mozilla/dom/ElementInlines.h" #include "mozilla/RestyleManagerInlines.h" @@ -308,19 +307,10 @@ ServoStyleSet::PreTraverseSync() mUserFontSetUpdateGeneration = generation; } - // Ensure that the FontFaceSet's cached document principal is up to date. - FontFaceSet* fontFaceSet = - static_cast(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) { + if (cacheGeneration != mUserFontCacheUpdateGeneration) { gfxUserFontSet::UserFontCache::UpdateAllowedFontSets(userFontSet); mUserFontCacheUpdateGeneration = cacheGeneration; }