Repository: servo/servo
File: components/script/script_thread.rs (Rust)

Code before:
            ctxt.process_response_chunk(request_id, chunk);
        }
    }

    fn handle_fetch_eof(
        &self,
        id: PipelineId,
        request_id: RequestId,
        eof: Result<(), NetworkError>,
        timing: ResourceFetchTiming,
    ) {
        let idx = self
            .incomplete_parser_contexts
            .0
            .borrow()
            .iter()
            .position(|&(pipeline_id, _)| pipeline_id == id);

        if let Some(idx) = idx {
            let (_, context) = self.incomplete_parser_contexts.0.borrow_mut().remove(idx);

            // we need to register an iframe entry to the performance timeline if present
            if let Some(document) = context.get_document()// get the document from the context
                && let Some(window_proxy) = document.browsing_context() // check if there is a window_proxy
                && let Some(frame_element) = window_proxy.frame_element()// retrieval of the frame element if present
                && let Some(frame_element) = frame_element.downcast::<HTMLIFrameElement>()
            {
                let iframe_ctx = IframeContext::new(frame_element);

                // submit_timing will only accept timing that is of type ResourceTimingType::Resource
                let mut resource_timing = timing.clone();
                resource_timing.timing_type = ResourceTimingType::Resource;
                submit_timing(&iframe_ctx, &eof, &resource_timing, CanGc::note());
            }

            context.process_response_eof(request_id, eof, timing);
        }
    }

    fn handle_csp_violations(&self, id: PipelineId, _: RequestId, violations: Vec<Violation>) {
        if let Some(global) = self.documents.borrow().find_global(id) {
            // TODO(https://github.com/w3c/webappsec-csp/issues/687): Update after spec is resolved
            global.report_csp_violations(violations, None, None);
        }
    }

    fn handle_navigation_redirect(&self, id: PipelineId, metadata: &Metadata) {
        // TODO(mrobinson): This tries to accomplish some steps from
        // <https://html.spec.whatwg.org/multipage/#process-a-navigate-fetch>, but it's
        // very out of sync with the specification.
        assert!(metadata.location_url.is_some());

Review comment (bug):
This will fail to build in our minimum supported Rust version, so let's use:
```rust
if let Some(frame_element) = context
    .get_document()
    .and_then(|document| document.browsing_context())
    .and_then(|window_proxy| window_proxy.frame_element())
    .and_then(|frame_element| frame_element.downcast::<HTMLIFrameElement>())
{
    // ...
}
```

Code after:
        }
    }

    fn handle_fetch_eof(
        &self,
        id: PipelineId,
        request_id: RequestId,
        eof: Result<(), NetworkError>,
        timing: ResourceFetchTiming,
    ) {
        let idx = self
            .incomplete_parser_contexts
            .0
            .borrow()
            .iter()
            .position(|&(pipeline_id, _)| pipeline_id == id);

        if let Some(idx) = idx {
            let (_, context) = self.incomplete_parser_contexts.0.borrow_mut().remove(idx);

            // we need to register an iframe entry to the performance timeline if present
            if let Some(window_proxy) = context
                .get_document()
                .and_then(|document| document.browsing_context())
            {
                if let Some(frame_element) = window_proxy.frame_element() {
                    let iframe_ctx = IframeContext::new(
                        frame_element
                            .downcast::<HTMLIFrameElement>()
                            .expect("WindowProxy::frame_element should be an HTMLIFrameElement"),
                    );

                    // submit_timing will only accept timing that is of type ResourceTimingType::Resource
                    let mut resource_timing = timing.clone();
                    resource_timing.timing_type = ResourceTimingType::Resource;
                    submit_timing(&iframe_ctx, &eof, &resource_timing, CanGc::note());
                }
            }

            context.process_response_eof(request_id, eof, timing);
        }
    }

    fn handle_csp_violations(&self, id: PipelineId, _: RequestId, violations: Vec<Violation>) {
        if let Some(global) = self.documents.borrow().find_global(id) {
            // TODO(https://github.com/w3c/webappsec-csp/issues/687): Update after spec is resolved
            global.report_csp_violations(violations, None, None);
        }
    }

    fn handle_navigation_redirect(&self, id: PipelineId, metadata: &Metadata) {