Bug 1342479 - gather telemetry on webfont extension usage
This is separate to the actual font type. We specifically want to know whether
fonts are being loaded from URLs that obviously point to a webfont (i.e.
have an obvious extension in the filename).
MozReview-Commit-ID: G2Jhlf0HBhs
--- a/layout/style/FontFaceSet.cpp
+++ b/layout/style/FontFaceSet.cpp
@@ -575,25 +575,50 @@ FontFaceSet::ForEach(JSContext* aCx,
}
void
FontFaceSet::RemoveLoader(nsFontFaceLoader* aLoader)
{
mLoaders.RemoveEntry(aLoader);
}
+#ifndef RELEASE_BUILD
+// This code is only intended for use during 55 nightly, and will be removed
+// directly thereafter
+
+void
+ProcessFontLoadTelemetry(const nsCOMPtr<nsIURI>& uri)
+{
+ nsCString path;
+ uri->GetPath(path);
+
+ const nsCaseInsensitiveUTF8StringComparator comparator = nsCaseInsensitiveUTF8StringComparator();
+ const bool standardExtension = StringEndsWith(path, NS_LITERAL_CSTRING(".woff2"), comparator) ||
+ StringEndsWith(path, NS_LITERAL_CSTRING(".woff"), comparator) ||
+ StringEndsWith(path, NS_LITERAL_CSTRING(".otf"), comparator) ||
+ StringEndsWith(path, NS_LITERAL_CSTRING(".eot"), comparator) ||
+ StringEndsWith(path, NS_LITERAL_CSTRING(".ttf"), comparator);
+
+ Telemetry::Accumulate(Telemetry::WEBFONT_STANDARD_EXTENSION, standardExtension);
+}
+#endif
+
nsresult
FontFaceSet::StartLoad(gfxUserFontEntry* aUserFontEntry,
const gfxFontFaceSrc* aFontFaceSrc)
{
nsresult rv;
nsCOMPtr<nsIStreamLoader> streamLoader;
nsCOMPtr<nsILoadGroup> loadGroup(mDocument->GetDocumentLoadGroup());
+#ifndef RELEASE_BUILD
+ ProcessFontLoadTelemetry(aFontFaceSrc->mURI);
+#endif
+
nsCOMPtr<nsIChannel> channel;
// Note we are calling NS_NewChannelWithTriggeringPrincipal() with both a
// node and a principal. This is because the document where the font is
// being loaded might have a different origin from the principal of the
// stylesheet that initiated the font load.
rv = NS_NewChannelWithTriggeringPrincipal(getter_AddRefs(channel),
aFontFaceSrc->mURI,
mDocument,
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -10306,16 +10306,23 @@
},
"WEBFONT_SRCTYPE": {
"alert_emails": ["jdaggett@mozilla.com"],
"expires_in_version": "never",
"kind": "enumerated",
"n_values": 5,
"description": "Font src type loaded (1 = local, 2 = url, 3 = data)"
},
+ "WEBFONT_STANDARD_EXTENSION": {
+ "expires_in_version": "56",
+ "kind": "boolean",
+ "description": "Whether a webfont being loaded has a standard extension (true for .woff/.woff2/.eot/.ttf/.svg#/.otf). This is different to FONTTYPE - a valid webfont doesn't have to have the corresponding extension as part of its path/URL.",
+ "bug_numbers": [1342479],
+ "alert_emails": ["ahunt@mozilla.com"]
+ },
"WEBFONT_PER_PAGE": {
"alert_emails": ["jdaggett@mozilla.com"],
"expires_in_version": "never",
"kind": "count",
"description": "Number of fonts loaded at page load"
},
"WEBFONT_SIZE_PER_PAGE": {
"alert_emails": ["jdaggett@mozilla.com"],