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 #[allow(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 origin,
59 is_html_document,
60 content_type,
61 last_modified,
62 activity,
63 source,
64 doc_loader,
65 None,
66 None,
67 Default::default(),
68 false,
69 false,
70 inherited_insecure_requests_policy,
71 has_trustworthy_ancestor_origin,
72 custom_element_reaction_stack,
73 window.Document().creation_sandboxing_flag_set(),
74 ),
75 }
76 }
77
78 #[allow(clippy::too_many_arguments)]
79 pub(crate) fn new(
80 window: &Window,
81 has_browsing_context: HasBrowsingContext,
82 url: Option<ServoUrl>,
83 origin: MutableOrigin,
84 doctype: IsHTMLDocument,
85 content_type: Option<Mime>,
86 last_modified: Option<String>,
87 activity: DocumentActivity,
88 source: DocumentSource,
89 doc_loader: DocumentLoader,
90 inherited_insecure_requests_policy: Option<InsecureRequestsPolicy>,
91 has_trustworthy_ancestor_origin: bool,
92 custom_element_reaction_stack: Rc<CustomElementReactionStack>,
93 can_gc: CanGc,
94 ) -> DomRoot<XMLDocument> {
95 let doc = reflect_dom_object(
96 Box::new(XMLDocument::new_inherited(
97 window,
98 has_browsing_context,
99 url,
100 origin,
101 doctype,
102 content_type,
103 last_modified,
104 activity,
105 source,
106 doc_loader,
107 inherited_insecure_requests_policy,
108 has_trustworthy_ancestor_origin,
109 custom_element_reaction_stack,
110 )),
111 window,
112 can_gc,
113 );
114 {
115 let node = doc.upcast::<Node>();
116 node.set_owner_doc(&doc.document);
117 }
118 doc
119 }
120}
121
122impl XMLDocumentMethods<crate::DomTypeHolder> for XMLDocument {
123 fn GetLocation(&self) -> Option<DomRoot<Location>> {
125 self.upcast::<Document>().GetLocation()
126 }
127
128 fn SupportedPropertyNames(&self) -> Vec<DOMString> {
130 self.upcast::<Document>().SupportedPropertyNames()
131 }
132
133 fn NamedGetter(&self, name: DOMString, can_gc: CanGc) -> Option<NamedPropertyValue> {
135 self.upcast::<Document>().NamedGetter(name, can_gc)
136 }
137}