mirror of
https://github.com/servo/servo
synced 2026-04-25 17:15:48 +02:00
`blob` URLs have a implicit blob URL entry attached, which stores the data contained in the blob. The specification requires this entry to be resolved as the URL is parsed. We only resolve it inside `net` when loading the URL. That causes problems if the blob entry has been revoked in the meantime - see https://github.com/servo/servo/issues/25226. Ideally we would want to resolve blobs at parse-time as required. But because `ServoUrl` is such a fundamental type, I've not managed to do this change without having to touch hundreds of files at once. Thus, we now require passing a `UrlWithBlobClaim` instead of a `ServoUrl` when `fetch`-ing. This type proves that the caller has acquired the blob beforehand. As a temporary escape hatch, I've added `UrlWithBlobClaim::from_url_without_having_claimed_blob`. That method logs a warning if its used unsafely. This method is currently used in most places to keep this change small. Only workers now acquire the blob beforehand. Testing: A new test starts to pass Part of https://github.com/servo/servo/issues/43326 Part of https://github.com/servo/servo/issues/25226 --------- Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> Co-authored-by: Josh Matthews <josh@joshmatthews.net>
27 lines
840 B
Rust
27 lines
840 B
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
use net_traits::blob_url_store::{BlobResolver, UrlWithBlobClaim};
|
|
use servo_url::ServoUrl;
|
|
|
|
use crate::dom::globalscope::GlobalScope;
|
|
|
|
pub(crate) fn ensure_blob_referenced_by_url_is_kept_alive(
|
|
global: &GlobalScope,
|
|
url: ServoUrl,
|
|
) -> UrlWithBlobClaim {
|
|
match UrlWithBlobClaim::for_url(url) {
|
|
Ok(lock) => lock,
|
|
Err(url) => {
|
|
let token = BlobResolver {
|
|
origin: global.api_base_url().origin(),
|
|
resource_threads: global.resource_threads(),
|
|
}
|
|
.acquire_blob_token_for(&url);
|
|
|
|
UrlWithBlobClaim::new(url, token)
|
|
},
|
|
}
|
|
}
|