Bug 508421 - move res/ stuff into toolkit.jar (r=bsmedberg)
authortglek@mozilla.com
Thu, 27 Aug 2009 08:35:48 -0700
changeset 32031 a0c23bfa5219498a62b738f7b619fff9c933d280
parent 32030 8a4ff86268ea2ccdb3a3b9be349f1f27aebda005
child 32032 b0be3786ac2dccfa59dea974bccdba7b880f9811
push idunknown
push userunknown
push dateunknown
reviewersbsmedberg
bugs508421
milestone1.9.3a1pre
Bug 508421 - move res/ stuff into toolkit.jar (r=bsmedberg) * * * * * *
browser/installer/unix/packages-static
browser/installer/windows/packages-static
configure.in
intl/uconv/src/Makefile.in
intl/uconv/src/jar.mn
intl/uconv/src/nsCharsetConverterManager.cpp
intl/uconv/src/nsGREResProperties.cpp
netwerk/protocol/res/src/nsResProtocolHandler.cpp
netwerk/test/unit/test_gre_resources.js
--- a/browser/installer/unix/packages-static
+++ b/browser/installer/unix/packages-static
@@ -320,18 +320,16 @@ bin/res/viewsource.css
 bin/res/mathml.css
 bin/res/arrow.gif
 bin/res/loading-image.png
 bin/res/broken-image.png
 bin/res/fonts/*
 bin/res/dtd/*
 bin/res/html/*
 bin/res/unixcharset.properties
-bin/res/charsetalias.properties
-bin/res/charsetData.properties
 bin/res/langGroups.properties
 bin/res/language.properties
 bin/res/entityTables/*
 
 ; svg
 bin/res/svg.css
 bin/components/dom_svg.xpt
 #ifdef MOZ_SMIL
--- a/browser/installer/windows/packages-static
+++ b/browser/installer/windows/packages-static
@@ -326,18 +326,16 @@ bin\res\viewsource.css
 bin\res\mathml.css
 bin\res\arrow.gif
 bin\res\loading-image.png
 bin\res\broken-image.png
 bin\res\fonts\*
 bin\res\dtd\*
 bin\res\html\*
 bin\res\wincharset.properties
-bin\res\charsetalias.properties
-bin\res\charsetData.properties
 bin\res\langGroups.properties
 bin\res\language.properties
 bin\res\entityTables\*
 
 ; svg
 bin\res\svg.css
 bin\components\dom_svg.xpt
 #ifdef MOZ_SMIL
--- a/configure.in
+++ b/configure.in
@@ -7032,16 +7032,19 @@ fi
 
 if test "$MOZ_CHROME_FILE_FORMAT" != "jar" && 
     test "$MOZ_CHROME_FILE_FORMAT" != "flat" &&
     test "$MOZ_CHROME_FILE_FORMAT" != "symlink" &&
     test "$MOZ_CHROME_FILE_FORMAT" != "both"; then
     AC_MSG_ERROR([--enable-chrome-format must be set to either jar, flat, both, or symlink])
 fi
 
+if test "$MOZ_CHROME_FILE_FORMAT" = "jar"; then
+   AC_DEFINE(MOZ_CHROME_FILE_FORMAT_JAR)
+fi
 dnl ========================================================
 dnl = Define default location for MOZILLA_FIVE_HOME
 dnl ========================================================
 MOZ_ARG_WITH_STRING(default-mozilla-five-home,
 [  --with-default-mozilla-five-home
                           Set the default value for MOZILLA_FIVE_HOME],
 [ val=`echo $withval`
   AC_DEFINE_UNQUOTED(MOZ_DEFAULT_MOZILLA_FIVE_HOME,"$val") ])
--- a/intl/uconv/src/Makefile.in
+++ b/intl/uconv/src/Makefile.in
@@ -78,21 +78,16 @@ CPPSRCS         += \
 		nsMacRomanToUnicode.cpp \
 		nsUnicodeToISO88591.cpp \
 		nsUnicodeToCP1252.cpp \
 		nsUnicodeToMacRoman.cpp \
 		$(NULL)
 
 endif
 
-EXPORT_RESOURCE	= \
-		charsetalias.properties \
-		charsetData.properties \
-		$(NULL)
-
 ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
 CPPSRCS			+= nsOS2Charset.cpp
 EXPORT_RESOURCE		+= os2charset.properties
 else
 ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
 CPPSRCS			+= nsWinCharset.cpp
 EXPORT_RESOURCE		+= wincharset.properties
 else
new file mode 100644
--- /dev/null
+++ b/intl/uconv/src/jar.mn
@@ -0,0 +1,3 @@
+toolkit.jar:
+        res/charsetalias.properties    (charsetalias.properties)
+        res/charsetData.properties     (charsetData.properties)
--- a/intl/uconv/src/nsCharsetConverterManager.cpp
+++ b/intl/uconv/src/nsCharsetConverterManager.cpp
@@ -99,17 +99,17 @@ nsresult nsCharsetConverterManager::Regi
   nsresult rv;
   nsCOMPtr<nsICategoryManager> catman = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
   if (NS_FAILED(rv))
     return rv;
 
   RegisterConverterCategory(catman, NS_TITLE_BUNDLE_CATEGORY,
                             "chrome://global/locale/charsetTitles.properties");
   RegisterConverterCategory(catman, NS_DATA_BUNDLE_CATEGORY,
-                            "resource://gre/res/charsetData.properties");
+                            "resource://gre-resources/charsetData.properties");
 
   return NS_OK;
 }
 
 nsresult
 nsCharsetConverterManager::RegisterConverterCategory(nsICategoryManager* catman,
                                                      const char* aCategory,
                                                      const char* aURL)
--- a/intl/uconv/src/nsGREResProperties.cpp
+++ b/intl/uconv/src/nsGREResProperties.cpp
@@ -38,29 +38,35 @@
 #include "nsGREResProperties.h"
 #include "nsILocalFile.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsDirectoryServiceUtils.h"
 #include "nsNetUtil.h"
 
 nsGREResProperties::nsGREResProperties(const nsACString& aFile)
 {
-  nsCOMPtr<nsIFile> file;
-  nsresult rv = NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(file));
+  nsresult rv;
+  nsCOMPtr<nsIIOService> ioservice(do_GetIOService(&rv));
+  nsCOMPtr<nsIInputStream> inStr;
+  nsCOMPtr<nsIURI> uri;
+  nsCOMPtr<nsIChannel> channel;
+  printf("nsGREResProperties %s\n", aFile.BeginReading());
   if (NS_FAILED(rv))
     return;
 
-  file->AppendNative(NS_LITERAL_CSTRING("res"));
-  file->AppendNative(aFile);
+  rv = ioservice->NewURI(NS_LITERAL_CSTRING("resource://gre-resources/") + aFile,
+                         nsnull, nsnull, getter_AddRefs(uri));
+  if (NS_FAILED(rv))
+    return;
 
-  nsCOMPtr<nsILocalFile> lf(do_QueryInterface(file));
-  NS_ENSURE_TRUE(lf, /**/);
+  rv = NS_NewChannel(getter_AddRefs(channel), uri, ioservice);
+  if (NS_FAILED(rv))
+    return;
 
