Bug 568691 - Fix MOZ_OMNIJAR registration, r=mwu
authorBenjamin Smedberg <benjamin@smedbergs.us>
Fri, 02 Jul 2010 09:53:19 -0400
changeset 47130 a5f7f9e82281ef5c713c2ed0d902236fe8c5e2e2
parent 47129 6b5b08f6856bfcf0b1a6b7470d2727d9b516d354
child 47131 dc446291a715cbb4994c299426139a8f7f70b768
push idunknown
push userunknown
push dateunknown
reviewersmwu
bugs568691
milestone2.0b2pre
Bug 568691 - Fix MOZ_OMNIJAR registration, r=mwu
chrome/src/nsChromeRegistry.h
chrome/src/nsChromeRegistryChrome.cpp
modules/libjar/nsManifestZIPLoader.cpp
modules/libjar/nsManifestZIPLoader.h
modules/libjar/nsXPTZipLoader.cpp
modules/libjar/nsXPTZipLoader.h
modules/libjar/objs.mk
xpcom/components/Makefile.in
xpcom/components/ManifestParser.cpp
xpcom/components/ManifestParser.h
xpcom/components/ModuleLoader.h
xpcom/components/nsComponentManager.cpp
xpcom/components/nsComponentManager.h
xpcom/components/nsIManifestLoader.idl
xpcom/reflect/xptinfo/public/Makefile.in
xpcom/reflect/xptinfo/public/nsIXPTLoader.idl
xpcom/reflect/xptinfo/src/xptiInterfaceInfo.cpp
xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp
xpcom/reflect/xptinfo/src/xptiprivate.h
--- a/chrome/src/nsChromeRegistry.h
+++ b/chrome/src/nsChromeRegistry.h
@@ -56,16 +56,18 @@
 #include "nsString.h"
 #include "nsTHashtable.h"
 #include "nsURIHashKey.h"
 #include "nsInterfaceHashtable.h"
 #include "nsXULAppAPI.h"
 #include "nsIResProtocolHandler.h"
 #include "nsIXPConnect.h"
 
+#include "mozilla/Omnijar.h"
+
 class nsIDOMWindowInternal;
 class nsIURL;
 
 // The chrome registry is actually split between nsChromeRegistryChrome and
 // nsChromeRegistryContent. The work/data that is common to both resides in
 // the shared nsChromeRegistry implementation, with operations that only make
 // sense for one side erroring out in the other.
 
@@ -132,27 +134,38 @@ protected:
 public:
   static already_AddRefed<nsChromeRegistry> GetSingleton();
 
   struct ManifestProcessingContext
   {
     ManifestProcessingContext(NSLocationType aType, nsILocalFile* aFile)
       : mType(aType)
       , mFile(aFile)
+      , mPath(NULL)
     { }
+
+#ifdef MOZ_OMNIJAR
+    ManifestProcessingContext(NSLocationType aType, const char* aPath)
+      : mType(aType)
+      , mFile(mozilla::OmnijarPath())
+      , mPath(aPath)
+    { }
+#endif
+
     ~ManifestProcessingContext()
     { }
 
     nsIURI* GetManifestURI();
     nsIXPConnect* GetXPConnect();
 
     already_AddRefed<nsIURI> ResolveURI(const char* uri);
 
     NSLocationType mType;
-    nsCOMPtr<nsILocalFile> mFile;
+    nsILocalFile* mFile;
+    const char* mPath;
     nsCOMPtr<nsIURI> mManifestURI;
     nsCOMPtr<nsIXPConnect> mXPConnect;
   };
 
   virtual void ManifestContent(ManifestProcessingContext& cx, int lineno,
                                char *const * argv, bool platform,
                                bool contentaccessible) = 0;
   virtual void ManifestLocale(ManifestProcessingContext& cx, int lineno,
--- a/chrome/src/nsChromeRegistryChrome.cpp
+++ b/chrome/src/nsChromeRegistryChrome.cpp
@@ -408,58 +408,16 @@ nsChromeRegistryChrome::Observe(nsISuppo
   }
   else {
     NS_ERROR("Unexpected observer topic!");
   }
 
   return rv;
 }
 
