script/dom/html/htmliframeelement.rs
1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use 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_bindings::script_runtime::temp_cx;
25use script_traits::{NewPipelineInfo, UpdatePipelineIdReason};
26use servo_url::ServoUrl;
27use style::attr::{AttrValue, LengthOrPercentageOrAuto};
28use stylo_atoms::Atom;
29
30use crate::document_loader::{LoadBlocker, LoadType};
31use crate::dom::attr::Attr;
32use crate::dom::bindings::cell::DomRefCell;
33use crate::dom::bindings::codegen::Bindings::HTMLIFrameElementBinding::HTMLIFrameElementMethods;
34use crate::dom::bindings::codegen::Bindings::WindowBinding::Window_Binding::WindowMethods;
35use crate::dom::bindings::codegen::UnionTypes::TrustedHTMLOrString;
36use crate::dom::bindings::error::Fallible;
37use crate::dom::bindings::inheritance::Castable;
38use crate::dom::bindings::reflector::DomGlobal;
39use crate::dom::bindings::root::{DomRoot, LayoutDom, MutNullableDom};
40use crate::dom::bindings::str::{DOMString, USVString};
41use crate::dom::document::Document;
42use crate::dom::domtokenlist::DOMTokenList;
43use crate::dom::element::{
44 AttributeMutation, Element, LayoutElementHelpers, reflect_referrer_policy_attribute,
45};
46use crate::dom::eventtarget::EventTarget;
47use crate::dom::globalscope::GlobalScope;
48use crate::dom::html::htmlelement::HTMLElement;
49use crate::dom::node::{BindContext, Node, NodeDamage, NodeTraits, UnbindContext};
50use crate::dom::performance::performanceresourcetiming::InitiatorType;
51use crate::dom::trustedtypes::trustedhtml::TrustedHTML;
52use crate::dom::virtualmethods::VirtualMethods;
53use crate::dom::windowproxy::WindowProxy;
54use crate::network_listener::ResourceTimingListener;
55use crate::script_runtime::CanGc;
56use crate::script_thread::{ScriptThread, with_script_thread};
57use crate::script_window_proxies::ScriptWindowProxies;
58
59#[derive(PartialEq)]
60enum PipelineType {
61 InitialAboutBlank,
62 Navigation,
63}
64
65#[derive(PartialEq)]
66enum ProcessingMode {
67 FirstTime,
68 NotFirstTime,
69}
70
71/// <https://html.spec.whatwg.org/multipage/#lazy-load-resumption-steps>
72#[derive(Clone, Copy, Default, MallocSizeOf, PartialEq)]
73enum LazyLoadResumptionSteps {
74 #[default]
75 None,
76 SrcDoc,
77}
78
79#[dom_struct]
80pub(crate) struct HTMLIFrameElement {
81 htmlelement: HTMLElement,
82 #[no_trace]
83 webview_id: Cell<Option<WebViewId>>,
84 #[no_trace]
85 browsing_context_id: Cell<Option<BrowsingContextId>>,
86 #[no_trace]
87 pipeline_id: Cell<Option<PipelineId>>,
88 #[no_trace]
89 pending_pipeline_id: Cell<Option<PipelineId>>,
90 #[no_trace]
91 about_blank_pipeline_id: Cell<Option<PipelineId>>,
92 sandbox: MutNullableDom<DOMTokenList>,
93 #[no_trace]
94 sandboxing_flag_set: Cell<Option<SandboxingFlagSet>>,
95 load_blocker: DomRefCell<Option<LoadBlocker>>,
96 throttled: Cell<bool>,
97 #[conditional_malloc_size_of]
98 script_window_proxies: Rc<ScriptWindowProxies>,
99 /// <https://html.spec.whatwg.org/multipage/#current-navigation-was-lazy-loaded>
100 current_navigation_was_lazy_loaded: Cell<bool>,
101 /// <https://html.spec.whatwg.org/multipage/#lazy-load-resumption-steps>
102 #[no_trace]
103 lazy_load_resumption_steps: Cell<LazyLoadResumptionSteps>,
104 /// Keeping track of whether the iframe will be navigated
105 /// outside of the processing of it's attribute(for example: form navigation).
106 /// This is necessary to prevent the iframe load event steps
107 /// from asynchronously running for the initial blank document
108 /// while script at this point(when the flag is set)
109 /// expects those to run only for the navigated documented.
110 pending_navigation: Cell<bool>,
111 /// Whether a load event was synchronously fired, for example when
112 /// an empty iframe is attached. In that case, we shouldn't fire a
113 /// subsequent asynchronous load event.
114 already_fired_synchronous_load_event: Cell<bool>,
115}
116
117impl HTMLIFrameElement {
118 /// <https://html.spec.whatwg.org/multipage/#shared-attribute-processing-steps-for-iframe-and-frame-elements>,
119 fn shared_attribute_processing_steps_for_iframe_and_frame_elements(&self) -> Option<ServoUrl> {
120 let element = self.upcast::<Element>();
121 // Step 2. If element has a src attribute specified, and its value is not the empty string, then:
122 let url = element
123 .get_attribute(&local_name!("src"))
124 .and_then(|src| {
125 let url = src.value();
126 if url.is_empty() {
127 None
128 } else {
129 // Step 2.1. Let maybeURL be the result of encoding-parsing a URL given that attribute's value,
130 // relative to element's node document.
131 // Step 2.2. If maybeURL is not failure, then set url to maybeURL.
132 self.owner_document().base_url().join(&url).ok()
133 }
134 })
135 // Step 1. Let url be the URL record about:blank.
136 .unwrap_or_else(|| ServoUrl::parse("about:blank").unwrap());
137 // Step 3. If the inclusive ancestor navigables of element's node navigable contains
138 // a navigable whose active document's URL equals url with exclude fragments set to true, then return null.
139 // TODO
140
141 // Step 4. If url matches about:blank and initialInsertion is true, then perform the URL and history update steps
142 // given element's content navigable's active document and url.
143 // TODO
144
145 // Step 5. Return url.
146 Some(url)
147 }
148
149 pub(crate) fn navigate_or_reload_child_browsing_context(
150 &self,
151 load_data: LoadData,
152 history_handling: NavigationHistoryBehavior,
153 cx: &mut js::context::JSContext,
154 ) {
155 // In case we fired a synchronous load event, but navigate away
156 // in the event listener of that event, then we should still
157 // fire a second asynchronous load event when that navigation
158 // finishes. Therefore, on any navigation (but not the initial
159 // about blank), we should always set this to false, regardless
160 // of whether we synchronously fired a load in the same microtask.
161 self.already_fired_synchronous_load_event.set(false);
162
163 self.start_new_pipeline(load_data, PipelineType::Navigation, history_handling, cx);
164 }
165
166 fn start_new_pipeline(
167 &self,
168 mut load_data: LoadData,
169 pipeline_type: PipelineType,
170 history_handling: NavigationHistoryBehavior,
171 cx: &mut js::context::JSContext,
172 ) {
173 let browsing_context_id = match self.browsing_context_id() {
174 None => return warn!("Attempted to start a new pipeline on an unattached iframe."),
175 Some(id) => id,
176 };
177
178 let webview_id = match self.webview_id() {
179 None => return warn!("Attempted to start a new pipeline on an unattached iframe."),
180 Some(id) => id,
181 };
182
183 let document = self.owner_document();
184
185 {
186 let load_blocker = &self.load_blocker;
187 // Any oustanding load is finished from the point of view of the blocked
188 // document; the new navigation will continue blocking it.
189 LoadBlocker::terminate(load_blocker, cx);
190 }
191
192 if load_data.url.scheme() == "javascript" {
193 let window_proxy = self.GetContentWindow();
194 if let Some(window_proxy) = window_proxy {
195 if !ScriptThread::navigate_to_javascript_url(
196 cx,
197 &document.global(),
198 &window_proxy.global(),
199 &mut load_data,
200 Some(self.upcast()),
201 ) {
202 return;
203 }
204 load_data.about_base_url = document.about_base_url();
205 }
206 }
207
208 match load_data.js_eval_result {
209 Some(JsEvalResult::NoContent) => (),
210 _ => {
211 let mut load_blocker = self.load_blocker.borrow_mut();
212 *load_blocker = Some(LoadBlocker::new(
213 &document,
214 LoadType::Subframe(load_data.url.clone()),
215 ));
216 },
217 };
218
219 let window = self.owner_window();
220 let old_pipeline_id = self.pipeline_id();
221 let new_pipeline_id = PipelineId::new();
222 self.pending_pipeline_id.set(Some(new_pipeline_id));
223
224 let load_info = IFrameLoadInfo {
225 parent_pipeline_id: window.pipeline_id(),
226 browsing_context_id,
227 webview_id,
228 new_pipeline_id,
229 is_private: false, // FIXME
230 inherited_secure_context: load_data.inherited_secure_context,
231 history_handling,
232 };
233
234 let viewport_details = window
235 .get_iframe_viewport_details_if_known(browsing_context_id)
236 .unwrap_or_else(|| ViewportDetails {
237 hidpi_scale_factor: window.device_pixel_ratio(),
238 ..Default::default()
239 });
240
241 match pipeline_type {
242 PipelineType::InitialAboutBlank => {
243 self.about_blank_pipeline_id.set(Some(new_pipeline_id));
244
245 let load_info = IFrameLoadInfoWithData {
246 info: load_info,
247 load_data: load_data.clone(),
248 old_pipeline_id,
249 viewport_details,
250 theme: window.theme(),
251 };
252 window
253 .as_global_scope()
254 .script_to_constellation_chan()
255 .send(ScriptToConstellationMessage::ScriptNewIFrame(load_info))
256 .unwrap();
257
258 let new_pipeline_info = NewPipelineInfo {
259 parent_info: Some(window.pipeline_id()),
260 new_pipeline_id,
261 browsing_context_id,
262 webview_id,
263 opener: None,
264 load_data,
265 viewport_details,
266 user_content_manager_id: None,
267 theme: window.theme(),
268 };
269
270 self.pipeline_id.set(Some(new_pipeline_id));
271 with_script_thread(|script_thread| {
272 script_thread.spawn_pipeline(new_pipeline_info);
273 });
274 },
275 PipelineType::Navigation => {
276 let load_info = IFrameLoadInfoWithData {
277 info: load_info,
278 load_data,
279 old_pipeline_id,
280 viewport_details,
281 theme: window.theme(),
282 };
283 window
284 .as_global_scope()
285 .script_to_constellation_chan()
286 .send(ScriptToConstellationMessage::ScriptLoadedURLInIFrame(
287 load_info,
288 ))
289 .unwrap();
290 },
291 }
292 }
293
294 /// When an iframe is first inserted into the document,
295 /// an "about:blank" document is created,
296 /// and synchronously processed by the script thread.
297 /// This initial synchronous load should have no noticeable effect in script.
298 /// See the note in `iframe_load_event_steps`.
299 pub(crate) fn is_initial_blank_document(&self) -> bool {
300 self.pending_pipeline_id.get() == self.about_blank_pipeline_id.get()
301 }
302
303 /// <https://html.spec.whatwg.org/multipage/#navigate-an-iframe-or-frame>
304 fn navigate_an_iframe_or_frame(&self, cx: &mut js::context::JSContext, load_data: LoadData) {
305 // Step 2. If element's content navigable's active document is not completely loaded,
306 // then set historyHandling to "replace".
307 let history_handling = if !self
308 .GetContentDocument()
309 .is_some_and(|doc| doc.completely_loaded())
310 {
311 NavigationHistoryBehavior::Replace
312 } else {
313 // Step 1. Let historyHandling be "auto".
314 NavigationHistoryBehavior::Auto
315 };
316 // Step 3. If element is an iframe, then set element's pending resource-timing start time
317 // to the current high resolution time given element's node document's relevant global object.
318 // TODO
319
320 // Step 4. Navigate element's content navigable to url using element's node document,
321 // with historyHandling set to historyHandling, referrerPolicy set to referrerPolicy,
322 // documentResource set to srcdocString, and initialInsertion set to initialInsertion.
323 self.navigate_or_reload_child_browsing_context(load_data, history_handling, cx);
324 }
325
326 /// <https://html.spec.whatwg.org/multipage/#will-lazy-load-element-steps>
327 fn will_lazy_load_element_steps(&self) -> bool {
328 // Step 1. If scripting is disabled for element, then return false.
329 if !self.owner_document().scripting_enabled() {
330 return false;
331 }
332 // Step 2. If element's lazy loading attribute is in the Lazy state, then return true.
333 // Step 3. Return false.
334 self.Loading() == "lazy"
335 }
336
337 /// Step 1.3. of <https://html.spec.whatwg.org/multipage/#process-the-iframe-attributes>
338 fn navigate_to_the_srcdoc_resource(&self, cx: &mut js::context::JSContext) {
339 // Step 1.3. Navigate to the srcdoc resource: Navigate an iframe or frame given element,
340 // about:srcdoc, the empty string, and the value of element's srcdoc attribute.
341 let url = ServoUrl::parse("about:srcdoc").unwrap();
342 let document = self.owner_document();
343 let window = self.owner_window();
344 let pipeline_id = Some(window.pipeline_id());
345 let mut load_data = LoadData::new(
346 LoadOrigin::Script(document.origin().snapshot()),
347 url,
348 Some(document.base_url()),
349 pipeline_id,
350 window.as_global_scope().get_referrer(),
351 document.get_referrer_policy(),
352 Some(window.as_global_scope().is_secure_context()),
353 Some(document.insecure_requests_policy()),
354 document.has_trustworthy_ancestor_or_current_origin(),
355 self.sandboxing_flag_set(),
356 );
357 load_data.destination = Destination::IFrame;
358 load_data.policy_container = Some(window.as_global_scope().policy_container());
359 load_data.srcdoc = String::from(
360 self.upcast::<Element>()
361 .get_string_attribute(&local_name!("srcdoc")),
362 );
363
364 self.navigate_an_iframe_or_frame(cx, load_data);
365 }
366
367 /// <https://html.spec.whatwg.org/multipage/#the-iframe-element:potentially-delays-the-load-event>
368 fn mark_navigation_as_lazy_loaded(&self, cx: &mut js::context::JSContext) {
369 // > An iframe element whose current navigation was lazy loaded boolean is false potentially delays the load event.
370 self.current_navigation_was_lazy_loaded.set(true);
371 let blocker = &self.load_blocker;
372 LoadBlocker::terminate(blocker, cx);
373 }
374
375 /// <https://html.spec.whatwg.org/multipage/#process-the-iframe-attributes>
376 fn process_the_iframe_attributes(&self, mode: ProcessingMode, cx: &mut js::context::JSContext) {
377 let element = self.upcast::<Element>();
378 // Step 1. If `element`'s `srcdoc` attribute is specified, then:
379 //
380 // Note that this also includes the empty string
381 if element.has_attribute(&local_name!("srcdoc")) {
382 // Step 1.1. Set element's current navigation was lazy loaded boolean to false.
383 self.current_navigation_was_lazy_loaded.set(false);
384 // Step 1.2. If the will lazy load element steps given element return true, then:
385 if self.will_lazy_load_element_steps() {
386 // Step 1.2.1. Set element's lazy load resumption steps to the rest of this algorithm
387 // starting with the step labeled navigate to the srcdoc resource.
388 self.lazy_load_resumption_steps
389 .set(LazyLoadResumptionSteps::SrcDoc);
390 // Step 1.2.2. Set element's current navigation was lazy loaded boolean to true.
391 self.mark_navigation_as_lazy_loaded(cx);
392 // Step 1.2.3. Start intersection-observing a lazy loading element for element.
393 // TODO
394 // Step 1.2.4. Return.
395 return;
396 }
397 // Step 1.3. Navigate to the srcdoc resource: Navigate an iframe or frame given element,
398 // about:srcdoc, the empty string, and the value of element's srcdoc attribute.
399 self.navigate_to_the_srcdoc_resource(cx);
400 return;
401 }
402
403 let window = self.owner_window();
404
405 // https://html.spec.whatwg.org/multipage/#attr-iframe-name
406 // Note: the spec says to set the name 'when the nested browsing context is created'.
407 // The current implementation sets the name on the window,
408 // when the iframe attributes are first processed.
409 if mode == ProcessingMode::FirstTime {
410 if let Some(window) = self.GetContentWindow() {
411 window.set_name(
412 element
413 .get_name()
414 .map_or(DOMString::from(""), |n| DOMString::from(&*n)),
415 );
416 }
417 }
418
419 // Step 2.1. Let url be the result of running the shared attribute processing steps
420 // for iframe and frame elements given element and initialInsertion.
421 let Some(url) = self.shared_attribute_processing_steps_for_iframe_and_frame_elements()
422 else {
423 // Step 2.2. If url is null, then return.
424 return;
425 };
426
427 // Step 2.3. If url matches about:blank and initialInsertion is true, then:
428 if url.matches_about_blank() && mode == ProcessingMode::FirstTime {
429 // We should **not** send a load event in `iframe_load_event_steps`.
430 self.already_fired_synchronous_load_event.set(true);
431 // Step 2.3.1. Run the iframe load event steps given element.
432 //
433 // Note: we are not actually calling that method. That's because
434 // `iframe_load_event_steps` currently doesn't adhere to the spec
435 // at all. In this case, WPT tests only care about the load event,
436 // so we can fire that. Following https://github.com/servo/servo/issues/31973
437 // we should call `iframe_load_event_steps` once it is spec-compliant.
438 self.upcast::<EventTarget>()
439 .fire_event(atom!("load"), CanGc::from_cx(cx));
440 // Step 2.3.2. Return.
441 return;
442 }
443
444 // Step 2.4: Let referrerPolicy be the current state of element's referrerpolicy content
445 // attribute.
446 let document = self.owner_document();
447 let referrer_policy_token = self.ReferrerPolicy();
448
449 // Note: despite not being explicitly stated in the spec steps, this falls back to
450 // document's referrer policy here because it satisfies the expectations that when unset,
451 // the iframe should inherit the referrer policy of its parent
452 let referrer_policy = match ReferrerPolicy::from(&*referrer_policy_token.str()) {
453 ReferrerPolicy::EmptyString => document.get_referrer_policy(),
454 policy => policy,
455 };
456
457 // TODO(#25748):
458 // By spec, we return early if there's an ancestor browsing context
459 // "whose active document's url, ignoring fragments, is equal".
460 // However, asking about ancestor browsing contexts is more nuanced than
461 // it sounds and not implemented here.
462 // Within a single origin, we can do it by walking window proxies,
463 // and this check covers only that single-origin case, protecting
464 // against simple typo self-includes but nothing more elaborate.
465 let mut ancestor = window.GetParent();
466 while let Some(a) = ancestor {
467 if let Some(ancestor_url) = a.document().map(|d| d.url()) {
468 if ancestor_url.scheme() == url.scheme() &&
469 ancestor_url.username() == url.username() &&
470 ancestor_url.password() == url.password() &&
471 ancestor_url.host() == url.host() &&
472 ancestor_url.port() == url.port() &&
473 ancestor_url.path() == url.path() &&
474 ancestor_url.query() == url.query()
475 {
476 return;
477 }
478 }
479 ancestor = a.parent().map(DomRoot::from_ref);
480 }
481
482 let (creator_pipeline_id, about_base_url) = if url.matches_about_blank() {
483 (Some(window.pipeline_id()), Some(document.base_url()))
484 } else {
485 (None, document.about_base_url())
486 };
487
488 let propagate_encoding_to_child_document = url.origin().same_origin(window.origin());
489 let mut load_data = LoadData::new(
490 LoadOrigin::Script(document.origin().snapshot()),
491 url,
492 about_base_url,
493 creator_pipeline_id,
494 window.as_global_scope().get_referrer(),
495 referrer_policy,
496 Some(window.as_global_scope().is_secure_context()),
497 Some(document.insecure_requests_policy()),
498 document.has_trustworthy_ancestor_or_current_origin(),
499 self.sandboxing_flag_set(),
500 );
501 load_data.destination = Destination::IFrame;
502 load_data.policy_container = Some(window.as_global_scope().policy_container());
503 if propagate_encoding_to_child_document {
504 load_data.container_document_encoding = Some(document.encoding());
505 }
506
507 let pipeline_id = self.pipeline_id();
508 // If the initial `about:blank` page is the current page, load with replacement enabled,
509 // see https://html.spec.whatwg.org/multipage/#the-iframe-element:about:blank-3
510 let is_about_blank =
511 pipeline_id.is_some() && pipeline_id == self.about_blank_pipeline_id.get();
512
513 let history_handling = if is_about_blank {
514 NavigationHistoryBehavior::Replace
515 } else {
516 NavigationHistoryBehavior::Push
517 };
518
519 self.navigate_or_reload_child_browsing_context(load_data, history_handling, cx);
520 }
521
522 /// <https://html.spec.whatwg.org/multipage/#create-a-new-child-navigable>
523 /// Synchronously create a new browsing context(This is not a navigation).
524 /// The pipeline started here should remain unnoticeable to script, but this is not easy
525 /// to refactor because it appears other features have come to rely on the current behavior.
526 /// For now only the iframe load event steps are skipped in some cases for this initial document,
527 /// and we still fire load and pageshow events as part of `maybe_queue_document_completion`.
528 /// Also, some controversy spec-wise remains: <https://github.com/whatwg/html/issues/4965>
529 fn create_nested_browsing_context(&self, cx: &mut js::context::JSContext) {
530 let url = ServoUrl::parse("about:blank").unwrap();
531 let document = self.owner_document();
532 let window = self.owner_window();
533 let pipeline_id = Some(window.pipeline_id());
534 let mut load_data = LoadData::new(
535 LoadOrigin::Script(document.origin().snapshot()),
536 url,
537 Some(document.base_url()),
538 pipeline_id,
539 window.as_global_scope().get_referrer(),
540 document.get_referrer_policy(),
541 Some(window.as_global_scope().is_secure_context()),
542 Some(document.insecure_requests_policy()),
543 document.has_trustworthy_ancestor_or_current_origin(),
544 self.sandboxing_flag_set(),
545 );
546 load_data.destination = Destination::IFrame;
547 load_data.policy_container = Some(window.as_global_scope().policy_container());
548
549 let browsing_context_id = BrowsingContextId::new();
550 let webview_id = window.window_proxy().webview_id();
551 self.pipeline_id.set(None);
552 self.pending_pipeline_id.set(None);
553 self.webview_id.set(Some(webview_id));
554 self.browsing_context_id.set(Some(browsing_context_id));
555 self.start_new_pipeline(
556 load_data,
557 PipelineType::InitialAboutBlank,
558 NavigationHistoryBehavior::Push,
559 cx,
560 );
561 }
562
563 fn destroy_nested_browsing_context(&self) {
564 self.pipeline_id.set(None);
565 self.pending_pipeline_id.set(None);
566 self.about_blank_pipeline_id.set(None);
567 self.webview_id.set(None);
568 if let Some(browsing_context_id) = self.browsing_context_id.take() {
569 self.script_window_proxies.remove(browsing_context_id)
570 }
571 }
572
573 pub(crate) fn update_pipeline_id(
574 &self,
575 new_pipeline_id: PipelineId,
576 reason: UpdatePipelineIdReason,
577 cx: &mut js::context::JSContext,
578 ) {
579 // For all updates except the one for the initial blank document,
580 // we need to set the flag back to false because the navigation is complete,
581 // because the goal is to, when a navigation is pending, to skip the async load
582 // steps of the initial blank document.
583 if !self.is_initial_blank_document() {
584 self.pending_navigation.set(false);
585 }
586 if self.pending_pipeline_id.get() != Some(new_pipeline_id) &&
587 reason == UpdatePipelineIdReason::Navigation
588 {
589 return;
590 }
591
592 self.pipeline_id.set(Some(new_pipeline_id));
593
594 // Only terminate the load blocker if the pipeline id was updated due to a traversal.
595 // The load blocker will be terminated for a navigation in iframe_load_event_steps.
596 if reason == UpdatePipelineIdReason::Traversal {
597 let blocker = &self.load_blocker;
598 LoadBlocker::terminate(blocker, cx);
599 }
600
601 self.upcast::<Node>().dirty(NodeDamage::Other);
602 }
603
604 fn new_inherited(
605 local_name: LocalName,
606 prefix: Option<Prefix>,
607 document: &Document,
608 ) -> HTMLIFrameElement {
609 HTMLIFrameElement {
610 htmlelement: HTMLElement::new_inherited(local_name, prefix, document),
611 browsing_context_id: Cell::new(None),
612 webview_id: Cell::new(None),
613 pipeline_id: Cell::new(None),
614 pending_pipeline_id: Cell::new(None),
615 about_blank_pipeline_id: Cell::new(None),
616 sandbox: Default::default(),
617 sandboxing_flag_set: Cell::new(None),
618 load_blocker: DomRefCell::new(None),
619 throttled: Cell::new(false),
620 script_window_proxies: ScriptThread::window_proxies(),
621 current_navigation_was_lazy_loaded: Default::default(),
622 lazy_load_resumption_steps: Default::default(),
623 pending_navigation: Default::default(),
624 already_fired_synchronous_load_event: Default::default(),
625 }
626 }
627
628 pub(crate) fn new(
629 local_name: LocalName,
630 prefix: Option<Prefix>,
631 document: &Document,
632 proto: Option<HandleObject>,
633 can_gc: CanGc,
634 ) -> DomRoot<HTMLIFrameElement> {
635 Node::reflect_node_with_proto(
636 Box::new(HTMLIFrameElement::new_inherited(
637 local_name, prefix, document,
638 )),
639 document,
640 proto,
641 can_gc,
642 )
643 }
644
645 #[inline]
646 pub(crate) fn pipeline_id(&self) -> Option<PipelineId> {
647 self.pipeline_id.get()
648 }
649
650 #[inline]
651 pub(crate) fn browsing_context_id(&self) -> Option<BrowsingContextId> {
652 self.browsing_context_id.get()
653 }
654
655 #[inline]
656 pub(crate) fn webview_id(&self) -> Option<WebViewId> {
657 self.webview_id.get()
658 }
659
660 #[inline]
661 pub(crate) fn sandboxing_flag_set(&self) -> SandboxingFlagSet {
662 self.sandboxing_flag_set
663 .get()
664 .unwrap_or_else(SandboxingFlagSet::empty)
665 }
666
667 pub(crate) fn set_throttled(&self, throttled: bool) {
668 if self.throttled.get() != throttled {
669 self.throttled.set(throttled);
670 }
671 }
672
673 /// Note a pending navigation.
674 /// This is used to ignore the async load event steps for
675 /// the initial blank document if those haven't run yet.
676 pub(crate) fn note_pending_navigation(&self) {
677 self.pending_navigation.set(true);
678 }
679
680 /// <https://html.spec.whatwg.org/multipage/#iframe-load-event-steps>
681 pub(crate) fn iframe_load_event_steps(
682 &self,
683 loaded_pipeline: PipelineId,
684 cx: &mut js::context::JSContext,
685 ) {
686 // TODO(#9592): assert that the load blocker is present at all times when we
687 // can guarantee that it's created for the case of iframe.reload().
688 if Some(loaded_pipeline) != self.pending_pipeline_id.get() {
689 return;
690 }
691
692 // TODO 1. Assert: element's content navigable is not null.
693
694 // TODO 2-4 Mark resource timing.
695
696 // TODO 5 Set childDocument's iframe load in progress flag.
697
698 // Note: in the spec, these steps are either run synchronously as part of
699 // "If url matches about:blank and initialInsertion is true, then:"
700 // in `process the iframe attributes`,
701 // or asynchronously when navigation completes.
702 //
703 // In our current implementation,
704 // we arrive here always asynchronously in the following two cases:
705 // 1. as part of loading the initial blank document
706 // created in `create_nested_browsing_context`
707 // 2. optionally, as part of loading a second document created as
708 // as part of the first processing of the iframe attributes.
709 //
710 // To preserve the logic of the spec--firing the load event once--in the context of
711 // our current implementation, we must not fire the load event
712 // for the initial blank document if we know that a navigation is ongoing,
713 // which can be deducted from `pending_navigation` or the presence of an src.
714 //
715 // Additionally, to prevent a race condition with navigations,
716 // in all cases, skip the load event if there is a pending navigation.
717 // See #40348
718 //
719 // TODO: run these step synchronously as part of processing the iframe attributes.
720 let should_fire_event = if self.is_initial_blank_document() {
721 // If this is the initial blank doc:
722 // do not fire if there is a pending navigation,
723 // or if the iframe has an src.
724 !self.pending_navigation.get() &&
725 !self.upcast::<Element>().has_attribute(&local_name!("src"))
726 } else {
727 // If this is not the initial blank doc:
728 // do not fire if there is a pending navigation.
729 !self.pending_navigation.get()
730 };
731 // If we already fired a synchronous load event, we shouldn't fire another
732 // one in this method.
733 let should_fire_event =
734 !self.already_fired_synchronous_load_event.replace(false) && should_fire_event;
735 if should_fire_event {
736 // Step 6. Fire an event named load at element.
737 self.upcast::<EventTarget>()
738 .fire_event(atom!("load"), CanGc::from_cx(cx));
739 }
740
741 let blocker = &self.load_blocker;
742 LoadBlocker::terminate(blocker, cx);
743
744 // TODO Step 7 - unset child document `mute iframe load` flag
745 }
746
747 /// Parse the `sandbox` attribute value given the [`Attr`]. This sets the `sandboxing_flag_set`
748 /// property or clears it is the value isn't specified. Notably, an unspecified sandboxing
749 /// attribute (no sandboxing) is different from an empty one (full sandboxing).
750 fn parse_sandbox_attribute(&self) {
751 let attribute = self
752 .upcast::<Element>()
753 .get_attribute(&local_name!("sandbox"));
754 self.sandboxing_flag_set
755 .set(attribute.map(|attribute_value| {
756 let tokens: Vec<_> = attribute_value
757 .value()
758 .as_tokens()
759 .iter()
760 .map(|atom| atom.to_string().to_ascii_lowercase())
761 .collect();
762 parse_a_sandboxing_directive(&tokens)
763 }));
764 }
765
766 /// Step 4.2. of <https://html.spec.whatwg.org/multipage/#destroy-a-document-and-its-descendants>
767 pub(crate) fn destroy_document_and_its_descendants(&self, cx: &mut js::context::JSContext) {
768 let Some(pipeline_id) = self.pipeline_id.get() else {
769 return;
770 };
771 // Step 4.2. Destroy a document and its descendants given childNavigable's active document and incrementDestroyed.
772 if let Some(exited_document) = ScriptThread::find_document(pipeline_id) {
773 exited_document.destroy_document_and_its_descendants(cx);
774 }
775 self.destroy_nested_browsing_context();
776 }
777
778 /// <https://html.spec.whatwg.org/multipage/#destroy-a-child-navigable>
779 fn destroy_child_navigable(&self, cx: &mut js::context::JSContext) {
780 let blocker = &self.load_blocker;
781 LoadBlocker::terminate(blocker, cx);
782
783 // Step 1. Let navigable be container's content navigable.
784 let Some(browsing_context_id) = self.browsing_context_id() else {
785 // Step 2. If navigable is null, then return.
786 return;
787 };
788 // Store now so that we can destroy the context and delete the
789 // document later
790 let pipeline_id = self.pipeline_id.get();
791
792 // Step 3. Set container's content navigable to null.
793 //
794 // Resetting the pipeline_id to None is required here so that
795 // if this iframe is subsequently re-added to the document
796 // the load doesn't think that it's a navigation, but instead
797 // a new iframe. Without this, the constellation gets very
798 // confused.
799 self.destroy_nested_browsing_context();
800
801 // Step 4. Inform the navigation API about child navigable destruction given navigable.
802 // TODO
803
804 // Step 5. Destroy a document and its descendants given navigable's active document.
805 let (sender, receiver) =
806 ProfiledIpc::channel(self.global().time_profiler_chan().clone()).unwrap();
807 let msg = ScriptToConstellationMessage::RemoveIFrame(browsing_context_id, sender);
808 self.owner_window()
809 .as_global_scope()
810 .script_to_constellation_chan()
811 .send(msg)
812 .unwrap();
813 let _exited_pipeline_ids = receiver.recv().unwrap();
814 let Some(pipeline_id) = pipeline_id else {
815 return;
816 };
817 if let Some(exited_document) = ScriptThread::find_document(pipeline_id) {
818 exited_document.destroy_document_and_its_descendants(cx);
819 }
820
821 // Step 6. Let parentDocState be container's node navigable's active session history entry's document state.
822 // TODO
823
824 // Step 7. Remove the nested history from parentDocState's nested histories whose id equals navigable's id.
825 // TODO
826
827 // Step 8. Let traversable be container's node navigable's traversable navigable.
828 // TODO
829
830 // Step 9. Append the following session history traversal steps to traversable:
831 // TODO
832
833 // Step 10. Invoke WebDriver BiDi navigable destroyed with navigable.
834 // TODO
835 }
836}
837
838pub(crate) trait HTMLIFrameElementLayoutMethods {
839 fn pipeline_id(self) -> Option<PipelineId>;
840 fn browsing_context_id(self) -> Option<BrowsingContextId>;
841 fn get_width(self) -> LengthOrPercentageOrAuto;
842 fn get_height(self) -> LengthOrPercentageOrAuto;
843}
844
845impl HTMLIFrameElementLayoutMethods for LayoutDom<'_, HTMLIFrameElement> {
846 #[inline]
847 fn pipeline_id(self) -> Option<PipelineId> {
848 (self.unsafe_get()).pipeline_id.get()
849 }
850
851 #[inline]
852 fn browsing_context_id(self) -> Option<BrowsingContextId> {
853 (self.unsafe_get()).browsing_context_id.get()
854 }
855
856 fn get_width(self) -> LengthOrPercentageOrAuto {
857 self.upcast::<Element>()
858 .get_attr_for_layout(&ns!(), &local_name!("width"))
859 .map(AttrValue::as_dimension)
860 .cloned()
861 .unwrap_or(LengthOrPercentageOrAuto::Auto)
862 }
863
864 fn get_height(self) -> LengthOrPercentageOrAuto {
865 self.upcast::<Element>()
866 .get_attr_for_layout(&ns!(), &local_name!("height"))
867 .map(AttrValue::as_dimension)
868 .cloned()
869 .unwrap_or(LengthOrPercentageOrAuto::Auto)
870 }
871}
872
873impl HTMLIFrameElementMethods<crate::DomTypeHolder> for HTMLIFrameElement {
874 // https://html.spec.whatwg.org/multipage/#dom-iframe-src
875 make_url_getter!(Src, "src");
876
877 // https://html.spec.whatwg.org/multipage/#dom-iframe-src
878 make_url_setter!(SetSrc, "src");
879
880 /// <https://html.spec.whatwg.org/multipage/#dom-iframe-srcdoc>
881 fn Srcdoc(&self) -> TrustedHTMLOrString {
882 let element = self.upcast::<Element>();
883 element.get_trusted_html_attribute(&local_name!("srcdoc"))
884 }
885
886 /// <https://html.spec.whatwg.org/multipage/#dom-iframe-srcdoc>
887 fn SetSrcdoc(&self, value: TrustedHTMLOrString, can_gc: CanGc) -> Fallible<()> {
888 // Step 1: Let compliantString be the result of invoking the
889 // Get Trusted Type compliant string algorithm with TrustedHTML,
890 // this's relevant global object, the given value, "HTMLIFrameElement srcdoc", and "script".
891 let element = self.upcast::<Element>();
892 let value = TrustedHTML::get_trusted_script_compliant_string(
893 &element.owner_global(),
894 value,
895 "HTMLIFrameElement srcdoc",
896 can_gc,
897 )?;
898 // Step 2: Set an attribute value given this, srcdoc's local name, and compliantString.
899 element.set_attribute(
900 &local_name!("srcdoc"),
901 AttrValue::String(value.str().to_owned()),
902 can_gc,
903 );
904 Ok(())
905 }
906
907 /// <https://html.spec.whatwg.org/multipage/#dom-iframe-sandbox>
908 ///
909 /// The supported tokens for sandbox's DOMTokenList are the allowed values defined in the
910 /// sandbox attribute and supported by the user agent. These range of possible values is
911 /// defined here: <https://html.spec.whatwg.org/multipage/#attr-iframe-sandbox>
912 fn Sandbox(&self, can_gc: CanGc) -> DomRoot<DOMTokenList> {
913 self.sandbox.or_init(|| {
914 DOMTokenList::new(
915 self.upcast::<Element>(),
916 &local_name!("sandbox"),
917 Some(vec![
918 Atom::from("allow-downloads"),
919 Atom::from("allow-forms"),
920 Atom::from("allow-modals"),
921 Atom::from("allow-orientation-lock"),
922 Atom::from("allow-pointer-lock"),
923 Atom::from("allow-popups"),
924 Atom::from("allow-popups-to-escape-sandbox"),
925 Atom::from("allow-presentation"),
926 Atom::from("allow-same-origin"),
927 Atom::from("allow-scripts"),
928 Atom::from("allow-top-navigation"),
929 Atom::from("allow-top-navigation-by-user-activation"),
930 Atom::from("allow-top-navigation-to-custom-protocols"),
931 ]),
932 can_gc,
933 )
934 })
935 }
936
937 /// <https://html.spec.whatwg.org/multipage/#dom-iframe-contentwindow>
938 fn GetContentWindow(&self) -> Option<DomRoot<WindowProxy>> {
939 self.browsing_context_id
940 .get()
941 .and_then(|id| self.script_window_proxies.find_window_proxy(id))
942 }
943
944 /// <https://html.spec.whatwg.org/multipage/#concept-bcc-content-document>
945 fn GetContentDocument(&self) -> Option<DomRoot<Document>> {
946 // Step 1. If container's content navigable is null, then return null.
947 let pipeline_id = self.pipeline_id.get()?;
948
949 // Step 2. Let document be container's content navigable's active document.
950 // Note that this lookup will fail if the document is dissimilar-origin,
951 // so we should return None in that case.
952 let document = ScriptThread::find_document(pipeline_id)?;
953 // Step 3. If document's origin and container's node document's origin are not same origin-domain, then return null.
954 if !self
955 .owner_document()
956 .origin()
957 .same_origin_domain(document.origin())
958 {
959 return None;
960 }
961 // Step 4. Return document.
962 Some(document)
963 }
964
965 /// <https://html.spec.whatwg.org/multipage/#attr-iframe-referrerpolicy>
966 fn ReferrerPolicy(&self) -> DOMString {
967 reflect_referrer_policy_attribute(self.upcast::<Element>())
968 }
969
970 // https://html.spec.whatwg.org/multipage/#attr-iframe-referrerpolicy
971 make_setter!(SetReferrerPolicy, "referrerpolicy");
972
973 // https://html.spec.whatwg.org/multipage/#attr-iframe-allowfullscreen
974 make_bool_getter!(AllowFullscreen, "allowfullscreen");
975 // https://html.spec.whatwg.org/multipage/#attr-iframe-allowfullscreen
976 make_bool_setter!(SetAllowFullscreen, "allowfullscreen");
977
978 // <https://html.spec.whatwg.org/multipage/#dom-dim-width>
979 make_getter!(Width, "width");
980 // <https://html.spec.whatwg.org/multipage/#dom-dim-width>
981 make_dimension_setter!(SetWidth, "width");
982
983 // <https://html.spec.whatwg.org/multipage/#dom-dim-height>
984 make_getter!(Height, "height");
985 // <https://html.spec.whatwg.org/multipage/#dom-dim-height>
986 make_dimension_setter!(SetHeight, "height");
987
988 // https://html.spec.whatwg.org/multipage/#other-elements,-attributes-and-apis:attr-iframe-frameborder
989 make_getter!(FrameBorder, "frameborder");
990 // https://html.spec.whatwg.org/multipage/#other-elements,-attributes-and-apis:attr-iframe-frameborder
991 make_setter!(SetFrameBorder, "frameborder");
992
993 // https://html.spec.whatwg.org/multipage/#dom-iframe-name
994 // A child browsing context checks the name of its iframe only at the time
995 // it is created; subsequent name sets have no special effect.
996 make_atomic_setter!(SetName, "name");
997
998 // https://html.spec.whatwg.org/multipage/#dom-iframe-name
999 // This is specified as reflecting the name content attribute of the
1000 // element, not the name of the child browsing context.
1001 make_getter!(Name, "name");
1002
1003 // https://html.spec.whatwg.org/multipage/#attr-iframe-loading
1004 // > The loading attribute is a lazy loading attribute. Its purpose is to indicate the policy for loading iframe elements that are outside the viewport.
1005 make_enumerated_getter!(
1006 Loading,
1007 "loading",
1008 "lazy" | "eager",
1009 // https://html.spec.whatwg.org/multipage/#lazy-loading-attribute
1010 // > The attribute's missing value default and invalid value default are both the Eager state.
1011 missing => "eager",
1012 invalid => "eager"
1013 );
1014
1015 // https://html.spec.whatwg.org/multipage/#attr-iframe-loading
1016 make_setter!(SetLoading, "loading");
1017}
1018
1019impl VirtualMethods for HTMLIFrameElement {
1020 fn super_type(&self) -> Option<&dyn VirtualMethods> {
1021 Some(self.upcast::<HTMLElement>() as &dyn VirtualMethods)
1022 }
1023
1024 #[expect(unsafe_code)]
1025 fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation, _can_gc: CanGc) {
1026 // TODO: https://github.com/servo/servo/issues/42812
1027 let mut cx = unsafe { temp_cx() };
1028 let cx = &mut cx;
1029 self.super_type()
1030 .unwrap()
1031 .attribute_mutated(attr, mutation, CanGc::from_cx(cx));
1032 match *attr.local_name() {
1033 // From <https://html.spec.whatwg.org/multipage/#attr-iframe-sandbox>:
1034 //
1035 // > When an iframe element's sandbox attribute is set or changed while
1036 // > it has a non-null content navigable, the user agent must parse the
1037 // > sandboxing directive given the attribute's value and the iframe
1038 // > element's iframe sandboxing flag set.
1039 //
1040 // > When an iframe element's sandbox attribute is removed while it has
1041 // > a non-null content navigable, the user agent must empty the iframe
1042 // > element's iframe sandboxing flag set.
1043 local_name!("sandbox") if self.browsing_context_id.get().is_some() => {
1044 self.parse_sandbox_attribute();
1045 },
1046 local_name!("srcdoc") => {
1047 // https://html.spec.whatwg.org/multipage/#the-iframe-element:the-iframe-element-9
1048 // "Whenever an iframe element with a non-null nested browsing context has its
1049 // srcdoc attribute set, changed, or removed, the user agent must process the
1050 // iframe attributes."
1051 // but we can't check that directly, since the child browsing context
1052 // may be in a different script thread. Instead, we check to see if the parent
1053 // is in a document tree and has a browsing context, which is what causes
1054 // the child browsing context to be created.
1055
1056 // trigger the processing of iframe attributes whenever "srcdoc" attribute is set, changed or removed
1057 if self.upcast::<Node>().is_connected_with_browsing_context() {
1058 debug!("iframe srcdoc modified while in browsing context.");
1059 self.process_the_iframe_attributes(ProcessingMode::NotFirstTime, cx);
1060 }
1061 },
1062 local_name!("src") => {
1063 // https://html.spec.whatwg.org/multipage/#the-iframe-element
1064 // "Similarly, whenever an iframe element with a non-null nested browsing context
1065 // but with no srcdoc attribute specified has its src attribute set, changed, or removed,
1066 // the user agent must process the iframe attributes,"
1067 // but we can't check that directly, since the child browsing context
1068 // may be in a different script thread. Instead, we check to see if the parent
1069 // is in a document tree and has a browsing context, which is what causes
1070 // the child browsing context to be created.
1071 if self.upcast::<Node>().is_connected_with_browsing_context() {
1072 debug!("iframe src set while in browsing context.");
1073 self.process_the_iframe_attributes(ProcessingMode::NotFirstTime, cx);
1074 }
1075 },
1076 local_name!("loading") => {
1077 // https://html.spec.whatwg.org/multipage/#attr-iframe-loading
1078 // > When the loading attribute's state is changed to the Eager state, the user agent must run these steps:
1079 if !mutation.is_removal() && &**attr.value() == "lazy" {
1080 return;
1081 }
1082
1083 // Step 1. Let resumptionSteps be the iframe element's lazy load resumption steps.
1084 // Step 3. Set the iframe's lazy load resumption steps to null.
1085 let previous_resumption_steps = self
1086 .lazy_load_resumption_steps
1087 .replace(LazyLoadResumptionSteps::None);
1088 match previous_resumption_steps {
1089 // Step 2. If resumptionSteps is null, then return.
1090 LazyLoadResumptionSteps::None => (),
1091 LazyLoadResumptionSteps::SrcDoc => {
1092 // Step 4. Invoke resumptionSteps.
1093 self.navigate_to_the_srcdoc_resource(cx);
1094 },
1095 }
1096 },
1097 _ => {},
1098 }
1099 }
1100
1101 fn attribute_affects_presentational_hints(&self, attr: &Attr) -> bool {
1102 match attr.local_name() {
1103 &local_name!("width") | &local_name!("height") => true,
1104 _ => self
1105 .super_type()
1106 .unwrap()
1107 .attribute_affects_presentational_hints(attr),
1108 }
1109 }
1110
1111 fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
1112 match *name {
1113 local_name!("sandbox") => AttrValue::from_serialized_tokenlist(value.into()),
1114 local_name!("width") => AttrValue::from_dimension(value.into()),
1115 local_name!("height") => AttrValue::from_dimension(value.into()),
1116 _ => self
1117 .super_type()
1118 .unwrap()
1119 .parse_plain_attribute(name, value),
1120 }
1121 }
1122
1123 /// <https://html.spec.whatwg.org/multipage/#the-iframe-element:html-element-post-connection-steps>
1124 fn post_connection_steps(&self, cx: &mut JSContext) {
1125 if let Some(s) = self.super_type() {
1126 s.post_connection_steps(cx);
1127 }
1128
1129 // This isn't mentioned any longer in the specification, but still seems important. This is
1130 // likely due to the fact that we have deviated a great deal with it comes to navigables
1131 // and browsing contexts.
1132 if !self.upcast::<Node>().is_connected_with_browsing_context() {
1133 return;
1134 }
1135
1136 debug!("<iframe> running post connection steps");
1137
1138 // Step 1. Create a new child navigable for insertedNode.
1139 self.create_nested_browsing_context(cx);
1140
1141 // Step 2: If insertedNode has a sandbox attribute, then parse the sandboxing directive
1142 // given the attribute's value and insertedNode's iframe sandboxing flag set.
1143 self.parse_sandbox_attribute();
1144
1145 // Step 3. Process the iframe attributes for insertedNode, with initialInsertion set to true.
1146 self.process_the_iframe_attributes(ProcessingMode::FirstTime, cx);
1147 }
1148
1149 fn bind_to_tree(&self, context: &BindContext, can_gc: CanGc) {
1150 if let Some(s) = self.super_type() {
1151 s.bind_to_tree(context, can_gc);
1152 }
1153 self.owner_document().invalidate_iframes_collection();
1154 }
1155
1156 /// <https://html.spec.whatwg.org/multipage/#the-iframe-element:html-element-removing-steps>
1157 #[expect(unsafe_code)]
1158 fn unbind_from_tree(&self, context: &UnbindContext, can_gc: CanGc) {
1159 self.super_type().unwrap().unbind_from_tree(context, can_gc);
1160
1161 // TODO: https://github.com/servo/servo/issues/42837
1162 let mut cx = unsafe { temp_cx() };
1163
1164 // The iframe HTML element removing steps, given removedNode, are to destroy a child navigable given removedNode
1165 self.destroy_child_navigable(&mut cx);
1166
1167 self.owner_document().invalidate_iframes_collection();
1168 }
1169}
1170
1171/// IframeContext is a wrapper around [`HTMLIFrameElement`] that implements the [`ResourceTimingListener`] trait.
1172/// Note: this implementation of `resource_timing_global` returns the parent document's global scope, not the iframe's global scope.
1173pub(crate) struct IframeContext<'a> {
1174 // The iframe element that this context is associated with.
1175 element: &'a HTMLIFrameElement,
1176 // The URL of the iframe document.
1177 url: ServoUrl,
1178}
1179
1180impl<'a> IframeContext<'a> {
1181 /// Creates a new IframeContext from a reference to an HTMLIFrameElement.
1182 pub fn new(element: &'a HTMLIFrameElement) -> Self {
1183 Self {
1184 element,
1185 url: element
1186 .shared_attribute_processing_steps_for_iframe_and_frame_elements()
1187 .expect("Must always have a URL when navigating"),
1188 }
1189 }
1190}
1191
1192impl<'a> ResourceTimingListener for IframeContext<'a> {
1193 fn resource_timing_information(&self) -> (InitiatorType, ServoUrl) {
1194 (
1195 InitiatorType::LocalName("iframe".to_string()),
1196 self.url.clone(),
1197 )
1198 }
1199
1200 fn resource_timing_global(&self) -> DomRoot<GlobalScope> {
1201 self.element.upcast::<Node>().owner_doc().global()
1202 }
1203}