mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-08 08:17:31 +09:00
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:
parent
62be542166
commit
ba01d99e31
2 changed files with 38 additions and 16 deletions
|
|
@ -89,6 +89,7 @@ ScriptFetchOptions::ScriptFetchOptions(mozilla::CORSMode aCORSMode,
|
||||||
nsIPrincipal* aTriggeringPrincipal)
|
nsIPrincipal* aTriggeringPrincipal)
|
||||||
: mCORSMode(aCORSMode)
|
: mCORSMode(aCORSMode)
|
||||||
, mReferrerPolicy(aReferrerPolicy)
|
, mReferrerPolicy(aReferrerPolicy)
|
||||||
|
, mIsPreload(false)
|
||||||
, mElement(aElement)
|
, mElement(aElement)
|
||||||
, mTriggeringPrincipal(aTriggeringPrincipal)
|
, mTriggeringPrincipal(aTriggeringPrincipal)
|
||||||
{
|
{
|
||||||
|
|
@ -1110,7 +1111,7 @@ ScriptLoader::ProcessLoadedModuleTree(ModuleLoadRequest* aRequest)
|
||||||
RefPtr<ScriptLoadRequest> req = mDynamicImportRequests.Steal(aRequest);
|
RefPtr<ScriptLoadRequest> req = mDynamicImportRequests.Steal(aRequest);
|
||||||
RunScriptWhenSafe(req);
|
RunScriptWhenSafe(req);
|
||||||
} else if (aRequest->mIsInline &&
|
} else if (aRequest->mIsInline &&
|
||||||
aRequest->Element()->GetParserCreated() == NOT_FROM_PARSER) {
|
aRequest->GetParserCreated() == NOT_FROM_PARSER) {
|
||||||
RunScriptWhenSafe(aRequest);
|
RunScriptWhenSafe(aRequest);
|
||||||
} else {
|
} else {
|
||||||
MaybeMoveToLoadedList(aRequest);
|
MaybeMoveToLoadedList(aRequest);
|
||||||
|
|
@ -1510,7 +1511,7 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
|
||||||
// preloaded
|
// preloaded
|
||||||
// note that a script-inserted script can steal a preload!
|
// note that a script-inserted script can steal a preload!
|
||||||
request = mPreloads[i].mRequest;
|
request = mPreloads[i].mRequest;
|
||||||
request->SetElement(aElement);
|
request->SetIsLoadRequest(aElement);
|
||||||
nsString preloadCharset(mPreloads[i].mCharset);
|
nsString preloadCharset(mPreloads[i].mCharset);
|
||||||
mPreloads.RemoveElementAt(i);
|
mPreloads.RemoveElementAt(i);
|
||||||
|
|
||||||
|
|
@ -1981,7 +1982,7 @@ ScriptLoader::ProcessRequest(ScriptLoadRequest* aRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIScriptElement> oldParserInsertedScript;
|
nsCOMPtr<nsIScriptElement> oldParserInsertedScript;
|
||||||
uint32_t parserCreated = aRequest->Element()->GetParserCreated();
|
uint32_t parserCreated = aRequest->GetParserCreated();
|
||||||
if (parserCreated) {
|
if (parserCreated) {
|
||||||
oldParserInsertedScript = mCurrentParserInsertedScript;
|
oldParserInsertedScript = mCurrentParserInsertedScript;
|
||||||
mCurrentParserInsertedScript = aRequest->Element();
|
mCurrentParserInsertedScript = aRequest->Element();
|
||||||
|
|
@ -2192,14 +2193,14 @@ ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIContent> scriptContent(do_QueryInterface(aRequest->Element()));
|
nsCOMPtr<nsIContent> scriptContent(do_QueryInterface(aRequest->Element()));
|
||||||
|
MOZ_ASSERT_IF(!scriptContent, aRequest->AsModuleRequest()->IsDynamicImport());
|
||||||
|
if (scriptContent) {
|
||||||
nsIDocument* ownerDoc = scriptContent->OwnerDoc();
|
nsIDocument* ownerDoc = scriptContent->OwnerDoc();
|
||||||
if (ownerDoc != mDocument) {
|
if (ownerDoc != mDocument) {
|
||||||
// Willful violation of HTML5 as of 2010-12-01
|
// Willful violation of HTML5 as of 2010-12-01
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Get the script-type to be used by this element.
|
|
||||||
NS_ASSERTION(scriptContent, "no content - what is default script-type?");
|
|
||||||
|
|
||||||
nsCOMPtr<nsIScriptGlobalObject> globalObject = GetScriptGlobalObject();
|
nsCOMPtr<nsIScriptGlobalObject> globalObject = GetScriptGlobalObject();
|
||||||
if (!globalObject) {
|
if (!globalObject) {
|
||||||
|
|
@ -2955,6 +2956,7 @@ ScriptLoader::PreloadURI(nsIURI *aURI,
|
||||||
aReferrerPolicy);
|
aReferrerPolicy);
|
||||||
request->mIsInline = false;
|
request->mIsInline = false;
|
||||||
request->SetScriptMode(aDefer, aAsync);
|
request->SetScriptMode(aDefer, aAsync);
|
||||||
|
request->SetIsPreloadRequest();
|
||||||
|
|
||||||
nsresult rv = StartLoad(request, aType, aScriptFromHead);
|
nsresult rv = StartLoad(request, aType, aScriptFromHead);
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,7 @@ public:
|
||||||
|
|
||||||
const mozilla::CORSMode mCORSMode;
|
const mozilla::CORSMode mCORSMode;
|
||||||
const mozilla::net::ReferrerPolicy mReferrerPolicy;
|
const mozilla::net::ReferrerPolicy mReferrerPolicy;
|
||||||
|
bool mIsPreload;
|
||||||
nsCOMPtr<nsIScriptElement> mElement;
|
nsCOMPtr<nsIScriptElement> mElement;
|
||||||
nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
|
nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
|
||||||
};
|
};
|
||||||
|
|
@ -113,9 +114,9 @@ public:
|
||||||
Element()->ScriptEvaluated(aResult, Element(), mIsInline);
|
Element()->ScriptEvaluated(aResult, Element(), mIsInline);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsPreload()
|
bool IsPreload() const {
|
||||||
{
|
MOZ_ASSERT_IF(mFetchOptions->mIsPreload, !Element());
|
||||||
return Element() == nullptr;
|
return mFetchOptions->mIsPreload;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Cancel();
|
virtual void Cancel();
|
||||||
|
|
@ -195,12 +196,31 @@ public:
|
||||||
return mFetchOptions->mTriggeringPrincipal;
|
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(aElement);
|
||||||
MOZ_ASSERT(!Element());
|
MOZ_ASSERT(!Element());
|
||||||
|
MOZ_ASSERT(IsPreload());
|
||||||
mFetchOptions->mElement = aElement;
|
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);
|
void SetScript(JSScript* aScript);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue