Bug 1637039 - Notify script preload when the loading channel synchronously fails to open, remove a used script preload from Document, r=hsivonen

Differential Revision: https://phabricator.services.mozilla.com/D76364
This commit is contained in:
Honza Bambas 2020-05-25 18:39:11 +00:00
Родитель 3e13f22e1b
Коммит 07f63ad409
1 изменённых файлов: 15 добавлений и 3 удалений

Просмотреть файл

@ -1497,15 +1497,23 @@ nsresult ScriptLoader::StartLoad(ScriptLoadRequest* aRequest) {
rv = NS_NewIncrementalStreamLoader(getter_AddRefs(loader), handler);
NS_ENSURE_SUCCESS(rv, rv);
rv = channel->AsyncOpen(loader);
NS_ENSURE_SUCCESS(rv, rv);
auto key = PreloadHashKey::CreateAsScript(
aRequest->mURI, aRequest->CORSMode(), aRequest->mKind,
aRequest->ReferrerPolicy());
aRequest->NotifyOpen(&key, channel, mDocument,
aRequest->IsLinkPreloadScript());
rv = channel->AsyncOpen(loader);
if (NS_FAILED(rv)) {
// Make sure to inform any <link preload> tags about failure to load the
// resource.
aRequest->NotifyStart(channel);
aRequest->NotifyStop(rv);
}
NS_ENSURE_SUCCESS(rv, rv);
if (aRequest->IsModuleRequest()) {
// We successfully started fetching a module so put its URL in the module
// map and mark it as fetching.
@ -1966,6 +1974,10 @@ ScriptLoadRequest* ScriptLoader::LookupPreloadRequest(
// This makes sure the pending preload (if exists) for this resource is
// properly marked as used and thus not notified in the console as unused.
request->NotifyUsage();
// A used preload must no longer be found in the Document's hash table. Any
// <link preload> tag after the <script> tag will start a new request, that
// can be satisfied from a different cache, but not from the preload cache.
request->RemoveSelf(mDocument);
return request;
}