Skip to content

script: Keep blob URLs alive when creating CORS requests in components/script/dom/html/embedded_content/htmlimageelement.rs - #48993

Open
elomscansio wants to merge 2 commits into
servo:mainfrom
elomscansio:Keep-blob-URLs-alive
Open

elomscansio wants to merge 2 commits into
servo:mainfrom
elomscansio:Keep-blob-URLs-alive

Conversation

@elomscansio

@elomscansio elomscansio commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Use ensure_blob_referenced_by_url_is_kept_alive to claim the blob URL in components/script/dom/html/embedded_content/htmlimageelement.rs, and switch from create_a_potential_cors_request to create_a_potential_cors_request_with_claim.

Part of #48892

@jdm jdm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@servo-highfive servo-highfive added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Oct 18, 2026
@servo-highfive servo-highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Oct 18, 2026
@elomscansio
elomscansio requested a review from jdm October 18, 2026 11:10
@elomscansio

Copy link
Copy Markdown
Contributor Author

@jdm ping

@jdm jdm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need to write a test for revoking blob URLs in tests/wpt/tests/html/semantics/embedded-content/the-img-element as well. I suggest:

  • fetch a same-origin image, get the response as a blob
  • use URL.createObjectURL(blob) to create the blob URL from the image data
  • create an image element, set the src, then immediately revoke the blob URL
  • add a load handler that passes the test, and an error handler that fails the test

doc: Trusted::new(&document),
element: Trusted::new(self),
url: img_url.clone(),
url: img_url.url(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to store the UrlWithBlobClaim in ImageContext.

// Step 6. Let urlString be the result of encoding-parsing-and-serializing a URL given
// selected source, relative to the element's node document.
// Step 7. If urlString is failure, then return.
let Ok(image_url) = document.base_url().join(&selected_source) else {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should call ensure_blob_referenced_by_url_is_kept_alive right after computing the URL here.


// Step 13. Set the element's pending request to image request.
self.image_request.set(ImageRequestPhase::Pending);
self.init_pending_image_request(cx, &self.pending_request, &image_url, &selected_source);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should store the UrlWithBlobClaim in ImageRequest::parsed_url instead of ServoUrl.

Comment on lines +1084 to +1087
let url_with_claim = ensure_blob_referenced_by_url_is_kept_alive(
&self.owner_global(),
image_url.clone(),
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let url_with_claim = ensure_blob_referenced_by_url_is_kept_alive(
&self.owner_global(),
image_url.clone(),
);

#[expect(non_snake_case)]
impl HTMLImageElement {
/// Update the current image with a valid URL.
fn fetch_image(&self, cx: &mut JSContext, img_url: &ServoUrl) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fn fetch_image(&self, cx: &mut JSContext, img_url: UrlWithBlobClaim) {

Comment on lines +310 to +313
let url_with_claim = ensure_blob_referenced_by_url_is_kept_alive(
&self.owner_global(),
img_url.clone(),
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let url_with_claim = ensure_blob_referenced_by_url_is_kept_alive(
&self.owner_global(),
img_url.clone(),
);

@servo-highfive servo-highfive added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Oct 20, 2026
@jdm jdm added the S-needs-tests New tests have been requested by a reviewer. label Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-needs-code-changes Changes have not yet been made that were requested by a reviewer. S-needs-tests New tests have been requested by a reviewer.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants