script/
url.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 net_traits::blob_url_store::{BlobResolver, UrlWithBlobClaim};
6use servo_url::ServoUrl;
7
8use crate::dom::globalscope::GlobalScope;
9
10pub(crate) fn ensure_blob_referenced_by_url_is_kept_alive(
11    global: &GlobalScope,
12    url: ServoUrl,
13) -> UrlWithBlobClaim {
14    match UrlWithBlobClaim::for_url(url) {
15        Ok(lock) => lock,
16        Err(url) => {
17            let token = BlobResolver {
18                origin: global.origin().immutable().clone(),
19                resource_threads: global.resource_threads(),
20            }
21            .acquire_blob_token_for(&url);
22
23            UrlWithBlobClaim::new(url, token)
24        },
25    }
26}