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