script/dom/
xmldocument.rs1use std::rc::Rc;
6
7use data_url::mime::Mime;
8use dom_struct::dom_struct;
9use net_traits::request::InsecureRequestsPolicy;
10use script_bindings::codegen::GenericBindings::WindowBinding::WindowMethods;
11use script_traits::DocumentActivity;
12use servo_url::{MutableOrigin, ServoUrl};
13
14use crate::document_loader::DocumentLoader;
15use crate::dom::bindings::codegen::Bindings::DocumentBinding::{
16 DocumentMethods, NamedPropertyValue,
17};
18use crate::dom::bindings::codegen::Bindings::XMLDocumentBinding::XMLDocumentMethods;
19use crate::dom::bindings::inheritance::Castable;
20use crate::dom::bindings::reflector::reflect_dom_object;
21use crate::dom::bindings::root::DomRoot;
22use crate::dom::bindings::str::DOMString;
23use crate::dom::customelementregistry::CustomElementReactionStack;
24use crate::dom::document::{Document, DocumentSource, HasBrowsingContext, IsHTMLDocument};
25use crate::dom::location::Location;
26use crate::dom::node::Node;
27use crate::dom::window::Window;
28use crate::script_runtime::CanGc;
29
30#[dom_struct]
32pub(crate) struct XMLDocument {
33 document: Document,
34}
35
36impl XMLDocument {
37 #[expect(clippy::too_many_arguments)]
38 fn new_inherited(
39 window: &Window,
40 has_browsing_context: HasBrowsingContext,
41 url: Option<ServoUrl>,
42 origin: MutableOrigin,
43 is_html_document: IsHTMLDocument,
44 content_type: Option<Mime>,
45 last_modified: Option<String>,
46 activity: DocumentActivity,
47 source: DocumentSource,
48 doc_loader: DocumentLoader,
49 inherited_insecure_requests_policy: Option<InsecureRequestsPolicy>,
50 has_trustworthy_ancestor_origin: bool,
51 custom_element_reaction_stack: Rc<CustomElementReactionStack>,
52 ) -> XMLDocument {
53 XMLDocument {
54 document: Document::new_inherited(
55 window,
56 has_browsing_context,
57 url,
58 None,
59 origin,
60 is_html_document,
61 content_type,
62 last_modified,
63 activity,
64 source,
65 doc_loader,
66 None,
67 None,
68 Default::default(),
69 false,
70 false,
71 inherited_insecure_requests_policy,
72 has_trustworthy_ancestor_origin,
73 custom_element_reaction_stack,
74 window.Document().creation_sandboxing_flag_set(),
75 ),
76 }
77 }
78
79 #[expect(clippy::too_many_arguments)]
80 pub(crate) fn new(
81 window: &Window,
82 has_browsing_context: HasBrowsingContext,
83 url: Option<ServoUrl>,
84 origin: MutableOrigin,
85 doctype: IsHTMLDocument,
86 content_type: Option<Mime>,
87 last_modified: Option<String>,
88 activity: DocumentActivity,
89 source: DocumentSource,
90 doc_loader: DocumentLoader,
91 inherited_insecure_requests_policy: Option<InsecureRequestsPolicy>,
92 has_trustworthy_ancestor_origin: bool,
93 custom_element_reaction_stack: Rc<CustomElementReactionStack>,
94 can_gc: CanGc,
95 ) -> DomRoot<XMLDocument> {
96 let doc = reflect_dom_object(
97 Box::new(XMLDocument::new_inherited(
98 window,
99 has_browsing_context,
100 url,
101 origin,
102 doctype,
103 content_type,
104 last_modified,
105 activity,
106 source,
107 doc_loader,
108 inherited_insecure_requests_policy,
109 has_trustworthy_ancestor_origin,
110 custom_element_reaction_stack,
111 )),
112 window,
113 can_gc,
114 );
115 {
116 let node = doc.upcast::<Node>();
117 node.set_owner_doc(&doc.document);
118 }
119 doc
120 }
121}
122
123impl XMLDocumentMethods<crate::DomTypeHolder> for XMLDocument {
124 fn GetLocation(&self) -> Option<DomRoot<Location>> {
126 self.upcast::<Document>().GetLocation()
127 }
128
129 fn SupportedPropertyNames(&self) -> Vec<DOMString> {
131 self.upcast::<Document>().SupportedPropertyNames()
132 }
133
134 fn NamedGetter(&self, name: DOMString, can_gc: CanGc) -> Option<NamedPropertyValue> {
136 self.upcast::<Document>().NamedGetter(name, can_gc)
137 }
138}