Bug 1265621 - Add flag to track omnijar handle in nsJAR; r=aklotz

Add a bool flag in nsJAR to track whether the zip handle came from
omnijar.  The old code compared pointers instead, but other patches in
this bug made it no longer possible to do that.
This commit is contained in:
Jim Chen 2016-04-28 16:07:02 -04:00
parent 93b208fc7e
commit 4932a777ef
2 changed files with 12 additions and 5 deletions

View File

@ -86,7 +86,8 @@ nsJAR::nsJAR(): mZip(new nsZipArchive()),
mLock("nsJAR::mLock"),
mMtime(0),
mTotalItemsInManifest(0),
mOpened(false)
mOpened(false),
mIsOmnijar(false)
{
}
@ -141,6 +142,7 @@ nsJAR::Open(nsIFile* zipFile)
RefPtr<nsZipArchive> zip = mozilla::Omnijar::GetReader(zipFile);
if (zip) {
mZip = zip;
mIsOmnijar = true;
return NS_OK;
}
return mZip->OpenArchive(zipFile);
@ -201,19 +203,23 @@ nsJAR::GetFile(nsIFile* *result)
NS_IMETHODIMP
nsJAR::Close()
{
if (!mOpened) {
return NS_ERROR_FAILURE; // Never opened or already closed.
}
mOpened = false;
mParsedManifest = false;
mManifestData.Clear();
mGlobalStatus = JAR_MANIFEST_NOT_PARSED;
mTotalItemsInManifest = 0;
RefPtr<nsZipArchive> greOmni = mozilla::Omnijar::GetReader(mozilla::Omnijar::GRE);
RefPtr<nsZipArchive> appOmni = mozilla::Omnijar::GetReader(mozilla::Omnijar::APP);
if (mZip == greOmni || mZip == appOmni) {
if (mIsOmnijar) {
// Reset state, but don't close the omnijar because we did not open it.
mIsOmnijar = false;
mZip = new nsZipArchive();
return NS_OK;
}
return mZip->CloseArchive();
}

View File

@ -113,6 +113,7 @@ class nsJAR final : public nsIZipReader
int64_t mMtime;
int32_t mTotalItemsInManifest;
bool mOpened;
bool mIsOmnijar;
nsresult ParseManifest();
void ReportError(const nsACString &aFilename, int16_t errorCode);