Issue #618 - Don't preload nomodule scripts when modules are enabled

Ref: BZ 1382020
This commit is contained in:
Gaming4JC 2020-08-26 11:19:42 -04:00 • committed by Roy Tam
commit 6c8f24a735
8 changed files with 57 additions and 18 deletions

View file

@ -2576,13 +2576,15 @@ ScriptLoader::ParsingComplete(bool aTerminated)
} }
void void
ScriptLoader::PreloadURI(nsIURI *aURI, const nsAString &aCharset, ScriptLoader::PreloadURI(nsIURI *aURI,
const nsAString &aCharset,
const nsAString &aType, const nsAString &aType,
const nsAString &aCrossOrigin, const nsAString &aCrossOrigin,
const nsAString& aIntegrity, const nsAString& aIntegrity,
bool aScriptFromHead, bool aScriptFromHead,
bool aAsync, bool aAsync,
bool aDefer, bool aDefer,
bool aNoModule,
const mozilla::net::ReferrerPolicy aReferrerPolicy) const mozilla::net::ReferrerPolicy aReferrerPolicy)
{ {
NS_ENSURE_TRUE_VOID(mDocument); NS_ENSURE_TRUE_VOID(mDocument);
@ -2591,9 +2593,16 @@ ScriptLoader::PreloadURI(nsIURI *aURI, const nsAString &aCharset,
return; return;
} }
// TODO: Preload module scripts. if (mDocument->ModuleScriptsEnabled()) {
if (mDocument->ModuleScriptsEnabled() && aType.LowerCaseEqualsASCII("module")) { // Don't load nomodule scripts.
return; if (aNoModule) {
return;
}
// TODO: Preload module scripts.
if (aType.LowerCaseEqualsASCII("module")) {
return;
}
} }
SRIMetadata sriMetadata; SRIMetadata sriMetadata;

View file

