Issue #1691 - Part 7b: Make load request element optional. https://bugzilla.mozilla.org/show_bug.cgi?id=1342012

(cherry picked from commit 169bb5d2ada59026fb6407716a7b3862810c9b97)
This commit is contained in:
Brian Smith 2023-04-18 23:00:12 -05:00 committed by roytam1
commit ba01d99e31
2 changed files with 38 additions and 16 deletions

View file

@ -70,6 +70,7 @@ public:
const mozilla::CORSMode mCORSMode;
const mozilla::net::ReferrerPolicy mReferrerPolicy;
bool mIsPreload;
nsCOMPtr<nsIScriptElement> mElement;
nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
};
@ -113,9 +114,9 @@ public:
Element()->ScriptEvaluated(aResult, Element(), mIsInline);
}
bool IsPreload()
{
return Element() == nullptr;
bool IsPreload() const {
MOZ_ASSERT_IF(mFetchOptions->mIsPreload, !Element());
return mFetchOptions->mIsPreload;
}
virtual void Cancel();
@ -195,13 +196,32 @@ public:
return mFetchOptions->mTriggeringPrincipal;
}
void SetElement(nsIScriptElement* aElement)
// Make this request a preload (speculative) request.
void SetIsPreloadRequest()
{
MOZ_ASSERT(!Element());
MOZ_ASSERT(!IsPreload());
mFetchOptions->mIsPreload = true;
}
// Make a preload request into an actual load request for the given element.
void SetIsLoadRequest(nsIScriptElement* aElement)
{
// Called when a preload request is later used for an actual request.
MOZ_ASSERT(aElement);
MOZ_ASSERT(!Element());
MOZ_ASSERT(IsPreload());
mFetchOptions->mElement = aElement;
}
mFetchOptions->mIsPreload = false;
}
FromParser GetParserCreated() const
{
nsIScriptElement* element = Element();
if (!element) {
return NOT_FROM_PARSER;
}
return element->GetParserCreated();
}
void SetScript(JSScript* aScript);