From 38d13e2779f9bfbf8620ead68a9bf0ffbed5762a Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Wed, 26 Aug 2020 11:19:42 -0400 Subject: Issue #618 - Don't preload nomodule scripts when modules are enabled Ref: BZ 1382020 --- .../src/nu/validator/htmlparser/impl/AttributeName.java | 2 ++ parser/html/nsHtml5SpeculativeLoad.cpp | 16 +++++++++++++--- parser/html/nsHtml5SpeculativeLoad.h | 17 +++++++++++++---- parser/html/nsHtml5TreeBuilderCppSupplement.h | 10 +++++++--- parser/html/nsHtml5TreeOpExecutor.cpp | 6 ++++-- parser/html/nsHtml5TreeOpExecutor.h | 3 ++- 6 files changed, 41 insertions(+), 13 deletions(-) (limited to 'parser') diff --git a/parser/html/java/htmlparser/src/nu/validator/htmlparser/impl/AttributeName.java b/parser/html/java/htmlparser/src/nu/validator/htmlparser/impl/AttributeName.java index aaf0b7b91..b08e41baa 100644 --- a/parser/html/java/htmlparser/src/nu/validator/htmlparser/impl/AttributeName.java +++ b/parser/html/java/htmlparser/src/nu/validator/htmlparser/impl/AttributeName.java @@ -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 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 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 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); @@ -1464,6 +1465,7 @@ public final class AttributeName XLINK_SHOW, COLOR_RENDERING, IDEOGRAPHIC, + NOMODULE, ONMOUSEWHEEL, ONCONTEXTMENU, ONMOUSEMOVE, diff --git a/parser/html/nsHtml5SpeculativeLoad.cpp b/parser/html/nsHtml5SpeculativeLoad.cpp index 7bae0699f..35c11b739 100644 --- a/parser/html/nsHtml5SpeculativeLoad.cpp +++ b/parser/html/nsHtml5SpeculativeLoad.cpp @@ -52,17 +52,27 @@ nsHtml5SpeculativeLoad::Perform(nsHtml5TreeOpExecutor* aExecutor) case eSpeculativeLoadScript: aExecutor->PreloadScript(mUrl, mCharset, mTypeOrCharsetSourceOrDocumentMode, mCrossOrigin, mIntegrity, false, - mIsAsync, mIsDefer); + mIsAsync, mIsDefer, false); break; case eSpeculativeLoadScriptFromHead: aExecutor->PreloadScript(mUrl, mCharset, mTypeOrCharsetSourceOrDocumentMode, 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; case eSpeculativeLoadStyle: aExecutor->PreloadStyle(mUrl, mCharset, mCrossOrigin, mIntegrity); break; - case eSpeculativeLoadManifest: + case eSpeculativeLoadManifest: aExecutor->ProcessOfflineManifest(mUrl); break; case eSpeculativeLoadSetDocumentCharset: { diff --git a/parser/html/nsHtml5SpeculativeLoad.h b/parser/html/nsHtml5SpeculativeLoad.h index fcc84de4f..1f4a61741 100644 --- a/parser/html/nsHtml5SpeculativeLoad.h +++ b/parser/html/nsHtml5SpeculativeLoad.h @@ -10,7 +10,8 @@ class nsHtml5TreeOpExecutor; -enum eHtml5SpeculativeLoad { +enum eHtml5SpeculativeLoad +{ #ifdef DEBUG eSpeculativeLoadUninitialized, #endif @@ -23,6 +24,8 @@ enum eHtml5SpeculativeLoad { eSpeculativeLoadPictureSource, eSpeculativeLoadScript, eSpeculativeLoadScriptFromHead, + eSpeculativeLoadNoModuleScript, + eSpeculativeLoadNoModuleScriptFromHead, eSpeculativeLoadStyle, eSpeculativeLoadManifest, eSpeculativeLoadSetDocumentCharset, @@ -130,12 +133,18 @@ class nsHtml5SpeculativeLoad { nsHtml5String aIntegrity, bool aParserInHead, bool aAsync, - bool aDefer) + bool aDefer, + bool aNoModule) { NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized, "Trying to reinitialize a speculative load!"); - mOpCode = aParserInHead ? - eSpeculativeLoadScriptFromHead : eSpeculativeLoadScript; + if (aNoModule) { + mOpCode = aParserInHead ? eSpeculativeLoadNoModuleScriptFromHead + : eSpeculativeLoadNoModuleScript; + } else { + mOpCode = aParserInHead ? eSpeculativeLoadScriptFromHead + : eSpeculativeLoadScript; + } aUrl.ToString(mUrl); aCharset.ToString(mCharset); aType.ToString(mTypeOrCharsetSourceOrDocumentMode); diff --git a/parser/html/nsHtml5TreeBuilderCppSupplement.h b/parser/html/nsHtml5TreeBuilderCppSupplement.h index 634c5c218..f09cc1853 100644 --- a/parser/html/nsHtml5TreeBuilderCppSupplement.h +++ b/parser/html/nsHtml5TreeBuilderCppSupplement.h @@ -189,15 +189,18 @@ nsHtml5TreeBuilder::createElement(int32_t aNamespace, aAttributes->contains(nsHtml5AttributeName::ATTR_ASYNC); bool defer = aAttributes->contains(nsHtml5AttributeName::ATTR_DEFER); + bool noModule = + aAttributes->contains(nsHtml5AttributeName::ATTR_NOMODULE); mSpeculativeLoadQueue.AppendElement()->InitScript( url, charset, type, crossOrigin, integrity, - mode == nsHtml5TreeBuilder::IN_HEAD, + mode == nsHtml5TreeBuilder::IN_HEAD, async, - defer); + defer, + noModule); mCurrentHtmlScriptIsAsyncOrDefer = async || defer; } } else if (nsHtml5Atoms::link == aName) { @@ -303,7 +306,8 @@ nsHtml5TreeBuilder::createElement(int32_t aNamespace, integrity, mode == nsHtml5TreeBuilder::IN_HEAD, false /* async */, - false /* defer */); + false /* defer */, + false /* noModule */); } } else if (nsHtml5Atoms::style == aName) { nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement(); diff --git a/parser/html/nsHtml5TreeOpExecutor.cpp b/parser/html/nsHtml5TreeOpExecutor.cpp index 9be7f3b0d..cd5c68913 100644 --- a/parser/html/nsHtml5TreeOpExecutor.cpp +++ b/parser/html/nsHtml5TreeOpExecutor.cpp @@ -923,14 +923,16 @@ nsHtml5TreeOpExecutor::PreloadScript(const nsAString& aURL, const nsAString& aIntegrity, bool aScriptFromHead, bool aAsync, - bool aDefer) + bool aDefer, + bool aNoModule) { nsCOMPtr uri = ConvertIfNotPreloadedYet(aURL); if (!uri) { return; } mDocument->ScriptLoader()->PreloadURI(uri, aCharset, aType, aCrossOrigin, - aIntegrity, aScriptFromHead, aAsync, aDefer, + aIntegrity, aScriptFromHead, aAsync, + aDefer, aNoModule, mSpeculationReferrerPolicy); } diff --git a/parser/html/nsHtml5TreeOpExecutor.h b/parser/html/nsHtml5TreeOpExecutor.h index 64a5daa96..878f359c5 100644 --- a/parser/html/nsHtml5TreeOpExecutor.h +++ b/parser/html/nsHtml5TreeOpExecutor.h @@ -251,7 +251,8 @@ class nsHtml5TreeOpExecutor final : public nsHtml5DocumentBuilder, const nsAString& aIntegrity, bool aScriptFromHead, bool aAsync, - bool aDefer); + bool aDefer, + bool aNoModule); void PreloadStyle(const nsAString& aURL, const nsAString& aCharset, const nsAString& aCrossOrigin, -- cgit v1.2.3