summaryrefslogtreecommitdiffstats
path: root/dom
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-08-24 11:11:17 +0000
committerMoonchild <moonchild@palemoon.org>2020-08-30 09:47:49 +0000
commitd58cb8e11b15c054f0773918cd7fd89ce2a7464e (patch)
tree380d82f3b0ad12222da2338da83408b97b402634 /dom
parent429a7bdb93e443236f4a4b04afc9a12c78f54247 (diff)
downloadUXP-d58cb8e11b15c054f0773918cd7fd89ce2a7464e.tar
UXP-d58cb8e11b15c054f0773918cd7fd89ce2a7464e.tar.gz
UXP-d58cb8e11b15c054f0773918cd7fd89ce2a7464e.tar.lz
UXP-d58cb8e11b15c054f0773918cd7fd89ce2a7464e.tar.xz
UXP-d58cb8e11b15c054f0773918cd7fd89ce2a7464e.zip
Issue #618 - (async, preload) Correctly pass info about async/defer to parser.
This makes sure we don't block body-referred sub-resources by head-referenced defer and async scripts. This is important for all script loads, not just modules, but is added here because it was run into while implementing modules.
Diffstat (limited to 'dom')
-rw-r--r--dom/script/ScriptLoader.cpp12
-rw-r--r--dom/script/ScriptLoader.h6
2 files changed, 15 insertions, 3 deletions
diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp
index 58f0c0bbe..9216be835 100644
--- a/dom/script/ScriptLoader.cpp
+++ b/dom/script/ScriptLoader.cpp
@@ -1050,15 +1050,17 @@ ScriptLoader::StartLoad(ScriptLoadRequest *aRequest, const nsAString &aType,
NS_ENSURE_SUCCESS(rv, rv);
nsIScriptElement *script = aRequest->mElement;
+ bool async = script ? script->GetScriptAsync() : aRequest->mPreloadAsAsync;
+ bool defer = script ? script->GetScriptDeferred() : aRequest->mPreloadAsDefer;
+
nsCOMPtr<nsIClassOfService> cos(do_QueryInterface(channel));
if (cos) {
- if (aScriptFromHead &&
- !(script && (script->GetScriptAsync() || script->GetScriptDeferred()))) {
+ if (aScriptFromHead && !async && !defer) {
// synchronous head scripts block lading of most other non js/css
// content such as images
cos->AddClassFlags(nsIClassOfService::Leader);
- } else if (!(script && script->GetScriptDeferred())) {
+ } else if (!defer) {
// other scripts are neither blocked nor prioritized unless marked deferred
cos->AddClassFlags(nsIClassOfService::Unblocked);
}
@@ -2571,6 +2573,8 @@ ScriptLoader::PreloadURI(nsIURI *aURI, const nsAString &aCharset,
const nsAString &aCrossOrigin,
const nsAString& aIntegrity,
bool aScriptFromHead,
+ bool aAsync,
+ bool aDefer,
const mozilla::net::ReferrerPolicy aReferrerPolicy)
{
NS_ENSURE_TRUE_VOID(mDocument);
@@ -2601,6 +2605,8 @@ ScriptLoader::PreloadURI(nsIURI *aURI, const nsAString &aCharset,
Element::StringToCORSMode(aCrossOrigin), sriMetadata,
aReferrerPolicy);
request->mIsInline = false;
+ request->mPreloadAsAsync = aAsync;
+ request->mPreloadAsDefer = aDefer;
nsresult rv = StartLoad(request, aType, aScriptFromHead);
if (NS_FAILED(rv)) {
diff --git a/dom/script/ScriptLoader.h b/dom/script/ScriptLoader.h
index 61680a3ee..b7e20c7ee 100644
--- a/dom/script/ScriptLoader.h
+++ b/dom/script/ScriptLoader.h
@@ -76,6 +76,8 @@ public:
mHasSourceMapURL(false),
mInDeferList(false),
mInAsyncList(false),
+ mPreloadAsAsync(false),
+ mPreloadAsDefer(false),
mIsNonAsyncScriptInserted(false),
mIsXSLT(false),
mIsCanceled(false),
@@ -161,6 +163,8 @@ public:
bool mHasSourceMapURL; // Does the HTTP header have a source map url?
bool mInDeferList; // True if we live in mDeferRequests.
bool mInAsyncList; // True if we live in mLoadingAsyncRequests or mLoadedAsyncRequests.
+ bool mPreloadAsAsync; // True if this is a preload request and the script is async
+ bool mPreloadAsDefer; // True if this is a preload request and the script is defer
bool mIsNonAsyncScriptInserted; // True if we live in mNonAsyncExternalScriptInsertedRequests
bool mIsXSLT; // True if we live in mXSLTRequests.
bool mIsCanceled; // True if we have been explicitly canceled.
@@ -459,6 +463,8 @@ public:
const nsAString &aCrossOrigin,
const nsAString& aIntegrity,
bool aScriptFromHead,
+ bool aAsync,
+ bool aDefer,
const mozilla::net::ReferrerPolicy aReferrerPolicy);
/**