Bug 1839316: part 10) Factor preparing the HTTP request and initiator type out of StartLoadInternal. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D187177
This commit is contained in:
@@ -711,6 +711,60 @@ void ScriptLoader::PrepareRequestPriorityAndRequestDependencies(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
nsresult ScriptLoader::PrepareHttpRequestAndInitiatorType(
|
||||||
|
nsIChannel* aChannel, ScriptLoadRequest* aRequest,
|
||||||
|
const Maybe<nsAutoString>& aCharsetForPreload) {
|
||||||
|
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(aChannel));
|
||||||
|
nsresult rv = NS_OK;
|
||||||
|
|
||||||
|
if (httpChannel) {
|
||||||
|
// HTTP content negotation has little value in this context.
|
||||||
|
nsAutoCString acceptTypes("*/*");
|
||||||
|
rv = httpChannel->SetRequestHeader("Accept"_ns, acceptTypes, false);
|
||||||
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||||
|
|
||||||
|
nsCOMPtr<nsIReferrerInfo> referrerInfo =
|
||||||
|
new ReferrerInfo(aRequest->mReferrer, aRequest->ReferrerPolicy());
|
||||||
|
rv = httpChannel->SetReferrerInfoWithoutClone(referrerInfo);
|
||||||
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||||
|
|
||||||
|
nsCOMPtr<nsIHttpChannelInternal> internalChannel(
|
||||||
|
do_QueryInterface(httpChannel));
|
||||||
|
if (internalChannel) {
|
||||||
|
rv = internalChannel->SetIntegrityMetadata(
|
||||||
|
aRequest->mIntegrity.GetIntegrityString());
|
||||||
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||||
|
}
|
||||||
|
|
||||||
|
nsAutoString hintCharset;
|
||||||
|
if (!aRequest->GetScriptLoadContext()->IsPreload() &&
|
||||||
|
aRequest->GetScriptLoadContext()->GetScriptElement()) {
|
||||||
|
aRequest->GetScriptLoadContext()->GetScriptElement()->GetScriptCharset(
|
||||||
|
hintCharset);
|
||||||
|
} else if (aCharsetForPreload.isSome()) {
|
||||||
|
hintCharset = aCharsetForPreload.ref();
|
||||||
|
}
|
||||||
|
|
||||||
|
rv = httpChannel->SetClassicScriptHintCharset(hintCharset);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the initiator type
|
||||||
|
nsCOMPtr<nsITimedChannel> timedChannel(do_QueryInterface(httpChannel));
|
||||||
|
if (timedChannel) {
|
||||||
|
if (aRequest->mEarlyHintPreloaderId) {
|
||||||
|
timedChannel->SetInitiatorType(u"early-hints"_ns);
|
||||||
|
} else if (aRequest->GetScriptLoadContext()->IsLinkPreloadScript()) {
|
||||||
|
timedChannel->SetInitiatorType(u"link"_ns);
|
||||||
|
} else {
|
||||||
|
timedChannel->SetInitiatorType(u"script"_ns);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
nsresult ScriptLoader::StartLoadInternal(
|
nsresult ScriptLoader::StartLoadInternal(
|
||||||
ScriptLoadRequest* aRequest, nsSecurityFlags securityFlags,
|
ScriptLoadRequest* aRequest, nsSecurityFlags securityFlags,
|
||||||
const Maybe<nsAutoString>& aCharsetForPreload) {
|
const Maybe<nsAutoString>& aCharsetForPreload) {
|
||||||
@@ -745,56 +799,15 @@ nsresult ScriptLoader::StartLoadInternal(
|
|||||||
|
|
||||||
PrepareRequestPriorityAndRequestDependencies(channel, aRequest);
|
PrepareRequestPriorityAndRequestDependencies(channel, aRequest);
|
||||||
|
|
||||||
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel));
|
rv =
|
||||||
if (httpChannel) {
|
PrepareHttpRequestAndInitiatorType(channel, aRequest, aCharsetForPreload);
|
||||||
// HTTP content negotation has little value in this context.
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
nsAutoCString acceptTypes("*/*");
|
|
||||||
rv = httpChannel->SetRequestHeader("Accept"_ns, acceptTypes, false);
|
|
||||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
|
||||||
|
|
||||||
nsCOMPtr<nsIReferrerInfo> referrerInfo =
|
|
||||||
new ReferrerInfo(aRequest->mReferrer, aRequest->ReferrerPolicy());
|
|
||||||
rv = httpChannel->SetReferrerInfoWithoutClone(referrerInfo);
|
|
||||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
|
||||||
|
|
||||||
nsCOMPtr<nsIHttpChannelInternal> internalChannel(
|
|
||||||
do_QueryInterface(httpChannel));
|
|
||||||
if (internalChannel) {
|
|
||||||
rv = internalChannel->SetIntegrityMetadata(
|
|
||||||
aRequest->mIntegrity.GetIntegrityString());
|
|
||||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
|
||||||
}
|
|
||||||
|
|
||||||
nsAutoString hintCharset;
|
|
||||||
if (!aRequest->GetScriptLoadContext()->IsPreload() &&
|
|
||||||
aRequest->GetScriptLoadContext()->GetScriptElement()) {
|
|
||||||
aRequest->GetScriptLoadContext()->GetScriptElement()->GetScriptCharset(
|
|
||||||
hintCharset);
|
|
||||||
} else if (aCharsetForPreload.isSome()) {
|
|
||||||
hintCharset = aCharsetForPreload.ref();
|
|
||||||
}
|
|
||||||
|
|
||||||
rv = httpChannel->SetClassicScriptHintCharset(hintCharset);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
}
|
|
||||||
|
|
||||||
mozilla::net::PredictorLearn(
|
mozilla::net::PredictorLearn(
|
||||||
aRequest->mURI, mDocument->GetDocumentURI(),
|
aRequest->mURI, mDocument->GetDocumentURI(),
|
||||||
nsINetworkPredictor::LEARN_LOAD_SUBRESOURCE,
|
nsINetworkPredictor::LEARN_LOAD_SUBRESOURCE,
|
||||||
mDocument->NodePrincipal()->OriginAttributesRef());
|
mDocument->NodePrincipal()->OriginAttributesRef());
|
||||||
|
|
||||||
// Set the initiator type
|
|
||||||
nsCOMPtr<nsITimedChannel> timedChannel(do_QueryInterface(httpChannel));
|
|
||||||
if (timedChannel) {
|
|
||||||
if (aRequest->mEarlyHintPreloaderId) {
|
|
||||||
timedChannel->SetInitiatorType(u"early-hints"_ns);
|
|
||||||
} else if (aRequest->GetScriptLoadContext()->IsLinkPreloadScript()) {
|
|
||||||
timedChannel->SetInitiatorType(u"link"_ns);
|
|
||||||
} else {
|
|
||||||
timedChannel->SetInitiatorType(u"script"_ns);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
UniquePtr<mozilla::dom::SRICheckDataVerifier> sriDataVerifier;
|
UniquePtr<mozilla::dom::SRICheckDataVerifier> sriDataVerifier;
|
||||||
if (!aRequest->mIntegrity.IsEmpty()) {
|
if (!aRequest->mIntegrity.IsEmpty()) {
|
||||||
nsAutoCString sourceUri;
|
nsAutoCString sourceUri;
|
||||||
|
|||||||
@@ -508,6 +508,10 @@ class ScriptLoader final : public JS::loader::ScriptLoaderInterface {
|
|||||||
static void PrepareRequestPriorityAndRequestDependencies(
|
static void PrepareRequestPriorityAndRequestDependencies(
|
||||||
nsIChannel* aChannel, ScriptLoadRequest* aRequest);
|
nsIChannel* aChannel, ScriptLoadRequest* aRequest);
|
||||||
|
|
||||||
|
[[nodiscard]] static nsresult PrepareHttpRequestAndInitiatorType(
|
||||||
|
nsIChannel* aChannel, ScriptLoadRequest* aRequest,
|
||||||
|
const Maybe<nsAutoString>& aCharsetForPreload);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start a load for a script (module or classic) URI.
|
* Start a load for a script (module or classic) URI.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user