diff options
author | janekptacijarabaci <janekptacijarabaci@seznam.cz> | 2018-04-14 08:45:16 +0200 |
---|---|---|
committer | janekptacijarabaci <janekptacijarabaci@seznam.cz> | 2018-04-14 08:45:16 +0200 |
commit | 700c322d3766f191cfc8b329ac2000a973677139 (patch) | |
tree | b86565c9e782cbb49df86091bf187dbf678a342b | |
parent | 87e4f43be04313da7b4b5ede81c9c97b6bd5394c (diff) | |
download | UXP-700c322d3766f191cfc8b329ac2000a973677139.tar UXP-700c322d3766f191cfc8b329ac2000a973677139.tar.gz UXP-700c322d3766f191cfc8b329ac2000a973677139.tar.lz UXP-700c322d3766f191cfc8b329ac2000a973677139.tar.xz UXP-700c322d3766f191cfc8b329ac2000a973677139.zip |
Bug 1330657 - Enable <script type="module"> behind a pref
-rw-r--r-- | dom/base/nsScriptLoader.cpp | 18 | ||||
-rw-r--r-- | dom/base/nsScriptLoader.h | 2 | ||||
-rw-r--r-- | modules/libpref/init/all.js | 3 |
3 files changed, 20 insertions, 3 deletions
diff --git a/dom/base/nsScriptLoader.cpp b/dom/base/nsScriptLoader.cpp index a6d20e363..2098b8e70 100644 --- a/dom/base/nsScriptLoader.cpp +++ b/dom/base/nsScriptLoader.cpp @@ -647,6 +647,19 @@ nsScriptLoader::CheckContentPolicy(nsIDocument* aDocument, } 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 { // Returns whether we have fetched, or are currently fetching, a module script @@ -1441,8 +1454,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); @@ -2761,7 +2773,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; } diff --git a/dom/base/nsScriptLoader.h b/dom/base/nsScriptLoader.h index d30a58441..a00239be5 100644 --- a/dom/base/nsScriptLoader.h +++ b/dom/base/nsScriptLoader.h @@ -568,6 +568,8 @@ private: JS::SourceBufferHolder GetScriptSource(nsScriptLoadRequest* aRequest, nsAutoString& inlineData); + bool ModuleScriptsEnabled(); + void SetModuleFetchStarted(nsModuleLoadRequest *aRequest); void SetModuleFetchFinishedAndResumeWaitingRequests(nsModuleLoadRequest *aRequest, nsresult aResult); diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 59f8de9ac..e82cb103e 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -5568,3 +5568,6 @@ pref("dom.storageManager.enabled", false); // be blocked (automatically canceled) for that page. The counter resets // when the page is reloaded. To turn this feature off, just set the limit to 0. pref("prompts.authentication_dialog_abuse_limit", 3); + +// Whether module scripts (<script type="module">) are enabled for content. +pref("dom.moduleScripts.enabled", false); |