Add Helper method for creating new WebFontDocumentContext

Signed-off-by: Uthman Yahaya Baba <uthmanyahayababa@gmail.com>
This commit is contained in:
Uthman Yahaya Baba 2025-05-19 20:59:36 +01:00
parent e9e360edef
commit 8ac9dfcde6
4 changed files with 17 additions and 36 deletions

View file

@ -4918,15 +4918,7 @@ impl Document {
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(),
};
let document_context = self.window.new_document_context();
self.window.layout_mut().add_stylesheet(
sheet.clone(),

View file

@ -7,10 +7,7 @@ use std::rc::Rc;
use cssparser::{Parser, ParserInput};
use dom_struct::dom_struct;
use fonts::{
FontContext, FontContextWebFontMethods, FontTemplate, LowercaseFontFamilyName,
WebFontDocumentContext,
};
use fonts::{FontContext, FontContextWebFontMethods, FontTemplate, LowercaseFontFamilyName};
use js::rust::HandleObject;
use style::error_reporting::ParseErrorReporter;
use style::font_face::SourceList;
@ -543,13 +540,8 @@ impl FontFaceMethods<crate::DomTypeHolder> for FontFace {
)
.expect("Parsing shouldn't fail as descriptors are valid by construction");
//Construct a WebFontDocumentContext object for the current document.
let document_context = WebFontDocumentContext {
policy_container: global.policy_container(),
document_url: global.api_base_url(),
has_trustworthy_ancestor_origin: global.has_trustworthy_ancestor_origin(),
insecure_requests_policy: global.insecure_requests_policy(),
};
// Construct a WebFontDocumentContext object for the current document.
let document_context = global.as_window().new_document_context();
// Step 4. Using the value of font faces [[Urls]] slot, attempt to load a font as defined
// in [CSS-FONTS-3], as if it was the value of a @font-face rules src descriptor.

View file

@ -769,6 +769,15 @@ impl Window {
})
);
}
pub fn new_document_context(&self) -> WebFontDocumentContext {
WebFontDocumentContext {
policy_container: self.global().policy_container(),
document_url: self.global().api_base_url(),
has_trustworthy_ancestor_origin: self.global().has_trustworthy_ancestor_origin(),
insecure_requests_policy: self.global().insecure_requests_policy(),
}
}
}
// https://html.spec.whatwg.org/multipage/#atob
@ -2171,12 +2180,8 @@ impl Window {
let highlighted_dom_node = document.highlighted_dom_node().map(|node| node.to_opaque());
//Construct a new document context for the reflow.
let document_context = WebFontDocumentContext {
policy_container: self.global().policy_container(),
document_url: self.global().api_base_url(),
has_trustworthy_ancestor_origin: self.global().has_trustworthy_ancestor_origin(),
insecure_requests_policy: self.global().insecure_requests_policy(),
};
let document_context = self.new_document_context();
// Send new document and relevant styles to layout.
let reflow = ReflowRequest {
reflow_info: Reflow {

View file

@ -8,7 +8,6 @@ use std::sync::atomic::AtomicBool;
use content_security_policy as csp;
use cssparser::SourceLocation;
use encoding_rs::UTF_8;
use fonts::WebFontDocumentContext;
use mime::{self, Mime};
use net_traits::request::{CorsSettings, Destination, RequestId};
use net_traits::{
@ -233,15 +232,8 @@ impl FetchResponseListener for StylesheetContext {
Some(&loader),
win.css_error_reporter(),
);
//Construct a new WebFontDocumentContext for the stylesheet
let document_context = WebFontDocumentContext {
policy_container: win.global().policy_container(),
document_url: win.global().api_base_url(),
has_trustworthy_ancestor_origin: win
.global()
.has_trustworthy_ancestor_origin(),
insecure_requests_policy: win.global().insecure_requests_policy(),
};
// Construct a new WebFontDocumentContext for the stylesheet
let document_context = win.new_document_context();
// Layout knows about this stylesheet, because Stylo added it to the Stylist,
// but Layout doesn't know about any new web fonts that it contains.