Bug 595522 - Read defaults/autoconfig/* from omnijar as appropriate, r=bsmedberg a=blocking2.0
authorMichael Wu <mwu@mozilla.com>
Wed, 02 Feb 2011 15:42:10 -0800
changeset 61819 5212ab4ae8082122ad57b5e8bc8015fb25814f68
parent 61818 7f80cd5abf478daa50394bb3ffd525f77114348f
child 61820 ee00364d30927ea8981eaac56dcb6e14a343bb77
push idunknown
push userunknown
push dateunknown
reviewersbsmedberg, blocking2
bugs595522
milestone2.0b12pre
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 595522 - Read defaults/autoconfig/* from omnijar as appropriate, r=bsmedberg a=blocking2.0
extensions/pref/autoconfig/src/nsReadConfig.cpp
--- a/extensions/pref/autoconfig/src/nsReadConfig.cpp
+++ b/extensions/pref/autoconfig/src/nsReadConfig.cpp
@@ -267,72 +267,76 @@ nsresult nsReadConfig::readConfigFile()
 } // ReadConfigFile
 
 
 nsresult nsReadConfig::openAndEvaluateJSFile(const char *aFileName, PRInt32 obscureValue,
                                              PRBool isEncoded,
                                              PRBool isBinDir)
 {
     nsresult rv;
-    nsCOMPtr<nsIFile> jsFile;
 
+    nsCOMPtr<nsIInputStream> inStr;
     if (isBinDir) {
+        nsCOMPtr<nsIFile> jsFile;
         rv = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR, 
                                     getter_AddRefs(jsFile));
         if (NS_FAILED(rv)) 
             return rv;
         
 #ifdef XP_MAC
         jsFile->AppendNative(NS_LITERAL_CSTRING("Essential Files"));
 #endif
+        rv = jsFile->AppendNative(nsDependentCString(aFileName));
+        if (NS_FAILED(rv)) 
+            return rv;
+
+        rv = NS_NewLocalFileInputStream(getter_AddRefs(inStr), jsFile);
+        if (NS_FAILED(rv)) 
+            return rv;
+
     } else {
-        rv = NS_GetSpecialDirectory(NS_GRE_DIR,
-                                    getter_AddRefs(jsFile));
+        nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv);
         if (NS_FAILED(rv)) 
             return rv;
-        rv = jsFile->AppendNative(NS_LITERAL_CSTRING("defaults"));
+
+        nsCAutoString location("resource://gre/defaults/autoconfig/");
+        location += aFileName;
+
+        nsCOMPtr<nsIURI> uri;
+        rv = ioService->NewURI(location, nsnull, nsnull, getter_AddRefs(uri));
         if (NS_FAILED(rv))
             return rv;
-        rv = jsFile->AppendNative(NS_LITERAL_CSTRING("autoconfig"));
+
+        nsCOMPtr<nsIChannel> channel;
+        rv = ioService->NewChannelFromURI(uri, getter_AddRefs(channel));
         if (NS_FAILED(rv))
             return rv;
+
+        rv = channel->Open(getter_AddRefs(inStr));
+        if (NS_FAILED(rv)) 
+            return rv;
     }
-    rv = jsFile->AppendNative(nsDependentCString(aFileName));
-    if (NS_FAILED(rv)) 
-        return rv;
 
-    nsCOMPtr<nsIInputStream> inStr;
-    rv = NS_NewLocalFileInputStream(getter_AddRefs(inStr), jsFile);
-    if (NS_FAILED(rv)) 
-        return rv;        
-        
-    PRInt64 fileSize;
     PRUint32 fs, amt = 0;
-    jsFile->GetFileSize(&fileSize);
-    LL_L2UI(fs, fileSize); // Converting 64 bit structure to unsigned int
+    inStr->Available(&fs);
 
     char *buf = (char *)PR_Malloc(fs * sizeof(char));
     if (!buf) 
         return NS_ERROR_OUT_OF_MEMORY;
-      
+
     rv = inStr->Read(buf, fs, &amt);
     NS_ASSERTION((amt == fs), "failed to read the entire configuration file!!");
     if (NS_SUCCEEDED(rv)) {
         if (obscureValue > 0) {
 
             // Unobscure file by subtracting some value from every char. 
             for (PRUint32 i = 0; i < amt; i++)
                 buf[i] -= obscureValue;
         }
-        nsCAutoString path;
-
-        jsFile->GetNativePath(path);
-        nsCAutoString fileURL;
-        fileURL = NS_LITERAL_CSTRING("file:///") + path;
-        rv = EvaluateAdminConfigScript(buf, amt, fileURL.get(), 
-                                       PR_FALSE, PR_TRUE, 
+        rv = EvaluateAdminConfigScript(buf, amt, aFileName,
+                                       PR_FALSE, PR_TRUE,
                                        isEncoded ? PR_TRUE:PR_FALSE);
     }
     inStr->Close();
     PR_Free(buf);
     
     return rv;
 }