/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use std::rc::Rc; use std::sync::Arc; use data_url::mime::Mime; use dom_struct::dom_struct; use js::context::{JSContext, NoGC}; use net_traits::image_cache::ImageCache; use net_traits::request::InsecureRequestsPolicy; use script_bindings::codegen::GenericBindings::WindowBinding::WindowMethods; use script_bindings::reflector::reflect_dom_object; use script_traits::DocumentActivity; use servo_url::{MutableOrigin, ServoUrl}; use crate::dom::animations::documenttimeline::DocumentTimeline; use crate::dom::bindings::codegen::Bindings::DocumentBinding::{ DocumentMethods, NamedPropertyValue, }; use crate::dom::bindings::codegen::Bindings::XMLDocumentBinding::XMLDocumentMethods; use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::str::DOMString; use crate::dom::customelementregistry::CustomElementReactionStack; use crate::dom::document::{Document, HasBrowsingContext, IsHTMLDocument}; use crate::dom::location::Location; use crate::dom::node::Node; use crate::dom::window::Window; use crate::event_loop::document_loader::DocumentLoader; // https://dom.spec.whatwg.org/#xmldocument #[dom_struct] pub(crate) struct XMLDocument { document: Document, } impl XMLDocument { #[expect(clippy::too_many_arguments)] fn new_inherited( window: &Window, has_browsing_context: HasBrowsingContext, url: Option, origin: MutableOrigin, is_html_document: IsHTMLDocument, content_type: Option, last_modified: Option, activity: DocumentActivity, doc_loader: DocumentLoader, inherited_insecure_requests_policy: Option, has_trustworthy_ancestor_origin: bool, custom_element_reaction_stack: Rc, timeline: &DocumentTimeline, image_cache: Arc, ) -> XMLDocument { XMLDocument { document: Document::new_inherited( window, has_browsing_context, url, None, origin, is_html_document, content_type, last_modified, activity, doc_loader, None, None, Default::default(), false, false, inherited_insecure_requests_policy, has_trustworthy_ancestor_origin, custom_element_reaction_stack, window.Document().creation_sandboxing_flag_set(), timeline, window.pipeline_id(), image_cache, ), } } #[expect(clippy::too_many_arguments)] pub(crate) fn new( cx: &mut JSContext, window: &Window, has_browsing_context: HasBrowsingContext, url: Option, origin: MutableOrigin, doctype: IsHTMLDocument, content_type: Option, last_modified: Option, activity: DocumentActivity, doc_loader: DocumentLoader, inherited_insecure_requests_policy: Option, has_trustworthy_ancestor_origin: bool, custom_element_reaction_stack: Rc, image_cache: Arc, ) -> DomRoot { let timeline = DocumentTimeline::new(cx, window); let doc = reflect_dom_object( cx, Box::new(XMLDocument::new_inherited( window, has_browsing_context, url, origin, doctype, content_type, last_modified, activity, doc_loader, inherited_insecure_requests_policy, has_trustworthy_ancestor_origin, custom_element_reaction_stack, &timeline, image_cache, )), window, ); { let node = doc.upcast::(); node.set_owner_doc(&doc.document); } doc } } impl XMLDocumentMethods for XMLDocument { /// fn GetLocation(&self, cx: &mut JSContext) -> Option> { self.upcast::().GetLocation(cx) } /// fn SupportedPropertyNames(&self, no_gc: &NoGC) -> Vec { self.upcast::().SupportedPropertyNames(no_gc) } /// fn NamedGetter( &self, cx: &mut js::context::JSContext, name: DOMString, ) -> Option { self.upcast::().NamedGetter(cx, name) } }