fonts: Remove web fonts when their stylsheet is removed (#32346)

This is the first part of ensuring that unused fonts do not leak. This
change makes it so that when a stylesheet is removed, the corresponding
web fonts are removed from the `FontContext`.

Note: WebRender assets are still leaked, which was the situation before
for all fonts. A followup change will fix this issue.

Fixes #15139.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
This commit is contained in:
Martin Robinson 2024-05-23 08:49:31 +02:00 committed by GitHub
parent a772ecf786
commit 14286d913d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 258 additions and 57 deletions

View file

@ -179113,7 +179113,20 @@
{}
]
]
}
},
"web-font-no-longer-accessible-when-stylesheet-removed.html": [
"aac3e77a819019d349123fac2265531f3746f826",
[
null,
[
[
"/css/css-fonts/web-font-no-longer-accessible-when-stylesheet-removed-ref.html",
"=="
]
],
{}
]
]
},
"css-grid": {
"abspos": {
@ -403830,7 +403843,11 @@
"4e88cace350e32711fc06220c2d14dcbd3ab3339",
[]
]
}
},
"web-font-no-longer-accessible-when-stylesheet-removed-ref.html": [
"363b88d7180a9471c647cd69b9c69678e2f88da6",
[]
]
},
"css-gcpm": {
"META.yml": [

View file

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<title>CSS fonts: Web fonts from removed stylsheets should not be accessible</title>
<link rel="author" title="Martin Robinson" href="mrobinson@igalia.com">
<link rel="help" href="https://drafts.csswg.org/css-fonts/#font-face-rule">
</head>
<body>
<p>Test passes if the text below is not rendered with Ahem.</p>
<p>TEXT</p>
</body>
</html>

View file

@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<title>CSS fonts: Web fonts from removed stylsheets should not be accessible</title>
<link rel="author" title="Martin Robinson" href="mrobinson@igalia.com">
<link rel="match" href="web-font-no-longer-accessible-when-stylesheet-removed-ref.html">
<link rel="help" href="https://drafts.csswg.org/css-fonts/#font-face-rule">
</head>
<body>
<style id="web-font-stylesheet">
@font-face {
font-family: CustomFontFamily;
src: url(/fonts/Ahem.ttf);
}
</style>
<p>Test passes if the text below is not rendered with Ahem.</p>
<p style="font-family: CustomFontFamily;">TEXT</p>
<script>
let styleTag = document.getElementById("web-font-stylesheet");
styleTag.parentNode.removeChild(styleTag);
</script>
</body>
</html>