Fix omnijar from bug 579178 - move the manifest ziploader code into xpcom/components, and don't load the same JAR a bunch of times.

This commit is contained in:
Benjamin Smedberg
2010-08-04 14:09:21 -04:00
parent 5595b68e04
commit 9982423a9d
6 changed files with 35 additions and 39 deletions

View File

@@ -45,10 +45,6 @@ MODULES_LIBJAR_LCPPSRCS = \
nsJARURI.cpp \
$(NULL)
ifdef MOZ_OMNIJAR
MODULES_LIBJAR_LCPPSRCS += nsManifestZIPLoader.cpp
endif
MODULES_LIBJAR_LEXPORTS = \
zipstruct.h \
nsZipArchive.h \

View File

@@ -68,6 +68,10 @@ CPPSRCS = \
nsNativeComponentLoader.cpp \
$(NULL)
ifdef MOZ_OMNIJAR
CPPSRCS += nsManifestZIPLoader.cpp
endif
SDK_XPIDLSRCS = \
nsIClassInfo.idl \
nsIComponentRegistrar.idl \

View File

@@ -533,20 +533,20 @@ nsComponentManagerImpl::RegisterOmnijar(const char* aPath, bool aChromeOnly)
nsAutoArrayPtr<char> whole(new char[flen + 1]);
if (!whole)
return NS_ERROR_OUT_OF_MEMORY;
return;
for (PRUint32 totalRead = 0; totalRead < flen; ) {
PRUint32 avail;
PRUint32 read;
if (NS_FAILED(is->Available(&avail)))
return NS_ERROR_FAILURE;
return;
if (avail > flen)
return NS_ERROR_FAILURE;
return;
if (NS_FAILED(is->Read(whole + totalRead, avail, &read)))
return NS_ERROR_FAILURE;
return;
totalRead += read;
}
@@ -554,7 +554,6 @@ nsComponentManagerImpl::RegisterOmnijar(const char* aPath, bool aChromeOnly)
whole[flen] = '\0';
ParseManifest(NS_COMPONENT_LOCATION, aPath, whole, aChromeOnly);
return NS_OK;
}
#endif // MOZ_OMNIJAR
@@ -630,6 +629,21 @@ TranslateSlashes(char* path)
}
#endif
#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::ManifestManifest(ManifestProcessingContext& cx, int lineno, char *const * argv)
{
@@ -698,21 +712,6 @@ nsComponentManagerImpl::ManifestBinaryComponent(ManifestProcessingContext& cx, i
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)
{
@@ -727,10 +726,9 @@ nsComponentManagerImpl::ManifestXPT(ManifestProcessingContext& cx, int lineno, c
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)) {
nsCOMPtr<nsIInputStream> stream =
mManifestLoader->LoadEntry(manifest.get());
if (!stream) {
NS_WARNING("Failed to load omnijar XPT file.");
return;
}

View File

@@ -118,18 +118,12 @@ class nsComponentManagerImpl
, 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);

View File

@@ -45,19 +45,23 @@
nsManifestZIPLoader::nsManifestZIPLoader()
: mZipReader(new nsJAR())
{
nsresult rv = reader->Open(mozilla::OmnijarPath());
nsresult rv = mZipReader->Open(mozilla::OmnijarPath());
if (NS_FAILED(rv))
mZipReader = NULL;
}
nsManifestZIPLoader::~nsManifestZIPLoader()
{
}
already_AddRefed<nsIInputStream>
nsManifestZIPLoader::LoadEntry(const char* aName)
{
if (!mZipReader)
return NS_ERROR_NOT_INITIALIZED;
return NULL;
nsCOMPtr<nsIInputStream> is;
nsresult rv = zip->GetInputStream(aName, getter_AddRefs(is));
nsresult rv = mZipReader->GetInputStream(aName, getter_AddRefs(is));
if (NS_FAILED(rv))
return NULL;

View File

@@ -37,10 +37,10 @@
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.h"
#include "nsIManifestLoader.h"
#include "nsCOMPtr.h"
#include "nsIZipReader.h"
#include "nsIInputStream.h"
class nsManifestZIPLoader
{