1999-11-08 00:55:12 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
2000-09-22 10:21:18 +04:00
|
|
|
* Copyright (C) 1998,2000 Netscape Communications Corporation. All Rights
|
1999-11-08 00:55:12 +03:00
|
|
|
* Reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsJARChannel.h"
|
2003-01-18 05:15:14 +03:00
|
|
|
#include "nsJARProtocolHandler.h"
|
2000-02-09 08:04:52 +03:00
|
|
|
#include "nsMimeTypes.h"
|
2003-01-18 05:15:14 +03:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
|
2003-10-22 02:11:49 +04:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
#include "nsIPrincipal.h"
|
2003-01-18 05:15:14 +03:00
|
|
|
#include "nsIFileURL.h"
|
2001-02-23 03:15:04 +03:00
|
|
|
#include "nsIJAR.h"
|
2000-06-03 03:39:45 +04:00
|
|
|
|
2003-06-24 02:58:28 +04:00
|
|
|
static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID);
|
2003-01-18 05:15:14 +03:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2000-02-01 02:43:09 +03:00
|
|
|
|
2000-03-30 11:39:31 +04:00
|
|
|
#if defined(PR_LOGGING)
|
|
|
|
//
|
2003-01-18 05:15:14 +03:00
|
|
|
// set NSPR_LOG_MODULES=nsJarProtocol:5
|
2000-03-30 11:39:31 +04:00
|
|
|
//
|
2003-01-18 05:15:14 +03:00
|
|
|
static PRLogModuleInfo *gJarProtocolLog = nsnull;
|
|
|
|
#endif
|
2000-03-30 11:39:31 +04:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
#define LOG(args) PR_LOG(gJarProtocolLog, PR_LOG_DEBUG, args)
|
|
|
|
#define LOG_ENABLED() PR_LOG_TEST(gJarProtocolLog, 4)
|
1999-11-08 00:55:12 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsJARInputThunk
|
|
|
|
//
|
|
|
|
// this class allows us to do some extra work on the stream transport thread.
|
|
|
|
//-----------------------------------------------------------------------------
|
2000-04-12 11:58:24 +04:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
class nsJARInputThunk : public nsIInputStream
|
1999-11-08 00:55:12 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIINPUTSTREAM
|
1999-11-08 00:55:12 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARInputThunk(nsIFile *jarFile, const nsACString &jarEntry,
|
|
|
|
nsIZipReaderCache *jarCache)
|
|
|
|
: mJarCache(jarCache)
|
|
|
|
, mJarFile(jarFile)
|
|
|
|
, mJarEntry(jarEntry)
|
2003-01-28 22:13:52 +03:00
|
|
|
, mContentLength(-1)
|
2003-01-18 05:15:14 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mJarFile, "no jar file");
|
|
|
|
}
|
2003-06-24 02:58:28 +04:00
|
|
|
|
|
|
|
virtual ~nsJARInputThunk()
|
|
|
|
{
|
|
|
|
if (!mJarCache && mJarReader)
|
|
|
|
mJarReader->Close();
|
|
|
|
}
|
1999-11-08 00:55:12 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
void GetJarReader(nsIZipReader **result)
|
|
|
|
{
|
2003-01-28 22:13:52 +03:00
|
|
|
NS_IF_ADDREF(*result = mJarReader);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 GetContentLength()
|
|
|
|
{
|
|
|
|
return mContentLength;
|
2003-01-18 05:15:14 +03:00
|
|
|
}
|
1999-11-08 00:55:12 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
nsresult EnsureJarStream();
|
1999-11-08 00:55:12 +03:00
|
|
|
|
2003-01-29 09:47:55 +03:00
|
|
|
private:
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
nsCOMPtr<nsIZipReaderCache> mJarCache;
|
|
|
|
nsCOMPtr<nsIZipReader> mJarReader;
|
|
|
|
nsCOMPtr<nsIFile> mJarFile;
|
|
|
|
nsCOMPtr<nsIInputStream> mJarStream;
|
|
|
|
nsCString mJarEntry;
|
2003-01-28 22:13:52 +03:00
|
|
|
PRInt32 mContentLength;
|
2003-01-18 05:15:14 +03:00
|
|
|
};
|
1999-11-08 00:55:12 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS1(nsJARInputThunk, nsIInputStream)
|
1999-11-08 00:55:12 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
nsresult
|
|
|
|
nsJARInputThunk::EnsureJarStream()
|
1999-11-08 00:55:12 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
if (mJarStream)
|
|
|
|
return NS_OK;
|
1999-11-17 11:14:52 +03:00
|
|
|
|
2003-01-28 22:13:52 +03:00
|
|
|
nsresult rv;
|
2003-06-24 02:58:28 +04:00
|
|
|
if (mJarCache)
|
|
|
|
rv = mJarCache->GetZip(mJarFile, getter_AddRefs(mJarReader));
|
|
|
|
else {
|
|
|
|
// create an uncached jar reader
|
|
|
|
mJarReader = do_CreateInstance(kZipReaderCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = mJarReader->Init(mJarFile);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = mJarReader->Open();
|
|
|
|
}
|
2003-01-18 05:15:14 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-11-08 00:55:12 +03:00
|
|
|
|
2003-01-28 22:13:52 +03:00
|
|
|
rv = mJarReader->GetInputStream(mJarEntry.get(),
|
|
|
|
getter_AddRefs(mJarStream));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2003-09-11 20:45:50 +04:00
|
|
|
// ask the JarStream for the content length
|
|
|
|
mJarStream->Available((PRUint32 *) &mContentLength);
|
2003-01-28 22:13:52 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2000-08-21 12:23:54 +04:00
|
|
|
}
|
|
|
|
|
1999-11-08 00:55:12 +03:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARInputThunk::Close()
|
1999-11-08 00:55:12 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
if (mJarStream)
|
|
|
|
return mJarStream->Close();
|
1999-11-08 00:55:12 +03:00
|
|
|
|
2000-03-29 07:58:50 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARInputThunk::Available(PRUint32 *avail)
|
1999-11-08 00:55:12 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
nsresult rv = EnsureJarStream();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-02-21 23:38:08 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
return mJarStream->Available(avail);
|
1999-11-08 00:55:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARInputThunk::Read(char *buf, PRUint32 count, PRUint32 *countRead)
|
1999-11-08 00:55:12 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
nsresult rv = EnsureJarStream();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-01-24 06:54:20 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
return mJarStream->Read(buf, count, countRead);
|
1999-11-08 00:55:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARInputThunk::ReadSegments(nsWriteSegmentFun writer, void *closure,
|
|
|
|
PRUint32 count, PRUint32 *countRead)
|
1999-11-08 00:55:12 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
// stream transport does only calls Read()
|
|
|
|
NS_NOTREACHED("nsJarInputThunk::ReadSegments");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1999-11-08 00:55:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARInputThunk::IsNonBlocking(PRBool *nonBlocking)
|
1999-11-08 00:55:12 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
*nonBlocking = PR_FALSE;
|
1999-11-08 00:55:12 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
//-----------------------------------------------------------------------------
|
2000-03-29 07:58:50 +04:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARChannel::nsJARChannel()
|
|
|
|
: mContentLength(-1)
|
|
|
|
, mLoadFlags(LOAD_NORMAL)
|
|
|
|
, mStatus(NS_OK)
|
|
|
|
, mIsPending(PR_FALSE)
|
|
|
|
, mJarInput(nsnull)
|
1999-11-08 00:55:12 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
#if defined(PR_LOGGING)
|
|
|
|
if (!gJarProtocolLog)
|
|
|
|
gJarProtocolLog = PR_NewLogModule("nsJarProtocol");
|
|
|
|
#endif
|
1999-11-08 00:55:12 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
// hold an owning reference to the jar handler
|
|
|
|
NS_ADDREF(gJarHandler);
|
2000-03-30 11:39:31 +04:00
|
|
|
}
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARChannel::~nsJARChannel()
|
1999-11-08 00:55:12 +03:00
|
|
|
{
|
2003-01-18 06:50:41 +03:00
|
|
|
// with the exception of certain error cases mJarInput will already be null.
|
|
|
|
NS_IF_RELEASE(mJarInput);
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
// release owning reference to the jar handler
|
|
|
|
nsJARProtocolHandler *handler = gJarHandler;
|
|
|
|
NS_RELEASE(handler); // NULL parameter
|
2000-03-29 07:58:50 +04:00
|
|
|
}
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
NS_IMPL_ISUPPORTS6(nsJARChannel,
|
|
|
|
nsIRequest,
|
|
|
|
nsIChannel,
|
|
|
|
nsIStreamListener,
|
|
|
|
nsIRequestObserver,
|
|
|
|
nsIDownloadObserver,
|
|
|
|
nsIJARChannel)
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsJARChannel::Init(nsIURI *uri)
|
2000-03-30 11:39:31 +04:00
|
|
|
{
|
2000-08-25 02:35:46 +04:00
|
|
|
nsresult rv;
|
2003-01-18 05:15:14 +03:00
|
|
|
mJarURI = do_QueryInterface(uri, &rv);
|
2001-09-15 01:19:41 +04:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
#if defined(PR_LOGGING)
|
|
|
|
mJarURI->GetSpec(mSpec);
|
2001-09-19 03:07:57 +04:00
|
|
|
#endif
|
2003-01-18 05:15:14 +03:00
|
|
|
return rv;
|
|
|
|
}
|
2001-09-19 03:07:57 +04:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
nsresult
|
2003-06-24 02:58:28 +04:00
|
|
|
nsJARChannel::CreateJarInput(nsIZipReaderCache *jarCache)
|
2003-01-18 05:15:14 +03:00
|
|
|
{
|
|
|
|
// important to pass a clone of the file since the nsIFile impl is not
|
|
|
|
// necessarily MT-safe
|
|
|
|
nsCOMPtr<nsIFile> clonedFile;
|
|
|
|
nsresult rv = mJarFile->Clone(getter_AddRefs(clonedFile));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-08-25 02:35:46 +04:00
|
|
|
|
2003-06-24 02:58:28 +04:00
|
|
|
mJarInput = new nsJARInputThunk(clonedFile, mJarEntry, jarCache);
|
2003-01-18 05:15:14 +03:00
|
|
|
if (!mJarInput)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(mJarInput);
|
|
|
|
return NS_OK;
|
2000-03-30 11:39:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARChannel::EnsureJarInput(PRBool blocking)
|
1999-11-08 00:55:12 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("nsJARChannel::EnsureJarInput [this=%x %s]\n", this, mSpec.get()));
|
2000-03-30 11:39:31 +04:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
2000-03-30 11:39:31 +04:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
rv = mJarURI->GetJARFile(getter_AddRefs(mJarBaseURI));
|
2001-09-15 01:19:41 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-11-08 00:55:12 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
rv = mJarURI->GetJAREntry(mJarEntry);
|
2001-09-15 01:19:41 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-09-10 04:42:50 +04:00
|
|
|
|
2001-09-15 01:19:41 +04:00
|
|
|
// try to get a nsIFile directly from the url, which will often succeed.
|
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(mJarBaseURI);
|
2001-09-15 01:19:41 +04:00
|
|
|
if (fileURL)
|
2003-01-18 05:15:14 +03:00
|
|
|
fileURL->GetFile(getter_AddRefs(mJarFile));
|
2001-09-15 01:19:41 +04:00
|
|
|
}
|
2000-09-21 12:26:07 +04:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
if (mJarFile) {
|
2003-06-24 02:58:28 +04:00
|
|
|
rv = CreateJarInput(gJarHandler->JarCache());
|
2003-01-18 05:15:14 +03:00
|
|
|
}
|
|
|
|
else if (blocking) {
|
|
|
|
NS_NOTREACHED("need sync downloader");
|
|
|
|
rv = NS_ERROR_NOT_IMPLEMENTED;
|
2001-09-15 01:19:41 +04:00
|
|
|
}
|
|
|
|
else {
|
2003-01-18 05:15:14 +03:00
|
|
|
// kick off an async download of the base URI...
|
2003-06-24 02:58:28 +04:00
|
|
|
rv = NS_NewDownloader(getter_AddRefs(mDownloader), this);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = NS_OpenURI(mDownloader, nsnull, mJarBaseURI, nsnull,
|
|
|
|
mLoadGroup, mCallbacks,
|
|
|
|
mLoadFlags & ~LOAD_DOCUMENT_URI);
|
1999-11-08 00:55:12 +03:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
}
|
1999-11-17 11:14:52 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsIRequest
|
|
|
|
//-----------------------------------------------------------------------------
|
2001-02-21 23:38:08 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARChannel::GetName(nsACString &result)
|
|
|
|
{
|
|
|
|
return mJarURI->GetSpec(result);
|
|
|
|
}
|
2000-04-12 11:58:24 +04:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARChannel::IsPending(PRBool *result)
|
|
|
|
{
|
|
|
|
*result = mIsPending;
|
|
|
|
return NS_OK;
|
1999-11-08 00:55:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARChannel::GetStatus(nsresult *status)
|
1999-11-08 00:55:12 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
if (mPump && NS_SUCCEEDED(mStatus))
|
|
|
|
mPump->GetStatus(status);
|
|
|
|
else
|
|
|
|
*status = mStatus;
|
1999-11-08 00:55:12 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARChannel::Cancel(nsresult status)
|
1999-11-08 00:55:12 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
mStatus = status;
|
|
|
|
if (mPump)
|
|
|
|
return mPump->Cancel(status);
|
|
|
|
|
|
|
|
NS_ASSERTION(!mIsPending, "need to implement cancel when downloading");
|
1999-11-08 00:55:12 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARChannel::Suspend()
|
1999-11-08 00:55:12 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
if (mPump)
|
|
|
|
return mPump->Suspend();
|
1999-11-08 00:55:12 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
NS_ASSERTION(!mIsPending, "need to implement suspend when downloading");
|
|
|
|
return NS_OK;
|
1999-11-08 00:55:12 +03:00
|
|
|
}
|
|
|
|
|
2000-01-08 09:26:04 +03:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARChannel::Resume()
|
2000-01-08 09:26:04 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
if (mPump)
|
|
|
|
return mPump->Resume();
|
|
|
|
|
|
|
|
NS_ASSERTION(!mIsPending, "need to implement resume when downloading");
|
2002-03-21 01:50:33 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-01-08 09:26:04 +03:00
|
|
|
|
2002-03-21 01:50:33 +03:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARChannel::GetLoadFlags(nsLoadFlags *aLoadFlags)
|
2002-03-21 01:50:33 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
*aLoadFlags = mLoadFlags;
|
2002-03-21 01:50:33 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-01-08 09:26:04 +03:00
|
|
|
|
2002-03-21 01:50:33 +03:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARChannel::SetLoadFlags(nsLoadFlags aLoadFlags)
|
2002-03-21 01:50:33 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
mLoadFlags = aLoadFlags;
|
2000-01-08 09:26:04 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-08 00:55:12 +03:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARChannel::GetLoadGroup(nsILoadGroup **aLoadGroup)
|
1999-11-08 00:55:12 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
NS_IF_ADDREF(*aLoadGroup = mLoadGroup);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-03-21 01:50:33 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARChannel::SetLoadGroup(nsILoadGroup *aLoadGroup)
|
|
|
|
{
|
|
|
|
mLoadGroup = aLoadGroup;
|
1999-11-08 00:55:12 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsIChannel
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2000-03-29 07:58:50 +04:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARChannel::GetOriginalURI(nsIURI **aURI)
|
2000-03-29 07:58:50 +04:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
if (mOriginalURI)
|
|
|
|
*aURI = mOriginalURI;
|
|
|
|
else
|
|
|
|
*aURI = mJarURI;
|
|
|
|
NS_IF_ADDREF(*aURI);
|
|
|
|
return NS_OK;
|
2000-03-29 07:58:50 +04:00
|
|
|
}
|
|
|
|
|
1999-11-08 00:55:12 +03:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARChannel::SetOriginalURI(nsIURI *aURI)
|
1999-11-08 00:55:12 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
mOriginalURI = aURI;
|
1999-11-08 00:55:12 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-17 11:14:52 +03:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARChannel::GetURI(nsIURI **aURI)
|
1999-11-17 11:14:52 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
NS_IF_ADDREF(*aURI = mJarURI);
|
1999-11-17 11:14:52 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-08 00:55:12 +03:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARChannel::GetOwner(nsISupports **result)
|
1999-11-08 00:55:12 +03:00
|
|
|
{
|
2000-08-23 07:17:42 +04:00
|
|
|
nsresult rv;
|
2003-01-18 05:15:14 +03:00
|
|
|
|
|
|
|
if (mOwner) {
|
|
|
|
NS_ADDREF(*result = mOwner);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mJarInput) {
|
|
|
|
*result = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-- Verify signature, if one is present, and set owner accordingly
|
|
|
|
nsCOMPtr<nsIZipReader> jarReader;
|
|
|
|
mJarInput->GetJarReader(getter_AddRefs(jarReader));
|
|
|
|
if (!jarReader)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIJAR> jar = do_QueryInterface(jarReader, &rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_ERROR("nsIJAR not supported");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrincipal> cert;
|
|
|
|
rv = jar->GetCertificatePrincipal(mJarEntry.get(), getter_AddRefs(cert));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (cert) {
|
2003-10-22 02:11:49 +04:00
|
|
|
nsXPIDLCString certID;
|
|
|
|
rv = cert->GetCertificateID(getter_Copies(certID));
|
2000-08-24 11:36:53 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2003-10-22 02:11:49 +04:00
|
|
|
nsCOMPtr<nsIScriptSecurityManager> secMan =
|
|
|
|
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
|
2003-01-18 05:15:14 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2003-10-22 02:11:49 +04:00
|
|
|
rv = secMan->GetCertificatePrincipal(certID, mJarBaseURI,
|
|
|
|
getter_AddRefs(cert));
|
2003-01-18 05:15:14 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2003-10-22 02:11:49 +04:00
|
|
|
mOwner = do_QueryInterface(cert, &rv);
|
2003-01-18 05:15:14 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
NS_ADDREF(*result = mOwner);
|
2000-08-23 07:17:42 +04:00
|
|
|
}
|
1999-11-08 00:55:12 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARChannel::SetOwner(nsISupports *aOwner)
|
1999-11-08 00:55:12 +03:00
|
|
|
{
|
2000-03-21 07:17:37 +03:00
|
|
|
mOwner = aOwner;
|
|
|
|
return NS_OK;
|
1999-11-08 00:55:12 +03:00
|
|
|
}
|
|
|
|
|
1999-11-17 11:14:52 +03:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARChannel::GetNotificationCallbacks(nsIInterfaceRequestor **aCallbacks)
|
1999-11-17 11:14:52 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
NS_IF_ADDREF(*aCallbacks = mCallbacks);
|
1999-11-17 11:14:52 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARChannel::SetNotificationCallbacks(nsIInterfaceRequestor *aCallbacks)
|
1999-11-17 11:14:52 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
mCallbacks = aCallbacks;
|
|
|
|
mProgressSink = do_GetInterface(mCallbacks);
|
1999-11-17 11:14:52 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-18 01:06:32 +03:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARChannel::GetSecurityInfo(nsISupports **aSecurityInfo)
|
2000-03-18 01:06:32 +03:00
|
|
|
{
|
|
|
|
*aSecurityInfo = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-08-24 11:36:53 +04:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARChannel::GetContentType(nsACString &result)
|
|
|
|
{
|
2003-11-12 23:09:05 +03:00
|
|
|
if (mContentType.IsEmpty()) {
|
|
|
|
//
|
|
|
|
// generate content type and set it
|
|
|
|
//
|
|
|
|
if (mJarEntry.IsEmpty()) {
|
|
|
|
LOG(("mJarEntry is empty!\n"));
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2003-01-18 05:15:14 +03:00
|
|
|
}
|
2003-11-12 23:09:05 +03:00
|
|
|
|
|
|
|
const char *ext = nsnull, *fileName = mJarEntry.get();
|
|
|
|
PRInt32 len = mJarEntry.Length();
|
|
|
|
for (PRInt32 i = len-1; i >= 0; i--) {
|
|
|
|
if (fileName[i] == '.') {
|
|
|
|
ext = &fileName[i + 1];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ext) {
|
|
|
|
nsIMIMEService *mimeServ = gJarHandler->MimeService();
|
|
|
|
if (mimeServ) {
|
|
|
|
nsXPIDLCString mimeType;
|
|
|
|
nsresult rv = mimeServ->GetTypeFromExtension(ext, getter_Copies(mimeType));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mContentType = mimeType;
|
|
|
|
}
|
2003-01-18 05:15:14 +03:00
|
|
|
}
|
2003-11-12 23:09:05 +03:00
|
|
|
if (mContentType.IsEmpty())
|
|
|
|
mContentType = NS_LITERAL_CSTRING(UNKNOWN_CONTENT_TYPE);
|
2003-01-18 05:15:14 +03:00
|
|
|
}
|
|
|
|
result = mContentType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-09-22 10:21:18 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARChannel::SetContentType(const nsACString &aContentType)
|
2000-09-22 10:21:18 +04:00
|
|
|
{
|
2003-06-24 01:00:46 +04:00
|
|
|
// If someone gives us a type hint we should just use that type instead of
|
|
|
|
// doing our guessing. So we don't care when this is being called.
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
// mContentCharset is unchanged if not parsed
|
|
|
|
NS_ParseContentType(aContentType, mContentType, mContentCharset);
|
|
|
|
return NS_OK;
|
2000-09-22 10:21:18 +04:00
|
|
|
}
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARChannel::GetContentCharset(nsACString &aContentCharset)
|
|
|
|
{
|
2003-06-24 01:00:46 +04:00
|
|
|
// If someone gives us a charset hint we should just use that charset.
|
|
|
|
// So we don't care when this is being called.
|
2003-01-18 05:15:14 +03:00
|
|
|
aContentCharset = mContentCharset;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-11-08 00:55:12 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARChannel::SetContentCharset(const nsACString &aContentCharset)
|
1999-11-08 00:55:12 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
mContentCharset = aContentCharset;
|
|
|
|
return NS_OK;
|
1999-11-08 00:55:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARChannel::GetContentLength(PRInt32 *result)
|
1999-11-08 00:55:12 +03:00
|
|
|
{
|
2003-01-28 22:13:52 +03:00
|
|
|
// if content length is unknown, query mJarInput...
|
|
|
|
if (mContentLength < 0 && mJarInput)
|
|
|
|
mContentLength = mJarInput->GetContentLength();
|
2000-09-08 04:24:13 +04:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
*result = mContentLength;
|
|
|
|
return NS_OK;
|
1999-11-08 00:55:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARChannel::SetContentLength(PRInt32 aContentLength)
|
1999-11-08 00:55:12 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
// XXX does this really make any sense at all?
|
|
|
|
mContentLength = aContentLength;
|
|
|
|
return NS_OK;
|
1999-11-08 00:55:12 +03:00
|
|
|
}
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARChannel::Open(nsIInputStream **stream)
|
1999-11-08 00:55:12 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("nsJARChannel::Open [this=%x]\n", this));
|
2000-03-30 11:39:31 +04:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
NS_ENSURE_TRUE(!mJarInput, NS_ERROR_IN_PROGRESS);
|
|
|
|
NS_ENSURE_TRUE(!mIsPending, NS_ERROR_IN_PROGRESS);
|
2000-08-24 11:36:53 +04:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
nsresult rv = EnsureJarInput(PR_TRUE);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (!mJarInput)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
2003-01-29 09:47:55 +03:00
|
|
|
// force load the jar file now so GetContentLength will return a
|
|
|
|
// meaningful value once we return.
|
|
|
|
mJarInput->EnsureJarStream();
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
NS_ADDREF(*stream = mJarInput);
|
2000-08-24 11:36:53 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctx)
|
2000-08-24 11:36:53 +04:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("nsJARChannel::AsyncOpen [this=%x]\n", this));
|
1999-11-12 09:13:13 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
NS_ENSURE_TRUE(!mIsPending, NS_ERROR_IN_PROGRESS);
|
|
|
|
|
|
|
|
nsresult rv = EnsureJarInput(PR_FALSE);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (mJarInput) {
|
|
|
|
// create input stream pump
|
|
|
|
rv = NS_NewInputStreamPump(getter_AddRefs(mPump), mJarInput);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = mPump->AsyncRead(this, nsnull);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mLoadGroup)
|
|
|
|
mLoadGroup->AddRequest(this, nsnull);
|
|
|
|
|
|
|
|
mListener = listener;
|
|
|
|
mListenerContext = ctx;
|
|
|
|
mIsPending = PR_TRUE;
|
Bit checkin for bug 68045, r/sr=waterson&shaver, second attempt. It all works
for me on optimized and debug gcc2.96, rh7.1.
- Better failure codes from nsXULPrototypeScript::Deserialize.
- Call nsXULDocument::AbortFastLoads after nsXULPrototypeScript::Serialize
failure, instead of just nulling the FastLoad service's output stream.
- Expose nsXULDocument::AbortFastLoads via nsIXULPrototypeCache, for use from
nsChromeProtocolHandler.cpp. AbortFastLoads flushes the XUL cache now, for
good measure.
- The needless "Current" adjective in nsIFastLoadService attribute and method
names is no more.
- Add a do_GetFastLoadService() helper, to use CID instead of contractid, and
to let the compiler consolidate the static inline CID.
- Add "nglayout.debug.checksum_xul_fastload_file" pref so people can do without
the checksum verification step when reading a FastLoad file.
- Verify the FastLoad file checksum, by default. Also, cache it in the FastLoad
service so we don't recompute it when re-opening the FastLoad file as mailnews
and other top-levels start up. Fill the checksum cache in EndFastLoad, when
the last pseudo-concurrent top-level finishes loading.
My hope to compute the checksum while writing the FastLoad file ran afoul of
misordered writes. The old code to checksum the in-memory nsFastLoadHeader
also was broken on little endian platforms. Now all checksumming is done via
a separate read pass over the complete file, save for the header's checksum
field, which is summed as if it contained zero.
- Track and check FastLoad file dependencies. This required groveling with a
bunch of Necko interfaces in nsChromeProtocolHandler::NewChannel -- read it
and weep. Dependency checking, as well as checksum access and computation,
use better-factored nsIFastLoad{File,Read,Write}Control interfaces.
- nsBufferedStream::Seek wasn't flushing the buffer when seeking backward
within the buffer, but it must, because mCursor bounds the amount to write
if the buffer contains the end of file.
- Add an unbufferedStream readonly attribute to nsIStreamBufferAccess, so we
don't have to screw around with the bufferying layer when checksumming. Also
implement nsIStreamBufferAccess in nsBufferedOutputStream.
- nsISeekableOutputStream was bogus, based on a bad state I had put the
nsBufferedOutputStream code in on its way from being completely broken when
you seek backwards outside of the buffer. Removing this interface required
using nsIFastLoadFileIO in nsFastLoadFileWriter, and it also required careful
ordering of Close calls (the Reader must close after the Writer or Updater,
so that the Reader's underlying, unbuffered input stream can be read by
nsFastLoadFileWriter::Close to compute the checksum.
- Miscellaneous tab/indentation, comment typo, bracing, if( => if ( style,
nsnull vs. 0, useless variable elimination, tortured control flow,
AutoString instead of String, and gratuitous ; after nsISupportsUtils.h
macro call cleanups.
2001-08-22 00:51:34 +04:00
|
|
|
return NS_OK;
|
1999-11-08 00:55:12 +03:00
|
|
|
}
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsIDownloadObserver
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
1999-11-08 00:55:12 +03:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARChannel::OnDownloadComplete(nsIDownloader *downloader,
|
2003-06-24 02:58:28 +04:00
|
|
|
nsresult status,
|
|
|
|
nsIFile *file)
|
1999-11-08 00:55:12 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
if (NS_SUCCEEDED(status)) {
|
|
|
|
mJarFile = file;
|
|
|
|
|
2003-06-24 02:58:28 +04:00
|
|
|
nsresult rv = CreateJarInput(nsnull);
|
2003-01-18 05:15:14 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// create input stream pump
|
|
|
|
rv = NS_NewInputStreamPump(getter_AddRefs(mPump), mJarInput);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = mPump->AsyncRead(this, nsnull);
|
|
|
|
}
|
|
|
|
status = rv;
|
2001-09-15 01:19:41 +04:00
|
|
|
}
|
2003-01-18 05:15:14 +03:00
|
|
|
|
|
|
|
if (NS_FAILED(status)) {
|
|
|
|
OnStartRequest(nsnull, nsnull);
|
|
|
|
OnStopRequest(nsnull, nsnull, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-11-08 00:55:12 +03:00
|
|
|
}
|
2003-01-18 05:15:14 +03:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsIStreamListener
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
1999-11-08 00:55:12 +03:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARChannel::OnStartRequest(nsIRequest *req, nsISupports *ctx)
|
1999-11-08 00:55:12 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("nsJARChannel::OnStartRequest [this=%x %s]\n", this, mSpec.get()));
|
|
|
|
|
|
|
|
return mListener->OnStartRequest(this, mListenerContext);
|
1999-11-08 00:55:12 +03:00
|
|
|
}
|
|
|
|
|
2000-04-13 13:20:50 +04:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARChannel::OnStopRequest(nsIRequest *req, nsISupports *ctx, nsresult status)
|
2000-04-13 13:20:50 +04:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("nsJARChannel::OnStopRequest [this=%x %s status=%x]\n",
|
|
|
|
this, mSpec.get(), status));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(mStatus))
|
|
|
|
mStatus = status;
|
|
|
|
|
|
|
|
if (mListener) {
|
|
|
|
mListener->OnStopRequest(this, mListenerContext, status);
|
|
|
|
mListener = 0;
|
|
|
|
mListenerContext = 0;
|
|
|
|
}
|
2000-04-13 13:20:50 +04:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
if (mLoadGroup)
|
|
|
|
mLoadGroup->RemoveRequest(this, nsnull, status);
|
|
|
|
|
|
|
|
mPump = 0;
|
|
|
|
NS_IF_RELEASE(mJarInput);
|
|
|
|
mIsPending = PR_FALSE;
|
2003-06-24 02:58:28 +04:00
|
|
|
mDownloader = 0; // this may delete the underlying jar file
|
2003-01-18 05:15:14 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-11-08 00:55:12 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARChannel::OnDataAvailable(nsIRequest *req, nsISupports *ctx,
|
|
|
|
nsIInputStream *stream,
|
|
|
|
PRUint32 offset, PRUint32 count)
|
1999-11-08 00:55:12 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
#if defined(PR_LOGGING)
|
|
|
|
LOG(("nsJARChannel::OnDataAvailable [this=%x %s]\n", this, mSpec.get()));
|
|
|
|
#endif
|
1999-11-08 00:55:12 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
rv = mListener->OnDataAvailable(this, mListenerContext, stream, offset, count);
|
|
|
|
|
|
|
|
// simply report progress here instead of hooking ourselves up as a
|
|
|
|
// nsITransportEventSink implementation.
|
|
|
|
if (mProgressSink && NS_SUCCEEDED(rv) && !(mLoadFlags & LOAD_BACKGROUND))
|
|
|
|
mProgressSink->OnProgress(this, nsnull, offset + count, mContentLength);
|
|
|
|
|
|
|
|
return rv; // let the pump cancel on failure
|
|
|
|
}
|