Bug 1425310 - Implement modulepreload for link rel. r=yulia,smaug,jonco

Does perform the optional step of fetching descendants and linking:
https://html.spec.whatwg.org/multipage/webappapis.html#fetching-scripts:fetch-the-descendants-of-and-link-a-module-script-2

Partially implements some new destinations ("as" attribute values) for
modulepreload only (not for preload or link attribute reflection)

Differential Revision: https://phabricator.services.mozilla.com/D172368
This commit is contained in:
Em Zhan
2023-05-13 16:09:03 +00:00
parent f6cb96b1f7
commit d6891e6ffe
18 changed files with 396 additions and 117 deletions

View File

@@ -6,6 +6,7 @@
#include "ErrorList.h"
#include "nsError.h"
#include "nsNetUtil.h"
#include "mozilla/CheckedInt.h"
#include "mozilla/Likely.h"
#include "mozilla/StaticPrefs_dom.h"
@@ -336,6 +337,35 @@ nsIContentHandle* nsHtml5TreeBuilder::createElement(
}
// Other "as" values will be supported later.
}
} else if (mozilla::StaticPrefs::network_modulepreload() &&
rel.LowerCaseEqualsASCII("modulepreload")) {
nsHtml5String url =
aAttributes->getValue(nsHtml5AttributeName::ATTR_HREF);
if (url && url.Length() != 0) {
nsHtml5String as =
aAttributes->getValue(nsHtml5AttributeName::ATTR_AS);
nsAutoString asString;
as.ToString(asString);
if (mozilla::net::IsScriptLikeOrInvalid(asString)) {
nsHtml5String charset =
aAttributes->getValue(nsHtml5AttributeName::ATTR_CHARSET);
RefPtr<nsAtom> moduleType = nsGkAtoms::_module;
nsHtml5String type =
nsHtml5String::FromAtom(moduleType.forget());
nsHtml5String crossOrigin = aAttributes->getValue(
nsHtml5AttributeName::ATTR_CROSSORIGIN);
nsHtml5String media =
aAttributes->getValue(nsHtml5AttributeName::ATTR_MEDIA);
nsHtml5String integrity = aAttributes->getValue(
nsHtml5AttributeName::ATTR_INTEGRITY);
nsHtml5String referrerPolicy = aAttributes->getValue(
nsHtml5AttributeName::ATTR_REFERRERPOLICY);
mSpeculativeLoadQueue.AppendElement()->InitScript(
url, charset, type, crossOrigin, media, integrity,
referrerPolicy, mode == nsHtml5TreeBuilder::IN_HEAD,
false, false, false, true);
}
}
}
}
} else if (nsGkAtoms::video == aName) {