mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 967941, part 1 - Remove all trailing whitespace from nsJAR.{h,cpp}. r=aklotz
This commit is contained in:
parent
d065a93adf
commit
66a2e9ef09
@ -23,8 +23,8 @@ using namespace mozilla;
|
|||||||
// nsJARManifestItem declaration
|
// nsJARManifestItem declaration
|
||||||
//----------------------------------------------
|
//----------------------------------------------
|
||||||
/*
|
/*
|
||||||
* nsJARManifestItem contains meta-information pertaining
|
* nsJARManifestItem contains meta-information pertaining
|
||||||
* to an individual JAR entry, taken from the
|
* to an individual JAR entry, taken from the
|
||||||
* META-INF/MANIFEST.MF and META-INF/ *.SF files.
|
* META-INF/MANIFEST.MF and META-INF/ *.SF files.
|
||||||
* This is security-critical information, defined here so it is not
|
* This is security-critical information, defined here so it is not
|
||||||
* accessible from anywhere else.
|
* accessible from anywhere else.
|
||||||
@ -41,7 +41,7 @@ class nsJARManifestItem
|
|||||||
public:
|
public:
|
||||||
JARManifestItemType mType;
|
JARManifestItemType mType;
|
||||||
|
|
||||||
// True if the second step of verification (VerifyEntry)
|
// True if the second step of verification (VerifyEntry)
|
||||||
// has taken place:
|
// has taken place:
|
||||||
bool entryVerified;
|
bool entryVerified;
|
||||||
|
|
||||||
@ -85,8 +85,8 @@ nsJAR::nsJAR(): mZip(new nsZipArchive()),
|
|||||||
mManifestData(nullptr, nullptr, DeleteManifestEntry, nullptr, 10),
|
mManifestData(nullptr, nullptr, DeleteManifestEntry, nullptr, 10),
|
||||||
mParsedManifest(false),
|
mParsedManifest(false),
|
||||||
mGlobalStatus(JAR_MANIFEST_NOT_PARSED),
|
mGlobalStatus(JAR_MANIFEST_NOT_PARSED),
|
||||||
mReleaseTime(PR_INTERVAL_NO_TIMEOUT),
|
mReleaseTime(PR_INTERVAL_NO_TIMEOUT),
|
||||||
mCache(nullptr),
|
mCache(nullptr),
|
||||||
mLock("nsJAR::mLock"),
|
mLock("nsJAR::mLock"),
|
||||||
mTotalItemsInManifest(0),
|
mTotalItemsInManifest(0),
|
||||||
mOpened(false)
|
mOpened(false)
|
||||||
@ -102,18 +102,18 @@ NS_IMPL_QUERY_INTERFACE1(nsJAR, nsIZipReader)
|
|||||||
NS_IMPL_ADDREF(nsJAR)
|
NS_IMPL_ADDREF(nsJAR)
|
||||||
|
|
||||||
// Custom Release method works with nsZipReaderCache...
|
// Custom Release method works with nsZipReaderCache...
|
||||||
nsrefcnt nsJAR::Release(void)
|
nsrefcnt nsJAR::Release(void)
|
||||||
{
|
{
|
||||||
nsrefcnt count;
|
nsrefcnt count;
|
||||||
NS_PRECONDITION(0 != mRefCnt, "dup release");
|
NS_PRECONDITION(0 != mRefCnt, "dup release");
|
||||||
count = --mRefCnt;
|
count = --mRefCnt;
|
||||||
NS_LOG_RELEASE(this, count, "nsJAR");
|
NS_LOG_RELEASE(this, count, "nsJAR");
|
||||||
if (0 == count) {
|
if (0 == count) {
|
||||||
mRefCnt = 1; /* stabilize */
|
mRefCnt = 1; /* stabilize */
|
||||||
/* enable this to find non-threadsafe destructors: */
|
/* enable this to find non-threadsafe destructors: */
|
||||||
/* NS_ASSERT_OWNINGTHREAD(nsJAR); */
|
/* NS_ASSERT_OWNINGTHREAD(nsJAR); */
|
||||||
delete this;
|
delete this;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else if (1 == count && mCache) {
|
else if (1 == count && mCache) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@ -122,8 +122,8 @@ nsrefcnt nsJAR::Release(void)
|
|||||||
mCache->ReleaseZip(this);
|
mCache->ReleaseZip(this);
|
||||||
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to release zip file");
|
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to release zip file");
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------
|
//----------------------------------------------
|
||||||
// nsIZipReader implementation
|
// nsIZipReader implementation
|
||||||
@ -138,7 +138,7 @@ nsJAR::Open(nsIFile* zipFile)
|
|||||||
mZipFile = zipFile;
|
mZipFile = zipFile;
|
||||||
mOuterZipEntry.Truncate();
|
mOuterZipEntry.Truncate();
|
||||||
mOpened = true;
|
mOpened = true;
|
||||||
|
|
||||||
// The omnijar is special, it is opened early on and closed late
|
// The omnijar is special, it is opened early on and closed late
|
||||||
// this avoids reopening it
|
// this avoids reopening it
|
||||||
nsRefPtr<nsZipArchive> zip = mozilla::Omnijar::GetReader(zipFile);
|
nsRefPtr<nsZipArchive> zip = mozilla::Omnijar::GetReader(zipFile);
|
||||||
@ -257,7 +257,7 @@ nsJAR::Extract(const nsACString &aEntryName, nsIFile* outFile)
|
|||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsJAR::GetEntry(const nsACString &aEntryName, nsIZipEntry* *result)
|
nsJAR::GetEntry(const nsACString &aEntryName, nsIZipEntry* *result)
|
||||||
{
|
{
|
||||||
nsZipItem* zipItem = mZip->GetItem(PromiseFlatCString(aEntryName).get());
|
nsZipItem* zipItem = mZip->GetItem(PromiseFlatCString(aEntryName).get());
|
||||||
@ -303,7 +303,7 @@ nsJAR::GetInputStream(const nsACString &aFilename, nsIInputStream** result)
|
|||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsJAR::GetInputStreamWithSpec(const nsACString& aJarDirSpec,
|
nsJAR::GetInputStreamWithSpec(const nsACString& aJarDirSpec,
|
||||||
const nsACString &aEntryName, nsIInputStream** result)
|
const nsACString &aEntryName, nsIInputStream** result)
|
||||||
{
|
{
|
||||||
NS_ENSURE_ARG_POINTER(result);
|
NS_ENSURE_ARG_POINTER(result);
|
||||||
@ -388,7 +388,7 @@ nsJAR::GetCertificatePrincipal(const nsACString &aFilename, nsICertificatePrinci
|
|||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsJAR::GetManifestEntriesCount(uint32_t* count)
|
nsJAR::GetManifestEntriesCount(uint32_t* count)
|
||||||
{
|
{
|
||||||
*count = mTotalItemsInManifest;
|
*count = mTotalItemsInManifest;
|
||||||
@ -406,7 +406,7 @@ nsJAR::GetJarPath(nsACString& aResult)
|
|||||||
//----------------------------------------------
|
//----------------------------------------------
|
||||||
// nsJAR private implementation
|
// nsJAR private implementation
|
||||||
//----------------------------------------------
|
//----------------------------------------------
|
||||||
nsresult
|
nsresult
|
||||||
nsJAR::LoadEntry(const nsACString &aFilename, char** aBuf, uint32_t* aBufLen)
|
nsJAR::LoadEntry(const nsACString &aFilename, char** aBuf, uint32_t* aBufLen)
|
||||||
{
|
{
|
||||||
//-- Get a stream for reading the file
|
//-- Get a stream for reading the file
|
||||||
@ -414,7 +414,7 @@ nsJAR::LoadEntry(const nsACString &aFilename, char** aBuf, uint32_t* aBufLen)
|
|||||||
nsCOMPtr<nsIInputStream> manifestStream;
|
nsCOMPtr<nsIInputStream> manifestStream;
|
||||||
rv = GetInputStream(aFilename, getter_AddRefs(manifestStream));
|
rv = GetInputStream(aFilename, getter_AddRefs(manifestStream));
|
||||||
if (NS_FAILED(rv)) return NS_ERROR_FILE_TARGET_DOES_NOT_EXIST;
|
if (NS_FAILED(rv)) return NS_ERROR_FILE_TARGET_DOES_NOT_EXIST;
|
||||||
|
|
||||||
//-- Read the manifest file into memory
|
//-- Read the manifest file into memory
|
||||||
char* buf;
|
char* buf;
|
||||||
uint64_t len64;
|
uint64_t len64;
|
||||||
@ -426,7 +426,7 @@ nsJAR::LoadEntry(const nsACString &aFilename, char** aBuf, uint32_t* aBufLen)
|
|||||||
if (!buf) return NS_ERROR_OUT_OF_MEMORY;
|
if (!buf) return NS_ERROR_OUT_OF_MEMORY;
|
||||||
uint32_t bytesRead;
|
uint32_t bytesRead;
|
||||||
rv = manifestStream->Read(buf, len, &bytesRead);
|
rv = manifestStream->Read(buf, len, &bytesRead);
|
||||||
if (bytesRead != len)
|
if (bytesRead != len)
|
||||||
rv = NS_ERROR_FILE_CORRUPTED;
|
rv = NS_ERROR_FILE_CORRUPTED;
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
free(buf);
|
free(buf);
|
||||||
@ -544,7 +544,7 @@ nsJAR::ParseManifest()
|
|||||||
|
|
||||||
rv = LoadEntry(manifestFilename, getter_Copies(manifestBuffer), &manifestLen);
|
rv = LoadEntry(manifestFilename, getter_Copies(manifestBuffer), &manifestLen);
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
//-- Get its corresponding signature file
|
//-- Get its corresponding signature file
|
||||||
nsAutoCString sigFilename(manifestFilename);
|
nsAutoCString sigFilename(manifestFilename);
|
||||||
int32_t extension = sigFilename.RFindChar('.') + 1;
|
int32_t extension = sigFilename.RFindChar('.') + 1;
|
||||||
@ -569,7 +569,7 @@ nsJAR::ParseManifest()
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-- Get the signature verifier service
|
//-- Get the signature verifier service
|
||||||
nsCOMPtr<nsISignatureVerifier> verifier =
|
nsCOMPtr<nsISignatureVerifier> verifier =
|
||||||
do_GetService(SIGNATURE_VERIFIER_CONTRACTID, &rv);
|
do_GetService(SIGNATURE_VERIFIER_CONTRACTID, &rv);
|
||||||
if (NS_FAILED(rv)) // No signature verifier available
|
if (NS_FAILED(rv)) // No signature verifier available
|
||||||
{
|
{
|
||||||
@ -580,7 +580,7 @@ nsJAR::ParseManifest()
|
|||||||
|
|
||||||
//-- Verify that the signature file is a valid signature of the SF file
|
//-- Verify that the signature file is a valid signature of the SF file
|
||||||
int32_t verifyError;
|
int32_t verifyError;
|
||||||
rv = verifier->VerifySignature(sigBuffer, sigLen, manifestBuffer, manifestLen,
|
rv = verifier->VerifySignature(sigBuffer, sigLen, manifestBuffer, manifestLen,
|
||||||
&verifyError, getter_AddRefs(mPrincipal));
|
&verifyError, getter_AddRefs(mPrincipal));
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
if (mPrincipal && verifyError == 0)
|
if (mPrincipal && verifyError == 0)
|
||||||
@ -592,8 +592,8 @@ nsJAR::ParseManifest()
|
|||||||
|
|
||||||
//-- Parse the SF file. If the verification above failed, principal
|
//-- Parse the SF file. If the verification above failed, principal
|
||||||
// is null, and ParseOneFile will mark the relevant entries as invalid.
|
// is null, and ParseOneFile will mark the relevant entries as invalid.
|
||||||
// if ParseOneFile fails, then it has no effect, and we can safely
|
// if ParseOneFile fails, then it has no effect, and we can safely
|
||||||
// continue to the next SF file, or return.
|
// continue to the next SF file, or return.
|
||||||
ParseOneFile(manifestBuffer, JAR_SF);
|
ParseOneFile(manifestBuffer, JAR_SF);
|
||||||
mParsedManifest = true;
|
mParsedManifest = true;
|
||||||
|
|
||||||
@ -637,20 +637,20 @@ nsJAR::ParseOneFile(const char* filebuf, int16_t aFileType)
|
|||||||
curPos = nextLineStart;
|
curPos = nextLineStart;
|
||||||
linelen = ReadLine(&nextLineStart);
|
linelen = ReadLine(&nextLineStart);
|
||||||
curLine.Assign(curPos, linelen);
|
curLine.Assign(curPos, linelen);
|
||||||
if (linelen == 0)
|
if (linelen == 0)
|
||||||
// end of section (blank line or end-of-file)
|
// end of section (blank line or end-of-file)
|
||||||
{
|
{
|
||||||
if (aFileType == JAR_MF)
|
if (aFileType == JAR_MF)
|
||||||
{
|
{
|
||||||
mTotalItemsInManifest++;
|
mTotalItemsInManifest++;
|
||||||
if (curItemMF->mType != JAR_INVALID)
|
if (curItemMF->mType != JAR_INVALID)
|
||||||
{
|
{
|
||||||
//-- Did this section have a name: line?
|
//-- Did this section have a name: line?
|
||||||
if(!foundName)
|
if(!foundName)
|
||||||
curItemMF->mType = JAR_INVALID;
|
curItemMF->mType = JAR_INVALID;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//-- If it's an internal item, it must correspond
|
//-- If it's an internal item, it must correspond
|
||||||
// to a valid jar entry
|
// to a valid jar entry
|
||||||
if (curItemMF->mType == JAR_INTERNAL)
|
if (curItemMF->mType == JAR_INTERNAL)
|
||||||
{
|
{
|
||||||
@ -685,7 +685,7 @@ nsJAR::ParseOneFile(const char* filebuf, int16_t aFileType)
|
|||||||
return NS_ERROR_OUT_OF_MEMORY;
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
} // (aFileType == JAR_MF)
|
} // (aFileType == JAR_MF)
|
||||||
else
|
else
|
||||||
//-- file type is SF, compare digest with calculated
|
//-- file type is SF, compare digest with calculated
|
||||||
// section digests from MF file.
|
// section digests from MF file.
|
||||||
{
|
{
|
||||||
if (foundName)
|
if (foundName)
|
||||||
@ -744,7 +744,7 @@ nsJAR::ParseOneFile(const char* filebuf, int16_t aFileType)
|
|||||||
//-- Lines to look for:
|
//-- Lines to look for:
|
||||||
// (1) Digest:
|
// (1) Digest:
|
||||||
if (lineName.LowerCaseEqualsLiteral("sha1-digest"))
|
if (lineName.LowerCaseEqualsLiteral("sha1-digest"))
|
||||||
//-- This is a digest line, save the data in the appropriate place
|
//-- This is a digest line, save the data in the appropriate place
|
||||||
{
|
{
|
||||||
if(aFileType == JAR_MF)
|
if(aFileType == JAR_MF)
|
||||||
curItemMF->storedEntryDigest = lineData;
|
curItemMF->storedEntryDigest = lineData;
|
||||||
@ -752,7 +752,7 @@ nsJAR::ParseOneFile(const char* filebuf, int16_t aFileType)
|
|||||||
storedSectionDigest = lineData;
|
storedSectionDigest = lineData;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// (2) Name: associates this manifest section with a file in the jar.
|
// (2) Name: associates this manifest section with a file in the jar.
|
||||||
if (!foundName && lineName.LowerCaseEqualsLiteral("name"))
|
if (!foundName && lineName.LowerCaseEqualsLiteral("name"))
|
||||||
{
|
{
|
||||||
@ -761,7 +761,7 @@ nsJAR::ParseOneFile(const char* filebuf, int16_t aFileType)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// (3) Magic: this may be an inline Javascript.
|
// (3) Magic: this may be an inline Javascript.
|
||||||
// We can't do any other kind of magic.
|
// We can't do any other kind of magic.
|
||||||
if (aFileType == JAR_MF && lineName.LowerCaseEqualsLiteral("magic"))
|
if (aFileType == JAR_MF && lineName.LowerCaseEqualsLiteral("magic"))
|
||||||
{
|
{
|
||||||
@ -802,7 +802,7 @@ nsJAR::VerifyEntry(nsJARManifestItem* aManItem, const char* aEntryData,
|
|||||||
void nsJAR::ReportError(const nsACString &aFilename, int16_t errorCode)
|
void nsJAR::ReportError(const nsACString &aFilename, int16_t errorCode)
|
||||||
{
|
{
|
||||||
//-- Generate error message
|
//-- Generate error message
|
||||||
nsAutoString message;
|
nsAutoString message;
|
||||||
message.AssignLiteral("Signature Verification Error: the signature on ");
|
message.AssignLiteral("Signature Verification Error: the signature on ");
|
||||||
if (!aFilename.IsEmpty())
|
if (!aFilename.IsEmpty())
|
||||||
AppendASCIItoUTF16(aFilename, message);
|
AppendASCIItoUTF16(aFilename, message);
|
||||||
@ -832,7 +832,7 @@ void nsJAR::ReportError(const nsACString &aFilename, int16_t errorCode)
|
|||||||
default:
|
default:
|
||||||
message.AppendLiteral("of an unknown problem.");
|
message.AppendLiteral("of an unknown problem.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Report error in JS console
|
// Report error in JS console
|
||||||
nsCOMPtr<nsIConsoleService> console(do_GetService("@mozilla.org/consoleservice;1"));
|
nsCOMPtr<nsIConsoleService> console(do_GetService("@mozilla.org/consoleservice;1"));
|
||||||
if (console)
|
if (console)
|
||||||
@ -866,7 +866,7 @@ nsresult nsJAR::CalculateDigest(const char* aInBuf, uint32_t aLen,
|
|||||||
}
|
}
|
||||||
|
|
||||||
NS_IMPL_ISUPPORTS1(nsJAREnumerator, nsIUTF8StringEnumerator)
|
NS_IMPL_ISUPPORTS1(nsJAREnumerator, nsIUTF8StringEnumerator)
|
||||||
|
|
||||||
//----------------------------------------------
|
//----------------------------------------------
|
||||||
// nsJAREnumerator::HasMore
|
// nsJAREnumerator::HasMore
|
||||||
//----------------------------------------------
|
//----------------------------------------------
|
||||||
@ -1038,10 +1038,10 @@ nsZipReaderCache::nsZipReaderCache()
|
|||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsZipReaderCache::Init(uint32_t cacheSize)
|
nsZipReaderCache::Init(uint32_t cacheSize)
|
||||||
{
|
{
|
||||||
mCacheSize = cacheSize;
|
mCacheSize = cacheSize;
|
||||||
|
|
||||||
// Register as a memory pressure observer
|
// Register as a memory pressure observer
|
||||||
nsCOMPtr<nsIObserverService> os =
|
nsCOMPtr<nsIObserverService> os =
|
||||||
do_GetService("@mozilla.org/observer-service;1");
|
do_GetService("@mozilla.org/observer-service;1");
|
||||||
if (os)
|
if (os)
|
||||||
{
|
{
|
||||||
@ -1068,8 +1068,8 @@ nsZipReaderCache::~nsZipReaderCache()
|
|||||||
|
|
||||||
#ifdef ZIP_CACHE_HIT_RATE
|
#ifdef ZIP_CACHE_HIT_RATE
|
||||||
printf("nsZipReaderCache size=%d hits=%d lookups=%d rate=%f%% flushes=%d missed %d\n",
|
printf("nsZipReaderCache size=%d hits=%d lookups=%d rate=%f%% flushes=%d missed %d\n",
|
||||||
mCacheSize, mZipCacheHits, mZipCacheLookups,
|
mCacheSize, mZipCacheHits, mZipCacheLookups,
|
||||||
(float)mZipCacheHits / mZipCacheLookups,
|
(float)mZipCacheHits / mZipCacheLookups,
|
||||||
mZipCacheFlushes, mZipSyncMisses);
|
mZipCacheFlushes, mZipSyncMisses);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -1205,12 +1205,12 @@ FindOldestZip(nsHashKey *aKey, void *aData, void* closure)
|
|||||||
if (oldest == nullptr ||
|
if (oldest == nullptr ||
|
||||||
currentReleaseTime < oldest->GetReleaseTime()) {
|
currentReleaseTime < oldest->GetReleaseTime()) {
|
||||||
*oldestPtr = current;
|
*oldestPtr = current;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ZipFindData {nsJAR* zip; bool found;};
|
struct ZipFindData {nsJAR* zip; bool found;};
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
FindZip(nsHashKey *aKey, void *aData, void* closure)
|
FindZip(nsHashKey *aKey, void *aData, void* closure)
|
||||||
@ -1218,7 +1218,7 @@ FindZip(nsHashKey *aKey, void *aData, void* closure)
|
|||||||
ZipFindData* find_data = (ZipFindData*)closure;
|
ZipFindData* find_data = (ZipFindData*)closure;
|
||||||
|
|
||||||
if (find_data->zip == (nsJAR*)aData) {
|
if (find_data->zip == (nsJAR*)aData) {
|
||||||
find_data->found = true;
|
find_data->found = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -1230,20 +1230,20 @@ nsZipReaderCache::ReleaseZip(nsJAR* zip)
|
|||||||
nsresult rv;
|
nsresult rv;
|
||||||
MutexAutoLock lock(mLock);
|
MutexAutoLock lock(mLock);
|
||||||
|
|
||||||
// It is possible that two thread compete for this zip. The dangerous
|
// It is possible that two thread compete for this zip. The dangerous
|
||||||
// case is where one thread Releases the zip and discovers that the ref
|
// case is where one thread Releases the zip and discovers that the ref
|
||||||
// count has gone to one. Before it can call this ReleaseZip method
|
// count has gone to one. Before it can call this ReleaseZip method
|
||||||
// another thread calls our GetZip method. The ref count goes to two. That
|
// another thread calls our GetZip method. The ref count goes to two. That
|
||||||
// second thread then Releases the zip and the ref count goes to one. It
|
// second thread then Releases the zip and the ref count goes to one. It
|
||||||
// then tries to enter this ReleaseZip method and blocks while the first
|
// then tries to enter this ReleaseZip method and blocks while the first
|
||||||
// thread is still here. The first thread continues and remove the zip from
|
// thread is still here. The first thread continues and remove the zip from
|
||||||
// the cache and calls its Release method sending the ref count to 0 and
|
// the cache and calls its Release method sending the ref count to 0 and
|
||||||
// deleting the zip. However, the second thread is still blocked at the
|
// deleting the zip. However, the second thread is still blocked at the
|
||||||
// start of ReleaseZip, but the 'zip' param now hold a reference to a
|
// start of ReleaseZip, but the 'zip' param now hold a reference to a
|
||||||
// deleted zip!
|
// deleted zip!
|
||||||
//
|
//
|
||||||
// So, we are going to try safeguarding here by searching our hashtable while
|
// So, we are going to try safeguarding here by searching our hashtable while
|
||||||
// locked here for the zip. We return fast if it is not found.
|
// locked here for the zip. We return fast if it is not found.
|
||||||
|
|
||||||
ZipFindData find_data = {zip, false};
|
ZipFindData find_data = {zip, false};
|
||||||
mZips.Enumerate(FindZip, &find_data);
|
mZips.Enumerate(FindZip, &find_data);
|
||||||
@ -1261,9 +1261,9 @@ nsZipReaderCache::ReleaseZip(nsJAR* zip)
|
|||||||
|
|
||||||
nsJAR* oldest = nullptr;
|
nsJAR* oldest = nullptr;
|
||||||
mZips.Enumerate(FindOldestZip, &oldest);
|
mZips.Enumerate(FindOldestZip, &oldest);
|
||||||
|
|
||||||
// Because of the craziness above it is possible that there is no zip that
|
// Because of the craziness above it is possible that there is no zip that
|
||||||
// needs removing.
|
// needs removing.
|
||||||
if (!oldest)
|
if (!oldest)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|
||||||
@ -1302,7 +1302,7 @@ FindFlushableZip(nsHashKey *aKey, void *aData, void* closure)
|
|||||||
{
|
{
|
||||||
nsHashKey** flushableKeyPtr = (nsHashKey**)closure;
|
nsHashKey** flushableKeyPtr = (nsHashKey**)closure;
|
||||||
nsJAR* current = (nsJAR*)aData;
|
nsJAR* current = (nsJAR*)aData;
|
||||||
|
|
||||||
if (current->GetReleaseTime() != PR_INTERVAL_NO_TIMEOUT) {
|
if (current->GetReleaseTime() != PR_INTERVAL_NO_TIMEOUT) {
|
||||||
*flushableKeyPtr = aKey;
|
*flushableKeyPtr = aKey;
|
||||||
current->SetZipReaderCache(nullptr);
|
current->SetZipReaderCache(nullptr);
|
||||||
@ -1313,14 +1313,14 @@ FindFlushableZip(nsHashKey *aKey, void *aData, void* closure)
|
|||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsZipReaderCache::Observe(nsISupports *aSubject,
|
nsZipReaderCache::Observe(nsISupports *aSubject,
|
||||||
const char *aTopic,
|
const char *aTopic,
|
||||||
const char16_t *aSomeData)
|
const char16_t *aSomeData)
|
||||||
{
|
{
|
||||||
if (strcmp(aTopic, "memory-pressure") == 0) {
|
if (strcmp(aTopic, "memory-pressure") == 0) {
|
||||||
MutexAutoLock lock(mLock);
|
MutexAutoLock lock(mLock);
|
||||||
while (true) {
|
while (true) {
|
||||||
nsHashKey* flushable = nullptr;
|
nsHashKey* flushable = nullptr;
|
||||||
mZips.Enumerate(FindFlushableZip, &flushable);
|
mZips.Enumerate(FindFlushableZip, &flushable);
|
||||||
if ( ! flushable )
|
if ( ! flushable )
|
||||||
break;
|
break;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@ -1350,7 +1350,7 @@ nsZipReaderCache::Observe(nsISupports *aSubject,
|
|||||||
uri.Insert(NS_LITERAL_CSTRING("file:"), 0);
|
uri.Insert(NS_LITERAL_CSTRING("file:"), 0);
|
||||||
nsCStringKey key(uri);
|
nsCStringKey key(uri);
|
||||||
|
|
||||||
MutexAutoLock lock(mLock);
|
MutexAutoLock lock(mLock);
|
||||||
nsJAR* zip = static_cast<nsJAR*>(static_cast<nsIZipReader*>(mZips.Get(&key)));
|
nsJAR* zip = static_cast<nsJAR*>(static_cast<nsIZipReader*>(mZips.Get(&key)));
|
||||||
if (!zip)
|
if (!zip)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
@ -47,9 +47,9 @@ typedef enum
|
|||||||
} JARManifestStatusType;
|
} JARManifestStatusType;
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------
|
/*-------------------------------------------------------------------------
|
||||||
* Class nsJAR declaration.
|
* Class nsJAR declaration.
|
||||||
* nsJAR serves as an XPCOM wrapper for nsZipArchive with the addition of
|
* nsJAR serves as an XPCOM wrapper for nsZipArchive with the addition of
|
||||||
* JAR manifest file parsing.
|
* JAR manifest file parsing.
|
||||||
*------------------------------------------------------------------------*/
|
*------------------------------------------------------------------------*/
|
||||||
class nsJAR : public nsIZipReader
|
class nsJAR : public nsIZipReader
|
||||||
{
|
{
|
||||||
@ -62,9 +62,9 @@ class nsJAR : public nsIZipReader
|
|||||||
|
|
||||||
nsJAR();
|
nsJAR();
|
||||||
virtual ~nsJAR();
|
virtual ~nsJAR();
|
||||||
|
|
||||||
NS_DEFINE_STATIC_CID_ACCESSOR( NS_ZIPREADER_CID )
|
NS_DEFINE_STATIC_CID_ACCESSOR( NS_ZIPREADER_CID )
|
||||||
|
|
||||||
NS_DECL_THREADSAFE_ISUPPORTS
|
NS_DECL_THREADSAFE_ISUPPORTS
|
||||||
|
|
||||||
NS_DECL_NSIZIPREADER
|
NS_DECL_NSIZIPREADER
|
||||||
@ -74,7 +74,7 @@ class nsJAR : public nsIZipReader
|
|||||||
PRIntervalTime GetReleaseTime() {
|
PRIntervalTime GetReleaseTime() {
|
||||||
return mReleaseTime;
|
return mReleaseTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsReleased() {
|
bool IsReleased() {
|
||||||
return mReleaseTime != PR_INTERVAL_NO_TIMEOUT;
|
return mReleaseTime != PR_INTERVAL_NO_TIMEOUT;
|
||||||
}
|
}
|
||||||
@ -82,11 +82,11 @@ class nsJAR : public nsIZipReader
|
|||||||
void SetReleaseTime() {
|
void SetReleaseTime() {
|
||||||
mReleaseTime = PR_IntervalNow();
|
mReleaseTime = PR_IntervalNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClearReleaseTime() {
|
void ClearReleaseTime() {
|
||||||
mReleaseTime = PR_INTERVAL_NO_TIMEOUT;
|
mReleaseTime = PR_INTERVAL_NO_TIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetZipReaderCache(nsZipReaderCache* cache) {
|
void SetZipReaderCache(nsZipReaderCache* cache) {
|
||||||
mCache = cache;
|
mCache = cache;
|
||||||
}
|
}
|
||||||
@ -102,18 +102,18 @@ class nsJAR : public nsIZipReader
|
|||||||
int16_t mGlobalStatus; // Global signature verification status
|
int16_t mGlobalStatus; // Global signature verification status
|
||||||
PRIntervalTime mReleaseTime; // used by nsZipReaderCache for flushing entries
|
PRIntervalTime mReleaseTime; // used by nsZipReaderCache for flushing entries
|
||||||
nsZipReaderCache* mCache; // if cached, this points to the cache it's contained in
|
nsZipReaderCache* mCache; // if cached, this points to the cache it's contained in
|
||||||
mozilla::Mutex mLock;
|
mozilla::Mutex mLock;
|
||||||
int64_t mMtime;
|
int64_t mMtime;
|
||||||
int32_t mTotalItemsInManifest;
|
int32_t mTotalItemsInManifest;
|
||||||
bool mOpened;
|
bool mOpened;
|
||||||
|
|
||||||
nsresult ParseManifest();
|
nsresult ParseManifest();
|
||||||
void ReportError(const nsACString &aFilename, int16_t errorCode);
|
void ReportError(const nsACString &aFilename, int16_t errorCode);
|
||||||
nsresult LoadEntry(const nsACString &aFilename, char** aBuf,
|
nsresult LoadEntry(const nsACString &aFilename, char** aBuf,
|
||||||
uint32_t* aBufLen = nullptr);
|
uint32_t* aBufLen = nullptr);
|
||||||
int32_t ReadLine(const char** src);
|
int32_t ReadLine(const char** src);
|
||||||
nsresult ParseOneFile(const char* filebuf, int16_t aFileType);
|
nsresult ParseOneFile(const char* filebuf, int16_t aFileType);
|
||||||
nsresult VerifyEntry(nsJARManifestItem* aEntry, const char* aEntryData,
|
nsresult VerifyEntry(nsJARManifestItem* aEntry, const char* aEntryData,
|
||||||
uint32_t aLen);
|
uint32_t aLen);
|
||||||
|
|
||||||
nsresult CalculateDigest(const char* aInBuf, uint32_t aInBufLen,
|
nsresult CalculateDigest(const char* aInBuf, uint32_t aInBufLen,
|
||||||
@ -131,7 +131,7 @@ class nsJARItem : public nsIZipEntry
|
|||||||
public:
|
public:
|
||||||
NS_DECL_THREADSAFE_ISUPPORTS
|
NS_DECL_THREADSAFE_ISUPPORTS
|
||||||
NS_DECL_NSIZIPENTRY
|
NS_DECL_NSIZIPENTRY
|
||||||
|
|
||||||
nsJARItem(nsZipItem* aZipItem);
|
nsJARItem(nsZipItem* aZipItem);
|
||||||
virtual ~nsJARItem() {}
|
virtual ~nsJARItem() {}
|
||||||
|
|
||||||
@ -142,14 +142,14 @@ private:
|
|||||||
PRTime mLastModTime;
|
PRTime mLastModTime;
|
||||||
uint16_t mCompression;
|
uint16_t mCompression;
|
||||||
uint32_t mPermissions;
|
uint32_t mPermissions;
|
||||||
bool mIsDirectory;
|
bool mIsDirectory;
|
||||||
bool mIsSynthetic;
|
bool mIsSynthetic;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nsJAREnumerator
|
* nsJAREnumerator
|
||||||
*
|
*
|
||||||
* Enumerates a list of files in a zip archive
|
* Enumerates a list of files in a zip archive
|
||||||
* (based on a pattern match in its member nsZipFind).
|
* (based on a pattern match in its member nsZipFind).
|
||||||
*/
|
*/
|
||||||
class nsJAREnumerator MOZ_FINAL : public nsIUTF8StringEnumerator
|
class nsJAREnumerator MOZ_FINAL : public nsIUTF8StringEnumerator
|
||||||
@ -158,7 +158,7 @@ public:
|
|||||||
NS_DECL_THREADSAFE_ISUPPORTS
|
NS_DECL_THREADSAFE_ISUPPORTS
|
||||||
NS_DECL_NSIUTF8STRINGENUMERATOR
|
NS_DECL_NSIUTF8STRINGENUMERATOR
|
||||||
|
|
||||||
nsJAREnumerator(nsZipFind *aFind) : mFind(aFind), mName(nullptr) {
|
nsJAREnumerator(nsZipFind *aFind) : mFind(aFind), mName(nullptr) {
|
||||||
NS_ASSERTION(mFind, "nsJAREnumerator: Missing zipFind.");
|
NS_ASSERTION(mFind, "nsJAREnumerator: Missing zipFind.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user