Bug 1863574 - patch 2 - Create an RFPTarget option to control whether the resolution of CSS generics is subject to font-visibility restrictions. r=jwatt

Differential Revision: https://phabricator.services.mozilla.com/D195426
This commit is contained in:
Jonathan Kew 2023-12-07 10:29:34 +00:00
Родитель cabcf47a27
Коммит 630dcfd972
3 изменённых файлов: 27 добавлений и 1 удалений

Просмотреть файл

@ -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,

Просмотреть файл

@ -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 <generic-family> 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);

Просмотреть файл

@ -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 <generic-family>?
// (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.