1use std::cell::Cell;
6use std::rc::Rc;
7
8use base::id::{BrowsingContextId, PipelineId, WebViewId};
9use constellation_traits::{
10 IFrameLoadInfo, IFrameLoadInfoWithData, JsEvalResult, LoadData, LoadOrigin,
11 NavigationHistoryBehavior, ScriptToConstellationMessage,
12};
13use content_security_policy::sandboxing_directive::{
14 SandboxingFlagSet, parse_a_sandboxing_directive,
15};
16use dom_struct::dom_struct;
17use embedder_traits::ViewportDetails;
18use html5ever::{LocalName, Prefix, local_name, ns};
19use js::rust::HandleObject;
20use net_traits::ReferrerPolicy;
21use net_traits::request::Destination;
22use profile_traits::ipc as ProfiledIpc;
23use script_traits::{NewPipelineInfo, UpdatePipelineIdReason};
24use servo_url::ServoUrl;
25use style::attr::{AttrValue, LengthOrPercentageOrAuto};
26use stylo_atoms::Atom;
27
28use crate::document_loader::{LoadBlocker, LoadType};
29use crate::dom::attr::Attr;
30use crate::dom::bindings::cell::DomRefCell;
31use crate::dom::bindings::codegen::Bindings::HTMLIFrameElementBinding::HTMLIFrameElementMethods;
32use crate::dom::bindings::codegen::Bindings::WindowBinding::Window_Binding::WindowMethods;
33use crate::dom::bindings::codegen::UnionTypes::TrustedHTMLOrString;
34use crate::dom::bindings::error::Fallible;
35use crate::dom::bindings::inheritance::Castable;
36use crate::dom::bindings::reflector::DomGlobal;
37use crate::dom::bindings::root::{DomRoot, LayoutDom, MutNullableDom};
38use crate::dom::bindings::str::{DOMString, USVString};
39use crate::dom::document::Document;
40use crate::dom::domtokenlist::DOMTokenList;
41use crate::dom::element::{
42 AttributeMutation, Element, LayoutElementHelpers, reflect_referrer_policy_attribute,
43};
44use crate::dom::eventtarget::EventTarget;
45use crate::dom::globalscope::GlobalScope;
46use crate::dom::html::htmlelement::HTMLElement;
47use crate::dom::node::{BindContext, Node, NodeDamage, NodeTraits, UnbindContext};
48use crate::dom::performance::performanceresourcetiming::InitiatorType;
49use crate::dom::trustedhtml::TrustedHTML;
50use crate::dom::virtualmethods::VirtualMethods;
51use crate::dom::windowproxy::WindowProxy;
52use crate::network_listener::ResourceTimingListener;
53use crate::script_runtime::CanGc;
54use crate::script_thread::{ScriptThread, with_script_thread};
55use crate::script_window_proxies::ScriptWindowProxies;
56
57#[derive(PartialEq)]
58enum PipelineType {
59 InitialAboutBlank,
60 Navigation,
61}
62
63#[derive(PartialEq)]
64enum ProcessingMode {
65 FirstTime,
66 NotFirstTime,
67}
68
69#[dom_struct]
70pub(crate) struct HTMLIFrameElement {
71 htmlelement: HTMLElement,
72 #[no_trace]
73 webview_id: Cell<Option<WebViewId>>,
74 #[no_trace]
75 browsing_context_id: Cell<Option<BrowsingContextId>>,
76 #[no_trace]
77 pipeline_id: Cell<Option<PipelineId>>,
78 #[no_trace]
79 pending_pipeline_id: Cell<Option<PipelineId>>,
80 #[no_trace]
81 about_blank_pipeline_id: Cell<Option<PipelineId>>,
82 sandbox: MutNullableDom<DOMTokenList>,
83 #[no_trace]
84 sandboxing_flag_set: Cell<Option<SandboxingFlagSet>>,
85 load_blocker: DomRefCell<Option<LoadBlocker>>,
86 throttled: Cell<bool>,
87 #[conditional_malloc_size_of]
88 script_window_proxies: Rc<ScriptWindowProxies>,
89 pending_navigation: Cell<bool>,
96 already_fired_synchronous_load_event: Cell<bool>,
100}
101
102impl HTMLIFrameElement {
103 fn shared_attribute_processing_steps_for_iframe_and_frame_elements(&self) -> Option<ServoUrl> {
105 let element = self.upcast::<Element>();
106 let url = element
108 .get_attribute(&ns!(), &local_name!("src"))
109 .and_then(|src| {
110 let url = src.value();
111 if url.is_empty() {
112 None
113 } else {
114 self.owner_document().base_url().join(&url).ok()
118 }
119 })
120 .unwrap_or_else(|| ServoUrl::parse("about:blank").unwrap());
122 Some(url)
132 }
133
134 pub(crate) fn navigate_or_reload_child_browsing_context(
135 &self,
136 load_data: LoadData,
137 history_handling: NavigationHistoryBehavior,
138 can_gc: CanGc,
139 ) {
140 self.already_fired_synchronous_load_event.set(false);
147
148 self.start_new_pipeline(
149 load_data,
150 PipelineType::Navigation,
151 history_handling,
152 can_gc,
153 );
154 }
155
156 fn start_new_pipeline(
157 &self,
158 mut load_data: LoadData,
159 pipeline_type: PipelineType,
160 history_handling: NavigationHistoryBehavior,
161 can_gc: CanGc,
162 ) {
163 let browsing_context_id = match self.browsing_context_id() {
164 None => return warn!("Attempted to start a new pipeline on an unattached iframe."),
165 Some(id) => id,
166 };
167
168 let webview_id = match self.webview_id() {
169 None => return warn!("Attempted to start a new pipeline on an unattached iframe."),
170 Some(id) => id,
171 };
172
173 let document = self.owner_document();
174
175 {
176 let load_blocker = &self.load_blocker;
177 LoadBlocker::terminate(load_blocker, can_gc);
180 }
181
182 if load_data.url.scheme() == "javascript" {
183 let window_proxy = self.GetContentWindow();
184 if let Some(window_proxy) = window_proxy {
185 if !ScriptThread::navigate_to_javascript_url(
186 &document.global(),
187 &window_proxy.global(),
188 &mut load_data,
189 Some(self.upcast()),
190 can_gc,
191 ) {
192 return;
193 }
194 load_data.about_base_url = document.about_base_url();
195 }
196 }
197
198 match load_data.js_eval_result {
199 Some(JsEvalResult::NoContent) => (),
200 _ => {
201 let mut load_blocker = self.load_blocker.borrow_mut();
202 *load_blocker = Some(LoadBlocker::new(
203 &document,
204 LoadType::Subframe(load_data.url.clone()),
205 ));
206 },
207 };
208
209 let window = self.owner_window();
210 let old_pipeline_id = self.pipeline_id();
211 let new_pipeline_id = PipelineId::new();
212 self.pending_pipeline_id.set(Some(new_pipeline_id));
213
214 let load_info = IFrameLoadInfo {
215 parent_pipeline_id: window.pipeline_id(),
216 browsing_context_id,
217 webview_id,
218 new_pipeline_id,
219 is_private: false, inherited_secure_context: load_data.inherited_secure_context,
221 history_handling,
222 };
223
224 let viewport_details = window
225 .get_iframe_viewport_details_if_known(browsing_context_id)
226 .unwrap_or_else(|| ViewportDetails {
227 hidpi_scale_factor: window.device_pixel_ratio(),
228 ..Default::default()
229 });
230
231 match pipeline_type {
232 PipelineType::InitialAboutBlank => {
233 self.about_blank_pipeline_id.set(Some(new_pipeline_id));
234
235 let load_info = IFrameLoadInfoWithData {
236 info: load_info,
237 load_data: load_data.clone(),
238 old_pipeline_id,
239 viewport_details,
240 theme: window.theme(),
241 };
242 window
243 .as_global_scope()
244 .script_to_constellation_chan()
245 .send(ScriptToConstellationMessage::ScriptNewIFrame(load_info))
246 .unwrap();
247
248 let new_pipeline_info = NewPipelineInfo {
249 parent_info: Some(window.pipeline_id()),
250 new_pipeline_id,
251 browsing_context_id,
252 webview_id,
253 opener: None,
254 load_data,
255 viewport_details,
256 user_content_manager_id: None,
257 theme: window.theme(),
258 };
259
260 self.pipeline_id.set(Some(new_pipeline_id));
261 with_script_thread(|script_thread| {
262 script_thread.spawn_pipeline(new_pipeline_info);
263 });
264 },
265 PipelineType::Navigation => {
266 let load_info = IFrameLoadInfoWithData {
267 info: load_info,
268 load_data,
269 old_pipeline_id,
270 viewport_details,
271 theme: window.theme(),
272 };
273 window
274 .as_global_scope()
275 .script_to_constellation_chan()
276 .send(ScriptToConstellationMessage::ScriptLoadedURLInIFrame(
277 load_info,
278 ))
279 .unwrap();
280 },
281 }
282 }
283
284 pub(crate) fn is_initial_blank_document(&self) -> bool {
290 self.pending_pipeline_id.get() == self.about_blank_pipeline_id.get()
291 }
292
293 fn process_the_iframe_attributes(&self, mode: ProcessingMode, can_gc: CanGc) {
295 let element = self.upcast::<Element>();
296 if element.has_attribute(&local_name!("srcdoc")) {
300 let url = ServoUrl::parse("about:srcdoc").unwrap();
301 let document = self.owner_document();
302 let window = self.owner_window();
303 let pipeline_id = Some(window.pipeline_id());
304 let mut load_data = LoadData::new(
305 LoadOrigin::Script(document.origin().snapshot()),
306 url,
307 Some(document.base_url()),
308 pipeline_id,
309 window.as_global_scope().get_referrer(),
310 document.get_referrer_policy(),
311 Some(window.as_global_scope().is_secure_context()),
312 Some(document.insecure_requests_policy()),
313 document.has_trustworthy_ancestor_or_current_origin(),
314 self.sandboxing_flag_set(),
315 );
316 load_data.destination = Destination::IFrame;
317 load_data.policy_container = Some(window.as_global_scope().policy_container());
318 load_data.srcdoc = String::from(element.get_string_attribute(&local_name!("srcdoc")));
319 self.navigate_or_reload_child_browsing_context(
320 load_data,
321 NavigationHistoryBehavior::Push,
322 can_gc,
323 );
324 return;
325 }
326
327 let window = self.owner_window();
328
329 if mode == ProcessingMode::FirstTime {
334 if let Some(window) = self.GetContentWindow() {
335 window.set_name(
336 element
337 .get_name()
338 .map_or(DOMString::from(""), |n| DOMString::from(&*n)),
339 );
340 }
341 }
342
343 let Some(url) = self.shared_attribute_processing_steps_for_iframe_and_frame_elements()
346 else {
347 return;
349 };
350
351 if url.matches_about_blank() && mode == ProcessingMode::FirstTime {
353 self.already_fired_synchronous_load_event.set(true);
355 self.upcast::<EventTarget>()
363 .fire_event(atom!("load"), can_gc);
364 return;
366 }
367
368 let document = self.owner_document();
371 let referrer_policy_token = self.ReferrerPolicy();
372
373 let referrer_policy = match ReferrerPolicy::from(&*referrer_policy_token.str()) {
377 ReferrerPolicy::EmptyString => document.get_referrer_policy(),
378 policy => policy,
379 };
380
381 let mut ancestor = window.GetParent();
390 while let Some(a) = ancestor {
391 if let Some(ancestor_url) = a.document().map(|d| d.url()) {
392 if ancestor_url.scheme() == url.scheme() &&
393 ancestor_url.username() == url.username() &&
394 ancestor_url.password() == url.password() &&
395 ancestor_url.host() == url.host() &&
396 ancestor_url.port() == url.port() &&
397 ancestor_url.path() == url.path() &&
398 ancestor_url.query() == url.query()
399 {
400 return;
401 }
402 }
403 ancestor = a.parent().map(DomRoot::from_ref);
404 }
405
406 let (creator_pipeline_id, about_base_url) = if url.matches_about_blank() {
407 (Some(window.pipeline_id()), Some(document.base_url()))
408 } else {
409 (None, document.about_base_url())
410 };
411
412 let propagate_encoding_to_child_document = url.origin().same_origin(window.origin());
413 let mut load_data = LoadData::new(
414 LoadOrigin::Script(document.origin().snapshot()),
415 url,
416 about_base_url,
417 creator_pipeline_id,
418 window.as_global_scope().get_referrer(),
419 referrer_policy,
420 Some(window.as_global_scope().is_secure_context()),
421 Some(document.insecure_requests_policy()),
422 document.has_trustworthy_ancestor_or_current_origin(),
423 self.sandboxing_flag_set(),
424 );
425 load_data.destination = Destination::IFrame;
426 load_data.policy_container = Some(window.as_global_scope().policy_container());
427 if propagate_encoding_to_child_document {
428 load_data.container_document_encoding = Some(document.encoding());
429 }
430
431 let pipeline_id = self.pipeline_id();
432 let is_about_blank =
435 pipeline_id.is_some() && pipeline_id == self.about_blank_pipeline_id.get();
436
437 let history_handling = if is_about_blank {
438 NavigationHistoryBehavior::Replace
439 } else {
440 NavigationHistoryBehavior::Push
441 };
442
443 self.navigate_or_reload_child_browsing_context(load_data, history_handling, can_gc);
444 }
445
446 fn create_nested_browsing_context(&self, can_gc: CanGc) {
454 let url = ServoUrl::parse("about:blank").unwrap();
455 let document = self.owner_document();
456 let window = self.owner_window();
457 let pipeline_id = Some(window.pipeline_id());
458 let mut load_data = LoadData::new(
459 LoadOrigin::Script(document.origin().snapshot()),
460 url,
461 Some(document.base_url()),
462 pipeline_id,
463 window.as_global_scope().get_referrer(),
464 document.get_referrer_policy(),
465 Some(window.as_global_scope().is_secure_context()),
466 Some(document.insecure_requests_policy()),
467 document.has_trustworthy_ancestor_or_current_origin(),
468 self.sandboxing_flag_set(),
469 );
470 load_data.destination = Destination::IFrame;
471 load_data.policy_container = Some(window.as_global_scope().policy_container());
472
473 let browsing_context_id = BrowsingContextId::new();
474 let webview_id = window.window_proxy().webview_id();
475 self.pipeline_id.set(None);
476 self.pending_pipeline_id.set(None);
477 self.webview_id.set(Some(webview_id));
478 self.browsing_context_id.set(Some(browsing_context_id));
479 self.start_new_pipeline(
480 load_data,
481 PipelineType::InitialAboutBlank,
482 NavigationHistoryBehavior::Push,
483 can_gc,
484 );
485 }
486
487 fn destroy_nested_browsing_context(&self) {
488 self.pipeline_id.set(None);
489 self.pending_pipeline_id.set(None);
490 self.about_blank_pipeline_id.set(None);
491 self.webview_id.set(None);
492 if let Some(browsing_context_id) = self.browsing_context_id.take() {
493 self.script_window_proxies.remove(browsing_context_id)
494 }
495 }
496
497 pub(crate) fn update_pipeline_id(
498 &self,
499 new_pipeline_id: PipelineId,
500 reason: UpdatePipelineIdReason,
501 can_gc: CanGc,
502 ) {
503 if !self.is_initial_blank_document() {
508 self.pending_navigation.set(false);
509 }
510 if self.pending_pipeline_id.get() != Some(new_pipeline_id) &&
511 reason == UpdatePipelineIdReason::Navigation
512 {
513 return;
514 }
515
516 self.pipeline_id.set(Some(new_pipeline_id));
517
518 if reason == UpdatePipelineIdReason::Traversal {
521 let blocker = &self.load_blocker;
522 LoadBlocker::terminate(blocker, can_gc);
523 }
524
525 self.upcast::<Node>().dirty(NodeDamage::Other);
526 }
527
528 fn new_inherited(
529 local_name: LocalName,
530 prefix: Option<Prefix>,
531 document: &Document,
532 ) -> HTMLIFrameElement {
533 HTMLIFrameElement {
534 htmlelement: HTMLElement::new_inherited(local_name, prefix, document),
535 browsing_context_id: Cell::new(None),
536 webview_id: Cell::new(None),
537 pipeline_id: Cell::new(None),
538 pending_pipeline_id: Cell::new(None),
539 about_blank_pipeline_id: Cell::new(None),
540 sandbox: Default::default(),
541 sandboxing_flag_set: Cell::new(None),
542 load_blocker: DomRefCell::new(None),
543 throttled: Cell::new(false),
544 script_window_proxies: ScriptThread::window_proxies(),
545 pending_navigation: Default::default(),
546 already_fired_synchronous_load_event: Default::default(),
547 }
548 }
549
550 pub(crate) fn new(
551 local_name: LocalName,
552 prefix: Option<Prefix>,
553 document: &Document,
554 proto: Option<HandleObject>,
555 can_gc: CanGc,
556 ) -> DomRoot<HTMLIFrameElement> {
557 Node::reflect_node_with_proto(
558 Box::new(HTMLIFrameElement::new_inherited(
559 local_name, prefix, document,
560 )),
561 document,
562 proto,
563 can_gc,
564 )
565 }
566
567 #[inline]
568 pub(crate) fn pipeline_id(&self) -> Option<PipelineId> {
569 self.pipeline_id.get()
570 }
571
572 #[inline]
573 pub(crate) fn browsing_context_id(&self) -> Option<BrowsingContextId> {
574 self.browsing_context_id.get()
575 }
576
577 #[inline]
578 pub(crate) fn webview_id(&self) -> Option<WebViewId> {
579 self.webview_id.get()
580 }
581
582 #[inline]
583 pub(crate) fn sandboxing_flag_set(&self) -> SandboxingFlagSet {
584 self.sandboxing_flag_set
585 .get()
586 .unwrap_or_else(SandboxingFlagSet::empty)
587 }
588
589 pub(crate) fn set_throttled(&self, throttled: bool) {
590 if self.throttled.get() != throttled {
591 self.throttled.set(throttled);
592 }
593 }
594
595 pub(crate) fn note_pending_navigation(&self) {
599 self.pending_navigation.set(true);
600 }
601
602 pub(crate) fn iframe_load_event_steps(&self, loaded_pipeline: PipelineId, can_gc: CanGc) {
604 if Some(loaded_pipeline) != self.pending_pipeline_id.get() {
607 return;
608 }
609
610 let should_fire_event = if self.is_initial_blank_document() {
639 !self.pending_navigation.get() &&
643 !self.upcast::<Element>().has_attribute(&local_name!("src"))
644 } else {
645 !self.pending_navigation.get()
648 };
649 let should_fire_event =
652 !self.already_fired_synchronous_load_event.replace(false) && should_fire_event;
653 if should_fire_event {
654 self.upcast::<EventTarget>()
656 .fire_event(atom!("load"), can_gc);
657 }
658
659 let blocker = &self.load_blocker;
660 LoadBlocker::terminate(blocker, can_gc);
661
662 }
664
665 fn parse_sandbox_attribute(&self) {
669 let attribute = self
670 .upcast::<Element>()
671 .get_attribute(&ns!(), &local_name!("sandbox"));
672 self.sandboxing_flag_set
673 .set(attribute.map(|attribute_value| {
674 let tokens: Vec<_> = attribute_value
675 .value()
676 .as_tokens()
677 .iter()
678 .map(|atom| atom.to_string().to_ascii_lowercase())
679 .collect();
680 parse_a_sandboxing_directive(&tokens)
681 }));
682 }
683
684 pub(crate) fn destroy_document_and_its_descendants(&self, can_gc: CanGc) {
686 let Some(pipeline_id) = self.pipeline_id.get() else {
687 return;
688 };
689 if let Some(exited_document) = ScriptThread::find_document(pipeline_id) {
691 exited_document.destroy_document_and_its_descendants(can_gc);
692 }
693 self.destroy_nested_browsing_context();
694 }
695
696 fn destroy_child_navigable(&self, can_gc: CanGc) {
698 let blocker = &self.load_blocker;
699 LoadBlocker::terminate(blocker, CanGc::note());
700
701 let Some(browsing_context_id) = self.browsing_context_id() else {
703 return;
705 };
706 let pipeline_id = self.pipeline_id.get();
709
710 self.destroy_nested_browsing_context();
718
719 let (sender, receiver) =
724 ProfiledIpc::channel(self.global().time_profiler_chan().clone()).unwrap();
725 let msg = ScriptToConstellationMessage::RemoveIFrame(browsing_context_id, sender);
726 self.owner_window()
727 .as_global_scope()
728 .script_to_constellation_chan()
729 .send(msg)
730 .unwrap();
731 let _exited_pipeline_ids = receiver.recv().unwrap();
732 let Some(pipeline_id) = pipeline_id else {
733 return;
734 };
735 if let Some(exited_document) = ScriptThread::find_document(pipeline_id) {
736 exited_document.destroy_document_and_its_descendants(can_gc);
737 }
738
739 }
754}
755
756pub(crate) trait HTMLIFrameElementLayoutMethods {
757 fn pipeline_id(self) -> Option<PipelineId>;
758 fn browsing_context_id(self) -> Option<BrowsingContextId>;
759 fn get_width(self) -> LengthOrPercentageOrAuto;
760 fn get_height(self) -> LengthOrPercentageOrAuto;
761}
762
763impl HTMLIFrameElementLayoutMethods for LayoutDom<'_, HTMLIFrameElement> {
764 #[inline]
765 fn pipeline_id(self) -> Option<PipelineId> {
766 (self.unsafe_get()).pipeline_id.get()
767 }
768
769 #[inline]
770 fn browsing_context_id(self) -> Option<BrowsingContextId> {
771 (self.unsafe_get()).browsing_context_id.get()
772 }
773
774 fn get_width(self) -> LengthOrPercentageOrAuto {
775 self.upcast::<Element>()
776 .get_attr_for_layout(&ns!(), &local_name!("width"))
777 .map(AttrValue::as_dimension)
778 .cloned()
779 .unwrap_or(LengthOrPercentageOrAuto::Auto)
780 }
781
782 fn get_height(self) -> LengthOrPercentageOrAuto {
783 self.upcast::<Element>()
784 .get_attr_for_layout(&ns!(), &local_name!("height"))
785 .map(AttrValue::as_dimension)
786 .cloned()
787 .unwrap_or(LengthOrPercentageOrAuto::Auto)
788 }
789}
790
791impl HTMLIFrameElementMethods<crate::DomTypeHolder> for HTMLIFrameElement {
792 make_url_getter!(Src, "src");
794
795 make_url_setter!(SetSrc, "src");
797
798 fn Srcdoc(&self) -> TrustedHTMLOrString {
800 let element = self.upcast::<Element>();
801 element.get_trusted_html_attribute(&local_name!("srcdoc"))
802 }
803
804 fn SetSrcdoc(&self, value: TrustedHTMLOrString, can_gc: CanGc) -> Fallible<()> {
806 let element = self.upcast::<Element>();
810 let value = TrustedHTML::get_trusted_script_compliant_string(
811 &element.owner_global(),
812 value,
813 "HTMLIFrameElement srcdoc",
814 can_gc,
815 )?;
816 element.set_attribute(
818 &local_name!("srcdoc"),
819 AttrValue::String(value.str().to_owned()),
820 can_gc,
821 );
822 Ok(())
823 }
824
825 fn Sandbox(&self, can_gc: CanGc) -> DomRoot<DOMTokenList> {
831 self.sandbox.or_init(|| {
832 DOMTokenList::new(
833 self.upcast::<Element>(),
834 &local_name!("sandbox"),
835 Some(vec![
836 Atom::from("allow-downloads"),
837 Atom::from("allow-forms"),
838 Atom::from("allow-modals"),
839 Atom::from("allow-orientation-lock"),
840 Atom::from("allow-pointer-lock"),
841 Atom::from("allow-popups"),
842 Atom::from("allow-popups-to-escape-sandbox"),
843 Atom::from("allow-presentation"),
844 Atom::from("allow-same-origin"),
845 Atom::from("allow-scripts"),
846 Atom::from("allow-top-navigation"),
847 Atom::from("allow-top-navigation-by-user-activation"),
848 Atom::from("allow-top-navigation-to-custom-protocols"),
849 ]),
850 can_gc,
851 )
852 })
853 }
854
855 fn GetContentWindow(&self) -> Option<DomRoot<WindowProxy>> {
857 self.browsing_context_id
858 .get()
859 .and_then(|id| self.script_window_proxies.find_window_proxy(id))
860 }
861
862 fn GetContentDocument(&self) -> Option<DomRoot<Document>> {
864 let pipeline_id = self.pipeline_id.get()?;
866
867 let document = ScriptThread::find_document(pipeline_id)?;
871 if !self
873 .owner_document()
874 .origin()
875 .same_origin_domain(document.origin())
876 {
877 return None;
878 }
879 Some(document)
881 }
882
883 fn ReferrerPolicy(&self) -> DOMString {
885 reflect_referrer_policy_attribute(self.upcast::<Element>())
886 }
887
888 make_setter!(SetReferrerPolicy, "referrerpolicy");
890
891 make_bool_getter!(AllowFullscreen, "allowfullscreen");
893 make_bool_setter!(SetAllowFullscreen, "allowfullscreen");
895
896 make_getter!(Width, "width");
898 make_dimension_setter!(SetWidth, "width");
900
901 make_getter!(Height, "height");
903 make_dimension_setter!(SetHeight, "height");
905
906 make_getter!(FrameBorder, "frameborder");
908 make_setter!(SetFrameBorder, "frameborder");
910
911 make_atomic_setter!(SetName, "name");
915
916 make_getter!(Name, "name");
920}
921
922impl VirtualMethods for HTMLIFrameElement {
923 fn super_type(&self) -> Option<&dyn VirtualMethods> {
924 Some(self.upcast::<HTMLElement>() as &dyn VirtualMethods)
925 }
926
927 fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation, can_gc: CanGc) {
928 self.super_type()
929 .unwrap()
930 .attribute_mutated(attr, mutation, can_gc);
931 match *attr.local_name() {
932 local_name!("sandbox") if self.browsing_context_id.get().is_some() => {
943 self.parse_sandbox_attribute();
944 },
945 local_name!("srcdoc") => {
946 if self.upcast::<Node>().is_connected_with_browsing_context() {
957 debug!("iframe srcdoc modified while in browsing context.");
958 self.process_the_iframe_attributes(ProcessingMode::NotFirstTime, can_gc);
959 }
960 },
961 local_name!("src") => {
962 if self.upcast::<Node>().is_connected_with_browsing_context() {
971 debug!("iframe src set while in browsing context.");
972 self.process_the_iframe_attributes(ProcessingMode::NotFirstTime, can_gc);
973 }
974 },
975 _ => {},
976 }
977 }
978
979 fn attribute_affects_presentational_hints(&self, attr: &Attr) -> bool {
980 match attr.local_name() {
981 &local_name!("width") | &local_name!("height") => true,
982 _ => self
983 .super_type()
984 .unwrap()
985 .attribute_affects_presentational_hints(attr),
986 }
987 }
988
989 fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
990 match *name {
991 local_name!("sandbox") => AttrValue::from_serialized_tokenlist(value.into()),
992 local_name!("width") => AttrValue::from_dimension(value.into()),
993 local_name!("height") => AttrValue::from_dimension(value.into()),
994 _ => self
995 .super_type()
996 .unwrap()
997 .parse_plain_attribute(name, value),
998 }
999 }
1000
1001 fn post_connection_steps(&self, can_gc: CanGc) {
1003 if let Some(s) = self.super_type() {
1004 s.post_connection_steps(can_gc);
1005 }
1006
1007 if !self.upcast::<Node>().is_connected_with_browsing_context() {
1011 return;
1012 }
1013
1014 debug!("<iframe> running post connection steps");
1015
1016 self.create_nested_browsing_context(can_gc);
1018
1019 self.parse_sandbox_attribute();
1022
1023 self.process_the_iframe_attributes(ProcessingMode::FirstTime, can_gc);
1025 }
1026
1027 fn bind_to_tree(&self, context: &BindContext, can_gc: CanGc) {
1028 if let Some(s) = self.super_type() {
1029 s.bind_to_tree(context, can_gc);
1030 }
1031 self.owner_document().invalidate_iframes_collection();
1032 }
1033
1034 fn unbind_from_tree(&self, context: &UnbindContext, can_gc: CanGc) {
1036 self.super_type().unwrap().unbind_from_tree(context, can_gc);
1037
1038 self.destroy_child_navigable(can_gc);
1040
1041 self.owner_document().invalidate_iframes_collection();
1042 }
1043}
1044
1045pub(crate) struct IframeContext<'a> {
1048 element: &'a HTMLIFrameElement,
1050 url: ServoUrl,
1052}
1053
1054impl<'a> IframeContext<'a> {
1055 pub fn new(element: &'a HTMLIFrameElement) -> Self {
1057 Self {
1058 element,
1059 url: element
1060 .shared_attribute_processing_steps_for_iframe_and_frame_elements()
1061 .expect("Must always have a URL when navigating"),
1062 }
1063 }
1064}
1065
1066impl<'a> ResourceTimingListener for IframeContext<'a> {
1067 fn resource_timing_information(&self) -> (InitiatorType, ServoUrl) {
1068 (
1069 InitiatorType::LocalName("iframe".to_string()),
1070 self.url.clone(),
1071 )
1072 }
1073
1074 fn resource_timing_global(&self) -> DomRoot<GlobalScope> {
1075 self.element.upcast::<Node>().owner_doc().global()
1076 }
1077}