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