-#ifdef MOZ_OMNIJAR
-nsresult
-nsChromeRegistryChrome::CheckOmnijarChrome()
-{
-  nsresult rv;
-
-  nsZipArchive* jarReader = mozilla::OmnijarReader();
-  // just proceed normally if there is no omnijar
-  if (!jarReader)
-    return NS_OK;
-
-  nsZipItem* manifest = jarReader->GetItem("chrome/chrome.manifest");
-  NS_ENSURE_TRUE(manifest, NS_ERROR_NOT_AVAILABLE);
-
-  nsCAutoString omniJarSpec;
-  rv = NS_GetURLSpecFromActualFile(mozilla::OmnijarPath(), omniJarSpec);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  PRUint32 len = manifest->RealSize();
-  nsAutoArrayPtr<PRUint8> outbuf(new PRUint8[len]);
-  NS_ENSURE_TRUE(outbuf, NS_ERROR_OUT_OF_MEMORY);
-
-  nsZipCursor cursor(manifest, jarReader, outbuf, len);
-  PRUint32 readlen;
-  PRUint8* buf = cursor.Read(&readlen);
-  NS_ENSURE_TRUE(buf, NS_ERROR_FILE_CORRUPTED);
-
-  nsAutoString jarString(NS_LITERAL_STRING("jar:"));
-  AppendUTF8toUTF16(omniJarSpec, jarString);
-  jarString += NS_LITERAL_STRING("!/chrome/chrome.manifest"); 
-
-  nsCOMPtr<nsIURI> manifestURI;
-  rv = NS_NewURI(getter_AddRefs(manifestURI), jarString);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  rv = ProcessManifestBuffer((char *)buf, readlen, manifestURI, PR_FALSE);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  return rv;
-}
-#endif /* MOZ_OMNIJAR */
-
 NS_IMETHODIMP
 nsChromeRegistryChrome::CheckForNewChrome()
 {
   PL_DHashTableEnumerate(&mPackagesHash, RemoveAll, nsnull);
   mOverlayHash.Clear();
   mStyleHash.Clear();
   mOverrideTable.Clear();
 
@@ -825,17 +783,34 @@ nsChromeRegistry::ManifestProcessingCont
 {
   if (!mManifestURI) {
     nsCOMPtr<nsIIOService> io = mozilla::services::GetIOService();
     if (!io) {
       NS_WARNING("No IO service trying to process chrome manifests");
       return NULL;
     }
 
-    io->NewFileURI(mFile, getter_AddRefs(mManifestURI));
+#ifdef MOZ_OMNIJAR
+    if (mPath) {
+      nsCOMPtr<nsIURI> fileURI;
+      io->NewFileURI(mFile, getter_AddRefs(fileURI));
+
+      nsCAutoString spec;
+      fileURI->GetSpec(spec);
+      spec.Insert(NS_LITERAL_CSTRING("jar:"), 0);
+      spec.AppendLiteral("!/");
+      spec.Append(mPath);
+
+      NS_NewURI(getter_AddRefs(mManifestURI), spec, NULL, NULL, io);
+    }
+    else
+#endif
+    {
+      io->NewFileURI(mFile, getter_AddRefs(mManifestURI));
+    }
   }
   return mManifestURI;
 }
 
 nsIXPConnect*
 nsChromeRegistry::ManifestProcessingContext::GetXPConnect()
 {
   if (!mXPConnect)
rename from modules/libjar/nsXPTZipLoader.cpp
rename to modules/libjar/nsManifestZIPLoader.cpp
--- a/modules/libjar/nsXPTZipLoader.cpp
+++ b/modules/libjar/nsManifestZIPLoader.cpp
@@ -33,77 +33,84 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 
-#include "nsXPTZipLoader.h"
+#include "nsManifestZIPLoader.h"
 #include "nsJAR.h"
 #include "nsString.h"
 #include "nsStringEnumerator.h"
 
-nsXPTZipLoader::nsXPTZipLoader() {
+nsManifestZIPLoader::nsManifestZIPLoader() {
 }
 
-NS_IMPL_ISUPPORTS1(nsXPTZipLoader, nsIXPTLoader)
+NS_IMPL_ISUPPORTS1(nsManifestZIPLoader, nsIManifestLoader)
 
 nsresult
-nsXPTZipLoader::LoadEntry(nsILocalFile* aFile,
-                          const char* aName,
-                          nsIInputStream** aResult)
+nsManifestZIPLoader::LoadEntry(nsILocalFile* aFile,
+                               const char* aName,
+                               nsIInputStream** aResult)
 {
     nsCOMPtr<nsIZipReader> zip = dont_AddRef(GetZipReader(aFile));
 
     if (!zip)
         return NS_OK;
 
     return zip->GetInputStream(aName, aResult);
 }
+
+static void
+EnumerateEntriesForPattern(nsIZipReader* zip, const char* pattern,
+                           nsIManifestLoaderSink* aSink)
+{
+    nsCOMPtr<nsIUTF8StringEnumerator> entries;
+    if (NS_FAILED(zip->FindEntries(pattern, getter_AddRefs(entries))) ||
+        !entries) {
+        return;
+    }
+
+    PRBool hasMore;
+    int index = 0;
+    while (NS_SUCCEEDED(entries->HasMore(&hasMore)) && hasMore) {
+        nsCAutoString itemName;
+        if (NS_FAILED(entries->GetNext(itemName)))
+            return;
+
+        nsCOMPtr<nsIInputStream> stream;
+        if (NS_FAILED(zip->GetInputStream(itemName.get(), getter_AddRefs(stream))))
+            continue;
+
+        // ignore the result
+        aSink->FoundEntry(itemName.get(), index++, stream);
+    }
+}
     
 nsresult
-nsXPTZipLoader::EnumerateEntries(nsILocalFile* aFile,
-                                 nsIXPTLoaderSink* aSink)
+nsManifestZIPLoader::EnumerateEntries(nsILocalFile* aFile,
+                                      nsIManifestLoaderSink* aSink)
 {
     nsCOMPtr<nsIZipReader> zip = dont_AddRef(GetZipReader(aFile));
 
     if (!zip) {
         NS_WARNING("Could not get Zip Reader");
         return NS_OK;
     }
 
-    nsCOMPtr<nsIUTF8StringEnumerator> entries;
-    if (NS_FAILED(zip->FindEntries("*.xpt", getter_AddRefs(entries))) ||
-        !entries) {
-        // no problem, just no .xpt files in this archive
-        return NS_OK;
-    }
-
-    PRBool hasMore;
-    int index = 0;
-    while (NS_SUCCEEDED(entries->HasMore(&hasMore)) && hasMore) {
-        nsCAutoString itemName;
-        if (NS_FAILED(entries->GetNext(itemName)))
-            return NS_ERROR_UNEXPECTED;
-
-        nsCOMPtr<nsIInputStream> stream;
-        if (NS_FAILED(zip->GetInputStream(itemName.get(), getter_AddRefs(stream))))
-            return NS_ERROR_FAILURE;
-
-        // ignore the result
-        aSink->FoundEntry(itemName.get(), index++, stream);
-    }
+    EnumerateEntriesForPattern(zip, "components/*.manifest$", aSink);
+    EnumerateEntriesForPattern(zip, "chrome/*.manifest$", aSink);
 
     return NS_OK;
 }
 
 already_AddRefed<nsIZipReader>
-nsXPTZipLoader::GetZipReader(nsILocalFile* file)
+nsManifestZIPLoader::GetZipReader(nsILocalFile* file)
 {
     NS_ASSERTION(file, "bad file");
     
     nsCOMPtr<nsIZipReader> reader = new nsJAR();
     nsresult rv = reader->Open(file);
     if (NS_FAILED(rv))
         return NULL;
 
rename from modules/libjar/nsXPTZipLoader.h
rename to modules/libjar/nsManifestZIPLoader.h
--- a/modules/libjar/nsXPTZipLoader.h
+++ b/modules/libjar/nsManifestZIPLoader.h
@@ -33,25 +33,25 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsISupports.h"
-#include "nsIXPTLoader.h"
+#include "nsIManifestLoader.h"
 
 #include "nsIZipReader.h"
 
-class nsXPTZipLoader : public nsIXPTLoader
+class nsManifestZIPLoader : public nsIManifestLoader
 {
  public:
-    nsXPTZipLoader();
-    virtual ~nsXPTZipLoader() {}
+    nsManifestZIPLoader();
+    virtual ~nsManifestZIPLoader() {}
     
     NS_DECL_ISUPPORTS
-    NS_DECL_NSIXPTLOADER
+    NS_DECL_NSIMANIFESTLOADER
 
  private:
     already_AddRefed<nsIZipReader> GetZipReader(nsILocalFile* aFile);
 };
 
--- a/modules/libjar/objs.mk
+++ b/modules/libjar/objs.mk
@@ -35,26 +35,26 @@
 #
 # ***** END LICENSE BLOCK *****
 
 MODULES_LIBJAR_LCPPSRCS = \
 		nsZipArchive.cpp \
 		nsJARInputStream.cpp \
 		nsJAR.cpp \
 		nsJARFactory.cpp \
-		nsXPTZipLoader.cpp \
+		nsManifestZIPLoader.cpp \
 		nsJARProtocolHandler.cpp \
 		nsJARChannel.cpp  \
 		nsJARURI.cpp  \
 		$(NULL)
 
 MODULES_LIBJAR_LEXPORTS = \
 		zipstruct.h \
 		nsZipArchive.h \
-		nsXPTZipLoader.h \
+		nsManifestZIPLoader.h \
 		$(NULL)
 
 MODULES_LIBJAR_LXPIDLSRCS = \
 		nsIZipReader.idl \
 		nsIJARChannel.idl \
 		nsIJARURI.idl \
 		nsIJARProtocolHandler.idl \
 		$(NULL)
--- a/xpcom/components/Makefile.in
+++ b/xpcom/components/Makefile.in
@@ -71,16 +71,17 @@ CPPSRCS		= \
 SDK_XPIDLSRCS	= \
 		nsIClassInfo.idl	      \
 		nsIComponentRegistrar.idl     \
 		nsIFactory.idl		      \
 		nsIModule.idl		      \
 		nsIServiceManager.idl	      \
 		nsIComponentManager.idl       \
 		nsICategoryManager.idl        \
+		nsIManifestLoader.idl         \
 		$(NULL)
 
 LOCAL_INCLUDES	= \
 	-I$(srcdir)/../reflect/xptinfo/src \
 	-I$(srcdir)/../base \
 	-I$(srcdir)/../thread \
 	-I$(srcdir)/../ds \
 	-I$(srcdir)/../build \
--- a/xpcom/components/ManifestParser.cpp
+++ b/xpcom/components/ManifestParser.cpp
@@ -157,27 +157,32 @@ void LogMessage(const char* aMsg, ...)
   AutoPR_smprintf_free formatted(PR_vsmprintf(aMsg, args));
   va_end(args);
 
   nsCOMPtr<nsIConsoleMessage> error =
     new nsConsoleMessage(NS_ConvertUTF8toUTF16(formatted).get());
   console->LogMessage(error);
 }
 
-void LogMessageWithContext(nsILocalFile* aFile, PRUint32 aLineNumber, const char* aMsg, ...)
+void LogMessageWithContext(nsILocalFile* aFile, const char* aPath,
+                           PRUint32 aLineNumber, const char* aMsg, ...)
 {
   va_list args;
   va_start(args, aMsg);
   AutoPR_smprintf_free formatted(PR_vsmprintf(aMsg, args));
   va_end(args);
   if (!formatted)
     return;
 
   nsString file;
   aFile->GetPath(file);
+  if (aPath) {
+    file.Append(':');
+    file.Append(NS_ConvertUTF8toUTF16(aPath));
+  }
 
   nsCOMPtr<nsIScriptError> error =
     do_CreateInstance(NS_SCRIPTERROR_CONTRACTID);
   if (!error) {
     // This can happen early in component registration. Fall back to a
     // generic console message.
     LogMessage("Warning: in file '%s', line %i: %s",
                NS_ConvertUTF16toUTF8(file).get(),
@@ -393,25 +398,24 @@ namespace {
 struct CachedDirective
 {
   int lineno;
   char* argv[4];
 };
 
 } // anonymous namespace
 
-void
-ParseManifest(NSLocationType aType, nsILocalFile* aFile, char* buf,
-              bool aChromeOnly)
+static void
+ParseManifestCommon(NSLocationType aType, nsILocalFile* aFile,
+                    nsComponentManagerImpl::ManifestProcessingContext& mgrcx,
+                    nsChromeRegistry::ManifestProcessingContext& chromecx,
+                    const char* aPath, char* buf, bool aChromeOnly)
 {
   nsresult rv;
 
-  nsComponentManagerImpl::ManifestProcessingContext mgrcx(aType, aFile);
-  nsChromeRegistry::ManifestProcessingContext chromecx(aType, aFile);
-
   NS_NAMED_LITERAL_STRING(kPlatform, "platform");
   NS_NAMED_LITERAL_STRING(kContentAccessible, "contentaccessible");
   NS_NAMED_LITERAL_STRING(kApplication, "application");
   NS_NAMED_LITERAL_STRING(kAppVersion, "appversion");
   NS_NAMED_LITERAL_STRING(kOs, "os");
   NS_NAMED_LITERAL_STRING(kOsVersion, "osversion");
   NS_NAMED_LITERAL_STRING(kABI, "abi");
 
@@ -510,31 +514,37 @@ ParseManifest(NSLocationType aType, nsIL
 	 d < kParsingTable + NS_ARRAY_LENGTH(kParsingTable);
 	 ++d) {
       if (!strcmp(d->directive, token)) {
 	directive = d;
 	break;
       }
     }
     if (!directive) {
-      LogMessageWithContext(aFile, line, "Ignoring unrecognized chrome manifest directive '%s'.", token);
+      LogMessageWithContext(aFile, aPath, line,
+                            "Ignoring unrecognized chrome manifest directive '%s'.",
+                            token);
       continue;
     }
     if (directive->componentonly && NS_COMPONENT_LOCATION != aType) {
-      LogMessageWithContext(aFile, line, "Skin manifest not allowed to use '%s' directive.", token);
+      LogMessageWithContext(aFile, aPath, line,
+                            "Skin manifest not allowed to use '%s' directive.",
+                            token);
       continue;
     }
 
     NS_ASSERTION(directive->argc < 4, "Need to reset argv array length");
     char* argv[4];
     for (int i = 0; i < directive->argc; ++i)
       argv[i] = nsCRT::strtok(whitespace, kWhitespace, &whitespace);
 
     if (!argv[directive->argc - 1]) {
-      LogMessageWithContext(aFile, line, "Not enough arguments for chrome manifest directive '%s', expected %i.", token, directive->argc);
+      LogMessageWithContext(aFile, aPath, line,
+                            "Not enough arguments for chrome manifest directive '%s', expected %i.",
+                            token, directive->argc);
       continue;
     }
 
     bool ok = true;
     TriState stAppVersion = eUnspecified;
     TriState stApp = eUnspecified;
     TriState stOsVersion = eUnspecified;
     TriState stOs = eUnspecified;
@@ -553,17 +563,19 @@ ParseManifest(NSLocationType aType, nsIL
 	  CheckVersionFlag(kAppVersion, wtoken, appVersion, stAppVersion))
 	continue;
 
       if (directive->contentflags &&
 	  (CheckFlag(kPlatform, wtoken, platform) ||
 	   CheckFlag(kContentAccessible, wtoken, contentAccessible)))
 	  continue;
 
-      LogMessageWithContext(aFile, line, "Unrecognized chrome manifest modifier '%s'.", token);
+      LogMessageWithContext(aFile, aPath, line,
+                            "Unrecognized chrome manifest modifier '%s'.",
+                            token);
       ok = false;
     }
 
     if (!ok ||
         stApp == eBad ||
         stAppVersion == eBad ||
         stOs == eBad ||
         stOsVersion == eBad ||
@@ -575,17 +587,18 @@ ParseManifest(NSLocationType aType, nsIL
       if (GeckoProcessType_Default != XRE_GetProcessType())
         continue;
 #endif
 
       if (!nsChromeRegistry::gChromeRegistry) {
         nsCOMPtr<nsIChromeRegistry> cr =
           mozilla::services::GetChromeRegistryService();
         if (!nsChromeRegistry::gChromeRegistry) {
-          LogMessageWithContext(aFile, line, "Chrome registry isn't available yet.");
+          LogMessageWithContext(aFile, aPath, line,
+                                "Chrome registry isn't available yet.");
           continue;
         }
       }
 
       (nsChromeRegistry::gChromeRegistry->*(directive->regfunc))
 	(chromecx, line, argv, platform, contentAccessible);
     }
     else if (!aChromeOnly) {
@@ -602,8 +615,29 @@ ParseManifest(NSLocationType aType, nsIL
   }
 
   for (PRUint32 i = 0; i < contracts.Length(); ++i) {
     CachedDirective& d = contracts[i];
     nsComponentManagerImpl::gComponentManager->ManifestContract
       (mgrcx, d.lineno, d.argv);
   }
 }
+
+void
+ParseManifest(NSLocationType type, nsILocalFile* file,
+              char* buf, bool aChromeOnly)
+{
+  nsComponentManagerImpl::ManifestProcessingContext mgrcx(type, file);
+  nsChromeRegistry::ManifestProcessingContext chromecx(type, file);
+  ParseManifestCommon(type, file, mgrcx, chromecx, NULL, buf, aChromeOnly);
+}
+
+#ifdef MOZ_OMNIJAR
+void
+ParseManifest(NSLocationType type, const char* jarPath,
+              char* buf, bool aChromeOnly)
+{
+  nsComponentManagerImpl::ManifestProcessingContext mgrcx(type, jarPath);
+  nsChromeRegistry::ManifestProcessingContext chromecx(type, jarPath);
+  ParseManifestCommon(type, mozilla::OmnijarPath(), mgrcx, chromecx, jarPath,
+                      buf, aChromeOnly);
+}
+#endif
--- a/xpcom/components/ManifestParser.h
+++ b/xpcom/components/ManifestParser.h
@@ -38,16 +38,22 @@
 #ifndef ManifestParser_h
 #define ManifestParser_h
 
 #include "nsComponentManager.h"
 #include "nsChromeRegistry.h"
 
 class nsILocalFile;
 
-void ParseManifest(NSLocationType type, nsILocalFile* file, char* buf,
-                   bool aChromeOnly);
+void ParseManifest(NSLocationType type, nsILocalFile* file,
+                   char* buf, bool aChromeOnly);
+
+#ifdef MOZ_OMNIJAR
+void ParseManifest(NSLocationType type, const char* jarPath,
+                   char* buf, bool aChromeOnly);
+#endif
 
 void LogMessage(const char* aMsg, ...);
 
-void LogMessageWithContext(nsILocalFile* aFile, PRUint32 aLineNumber, const char* aMsg, ...);
+void LogMessageWithContext(nsILocalFile* aFile, const char* aPath,
+                           PRUint32 aLineNumber, const char* aMsg, ...);
 
 #endif // ManifestParser_h
--- a/xpcom/components/ModuleLoader.h
+++ b/xpcom/components/ModuleLoader.h
@@ -56,20 +56,20 @@ namespace mozilla {
  *       methods may be called from any thread.
  */
 class ModuleLoader : public nsISupports
 {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_MODULELOADER_PSEUDO_IID)
 
   /**
-   * Return the module for a specified file. The loader should cache
-   * the module and return the same module in future calls. The Module
-   * should either be statically or permanently allocated, it will not
-   * be freed.
+   * Return the module for a specified file. The caller should cache
+   * the module: the implementer should not expect for the same file
+   * to be loaded multiple times. The Module object should either be
+   * statically or permanently allocated; it will not be freed.
    */
   virtual const Module* LoadModule(nsILocalFile* aFile) = 0;
 
   /**
    * Return the module for a file located within a JAR.
    */
   virtual const Module* LoadModuleFromJAR(nsILocalFile* aJARFile,
                                           const nsACString& aPath) = 0;
--- a/xpcom/components/nsComponentManager.cpp
+++ b/xpcom/components/nsComponentManager.cpp
@@ -102,17 +102,17 @@
 
 
 #ifdef XP_BEOS
 #include <FindDirectory.h>
 #include <Path.h>
 #endif
 
 #ifdef MOZ_OMNIJAR
-#include "nsIZipReader.h"
+#include "nsManifestZIPLoader.h"
 #include "mozilla/Omnijar.h"
 static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID);
 #endif
 
 #include "prlog.h"
 
 NS_COM PRLogModuleInfo* nsComponentManagerLog = nsnull;
 
@@ -347,16 +347,19 @@ nsresult nsComponentManagerImpl::Init()
     // Initialize our arena
     NS_TIME_FUNCTION_MARK("Next: init component manager arena");
     PL_INIT_ARENA_POOL(&mArena, "ComponentManagerArena", NS_CM_BLOCK_SIZE);
 
     mFactories.Init(CONTRACTID_HASHTABLE_INITIAL_SIZE);
     mContractIDs.Init(CONTRACTID_HASHTABLE_INITIAL_SIZE);
     mLoaderMap.Init();
     mKnownFileModules.Init();
+#ifdef MOZ_OMNIJAR
+    mKnownJARModules.Init();
+#endif
 
     mMon = nsAutoMonitor::NewMonitor("nsComponentManagerImpl");
     if (mMon == nsnull)
         return NS_ERROR_OUT_OF_MEMORY;
 
     nsCOMPtr<nsILocalFile> greDir =
         GetLocationFromDirectoryService(NS_GRE_DIR);
     nsCOMPtr<nsILocalFile> appDir =
@@ -396,16 +399,20 @@ nsresult nsComponentManagerImpl::Init()
 
     nsCategoryManager::GetSingleton()->SuppressNotifications(true);
 
     RegisterModule(&kXPCOMModule, NULL);
 
     for (PRUint32 i = 0; i < sStaticModules->Length(); ++i)
         RegisterModule((*sStaticModules)[i], NULL);
 
+#ifdef MOZ_OMNIJAR
+    RegisterOmnijar(false);
+#endif
+
     for (PRUint32 i = 0; i < sModuleLocations->Length(); ++i) {
         ComponentLocation& l = sModuleLocations->ElementAt(i);
         RegisterLocation(l.type, l.location, false);
     }
 
     nsCategoryManager::GetSingleton()->SuppressNotifications(false);
 
     mStatus = NORMAL;
@@ -497,28 +504,32 @@ nsComponentManagerImpl::RegisterContract
                    idstr);
                    
         return;
     }
 
     mContractIDs.Put(nsDependentCString(aEntry->contractid), f);
 }
 
+static void
+CutExtension(nsCString& path)
+{
+    PRInt32 dotPos = path.RFindChar('.');
+    if (kNotFound == dotPos)
+        path.Truncate();
+    else
+        path.Cut(0, dotPos + 1);
+}
+
 static nsCString
 GetExtension(nsILocalFile* file)
 {
     nsCString extension;
     file->GetNativePath(extension);
-
-    PRInt32 dotPos = extension.RFindChar('.');
-    if (kNotFound == dotPos)
-        extension.Truncate();
-    else
-        extension.Cut(0, dotPos + 1);
-
+    CutExtension(extension);
     return extension;
 }
 
 void
 nsComponentManagerImpl::RegisterLocation(NSLocationType aType,
                                          nsILocalFile* aLocation,
                                          bool aChromeOnly)
 {
@@ -530,16 +541,67 @@ nsComponentManagerImpl::RegisterLocation
         GetManifestsInDirectory(aLocation, manifests);
     else if (GetExtension(aLocation).LowerCaseEqualsLiteral("manifest"))
         manifests.AppendObject(aLocation);
 
     for (PRInt32 i = 0; i < manifests.Count(); ++i)
         RegisterManifestFile(aType, manifests[i], aChromeOnly);
 }
 
+#ifdef MOZ_OMNIJAR
+void
+nsComponentManagerImpl::RegisterOmnijar(bool aChromeOnly)
+{
+    nsCOMPtr<nsIManifestLoader> loader = new nsManifestZIPLoader();
+
+    mManifestLoader = loader;
+    mRegisterJARChromeOnly = aChromeOnly;
+
+    loader->EnumerateEntries(mozilla::OmnijarPath(), this);
+
+    mManifestLoader = NULL;
+}
+
+NS_IMETHODIMP
+nsComponentManagerImpl::FoundEntry(const char* aPath,
+                                   PRInt32 aIndex,
+                                   nsIInputStream* aStream)
+{
+    NS_ASSERTION(mManifestLoader, "Not registering a JAR.");
+
+    PRUint32 flen;
+    aStream->Available(&flen);
+
+    nsAutoArrayPtr<char> whole(new char[flen + 1]);
+    if (!whole)
+        return NS_ERROR_OUT_OF_MEMORY;
+
+    for (PRUint32 totalRead = 0; totalRead < flen; ) {
+        PRUint32 avail;
+        PRUint32 read;
+
+        if (NS_FAILED(aStream->Available(&avail)))
+            return NS_ERROR_FAILURE;
+
+        if (avail > flen)
+            return NS_ERROR_FAILURE;
+
+        if (NS_FAILED(aStream->Read(whole + totalRead, avail, &read)))
+            return NS_ERROR_FAILURE;
+
+        totalRead += read;
+    }
+
+    whole[flen] = '\0';
+
+    ParseManifest(NS_COMPONENT_LOCATION, aPath, whole, mRegisterJARChromeOnly);
+    return NS_OK;
+}
+#endif // MOZ_OMNIJAR
+
 void
 nsComponentManagerImpl::GetManifestsInDirectory(nsILocalFile* aDirectory,
                                                 nsCOMArray<nsILocalFile>& aManifests)
 {
     nsCOMPtr<nsISimpleEnumerator> entries;
     aDirectory->GetDirectoryEntries(getter_AddRefs(entries));
     if (!entries)
         return;
@@ -623,16 +685,25 @@ TranslateSlashes(char* path)
             *path = '\\';
     }
 }
 #endif
 
 void
 nsComponentManagerImpl::ManifestBinaryComponent(ManifestProcessingContext& cx, int lineno, char *const * argv)
 {
+#ifdef MOZ_OMNIJAR
+    if (cx.mPath) {
+        NS_WARNING("Cannot load binary components from the omnijar.");
+        LogMessageWithContext(cx.mFile, cx.mPath, lineno,
+                              "Cannot load binary components from the omnijar.");
+        return;
+    }
+#endif
+
     char* file = argv[0];
 
 #ifdef TRANSLATE_SLASHES
     TranslateSlashes(file);
 #endif
 
     nsCOMPtr<nsIFile> cfile;
     cx.mFile->GetParent(getter_AddRefs(cfile));
@@ -646,88 +717,142 @@ nsComponentManagerImpl::ManifestBinaryCo
 
     const mozilla::Module* m = mNativeModuleLoader.LoadModule(clfile);
     if (!m)
         return;
 
     RegisterModule(m, clfile);
 }
 
+#ifdef MOZ_OMNIJAR
+static void
+AppendFileToManifestPath(nsCString& path,
+                         const char* file)
+{
+    PRInt32 i = path.RFindChar('/');
+    if (kNotFound == i)
+        path.Truncate(0);
+    else
+        path.Truncate(i + 1);
+
+    path.Append(file);
+}
+#endif
+
 void
 nsComponentManagerImpl::ManifestXPT(ManifestProcessingContext& cx, int lineno, char *const * argv)
 {
     char* file = argv[0];
 
 #ifdef TRANSLATE_SLASHES
     TranslateSlashes(file);
 #endif
 
-    nsCOMPtr<nsIFile> cfile;
-    cx.mFile->GetParent(getter_AddRefs(cfile));
-    nsCOMPtr<nsILocalFile> clfile = do_QueryInterface(cfile);
+#ifdef MOZ_OMNIJAR
+    if (cx.mPath) {
+        nsCAutoString manifest(cx.mPath);
+        AppendFileToManifestPath(manifest, file);
+
+        nsCOMPtr<nsIInputStream> stream;
+        nsresult rv = mManifestLoader->LoadEntry(cx.mFile, manifest.get(),
+                                                 getter_AddRefs(stream));
+        if (NS_FAILED(rv)) {
+            NS_WARNING("Failed to load omnijar XPT file.");
+            return;
+        }
 
-    nsresult rv = clfile->AppendRelativeNativePath(nsDependentCString(file));
-    if (NS_FAILED(rv)) {
-        NS_WARNING("Couldn't append relative path?");
-        return;
+        xptiInterfaceInfoManager::GetSingleton()
+            ->RegisterInputStream(stream);
     }
+    else
+#endif
+    {
+        nsCOMPtr<nsIFile> cfile;
+        cx.mFile->GetParent(getter_AddRefs(cfile));
+        nsCOMPtr<nsILocalFile> clfile = do_QueryInterface(cfile);
 
-    xptiInterfaceInfoManager::GetSingleton()
-        ->RegisterFile(clfile, xptiInterfaceInfoManager::XPT);
+        nsresult rv = clfile->AppendRelativeNativePath(nsDependentCString(file));
+        if (NS_FAILED(rv)) {
+            NS_WARNING("Couldn't append relative path?");
+            return;
+        }
+
+        xptiInterfaceInfoManager::GetSingleton()
+            ->RegisterFile(clfile);
+    }
 }
 
 void
 nsComponentManagerImpl::ManifestComponent(ManifestProcessingContext& cx, int lineno, char *const * argv)
 {
     char* id = argv[0];
     char* file = argv[1];
 
 #ifdef TRANSLATE_SLASHES
     TranslateSlashes(file);
 #endif
 
     nsID cid;
     if (!cid.Parse(id)) {
-        LogMessageWithContext(cx.mFile, lineno, "Malformed CID: '%s'.", id);
+        LogMessageWithContext(cx.mFile, cx.mPath, lineno,
+                              "Malformed CID: '%s'.", id);
         return;
     }
 
     nsAutoMonitor mon(mMon);
     nsFactoryEntry* f = mFactories.Get(cid);
     if (f) {
         char idstr[NSID_LENGTH];
         cid.ToProvidedString(idstr);
 
         nsCString existing;
         if (f->mModule)
             existing = f->mModule->Description();
         else
             existing = "<unknown module>";
 
-        LogMessageWithContext(cx.mFile, lineno, "Trying to re-register CID '%s' already registered by %s.",
+        LogMessageWithContext(cx.mFile, cx.mPath, lineno,
+                              "Trying to re-register CID '%s' already registered by %s.",
                               idstr,
                               existing.get());
         return;
     }
 
-    nsCOMPtr<nsIFile> cfile;
-    cx.mFile->GetParent(getter_AddRefs(cfile));
-    nsCOMPtr<nsILocalFile> clfile = do_QueryInterface(cfile);
+    KnownModule* km;
+
+#ifdef MOZ_OMNIJAR
+    if (cx.mPath) {
+        nsCAutoString manifest(cx.mPath);
+        AppendFileToManifestPath(manifest, file);
 
-    nsresult rv = clfile->AppendRelativeNativePath(nsDependentCString(file));
-    if (NS_FAILED(rv)) {
-        NS_WARNING("Couldn't append relative path?");
-        return;
+        km = mKnownJARModules.Get(manifest);
+        if (!km) {
+            km = new KnownModule(manifest);
+            mKnownJARModules.Put(manifest, km);
+        }
     }
+    else
+#endif
+    {
+        nsCOMPtr<nsIFile> cfile;
+        cx.mFile->GetParent(getter_AddRefs(cfile));
+        nsCOMPtr<nsILocalFile> clfile = do_QueryInterface(cfile);
 
-    nsCOMPtr<nsIHashable> h = do_QueryInterface(clfile);
-    KnownModule* km = mKnownFileModules.Get(h);
-    if (!km) {
-        km = new KnownModule(clfile);
-        mKnownFileModules.Put(h, km);
+        nsresult rv = clfile->AppendRelativeNativePath(nsDependentCString(file));
+        if (NS_FAILED(rv)) {
+            NS_WARNING("Couldn't append relative path?");
+            return;
+        }
+
+        nsCOMPtr<nsIHashable> h = do_QueryInterface(clfile);
+        km = mKnownFileModules.Get(h);
+        if (!km) {
+            km = new KnownModule(clfile);
+            mKnownFileModules.Put(h, km);
+        }
     }
 
     void* place;
 
     PL_ARENA_ALLOCATE(place, &mArena, sizeof(nsCID));
     nsID* permanentCID = static_cast<nsID*>(place);
     *permanentCID = cid;
 
@@ -742,24 +867,26 @@ nsComponentManagerImpl::ManifestComponen
 void
 nsComponentManagerImpl::ManifestContract(ManifestProcessingContext& cx, int lineno, char *const * argv)
 {
     char* contract = argv[0];
     char* id = argv[1];
 
     nsID cid;
     if (!cid.Parse(id)) {
-        LogMessageWithContext(cx.mFile, lineno, "Malformed CID: '%s'.", id);
+        LogMessageWithContext(cx.mFile, cx.mPath, lineno,
+                              "Malformed CID: '%s'.", id);
         return;
     }
 
     nsAutoMonitor mon(mMon);
     nsFactoryEntry* f = mFactories.Get(cid);
     if (!f) {
-        LogMessageWithContext(cx.mFile, lineno, "Could not map contract ID '%s' to CID %s because no implementation of the CID is registered.",
+        LogMessageWithContext(cx.mFile, cx.mPath, lineno,
+                              "Could not map contract ID '%s' to CID %s because no implementation of the CID is registered.",
                               contract, id);
         return;
     }
 
     mContractIDs.Put(nsDependentCString(contract), f);
 }
 
 void
@@ -771,42 +898,63 @@ nsComponentManagerImpl::ManifestCategory
 
     nsCategoryManager::GetSingleton()->
         AddCategoryEntry(category, key, value);
 }
 
 void
 nsComponentManagerImpl::RereadChromeManifests()
 {
+#ifdef MOZ_OMNIJAR
+    RegisterOmnijar(true);
+#endif
+
     for (PRUint32 i = 0; i < sModuleLocations->Length(); ++i) {
         ComponentLocation& l = sModuleLocations->ElementAt(i);
         RegisterLocation(l.type, l.location, true);
     }
 }
 
 bool
 nsComponentManagerImpl::KnownModule::EnsureLoader()
 {
     if (!mLoader) {
-        nsCString extension = GetExtension(mFile);
+        nsCString extension;
+#if MOZ_OMNIJAR
+        if (!mPath.IsEmpty()) {
+            extension = mPath;
+            CutExtension(extension);
+        }
+        else
+#endif
+        {
+            extension = GetExtension(mFile);
+        }
 
         mLoader = nsComponentManagerImpl::gComponentManager->LoaderForExtension(extension);
     }
     return !!mLoader;
 }
 
 bool
 nsComponentManagerImpl::KnownModule::Load()
 {
     if (mFailed)
         return false;
     if (!mModule) {
         if (!EnsureLoader())
             return false;
-        mModule = mLoader->LoadModule(mFile);
+
+#ifdef MOZ_OMNIJAR
+        if (!mPath.IsEmpty())
+            mModule = mLoader->LoadModuleFromJAR(mozilla::OmnijarPath(), mPath);
+        else
+#endif
+            mModule = mLoader->LoadModule(mFile);
+
         if (!mModule) {
             mFailed = true;
             return false;
         }
     }
     if (!mLoaded) {
         if (mModule->loadProc) {
             nsresult rv = mModule->loadProc();
@@ -819,16 +967,23 @@ nsComponentManagerImpl::KnownModule::Loa
     }
     return true;
 }
 
 nsCString
 nsComponentManagerImpl::KnownModule::Description() const
 {
     nsCString s;
+#ifdef MOZ_OMNIJAR
+    if (!mPath.IsEmpty()) {
+        s.AssignLiteral("omnijar:");
+        s.Append(mPath);
+    }
+    else
+#endif
     if (mFile)
         mFile->GetNativePath(s);
     else
         s = "<static module>";
     return s;
 }
 
 nsresult nsComponentManagerImpl::Shutdown(void)
@@ -841,16 +996,19 @@ nsresult nsComponentManagerImpl::Shutdow
 
     // Shutdown the component manager
     PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, ("nsComponentManager: Beginning Shutdown."));
 
     // Release all cached factories
     mContractIDs.Clear();
     mFactories.Clear(); // XXX release the objects, don't just clear
     mLoaderMap.Clear();
+#ifdef MOZ_OMNIJAR
+    mKnownJARModules.Clear();
+#endif
     mKnownFileModules.Clear();
     mKnownStaticModules.Clear();
 
     mLoaderData.Clear();
 
     delete sStaticModules;
     delete sModuleLocations;
 
--- a/xpcom/components/nsComponentManager.h
+++ b/xpcom/components/nsComponentManager.h
@@ -61,16 +61,21 @@
 #include "nsIFile.h"
 #include "plarena.h"
 #include "nsCOMArray.h"
 #include "nsDataHashtable.h"
 #include "nsInterfaceHashtable.h"
 #include "nsClassHashtable.h"
 #include "nsTArray.h"
 
+#ifdef MOZ_OMNIJAR
+#include "mozilla/Omnijar.h"
+#include "nsIManifestLoader.h"
+#endif
+
 struct nsFactoryEntry;
 class nsIServiceManager;
 struct PRThread;
 
 #define NS_COMPONENTMANAGER_CID                      \
 { /* 91775d60-d5dc-11d2-92fb-00e09805570f */         \
     0x91775d60,                                      \
     0xd5dc,                                          \
@@ -103,27 +108,33 @@ extern const mozilla::Module kXPCOMModul
 
 // Array of Loaders and their type strings
 struct nsLoaderdata {
     nsCOMPtr<mozilla::ModuleLoader> loader;
     nsCString                 type;
 };
 
 class nsComponentManagerImpl
-    : public nsIComponentManager,
-      public nsIServiceManager,
-      public nsSupportsWeakReference,
-      public nsIComponentRegistrar,
-      public nsIInterfaceRequestor
+    : public nsIComponentManager
+    , public nsIServiceManager
+    , public nsSupportsWeakReference
+    , public nsIComponentRegistrar
+    , public nsIInterfaceRequestor
+#ifdef MOZ_OMNIJAR
+    , public nsIManifestLoaderSink
+#endif
 {
 public:
     NS_DECL_ISUPPORTS
     NS_DECL_NSIINTERFACEREQUESTOR
     NS_DECL_NSICOMPONENTMANAGER
     NS_DECL_NSICOMPONENTREGISTRAR
+#ifdef MOZ_OMNIJAR
+    NS_DECL_NSIMANIFESTLOADERSINK
+#endif
 
     static nsresult Create(nsISupports* aOuter, REFNSIID aIID, void** aResult);
 
     nsresult RegistryLocationForFile(nsIFile* aFile,
                                      nsCString& aResult);
     nsresult FileForRegistryLocation(const nsCString &aLocation,
                                      nsILocalFile **aSpec);
 
@@ -187,16 +198,27 @@ public:
         KnownModule(nsILocalFile* aFile)
             : mModule(NULL)
             , mFile(aFile)
             , mLoader(NULL)
             , mLoaded(false)
             , mFailed(false)
         { }
 
+#ifdef MOZ_OMNIJAR
+        KnownModule(const nsACString& aPath)
+            : mModule(NULL)
+            , mFile(NULL)
+            , mPath(aPath)
+            , mLoader(NULL)
+            , mLoaded(false)
+            , mFailed(false)
+        { }
+#endif
+
         ~KnownModule()
         {
             if (mLoaded && mModule->unloadProc)
                 mModule->unloadProc();
         }
 
         bool EnsureLoader();
         bool Load();
@@ -210,51 +232,72 @@ public:
          * For error logging, get a description of this module, either the
          * file path, or <static module>.
          */
         nsCString Description() const;
 
     private:
         const mozilla::Module* mModule;
         nsCOMPtr<nsILocalFile> mFile;
+#ifdef MOZ_OMNIJAR
+        nsCString mPath;
+#endif
         nsCOMPtr<mozilla::ModuleLoader> mLoader;
         bool mLoaded;
         bool mFailed;
     };
 
-    // The KnownModule is kept alive by these members, it is referenced by pointer
-    // from the factory entries.
+    // The KnownModule is kept alive by these members, it is
+    // referenced by pointer from the factory entries.
     nsTArray< nsAutoPtr<KnownModule> > mKnownStaticModules;
     nsClassHashtable<nsHashableHashKey, KnownModule> mKnownFileModules;
+#ifdef MOZ_OMNIJAR
+    nsClassHashtable<nsCStringHashKey, KnownModule> mKnownJARModules;
+#endif
 
     void RegisterModule(const mozilla::Module* aModule,
                         nsILocalFile* aFile);
     void RegisterCIDEntry(const mozilla::Module::CIDEntry* aEntry,
                           KnownModule* aModule);
     void RegisterContractID(const mozilla::Module::ContractIDEntry* aEntry);
 
     void RegisterLocation(NSLocationType aType, nsILocalFile* aLocation,
                           bool aChromeOnly);
 
+#ifdef MOZ_OMNIJAR
+    void RegisterOmnijar(bool aChromeOnly);
+#endif
+
     void GetManifestsInDirectory(nsILocalFile* aDirectory,
                                  nsCOMArray<nsILocalFile>& aManifests);
 
     void RegisterManifestFile(NSLocationType aType, nsILocalFile* aFile,
                               bool aChromeOnly);
 
     struct ManifestProcessingContext
     {
         ManifestProcessingContext(NSLocationType aType, nsILocalFile* aFile)
             : mType(aType)
             , mFile(aFile)
+            , mPath(NULL)
         { }
+
+#ifdef MOZ_OMNIJAR
+        ManifestProcessingContext(NSLocationType aType, const char* aPath)
+            : mType(aType)
+            , mFile(mozilla::OmnijarPath())
+            , mPath(aPath)
+        { }
+#endif
+
         ~ManifestProcessingContext() { }
 
         NSLocationType mType;
-        nsCOMPtr<nsILocalFile> mFile;
+        nsILocalFile* mFile;
+        const char* mPath;
     };
 
     void ManifestBinaryComponent(ManifestProcessingContext& cx, int lineno, char *const * argv);
     void ManifestXPT(ManifestProcessingContext& cx, int lineno, char *const * argv);
     void ManifestComponent(ManifestProcessingContext& cx, int lineno, char *const * argv);
     void ManifestContract(ManifestProcessingContext& cx, int lineno, char* const * argv);
     void ManifestCategory(ManifestProcessingContext& cx, int lineno, char* const * argv);
 
@@ -281,16 +324,21 @@ public:
                                                  PRThread* aThread);
     inline void RemovePendingService(const nsCID& aServiceCID);
     inline PRThread* GetPendingServiceThread(const nsCID& aServiceCID) const;
 
     nsTArray<PendingServiceInfo> mPendingServices;
 
 private:
     ~nsComponentManagerImpl();
+
+#ifdef MOZ_OMNIJAR
+    nsIManifestLoader* mManifestLoader;
+    bool mRegisterJARChromeOnly;
+#endif
 };
 
 
 #define NS_MAX_FILENAME_LEN     1024
 
 #define NS_ERROR_IS_DIR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_XPCOM, 24)
 
 struct nsFactoryEntry
rename from xpcom/reflect/xptinfo/public/nsIXPTLoader.idl
rename to xpcom/components/nsIManifestLoader.idl
--- a/xpcom/reflect/xptinfo/public/nsIXPTLoader.idl
+++ b/xpcom/components/nsIManifestLoader.idl
@@ -42,59 +42,50 @@
 #include "nsILocalFile.idl"
 #include "nsIInputStream.idl"
 
 /**
  * Implement nsIXPTLoaderSink if you want to enumerate the entries in
  * an XPT archive of some kind
  */
 [scriptable, uuid(6E48C500-8682-4730-ADD6-7DB693B9E7BA)]
-interface nsIXPTLoaderSink : nsISupports {
-    
+interface nsIManifestLoaderSink : nsISupports
+{
     /**
-     * called by the loader for each entry in the archive
+     * Called by the loader for each components / *.manifest and
+     * chrome / *.manifest in the archive.
      * @param itemName the name of this particular item in the archive
      * @param index the index of the item inthe archive
      * @param stream contains the contents of the xpt file
      */
     void foundEntry(in string itemName,
                     in long index,
                     in nsIInputStream xptData);
 };
 
 /**
  * The XPT loader interface: implemented by a loader to grab an input
  * stream which will be consumed by the interface loader.
  */
 [scriptable, uuid(368A15D9-17A9-4c2b-AC3D-A35B3A22B876)]
-interface nsIXPTLoader : nsISupports {
+interface nsIManifestLoader : nsISupports {
     /**
      * enumerate entries in the given archive
      * for each entry found, the loader will call the sink's
      * foundEntry() method with the appropriate information and a
      * stream that the consumer can read from
      * @param file the file to read from
      * @param sink an object which will be called with each file found
      *             in the file
      */
     void enumerateEntries(in nsILocalFile file,
-                          in nsIXPTLoaderSink sink );
+                          in nsIManifestLoaderSink sink );
 
     /**
      * Load a specific entry from the archive
      * @param file the file to read from
      * @param name the name of the xpt within the file
      * @return an input stream that will read the raw xpt data from
      *         the file
      */
     nsIInputStream loadEntry(in nsILocalFile file,
                              in string name);
 };
-
-
-%{C++
-
-// the first part of the contractID for any loader
-// append the type of loader that you need, such as "zip"
-#define NS_XPTLOADER_CONTRACTID_PREFIX \
-   "@mozilla.org/xptinfo/loader;1&type="
-
-%}
--- a/xpcom/reflect/xptinfo/public/Makefile.in
+++ b/xpcom/reflect/xptinfo/public/Makefile.in
@@ -50,17 +50,16 @@ GRE_MODULE	= 1
 
 EXPORTS		= \
 		xptinfo.h \
 		$(NULL)
 
 XPIDLSRCS = \
 	nsIInterfaceInfo.idl          \
 	nsIInterfaceInfoManager.idl   \
-	nsIXPTLoader.idl \
 	$(NULL)
 
 EXPORTS		:= $(addprefix $(srcdir)/, $(EXPORTS))
 
 include $(topsrcdir)/config/rules.mk
 
 CFLAGS		+= -DEXPORT_XPCI_API
 
--- a/xpcom/reflect/xptinfo/src/xptiInterfaceInfo.cpp
+++ b/xpcom/reflect/xptinfo/src/xptiInterfaceInfo.cpp
@@ -110,19 +110,16 @@ xptiInterfaceEntry::ResolveLocked()
 {
     int resolvedState = GetResolveState();
 
     if(resolvedState == FULLY_RESOLVED)
         return PR_TRUE;
     if(resolvedState == RESOLVE_FAILED)
         return PR_FALSE;
 
-    xptiInterfaceInfoManager* mgr = xptiInterfaceInfoManager::GetSingleton();
-    
-
     NS_ASSERTION(GetResolveState() == PARTIALLY_RESOLVED, "bad state!");    
 
     // Finish out resolution by finding parent and Resolving it so
     // we can set the info we get from it.
 
     PRUint16 parent_index = mDescriptor->parent_interface;
 
     if(parent_index)
--- a/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp
+++ b/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp
@@ -40,21 +40,18 @@
 /* Implementation of xptiInterfaceInfoManager. */
 
 #include "xptiprivate.h"
 #include "nsDependentString.h"
 #include "nsString.h"
 #include "nsISupportsArray.h"
 #include "nsArrayEnumerator.h"
 #include "mozilla/FunctionTimer.h"
-#include "nsXPTZipLoader.h"
 #include "nsDirectoryService.h"
 
-#define NS_ZIPLOADER_CONTRACTID NS_XPTLOADER_CONTRACTID_PREFIX "zip"
-
 NS_IMPL_THREADSAFE_ISUPPORTS2(xptiInterfaceInfoManager, 
                               nsIInterfaceInfoManager,
                               nsIInterfaceInfoSuperManager)
 
 static xptiInterfaceInfoManager* gInterfaceInfoManager = nsnull;
 #ifdef DEBUG
 static int gCallCount = 0;
 #endif
@@ -220,64 +217,45 @@ xptiInterfaceInfoManager::ReadXPTFileFro
     }
 
     XPT_DestroyXDRState(state);
 
     return header;
 }
 
 void
-xptiInterfaceInfoManager::RegisterFile(nsILocalFile* aFile, Type aType)
+xptiInterfaceInfoManager::RegisterFile(nsILocalFile* aFile)
 {
-    switch (aType) {
-    case XPT: {
-        XPTHeader* header = ReadXPTFile(aFile);
-        if (!header)
-            return;
-
-        RegisterXPTHeader(header);
-        break;
-    }
+    XPTHeader* header = ReadXPTFile(aFile);
+    if (!header)
+        return;
 
-    case ZIP: {
-#ifndef MOZ_ENABLE_LIBXUL
-        NS_WARNING("Trying to register XPTs in a JAR in a non-libxul build");
-#else
-        nsCOMPtr<nsIXPTLoader> loader = new nsXPTZipLoader();
-        loader->EnumerateEntries(aFile, this);
-#endif
-        break;
-    }
-
-    default:
-        NS_ERROR("Unexpected enumeration value");
-    }
+    RegisterXPTHeader(header);
 }
 
 void
 xptiInterfaceInfoManager::RegisterXPTHeader(XPTHeader* aHeader)
 {
     if (aHeader->major_version >= XPT_MAJOR_INCOMPATIBLE_VERSION) {
         NS_ASSERTION(!aHeader->num_interfaces,"bad libxpt");
         LOG_AUTOREG(("      file is version %d.%d  Type file of version %d.0 or higher can not be read.\n", (int)header->major_version, (int)header->minor_version, (int)XPT_MAJOR_INCOMPATIBLE_VERSION));
     }
 
     xptiTypelibGuts* typelib = xptiTypelibGuts::Create(aHeader);
 
     for(PRUint16 k = 0; k < aHeader->num_interfaces; k++)
         VerifyAndAddEntryIfNew(aHeader->interface_directory + k, k, typelib);
 }
 
-NS_IMETHODIMP
-xptiInterfaceInfoManager::FoundEntry(const char* entryName, PRInt32 index, nsIInputStream* aStream)
+void
+xptiInterfaceInfoManager::RegisterInputStream(nsIInputStream* aStream)
 {
     XPTHeader* header = ReadXPTFileFromInputStream(aStream);
     if (header)
         RegisterXPTHeader(header);
-    return NS_OK;
 }
 
 void
 xptiInterfaceInfoManager::VerifyAndAddEntryIfNew(XPTInterfaceDirectoryEntry* iface,
                                                  PRUint16 idx,
                                                  xptiTypelibGuts* typelib)
 {
     if (!iface->interface_descriptor)
--- a/xpcom/reflect/xptinfo/src/xptiprivate.h
+++ b/xpcom/reflect/xptinfo/src/xptiprivate.h
@@ -49,17 +49,16 @@
 // this after nsISupports, to pick up IID
 // so that xpt stuff doesn't try to define it itself...
 #include "xpt_struct.h"
 #include "xpt_xdr.h"
 
 #include "nsIInterfaceInfo.h"
 #include "nsIInterfaceInfoManager.h"
 #include "xptinfo.h"
-#include "nsIXPTLoader.h"
 
 #include "nsIServiceManager.h"
 #include "nsILocalFile.h"
 #include "nsIDirectoryService.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsIWeakReference.h"
 
@@ -423,29 +422,27 @@ private:
     xptiInterfaceEntry* mEntry;
     xptiInterfaceInfo*  mParent;
 };
 
 /***************************************************************************/
 
 class xptiInterfaceInfoManager 
     : public nsIInterfaceInfoSuperManager
-    , public nsIXPTLoaderSink
 {
     NS_DECL_ISUPPORTS
     NS_DECL_NSIINTERFACEINFOMANAGER
     NS_DECL_NSIINTERFACEINFOSUPERMANAGER
-    NS_DECL_NSIXPTLOADERSINK
 
 public:
     static xptiInterfaceInfoManager* GetSingleton();
     static void FreeInterfaceInfoManager();
 
-    enum Type { XPT = 0, ZIP = 1 };
-    void RegisterFile(nsILocalFile* aFile, Type type);
+    void RegisterFile(nsILocalFile* aFile);
+    void RegisterInputStream(nsIInputStream* aStream);
 
     xptiWorkingSet*  GetWorkingSet() {return &mWorkingSet;}
 
     static PRLock* GetResolveLock(xptiInterfaceInfoManager* self = nsnull) 
         {if(!self && !(self = GetSingleton())) 
             return nsnull;
          return self->mResolveLock;}