@ -479,13 +479,15 @@ public:
* @param aIntegrity The expect hash url, if avail, of the request * @param aIntegrity The expect hash url, if avail, of the request
* @param aScriptFromHead Whether or not the script was a child of head * @param aScriptFromHead Whether or not the script was a child of head
*/ */
virtual void PreloadURI(nsIURI *aURI, const nsAString &aCharset, virtual void PreloadURI(nsIURI *aURI,
const nsAString &aCharset,
const nsAString &aType, const nsAString &aType,
const nsAString &aCrossOrigin, const nsAString &aCrossOrigin,
const nsAString& aIntegrity, const nsAString& aIntegrity,
bool aScriptFromHead, bool aScriptFromHead,
bool aAsync, bool aAsync,
bool aDefer, bool aDefer,
bool aNoModule,
const mozilla::net::ReferrerPolicy aReferrerPolicy); const mozilla::net::ReferrerPolicy aReferrerPolicy);
/** /**

View file

@ -1161,6 +1161,7 @@ public final class AttributeName
public static final AttributeName LQUOTE = new AttributeName(ALL_NO_NS, SAME_LOCAL("lquote"), ALL_NO_PREFIX, NCNAME_HTML | NCNAME_FOREIGN | NCNAME_LANG); public static final AttributeName LQUOTE = new AttributeName(ALL_NO_NS, SAME_LOCAL("lquote"), ALL_NO_PREFIX, NCNAME_HTML | NCNAME_FOREIGN | NCNAME_LANG);
public static final AttributeName PANOSE_1 = new AttributeName(ALL_NO_NS, SAME_LOCAL("panose-1"), ALL_NO_PREFIX, NCNAME_HTML | NCNAME_FOREIGN | NCNAME_LANG); public static final AttributeName PANOSE_1 = new AttributeName(ALL_NO_NS, SAME_LOCAL("panose-1"), ALL_NO_PREFIX, NCNAME_HTML | NCNAME_FOREIGN | NCNAME_LANG);
public static final AttributeName NUMOCTAVES = new AttributeName(ALL_NO_NS, SVG_DIFFERENT("numoctaves", "numOctaves"), ALL_NO_PREFIX, NCNAME_HTML | NCNAME_FOREIGN | NCNAME_LANG); public static final AttributeName NUMOCTAVES = new AttributeName(ALL_NO_NS, SVG_DIFFERENT("numoctaves", "numOctaves"), ALL_NO_PREFIX, NCNAME_HTML | NCNAME_FOREIGN | NCNAME_LANG);
public static final AttributeName NOMODULE = new AttributeName(ALL_NO_NS, SAME_LOCAL("nomodule"), ALL_NO_PREFIX, NCNAME_HTML | NCNAME_FOREIGN | NCNAME_LANG | CASE_FOLDED | BOOLEAN);
public static final AttributeName ONLOAD = new AttributeName(ALL_NO_NS, SAME_LOCAL("onload"), ALL_NO_PREFIX, NCNAME_HTML | NCNAME_FOREIGN | NCNAME_LANG); public static final AttributeName ONLOAD = new AttributeName(ALL_NO_NS, SAME_LOCAL("onload"), ALL_NO_PREFIX, NCNAME_HTML | NCNAME_FOREIGN | NCNAME_LANG);
public static final AttributeName ONBOUNCE = new AttributeName(ALL_NO_NS, SAME_LOCAL("onbounce"), ALL_NO_PREFIX, NCNAME_HTML | NCNAME_FOREIGN | NCNAME_LANG); public static final AttributeName ONBOUNCE = new AttributeName(ALL_NO_NS, SAME_LOCAL("onbounce"), ALL_NO_PREFIX, NCNAME_HTML | NCNAME_FOREIGN | NCNAME_LANG);
public static final AttributeName ONCONTROLSELECT = new AttributeName(ALL_NO_NS, SAME_LOCAL("oncontrolselect"), ALL_NO_PREFIX, NCNAME_HTML | NCNAME_FOREIGN | NCNAME_LANG); public static final AttributeName ONCONTROLSELECT = new AttributeName(ALL_NO_NS, SAME_LOCAL("oncontrolselect"), ALL_NO_PREFIX, NCNAME_HTML | NCNAME_FOREIGN | NCNAME_LANG);
@ -1464,6 +1465,7 @@ public final class AttributeName
XLINK_SHOW, XLINK_SHOW,
COLOR_RENDERING, COLOR_RENDERING,
IDEOGRAPHIC, IDEOGRAPHIC,
NOMODULE,
ONMOUSEWHEEL, ONMOUSEWHEEL,
ONCONTEXTMENU, ONCONTEXTMENU,
ONMOUSEMOVE, ONMOUSEMOVE,

View file

@ -52,12 +52,22 @@ nsHtml5SpeculativeLoad::Perform(nsHtml5TreeOpExecutor* aExecutor)
case eSpeculativeLoadScript: case eSpeculativeLoadScript:
aExecutor->PreloadScript(mUrl, mCharset, mTypeOrCharsetSourceOrDocumentMode, aExecutor->PreloadScript(mUrl, mCharset, mTypeOrCharsetSourceOrDocumentMode,
mCrossOrigin, mIntegrity, false, mCrossOrigin, mIntegrity, false,
mIsAsync, mIsDefer); mIsAsync, mIsDefer, false);
break; break;
case eSpeculativeLoadScriptFromHead: case eSpeculativeLoadScriptFromHead:
aExecutor->PreloadScript(mUrl, mCharset, mTypeOrCharsetSourceOrDocumentMode, aExecutor->PreloadScript(mUrl, mCharset, mTypeOrCharsetSourceOrDocumentMode,
mCrossOrigin, mIntegrity, true, mCrossOrigin, mIntegrity, true,
mIsAsync, mIsDefer); mIsAsync, mIsDefer, false);
break;
case eSpeculativeLoadNoModuleScript:
aExecutor->PreloadScript(mUrl, mCharset, mTypeOrCharsetSourceOrDocumentMode,
mCrossOrigin, mIntegrity, false,
mIsAsync, mIsDefer, true);
break;
case eSpeculativeLoadNoModuleScriptFromHead:
aExecutor->PreloadScript(mUrl, mCharset, mTypeOrCharsetSourceOrDocumentMode,
mCrossOrigin, mIntegrity, true,
mIsAsync, mIsDefer, true);
break; break;
case eSpeculativeLoadStyle: case eSpeculativeLoadStyle:
aExecutor->PreloadStyle(mUrl, mCharset, mCrossOrigin, mIntegrity); aExecutor->PreloadStyle(mUrl, mCharset, mCrossOrigin, mIntegrity);

View file

@ -10,7 +10,8 @@
class nsHtml5TreeOpExecutor; class nsHtml5TreeOpExecutor;
enum eHtml5SpeculativeLoad { enum eHtml5SpeculativeLoad
{
#ifdef DEBUG #ifdef DEBUG
eSpeculativeLoadUninitialized, eSpeculativeLoadUninitialized,
#endif #endif
@ -23,6 +24,8 @@ enum eHtml5SpeculativeLoad {
eSpeculativeLoadPictureSource, eSpeculativeLoadPictureSource,
eSpeculativeLoadScript, eSpeculativeLoadScript,
eSpeculativeLoadScriptFromHead, eSpeculativeLoadScriptFromHead,
eSpeculativeLoadNoModuleScript,
eSpeculativeLoadNoModuleScriptFromHead,
eSpeculativeLoadStyle, eSpeculativeLoadStyle,
eSpeculativeLoadManifest, eSpeculativeLoadManifest,
eSpeculativeLoadSetDocumentCharset, eSpeculativeLoadSetDocumentCharset,
@ -130,12 +133,18 @@ class nsHtml5SpeculativeLoad {
nsHtml5String aIntegrity, nsHtml5String aIntegrity,
bool aParserInHead, bool aParserInHead,
bool aAsync, bool aAsync,
bool aDefer) bool aDefer,
bool aNoModule)
{ {
NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized, NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
"Trying to reinitialize a speculative load!"); "Trying to reinitialize a speculative load!");
mOpCode = aParserInHead ? if (aNoModule) {
eSpeculativeLoadScriptFromHead : eSpeculativeLoadScript; mOpCode = aParserInHead ? eSpeculativeLoadNoModuleScriptFromHead
: eSpeculativeLoadNoModuleScript;
} else {
mOpCode = aParserInHead ? eSpeculativeLoadScriptFromHead
: eSpeculativeLoadScript;
}
aUrl.ToString(mUrl); aUrl.ToString(mUrl);
aCharset.ToString(mCharset); aCharset.ToString(mCharset);
aType.ToString(mTypeOrCharsetSourceOrDocumentMode); aType.ToString(mTypeOrCharsetSourceOrDocumentMode);

View file

@ -189,6 +189,8 @@ nsHtml5TreeBuilder::createElement(int32_t aNamespace,
aAttributes->contains(nsHtml5AttributeName::ATTR_ASYNC); aAttributes->contains(nsHtml5AttributeName::ATTR_ASYNC);
bool defer = bool defer =
aAttributes->contains(nsHtml5AttributeName::ATTR_DEFER); aAttributes->contains(nsHtml5AttributeName::ATTR_DEFER);
bool noModule =
aAttributes->contains(nsHtml5AttributeName::ATTR_NOMODULE);
mSpeculativeLoadQueue.AppendElement()->InitScript( mSpeculativeLoadQueue.AppendElement()->InitScript(
url, url,
charset, charset,
@ -197,7 +199,8 @@ nsHtml5TreeBuilder::createElement(int32_t aNamespace,
integrity, integrity,
mode == nsHtml5TreeBuilder::IN_HEAD, mode == nsHtml5TreeBuilder::IN_HEAD,
async, async,
defer); defer,
noModule);
mCurrentHtmlScriptIsAsyncOrDefer = async || defer; mCurrentHtmlScriptIsAsyncOrDefer = async || defer;
} }
} else if (nsHtml5Atoms::link == aName) { } else if (nsHtml5Atoms::link == aName) {
@ -303,7 +306,8 @@ nsHtml5TreeBuilder::createElement(int32_t aNamespace,
integrity, integrity,
mode == nsHtml5TreeBuilder::IN_HEAD, mode == nsHtml5TreeBuilder::IN_HEAD,
false /* async */, false /* async */,
false /* defer */); false /* defer */,
false /* noModule */);
} }
} else if (nsHtml5Atoms::style == aName) { } else if (nsHtml5Atoms::style == aName) {
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement(); nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();

View file

@ -923,14 +923,16 @@ nsHtml5TreeOpExecutor::PreloadScript(const nsAString& aURL,
const nsAString& aIntegrity, const nsAString& aIntegrity,
bool aScriptFromHead, bool aScriptFromHead,
bool aAsync, bool aAsync,
bool aDefer) bool aDefer,
bool aNoModule)
{ {
nsCOMPtr<nsIURI> uri = ConvertIfNotPreloadedYet(aURL); nsCOMPtr<nsIURI> uri = ConvertIfNotPreloadedYet(aURL);
if (!uri) { if (!uri) {
return; return;
} }
mDocument->ScriptLoader()->PreloadURI(uri, aCharset, aType, aCrossOrigin, mDocument->ScriptLoader()->PreloadURI(uri, aCharset, aType, aCrossOrigin,
aIntegrity, aScriptFromHead, aAsync, aDefer, aIntegrity, aScriptFromHead, aAsync,
aDefer, aNoModule,
mSpeculationReferrerPolicy); mSpeculationReferrerPolicy);
} }

View file

@ -251,7 +251,8 @@ class nsHtml5TreeOpExecutor final : public nsHtml5DocumentBuilder,
const nsAString& aIntegrity, const nsAString& aIntegrity,
bool aScriptFromHead, bool aScriptFromHead,
bool aAsync, bool aAsync,
bool aDefer); bool aDefer,
bool aNoModule);
void PreloadStyle(const nsAString& aURL, const nsAString& aCharset, void PreloadStyle(const nsAString& aURL, const nsAString& aCharset,
const nsAString& aCrossOrigin, const nsAString& aCrossOrigin,