diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp index f27d0a12abdd..2ef8a1af26e4 100644 --- a/dom/script/ScriptLoader.cpp +++ b/dom/script/ScriptLoader.cpp @@ -765,6 +765,26 @@ nsresult ScriptLoader::PrepareHttpRequestAndInitiatorType( return rv; } +nsresult ScriptLoader::PrepareIncrementalStreamLoader( + nsIIncrementalStreamLoader** aOutLoader, ScriptLoadRequest* aRequest) { + UniquePtr sriDataVerifier; + if (!aRequest->mIntegrity.IsEmpty()) { + nsAutoCString sourceUri; + if (mDocument->GetDocumentURI()) { + mDocument->GetDocumentURI()->GetAsciiSpec(sourceUri); + } + sriDataVerifier = MakeUnique(aRequest->mIntegrity, + sourceUri, mReporter); + } + + RefPtr handler = + new ScriptLoadHandler(this, aRequest, std::move(sriDataVerifier)); + + nsresult rv = NS_NewIncrementalStreamLoader(aOutLoader, handler); + NS_ENSURE_SUCCESS(rv, rv); + return rv; +} + nsresult ScriptLoader::StartLoadInternal( ScriptLoadRequest* aRequest, nsSecurityFlags securityFlags, const Maybe& aCharsetForPreload) { @@ -808,21 +828,8 @@ nsresult ScriptLoader::StartLoadInternal( nsINetworkPredictor::LEARN_LOAD_SUBRESOURCE, mDocument->NodePrincipal()->OriginAttributesRef()); - UniquePtr sriDataVerifier; - if (!aRequest->mIntegrity.IsEmpty()) { - nsAutoCString sourceUri; - if (mDocument->GetDocumentURI()) { - mDocument->GetDocumentURI()->GetAsciiSpec(sourceUri); - } - sriDataVerifier = MakeUnique(aRequest->mIntegrity, - sourceUri, mReporter); - } - - RefPtr handler = - new ScriptLoadHandler(this, aRequest, std::move(sriDataVerifier)); - nsCOMPtr loader; - rv = NS_NewIncrementalStreamLoader(getter_AddRefs(loader), handler); + rv = PrepareIncrementalStreamLoader(getter_AddRefs(loader), aRequest); NS_ENSURE_SUCCESS(rv, rv); auto key = PreloadHashKey::CreateAsScript( diff --git a/dom/script/ScriptLoader.h b/dom/script/ScriptLoader.h index 75c5194485ac..bfea36298f81 100644 --- a/dom/script/ScriptLoader.h +++ b/dom/script/ScriptLoader.h @@ -512,6 +512,9 @@ class ScriptLoader final : public JS::loader::ScriptLoaderInterface { nsIChannel* aChannel, ScriptLoadRequest* aRequest, const Maybe& aCharsetForPreload); + [[nodiscard]] nsresult PrepareIncrementalStreamLoader( + nsIIncrementalStreamLoader** aOutLoader, ScriptLoadRequest* aRequest); + /** * Start a load for a script (module or classic) URI. *