Commit b4bb18df authored by Alex Turner's avatar Alex Turner Committed by Commit Bot

Instrument src:local font existence lookups for identifiability study

While attempts to get src:local font data (including failures in those
attempts) are currently instrumented, it is possible to determine local
font existence through other means. In particular, FontFace.load() on a
FontFace object with a src:local attribute can be used to do this. (The
lookup will succeed if the font exists and result in a network error
otherwise.)

We therefore instrument any attempt to determine a local font's
existence by a unique name lookup. We include attempts to lookup the
font's data as that would also reveal existence.

Bug: 1136959
Change-Id: I7dcd900c541b3c9e20df353f7fe890b4e9352260
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2477453Reviewed-by: default avatarAsanka Herath <asanka@chromium.org>
Reviewed-by: default avatarDominik Röttsches <drott@chromium.org>
Commit-Queue: Alex Turner <alexmt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819459}
parent 3b5817e8
......@@ -217,6 +217,14 @@ class IdentifiableSurface {
// configuration provided.
kMediaCapabilities_DecodingInfo = 25,
// Represents determining that a local font exists or does not, based on a
// name lookup that is only allowed to match a unique name. This occurs in
// @font-face CSS rules with a src:local attribute, as well as calls to
// FontFace.load() for a FontFace object with a src:local attribute. The
// latter can reveal whether a font exists before the full font data are
// obtained. Input is the lookup name. Output is a bool.
kLocalFontExistenceByUniqueNameOnly = 26,
// Represents a call to Navigator.getUserMedia. Input is the set of
// constraints.
kNavigator_GetUserMedia = 27,
......
......@@ -91,11 +91,25 @@ void FontMatchingMetrics::ReportWebFontFamily(
void FontMatchingMetrics::ReportSuccessfulLocalFontMatch(
const AtomicString& font_name) {
local_fonts_succeeded_.insert(font_name);
ReportLocalFontExistenceByUniqueNameOnly(font_name, /*font_exists=*/true);
}
void FontMatchingMetrics::ReportFailedLocalFontMatch(
const AtomicString& font_name) {
local_fonts_failed_.insert(font_name);
ReportLocalFontExistenceByUniqueNameOnly(font_name, /*font_exists=*/false);
}
void FontMatchingMetrics::ReportLocalFontExistenceByUniqueNameOnly(
const AtomicString& font_name,
bool font_exists) {
if (!IdentifiabilityStudySettings::Get()->IsTypeAllowed(
IdentifiableSurface::Type::kLocalFontExistenceByUniqueNameOnly)) {
return;
}
IdentifiableTokenKey input_key(
IdentifiabilityBenignCaseFoldingStringToken(font_name));
local_font_existence_by_unique_name_only_.insert(input_key, font_exists);
}
void FontMatchingMetrics::InsertFontHashIntoMap(IdentifiableTokenKey input_key,
......@@ -263,6 +277,8 @@ void FontMatchingMetrics::PublishIdentifiabilityMetrics() {
IdentifiableSurface::Type::kGenericFontLookup},
{&font_load_postscript_name_,
IdentifiableSurface::Type::kLocalFontLoadPostScriptName},
{&local_font_existence_by_unique_name_only_,
IdentifiableSurface::Type::kLocalFontExistenceByUniqueNameOnly},
};
for (const auto& surface_entry : hash_maps_with_corresponding_surface_types) {
......
......@@ -200,6 +200,13 @@ class PLATFORM_EXPORT FontMatchingMetrics {
SimpleFontData* font_data,
TokenToTokenHashMap hash_map);
// Reports a local font's existence was looked up by a name, but its actual
// font data may or may not have been loaded. This only includes lookups where
// the name is allowed to match PostScript names and full font names, but not
// family names.
void ReportLocalFontExistenceByUniqueNameOnly(const AtomicString& font_name,
bool font_exists);
// Constructs a builder with a hash of the FontSelectionRequest already added.
IdentifiableTokenBuilder GetTokenBuilderWithFontSelectionRequest(
const FontDescription& font_description);
......@@ -243,6 +250,7 @@ class PLATFORM_EXPORT FontMatchingMetrics {
TokenToTokenHashMap font_lookups_as_last_resort_;
TokenToTokenHashMap generic_font_lookups_;
TokenToTokenHashMap font_load_postscript_name_;
TokenToTokenHashMap local_font_existence_by_unique_name_only_;
ukm::UkmRecorder* const ukm_recorder_;
const ukm::SourceId source_id_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment