Add WebFontDocumentContext for CSS Fonts 4 font fetching

Signed-off-by: Uthman Yahaya Baba <uthmanyahayababa@gmail.com>
This commit is contained in:
Uthman Yahaya Baba 2025-05-16 04:09:55 +01:00
parent 3af0992ead
commit e9e360edef
8 changed files with 122 additions and 20 deletions

View file

@ -35,6 +35,7 @@ use embedder_traits::{
};
use encoding_rs::{Encoding, UTF_8};
use euclid::default::{Point2D, Rect, Size2D};
use fonts::WebFontDocumentContext;
use html5ever::{LocalName, Namespace, QualName, local_name, ns};
use hyper_serde::Serde;
use ipc_channel::ipc;
@ -4916,9 +4917,21 @@ impl Document {
.cloned();
if self.has_browsing_context() {
// Construct WebFontDocumentContext for font fetching
let document_context = WebFontDocumentContext {
policy_container: self.window.global().policy_container(),
document_url: self.window.global().api_base_url(),
has_trustworthy_ancestor_origin: self
.window
.global()
.has_trustworthy_ancestor_origin(),
insecure_requests_policy: self.window.global().insecure_requests_policy(),
};
self.window.layout_mut().add_stylesheet(
sheet.clone(),
insertion_point.as_ref().map(|s| s.sheet.clone()),
&document_context,
);
}
@ -4932,10 +4945,14 @@ impl Document {
}
/// Given a stylesheet, load all web fonts from it in Layout.
pub(crate) fn load_web_fonts_from_stylesheet(&self, stylesheet: Arc<Stylesheet>) {
pub(crate) fn load_web_fonts_from_stylesheet(
&self,
stylesheet: Arc<Stylesheet>,
document_context: &WebFontDocumentContext,
) {
self.window
.layout()
.load_web_fonts_from_stylesheet(stylesheet);
.load_web_fonts_from_stylesheet(stylesheet, document_context);
}
/// Remove a stylesheet owned by `owner` from the list of document sheets.