diff options
author | Moonchild <moonchild@palemoon.org> | 2020-09-08 08:22:28 +0000 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2020-09-08 08:22:28 +0000 |
commit | 4f18d50091ee116e861b42504ad044ded41dff4d (patch) | |
tree | 943ce40b8380af5bccbf2fa1f801b7c7a864ffaa | |
parent | 7fb5c6d8acc775763f5a96813aa58a54ff1e0894 (diff) | |
download | uxp-4f18d50091ee116e861b42504ad044ded41dff4d.tar.gz |
Issue mcp-graveyard/UXP#618 - Make ES6 modules work for resource: URIs
-rw-r--r-- | dom/script/ScriptLoader.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp index 851987ed19..71838580f1 100644 --- a/dom/script/ScriptLoader.cpp +++ b/dom/script/ScriptLoader.cpp @@ -2446,6 +2446,18 @@ ScriptLoader::NumberOfProcessors() return mNumberOfProcessors; } +static bool +IsInternalURIScheme(nsIURI* uri) +{ + // Note: Extend this if other schemes need to be included. + bool isResource; + if (NS_SUCCEEDED(uri->SchemeIs("resource", &isResource)) && isResource) { + return true; + } + + return false; +} + nsresult ScriptLoader::PrepareLoadedRequest(ScriptLoadRequest* aRequest, nsIIncrementalStreamLoader* aLoader, @@ -2533,7 +2545,17 @@ ScriptLoader::PrepareLoadedRequest(ScriptLoadRequest* aRequest, return NS_ERROR_FAILURE; } - channel->GetURI(getter_AddRefs(request->mBaseURL)); + nsCOMPtr<nsIURI> uri; + rv = channel->GetOriginalURI(getter_AddRefs(uri)); + NS_ENSURE_SUCCESS(rv, rv); + + // Fixup internal scheme URIs like resource:, because the channel URI + // will point to file: which won't be allowed to load. + if (uri && IsInternalURIScheme(uri)) { + request->mBaseURL = uri; + } else { + channel->GetURI(getter_AddRefs(request->mBaseURL)); + } // Attempt to compile off main thread. rv = AttemptAsyncScriptCompile(request); |