Bug 632490: Use a content-type hint in mozJSSubScriptLoader::LoadSubScript. r=shaver a=blocking-fennec
authorMatt Brubeck <mbrubeck@mozilla.com>
Tue, 08 Feb 2011 12:16:06 -0800
changeset 62189 682d008059c6740065fa388be1fe0ac47207cc4d
parent 62188 3872a1e4a8811c41dd444cdeed36e62b7a393b04
child 62190 f34826051dd5351c58cb7c3b2d8d844c72c0c474
push id1
push userroot
push dateTue, 10 Dec 2013 15:46:25 +0000
reviewersshaver, blocking-fennec
bugs632490
milestone2.0b12pre
Bug 632490: Use a content-type hint in mozJSSubScriptLoader::LoadSubScript. r=shaver a=blocking-fennec
js/src/xpconnect/loader/mozJSSubScriptLoader.cpp
--- a/js/src/xpconnect/loader/mozJSSubScriptLoader.cpp
+++ b/js/src/xpconnect/loader/mozJSSubScriptLoader.cpp
@@ -318,21 +318,28 @@ mozJSSubScriptLoader::LoadSubScript (con
 
         // For file URIs prepend the filename with the filename of the
         // calling script, and " -> ". See bug 418356.
         nsCAutoString tmp(JS_GetScriptFilename(cx, script));
         tmp.AppendLiteral(" -> ");
         tmp.Append(uriStr);
 
         uriStr = tmp;
-    }        
-        
-    rv = NS_OpenURI(getter_AddRefs(instream), uri, serv,
-                    nsnull, nsnull, nsIRequest::LOAD_NORMAL,
-                    getter_AddRefs(chan));
+    }
+
+    // Instead of calling NS_OpenURI, we create the channel ourselves and call
+    // SetContentType, to avoid expensive MIME type lookups (bug 632490).
+    rv = NS_NewChannel(getter_AddRefs(chan), uri, serv,
+                       nsnull, nsnull, nsIRequest::LOAD_NORMAL);
+    if (NS_SUCCEEDED(rv))
+    {
+        chan->SetContentType(NS_LITERAL_CSTRING("application/javascript"));
+        rv = chan->Open(getter_AddRefs(instream));
+    }
+
     if (NS_FAILED(rv))
     {
         errmsg = JS_NewStringCopyZ (cx, LOAD_ERROR_NOSTREAM);
         goto return_exception;
     }
     
     rv = chan->GetContentLength (&len);
     if (NS_FAILED(rv) || len == -1)