Bug 945152 - Part 3-1: New libjar APIs. r=aklotz

This commit is contained in:
Shian-Yow Wu 2014-05-16 13:34:43 +08:00
parent 27facf2028
commit 19422a5329
5 changed files with 47 additions and 8 deletions

View File

@ -5,8 +5,10 @@
#include "nsIChannel.idl"
[scriptable, builtinclass, uuid(6e6cc56d-51eb-4299-a795-dcfd1229ab3d)]
interface nsIJARChannel : nsIChannel
interface nsIFile;
[scriptable, builtinclass, uuid(063e9698-ec67-4fe2-aa19-d21505beaa61)]
interface nsIJARChannel : nsIChannel
{
/**
* Returns TRUE if the JAR file is not safe (if the content type reported
@ -20,4 +22,9 @@ interface nsIJARChannel : nsIChannel
* Forces the uri to be a app:// uri.
*/
void setAppURI(in nsIURI uri);
/**
* Returns the JAR file.
*/
readonly attribute nsIFile jarFile;
};

View File

@ -825,6 +825,13 @@ nsJARChannel::SetAppURI(nsIURI *aURI) {
return NS_OK;
}
NS_IMETHODIMP
nsJARChannel::GetJarFile(nsIFile **aFile)
{
NS_IF_ADDREF(*aFile = mJarFile);
return NS_OK;
}
//-----------------------------------------------------------------------------
// nsIDownloadObserver
//-----------------------------------------------------------------------------

View File

@ -763,9 +763,9 @@ nsZipHandle* nsZipArchive::GetFD()
}
//---------------------------------------------
// nsZipArchive::GetData
// nsZipArchive::GetDataOffset
//---------------------------------------------
const uint8_t* nsZipArchive::GetData(nsZipItem* aItem)
uint32_t nsZipArchive::GetDataOffset(nsZipItem* aItem)
{
PR_ASSERT (aItem);
MOZ_WIN_MEM_TRY_BEGIN
@ -775,12 +775,12 @@ MOZ_WIN_MEM_TRY_BEGIN
const uint8_t* data = mFd->mFileData;
uint32_t offset = aItem->LocalOffset();
if (offset + ZIPLOCAL_SIZE > len)
return nullptr;
return 0;
// -- check signature before using the structure, in case the zip file is corrupt
ZipLocal* Local = (ZipLocal*)(data + offset);
if ((xtolong(Local->signature) != LOCALSIG))
return nullptr;
return 0;
//-- NOTE: extralen is different in central header and local header
//-- for archives created using the Unix "zip" utility. To set
@ -789,11 +789,24 @@ MOZ_WIN_MEM_TRY_BEGIN
xtoint(Local->filename_len) +
xtoint(Local->extrafield_len);
return offset;
MOZ_WIN_MEM_TRY_CATCH(return 0)
}
//---------------------------------------------
// nsZipArchive::GetData
//---------------------------------------------
const uint8_t* nsZipArchive::GetData(nsZipItem* aItem)
{
PR_ASSERT (aItem);
MOZ_WIN_MEM_TRY_BEGIN
uint32_t offset = GetDataOffset(aItem);
// -- check if there is enough source data in the file
if (offset + aItem->Size() > len)
if (!offset || offset + aItem->Size() > mFd->mLen)
return nullptr;
return data + offset;
return mFd->mFileData + offset;
MOZ_WIN_MEM_TRY_CATCH(return nullptr)
}

View File

@ -178,6 +178,13 @@ public:
*/
nsZipHandle* GetFD();
/**
* Gets the data offset.
* @param aItem Pointer to nsZipItem
* returns 0 on failure.
*/
uint32_t GetDataOffset(nsZipItem* aItem);
/**
* Get pointer to the data of the item.
* @param aItem Pointer to nsZipItem

View File

@ -118,6 +118,11 @@ NS_IMETHODIMP DummyChannel::SetAppURI(nsIURI *aURI)
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DummyChannel::GetJarFile(nsIFile* *aFile)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DummyChannel::Run()
{
nsresult rv = mListener->OnStartRequest(this, mListenerContext);