Bug 1453559 - Don't use channel URI for loading modules from resource: scheme r=baku
authorJon Coppeard <jcoppeard@mozilla.com>
Fri, 13 Apr 2018 14:15:33 +0100
changeset 413230 d0f8f8120bc6bb528b140aab5c99dc57816c0607
parent 413182 c51da7704570d4819da64d33dc7bf8ec9d2639d5
child 413231 dfb12ea49fd7d8883329ed4dbe2e0da6d1d81ac1
push id33840
push userapavel@mozilla.com
push dateFri, 13 Apr 2018 21:56:54 +0000
treeherdermozilla-central@6547c27303bc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1453559
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1453559 - Don't use channel URI for loading modules from resource: scheme r=baku
dom/script/ScriptLoader.cpp
--- a/dom/script/ScriptLoader.cpp
+++ b/dom/script/ScriptLoader.cpp
@@ -3049,16 +3049,32 @@ ScriptLoader::NumberOfProcessors()
     return mNumberOfProcessors;
 
   int32_t numProcs = PR_GetNumberOfProcessors();
   if (numProcs > 0)
     mNumberOfProcessors = numProcs;
   return mNumberOfProcessors;
 }
 
+static bool
+IsInternalURIScheme(nsIURI* uri)
+{
+  bool isWebExt;
+  if (NS_SUCCEEDED(uri->SchemeIs("moz-extension", &isWebExt)) && isWebExt) {
+    return true;
+  }
+
+  bool isResource;
+  if (NS_SUCCEEDED(uri->SchemeIs("resource", &isResource)) && isResource) {
+    return true;
+  }
+
+  return false;
+}
+
 nsresult
 ScriptLoader::PrepareLoadedRequest(ScriptLoadRequest* aRequest,
                                    nsIIncrementalStreamLoader* aLoader,
                                    nsresult aStatus)
 {
   if (NS_FAILED(aStatus)) {
     return aStatus;
   }
@@ -3137,20 +3153,19 @@ ScriptLoader::PrepareLoadedRequest(Scrip
     if (!nsContentUtils::IsJavascriptMIMEType(typeString)) {
       return NS_ERROR_FAILURE;
     }
 
     nsCOMPtr<nsIURI> uri;
     rv = channel->GetOriginalURI(getter_AddRefs(uri));
     NS_ENSURE_SUCCESS(rv, rv);
 
-    // Fixup moz-extension URIs, because the channel URI points to file:,
-    // which won't be allowed to load.
-    bool isWebExt = false;
-    if (uri && NS_SUCCEEDED(uri->SchemeIs("moz-extension", &isWebExt)) && isWebExt) {
+    // Fixup moz-extension: and resource: URIs, 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);