-  nsCOMPtr<nsIInputStream> inStr;
-  rv = NS_NewLocalFileInputStream(getter_AddRefs(inStr), lf);
+  rv = channel->Open(getter_AddRefs(inStr));
   if (NS_FAILED(rv))
     return;
 
   mProps = do_CreateInstance(NS_PERSISTENTPROPERTIES_CONTRACTID);
   if (mProps) {
     rv = mProps->Load(inStr);
     if (NS_FAILED(rv))
       mProps = nsnull;
--- a/netwerk/protocol/res/src/nsResProtocolHandler.cpp
+++ b/netwerk/protocol/res/src/nsResProtocolHandler.cpp
@@ -166,19 +166,32 @@ nsResProtocolHandler::Init()
     // make resource:/// point to the application directory
     //
     rv = AddSpecialDir(NS_OS_CURRENT_PROCESS_DIR, EmptyCString());
     NS_ENSURE_SUCCESS(rv, rv);
 
     //
     // make resource://gre/ point to the GRE directory
     //
-    rv = AddSpecialDir(NS_GRE_DIR, NS_LITERAL_CSTRING("gre"));
+    NS_NAMED_LITERAL_CSTRING(strGRE_DIR, "gre");
+    rv = AddSpecialDir(NS_GRE_DIR, strGRE_DIR);
     NS_ENSURE_SUCCESS(rv, rv);
 
+    // make resource://gre-resources/ point to gre toolkit[.jar]/res
+    nsCOMPtr<nsIURI> greURI;
+    nsCOMPtr<nsIURI> greResURI;
+    GetSubstitution(strGRE_DIR, getter_AddRefs(greURI));
+#ifdef MOZ_CHROME_FILE_FORMAT_JAR
+    NS_NAMED_LITERAL_CSTRING(strGRE_RES_URL, "jar:chrome/toolkit.jar!/res/");
+#else
+    NS_NAMED_LITERAL_CSTRING(strGRE_RES_URL, "chrome/toolkit/res/");
+#endif
+    rv = mIOService->NewURI(strGRE_RES_URL, nsnull, greURI,
+                            getter_AddRefs(greResURI));
+    SetSubstitution(NS_LITERAL_CSTRING("gre-resources"), greResURI);
     //XXXbsmedberg Neil wants a resource://pchrome/ for the profile chrome dir...
     // but once I finish multiple chrome registration I'm not sure that it is needed
 
     // XXX dveditz: resource://pchrome/ defeats profile directory salting
     // if web content can load it. Tread carefully.
 
     return rv;
 }
new file mode 100644
--- /dev/null
+++ b/netwerk/test/unit/test_gre_resources.js
@@ -0,0 +1,29 @@
+// test that things that are expected to be in gre-resources are still there
+
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+var ios = Cc["@mozilla.org/network/io-service;1"]. getService(Ci.nsIIOService);
+
+function wrapInputStream(input)
+{
+  var nsIScriptableInputStream = Components.interfaces.nsIScriptableInputStream;
+  var factory = Components.classes["@mozilla.org/scriptableinputstream;1"];
+  var wrapper = factory.createInstance(nsIScriptableInputStream);
+  wrapper.init(input);
+  return wrapper;
+}
+
+function check_file(file) {
+  var channel = ios.newChannel("resource://gre-resources/"+file, null, null);
+  try {
+    let instr = wrapInputStream(channel.open());
+    do_check_true(instr.read(1024).length > 0)
+  } catch (e) {
+    do_throw("Failed to read " + file + " from gre-resources:"+e)
+  }
+}
+
+function run_test() {
+  for each(let file in ["charsetalias.properties", "charsetData.properties"])
+    check_file(file)
+}