Bug 1330657 - Enable <script type="module"> behind a pref

This commit is contained in:
janekptacijarabaci 2018-04-14 08:45:16 +02:00 committed by Roy Tam
commit 408d61b4f0
3 changed files with 20 additions and 3 deletions

View file

@ -653,6 +653,19 @@ nsScriptLoader::CheckContentPolicy(nsIDocument* aDocument,
return NS_OK;
}
bool
nsScriptLoader::ModuleScriptsEnabled()
{
static bool sEnabledForContent = false;
static bool sCachedPref = false;
if (!sCachedPref) {
sCachedPref = true;
Preferences::AddBoolVarCache(&sEnabledForContent, "dom.moduleScripts.enabled", false);
}
return nsContentUtils::IsChromeDoc(mDocument) || sEnabledForContent;
}
bool
nsScriptLoader::ModuleMapContainsModule(nsModuleLoadRequest *aRequest) const
{
@ -1448,8 +1461,7 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
nsScriptKind scriptKind = nsScriptKind::Classic;
if (!type.IsEmpty()) {
// Support type="module" only for chrome documents.
if (nsContentUtils::IsChromeDoc(mDocument) && type.LowerCaseEqualsASCII("module")) {
if (ModuleScriptsEnabled() && type.LowerCaseEqualsASCII("module")) {
scriptKind = nsScriptKind::Module;
} else {
NS_ENSURE_TRUE(ParseTypeAttribute(type, &version), false);
@ -2768,7 +2780,7 @@ nsScriptLoader::PreloadURI(nsIURI *aURI, const nsAString &aCharset,
}
// TODO: Preload module scripts.
if (nsContentUtils::IsChromeDoc(mDocument) && aType.LowerCaseEqualsASCII("module")) {
if (ModuleScriptsEnabled() && aType.LowerCaseEqualsASCII("module")) {
return;
}