diff --git a/gfx/thebes/gfxPlatformFontList.cpp b/gfx/thebes/gfxPlatformFontList.cpp index 590ae9ce1bd6..55813eacb597 100644 --- a/gfx/thebes/gfxPlatformFontList.cpp +++ b/gfx/thebes/gfxPlatformFontList.cpp @@ -38,6 +38,7 @@ #include "mozilla/dom/ContentChild.h" #include "mozilla/dom/ContentParent.h" #include "mozilla/dom/ContentProcessMessageManager.h" +#include "mozilla/dom/Document.h" #include "mozilla/gfx/2D.h" #include "mozilla/ipc/FileDescriptorUtils.h" #include "mozilla/ResultExtensions.h" @@ -1535,6 +1536,17 @@ bool gfxPlatformFontList::FindAndAddFamiliesLocked( FontVisibility visibilityLevel = aPresContext ? aPresContext->GetFontVisibility() : FontVisibility::User; + // If this font lookup is the result of resolving a CSS generic (not a direct + // font-family request by the page), and RFP settings allow generics to be + // unrestricted, bump the effective visibility level applied here so as to + // allow user-installed fonts to be used. + if (visibilityLevel < FontVisibility::User && + aGeneric != StyleGenericFontFamily::None && + !aPresContext->Document()->ShouldResistFingerprinting( + RFPTarget::FontVisibilityRestrictGenerics)) { + visibilityLevel = FontVisibility::User; + } + if (SharedFontList()) { fontlist::Family* family = SharedFontList()->FindFamily(key); // If not found, and other family names have not yet been initialized, diff --git a/layout/base/nsPresContext.h b/layout/base/nsPresContext.h index 550ef009a72d..5e309c9498e6 100644 --- a/layout/base/nsPresContext.h +++ b/layout/base/nsPresContext.h @@ -161,7 +161,7 @@ class nsPresContext : public nsISupports, public mozilla::SupportsWeakPtr { */ nsresult Init(nsDeviceContext* aDeviceContext); - /* + /** * Initialize the font cache if it hasn't been initialized yet. * (Needed for stylo) */ @@ -169,7 +169,18 @@ class nsPresContext : public nsISupports, public mozilla::SupportsWeakPtr { void UpdateFontCacheUserFonts(gfxUserFontSet* aUserFontSet); + /** + * Return the font visibility level to be applied to this context, + * potentially blocking user-installed or non-standard fonts from being + * used by web content. + * Note that depending on ResistFingerprinting options, the caller may + * override this value when resolving CSS keywords. + */ FontVisibility GetFontVisibility() const { return mFontVisibility; } + + /** + * Log a message to the console about a font request being blocked. + */ void ReportBlockedFontFamily(const mozilla::fontlist::Family& aFamily); void ReportBlockedFontFamily(const gfxFontFamily& aFamily); diff --git a/toolkit/components/resistfingerprinting/RFPTargets.inc b/toolkit/components/resistfingerprinting/RFPTargets.inc index e70ba0e1a053..d2327ffbfe3a 100644 --- a/toolkit/components/resistfingerprinting/RFPTargets.inc +++ b/toolkit/components/resistfingerprinting/RFPTargets.inc @@ -91,6 +91,9 @@ ITEM_VALUE(CSSPointerCapabilities, 1llu << 57) ITEM_VALUE(WebGLRenderCapability, 1llu << 58) ITEM_VALUE(WebGLRenderInfo, 1llu << 59) ITEM_VALUE(SiteSpecificZoom, 1llu << 60) +// Are font visibility restrictions applied when resolving a CSS ? +// (This may block the fonts selected in Preferences from actually being used.) +ITEM_VALUE(FontVisibilityRestrictGenerics, 1llu << 61) // !!! Don't forget to update kDefaultFingerprintingProtections in nsRFPService.cpp // if necessary.