Bug 1425000 - Use a consistent window for CSP, etc. for FontFace loads. r=jfkthame, a=abillings
MozReview-Commit-ID: F2xhsgTBI1V
--- a/gfx/thebes/gfxUserFontSet.h
+++ b/gfx/thebes/gfxUserFontSet.h
@@ -674,16 +674,20 @@ public:
void GetFamilyNameAndURIForLogging(nsACString& aFamilyName,
nsACString& aURI);
gfxFontEntry* Clone() const override {
MOZ_ASSERT_UNREACHABLE("cannot Clone user fonts");
return nullptr;
}
+#ifdef DEBUG
+ gfxUserFontSet* GetUserFontSet() const { return mFontSet; }
+#endif
+
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/FontFace.cpp
+++ b/layout/style/FontFace.cpp
@@ -668,16 +668,21 @@ FontFace::SetUserFontEntry(gfxUserFontEn
if (mUserFontEntry) {
mUserFontEntry->mFontFaces.RemoveElement(this);
}
mUserFontEntry = static_cast<Entry*>(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");
+
// Our newly assigned user font entry might be in the process of or
// finished loading, so set our status accordingly. But only do so
// if we're not going "backwards" in status, which could otherwise
// happen in this case:
//
// new FontFace("ABC", "url(x)").load();
//
// where the SetUserFontEntry call (from the after-initialization
--- a/layout/style/FontFace.h
+++ b/layout/style/FontFace.h
@@ -90,16 +90,18 @@ public:
/**
* Returns whether this object is in the specified FontFaceSet.
*/
bool IsInFontFaceSet(FontFaceSet* aFontFaceSet) const;
void AddFontFaceSet(FontFaceSet* aFontFaceSet);
void RemoveFontFaceSet(FontFaceSet* aFontFaceSet);
+ FontFaceSet* GetPrimaryFontFaceSet() const { return mFontFaceSet; }
+
/**
* Gets the family name of the FontFace as a raw string (such as 'Times', as
* opposed to GetFamily, which returns a CSS-escaped string, such as
* '"Times"'). Returns whether a valid family name was available.
*/
bool GetFamilyName(nsString& aResult);
/**
--- a/layout/style/FontFaceSet.cpp
+++ b/layout/style/FontFaceSet.cpp
@@ -978,35 +978,37 @@ FontFaceSet::InsertRuleFontFace(FontFace
// Add the entry to the end of the list. If an existing userfont entry was
// returned by FindOrCreateUserFontEntryFromFontFace that was already stored
// on the family, gfxUserFontFamily::AddFontEntry(), which AddUserFontEntry
// calls, will automatically remove the earlier occurrence of the same
// userfont entry.
mUserFontSet->AddUserFontEntry(fontfamily, entry);
}
-already_AddRefed<gfxUserFontEntry>
+/* static */ already_AddRefed<gfxUserFontEntry>
FontFaceSet::FindOrCreateUserFontEntryFromFontFace(FontFace* aFontFace)
{
nsAutoString fontfamily;
if (!aFontFace->GetFamilyName(fontfamily)) {
// If there is no family name, this rule cannot contribute a
// usable font, so there is no point in processing it further.
return nullptr;
}
return FindOrCreateUserFontEntryFromFontFace(fontfamily, aFontFace,
SheetType::Doc);
}
-already_AddRefed<gfxUserFontEntry>
+/* static */ already_AddRefed<gfxUserFontEntry>
FontFaceSet::FindOrCreateUserFontEntryFromFontFace(const nsAString& aFamilyName,
FontFace* aFontFace,
SheetType aSheetType)
{
+ FontFaceSet* set = aFontFace->GetPrimaryFontFaceSet();
+
nsCSSValue val;
nsCSSUnit unit;
uint32_t weight = NS_STYLE_FONT_WEIGHT_NORMAL;
int32_t stretch = NS_STYLE_FONT_STRETCH_NORMAL;
uint8_t italicStyle = NS_STYLE_FONT_STYLE_NORMAL;
uint32_t languageOverride = NO_FONT_LANGUAGE_OVERRIDE;
uint8_t fontDisplay = NS_FONT_DISPLAY_AUTO;
@@ -1125,17 +1127,17 @@ FontFaceSet::FindOrCreateUserFontEntryFr
face->mReferrerPolicy = mozilla::net::RP_Unset;
break;
case eCSSUnit_URL: {
face->mSourceType = gfxFontFaceSrc::eSourceType_URL;
nsIURI* uri = val.GetURLValue();
face->mURI = uri ? new gfxFontSrcURI(uri) : nullptr;
URLValue* url = val.GetURLStructValue();
face->mReferrer = url->mExtraData->GetReferrer();
- face->mReferrerPolicy = mDocument->GetReferrerPolicy();
+ face->mReferrerPolicy = set->mDocument->GetReferrerPolicy();
face->mOriginPrincipal =
new gfxFontSrcPrincipal(url->mExtraData->GetPrincipal());
NS_ASSERTION(face->mOriginPrincipal, "null origin principal in @font-face rule");
// agent and user stylesheets are treated slightly differently,
// the same-site origin check and access control headers are
// enforced against the sheet principal rather than the document
// principal to allow user stylesheets to include @font-face rules
@@ -1192,21 +1194,21 @@ FontFaceSet::FindOrCreateUserFontEntryFr
}
}
if (srcArray.IsEmpty()) {
return nullptr;
}
RefPtr<gfxUserFontEntry> entry =
- mUserFontSet->FindOrCreateUserFontEntry(aFamilyName, srcArray, weight,
- stretch, italicStyle,
- featureSettings,
- languageOverride,
- unicodeRanges, fontDisplay);
+ set->mUserFontSet->FindOrCreateUserFontEntry(aFamilyName, srcArray, weight,
+ stretch, italicStyle,
+ featureSettings,
+ languageOverride,
+ unicodeRanges, fontDisplay);
return entry.forget();
}
nsCSSFontFaceRule*
FontFaceSet::FindRuleForEntry(gfxFontEntry* aFontEntry)
{
NS_ASSERTION(!aFontEntry->mIsUserFontContainer, "only platform font entries");
for (uint32_t i = 0; i < mRuleFaces.Length(); ++i) {
--- a/layout/style/FontFaceSet.h
+++ b/layout/style/FontFaceSet.h
@@ -130,17 +130,17 @@ public:
nsCSSFontFaceRule* 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.
*/
- already_AddRefed<gfxUserFontEntry>
+ static already_AddRefed<gfxUserFontEntry>
FindOrCreateUserFontEntryFromFontFace(FontFace* aFontFace);
/**
* Notification method called by a FontFace to indicate that its loading
* status has changed.
*/
void OnFontFaceStatusChanged(FontFace* aFontFace);
@@ -262,17 +262,17 @@ private:
SheetType mSheetType; // only relevant for mRuleFaces entries
// When true, indicates that when finished loading, the FontFace should be
// included in the subsequent loadingdone/loadingerror event fired at the
// FontFaceSet.
bool mLoadEventShouldFire;
};
- already_AddRefed<gfxUserFontEntry> FindOrCreateUserFontEntryFromFontFace(
+ static already_AddRefed<gfxUserFontEntry> FindOrCreateUserFontEntryFromFontFace(
const nsAString& aFamilyName,
FontFace* aFontFace,
SheetType aSheetType);
// search for @font-face rule that matches a userfont font entry
nsCSSFontFaceRule* FindRuleForUserFontEntry(gfxUserFontEntry* aUserFontEntry);
nsresult StartLoad(gfxUserFontEntry* aUserFontEntry,