Repository: servo/servo
File: components/script/dom/html/htmliframeelement.rs (Rust)

Code before:

    pub(crate) fn set_throttled(&self, throttled: bool) {
        if self.throttled.get() != throttled {
            self.throttled.set(throttled);
        }
    }

    /// Note a pending navigation.
    /// This is used to ignore the async load event steps for
    /// the initial blank document if those haven't run yet.
    pub(crate) fn note_pending_navigation(&self) {
        self.pending_navigation.set(true);
    }

    /// <https://html.spec.whatwg.org/multipage/#iframe-load-event-steps>
    pub(crate) fn iframe_load_event_steps(&self, loaded_pipeline: PipelineId, can_gc: CanGc) {
        // TODO(#9592): assert that the load blocker is present at all times when we
        //              can guarantee that it's created for the case of iframe.reload().
        if Some(loaded_pipeline) != self.pending_pipeline_id.get() {
            return;
        }

        // TODO 1. Assert: element's content navigable is not null.

        // Mark resource timing.
        let document = match ScriptThread::find_document(loaded_pipeline) {
            Some(document) => document,
            None => return,
        };

        let performance_entry = PerformanceResourceTiming::new(
            &document.global(),
            self.get_url(),
            InitiatorType::LocalName("iframe".into()), // <https://w3c.github.io/resource-timing/#dom-performanceresourcetiming-initiatortype>
            None,
            &ResourceFetchTiming::new(ResourceTimingType::Resource),
            can_gc,
        );

        document
            .global()
            .performance()
            .queue_entry(performance_entry.upcast::<PerformanceEntry>());

        // TODO 5 Set childDocument's iframe load in progress flag.

        // Note: in the spec, these steps are either run synchronously as part of
        // "If url matches about:blank and initialInsertion is true, then:"
        // in `process the iframe attributes`,
        // or asynchronously when navigation completes.
        //

Review comment (suggestion):
Step 4.1 says to use the iframe's node document, which is `self.owner_document()`. Right now we're getting the equivalent of child document from the specification.

Code after:
    }

    pub(crate) fn set_throttled(&self, throttled: bool) {
        if self.throttled.get() != throttled {
            self.throttled.set(throttled);
        }
    }

    /// Note a pending navigation.
    /// This is used to ignore the async load event steps for
    /// the initial blank document if those haven't run yet.
    pub(crate) fn note_pending_navigation(&self) {
        self.pending_navigation.set(true);
    }

    /// <https://html.spec.whatwg.org/multipage/#iframe-load-event-steps>
    pub(crate) fn iframe_load_event_steps(&self, loaded_pipeline: PipelineId, can_gc: CanGc) {
        // TODO(#9592): assert that the load blocker is present at all times when we
        //              can guarantee that it's created for the case of iframe.reload().
        if Some(loaded_pipeline) != self.pending_pipeline_id.get() {
            return;
        }

        // TODO 1. Assert: element's content navigable is not null.

        // TODO 2-4 Mark resource timing.

        // TODO 5 Set childDocument's iframe load in progress flag.

        // Note: in the spec, these steps are either run synchronously as part of
        // "If url matches about:blank and initialInsertion is true, then:"
        // in `process the iframe attributes`,
        // or asynchronously when navigation completes.
        //
        // In our current implementation,
        // we arrive here always asynchronously in the following two cases:
        // 1. as part of loading the initial blank document
        //    created in `create_nested_browsing_context`
        // 2. optionally, as part of loading a second document created as
        //    as part of the first processing of the iframe attributes.
        //
        // To preserve the logic of the spec--firing the load event once--in the context of
        // our current implementation, we must not fire the load event
        // for the initial blank document if we know that a navigation is ongoing,
        // which can be deducted from `pending_navigation` or the presence of an src.
        //
        // Additionally, to prevent a race condition with navigations,
        // in all cases, skip the load event if there is a pending navigation.
        // See #40348
        //
        // TODO: run these step synchronously as part of processing the iframe attributes.