Landing nsIFile.
git-svn-id: svn://10.0.0.236/trunk@58490 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -20,7 +20,6 @@
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIFileSpec.h"
|
||||
#include "nsSpecialSystemDirectory.h"
|
||||
#include "nsJARChannel.h"
|
||||
#include "nsCRT.h"
|
||||
@@ -28,12 +27,11 @@
|
||||
#include "nsIURL.h"
|
||||
#include "nsIMIMEService.h"
|
||||
#include "nsAutoLock.h"
|
||||
#include "nsIFileStreams.h"
|
||||
|
||||
static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID);
|
||||
static NS_DEFINE_CID(kMIMEServiceCID, NS_MIMESERVICE_CID);
|
||||
static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID);
|
||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsJARDownloadObserver : public nsIStreamObserver
|
||||
@@ -58,18 +56,18 @@ public:
|
||||
"wrong transport");
|
||||
// after successfully downloading the jar file to the cache,
|
||||
// start the extraction process:
|
||||
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIFileChannel> jarCacheFile;
|
||||
rv = serv->NewChannelFromNativePath(mJarCacheFile.GetNativePathCString(),
|
||||
mJARChannel->mLoadGroup,
|
||||
mJARChannel->mCallbacks,
|
||||
mJARChannel->mLoadAttributes,
|
||||
nsnull,
|
||||
mJARChannel->mBufferSegmentSize,
|
||||
mJARChannel->mBufferMaxSize,
|
||||
getter_AddRefs(jarCacheFile));
|
||||
rv = NS_NewFileChannel(mJarCacheFile,
|
||||
PR_RDONLY,
|
||||
nsnull, // XXX content type
|
||||
0, // XXX content length
|
||||
mJARChannel->mLoadGroup,
|
||||
mJARChannel->mCallbacks,
|
||||
mJARChannel->mLoadAttributes,
|
||||
nsnull,
|
||||
mJARChannel->mBufferSegmentSize,
|
||||
mJARChannel->mBufferMaxSize,
|
||||
getter_AddRefs(jarCacheFile));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = mJARChannel->ExtractJARElement(jarCacheFile);
|
||||
@@ -78,7 +76,7 @@ public:
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsJARDownloadObserver(nsFileSpec& jarCacheFile, nsJARChannel* jarChannel) {
|
||||
nsJARDownloadObserver(nsIFile* jarCacheFile, nsJARChannel* jarChannel) {
|
||||
NS_INIT_REFCNT();
|
||||
mJarCacheFile = jarCacheFile;
|
||||
mJARChannel = jarChannel;
|
||||
@@ -90,7 +88,7 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
nsFileSpec mJarCacheFile;
|
||||
nsCOMPtr<nsIFile> mJarCacheFile;
|
||||
nsJARChannel* mJARChannel;
|
||||
};
|
||||
|
||||
@@ -314,29 +312,35 @@ nsJARChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
|
||||
else {
|
||||
// otherwise, we need to download the jar file
|
||||
|
||||
nsFileSpec jarCacheFile;
|
||||
rv = GetCacheFile(jarCacheFile);
|
||||
nsCOMPtr<nsIFile> jarCacheFile;
|
||||
rv = GetCacheFile(getter_AddRefs(jarCacheFile));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (jarCacheFile.IsFile()) {
|
||||
|
||||
PRBool filePresent;
|
||||
|
||||
rv = jarCacheFile->IsFile(&filePresent);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (filePresent)
|
||||
{
|
||||
// then we've already got the file in the local cache -- no need to download it
|
||||
|
||||
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
|
||||
NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIFileChannel> jarCacheChannel;
|
||||
rv = serv->NewChannelFromNativePath(jarCacheFile.GetNativePathCString(),
|
||||
mLoadGroup,
|
||||
mCallbacks,
|
||||
mLoadAttributes,
|
||||
nsnull,
|
||||
mBufferSegmentSize,
|
||||
mBufferMaxSize,
|
||||
getter_AddRefs(jarCacheChannel));
|
||||
|
||||
nsCOMPtr<nsIChannel> jarCacheChannel;
|
||||
rv = fts->CreateTransport(jarCacheFile,
|
||||
PR_RDONLY,
|
||||
mCommand,
|
||||
mBufferSegmentSize,
|
||||
mBufferMaxSize,
|
||||
getter_AddRefs(jarCacheChannel));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = ExtractJARElement(jarCacheChannel);
|
||||
|
||||
nsCOMPtr<nsIFileChannel> fileChannel = do_QueryInterface(jarCacheChannel);
|
||||
if (fileChannel) return NS_ERROR_FAILURE;
|
||||
rv = ExtractJARElement(fileChannel);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -347,7 +351,8 @@ nsJARChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
|
||||
|
||||
// use a file transport to serve as a data pump for the download (done
|
||||
// on some other thread)
|
||||
rv = fts->CreateTransport(jarCacheFile, mCommand,
|
||||
nsCOMPtr<nsIChannel> jarCacheTransport;
|
||||
rv = fts->CreateTransport(jarCacheFile, PR_RDONLY, mCommand,
|
||||
mBufferSegmentSize, mBufferMaxSize,
|
||||
getter_AddRefs(mJarCacheTransport));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
@@ -369,16 +374,25 @@ nsJARChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJARChannel::GetCacheFile(nsFileSpec& cacheFile)
|
||||
nsJARChannel::GetCacheFile(nsIFile* *cacheFile)
|
||||
{
|
||||
// XXX change later to use the real network cache
|
||||
nsresult rv;
|
||||
|
||||
nsSpecialSystemDirectory jarCacheFile(nsSpecialSystemDirectory::OS_CurrentProcessDirectory);
|
||||
jarCacheFile += "jarCache";
|
||||
nsCOMPtr<nsIFile> jarCacheFile;
|
||||
rv = NS_GetSpecialDirectory("xpcom.currentProcess.componentDirectory",
|
||||
getter_AddRefs(jarCacheFile));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (!jarCacheFile.Exists())
|
||||
jarCacheFile.CreateDirectory();
|
||||
jarCacheFile->Append("jarCache");
|
||||
|
||||
PRBool exists;
|
||||
rv = jarCacheFile->Exists(&exists);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (!exists) {
|
||||
rv = jarCacheFile->Create(nsIFile::DIRECTORY_TYPE, 0664);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIURL> jarBaseURL = do_QueryInterface(mJARBaseURI, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
@@ -386,10 +400,11 @@ nsJARChannel::GetCacheFile(nsFileSpec& cacheFile)
|
||||
char* jarFileName;
|
||||
rv = jarBaseURL->GetFileName(&jarFileName);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
jarCacheFile += jarFileName;
|
||||
jarCacheFile->Append(jarFileName);
|
||||
nsCRT::free(jarFileName);
|
||||
|
||||
cacheFile = jarCacheFile;
|
||||
*cacheFile = jarCacheFile;
|
||||
NS_ADDREF(*cacheFile);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -606,8 +621,8 @@ nsJARChannel::Open(char* *contentType, PRInt32 *contentLength)
|
||||
getter_AddRefs(mJAR));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsFileSpec fs;
|
||||
rv = mJARBaseFile->GetFileSpec(&fs);
|
||||
nsCOMPtr<nsIFile> fs;
|
||||
rv = mJARBaseFile->GetFile(getter_AddRefs(fs));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = mJAR->Init(fs);
|
||||
|
||||
Reference in New Issue
Block a user