Compare commits
10 Commits
linkclickf
...
http11_tmp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff633f8d60 | ||
|
|
22361789fb | ||
|
|
9c456185f6 | ||
|
|
b36ebbf0e0 | ||
|
|
49f393c539 | ||
|
|
65fc46a090 | ||
|
|
28927614a1 | ||
|
|
0a0b6a0cd3 | ||
|
|
193207cbf5 | ||
|
|
4da7d69865 |
@@ -28,7 +28,6 @@ include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = necko
|
||||
LIBRARY_NAME = necko_datetime
|
||||
SHORT_LIBNAME = neckodtm
|
||||
IS_COMPONENT = 1
|
||||
|
||||
CPPSRCS = \
|
||||
|
||||
@@ -44,12 +44,20 @@ nsDateTimeChannel::~nsDateTimeChannel() {
|
||||
NS_IMPL_ISUPPORTS4(nsDateTimeChannel, nsIChannel, nsIRequest, nsIStreamListener, nsIStreamObserver)
|
||||
|
||||
nsresult
|
||||
nsDateTimeChannel::Init(nsIURI* uri)
|
||||
nsDateTimeChannel::Init(const char* verb,
|
||||
nsIURI* uri,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
NS_ASSERTION(uri, "no uri");
|
||||
|
||||
mOriginalURI = originalURI ? originalURI : uri;
|
||||
mUrl = uri;
|
||||
|
||||
rv = mUrl->GetPort(&mPort);
|
||||
@@ -61,6 +69,13 @@ nsDateTimeChannel::Init(nsIURI* uri)
|
||||
|
||||
if (!*(const char *)mHost) return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
rv = SetLoadAttributes(loadAttributes);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = SetLoadGroup(aLoadGroup);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = SetNotificationCallbacks(notificationCallbacks);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -82,35 +97,24 @@ nsDateTimeChannel::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::IsPending(PRBool *result)
|
||||
{
|
||||
NS_NOTREACHED("nsDateTimeChannel::IsPending");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::GetStatus(nsresult *status)
|
||||
nsDateTimeChannel::Cancel(void)
|
||||
{
|
||||
*status = NS_OK;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::Cancel(nsresult status)
|
||||
{
|
||||
NS_NOTREACHED("nsDateTimeChannel::Cancel");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::Suspend(void)
|
||||
{
|
||||
NS_NOTREACHED("nsDateTimeChannel::Suspend");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::Resume(void)
|
||||
{
|
||||
NS_NOTREACHED("nsDateTimeChannel::Resume");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@@ -118,22 +122,15 @@ nsDateTimeChannel::Resume(void)
|
||||
// nsIChannel methods:
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::GetOriginalURI(nsIURI* *aURI)
|
||||
nsDateTimeChannel::GetOriginalURI(nsIURI * *aURI)
|
||||
{
|
||||
*aURI = mOriginalURI ? mOriginalURI : mUrl;
|
||||
*aURI = mOriginalURI;
|
||||
NS_ADDREF(*aURI);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::SetOriginalURI(nsIURI* aURI)
|
||||
{
|
||||
mOriginalURI = aURI;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::GetURI(nsIURI* *aURI)
|
||||
nsDateTimeChannel::GetURI(nsIURI * *aURI)
|
||||
{
|
||||
*aURI = mUrl;
|
||||
NS_IF_ADDREF(*aURI);
|
||||
@@ -141,14 +138,8 @@ nsDateTimeChannel::GetURI(nsIURI* *aURI)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::SetURI(nsIURI* aURI)
|
||||
{
|
||||
mUrl = aURI;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::OpenInputStream(nsIInputStream **_retval)
|
||||
nsDateTimeChannel::OpenInputStream(PRUint32 startPosition, PRInt32 readCount,
|
||||
nsIInputStream **_retval)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
@@ -162,13 +153,12 @@ nsDateTimeChannel::OpenInputStream(nsIInputStream **_retval)
|
||||
rv = channel->SetNotificationCallbacks(mCallbacks);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return channel->OpenInputStream(_retval);
|
||||
return channel->OpenInputStream(startPosition, readCount, _retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::OpenOutputStream(nsIOutputStream **_retval)
|
||||
nsDateTimeChannel::OpenOutputStream(PRUint32 startPosition, nsIOutputStream **_retval)
|
||||
{
|
||||
NS_NOTREACHED("nsDateTimeChannel::OpenOutputStream");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@@ -191,8 +181,9 @@ nsDateTimeChannel::AsyncOpen(nsIStreamObserver *observer, nsISupports* ctxt)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::AsyncRead(nsIStreamListener *aListener,
|
||||
nsISupports *ctxt)
|
||||
nsDateTimeChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
|
||||
nsISupports *ctxt,
|
||||
nsIStreamListener *aListener)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
@@ -208,15 +199,16 @@ nsDateTimeChannel::AsyncRead(nsIStreamListener *aListener,
|
||||
|
||||
mListener = aListener;
|
||||
|
||||
return channel->AsyncRead(this, ctxt);
|
||||
return channel->AsyncRead(startPosition, readCount, ctxt, this);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::AsyncWrite(nsIInputStream *fromStream,
|
||||
nsIStreamObserver *observer,
|
||||
nsISupports *ctxt)
|
||||
PRUint32 startPosition,
|
||||
PRInt32 writeCount,
|
||||
nsISupports *ctxt,
|
||||
nsIStreamObserver *observer)
|
||||
{
|
||||
NS_NOTREACHED("nsDateTimeChannel::AsyncWrite");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@@ -260,90 +252,6 @@ nsDateTimeChannel::GetContentLength(PRInt32 *aContentLength)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::SetContentLength(PRInt32 aContentLength)
|
||||
{
|
||||
NS_NOTREACHED("nsDateTimeChannel::SetContentLength");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::GetTransferOffset(PRUint32 *aTransferOffset)
|
||||
{
|
||||
NS_NOTREACHED("nsDateTimeChannel::GetTransferOffset");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::SetTransferOffset(PRUint32 aTransferOffset)
|
||||
{
|
||||
NS_NOTREACHED("nsDateTimeChannel::SetTransferOffset");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::GetTransferCount(PRInt32 *aTransferCount)
|
||||
{
|
||||
NS_NOTREACHED("nsDateTimeChannel::GetTransferCount");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::SetTransferCount(PRInt32 aTransferCount)
|
||||
{
|
||||
NS_NOTREACHED("nsDateTimeChannel::SetTransferCount");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::GetBufferSegmentSize(PRUint32 *aBufferSegmentSize)
|
||||
{
|
||||
NS_NOTREACHED("nsDateTimeChannel::GetBufferSegmentSize");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::SetBufferSegmentSize(PRUint32 aBufferSegmentSize)
|
||||
{
|
||||
NS_NOTREACHED("nsDateTimeChannel::SetBufferSegmentSize");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::GetBufferMaxSize(PRUint32 *aBufferMaxSize)
|
||||
{
|
||||
NS_NOTREACHED("nsDateTimeChannel::GetBufferMaxSize");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::SetBufferMaxSize(PRUint32 aBufferMaxSize)
|
||||
{
|
||||
NS_NOTREACHED("nsDateTimeChannel::SetBufferMaxSize");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::GetShouldCache(PRBool *aShouldCache)
|
||||
{
|
||||
*aShouldCache = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::GetPipeliningAllowed(PRBool *aPipeliningAllowed)
|
||||
{
|
||||
*aPipeliningAllowed = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::SetPipeliningAllowed(PRBool aPipeliningAllowed)
|
||||
{
|
||||
NS_NOTREACHED("SetPipeliningAllowed");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup)
|
||||
{
|
||||
@@ -395,12 +303,6 @@ nsDateTimeChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotification
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
|
||||
{
|
||||
*aSecurityInfo = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsIStreamObserver methods
|
||||
NS_IMETHODIMP
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#ifndef nsDateTimeChannel_h___
|
||||
#define nsDateTimeChannel_h___
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsString2.h"
|
||||
#include "nsILoadGroup.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
@@ -55,7 +55,14 @@ public:
|
||||
static NS_METHOD
|
||||
Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult);
|
||||
|
||||
nsresult Init(nsIURI* uri);
|
||||
nsresult Init(const char* verb,
|
||||
nsIURI* uri,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize);
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
|
||||
|
||||
@@ -95,7 +95,14 @@ nsDateTimeHandler::NewURI(const char *aSpec, nsIURI *aBaseURI,
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeHandler::NewChannel(nsIURI* url, nsIChannel* *result)
|
||||
nsDateTimeHandler::NewChannel(const char* verb, nsIURI* url,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize,
|
||||
nsIChannel* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
@@ -103,7 +110,8 @@ nsDateTimeHandler::NewChannel(nsIURI* url, nsIChannel* *result)
|
||||
rv = nsDateTimeChannel::Create(nsnull, NS_GET_IID(nsIChannel), (void**)&channel);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = channel->Init(url);
|
||||
rv = channel->Init(verb, url, aLoadGroup, notificationCallbacks,
|
||||
loadAttributes, originalURI, bufferSegmentSize, bufferMaxSize);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(channel);
|
||||
return rv;
|
||||
|
||||
@@ -37,11 +37,10 @@ static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
|
||||
#define BUFFER_MAX_SIZE (64*1024)
|
||||
|
||||
// nsFingerChannel methods
|
||||
nsFingerChannel::nsFingerChannel()
|
||||
: mContentLength(-1),
|
||||
mActAsObserver(PR_TRUE),
|
||||
mPort(-1),
|
||||
mStatus(NS_OK)
|
||||
nsFingerChannel::nsFingerChannel():
|
||||
mContentLength(-1),
|
||||
mActAsObserver(PR_TRUE),
|
||||
mPort(-1)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
@@ -49,23 +48,30 @@ nsFingerChannel::nsFingerChannel()
|
||||
nsFingerChannel::~nsFingerChannel() {
|
||||
}
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS4(nsFingerChannel, nsIChannel, nsIRequest,
|
||||
nsIStreamListener, nsIStreamObserver)
|
||||
NS_IMPL_ISUPPORTS4(nsFingerChannel, nsIChannel, nsIRequest,
|
||||
nsIStreamListener, nsIStreamObserver)
|
||||
|
||||
nsresult
|
||||
nsFingerChannel::Init(nsIURI* uri)
|
||||
nsFingerChannel::Init(const char* verb,
|
||||
nsIURI* uri,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize)
|
||||
{
|
||||
nsresult rv;
|
||||
nsXPIDLCString autoBuffer;
|
||||
|
||||
NS_ASSERTION(uri, "no uri");
|
||||
|
||||
mOriginalURI = originalURI ? originalURI : uri;
|
||||
mUrl = uri;
|
||||
|
||||
// For security reasons, we do not allow the user to specify a
|
||||
// non-default port for finger: URL's.
|
||||
|
||||
mPort = FINGER_PORT;
|
||||
rv = mUrl->GetPort(&mPort);
|
||||
if (NS_FAILED(rv) || mPort < 1)
|
||||
mPort = FINGER_PORT;
|
||||
|
||||
rv = mUrl->GetPath(getter_Copies(autoBuffer)); // autoBuffer = user@host
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
@@ -94,10 +100,17 @@ nsFingerChannel::Init(nsIURI* uri)
|
||||
|
||||
#ifdef DEBUG_bryner
|
||||
printf("Status:mUser = %s, mHost = %s\n", (const char*)mUser,
|
||||
(const char*)mHost);
|
||||
(const char*)mHost);
|
||||
#endif
|
||||
if (!*(const char *)mHost) return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
rv = SetLoadAttributes(loadAttributes);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = SetLoadGroup(aLoadGroup);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = SetNotificationCallbacks(notificationCallbacks);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -119,40 +132,24 @@ nsFingerChannel::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult)
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::IsPending(PRBool *result)
|
||||
{
|
||||
NS_NOTREACHED("nsFingerChannel::IsPending");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::GetStatus(nsresult *status)
|
||||
nsFingerChannel::Cancel(void)
|
||||
{
|
||||
*status = mStatus;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::Cancel(nsresult status)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
mStatus = status;
|
||||
if (mTransport) {
|
||||
rv = mTransport->Cancel(status);
|
||||
}
|
||||
return rv;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::Suspend(void)
|
||||
{
|
||||
NS_NOTREACHED("nsFingerChannel::Suspend");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::Resume(void)
|
||||
{
|
||||
NS_NOTREACHED("nsFingerChannel::Resume");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@@ -160,22 +157,15 @@ nsFingerChannel::Resume(void)
|
||||
// nsIChannel methods:
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::GetOriginalURI(nsIURI* *aURI)
|
||||
nsFingerChannel::GetOriginalURI(nsIURI * *aURI)
|
||||
{
|
||||
*aURI = mOriginalURI ? mOriginalURI : mUrl;
|
||||
*aURI = mOriginalURI;
|
||||
NS_ADDREF(*aURI);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::SetOriginalURI(nsIURI* aURI)
|
||||
{
|
||||
mOriginalURI = aURI;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::GetURI(nsIURI* *aURI)
|
||||
nsFingerChannel::GetURI(nsIURI * *aURI)
|
||||
{
|
||||
*aURI = mUrl;
|
||||
NS_IF_ADDREF(*aURI);
|
||||
@@ -183,14 +173,8 @@ nsFingerChannel::GetURI(nsIURI* *aURI)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::SetURI(nsIURI* aURI)
|
||||
{
|
||||
mUrl = aURI;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::OpenInputStream(nsIInputStream **_retval)
|
||||
nsFingerChannel::OpenInputStream(PRUint32 startPosition, PRInt32 readCount,
|
||||
nsIInputStream **_retval)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
@@ -205,24 +189,38 @@ nsFingerChannel::OpenInputStream(nsIInputStream **_retval)
|
||||
rv = channel->SetNotificationCallbacks(mCallbacks);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return channel->OpenInputStream(_retval);
|
||||
return channel->OpenInputStream(startPosition, readCount, _retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::OpenOutputStream(nsIOutputStream **_retval)
|
||||
nsFingerChannel::OpenOutputStream(PRUint32 startPosition, nsIOutputStream **_retval)
|
||||
{
|
||||
NS_NOTREACHED("nsFingerChannel::OpenOutputStream");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::AsyncOpen(nsIStreamObserver *observer, nsISupports* ctxt)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
NS_WITH_SERVICE(nsISocketTransportService, socketService, kSocketTransportServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
rv = socketService->CreateTransport(mHost, mPort, mHost, BUFFER_SEG_SIZE,
|
||||
BUFFER_MAX_SIZE, getter_AddRefs(channel));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = channel->SetNotificationCallbacks(mCallbacks);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return channel->AsyncOpen(observer, ctxt);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::AsyncRead(nsIStreamListener *aListener, nsISupports *ctxt)
|
||||
nsFingerChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
|
||||
nsISupports *ctxt,
|
||||
nsIStreamListener *aListener)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
@@ -238,18 +236,17 @@ nsFingerChannel::AsyncRead(nsIStreamListener *aListener, nsISupports *ctxt)
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
mListener = aListener;
|
||||
mResponseContext = ctxt;
|
||||
mTransport = channel;
|
||||
|
||||
return SendRequest(channel);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::AsyncWrite(nsIInputStream *fromStream,
|
||||
nsIStreamObserver *observer,
|
||||
nsISupports *ctxt)
|
||||
PRUint32 startPosition,
|
||||
PRInt32 writeCount,
|
||||
nsISupports *ctxt,
|
||||
nsIStreamObserver *observer)
|
||||
{
|
||||
NS_NOTREACHED("nsFingerChannel::AsyncWrite");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@@ -293,90 +290,6 @@ nsFingerChannel::GetContentLength(PRInt32 *aContentLength)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::SetContentLength(PRInt32 aContentLength)
|
||||
{
|
||||
NS_NOTREACHED("nsFingerChannel::SetContentLength");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::GetTransferOffset(PRUint32 *aTransferOffset)
|
||||
{
|
||||
NS_NOTREACHED("nsFingerChannel::GetTransferOffset");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::SetTransferOffset(PRUint32 aTransferOffset)
|
||||
{
|
||||
NS_NOTREACHED("nsFingerChannel::SetTransferOffset");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::GetTransferCount(PRInt32 *aTransferCount)
|
||||
{
|
||||
NS_NOTREACHED("nsFingerChannel::GetTransferCount");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::SetTransferCount(PRInt32 aTransferCount)
|
||||
{
|
||||
NS_NOTREACHED("nsFingerChannel::SetTransferCount");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::GetBufferSegmentSize(PRUint32 *aBufferSegmentSize)
|
||||
{
|
||||
NS_NOTREACHED("nsFingerChannel::GetBufferSegmentSize");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::SetBufferSegmentSize(PRUint32 aBufferSegmentSize)
|
||||
{
|
||||
NS_NOTREACHED("nsFingerChannel::SetBufferSegmentSize");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::GetBufferMaxSize(PRUint32 *aBufferMaxSize)
|
||||
{
|
||||
NS_NOTREACHED("nsFingerChannel::GetBufferMaxSize");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::SetBufferMaxSize(PRUint32 aBufferMaxSize)
|
||||
{
|
||||
NS_NOTREACHED("nsFingerChannel::SetBufferMaxSize");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::GetShouldCache(PRBool *aShouldCache)
|
||||
{
|
||||
*aShouldCache = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::GetPipeliningAllowed(PRBool *aPipeliningAllowed)
|
||||
{
|
||||
*aPipeliningAllowed = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::SetPipeliningAllowed(PRBool aPipeliningAllowed)
|
||||
{
|
||||
NS_NOTREACHED("SetPipeliningAllowed");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup)
|
||||
{
|
||||
@@ -388,7 +301,13 @@ nsFingerChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup)
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::SetLoadGroup(nsILoadGroup* aLoadGroup)
|
||||
{
|
||||
if (mLoadGroup) // if we already had a load group remove ourselves...
|
||||
(void)mLoadGroup->RemoveChannel(this, nsnull, nsnull, nsnull);
|
||||
|
||||
mLoadGroup = aLoadGroup;
|
||||
if (mLoadGroup) {
|
||||
return mLoadGroup->AddChannel(this, nsnull);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -422,12 +341,6 @@ nsFingerChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCa
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
|
||||
{
|
||||
*aSecurityInfo = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsIStreamObserver methods
|
||||
NS_IMETHODIMP
|
||||
@@ -453,20 +366,18 @@ nsFingerChannel::OnStopRequest(nsIChannel* aChannel, nsISupports* aContext,
|
||||
#endif
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (NS_FAILED(aStatus) || !mActAsObserver) {
|
||||
if (!mActAsObserver) {
|
||||
if (mLoadGroup) {
|
||||
rv = mLoadGroup->RemoveChannel(this, nsnull, aStatus, aMsg);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
rv = mListener->OnStopRequest(this, aContext, aStatus, aMsg);
|
||||
mTransport = 0;
|
||||
return rv;
|
||||
return mListener->OnStopRequest(this, aContext, aStatus, aMsg);
|
||||
} else {
|
||||
// at this point we know the request has been sent.
|
||||
// we're no longer acting as an observer.
|
||||
|
||||
mActAsObserver = PR_FALSE;
|
||||
return aChannel->AsyncRead(this, mResponseContext);
|
||||
return aChannel->AsyncRead(0, -1, 0, this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -490,10 +401,6 @@ nsFingerChannel::SendRequest(nsIChannel* aChannel) {
|
||||
nsCOMPtr<nsIInputStream> charstream;
|
||||
nsCString requestBuffer(mUser);
|
||||
|
||||
if (mLoadGroup) {
|
||||
mLoadGroup->AddChannel(this, nsnull);
|
||||
}
|
||||
|
||||
requestBuffer.Append(CRLF);
|
||||
|
||||
mRequest = requestBuffer.ToNewCString();
|
||||
@@ -508,9 +415,8 @@ nsFingerChannel::SendRequest(nsIChannel* aChannel) {
|
||||
printf("Sending: %s\n", requestBuffer.GetBuffer());
|
||||
#endif
|
||||
|
||||
rv = aChannel->SetTransferCount(requestBuffer.Length());
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = aChannel->AsyncWrite(charstream, this, 0);
|
||||
rv = aChannel->AsyncWrite(charstream, 0, requestBuffer.Length(), 0,
|
||||
this);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#ifndef nsFingerChannel_h___
|
||||
#define nsFingerChannel_h___
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsString2.h"
|
||||
#include "nsILoadGroup.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
@@ -51,7 +51,14 @@ public:
|
||||
static NS_METHOD
|
||||
Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult);
|
||||
|
||||
nsresult Init(nsIURI* uri);
|
||||
nsresult Init(const char* verb,
|
||||
nsIURI* uri,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize);
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
|
||||
@@ -73,10 +80,6 @@ protected:
|
||||
|
||||
nsXPIDLCString mRequest;
|
||||
|
||||
nsCOMPtr<nsISupports> mResponseContext;
|
||||
nsCOMPtr<nsIChannel> mTransport;
|
||||
nsresult mStatus;
|
||||
|
||||
protected:
|
||||
nsresult SendRequest(nsIChannel* aChannel);
|
||||
};
|
||||
|
||||
@@ -95,7 +95,14 @@ nsFingerHandler::NewURI(const char *aSpec, nsIURI *aBaseURI,
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerHandler::NewChannel(nsIURI* url, nsIChannel* *result)
|
||||
nsFingerHandler::NewChannel(const char* verb, nsIURI* url,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize,
|
||||
nsIChannel* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
@@ -103,7 +110,8 @@ nsFingerHandler::NewChannel(nsIURI* url, nsIChannel* *result)
|
||||
rv = nsFingerChannel::Create(nsnull, NS_GET_IID(nsIChannel), (void**)&channel);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = channel->Init(url);
|
||||
rv = channel->Init(verb, url, aLoadGroup, notificationCallbacks,
|
||||
loadAttributes, originalURI, bufferSegmentSize, bufferMaxSize);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(channel);
|
||||
return rv;
|
||||
|
||||
@@ -28,31 +28,13 @@
|
||||
#include "nsIMIMEService.h"
|
||||
#include "nsAutoLock.h"
|
||||
#include "nsIFileStreams.h"
|
||||
#include "nsIPrincipal.h"
|
||||
#include "nsMimeTypes.h"
|
||||
#include "nsScriptSecurityManager.h"
|
||||
#include "nsIAggregatePrincipal.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(kScriptSecurityManagerCID, NS_SCRIPTSECURITYMANAGER_CID);
|
||||
|
||||
#if defined(PR_LOGGING)
|
||||
#include "nsXPIDLString.h"
|
||||
//
|
||||
// Log module for SocketTransport logging...
|
||||
//
|
||||
// To enable logging (see prlog.h for full details):
|
||||
//
|
||||
// set NSPR_LOG_MODULES=nsJarProtocol:5
|
||||
// set NSPR_LOG_FILE=nspr.log
|
||||
//
|
||||
// this enables PR_LOG_DEBUG level information and places all output in
|
||||
// the file nspr.log
|
||||
//
|
||||
PRLogModuleInfo* gJarProtocolLog = nsnull;
|
||||
|
||||
#endif /* PR_LOGGING */
|
||||
static NS_DEFINE_CID(kFileChannelCID, NS_FILECHANNEL_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -73,57 +55,35 @@ public:
|
||||
nsresult rv = NS_OK;
|
||||
nsAutoMonitor monitor(mJARChannel->mMonitor);
|
||||
|
||||
#ifdef PR_LOGGING
|
||||
nsCOMPtr<nsIURI> jarURI;
|
||||
rv = jarCacheTransport->GetURI(getter_AddRefs(jarURI));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsXPIDLCString jarURLStr;
|
||||
rv = jarURI->GetSpec(getter_Copies(jarURLStr));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
PR_LOG(gJarProtocolLog, PR_LOG_DEBUG,
|
||||
("nsJarProtocol: jar download complete %s status=%x",
|
||||
(const char*)jarURLStr, status));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (NS_SUCCEEDED(status) && mJARChannel->mJarCacheTransport) {
|
||||
NS_ASSERTION(jarCacheTransport == (mJARChannel->mJarCacheTransport).get(),
|
||||
"wrong transport");
|
||||
// after successfully downloading the jar file to the cache,
|
||||
// start the extraction process:
|
||||
nsCOMPtr<nsIFileChannel> jarCacheFile;
|
||||
rv = NS_NewLocalFileChannel(getter_AddRefs(jarCacheFile),
|
||||
mJarCacheFile,
|
||||
PR_RDONLY,
|
||||
0);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = jarCacheFile->SetLoadGroup(mJARChannel->mLoadGroup);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = jarCacheFile->SetBufferSegmentSize(mJARChannel->mBufferSegmentSize);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = jarCacheFile->SetBufferMaxSize(mJARChannel->mBufferMaxSize);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = jarCacheFile->SetLoadAttributes(mJARChannel->mLoadAttributes);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = jarCacheFile->SetNotificationCallbacks(mJARChannel->mCallbacks);
|
||||
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;
|
||||
|
||||
mJARChannel->SetJARBaseFile(jarCacheFile);
|
||||
rv = mOnJARFileAvailable(mJARChannel, mClosure);
|
||||
rv = mJARChannel->ExtractJARElement(jarCacheFile);
|
||||
}
|
||||
mJARChannel->mJarCacheTransport = nsnull;
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsJARDownloadObserver(nsIFile* jarCacheFile, nsJARChannel* jarChannel,
|
||||
OnJARFileAvailableFun onJARFileAvailable,
|
||||
void* closure)
|
||||
: mJarCacheFile(jarCacheFile),
|
||||
mJARChannel(jarChannel),
|
||||
mOnJARFileAvailable(onJARFileAvailable),
|
||||
mClosure(closure)
|
||||
{
|
||||
nsJARDownloadObserver(nsIFile* jarCacheFile, nsJARChannel* jarChannel) {
|
||||
NS_INIT_REFCNT();
|
||||
mJarCacheFile = jarCacheFile;
|
||||
mJARChannel = jarChannel;
|
||||
NS_ADDREF(mJARChannel);
|
||||
}
|
||||
|
||||
@@ -132,41 +92,27 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIFile> mJarCacheFile;
|
||||
nsJARChannel* mJARChannel;
|
||||
OnJARFileAvailableFun mOnJARFileAvailable;
|
||||
void* mClosure;
|
||||
nsCOMPtr<nsIFile> mJarCacheFile;
|
||||
nsJARChannel* mJARChannel;
|
||||
};
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsJARDownloadObserver, nsIStreamObserver)
|
||||
NS_IMPL_ISUPPORTS1(nsJARDownloadObserver, nsIStreamObserver)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsJARChannel::nsJARChannel()
|
||||
: mContentType(nsnull),
|
||||
mContentLength(-1),
|
||||
mLoadAttributes(LOAD_NORMAL),
|
||||
mStartPosition(0),
|
||||
mReadCount(-1),
|
||||
: mCommand(nsnull),
|
||||
mContentType(nsnull),
|
||||
mJAREntry(nsnull),
|
||||
mMonitor(nsnull),
|
||||
mStatus(NS_OK)
|
||||
mMonitor(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
#if defined(PR_LOGGING)
|
||||
//
|
||||
// Initialize the global PRLogModule for socket transport logging
|
||||
// if necessary...
|
||||
//
|
||||
if (nsnull == gJarProtocolLog) {
|
||||
gJarProtocolLog = PR_NewLogModule("nsJarProtocol");
|
||||
}
|
||||
#endif /* PR_LOGGING */
|
||||
}
|
||||
|
||||
nsJARChannel::~nsJARChannel()
|
||||
{
|
||||
if (mCommand)
|
||||
nsCRT::free(mCommand);
|
||||
if (mContentType)
|
||||
nsCRT::free(mContentType);
|
||||
if (mJAREntry)
|
||||
@@ -202,10 +148,33 @@ nsJARChannel::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJARChannel::Init(nsIJARProtocolHandler* aHandler, nsIURI* uri)
|
||||
nsJARChannel::Init(nsIJARProtocolHandler* aHandler,
|
||||
const char* command,
|
||||
nsIURI* uri,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize)
|
||||
{
|
||||
nsresult rv;
|
||||
mURI = do_QueryInterface(uri, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
mCommand = nsCRT::strdup(command);
|
||||
if (mCommand == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
mOriginalURI = originalURI ? originalURI : uri;
|
||||
mBufferSegmentSize = bufferSegmentSize;
|
||||
mBufferMaxSize = bufferMaxSize;
|
||||
|
||||
rv = SetLoadAttributes(loadAttributes);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = SetLoadGroup(aLoadGroup);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = SetNotificationCallbacks(notificationCallbacks);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
mMonitor = PR_NewMonitor();
|
||||
@@ -221,35 +190,27 @@ nsJARChannel::Init(nsIJARProtocolHandler* aHandler, nsIURI* uri)
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::IsPending(PRBool* result)
|
||||
{
|
||||
NS_NOTREACHED("nsJARChannel::IsPending");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::GetStatus(nsresult *status)
|
||||
{
|
||||
*status = mStatus;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::Cancel(nsresult status)
|
||||
nsJARChannel::Cancel()
|
||||
{
|
||||
nsresult rv;
|
||||
nsAutoMonitor monitor(mMonitor);
|
||||
|
||||
if (mJarCacheTransport) {
|
||||
rv = mJarCacheTransport->Cancel(status);
|
||||
rv = mJarCacheTransport->Cancel();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
mJarCacheTransport = nsnull;
|
||||
}
|
||||
if (mJarExtractionTransport) {
|
||||
rv = mJarExtractionTransport->Cancel(status);
|
||||
rv = mJarExtractionTransport->Cancel();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
mJarExtractionTransport = nsnull;
|
||||
}
|
||||
mStatus = status;
|
||||
return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@@ -294,18 +255,11 @@ nsJARChannel::Resume()
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::GetOriginalURI(nsIURI* *aOriginalURI)
|
||||
{
|
||||
*aOriginalURI = mOriginalURI ? mOriginalURI : nsCOMPtr<nsIURI>(mURI);
|
||||
*aOriginalURI = mOriginalURI;
|
||||
NS_ADDREF(*aOriginalURI);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::SetOriginalURI(nsIURI* aOriginalURI)
|
||||
{
|
||||
mOriginalURI = aOriginalURI;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::GetURI(nsIURI* *aURI)
|
||||
{
|
||||
@@ -315,82 +269,30 @@ nsJARChannel::GetURI(nsIURI* *aURI)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::SetURI(nsIURI* aURI)
|
||||
nsJARChannel::OpenInputStream(PRUint32 startPosition, PRInt32 readCount,
|
||||
nsIInputStream* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
mURI = do_QueryInterface(aURI, &rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
static nsresult
|
||||
OpenJARElement(nsJARChannel* channel, void* closure)
|
||||
{
|
||||
nsresult rv;
|
||||
nsIInputStream* *result = (nsIInputStream**)closure;
|
||||
nsAutoCMonitor mon(channel);
|
||||
rv = channel->Open(nsnull, nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = channel->GetInputStream(result);
|
||||
mon.Notify(); // wake up OpenInputStream
|
||||
return rv;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::OpenInputStream(nsIInputStream* *result)
|
||||
nsJARChannel::OpenOutputStream(PRUint32 startPosition, nsIOutputStream* *result)
|
||||
{
|
||||
nsAutoCMonitor mon(this);
|
||||
nsresult rv;
|
||||
*result = nsnull;
|
||||
rv = EnsureJARFileAvailable(OpenJARElement, result);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (*result == nsnull)
|
||||
mon.Wait();
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::OpenOutputStream(nsIOutputStream* *result)
|
||||
{
|
||||
NS_NOTREACHED("nsJARChannel::OpenOutputStream");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::AsyncOpen(nsIStreamObserver* observer, nsISupports* ctxt)
|
||||
{
|
||||
NS_NOTREACHED("nsJARChannel::AsyncOpen");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
static nsresult
|
||||
ReadJARElement(nsJARChannel* channel, void* closure)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = channel->AsyncReadJARElement();
|
||||
return rv;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::AsyncRead(nsIStreamListener* listener, nsISupports* ctxt)
|
||||
{
|
||||
mUserContext = ctxt;
|
||||
mUserListener = listener;
|
||||
return EnsureJARFileAvailable(ReadJARElement, nsnull);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJARChannel::EnsureJARFileAvailable(OnJARFileAvailableFun onJARFileAvailable,
|
||||
void* closure)
|
||||
nsJARChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
|
||||
nsISupports* ctxt,
|
||||
nsIStreamListener* listener)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
#ifdef PR_LOGGING
|
||||
nsXPIDLCString jarURLStr;
|
||||
mURI->GetSpec(getter_Copies(jarURLStr));
|
||||
PR_LOG(gJarProtocolLog, PR_LOG_DEBUG,
|
||||
("nsJarProtocol: EnsureJARFileAvailable %s", (const char*)jarURLStr));
|
||||
#endif
|
||||
|
||||
rv = mURI->GetJARFile(getter_AddRefs(mJARBaseURI));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
@@ -398,28 +300,21 @@ nsJARChannel::EnsureJARFileAvailable(OnJARFileAvailableFun onJARFileAvailable,
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIChannel> jarBaseChannel;
|
||||
rv = NS_OpenURI(getter_AddRefs(jarBaseChannel), mJARBaseURI, nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = jarBaseChannel->SetLoadGroup(mLoadGroup);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = jarBaseChannel->SetLoadAttributes(mLoadAttributes);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = jarBaseChannel->SetNotificationCallbacks(mCallbacks);
|
||||
rv = NS_OpenURI(getter_AddRefs(jarBaseChannel),
|
||||
mJARBaseURI, mLoadGroup, mCallbacks, mLoadAttributes);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (mLoadGroup)
|
||||
(void)mLoadGroup->AddChannel(this, nsnull);
|
||||
nsCOMPtr<nsIFileChannel> jarBaseFile = do_QueryInterface(jarBaseChannel, &rv);
|
||||
|
||||
// mJARBaseFile = do_QueryInterface(jarBaseChannel, &rv);
|
||||
// XXX need to set a state variable here to say we're reading
|
||||
mStartPosition = startPosition;
|
||||
mReadCount = readCount;
|
||||
mUserContext = ctxt;
|
||||
mUserListener = listener;
|
||||
|
||||
PRBool shouldCache;
|
||||
rv = jarBaseChannel->GetShouldCache(&shouldCache);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && !shouldCache) {
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// then we've already got a local jar file -- no need to download it
|
||||
PR_LOG(gJarProtocolLog, PR_LOG_DEBUG,
|
||||
("nsJarProtocol: extracting local jar file %s", (const char*)jarURLStr));
|
||||
rv = onJARFileAvailable(this, closure);
|
||||
rv = ExtractJARElement(jarBaseFile);
|
||||
}
|
||||
else {
|
||||
// otherwise, we need to download the jar file
|
||||
@@ -435,19 +330,26 @@ nsJARChannel::EnsureJARFileAvailable(OnJARFileAvailableFun onJARFileAvailable,
|
||||
if (NS_SUCCEEDED(rv) && filePresent)
|
||||
{
|
||||
// then we've already got the file in the local cache -- no need to download it
|
||||
rv = NS_NewLocalFileChannel(getter_AddRefs(mJARBaseFile),
|
||||
jarCacheFile,
|
||||
PR_RDONLY,
|
||||
0);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = mJARBaseFile->SetBufferSegmentSize(mBufferSegmentSize);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = mJARBaseFile->SetBufferMaxSize(mBufferMaxSize);
|
||||
nsCOMPtr<nsIFileChannel> fileChannel;
|
||||
rv = nsComponentManager::CreateInstance(kFileChannelCID,
|
||||
nsnull,
|
||||
NS_GET_IID(nsIFileChannel),
|
||||
getter_AddRefs(fileChannel));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PR_LOG(gJarProtocolLog, PR_LOG_DEBUG,
|
||||
("nsJarProtocol: jar file already in cache %s", (const char*)jarURLStr));
|
||||
rv = onJARFileAvailable(this, closure);
|
||||
rv = fileChannel->Init(jarCacheFile,
|
||||
PR_RDONLY,
|
||||
nsnull, // contentType
|
||||
-1, // contentLength
|
||||
nsnull, // loadGroup
|
||||
nsnull, // notificationCallbacks
|
||||
nsIChannel::LOAD_NORMAL,
|
||||
nsnull, // originalURI
|
||||
mBufferSegmentSize,
|
||||
mBufferMaxSize);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = ExtractJARElement(fileChannel);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -459,29 +361,23 @@ nsJARChannel::EnsureJARFileAvailable(OnJARFileAvailableFun onJARFileAvailable,
|
||||
// use a file transport to serve as a data pump for the download (done
|
||||
// on some other thread)
|
||||
nsCOMPtr<nsIChannel> jarCacheTransport;
|
||||
rv = fts->CreateTransport(jarCacheFile, PR_RDONLY, 0,
|
||||
rv = fts->CreateTransport(jarCacheFile, PR_RDONLY, mCommand,
|
||||
mBufferSegmentSize, mBufferMaxSize,
|
||||
getter_AddRefs(mJarCacheTransport));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = mJarCacheTransport->SetBufferSegmentSize(mBufferSegmentSize);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = mJarCacheTransport->SetBufferMaxSize(mBufferMaxSize);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = mJarCacheTransport->SetNotificationCallbacks(mCallbacks);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIStreamObserver> downloadObserver =
|
||||
new nsJARDownloadObserver(jarCacheFile, this, onJARFileAvailable, closure);
|
||||
nsCOMPtr<nsIStreamObserver> downloadObserver = new nsJARDownloadObserver(jarCacheFile, this);
|
||||
if (downloadObserver == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
PR_LOG(gJarProtocolLog, PR_LOG_DEBUG,
|
||||
("nsJarProtocol: downloading jar file %s", (const char*)jarURLStr));
|
||||
nsCOMPtr<nsIInputStream> jarBaseIn;
|
||||
rv = jarBaseChannel->OpenInputStream(getter_AddRefs(jarBaseIn));
|
||||
rv = jarBaseChannel->OpenInputStream(0, -1, getter_AddRefs(jarBaseIn));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = mJarCacheTransport->AsyncWrite(jarBaseIn, nsnull, downloadObserver);
|
||||
rv = mJarCacheTransport->AsyncWrite(jarBaseIn, 0, -1, nsnull, downloadObserver);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
@@ -523,68 +419,36 @@ nsJARChannel::GetCacheFile(nsIFile* *cacheFile)
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJARChannel::AsyncReadJARElement()
|
||||
nsJARChannel::ExtractJARElement(nsIFileChannel* jarBaseFile)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsAutoMonitor monitor(mMonitor);
|
||||
|
||||
NS_ASSERTION(mJARBaseFile, "mJARBaseFile is null");
|
||||
|
||||
if (mLoadGroup) {
|
||||
nsCOMPtr<nsILoadGroupListenerFactory> factory;
|
||||
//
|
||||
// Create a load group "proxy" listener...
|
||||
//
|
||||
rv = mLoadGroup->GetGroupListenerFactory(getter_AddRefs(factory));
|
||||
if (factory) {
|
||||
nsIStreamListener *newListener;
|
||||
rv = factory->CreateLoadGroupListener(mUserListener, &newListener);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mUserListener = newListener;
|
||||
NS_RELEASE(newListener);
|
||||
}
|
||||
}
|
||||
|
||||
rv = mLoadGroup->AddChannel(this, nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
mJARBaseFile = jarBaseFile;
|
||||
|
||||
NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = fts->CreateTransportFromFileSystem(this,
|
||||
rv = fts->CreateTransportFromFileSystem(this, mCommand,
|
||||
mBufferSegmentSize, mBufferMaxSize,
|
||||
getter_AddRefs(mJarExtractionTransport));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = mJarExtractionTransport->SetBufferSegmentSize(mBufferSegmentSize);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = mJarExtractionTransport->SetBufferMaxSize(mBufferMaxSize);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = mJarExtractionTransport->SetNotificationCallbacks(mCallbacks);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
#ifdef PR_LOGGING
|
||||
nsXPIDLCString jarURLStr;
|
||||
mURI->GetSpec(getter_Copies(jarURLStr));
|
||||
PR_LOG(gJarProtocolLog, PR_LOG_DEBUG,
|
||||
("nsJarProtocol: AsyncRead jar entry %s", (const char*)jarURLStr));
|
||||
#endif
|
||||
rv = mJarExtractionTransport->SetTransferOffset(mStartPosition);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = mJarExtractionTransport->SetTransferCount(mReadCount);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = mJarExtractionTransport->AsyncRead(this, nsnull);
|
||||
rv = mJarExtractionTransport->AsyncRead(mStartPosition, mReadCount, nsnull, this);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::AsyncWrite(nsIInputStream* fromStream,
|
||||
nsIStreamObserver* observer,
|
||||
nsISupports* ctxt)
|
||||
nsJARChannel::AsyncWrite(nsIInputStream* fromStream, PRUint32 startPosition,
|
||||
PRInt32 writeCount,
|
||||
nsISupports* ctxt,
|
||||
nsIStreamObserver* observer)
|
||||
{
|
||||
NS_NOTREACHED("nsJARChannel::AsyncWrite");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@@ -672,93 +536,6 @@ nsJARChannel::GetContentLength(PRInt32* aContentLength)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::SetContentLength(PRInt32 aContentLength)
|
||||
{
|
||||
NS_NOTREACHED("nsJARChannel::SetContentLength");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::GetTransferOffset(PRUint32 *aTransferOffset)
|
||||
{
|
||||
*aTransferOffset = mStartPosition;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::SetTransferOffset(PRUint32 aTransferOffset)
|
||||
{
|
||||
mStartPosition = aTransferOffset;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::GetTransferCount(PRInt32 *aTransferCount)
|
||||
{
|
||||
*aTransferCount = mReadCount;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::SetTransferCount(PRInt32 aTransferCount)
|
||||
{
|
||||
mReadCount = aTransferCount;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::GetBufferSegmentSize(PRUint32 *aBufferSegmentSize)
|
||||
{
|
||||
*aBufferSegmentSize = mBufferSegmentSize;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::SetBufferSegmentSize(PRUint32 aBufferSegmentSize)
|
||||
{
|
||||
mBufferSegmentSize = aBufferSegmentSize;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::GetBufferMaxSize(PRUint32 *aBufferMaxSize)
|
||||
{
|
||||
*aBufferMaxSize = mBufferMaxSize;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::SetBufferMaxSize(PRUint32 aBufferMaxSize)
|
||||
{
|
||||
mBufferMaxSize = aBufferMaxSize;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::GetShouldCache(PRBool *aShouldCache)
|
||||
{
|
||||
// Jar files report that you shouldn't cache them because this is really
|
||||
// a question about the jar entry, and the jar entry is always in a jar
|
||||
// file on disk.
|
||||
*aShouldCache = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::GetPipeliningAllowed(PRBool *aPipeliningAllowed)
|
||||
{
|
||||
*aPipeliningAllowed = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::SetPipeliningAllowed(PRBool aPipeliningAllowed)
|
||||
{
|
||||
NS_NOTREACHED("SetPipeliningAllowed");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup)
|
||||
{
|
||||
@@ -777,45 +554,21 @@ nsJARChannel::SetLoadGroup(nsILoadGroup* aLoadGroup)
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::GetOwner(nsISupports* *aOwner)
|
||||
{
|
||||
if (!mOwner)
|
||||
{
|
||||
nsCOMPtr<nsIPrincipal> certificate;
|
||||
PRInt16 result;
|
||||
nsresult rv = mJAR->GetCertificatePrincipal(mJAREntry,
|
||||
getter_AddRefs(certificate),
|
||||
&result);
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
if (certificate)
|
||||
{ // Get the codebase principal
|
||||
NS_WITH_SERVICE(nsIScriptSecurityManager, secMan,
|
||||
kScriptSecurityManagerCID, &rv);
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
nsCOMPtr<nsIPrincipal> codebase;
|
||||
rv = secMan->GetCodebasePrincipal(mJARBaseURI,
|
||||
getter_AddRefs(codebase));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Join the certificate and the codebase
|
||||
nsCOMPtr<nsIAggregatePrincipal> agg;
|
||||
agg = do_QueryInterface(certificate, &rv);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv),
|
||||
"Certificate principal is not an aggregate");
|
||||
rv = agg->SetCodebase(codebase);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
mOwner = do_QueryInterface(agg, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
}
|
||||
*aOwner = mOwner;
|
||||
NS_IF_ADDREF(*aOwner);
|
||||
nsCOMPtr<nsIPrincipal> principal;
|
||||
nsresult rv = mJAR->GetPrincipal(mJAREntry, getter_AddRefs(principal));
|
||||
if (NS_SUCCEEDED(rv) && principal)
|
||||
rv = principal->QueryInterface(NS_GET_IID(nsISupports), (void **)aOwner);
|
||||
else
|
||||
*aOwner = nsnull;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::SetOwner(nsISupports* aOwner)
|
||||
{
|
||||
mOwner = aOwner;
|
||||
return NS_OK;
|
||||
//XXX: is this OK?
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@@ -833,12 +586,6 @@ nsJARChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCallb
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
|
||||
{
|
||||
*aSecurityInfo = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIStreamObserver methods:
|
||||
|
||||
@@ -856,26 +603,7 @@ nsJARChannel::OnStopRequest(nsIChannel* jarExtractionTransport,
|
||||
const PRUnichar* aMsg)
|
||||
{
|
||||
nsresult rv;
|
||||
#ifdef PR_LOGGING
|
||||
nsCOMPtr<nsIURI> jarURI;
|
||||
nsXPIDLCString jarURLStr;
|
||||
rv = mURI->GetSpec(getter_Copies(jarURLStr));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
PR_LOG(gJarProtocolLog, PR_LOG_DEBUG,
|
||||
("nsJarProtocol: jar extraction complete %s status=%x",
|
||||
(const char*)jarURLStr, status));
|
||||
}
|
||||
#endif
|
||||
rv = mUserListener->OnStopRequest(this, mUserContext, status, aMsg);
|
||||
|
||||
if (mLoadGroup) {
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mLoadGroup->RemoveChannel(this, context, status, aMsg);
|
||||
}
|
||||
}
|
||||
|
||||
mUserListener = nsnull;
|
||||
mUserContext = nsnull;
|
||||
mJarExtractionTransport = nsnull;
|
||||
return rv;
|
||||
}
|
||||
@@ -901,8 +629,6 @@ NS_IMETHODIMP
|
||||
nsJARChannel::Open(char* *contentType, PRInt32 *contentLength)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_ASSERTION(mJARBaseFile, "mJARBaseFile is null");
|
||||
|
||||
rv = nsComponentManager::CreateInstance(kZipReaderCID,
|
||||
nsnull,
|
||||
NS_GET_IID(nsIZipReader),
|
||||
@@ -926,16 +652,10 @@ nsJARChannel::Open(char* *contentType, PRInt32 *contentLength)
|
||||
rv = mJAR->GetEntry(mJAREntry, getter_AddRefs(entry));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (contentLength) {
|
||||
rv = entry->GetRealSize((PRUint32*)contentLength);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
rv = entry->GetRealSize((PRUint32*)contentLength);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (contentType) {
|
||||
rv = GetContentType(contentType);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
return rv;
|
||||
return GetContentType(contentType);
|
||||
}
|
||||
|
||||
|
||||
@@ -949,20 +669,13 @@ nsJARChannel::Close(nsresult status)
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::GetInputStream(nsIInputStream* *aInputStream)
|
||||
{
|
||||
#ifdef PR_LOGGING
|
||||
nsXPIDLCString jarURLStr;
|
||||
mURI->GetSpec(getter_Copies(jarURLStr));
|
||||
PR_LOG(gJarProtocolLog, PR_LOG_DEBUG,
|
||||
("nsJarProtocol: GetInputStream jar entry %s", (const char*)jarURLStr));
|
||||
#endif
|
||||
return mJAR->GetInputStream(mJAREntry, aInputStream);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::GetOutputStream(nsIOutputStream* *aOutputStream)
|
||||
{
|
||||
NS_NOTREACHED("nsJARChannel::GetOutputStream");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -971,8 +684,7 @@ nsJARChannel::GetOutputStream(nsIOutputStream* *aOutputStream)
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::EnumerateEntries(const char *aRoot, nsISimpleEnumerator **_retval)
|
||||
{
|
||||
NS_NOTREACHED("nsJARChannel::EnumerateEntries");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
#include "prmon.h"
|
||||
|
||||
class nsIFileChannel;
|
||||
class nsJARChannel;
|
||||
|
||||
#define NS_JARCHANNEL_CID \
|
||||
{ /* 0xc7e410d5-0x85f2-11d3-9f63-006008a6efe9 */ \
|
||||
@@ -50,9 +49,6 @@ class nsJARChannel;
|
||||
|
||||
#define JAR_DIRECTORY "jarCache"
|
||||
|
||||
typedef nsresult
|
||||
(*OnJARFileAvailableFun)(nsJARChannel* channel, void* closure);
|
||||
|
||||
class nsJARChannel : public nsIJARChannel,
|
||||
public nsIStreamListener,
|
||||
public nsIFileSystem
|
||||
@@ -73,23 +69,28 @@ public:
|
||||
static NS_METHOD
|
||||
Create(nsISupports* aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
nsresult Init(nsIJARProtocolHandler* aHandler, nsIURI* uri);
|
||||
nsresult EnsureJARFileAvailable(OnJARFileAvailableFun fun,
|
||||
void* closure);
|
||||
nsresult AsyncReadJARElement();
|
||||
nsresult GetCacheFile(nsIFile* *cacheFile);
|
||||
nsresult Init(nsIJARProtocolHandler* aHandler,
|
||||
const char* command,
|
||||
nsIURI* uri,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize);
|
||||
|
||||
void SetJARBaseFile(nsIFileChannel* channel) { mJARBaseFile = channel; }
|
||||
nsresult ExtractJARElement(nsIFileChannel* jarFileChannel);
|
||||
nsresult GetCacheFile(nsIFile* *cacheFile);
|
||||
|
||||
friend class nsJARDownloadObserver;
|
||||
|
||||
protected:
|
||||
char* mCommand;
|
||||
nsCOMPtr<nsIJARURI> mURI;
|
||||
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
||||
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
|
||||
nsCOMPtr<nsIURI> mOriginalURI;
|
||||
nsLoadFlags mLoadAttributes;
|
||||
nsCOMPtr<nsISupports> mOwner;
|
||||
|
||||
PRUint32 mStartPosition;
|
||||
PRInt32 mReadCount;
|
||||
@@ -104,7 +105,6 @@ protected:
|
||||
nsCOMPtr<nsIZipReader> mJAR;
|
||||
PRUint32 mBufferSegmentSize;
|
||||
PRUint32 mBufferMaxSize;
|
||||
nsresult mStatus;
|
||||
|
||||
PRMonitor* mMonitor;
|
||||
nsCOMPtr<nsIChannel> mJarCacheTransport;
|
||||
|
||||
@@ -117,7 +117,14 @@ nsJARProtocolHandler::NewURI(const char *aSpec, nsIURI *aBaseURI,
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARProtocolHandler::NewChannel(nsIURI* uri, nsIChannel* *result)
|
||||
nsJARProtocolHandler::NewChannel(const char* verb, nsIURI* uri,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize,
|
||||
nsIChannel* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
@@ -125,7 +132,8 @@ nsJARProtocolHandler::NewChannel(nsIURI* uri, nsIChannel* *result)
|
||||
rv = nsJARChannel::Create(nsnull, NS_GET_IID(nsIJARChannel), (void**)&channel);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = channel->Init(this, uri);
|
||||
rv = channel->Init(this, verb, uri, aLoadGroup, notificationCallbacks,
|
||||
loadAttributes, originalURI, bufferSegmentSize, bufferMaxSize);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(channel);
|
||||
return rv;
|
||||
|
||||
@@ -34,257 +34,23 @@ interface nsIFile;
|
||||
typedef unsigned long nsLoadFlags;
|
||||
|
||||
/**
|
||||
* The nsIChannel interface allows the user to construct I/O requests for
|
||||
* specific protocols, and manage them in a uniform way. Once a channel
|
||||
* is created (via nsIIOService::NewChannel), parameters for that request
|
||||
* may be set by using the channel attributes, or by QueryInterfacing to a
|
||||
* subclass of nsIChannel for protocol-specific parameters. Then the actual
|
||||
* request can be issued in one of several ways:
|
||||
*
|
||||
* - AsyncRead and AsyncWrite allow for asynchronous requests, calling
|
||||
* back the user's stream listener or observer,
|
||||
* - OpenInputStream and OpenOutputStream allow for synchronous reads
|
||||
* and writes on the underlying channel.
|
||||
*
|
||||
* After a request has been completed, the channel is still valid for
|
||||
* accessing protocol-specific results. For example, QueryInterfacing to
|
||||
* nsIHTTPChannel allows response headers to be retrieved that result from
|
||||
* http transactions.
|
||||
*
|
||||
* Note that a channel is really only valid for one request. Reusing a channel
|
||||
* after a request has completed for a subsequent request may have undefined
|
||||
* results, depending on the channel implementation.
|
||||
*
|
||||
* Also of note are a special kind of channel called "transports." Transports
|
||||
* also implement the nsIChannel interface, but operate at a lower level from
|
||||
* protocol channels. The socket and file transports are notable implementations
|
||||
* of transports and allow higher level channels to be implemented. The cache
|
||||
* may also behave as a transport, and possibly things like sound playing services
|
||||
* etc. Transports usually operate in a separate thread and often multiplex
|
||||
* multiple requests for the same kind of service or resources.
|
||||
* nsIChannel is the abstract base class for transports and URLs.
|
||||
* It's abstract in that it doesn't provide a means to specify the
|
||||
* location/destination of the data being accessed.
|
||||
*/
|
||||
[scriptable, uuid(1788e79e-f947-11d3-8cda-0060b0fc14a3)]
|
||||
[scriptable, uuid(2d905684-8b5c-11d3-8cd9-0060b0fc14a3)]
|
||||
interface nsIChannel : nsIRequest
|
||||
{
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// nsIChannel accessors
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Returns the original URL used to construct the channel.
|
||||
* This is used in the case of a redirect or URI "resolution" (e.g.
|
||||
* resolving a resource: URI to a file: URI) so that the original
|
||||
* pre-redirect URI can still be obtained.
|
||||
*
|
||||
* Note that this is distinctly different from the http referrer
|
||||
* (referring URI) which is typically the page that contained the
|
||||
* original URI (accessible from nsIHTTPChannel).
|
||||
*/
|
||||
attribute nsIURI originalURI;
|
||||
readonly attribute nsIURI originalURI;
|
||||
|
||||
/**
|
||||
* Returns the URL to which the channel currently refers. If a redirect
|
||||
* or URI resolution occurs, this accessor returns the current location
|
||||
* to which the channel is referring.
|
||||
* Returns the URL to which the channel currently refers.
|
||||
*/
|
||||
attribute nsIURI URI;
|
||||
readonly attribute nsIURI URI;
|
||||
|
||||
/**
|
||||
* Accesses the start offset from the beginning of the data from/to which
|
||||
* reads/writes will occur. Users may set the transferOffset before making
|
||||
* any of the following requests: asyncOpen, asyncRead, asyncWrite,
|
||||
* openInputStream, openOutputstream.
|
||||
*/
|
||||
attribute unsigned long transferOffset;
|
||||
|
||||
/**
|
||||
* Accesses the count of bytes to be transfered. For openInputStream and
|
||||
* asyncRead, this specifies the amount to read, for asyncWrite, this
|
||||
* specifies the amount to write (note that for openOutputStream, the
|
||||
* end of the data can be signified simply by closing the stream).
|
||||
* If the transferCount is set after reading has been initiated, the
|
||||
* amount specified will become the current remaining amount to read
|
||||
* before the channel is closed (this can be useful if the content
|
||||
* length is encoded at the start of the stream).
|
||||
*
|
||||
* A transferCount value of -1 means the amount is unspecified, i.e.
|
||||
* read or write all the data that is available.
|
||||
*/
|
||||
attribute long transferCount;
|
||||
|
||||
/**
|
||||
* Accesses the load attributes for the channel. E.g. setting the load
|
||||
* attributes with the LOAD_QUIET bit set causes the loading process to
|
||||
* not deliver status notifications to the program performing the load,
|
||||
* and to not contribute to keeping any nsILoadGroup it may be contained
|
||||
* in from firing its OnLoadComplete notification.
|
||||
*/
|
||||
attribute nsLoadFlags loadAttributes;
|
||||
|
||||
/**
|
||||
* Returns the content MIME type of the channel if available. Note that the
|
||||
* content type can often be wrongly specified (wrong file extension, wrong
|
||||
* MIME type, wrong document type stored on a server, etc.) and the caller
|
||||
* most likely wants to verify with the actual data.
|
||||
*/
|
||||
attribute string contentType;
|
||||
|
||||
/**
|
||||
* Returns the length of the data associated with the channel if available.
|
||||
* If the length is unknown then -1 is returned.
|
||||
*/
|
||||
attribute long contentLength;
|
||||
|
||||
/**
|
||||
* Accesses the owner corresponding to the entity that is
|
||||
* responsible for this channel. Used by security code to grant
|
||||
* or deny privileges to mobile code loaded from this channel.
|
||||
*
|
||||
* Note: This is a strong reference to the owner, so if the owner is also
|
||||
* holding a pointer to the channel, care must be taken to explicitly drop
|
||||
* its reference to the channel -- otherwise a leak will result.
|
||||
*/
|
||||
attribute nsISupports owner;
|
||||
|
||||
/**
|
||||
* Accesses the load group in which the channel is a currently a member.
|
||||
*/
|
||||
attribute nsILoadGroup loadGroup;
|
||||
|
||||
/**
|
||||
* Accesses the capabilities callbacks of the channel. This is set by clients
|
||||
* who wish to provide a means to receive progress, status and protocol-specific
|
||||
* notifications.
|
||||
*/
|
||||
attribute nsIInterfaceRequestor notificationCallbacks;
|
||||
|
||||
/**
|
||||
* Any security information about this channel. This can be null.
|
||||
*/
|
||||
readonly attribute nsISupports securityInfo;
|
||||
|
||||
/**
|
||||
* Accesses the buffer segment size. The buffer segment size is used as
|
||||
* the initial size for any transfer buffers, and the increment size for
|
||||
* whenever the buffer space needs to be grown.
|
||||
* (Note this parameter is passed along to any underlying nsIPipe objects.)
|
||||
* If unspecified, the channel implementation picks a default.
|
||||
*/
|
||||
attribute unsigned long bufferSegmentSize;
|
||||
|
||||
/**
|
||||
* Accesses the buffer maximum size. The buffer maximum size is the limit
|
||||
* size that buffer will be grown to before suspending the channel.
|
||||
* (Note this parameter is passed along to any underlying nsIPipe objects.)
|
||||
* If unspecified, the channel implementation picks a default.
|
||||
*/
|
||||
attribute unsigned long bufferMaxSize;
|
||||
|
||||
/**
|
||||
* Returns true if the data from this channel should be cached. Local files
|
||||
* report false because they exist on the local disk and need not be cached.
|
||||
* Input stream channels, data protocol, datetime protocol and finger
|
||||
* protocol channels also should not be cached. Http and ftp on the other
|
||||
* hand should. Note that the value of this attribute doesn't reflect any
|
||||
* http headers that may specify that this channel should not be cached.
|
||||
*/
|
||||
readonly attribute boolean shouldCache;
|
||||
|
||||
/**
|
||||
* Setting pipeliningAllowed causes the load of a URL (issued via asyncOpen,
|
||||
* asyncRead or asyncWrite) to be deferred in order to allow the request to
|
||||
* be pipelined for greater throughput efficiency. Pipelined requests will
|
||||
* be forced to load when the first non-pipelined request is issued.
|
||||
*/
|
||||
attribute boolean pipeliningAllowed;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Load attribute flags. These may be or'd together.
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Note that more will follow for each protocol's implementation of a channel,
|
||||
* although channel writers have to be careful to not let the flag bits
|
||||
* overlap. Otherwise, users won't be able to create a single flag word
|
||||
* of load attributes that applies to a number of different channel types.
|
||||
*/
|
||||
|
||||
/**
|
||||
* No special load attributes -- use defaults:
|
||||
*/
|
||||
const unsigned long LOAD_NORMAL = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Don't deliver status notifications to the nsIProgressEventSink, or keep
|
||||
* this load from completing the nsILoadGroup it may belong to:
|
||||
*/
|
||||
const unsigned long LOAD_BACKGROUND = 1 << 0;
|
||||
|
||||
const unsigned long LOAD_DOCUMENT_URI = 1 << 1;
|
||||
|
||||
/**
|
||||
* If the end consumer for this load has been retargeted after discovering
|
||||
* it's content, this flag will be set:
|
||||
*/
|
||||
const unsigned long LOAD_RETARGETED_DOCUMENT_URI = 1 << 2;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* The following flags control caching behavior. Not all protocols pay
|
||||
* attention to all these flags, but they are applicable to more than one
|
||||
* protocol, so they are defined here.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Don't store data in the disk cache. This can be used to preserve
|
||||
* privacy, e.g. so that no https transactions are recorded, or to avoid
|
||||
* caching a stream to disk that is already stored in a local file,
|
||||
* e.g. the mailbox: protocol.
|
||||
*/
|
||||
const unsigned long INHIBIT_PERSISTENT_CACHING = 1 << 8;
|
||||
|
||||
/**
|
||||
* Force an end-to-end download of content data from the origin server (and
|
||||
* any intervening proxies that sit between it and the client), e.g. this
|
||||
* flag is used for a shift-reload.
|
||||
*/
|
||||
const unsigned long FORCE_RELOAD = 1 << 9;
|
||||
|
||||
/**
|
||||
* Force revalidation with server (or proxy) to verify that cached content
|
||||
* is up-to-date, e.g. by comparing last-modified date on server with that
|
||||
* of the cached version. For example, this flag is used when the reload
|
||||
* button is pressed.
|
||||
*/
|
||||
const unsigned long FORCE_VALIDATION = 1 << 10;
|
||||
|
||||
/**
|
||||
* If the CACHE_AS_FILE flag is set, any stream content is stored in the
|
||||
* cache as a single disk file. Content will not be cached in the memory
|
||||
* cache nor will it be stored in any other type of cache, e.g. a flat-file
|
||||
* cache database. This is used to implement the jar protocol handler and
|
||||
* to provide the stream-as-file semantics required by the classic browser
|
||||
* plugin API.
|
||||
*/
|
||||
const unsigned long CACHE_AS_FILE = 1 << 11;
|
||||
|
||||
/**
|
||||
* When cache data is potentially out of date, it can be revalidated with
|
||||
* the origin server to see if the content needs to be reloaded. The
|
||||
* following four flags control how often this validation occurs.
|
||||
* These flags are commonly used for "normal" loading. Note that
|
||||
* the VALIDATE_HEURISTICALLY and VALIDATE_ONCE_PER_SESSION flags can be
|
||||
* combined to validate heuristically but no more than once per session.
|
||||
*/
|
||||
const unsigned long VALIDATE_NEVER = 1 << 12;
|
||||
const unsigned long VALIDATE_ALWAYS = 1 << 13;
|
||||
const unsigned long VALIDATE_ONCE_PER_SESSION = 1 << 14;
|
||||
const unsigned long VALIDATE_HEURISTICALLY = 1 << 15;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// nsIChannel operations
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Opens a blocking input stream to the URL's specified source.
|
||||
* @param startPosition - The offset from the start of the data
|
||||
@@ -293,14 +59,15 @@ interface nsIChannel : nsIRequest
|
||||
* up to the end of the data is read. If greater than the end of
|
||||
* the data, the amount available is returned in the stream.
|
||||
*/
|
||||
nsIInputStream openInputStream();
|
||||
nsIInputStream openInputStream(in unsigned long startPosition,
|
||||
in long readCount);
|
||||
|
||||
/**
|
||||
* Opens a blocking output stream to the URL's specified destination.
|
||||
* @param startPosition - The offset from the start of the data
|
||||
* from which to begin writing.
|
||||
*/
|
||||
nsIOutputStream openOutputStream();
|
||||
nsIOutputStream openOutputStream(in unsigned long startPosition);
|
||||
|
||||
/**
|
||||
* Opens the channel asynchronously. The nsIStreamObserver's OnStartRequest
|
||||
@@ -320,8 +87,10 @@ interface nsIChannel : nsIRequest
|
||||
* If the readCount == -1 then all the available data is delivered to
|
||||
* the stream listener.
|
||||
*/
|
||||
void asyncRead(in nsIStreamListener listener,
|
||||
in nsISupports ctxt);
|
||||
void asyncRead(in unsigned long startPosition,
|
||||
in long readCount,
|
||||
in nsISupports ctxt,
|
||||
in nsIStreamListener listener);
|
||||
|
||||
/**
|
||||
* Writes asynchronously to the URL's specified destination. Notifications
|
||||
@@ -333,8 +102,114 @@ interface nsIChannel : nsIRequest
|
||||
* stream is written.
|
||||
*/
|
||||
void asyncWrite(in nsIInputStream fromStream,
|
||||
in nsIStreamObserver observer,
|
||||
in nsISupports ctxt);
|
||||
in unsigned long startPosition,
|
||||
in long writeCount,
|
||||
in nsISupports ctxt,
|
||||
in nsIStreamObserver observer);
|
||||
|
||||
/**
|
||||
* Load attribute flags. These may be or'd together.
|
||||
*
|
||||
* Note that more will follow for each protocol's implementation of a channel,
|
||||
* although channel writers have to be careful to not let the flag bits
|
||||
* overlap. Otherwise, users won't be able to create a single flag word
|
||||
* of load attributes that applies to a number of different channel types.
|
||||
*/
|
||||
const unsigned long LOAD_NORMAL = 0; /* no special load attributes -- use defaults */
|
||||
const unsigned long LOAD_BACKGROUND = 1 << 0; /* don't deliver status notifications to the
|
||||
* nsIProgressEventSink, or keep this load from
|
||||
* completing the nsILoadGroup it may belong to */
|
||||
|
||||
const unsigned long LOAD_DOCUMENT_URI = 1 << 1;
|
||||
const unsigned long LOAD_RETARGETED_DOCUMENT_URI = 1 << 2; /* if the end consumer for this
|
||||
load has been retargeted after
|
||||
discovering it's content, this flag
|
||||
will be set */
|
||||
//
|
||||
// The following flags control caching behavior. Not all protocols pay
|
||||
// attention to all these flags, but they are applicable to more than one
|
||||
// protocol, so they are defined here.
|
||||
//
|
||||
|
||||
// Don't store data in the disk cache. This can be used to preserve
|
||||
// privacy, e.g. so that no https transactions are recorded, or to avoid
|
||||
// caching a stream to disk that is already stored in a local file,
|
||||
// e.g. the mailbox: protocol.
|
||||
const unsigned long INHIBIT_PERSISTENT_CACHING = 1 << 8;
|
||||
|
||||
// Force an end-to-end download of content data from the origin server (and
|
||||
// any intervening proxies that sit between it and the client), e.g. this
|
||||
// flag is used for a shift-reload.
|
||||
const unsigned long FORCE_RELOAD = 1 << 9;
|
||||
|
||||
// Force revalidation with server (or proxy) to verify that cached content
|
||||
// is up-to-date, e.g. by comparing last-modified date on server with that
|
||||
// of the cached version. For example, this flag is used when the reload
|
||||
// button is pressed.
|
||||
const unsigned long FORCE_VALIDATION = 1 << 10;
|
||||
|
||||
// If the CACHE_AS_FILE flag is set, any stream content is stored in the
|
||||
// cache as a single disk file. Content will not be cached in the memory
|
||||
// cache nor will it be stored in any other type of cache, e.g. a flat-file
|
||||
// cache database. This is used to implement the jar protocol handler and
|
||||
// to provide the stream-as-file semantics required by the classic browser
|
||||
// plugin API.
|
||||
const unsigned long CACHE_AS_FILE = 1 << 11;
|
||||
|
||||
// When cache data is potentially out of date, it can be revalidated with
|
||||
// the origin server to see if the content needs to be reloaded. The
|
||||
// following four flags control how often this validation occurs.
|
||||
// These flags are commonly used for "normal" loading. Note that
|
||||
// the VALIDATE_HEURISTICALLY and VALIDATE_ONCE_PER_SESSION flags can be
|
||||
// combined to validate heuristically but no more than once per session.
|
||||
//
|
||||
const unsigned long VALIDATE_NEVER = 1 << 12;
|
||||
const unsigned long VALIDATE_ALWAYS = 1 << 13;
|
||||
const unsigned long VALIDATE_ONCE_PER_SESSION = 1 << 14;
|
||||
const unsigned long VALIDATE_HEURISTICALLY = 1 << 15;
|
||||
|
||||
|
||||
/**
|
||||
* Accesses the load attributes for the channel. E.g. setting the load
|
||||
* attributes with the LOAD_QUIET bit set causes the loading process to
|
||||
* not deliver status notifications to the program performing the load,
|
||||
* and to not contribute to keeping any nsILoadGroup it may be contained
|
||||
* in from firing its OnLoadComplete notification.
|
||||
*/
|
||||
attribute nsLoadFlags loadAttributes;
|
||||
|
||||
/**
|
||||
* Returns the content MIME type of the channel if available. Note that the
|
||||
* content type can often be wrongly specified (wrong file extension, wrong
|
||||
* MIME type, wrong document type stored on a server, etc.) and the caller
|
||||
* most likely wants to verify with the actual data.
|
||||
*/
|
||||
attribute string contentType;
|
||||
|
||||
/**
|
||||
* Returns the length of the data assiciated with the channel if available.
|
||||
* If the length is unknown then -1 is returned.
|
||||
*/
|
||||
readonly attribute long contentLength;
|
||||
|
||||
/**
|
||||
* Accesses the owner corresponding to the entity that is
|
||||
* responsible for this channel. Used by security code to grant
|
||||
* or diminish privileges to mobile code loaded from this channel.
|
||||
*/
|
||||
attribute nsISupports owner;
|
||||
|
||||
/**
|
||||
* Accesses the load group in which the channel is a currently a member.
|
||||
*/
|
||||
attribute nsILoadGroup loadGroup;
|
||||
|
||||
/**
|
||||
* Accesses the capabilities callbacks of the channel. This is set by clients
|
||||
* who wish to provide a means to receive progress, status and protocol-specific
|
||||
* notifications.
|
||||
*/
|
||||
attribute nsIInterfaceRequestor notificationCallbacks;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -345,23 +220,29 @@ interface nsIChannel : nsIRequest
|
||||
* associated content type. Input stream channels only allow the input stream
|
||||
* to be accessed, not the output stream.
|
||||
*/
|
||||
[scriptable, uuid(43070d6a-f947-11d3-8cda-0060b0fc14a3)]
|
||||
[scriptable, uuid(bfbf843a-8b89-11d3-8cd9-0060b0fc14a3)]
|
||||
interface nsIInputStreamChannel : nsIChannel
|
||||
{
|
||||
void init(in nsIURI uri,
|
||||
in nsIInputStream inStr,
|
||||
in string contentType,
|
||||
in long contentLength);
|
||||
in long contentLength,
|
||||
in nsIInputStream inStr,
|
||||
in nsILoadGroup aLoadGroup,
|
||||
in nsIInterfaceRequestor notificationCallbacks,
|
||||
in nsLoadFlags loadAttributes,
|
||||
in nsIURI originalURI,
|
||||
in unsigned long bufferSegmentSize,
|
||||
in unsigned long bufferMaxSize);
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
||||
#define NS_INPUTSTREAMCHANNEL_CID \
|
||||
{ /* 54d0d8e6-f947-11d3-8cda-0060b0fc14a3 */ \
|
||||
0x54d0d8e6, \
|
||||
0xf947, \
|
||||
{ /* 436d84f8-8b8a-11d3-8cd9-0060b0fc14a3 */ \
|
||||
0x436d84f8, \
|
||||
0x8b8a, \
|
||||
0x11d3, \
|
||||
{0x8c, 0xda, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
|
||||
{0x8c, 0xd9, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
|
||||
}
|
||||
|
||||
%}
|
||||
@@ -373,27 +254,32 @@ interface nsIInputStreamChannel : nsIChannel
|
||||
* of a simple nsIChannel that is constructed from a single nsIFile and
|
||||
* associated content type.
|
||||
*/
|
||||
[scriptable, uuid(68a26506-f947-11d3-8cda-0060b0fc14a3)]
|
||||
[scriptable, uuid(6eef6444-c7e3-11d3-8cda-0060b0fc14a3)]
|
||||
interface nsIFileChannel : nsIChannel
|
||||
{
|
||||
void init(in nsIFile file,
|
||||
in long ioFlags,
|
||||
in long perm);
|
||||
in long mode,
|
||||
in string contentType,
|
||||
in long contentLength,
|
||||
in nsILoadGroup aLoadGroup,
|
||||
in nsIInterfaceRequestor notificationCallbacks,
|
||||
in nsLoadFlags loadAttributes,
|
||||
in nsIURI originalURI,
|
||||
in unsigned long bufferSegmentSize,
|
||||
in unsigned long bufferMaxSize);
|
||||
|
||||
readonly attribute nsIFile file;
|
||||
attribute long ioFlags;
|
||||
attribute long permissions;
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
||||
#define NS_LOCALFILECHANNEL_CLASSNAME "Local File Channel"
|
||||
#define NS_LOCALFILECHANNEL_PROGID "component://netscape/network/local-file-channel"
|
||||
#define NS_FILECHANNEL_CLASSNAME "File Channel"
|
||||
#define NS_FILECHANNEL_PROGID "component://netscape/network/file-channel"
|
||||
|
||||
#define NS_LOCALFILECHANNEL_CID \
|
||||
{ /* 6d5b2d44-f947-11d3-8cda-0060b0fc14a3 */ \
|
||||
0x6d5b2d44, \
|
||||
0xf947, \
|
||||
#define NS_FILECHANNEL_CID \
|
||||
{ /* 7036066e-c7e3-11d3-8cda-0060b0fc14a3 */ \
|
||||
0x7036066e, \
|
||||
0xc7e3, \
|
||||
0x11d3, \
|
||||
{0x8c, 0xda, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
|
||||
}
|
||||
|
||||
@@ -27,13 +27,13 @@
|
||||
[scriptable, uuid(e3d56a20-c7ec-11d3-8cda-0060b0fc14a3)]
|
||||
interface nsIFileInputStream : nsIInputStream
|
||||
{
|
||||
void init(in nsIFile file, in long ioFlags, in long perm);
|
||||
void init(in nsILocalFile file);
|
||||
};
|
||||
|
||||
[scriptable, uuid(e6f68040-c7ec-11d3-8cda-0060b0fc14a3)]
|
||||
interface nsIFileOutputStream : nsIOutputStream
|
||||
{
|
||||
void init(in nsIFile file, in long ioFlags, in long perm);
|
||||
void init(in nsILocalFile file, in long flags, in long mode);
|
||||
};
|
||||
|
||||
[scriptable, uuid(e9de5df0-c7ec-11d3-8cda-0060b0fc14a3)]
|
||||
@@ -66,10 +66,10 @@ interface nsIBufferedOutputStream : nsIOutputStream
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define NS_LOCALFILEINPUTSTREAM_CLASSNAME "Local File Input Stream"
|
||||
#define NS_LOCALFILEINPUTSTREAM_PROGID "component://netscape/network/file-input-stream"
|
||||
#define NS_FILEINPUTSTREAM_CLASSNAME "File Input Stream"
|
||||
#define NS_FILEINPUTSTREAM_PROGID "component://netscape/network/file-input-stream"
|
||||
|
||||
#define NS_LOCALFILEINPUTSTREAM_CID \
|
||||
#define NS_FILEINPUTSTREAM_CID \
|
||||
{ /* be9a53ae-c7e9-11d3-8cda-0060b0fc14a3 */ \
|
||||
0xbe9a53ae, \
|
||||
0xc7e9, \
|
||||
@@ -77,10 +77,10 @@ interface nsIBufferedOutputStream : nsIOutputStream
|
||||
{0x8c, 0xda, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
|
||||
}
|
||||
|
||||
#define NS_LOCALFILEOUTPUTSTREAM_CLASSNAME "Local File Output Stream"
|
||||
#define NS_LOCALFILEOUTPUTSTREAM_PROGID "component://netscape/network/file-output-stream"
|
||||
#define NS_FILEOUTPUTSTREAM_CLASSNAME "File Output Stream"
|
||||
#define NS_FILEOUTPUTSTREAM_PROGID "component://netscape/network/file-output-stream"
|
||||
|
||||
#define NS_LOCALFILEOUTPUTSTREAM_CID \
|
||||
#define NS_FILEOUTPUTSTREAM_CID \
|
||||
{ /* c272fee0-c7e9-11d3-8cda-0060b0fc14a3 */ \
|
||||
0xc272fee0, \
|
||||
0xc7e9, \
|
||||
@@ -123,24 +123,32 @@ interface nsIBufferedOutputStream : nsIOutputStream
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "prio.h" // for read/write flags, permissions, etc.
|
||||
#include "prio.h" // for read/write modes, etc.
|
||||
|
||||
// This will QI the file argument to an nsILocalFile in the Init method.
|
||||
inline nsresult
|
||||
NS_NewLocalFileChannel(nsIFileChannel **result,
|
||||
nsIFile* file,
|
||||
PRInt32 ioFlags = -1,
|
||||
PRInt32 perm = -1)
|
||||
NS_NewFileChannel(nsIFile* file,
|
||||
PRInt32 mode,
|
||||
const char* contentType,
|
||||
PRUint32 contentLength,
|
||||
nsILoadGroup* group,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize,
|
||||
nsIFileChannel **result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIFileChannel> channel;
|
||||
static NS_DEFINE_CID(kLocalFileChannelCID, NS_LOCALFILECHANNEL_CID);
|
||||
rv = nsComponentManager::CreateInstance(kLocalFileChannelCID,
|
||||
static NS_DEFINE_CID(kFileChannelCID, NS_FILECHANNEL_CID);
|
||||
rv = nsComponentManager::CreateInstance(kFileChannelCID,
|
||||
nsnull,
|
||||
NS_GET_IID(nsIFileChannel),
|
||||
getter_AddRefs(channel));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = channel->Init(file, ioFlags, perm);
|
||||
rv = channel->Init(file, mode, contentType, contentLength, group,
|
||||
notificationCallbacks, loadAttributes, originalURI,
|
||||
bufferSegmentSize, bufferMaxSize);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*result = channel;
|
||||
@@ -148,22 +156,20 @@ NS_NewLocalFileChannel(nsIFileChannel **result,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// This will QI the file argument to an nsILocalFile in the Init method.
|
||||
inline nsresult
|
||||
NS_NewLocalFileInputStream(nsIInputStream* *result,
|
||||
nsIFile* file,
|
||||
PRInt32 ioFlags = -1,
|
||||
PRInt32 perm = -1)
|
||||
NS_NewFileInputStream(nsIFile* file, nsIInputStream* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIFileInputStream> in;
|
||||
static NS_DEFINE_CID(kLocalFileInputStreamCID, NS_LOCALFILEINPUTSTREAM_CID);
|
||||
rv = nsComponentManager::CreateInstance(kLocalFileInputStreamCID,
|
||||
static NS_DEFINE_CID(kFileInputStreamCID, NS_FILEINPUTSTREAM_CID);
|
||||
rv = nsComponentManager::CreateInstance(kFileInputStreamCID,
|
||||
nsnull,
|
||||
NS_GET_IID(nsIFileInputStream),
|
||||
getter_AddRefs(in));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = in->Init(file, ioFlags, perm);
|
||||
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(file, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = in->Init(localFile);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*result = in;
|
||||
@@ -171,22 +177,21 @@ NS_NewLocalFileInputStream(nsIInputStream* *result,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// This will QI the file argument to an nsILocalFile in the Init method.
|
||||
inline nsresult
|
||||
NS_NewLocalFileOutputStream(nsIOutputStream* *result,
|
||||
nsIFile* file,
|
||||
PRInt32 ioFlags = -1,
|
||||
PRInt32 perm = -1)
|
||||
NS_NewFileOutputStream(nsIFile* file, PRInt32 flags, PRInt32 mode,
|
||||
nsIOutputStream* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIFileOutputStream> out;
|
||||
static NS_DEFINE_CID(kLocalFileOutputStreamCID, NS_LOCALFILEOUTPUTSTREAM_CID);
|
||||
rv = nsComponentManager::CreateInstance(kLocalFileOutputStreamCID,
|
||||
static NS_DEFINE_CID(kFileOutputStreamCID, NS_FILEOUTPUTSTREAM_CID);
|
||||
rv = nsComponentManager::CreateInstance(kFileOutputStreamCID,
|
||||
nsnull,
|
||||
NS_GET_IID(nsIFileOutputStream),
|
||||
getter_AddRefs(out));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = out->Init(file, ioFlags, perm);
|
||||
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(file, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = out->Init(localFile, flags, mode);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*result = out;
|
||||
@@ -197,9 +202,8 @@ NS_NewLocalFileOutputStream(nsIOutputStream* *result,
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline nsresult
|
||||
NS_NewBufferedInputStream(nsIInputStream* *result,
|
||||
nsIInputStream* str,
|
||||
PRUint32 bufferSize)
|
||||
NS_NewBufferedInputStream(nsIInputStream* str, PRUint32 bufferSize,
|
||||
nsIInputStream* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIBufferedInputStream> in;
|
||||
@@ -218,9 +222,8 @@ NS_NewBufferedInputStream(nsIInputStream* *result,
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_NewBufferedOutputStream(nsIOutputStream* *result,
|
||||
nsIOutputStream* str,
|
||||
PRUint32 bufferSize)
|
||||
NS_NewBufferedOutputStream(nsIOutputStream* str, PRUint32 bufferSize,
|
||||
nsIOutputStream* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIBufferedOutputStream> out;
|
||||
|
||||
@@ -36,16 +36,24 @@ interface nsIFile;
|
||||
interface nsIFileTransportService : nsISupports
|
||||
{
|
||||
nsIChannel createTransport(in nsIFile file,
|
||||
in long ioFlags,
|
||||
in long perm);
|
||||
in long mode,
|
||||
in string command,
|
||||
in unsigned long bufferSegmentSize,
|
||||
in unsigned long bufferMaxSize);
|
||||
|
||||
// This version can be used with an existing input stream to serve
|
||||
// as a data pump:
|
||||
nsIChannel createTransportFromStream(in nsIInputStream fromStream,
|
||||
in string contentType,
|
||||
in long contentLength);
|
||||
in long contentLength,
|
||||
in string command,
|
||||
in unsigned long bufferSegmentSize,
|
||||
in unsigned long bufferMaxSize);
|
||||
|
||||
nsIChannel createTransportFromFileSystem(in nsIFileSystem fsObj);
|
||||
nsIChannel createTransportFromFileSystem(in nsIFileSystem fsObj,
|
||||
in string command,
|
||||
in unsigned long bufferSegmentSize,
|
||||
in unsigned long bufferMaxSize);
|
||||
|
||||
void dispatchRequest(in nsIRunnable runnable);
|
||||
void suspend(in nsIRunnable trans);
|
||||
|
||||
@@ -42,6 +42,20 @@ interface nsIOutputStream;
|
||||
[scriptable, uuid(ab7c3a84-d488-11d3-8cda-0060b0fc14a3)]
|
||||
interface nsIIOService : nsISupports
|
||||
{
|
||||
/**
|
||||
* constants for the Escape mask in the call to URLEscape
|
||||
*/
|
||||
const short url_Scheme = (1<<0);
|
||||
const short url_Username = (1<<1);
|
||||
const short url_Password = (1<<2);
|
||||
const short url_Host = (1<<3);
|
||||
const short url_Directory = (1<<4);
|
||||
const short url_FileBaseName = (1<<5);
|
||||
const short url_FileExtension = (1<<6);
|
||||
const short url_Param = (1<<7);
|
||||
const short url_Query = (1<<8);
|
||||
const short url_Ref = (1<<9);
|
||||
|
||||
/**
|
||||
* Returns a protocol handler for a given URI scheme.
|
||||
*/
|
||||
@@ -67,20 +81,28 @@ interface nsIIOService : nsISupports
|
||||
* URL to become different from the original URL. If NULL, the aURI parameter
|
||||
* will be used as the originalURI instead.
|
||||
*/
|
||||
nsIChannel newChannelFromURI(in nsIURI aURI);
|
||||
nsIChannel newChannelFromURI(in string verb,
|
||||
in nsIURI aURI,
|
||||
in nsILoadGroup aLoadGroup,
|
||||
in nsIInterfaceRequestor notificationCallbacks,
|
||||
in nsLoadFlags loadAttributes,
|
||||
in nsIURI originalURI,
|
||||
in unsigned long bufferSegmentSize,
|
||||
in unsigned long bufferMaxSize);
|
||||
|
||||
/**
|
||||
* Convenience routine that first creates a URI by calling NewURI, and
|
||||
* then passes the URI to NewChannelFromURI.
|
||||
*
|
||||
* @param originalURI - Specifies the original URI which caused the creation
|
||||
* of this channel. This can occur when the construction of one channel
|
||||
* (e.g. for resource:) causes another channel to be created on its behalf
|
||||
* (e.g. a file: channel), or if a redirect occurs, causing the current
|
||||
* URL to become different from the original URL. If NULL, the aURI parameter
|
||||
* will be used as the originalURI instead.
|
||||
*/
|
||||
nsIChannel newChannel(in string aSpec, in nsIURI aBaseURI);
|
||||
nsIChannel newChannel(in string verb,
|
||||
in string aSpec,
|
||||
in nsIURI aBaseURI,
|
||||
in nsILoadGroup aLoadGroup,
|
||||
in nsIInterfaceRequestor notificationCallbacks,
|
||||
in nsLoadFlags loadAttributes,
|
||||
in nsIURI originalURI,
|
||||
in unsigned long bufferSegmentSize,
|
||||
in unsigned long bufferMaxSize);
|
||||
|
||||
/**
|
||||
* Returns true if networking is in "offline" mode. When in offline mode, attempts
|
||||
@@ -113,21 +135,6 @@ interface nsIIOService : nsISupports
|
||||
out unsigned long schemeEndPos,
|
||||
out string scheme);
|
||||
|
||||
/**
|
||||
* Constants for the mask in the call to Escape
|
||||
*/
|
||||
const short url_Scheme = (1<<0);
|
||||
const short url_Username = (1<<1);
|
||||
const short url_Password = (1<<2);
|
||||
const short url_Host = (1<<3);
|
||||
const short url_Directory = (1<<4);
|
||||
const short url_FileBaseName = (1<<5);
|
||||
const short url_FileExtension = (1<<6);
|
||||
const short url_Param = (1<<7);
|
||||
const short url_Query = (1<<8);
|
||||
const short url_Ref = (1<<9);
|
||||
const short url_Forced = (1<<10);
|
||||
|
||||
/**
|
||||
* Encode characters into % escaped hexcodes.
|
||||
*/
|
||||
@@ -165,5 +172,4 @@ interface nsIIOService : nsISupports
|
||||
{0x93, 0x37, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40} \
|
||||
}
|
||||
|
||||
#define DUD 3.14
|
||||
%}
|
||||
|
||||
@@ -52,7 +52,14 @@ interface nsIProtocolHandler : nsISupports
|
||||
* URL to become different from the original URL. If NULL, the aURI parameter
|
||||
* will be used as the originalURI instead.
|
||||
*/
|
||||
nsIChannel newChannel(in nsIURI aURI);
|
||||
nsIChannel newChannel(in string verb,
|
||||
in nsIURI aURI,
|
||||
in nsILoadGroup aLoadGroup,
|
||||
in nsIInterfaceRequestor notificationCallbacks,
|
||||
in nsLoadFlags loadAttributes,
|
||||
in nsIURI originalURI,
|
||||
in unsigned long bufferSegmentSize,
|
||||
in unsigned long bufferMaxSize);
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
||||
@@ -32,19 +32,11 @@ interface nsIRequest : nsISupports
|
||||
*/
|
||||
boolean isPending();
|
||||
|
||||
/**
|
||||
* Returns any error status associated with the request.
|
||||
*/
|
||||
readonly attribute nsresult status;
|
||||
|
||||
/**
|
||||
* Cancels the current request. This will close any open input or
|
||||
* output streams and terminate any async requests. Users should
|
||||
* normally pass NS_BINDING_ABORTED, although other errors may also
|
||||
* be passed. The error passed in will become the value of the
|
||||
* status attribute.
|
||||
* output streams and terminate any async requests.
|
||||
*/
|
||||
void cancel(in nsresult status);
|
||||
void cancel();
|
||||
|
||||
/**
|
||||
* Suspends the current requests. This may have the effect of closing
|
||||
|
||||
@@ -27,29 +27,9 @@ interface nsISocketTransport : nsISupports
|
||||
{
|
||||
attribute boolean reuseConnection;
|
||||
|
||||
/**
|
||||
* socket read/write timeout in seconds; 0 = no timeout
|
||||
*/
|
||||
attribute unsigned long socketTimeout;
|
||||
|
||||
/**
|
||||
* socket connect timeout in seconds; 0 = no timeout
|
||||
*/
|
||||
attribute unsigned long socketConnectTimeout;
|
||||
|
||||
/**
|
||||
* Is used to tell the channel to stop reading data after a certain point;
|
||||
* needed by HTTP/1.1
|
||||
*/
|
||||
attribute long bytesExpected;
|
||||
attribute unsigned long reuseCount;
|
||||
|
||||
/**
|
||||
* Checks if the socket is still alive
|
||||
*
|
||||
* @param seconds amount of time after which the socket is always deemed to be
|
||||
* dead (no further checking is done in this case); seconds = 0
|
||||
* will cause it not to do the timeout checking at all
|
||||
*/
|
||||
boolean isAlive (in unsigned long seconds);
|
||||
attribute long bytesAllowed;
|
||||
};
|
||||
|
||||
@@ -56,9 +56,8 @@ interface nsISocketTransportService : nsISupports
|
||||
*/
|
||||
boolean reuseTransport(in nsIChannel i_Transport);
|
||||
|
||||
void init();
|
||||
void shutdown();
|
||||
void wakeup(in nsIChannel i_Transport);
|
||||
void shutdown ();
|
||||
void wakeup (in nsIChannel i_Transport);
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
||||
@@ -55,11 +55,6 @@ interface nsIStreamLoader : nsISupports
|
||||
* Gets the number of bytes read so far.
|
||||
*/
|
||||
readonly attribute unsigned long numBytesRead;
|
||||
|
||||
/**
|
||||
* Gets the owner of this file
|
||||
*/
|
||||
readonly attribute nsISupports owner;
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
||||
@@ -142,7 +142,6 @@ interface nsIFile;
|
||||
* nsIFileURL is used for the file: protocol, and gives access to the
|
||||
* underlying nsIFile object.
|
||||
*/
|
||||
[scriptable, uuid(d26b2e2e-1dd1-11b2-88f3-8545a7ba7949)]
|
||||
interface nsIFileURL : nsIURL
|
||||
{
|
||||
attribute nsIFile file;
|
||||
|
||||
@@ -37,94 +37,47 @@
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIHTTPProtocolHandler.h"
|
||||
#include "nsIStreamLoader.h"
|
||||
#include "prio.h" // for read/write flags, permissions, etc.
|
||||
|
||||
inline nsresult
|
||||
NS_NewURI(nsIURI* *result,
|
||||
const char* spec,
|
||||
nsIURI* baseURI = nsnull,
|
||||
nsIIOService* ioService = nsnull) // pass in nsIIOService to optimize callers
|
||||
NS_NewURI(nsIURI* *result, const char* spec, nsIURI* baseURI = nsnull)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsIIOService* serv = ioService;
|
||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
if (serv == nsnull) {
|
||||
rv = nsServiceManager::GetService(kIOServiceCID, NS_GET_IID(nsIIOService),
|
||||
(nsISupports**)&serv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = serv->NewURI(spec, baseURI, result);
|
||||
|
||||
if (ioService == nsnull) {
|
||||
(void)nsServiceManager::ReleaseService(kIOServiceCID, serv);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_NewURI(nsIURI* *result,
|
||||
const nsString& spec,
|
||||
nsIURI* baseURI = nsnull,
|
||||
nsIIOService* ioService = nsnull) // pass in nsIIOService to optimize callers
|
||||
NS_NewURI(nsIURI* *result, const nsString& spec, nsIURI* baseURI = nsnull)
|
||||
{
|
||||
char* specStr = spec.ToNewUTF8String(); // this forces a single byte char*
|
||||
if (specStr == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
nsresult rv = NS_NewURI(result, specStr, baseURI, ioService);
|
||||
nsresult rv = NS_NewURI(result, specStr, baseURI);
|
||||
nsAllocator::Free(specStr);
|
||||
return rv;
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_OpenURI(nsIChannel* *result,
|
||||
nsIURI* uri,
|
||||
nsIIOService* ioService = nsnull, // pass in nsIIOService to optimize callers
|
||||
nsILoadGroup* loadGroup = nsnull,
|
||||
nsIInterfaceRequestor* notificationCallbacks = nsnull,
|
||||
NS_OpenURI(nsIChannel* *result, nsIURI* uri, nsILoadGroup *aGroup,
|
||||
nsIInterfaceRequestor *capabilities = nsnull,
|
||||
nsLoadFlags loadAttributes = nsIChannel::LOAD_NORMAL,
|
||||
PRUint32 bufferSegmentSize = 0,
|
||||
PRUint32 bufferMaxSize = 0)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsIIOService* serv = ioService;
|
||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
if (serv == nsnull) {
|
||||
rv = nsServiceManager::GetService(kIOServiceCID, NS_GET_IID(nsIIOService),
|
||||
(nsISupports**)&serv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
nsIChannel* channel = nsnull;
|
||||
rv = serv->NewChannelFromURI(uri, &channel);
|
||||
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (loadGroup) {
|
||||
rv = channel->SetLoadGroup(loadGroup);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
if (notificationCallbacks) {
|
||||
rv = channel->SetNotificationCallbacks(notificationCallbacks);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
if (loadAttributes != nsIChannel::LOAD_NORMAL) {
|
||||
rv = channel->SetLoadAttributes(loadAttributes);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
if (bufferSegmentSize != 0) {
|
||||
rv = channel->SetBufferSegmentSize(bufferSegmentSize);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
if (bufferMaxSize != 0) {
|
||||
rv = channel->SetBufferMaxSize(bufferMaxSize);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
if (ioService == nsnull) {
|
||||
(void)nsServiceManager::ReleaseService(kIOServiceCID, serv);
|
||||
}
|
||||
nsIChannel* channel;
|
||||
rv = serv->NewChannelFromURI("load", uri, aGroup, capabilities,
|
||||
loadAttributes, nsnull,
|
||||
bufferSegmentSize, bufferMaxSize, &channel);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*result = channel;
|
||||
return rv;
|
||||
@@ -137,25 +90,17 @@ NS_OpenURI(nsIChannel* *result,
|
||||
// blown asyncrhonous consumer (via nsIStreamListener)
|
||||
// look at nsIStreamLoader instead.
|
||||
inline nsresult
|
||||
NS_OpenURI(nsIInputStream* *result,
|
||||
nsIURI* uri,
|
||||
nsIIOService* ioService = nsnull, // pass in nsIIOService to optimize callers
|
||||
nsILoadGroup* loadGroup = nsnull,
|
||||
nsIInterfaceRequestor* notificationCallbacks = nsnull,
|
||||
nsLoadFlags loadAttributes = nsIChannel::LOAD_NORMAL,
|
||||
PRUint32 bufferSegmentSize = 0,
|
||||
PRUint32 bufferMaxSize = 0)
|
||||
NS_OpenURI(nsIInputStream* *result, nsIURI* uri)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
nsIChannel* channel;
|
||||
|
||||
rv = NS_OpenURI(getter_AddRefs(channel), uri, ioService,
|
||||
loadGroup, notificationCallbacks, loadAttributes,
|
||||
bufferSegmentSize, bufferMaxSize);
|
||||
rv = NS_OpenURI(&channel, uri, nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsIInputStream* inStr;
|
||||
rv = channel->OpenInputStream(&inStr);
|
||||
rv = channel->OpenInputStream(0, -1, &inStr);
|
||||
NS_RELEASE(channel);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*result = inStr;
|
||||
@@ -163,109 +108,71 @@ NS_OpenURI(nsIInputStream* *result,
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_OpenURI(nsIStreamListener* aConsumer,
|
||||
nsISupports* context,
|
||||
nsIURI* uri,
|
||||
nsIIOService* ioService = nsnull, // pass in nsIIOService to optimize callers
|
||||
nsILoadGroup* loadGroup = nsnull,
|
||||
nsIInterfaceRequestor* notificationCallbacks = nsnull,
|
||||
nsLoadFlags loadAttributes = nsIChannel::LOAD_NORMAL,
|
||||
PRUint32 bufferSegmentSize = 0,
|
||||
PRUint32 bufferMaxSize = 0)
|
||||
NS_OpenURI(nsIStreamListener* aConsumer, nsISupports* context, nsIURI* uri,
|
||||
nsILoadGroup *aGroup)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
nsIChannel* channel;
|
||||
|
||||
rv = NS_OpenURI(getter_AddRefs(channel), uri, ioService,
|
||||
loadGroup, notificationCallbacks, loadAttributes,
|
||||
bufferSegmentSize, bufferMaxSize);
|
||||
rv = NS_OpenURI(&channel, uri, aGroup);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = channel->AsyncRead(aConsumer, context);
|
||||
rv = channel->AsyncRead(0, -1, context, aConsumer);
|
||||
NS_RELEASE(channel);
|
||||
return rv;
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_MakeAbsoluteURI(char* *result,
|
||||
const char* spec,
|
||||
nsIURI* baseURI = nsnull,
|
||||
nsIIOService* ioService = nsnull) // pass in nsIIOService to optimize callers
|
||||
NS_MakeAbsoluteURI(const char* spec, nsIURI* baseURI, char* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_ASSERTION(baseURI, "It doesn't make sense to not supply a base URI");
|
||||
|
||||
if (spec == nsnull)
|
||||
return baseURI->GetSpec(result);
|
||||
|
||||
nsIIOService* serv = ioService;
|
||||
|
||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
if (serv == nsnull) {
|
||||
rv = nsServiceManager::GetService(kIOServiceCID, NS_GET_IID(nsIIOService),
|
||||
(nsISupports**)&serv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
|
||||
|
||||
PRUint32 startPos, endPos;
|
||||
rv = serv->ExtractScheme(spec, &startPos, &endPos, nsnull);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// if spec has a scheme, then it's already absolute
|
||||
*result = nsCRT::strdup(spec);
|
||||
rv = (*result == nsnull) ? NS_ERROR_OUT_OF_MEMORY : NS_OK;
|
||||
return (*result == nsnull) ? NS_ERROR_OUT_OF_MEMORY : NS_OK;
|
||||
}
|
||||
else {
|
||||
rv = baseURI->Resolve(spec, result);
|
||||
}
|
||||
|
||||
if (ioService == nsnull) {
|
||||
(void)nsServiceManager::ReleaseService(kIOServiceCID, serv);
|
||||
}
|
||||
return rv;
|
||||
|
||||
return baseURI->Resolve(spec, result);
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_MakeAbsoluteURI(nsString& result,
|
||||
const nsString& spec,
|
||||
nsIURI* baseURI = nsnull,
|
||||
nsIIOService* ioService = nsnull) // pass in nsIIOService to optimize callers
|
||||
NS_MakeAbsoluteURI(const nsString& spec, nsIURI* baseURI, nsString& result)
|
||||
{
|
||||
char* resultStr;
|
||||
char* specStr = spec.ToNewUTF8String();
|
||||
if (!specStr) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
nsresult rv = NS_MakeAbsoluteURI(&resultStr, specStr, baseURI, ioService);
|
||||
nsresult rv = NS_MakeAbsoluteURI(specStr, baseURI, &resultStr);
|
||||
nsAllocator::Free(specStr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
result.AssignWithConversion(resultStr);
|
||||
result = resultStr;
|
||||
nsAllocator::Free(resultStr);
|
||||
return rv;
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_NewPostDataStream(nsIInputStream **result,
|
||||
PRBool isFile,
|
||||
const char *data,
|
||||
PRUint32 encodeFlags,
|
||||
nsIIOService* ioService = nsnull) // pass in nsIIOService to optimize callers
|
||||
NS_NewPostDataStream(PRBool isFile, const char *data, PRUint32 encodeFlags,
|
||||
nsIInputStream **result)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsIIOService* serv = ioService;
|
||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
if (serv == nsnull) {
|
||||
rv = nsServiceManager::GetService(kIOServiceCID, NS_GET_IID(nsIIOService),
|
||||
(nsISupports**)&serv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIProtocolHandler> handler;
|
||||
rv = serv->GetProtocolHandler("http", getter_AddRefs(handler));
|
||||
|
||||
if (ioService == nsnull) {
|
||||
(void)nsServiceManager::ReleaseService(kIOServiceCID, serv);
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIHTTPProtocolHandler> http = do_QueryInterface(handler, &rv);
|
||||
@@ -275,11 +182,17 @@ NS_NewPostDataStream(nsIInputStream **result,
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_NewInputStreamChannel(nsIChannel **result,
|
||||
nsIURI* uri,
|
||||
NS_NewInputStreamChannel(nsIURI* uri,
|
||||
const char* contentType,
|
||||
PRInt32 contentLength,
|
||||
nsIInputStream* inStr,
|
||||
const char* contentType,
|
||||
PRInt32 contentLength)
|
||||
nsILoadGroup* group,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize,
|
||||
nsIChannel **result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIInputStreamChannel> channel;
|
||||
@@ -289,7 +202,9 @@ NS_NewInputStreamChannel(nsIChannel **result,
|
||||
NS_GET_IID(nsIInputStreamChannel),
|
||||
getter_AddRefs(channel));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = channel->Init(uri, inStr, contentType, contentLength);
|
||||
rv = channel->Init(uri, contentType, contentLength, inStr, group,
|
||||
notificationCallbacks, loadAttributes, originalURI,
|
||||
bufferSegmentSize, bufferMaxSize);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*result = channel;
|
||||
@@ -298,7 +213,7 @@ NS_NewInputStreamChannel(nsIChannel **result,
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_NewLoadGroup(nsILoadGroup* *result, nsIStreamObserver* obs)
|
||||
NS_NewLoadGroup(nsIStreamObserver* obs, nsILoadGroup* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsILoadGroup> group;
|
||||
@@ -344,9 +259,8 @@ NS_NewStreamLoader(nsIStreamLoader* *result,
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_NewAsyncStreamObserver(nsIStreamObserver **result,
|
||||
nsIStreamObserver *receiver,
|
||||
nsIEventQueue *eventQueue)
|
||||
NS_NewAsyncStreamObserver(nsIStreamObserver *receiver, nsIEventQueue *eventQueue,
|
||||
nsIStreamObserver **result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIAsyncStreamObserver> obs;
|
||||
@@ -365,9 +279,8 @@ NS_NewAsyncStreamObserver(nsIStreamObserver **result,
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_NewAsyncStreamListener(nsIStreamListener **result,
|
||||
nsIStreamListener *receiver,
|
||||
nsIEventQueue *eventQueue)
|
||||
NS_NewAsyncStreamListener(nsIStreamListener *receiver, nsIEventQueue *eventQueue,
|
||||
nsIStreamListener **result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIAsyncStreamListener> lsnr;
|
||||
|
||||
@@ -95,18 +95,7 @@ void PR_CALLBACK nsStreamListenerEvent::HandlePLEvent(PLEvent* aEvent)
|
||||
NS_ASSERTION(nsnull != ev,"null event.");
|
||||
|
||||
nsresult rv = ev->HandleEvent();
|
||||
//
|
||||
// If the consumer fails, then cancel the transport. This is necessary
|
||||
// in case where the socket transport is blocked waiting for room in the
|
||||
// pipe, but the consumer fails without consuming all the data.
|
||||
//
|
||||
// Unless the transport is cancelled, it will block forever, waiting for
|
||||
// the pipe to empty...
|
||||
//
|
||||
if (NS_FAILED(rv)) {
|
||||
nsresult cancelRv = ev->mChannel->Cancel(rv);
|
||||
NS_ASSERTION(NS_SUCCEEDED(cancelRv), "Cancel failed");
|
||||
}
|
||||
ev->mListener->SetStatus(rv);
|
||||
}
|
||||
|
||||
void PR_CALLBACK nsStreamListenerEvent::DestroyPLEvent(PLEvent* aEvent)
|
||||
@@ -139,9 +128,15 @@ nsStreamListenerEvent::Fire(nsIEventQueue* aEventQueue)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS2(nsAsyncStreamObserver,
|
||||
nsIAsyncStreamObserver,
|
||||
nsIStreamObserver)
|
||||
nsAsyncStreamObserver::~nsAsyncStreamObserver()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_THREADSAFE_ADDREF(nsAsyncStreamObserver)
|
||||
NS_IMPL_THREADSAFE_RELEASE(nsAsyncStreamObserver)
|
||||
NS_IMPL_QUERY_INTERFACE2(nsAsyncStreamObserver,
|
||||
nsIAsyncStreamObserver,
|
||||
nsIStreamObserver)
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(nsAsyncStreamListener, nsAsyncStreamObserver);
|
||||
NS_IMPL_RELEASE_INHERITED(nsAsyncStreamListener, nsAsyncStreamObserver);
|
||||
@@ -204,23 +199,15 @@ nsOnStartRequestEvent::HandleEvent()
|
||||
("netlibEvent: Handle Start [event=%x]", this));
|
||||
#endif
|
||||
nsIStreamObserver* receiver = (nsIStreamObserver*)mListener->GetReceiver();
|
||||
nsresult status;
|
||||
nsresult rv = mChannel->GetStatus(&status);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "GetStatus failed");
|
||||
|
||||
if (NS_SUCCEEDED(rv) && NS_SUCCEEDED(status)) {
|
||||
rv = receiver->OnStartRequest(mChannel, mContext);
|
||||
}
|
||||
else {
|
||||
NS_WARNING("not calling OnStartRequest");
|
||||
}
|
||||
return rv;
|
||||
return receiver->OnStartRequest(mChannel, mContext);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAsyncStreamObserver::OnStartRequest(nsIChannel* channel, nsISupports* context)
|
||||
{
|
||||
nsresult rv;
|
||||
nsresult rv = GetStatus();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsOnStartRequestEvent* event =
|
||||
new nsOnStartRequestEvent(this, channel, context);
|
||||
if (event == nsnull)
|
||||
@@ -292,16 +279,14 @@ nsOnStopRequestEvent::HandleEvent()
|
||||
("netlibEvent: Handle Stop [event=%x]", this));
|
||||
#endif
|
||||
nsIStreamObserver* receiver = (nsIStreamObserver*)mListener->GetReceiver();
|
||||
nsresult status = NS_OK;
|
||||
nsresult rv = mChannel->GetStatus(&status);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "GetStatus failed");
|
||||
nsresult rv = mListener->GetStatus();
|
||||
|
||||
//
|
||||
// If the consumer returned a failure code, then pass it out in the
|
||||
// OnStopRequest(...) notification...
|
||||
//
|
||||
if (NS_SUCCEEDED(rv) && NS_FAILED(status)) {
|
||||
mStatus = status;
|
||||
if (NS_FAILED(rv)) {
|
||||
mStatus = rv;
|
||||
}
|
||||
return receiver->OnStopRequest(mChannel, mContext, mStatus, mMessage);
|
||||
}
|
||||
@@ -393,20 +378,25 @@ nsOnDataAvailableEvent::HandleEvent()
|
||||
("netlibEvent: Handle Data [event=%x]", this));
|
||||
#endif
|
||||
nsIStreamListener* receiver = (nsIStreamListener*)mListener->GetReceiver();
|
||||
nsresult status;
|
||||
nsresult rv = mChannel->GetStatus(&status);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "GetStatus failed");
|
||||
|
||||
nsresult rv = mListener->GetStatus();
|
||||
//
|
||||
// Only send OnDataAvailable(... ) notifications if all previous calls
|
||||
// have succeeded...
|
||||
//
|
||||
if (NS_SUCCEEDED(rv) && NS_SUCCEEDED(status)) {
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = receiver->OnDataAvailable(mChannel, mContext,
|
||||
mIStream, mSourceOffset, mLength);
|
||||
}
|
||||
else {
|
||||
NS_WARNING("not calling OnDataAvailable");
|
||||
//
|
||||
// If the consumer fails, then cancel the transport. This is necessary
|
||||
// in case where the socket transport is blocked waiting for room in the
|
||||
// pipe, but the consumer fails without consuming all the data.
|
||||
//
|
||||
// Unless the transport is cancelled, it will block forever, waiting for
|
||||
// the pipe to empty...
|
||||
//
|
||||
if (NS_FAILED(rv)) {
|
||||
mChannel->Cancel();
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
@@ -417,7 +407,9 @@ nsAsyncStreamListener::OnDataAvailable(nsIChannel* channel, nsISupports* context
|
||||
PRUint32 aSourceOffset,
|
||||
PRUint32 aLength)
|
||||
{
|
||||
nsresult rv;
|
||||
nsresult rv = GetStatus();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsOnDataAvailableEvent* event =
|
||||
new nsOnDataAvailableEvent(this, channel, context);
|
||||
if (event == nsnull)
|
||||
|
||||
@@ -40,20 +40,24 @@ public:
|
||||
|
||||
// nsAsyncStreamObserver methods:
|
||||
nsAsyncStreamObserver()
|
||||
: mStatus(NS_OK)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
virtual ~nsAsyncStreamObserver() {}
|
||||
virtual ~nsAsyncStreamObserver();
|
||||
|
||||
static NS_METHOD
|
||||
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
nsISupports* GetReceiver() { return mReceiver.get(); }
|
||||
nsresult GetStatus() { return mStatus; }
|
||||
void SetStatus(nsresult value) { if (NS_SUCCEEDED(mStatus)) mStatus = value; }
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIEventQueue> mEventQueue;
|
||||
nsCOMPtr<nsIStreamObserver> mReceiver;
|
||||
nsresult mStatus;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -90,13 +94,7 @@ public:
|
||||
}
|
||||
|
||||
// nsAsyncStreamListener methods:
|
||||
nsAsyncStreamListener() {
|
||||
MOZ_COUNT_CTOR(nsAsyncStreamListener);
|
||||
}
|
||||
|
||||
virtual ~nsAsyncStreamListener() {
|
||||
MOZ_COUNT_DTOR(nsAsyncStreamListener);
|
||||
}
|
||||
nsAsyncStreamListener() {}
|
||||
|
||||
static NS_METHOD
|
||||
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
@@ -227,9 +227,6 @@ nsAuthURLParser::ParseAtHost(const char* i_Spec, char* *o_Host,
|
||||
if (!brk) // everything is a host
|
||||
{
|
||||
rv = ExtractString((char*)i_Spec, o_Host, len);
|
||||
if (PL_strlen(*o_Host)==0) {
|
||||
return NS_ERROR_MALFORMED_URI;
|
||||
}
|
||||
ToLowerCase(*o_Host);
|
||||
return rv;
|
||||
}
|
||||
@@ -242,9 +239,6 @@ nsAuthURLParser::ParseAtHost(const char* i_Spec, char* *o_Host,
|
||||
rv = ExtractString((char*)i_Spec, o_Host, (brk - i_Spec));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
if (PL_strlen(*o_Host)==0) {
|
||||
return NS_ERROR_MALFORMED_URI;
|
||||
}
|
||||
ToLowerCase(*o_Host);
|
||||
rv = ParseAtPath(brk, o_Path);
|
||||
return rv;
|
||||
@@ -254,9 +248,6 @@ nsAuthURLParser::ParseAtHost(const char* i_Spec, char* *o_Host,
|
||||
rv = ExtractString((char*)i_Spec, o_Host, (brk - i_Spec));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
if (PL_strlen(*o_Host)==0) {
|
||||
return NS_ERROR_MALFORMED_URI;
|
||||
}
|
||||
ToLowerCase(*o_Host);
|
||||
rv = ParseAtPort(brk+1, o_Port, o_Path);
|
||||
return rv;
|
||||
@@ -277,37 +268,21 @@ nsAuthURLParser::ParseAtPort(const char* i_Spec, PRInt32 *o_Port,
|
||||
char* brk = PL_strpbrk(i_Spec, delimiters);
|
||||
if (!brk) // everything is a Port
|
||||
{
|
||||
if (PL_strlen(i_Spec)==0) {
|
||||
*o_Port = -1;
|
||||
*o_Port = ExtractPortFrom(i_Spec);
|
||||
if (*o_Port <= 0)
|
||||
return NS_ERROR_MALFORMED_URI;
|
||||
else
|
||||
return NS_OK;
|
||||
} else {
|
||||
*o_Port = ExtractPortFrom(i_Spec);
|
||||
if (*o_Port <= 0)
|
||||
return NS_ERROR_MALFORMED_URI;
|
||||
else
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
char* e_Port = nsnull;
|
||||
switch (*brk)
|
||||
{
|
||||
case '/' :
|
||||
case '?' :
|
||||
// Get the Port, the rest is Path
|
||||
rv = ExtractString((char*)i_Spec, &e_Port, brk-i_Spec);
|
||||
if (NS_FAILED(rv)) {
|
||||
CRTFREEIF(e_Port);
|
||||
return rv;
|
||||
}
|
||||
if (PL_strlen(e_Port)==0) {
|
||||
*o_Port = -1;
|
||||
} else {
|
||||
*o_Port = ExtractPortFrom(e_Port);
|
||||
if (*o_Port <= 0)
|
||||
return NS_ERROR_MALFORMED_URI;
|
||||
}
|
||||
CRTFREEIF(e_Port);
|
||||
*o_Port = ExtractPortFrom(i_Spec);
|
||||
if (*o_Port <= 0)
|
||||
return NS_ERROR_MALFORMED_URI;
|
||||
rv = ParseAtPath(brk, o_Path);
|
||||
return rv;
|
||||
break;
|
||||
|
||||
@@ -279,7 +279,7 @@ nsBufferedOutputStream::Write(const char *buf, PRUint32 count, PRUint32 *result)
|
||||
while (count > 0) {
|
||||
PRUint32 amt = PR_MIN(count, mFillPoint - mCursor);
|
||||
if (amt > 0) {
|
||||
nsCRT::memcpy(mBuffer + mCursor, buf + written, amt);
|
||||
nsCRT::memcpy(mBuffer + mCursor, buf, amt);
|
||||
written += amt;
|
||||
count -= amt;
|
||||
mCursor += amt;
|
||||
|
||||
@@ -219,7 +219,7 @@ nsDirectoryIndexStream::Read(char* aBuf, PRUint32 aCount, PRUint32* aReadCount)
|
||||
}
|
||||
|
||||
// The "content-length" field
|
||||
mBuf.AppendWithConversion(fileInfoSize, 10);
|
||||
mBuf.Append(fileInfoSize, 10);
|
||||
mBuf.Append(' ');
|
||||
|
||||
// The "last-modified" field
|
||||
|
||||
@@ -102,19 +102,10 @@ nsFileInputStream::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileInputStream::Init(nsIFile* file, PRInt32 ioFlags, PRInt32 perm)
|
||||
nsFileInputStream::Init(nsILocalFile* file)
|
||||
{
|
||||
NS_ASSERTION(mFD == nsnull, "already inited");
|
||||
if (mFD != nsnull)
|
||||
return NS_ERROR_FAILURE;
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(file, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (ioFlags == -1)
|
||||
ioFlags = PR_RDONLY;
|
||||
if (perm == -1)
|
||||
perm = 0;
|
||||
return localFile->OpenNSPRFileDesc(ioFlags, perm, &mFD);
|
||||
return file->OpenNSPRFileDesc(PR_RDONLY, 0, &mFD);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@@ -174,19 +165,12 @@ nsFileOutputStream::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileOutputStream::Init(nsIFile* file, PRInt32 ioFlags, PRInt32 perm)
|
||||
nsFileOutputStream::Init(nsILocalFile* file, PRInt32 flags, PRInt32 mode)
|
||||
{
|
||||
NS_ASSERTION(mFD == nsnull, "already inited");
|
||||
if (mFD != nsnull)
|
||||
return NS_ERROR_FAILURE;
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(file, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (ioFlags == -1)
|
||||
ioFlags = PR_WRONLY | PR_CREATE_FILE;
|
||||
if (perm == -1)
|
||||
perm = 0664;
|
||||
return localFile->OpenNSPRFileDesc(ioFlags, perm, &mFD);
|
||||
return file->OpenNSPRFileDesc(flags, mode, &mFD);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
||||
@@ -58,7 +58,7 @@ static NS_DEFINE_CID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID);
|
||||
|
||||
#if defined(PR_LOGGING)
|
||||
//
|
||||
// Log module for nsFileTransport logging...
|
||||
// Log module for SocketTransport logging...
|
||||
//
|
||||
// To enable logging (see prlog.h for full details):
|
||||
//
|
||||
@@ -74,7 +74,7 @@ PRLogModuleInfo* gFileTransportLog = nsnull;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define DEFAULT_TYPE "application/x-unknown-content-type"
|
||||
#define DEFAULT_TYPE "text/html"
|
||||
|
||||
class nsLocalFileSystem : public nsIFileSystem
|
||||
{
|
||||
@@ -109,20 +109,41 @@ public:
|
||||
*contentLength = -1;
|
||||
}
|
||||
else {
|
||||
|
||||
NS_WITH_SERVICE(nsIMIMEService, mimeServ, kMIMEServiceCID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = mimeServ->GetTypeFromFile(mFile, contentType);
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
// if all else fails treat it as text/html?
|
||||
*contentType = nsCRT::strdup(DEFAULT_TYPE);
|
||||
if (*contentType == nsnull)
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
else
|
||||
rv = NS_OK;
|
||||
}
|
||||
char* fileName;
|
||||
rv = mFile->GetLeafName(&fileName);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (fileName != nsnull) {
|
||||
PRInt32 len = nsCRT::strlen(fileName);
|
||||
const char* ext = nsnull;
|
||||
for (PRInt32 i = len; i >= 0; i--) {
|
||||
if (fileName[i] == '.') {
|
||||
ext = &fileName[i + 1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ext) {
|
||||
NS_WITH_SERVICE(nsIMIMEService, mimeServ, kMIMEServiceCID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = mimeServ->GetTypeFromExtension(ext, contentType);
|
||||
}
|
||||
}
|
||||
else
|
||||
rv = NS_ERROR_FAILURE;
|
||||
|
||||
nsCRT::free(fileName);
|
||||
} else {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
// if all else fails treat it as text/html?
|
||||
*contentType = nsCRT::strdup(DEFAULT_TYPE);
|
||||
if (*contentType == nsnull)
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
else
|
||||
rv = NS_OK;
|
||||
}
|
||||
}
|
||||
PR_LOG(gFileTransportLog, PR_LOG_DEBUG,
|
||||
("nsFileTransport: logically opening %s: type=%s len=%d",
|
||||
@@ -150,27 +171,15 @@ public:
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIInputStream> fileIn;
|
||||
rv = NS_NewLocalFileInputStream(getter_AddRefs(fileIn), mFile, mIOFlags, mPerm);
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
#if DEBUG
|
||||
char* filePath = nsnull;
|
||||
mFile->GetPath(&filePath);
|
||||
if (filePath)
|
||||
{
|
||||
printf("Opening %s failed\n", filePath);
|
||||
nsAllocator::Free(filePath);
|
||||
}
|
||||
#endif
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = NS_NewFileInputStream(mFile, getter_AddRefs(fileIn));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
#ifdef NO_BUFFERING
|
||||
*aInputStream = fileIn;
|
||||
NS_ADDREF(*aInputStream);
|
||||
#else
|
||||
rv = NS_NewBufferedInputStream(aInputStream,
|
||||
fileIn, NS_OUTPUT_STREAM_BUFFER_SIZE);
|
||||
rv = NS_NewBufferedInputStream(fileIn, NS_OUTPUT_STREAM_BUFFER_SIZE,
|
||||
aInputStream);
|
||||
#endif
|
||||
|
||||
// printf("opening %s for reading\n", (const char*)mSpec);
|
||||
@@ -189,16 +198,18 @@ public:
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIOutputStream> fileOut;
|
||||
rv = NS_NewLocalFileOutputStream(getter_AddRefs(fileOut),
|
||||
mFile, mIOFlags, mPerm);
|
||||
rv = NS_NewFileOutputStream(mFile,
|
||||
PR_CREATE_FILE | PR_WRONLY,
|
||||
0664,
|
||||
getter_AddRefs(fileOut));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIOutputStream> bufStr;
|
||||
#ifdef NO_BUFFERING
|
||||
bufStr = fileOut;
|
||||
#else
|
||||
rv = NS_NewBufferedOutputStream(getter_AddRefs(bufStr),
|
||||
fileOut, NS_OUTPUT_STREAM_BUFFER_SIZE);
|
||||
rv = NS_NewBufferedOutputStream(fileOut, NS_OUTPUT_STREAM_BUFFER_SIZE,
|
||||
getter_AddRefs(bufStr));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
#endif
|
||||
|
||||
@@ -212,8 +223,7 @@ public:
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsLocalFileSystem(nsIFile* file, PRInt32 ioFlags, PRInt32 perm)
|
||||
: mFile(file), mIOFlags(ioFlags), mPerm(perm) {
|
||||
nsLocalFileSystem(nsIFile* file) : mFile(file) {
|
||||
NS_INIT_REFCNT();
|
||||
//#ifdef PR_LOGGING
|
||||
(void)mFile->GetPath(&mSpec);
|
||||
@@ -226,9 +236,8 @@ public:
|
||||
//#endif
|
||||
}
|
||||
|
||||
static nsresult Create(nsIFile* file, PRInt32 ioFlags, PRInt32 perm,
|
||||
nsIFileSystem* *result) {
|
||||
nsLocalFileSystem* fs = new nsLocalFileSystem(file, ioFlags, perm);
|
||||
static nsresult Create(nsIFile* file, nsIFileSystem* *result) {
|
||||
nsLocalFileSystem* fs = new nsLocalFileSystem(file);
|
||||
if (fs == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(fs);
|
||||
@@ -238,8 +247,6 @@ public:
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIFile> mFile;
|
||||
PRInt32 mIOFlags;
|
||||
PRInt32 mPerm;
|
||||
//#ifdef PR_LOGGING
|
||||
char* mSpec;
|
||||
//#endif
|
||||
@@ -322,10 +329,6 @@ NS_IMPL_THREADSAFE_ISUPPORTS1(nsInputStreamFileSystem, nsIFileSystem);
|
||||
|
||||
nsFileTransport::nsFileTransport()
|
||||
: mContentType(nsnull),
|
||||
mBufferSegmentSize(NS_FILE_TRANSPORT_DEFAULT_SEGMENT_SIZE),
|
||||
mBufferMaxSize(NS_FILE_TRANSPORT_DEFAULT_BUFFER_SIZE),
|
||||
mIOFlags(-1),
|
||||
mPerm(-1),
|
||||
mState(CLOSED),
|
||||
mCommand(NONE),
|
||||
mSuspended(PR_FALSE),
|
||||
@@ -333,7 +336,7 @@ nsFileTransport::nsFileTransport()
|
||||
mStatus(NS_OK),
|
||||
mOffset(0),
|
||||
mTotalAmount(-1),
|
||||
mTransferAmount(-1),
|
||||
mTransferAmount(0),
|
||||
mBuffer(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
@@ -352,50 +355,50 @@ nsFileTransport::nsFileTransport()
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsFileTransport::Init(nsIFile* file, PRInt32 ioFlags, PRInt32 perm)
|
||||
nsFileTransport::Init(nsIFile* file, PRInt32 mode, const char* command,
|
||||
PRUint32 bufferSegmentSize, PRUint32 bufferMaxSize)
|
||||
{
|
||||
nsresult rv;
|
||||
mFile = file;
|
||||
mIOFlags = ioFlags;
|
||||
mPerm = perm;
|
||||
#if 0
|
||||
nsCOMPtr<nsIFileChannel> channel;
|
||||
rv = NS_NewLocalFileChannel(file,
|
||||
ioFlags,
|
||||
perm,
|
||||
nsnull, // contentType -- infer
|
||||
0, // contentLength -- infer
|
||||
nsnull, // loadGroup
|
||||
nsnull, // notificationCallbacks
|
||||
nsIChannel::LOAD_NORMAL,
|
||||
nsnull, // originalURI
|
||||
bufferSegmentSize,
|
||||
bufferMaxSize,
|
||||
getter_AddRefs(channel));
|
||||
rv = NS_NewFileChannel(file,
|
||||
mode,
|
||||
nsnull, // contentType -- infer
|
||||
0, // contentLength -- infer
|
||||
nsnull, // loadGroup
|
||||
nsnull, // notificationCallbacks
|
||||
nsIChannel::LOAD_NORMAL,
|
||||
nsnull, // originalURI
|
||||
bufferSegmentSize,
|
||||
bufferMaxSize,
|
||||
getter_AddRefs(channel));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr<nsIFileSystem> fsObj = do_QueryInterface(channel, &rv);
|
||||
#else
|
||||
nsCOMPtr<nsIFileSystem> fsObj;
|
||||
rv = nsLocalFileSystem::Create(file, ioFlags, perm, getter_AddRefs(fsObj));
|
||||
rv = nsLocalFileSystem::Create(file, getter_AddRefs(fsObj));
|
||||
#endif
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return Init(fsObj);
|
||||
return Init(fsObj, command, bufferSegmentSize, bufferMaxSize);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsFileTransport::Init(nsIInputStream* fromStream, const char* contentType,
|
||||
PRInt32 contentLength)
|
||||
PRInt32 contentLength, const char* command,
|
||||
PRUint32 bufferSegmentSize, PRUint32 bufferMaxSize)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIFileSystem> fsObj;
|
||||
rv = nsInputStreamFileSystem::Create(fromStream, contentType, contentLength,
|
||||
getter_AddRefs(fsObj));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return Init(fsObj);
|
||||
return Init(fsObj, command, bufferSegmentSize, bufferMaxSize);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsFileTransport::Init(nsIFileSystem* fsObj)
|
||||
nsFileTransport::Init(nsIFileSystem* fsObj, const char* command,
|
||||
PRUint32 bufferSegmentSize, PRUint32 bufferMaxSize)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (mMonitor == nsnull) {
|
||||
@@ -404,6 +407,10 @@ nsFileTransport::Init(nsIFileSystem* fsObj)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
mFileObject = fsObj;
|
||||
mBufferSegmentSize = bufferSegmentSize != 0
|
||||
? bufferSegmentSize : NS_FILE_TRANSPORT_DEFAULT_SEGMENT_SIZE;
|
||||
mBufferMaxSize = bufferMaxSize != 0
|
||||
? bufferMaxSize : NS_FILE_TRANSPORT_DEFAULT_BUFFER_SIZE;
|
||||
#ifdef PR_LOGGING
|
||||
if (mFile)
|
||||
(void)mFile->GetPath(&mSpec);
|
||||
@@ -463,14 +470,7 @@ nsFileTransport::IsPending(PRBool *result)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransport::GetStatus(nsresult *status)
|
||||
{
|
||||
*status = mStatus;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransport::Cancel(nsresult status)
|
||||
nsFileTransport::Cancel()
|
||||
{
|
||||
nsAutoMonitor mon(mMonitor);
|
||||
|
||||
@@ -480,7 +480,7 @@ nsFileTransport::Cancel(nsresult status)
|
||||
}
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// if there's no other error pending, say that we aborted
|
||||
mStatus = status;
|
||||
mStatus = NS_BINDING_ABORTED;
|
||||
}
|
||||
if (mState == READING)
|
||||
mState = END_READ;
|
||||
@@ -535,7 +535,8 @@ nsFileTransport::Resume()
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransport::OpenInputStream(nsIInputStream **result)
|
||||
nsFileTransport::OpenInputStream(PRUint32 startPosition, PRInt32 readCount,
|
||||
nsIInputStream **result)
|
||||
{
|
||||
nsAutoMonitor mon(mMonitor);
|
||||
|
||||
@@ -549,7 +550,7 @@ nsFileTransport::OpenInputStream(nsIInputStream **result)
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (!exists)
|
||||
return NS_ERROR_FILE_NOT_FOUND;
|
||||
return NS_ERROR_FAILURE; // XXX probably need NS_BASE_STREAM_FILE_NOT_FOUND or something
|
||||
|
||||
rv = NS_NewPipe(getter_AddRefs(mBufferInputStream),
|
||||
getter_AddRefs(mBufferOutputStream),
|
||||
@@ -562,13 +563,15 @@ nsFileTransport::OpenInputStream(nsIInputStream **result)
|
||||
|
||||
mState = OPENING;
|
||||
mCommand = INITIATE_READ;
|
||||
mOffset = startPosition;
|
||||
mTransferAmount = readCount;
|
||||
mListener = null_nsCOMPtr();
|
||||
|
||||
*result = mBufferInputStream.get();
|
||||
NS_ADDREF(*result);
|
||||
PR_LOG(gFileTransportLog, PR_LOG_DEBUG,
|
||||
("nsFileTransport: OpenInputStream [this=%x %s] mOffset=%d mTransferAmount=%d",
|
||||
this, (const char*)mSpec, mOffset, mTransferAmount));
|
||||
("nsFileTransport: OpenInputStream [this=%x %s] startPosition=%d readCount=%d",
|
||||
this, (const char*)mSpec, startPosition, readCount));
|
||||
|
||||
NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
@@ -579,7 +582,7 @@ nsFileTransport::OpenInputStream(nsIInputStream **result)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransport::OpenOutputStream(nsIOutputStream **result)
|
||||
nsFileTransport::OpenOutputStream(PRUint32 startPosition, nsIOutputStream **result)
|
||||
{
|
||||
nsAutoMonitor mon(mMonitor);
|
||||
|
||||
@@ -589,22 +592,25 @@ nsFileTransport::OpenOutputStream(nsIOutputStream **result)
|
||||
return NS_ERROR_IN_PROGRESS;
|
||||
|
||||
nsCOMPtr<nsIOutputStream> fileOut;
|
||||
rv = NS_NewLocalFileOutputStream(getter_AddRefs(fileOut),
|
||||
mFile, mIOFlags, mPerm);
|
||||
rv = NS_NewFileOutputStream(mFile,
|
||||
PR_CREATE_FILE | PR_WRONLY,
|
||||
0664,
|
||||
getter_AddRefs(fileOut));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIOutputStream> bufStr;
|
||||
#ifdef NO_BUFFERING
|
||||
bufStr = fileOut;
|
||||
#else
|
||||
rv = NS_NewBufferedOutputStream(getter_AddRefs(bufStr),
|
||||
fileOut, NS_OUTPUT_STREAM_BUFFER_SIZE);
|
||||
rv = NS_NewBufferedOutputStream(fileOut, NS_OUTPUT_STREAM_BUFFER_SIZE,
|
||||
getter_AddRefs(bufStr));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
#endif
|
||||
|
||||
*result = bufStr;
|
||||
NS_ADDREF(*result);
|
||||
|
||||
mOffset = startPosition;
|
||||
if (mOffset > 0) {
|
||||
// if we need to set a starting offset, QI for nsISeekableStream
|
||||
nsCOMPtr<nsISeekableStream> ras =
|
||||
@@ -636,8 +642,7 @@ nsFileTransport::AsyncOpen(nsIStreamObserver *observer, nsISupports* ctxt)
|
||||
return NS_ERROR_IN_PROGRESS;
|
||||
|
||||
NS_ASSERTION(observer, "need to supply an nsIStreamObserver");
|
||||
rv = NS_NewAsyncStreamObserver(getter_AddRefs(mOpenObserver),
|
||||
observer, NS_CURRENT_EVENTQ);
|
||||
rv = NS_NewAsyncStreamObserver(observer, NS_CURRENT_EVENTQ, getter_AddRefs(mOpenObserver));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_ASSERTION(mOpenContext == nsnull, "context not released");
|
||||
@@ -659,7 +664,9 @@ nsFileTransport::AsyncOpen(nsIStreamObserver *observer, nsISupports* ctxt)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransport::AsyncRead(nsIStreamListener *listener, nsISupports *ctxt)
|
||||
nsFileTransport::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
|
||||
nsISupports *ctxt,
|
||||
nsIStreamListener *listener)
|
||||
{
|
||||
nsAutoMonitor mon(mMonitor);
|
||||
|
||||
@@ -670,8 +677,7 @@ nsFileTransport::AsyncRead(nsIStreamListener *listener, nsISupports *ctxt)
|
||||
return NS_ERROR_IN_PROGRESS;
|
||||
|
||||
NS_ASSERTION(listener, "need to supply an nsIStreamListener");
|
||||
rv = NS_NewAsyncStreamListener(getter_AddRefs(mListener),
|
||||
listener, nsnull);
|
||||
rv = NS_NewAsyncStreamListener(listener, nsnull, getter_AddRefs(mListener));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = NS_NewPipe(getter_AddRefs(mBufferInputStream),
|
||||
@@ -691,10 +697,12 @@ nsFileTransport::AsyncRead(nsIStreamListener *listener, nsISupports *ctxt)
|
||||
if (mState == CLOSED)
|
||||
mState = OPENING;
|
||||
mCommand = INITIATE_READ;
|
||||
mOffset = startPosition;
|
||||
mTransferAmount = readCount;
|
||||
|
||||
PR_LOG(gFileTransportLog, PR_LOG_DEBUG,
|
||||
("nsFileTransport: AsyncRead [this=%x %s] mOffset=%d mTransferAmount=%d",
|
||||
this, (const char*)mSpec, mOffset, mTransferAmount));
|
||||
("nsFileTransport: AsyncRead [this=%x %s] startPosition=%d readCount=%d",
|
||||
this, (const char*)mSpec, startPosition, readCount));
|
||||
|
||||
NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
@@ -706,8 +714,9 @@ nsFileTransport::AsyncRead(nsIStreamListener *listener, nsISupports *ctxt)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransport::AsyncWrite(nsIInputStream *fromStream,
|
||||
nsIStreamObserver *observer,
|
||||
nsISupports *ctxt)
|
||||
PRUint32 startPosition, PRInt32 writeCount,
|
||||
nsISupports *ctxt,
|
||||
nsIStreamObserver *observer)
|
||||
{
|
||||
nsAutoMonitor mon(mMonitor);
|
||||
|
||||
@@ -718,8 +727,7 @@ nsFileTransport::AsyncWrite(nsIInputStream *fromStream,
|
||||
return NS_ERROR_IN_PROGRESS;
|
||||
|
||||
if (observer) {
|
||||
rv = NS_NewAsyncStreamObserver(getter_AddRefs(mObserver),
|
||||
observer, NS_CURRENT_EVENTQ);
|
||||
rv = NS_NewAsyncStreamObserver(observer, NS_CURRENT_EVENTQ, getter_AddRefs(mObserver));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
@@ -729,6 +737,8 @@ nsFileTransport::AsyncWrite(nsIInputStream *fromStream,
|
||||
if (mState == CLOSED)
|
||||
mState = OPENING;
|
||||
mCommand = INITIATE_WRITE;
|
||||
mOffset = startPosition;
|
||||
mTransferAmount = writeCount;
|
||||
mSource = fromStream;
|
||||
|
||||
PR_LOG(gFileTransportLog, PR_LOG_DEBUG,
|
||||
@@ -925,12 +935,11 @@ nsFileTransport::Process(void)
|
||||
}
|
||||
if (mProgress) {
|
||||
// XXX fix up this message for i18n
|
||||
nsAutoString msg;
|
||||
msg.AssignWithConversion("Read ");
|
||||
nsAutoString msg = "Read ";
|
||||
#ifdef PR_LOGGING
|
||||
msg.AppendWithConversion(NS_STATIC_CAST(const char*, mSpec));
|
||||
msg += (const char*)mSpec;
|
||||
#endif
|
||||
(void)mProgress->OnStatus(this, mContext, msg.GetUnicode());
|
||||
(void)mProgress->OnStatus(this, mContext, msg.mUStr);
|
||||
}
|
||||
mContext = null_nsCOMPtr();
|
||||
|
||||
@@ -1070,12 +1079,11 @@ nsFileTransport::Process(void)
|
||||
}
|
||||
if (mProgress) {
|
||||
// XXX fix up this message for i18n
|
||||
nsAutoString msg;
|
||||
msg.AssignWithConversion("Wrote ");
|
||||
nsAutoString msg = "Wrote ";
|
||||
#ifdef PR_LOGGING
|
||||
msg.AppendWithConversion(NS_STATIC_CAST(const char*, mSpec));
|
||||
msg += (const char*)mSpec;
|
||||
#endif
|
||||
(void)mProgress->OnStatus(this, mContext, msg.GetUnicode());
|
||||
(void)mProgress->OnStatus(this, mContext, msg.mUStr);
|
||||
}
|
||||
mContext = null_nsCOMPtr();
|
||||
|
||||
@@ -1150,44 +1158,27 @@ nsFileTransport::OnClose(nsIPipe* pipe)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransport::GetOriginalURI(nsIURI* *aURI)
|
||||
nsFileTransport::GetOriginalURI(nsIURI * *aURI)
|
||||
{
|
||||
NS_NOTREACHED("GetOriginalURI");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransport::SetOriginalURI(nsIURI* aURI)
|
||||
nsFileTransport::GetURI(nsIURI * *aURI)
|
||||
{
|
||||
NS_NOTREACHED("SetOriginalURI");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransport::GetURI(nsIURI* *aURI)
|
||||
{
|
||||
// NS_NOTREACHED("GetURI");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransport::SetURI(nsIURI* aURI)
|
||||
{
|
||||
NS_NOTREACHED("SetURI");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransport::GetLoadAttributes(nsLoadFlags *aLoadAttributes)
|
||||
{
|
||||
*aLoadAttributes = LOAD_NORMAL;
|
||||
return NS_OK;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransport::SetLoadAttributes(nsLoadFlags aLoadAttributes)
|
||||
{
|
||||
return NS_OK; // ignored for now
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@@ -1218,115 +1209,27 @@ nsFileTransport::GetContentLength(PRInt32 *aContentLength)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransport::SetContentLength(PRInt32 aContentLength)
|
||||
{
|
||||
NS_NOTREACHED("SetContentLength");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransport::GetTransferOffset(PRUint32 *aTransferOffset)
|
||||
{
|
||||
*aTransferOffset = mOffset;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransport::SetTransferOffset(PRUint32 aTransferOffset)
|
||||
{
|
||||
mOffset = aTransferOffset;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransport::GetTransferCount(PRInt32 *aTransferCount)
|
||||
{
|
||||
*aTransferCount = mTransferAmount;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransport::SetTransferCount(PRInt32 aTransferCount)
|
||||
{
|
||||
mTransferAmount = aTransferCount;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransport::GetBufferSegmentSize(PRUint32 *aBufferSegmentSize)
|
||||
{
|
||||
*aBufferSegmentSize = mBufferSegmentSize;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransport::SetBufferSegmentSize(PRUint32 aBufferSegmentSize)
|
||||
{
|
||||
mBufferSegmentSize = aBufferSegmentSize;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransport::GetBufferMaxSize(PRUint32 *aBufferMaxSize)
|
||||
{
|
||||
*aBufferMaxSize = mBufferMaxSize;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransport::SetBufferMaxSize(PRUint32 aBufferMaxSize)
|
||||
{
|
||||
mBufferMaxSize = aBufferMaxSize;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransport::GetShouldCache(PRBool *aShouldCache)
|
||||
{
|
||||
*aShouldCache = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransport::GetPipeliningAllowed(PRBool *aPipeliningAllowed)
|
||||
{
|
||||
*aPipeliningAllowed = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransport::SetPipeliningAllowed(PRBool aPipeliningAllowed)
|
||||
{
|
||||
NS_NOTREACHED("SetPipeliningAllowed");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransport::GetOwner(nsISupports * *aOwner)
|
||||
{
|
||||
NS_NOTREACHED("GetOwner");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransport::SetOwner(nsISupports * aOwner)
|
||||
{
|
||||
NS_NOTREACHED("SetOwner");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransport::GetLoadGroup(nsILoadGroup * *aLoadGroup)
|
||||
{
|
||||
NS_NOTREACHED("GetLoadGroup");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransport::SetLoadGroup(nsILoadGroup* aLoadGroup)
|
||||
{
|
||||
NS_NOTREACHED("SetLoadGroup");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@@ -1364,11 +1267,4 @@ nsFileTransport::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCa
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransport::GetSecurityInfo(nsISupports * *aSecurityInfo)
|
||||
{
|
||||
*aSecurityInfo = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -62,12 +62,20 @@ public:
|
||||
Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult);
|
||||
|
||||
nsresult Init(nsIFile* file,
|
||||
PRInt32 ioFlags,
|
||||
PRInt32 perm);
|
||||
PRInt32 mode,
|
||||
const char* command,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize);
|
||||
nsresult Init(nsIInputStream* fromStream,
|
||||
const char* contentType,
|
||||
PRInt32 contentLength);
|
||||
nsresult Init(nsIFileSystem* fsObj);
|
||||
PRInt32 contentLength,
|
||||
const char* command,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize);
|
||||
nsresult Init(nsIFileSystem* fsObj,
|
||||
const char* command,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize);
|
||||
|
||||
void Process(void);
|
||||
void DoClose(void);
|
||||
@@ -99,8 +107,6 @@ protected:
|
||||
char* mContentType;
|
||||
PRUint32 mBufferSegmentSize;
|
||||
PRUint32 mBufferMaxSize;
|
||||
PRInt32 mIOFlags;
|
||||
PRInt32 mPerm;
|
||||
|
||||
nsCOMPtr<nsIStreamObserver> mOpenObserver;
|
||||
nsCOMPtr<nsISupports> mOpenContext;
|
||||
|
||||
@@ -83,8 +83,10 @@ nsFileTransportService::Create(nsISupports *aOuter, REFNSIID aIID, void **aResul
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransportService::CreateTransport(nsIFile* file,
|
||||
PRInt32 ioFlags,
|
||||
PRInt32 perm,
|
||||
PRInt32 mode,
|
||||
const char* command,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize,
|
||||
nsIChannel** result)
|
||||
{
|
||||
nsresult rv;
|
||||
@@ -92,7 +94,7 @@ nsFileTransportService::CreateTransport(nsIFile* file,
|
||||
if (trans == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(trans);
|
||||
rv = trans->Init(file, ioFlags, perm);
|
||||
rv = trans->Init(file, mode, command, bufferSegmentSize, bufferMaxSize);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(trans);
|
||||
return rv;
|
||||
@@ -105,6 +107,9 @@ NS_IMETHODIMP
|
||||
nsFileTransportService::CreateTransportFromStream(nsIInputStream *fromStream,
|
||||
const char* contentType,
|
||||
PRInt32 contentLength,
|
||||
const char *command,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize,
|
||||
nsIChannel** result)
|
||||
{
|
||||
nsresult rv;
|
||||
@@ -112,7 +117,8 @@ nsFileTransportService::CreateTransportFromStream(nsIInputStream *fromStream,
|
||||
if (trans == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(trans);
|
||||
rv = trans->Init(fromStream, contentType, contentLength);
|
||||
rv = trans->Init(fromStream, contentType, contentLength, command,
|
||||
bufferSegmentSize, bufferMaxSize);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(trans);
|
||||
return rv;
|
||||
@@ -123,6 +129,9 @@ nsFileTransportService::CreateTransportFromStream(nsIInputStream *fromStream,
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFileTransportService::CreateTransportFromFileSystem(nsIFileSystem *fsObj,
|
||||
const char *command,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize,
|
||||
nsIChannel **result)
|
||||
{
|
||||
nsresult rv;
|
||||
@@ -130,7 +139,7 @@ nsFileTransportService::CreateTransportFromFileSystem(nsIFileSystem *fsObj,
|
||||
if (trans == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(trans);
|
||||
rv = trans->Init(fsObj);
|
||||
rv = trans->Init(fsObj, command, bufferSegmentSize, bufferMaxSize);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(trans);
|
||||
return rv;
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "nsIOService.h"
|
||||
#include "nsIProtocolHandler.h"
|
||||
#include "nscore.h"
|
||||
#include "nsString2.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIEventQueueService.h"
|
||||
#include "nsIFileTransportService.h"
|
||||
@@ -139,7 +140,7 @@ nsIOService::ExtractScheme(const char* inURI, PRUint32 *startPos, PRUint32 *endP
|
||||
const char* uri = inURI;
|
||||
|
||||
// skip leading white space
|
||||
while (nsCRT::IsAsciiSpace(*uri))
|
||||
while (nsString::IsSpace(*uri))
|
||||
uri++;
|
||||
|
||||
PRUint32 start = uri - inURI;
|
||||
@@ -165,7 +166,7 @@ nsIOService::ExtractScheme(const char* inURI, PRUint32 *startPos, PRUint32 *endP
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
else if (nsCRT::IsAsciiAlpha(c)) {
|
||||
else if (nsString::IsAlpha(c)) {
|
||||
length++;
|
||||
}
|
||||
else
|
||||
@@ -216,7 +217,14 @@ nsIOService::NewURI(const char* aSpec, nsIURI* aBaseURI,
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::NewChannelFromURI(nsIURI *aURI, nsIChannel **result)
|
||||
nsIOService::NewChannelFromURI(const char* verb, nsIURI *aURI,
|
||||
nsILoadGroup *aGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize,
|
||||
nsIChannel **result)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
@@ -228,12 +236,22 @@ nsIOService::NewChannelFromURI(nsIURI *aURI, nsIChannel **result)
|
||||
rv = GetProtocolHandler((const char*)scheme, getter_AddRefs(handler));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = handler->NewChannel(aURI, result);
|
||||
rv = handler->NewChannel(verb, aURI, aGroup, notificationCallbacks,
|
||||
loadAttributes, originalURI,
|
||||
bufferSegmentSize, bufferMaxSize, result);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::NewChannel(const char *aSpec, nsIURI *aBaseURI, nsIChannel **result)
|
||||
nsIOService::NewChannel(const char* verb, const char *aSpec,
|
||||
nsIURI *aBaseURI,
|
||||
nsILoadGroup *aGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize,
|
||||
nsIChannel **result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
@@ -241,7 +259,9 @@ nsIOService::NewChannel(const char *aSpec, nsIURI *aBaseURI, nsIChannel **result
|
||||
rv = NewURI(aSpec, aBaseURI, getter_AddRefs(uri), getter_AddRefs(handler));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = handler->NewChannel(uri, result);
|
||||
rv = handler->NewChannel(verb, uri, aGroup, notificationCallbacks,
|
||||
loadAttributes, originalURI,
|
||||
bufferSegmentSize, bufferMaxSize, result);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -255,10 +275,11 @@ nsIOService::GetOffline(PRBool *offline)
|
||||
NS_IMETHODIMP
|
||||
nsIOService::SetOffline(PRBool offline)
|
||||
{
|
||||
nsresult rv1 = NS_OK;
|
||||
nsresult rv2 = NS_OK;
|
||||
mOffline = offline;
|
||||
if (offline) {
|
||||
// be sure to try and shutdown both (even if the first fails)
|
||||
nsresult rv1 = NS_OK;
|
||||
nsresult rv2 = NS_OK;
|
||||
if (mSocketTransportService)
|
||||
rv1 = mSocketTransportService->Shutdown();
|
||||
if (mDNSService)
|
||||
@@ -266,48 +287,12 @@ nsIOService::SetOffline(PRBool offline)
|
||||
if (NS_FAILED(rv1)) return rv1;
|
||||
if (NS_FAILED(rv2)) return rv2;
|
||||
}
|
||||
else if (!offline && mOffline) {
|
||||
// go online
|
||||
if (mSocketTransportService)
|
||||
rv1 = mSocketTransportService->Init();
|
||||
if (NS_FAILED(rv1)) return rv1;
|
||||
|
||||
if (mDNSService)
|
||||
rv2 = mDNSService->Init();
|
||||
if (NS_FAILED(rv2)) return rv2; //XXX should we shutdown the socket transport service?
|
||||
}
|
||||
mOffline = offline;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// URL parsing utilities
|
||||
|
||||
/* encode characters into % escaped hexcodes */
|
||||
|
||||
/* use the following masks to specify which
|
||||
part of an URL you want to escape:
|
||||
|
||||
url_Scheme = 1
|
||||
url_Username = 2
|
||||
url_Password = 4
|
||||
url_Host = 8
|
||||
url_Directory = 16
|
||||
url_FileBaseName = 32
|
||||
url_FileExtension = 64
|
||||
url_Param = 128
|
||||
url_Query = 256
|
||||
url_Ref = 512
|
||||
*/
|
||||
|
||||
/* by default this function will not escape parts of a string
|
||||
that already look escaped, which means it already includes
|
||||
a valid hexcode. This is done to avoid multiple escapes of
|
||||
a string. Use the following mask to force escaping of a
|
||||
string:
|
||||
|
||||
url_Forced = 1024
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
nsIOService::Escape(const char *str, PRInt16 mask, char** result)
|
||||
{
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#define nsIOService_h__
|
||||
|
||||
#include "nsIIOService.h"
|
||||
#include "nsString.h"
|
||||
#include "nsString2.h"
|
||||
#include "nsISocketTransportService.h"
|
||||
#include "nsIFileTransportService.h"
|
||||
#include "nsIDNSService.h"
|
||||
|
||||
@@ -36,8 +36,7 @@ static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID);
|
||||
// nsInputStreamChannel methods:
|
||||
|
||||
nsInputStreamChannel::nsInputStreamChannel()
|
||||
: mContentType(nsnull), mContentLength(-1), mLoadAttributes(LOAD_NORMAL),
|
||||
mBufferSegmentSize(0), mBufferMaxSize(0), mStatus(NS_OK)
|
||||
: mContentType(nsnull), mContentLength(-1), mLoadAttributes(LOAD_NORMAL)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
@@ -62,12 +61,31 @@ nsInputStreamChannel::Create(nsISupports *aOuter, REFNSIID aIID,
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInputStreamChannel::Init(nsIURI* uri,
|
||||
nsIInputStream* in,
|
||||
const char* contentType,
|
||||
PRInt32 contentLength)
|
||||
PRInt32 contentLength,
|
||||
nsIInputStream* in,
|
||||
nsILoadGroup *aGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize)
|
||||
{
|
||||
nsresult rv;
|
||||
mOriginalURI = originalURI ? originalURI : uri;
|
||||
mURI = uri;
|
||||
mContentLength = contentLength;
|
||||
mBufferSegmentSize = bufferSegmentSize;
|
||||
mBufferMaxSize = bufferMaxSize;
|
||||
|
||||
rv = SetLoadAttributes(loadAttributes);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = SetLoadGroup(aGroup);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = SetNotificationCallbacks(notificationCallbacks);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (contentType) {
|
||||
mContentType = nsCRT::strdup(contentType);
|
||||
@@ -104,18 +122,10 @@ nsInputStreamChannel::IsPending(PRBool *result)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInputStreamChannel::GetStatus(nsresult *status)
|
||||
nsInputStreamChannel::Cancel(void)
|
||||
{
|
||||
*status = mStatus;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInputStreamChannel::Cancel(nsresult status)
|
||||
{
|
||||
mStatus = status;
|
||||
if (mFileTransport)
|
||||
return mFileTransport->Cancel(status);
|
||||
return mFileTransport->Cancel();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -139,35 +149,21 @@ nsInputStreamChannel::Resume(void)
|
||||
// nsIChannel methods:
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInputStreamChannel::GetOriginalURI(nsIURI* *aURI)
|
||||
nsInputStreamChannel::GetOriginalURI(nsIURI * *aURI)
|
||||
{
|
||||
*aURI = mOriginalURI ? mOriginalURI : mURI;
|
||||
*aURI = mOriginalURI;
|
||||
NS_IF_ADDREF(*aURI);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInputStreamChannel::SetOriginalURI(nsIURI* aURI)
|
||||
{
|
||||
mOriginalURI = aURI;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInputStreamChannel::GetURI(nsIURI* *aURI)
|
||||
nsInputStreamChannel::GetURI(nsIURI * *aURI)
|
||||
{
|
||||
*aURI = mURI;
|
||||
NS_IF_ADDREF(*aURI);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInputStreamChannel::SetURI(nsIURI* aURI)
|
||||
{
|
||||
mURI = aURI;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInputStreamChannel::AsyncOpen(nsIStreamObserver *observer, nsISupports* ctxt)
|
||||
{
|
||||
@@ -179,41 +175,37 @@ nsInputStreamChannel::AsyncOpen(nsIStreamObserver *observer, nsISupports* ctxt)
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = fts->CreateTransportFromStream(mInputStream, mContentType, mContentLength,
|
||||
"load", mBufferSegmentSize, mBufferMaxSize,
|
||||
getter_AddRefs(mFileTransport));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (mBufferSegmentSize > 0) {
|
||||
rv = mFileTransport->SetBufferSegmentSize(mBufferSegmentSize);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
if (mBufferMaxSize > 0) {
|
||||
rv = mFileTransport->SetBufferMaxSize(mBufferMaxSize);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
return mFileTransport->AsyncOpen(observer, ctxt);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInputStreamChannel::OpenInputStream(nsIInputStream **result)
|
||||
nsInputStreamChannel::OpenInputStream(PRUint32 startPosition, PRInt32 readCount,
|
||||
nsIInputStream **result)
|
||||
{
|
||||
// if we had seekable streams, we could seek here:
|
||||
NS_ASSERTION(startPosition == 0, "Can't seek in nsInputStreamChannel");
|
||||
*result = mInputStream;
|
||||
NS_ADDREF(*result);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInputStreamChannel::OpenOutputStream(nsIOutputStream **_retval)
|
||||
nsInputStreamChannel::OpenOutputStream(PRUint32 startPosition, nsIOutputStream **_retval)
|
||||
{
|
||||
// we don't do output
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInputStreamChannel::AsyncRead(nsIStreamListener *listener, nsISupports *ctxt)
|
||||
nsInputStreamChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
|
||||
nsISupports *ctxt, nsIStreamListener *listener)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
NS_ASSERTION(listener, "no listener");
|
||||
mRealListener = listener;
|
||||
|
||||
if (mLoadGroup) {
|
||||
@@ -240,24 +232,18 @@ nsInputStreamChannel::AsyncRead(nsIStreamListener *listener, nsISupports *ctxt)
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = fts->CreateTransportFromStream(mInputStream, mContentType, mContentLength,
|
||||
"load", mBufferSegmentSize, mBufferMaxSize,
|
||||
getter_AddRefs(mFileTransport));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (mBufferSegmentSize > 0) {
|
||||
rv = mFileTransport->SetBufferSegmentSize(mBufferSegmentSize);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
if (mBufferMaxSize > 0) {
|
||||
rv = mFileTransport->SetBufferMaxSize(mBufferMaxSize);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
}
|
||||
|
||||
return mFileTransport->AsyncRead(this, ctxt);
|
||||
return mFileTransport->AsyncRead(startPosition, readCount, ctxt, this);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInputStreamChannel::AsyncWrite(nsIInputStream *fromStream,
|
||||
nsIStreamObserver *observer, nsISupports *ctxt)
|
||||
nsInputStreamChannel::AsyncWrite(nsIInputStream *fromStream, PRUint32 startPosition,
|
||||
PRInt32 writeCount, nsISupports *ctxt,
|
||||
nsIStreamObserver *observer)
|
||||
{
|
||||
// we don't do output
|
||||
return NS_ERROR_FAILURE;
|
||||
@@ -307,90 +293,6 @@ nsInputStreamChannel::GetContentLength(PRInt32 *aContentLength)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInputStreamChannel::SetContentLength(PRInt32 aContentLength)
|
||||
{
|
||||
NS_NOTREACHED("SetContentLength");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInputStreamChannel::GetTransferOffset(PRUint32 *aTransferOffset)
|
||||
{
|
||||
NS_NOTREACHED("GetTransferOffset");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInputStreamChannel::SetTransferOffset(PRUint32 aTransferOffset)
|
||||
{
|
||||
NS_NOTREACHED("SetTransferOffset");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInputStreamChannel::GetTransferCount(PRInt32 *aTransferCount)
|
||||
{
|
||||
NS_NOTREACHED("GetTransferCount");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInputStreamChannel::SetTransferCount(PRInt32 aTransferCount)
|
||||
{
|
||||
NS_NOTREACHED("SetTransferCount");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInputStreamChannel::GetBufferSegmentSize(PRUint32 *aBufferSegmentSize)
|
||||
{
|
||||
*aBufferSegmentSize = mBufferSegmentSize;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInputStreamChannel::SetBufferSegmentSize(PRUint32 aBufferSegmentSize)
|
||||
{
|
||||
mBufferSegmentSize = aBufferSegmentSize;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInputStreamChannel::GetBufferMaxSize(PRUint32 *aBufferMaxSize)
|
||||
{
|
||||
*aBufferMaxSize = mBufferMaxSize;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInputStreamChannel::SetBufferMaxSize(PRUint32 aBufferMaxSize)
|
||||
{
|
||||
mBufferMaxSize = aBufferMaxSize;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInputStreamChannel::GetShouldCache(PRBool *aShouldCache)
|
||||
{
|
||||
*aShouldCache = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInputStreamChannel::GetPipeliningAllowed(PRBool *aPipeliningAllowed)
|
||||
{
|
||||
*aPipeliningAllowed = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInputStreamChannel::SetPipeliningAllowed(PRBool aPipeliningAllowed)
|
||||
{
|
||||
NS_NOTREACHED("SetPipeliningAllowed");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInputStreamChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup)
|
||||
{
|
||||
@@ -436,14 +338,6 @@ nsInputStreamChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificat
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInputStreamChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
|
||||
{
|
||||
*aSecurityInfo = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIStreamListener methods:
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -63,7 +63,6 @@ protected:
|
||||
PRUint32 mBufferSegmentSize;
|
||||
PRUint32 mBufferMaxSize;
|
||||
PRUint32 mLoadAttributes;
|
||||
nsresult mStatus;
|
||||
};
|
||||
|
||||
#endif // nsInputStreamChannel_h__
|
||||
|
||||
@@ -75,7 +75,7 @@ nsLoadGroup::~nsLoadGroup()
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
rv = Cancel(NS_BINDING_ABORTED);
|
||||
rv = Cancel();
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Cancel failed");
|
||||
|
||||
NS_IF_RELEASE(mChannels);
|
||||
@@ -161,15 +161,9 @@ nsLoadGroup::IsPending(PRBool *aResult)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLoadGroup::GetStatus(nsresult *status)
|
||||
{
|
||||
*status = NS_OK;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLoadGroup::Cancel(nsresult status)
|
||||
nsLoadGroup::Cancel()
|
||||
{
|
||||
nsresult rv, firstError;
|
||||
PRUint32 count;
|
||||
@@ -218,10 +212,10 @@ nsLoadGroup::Cancel(nsresult status)
|
||||
//
|
||||
// XXX: What should the context and error message be?
|
||||
//
|
||||
(void)RemoveChannel(channel, nsnull, status, nsnull);
|
||||
(void)RemoveChannel(channel, nsnull, NS_BINDING_ABORTED, nsnull);
|
||||
|
||||
// Cancel the channel...
|
||||
rv = channel->Cancel(status);
|
||||
rv = channel->Cancel();
|
||||
|
||||
// Remember the first failure and return it...
|
||||
if (NS_FAILED(rv) && NS_SUCCEEDED(firstError)) {
|
||||
@@ -448,14 +442,13 @@ nsLoadGroup::AddChannel(nsIChannel *channel, nsISupports* ctxt)
|
||||
// If the notification fails then DO NOT add the channel to
|
||||
// the load group.
|
||||
//
|
||||
nsCOMPtr<nsIStreamObserver> observer (do_QueryReferent(mObserver));
|
||||
if (observer) {
|
||||
if (mObserver) {
|
||||
PR_LOG(gLoadGroupLog, PR_LOG_DEBUG,
|
||||
("LOADGROUP [%x]: Firing OnStartRequest for channel %x."
|
||||
"(foreground count=%d).\n",
|
||||
this, channel, mForegroundCount));
|
||||
|
||||
rv = observer->OnStartRequest(channel, ctxt);
|
||||
rv = mObserver->OnStartRequest(channel, ctxt);
|
||||
if (NS_FAILED(rv)) {
|
||||
PR_LOG(gLoadGroupLog, PR_LOG_ERROR,
|
||||
("LOADGROUP [%x]: OnStartRequest for channel %x FAILED.\n",
|
||||
@@ -533,14 +526,13 @@ nsLoadGroup::RemoveChannel(nsIChannel *channel, nsISupports* ctxt,
|
||||
mForegroundCount -= 1;
|
||||
|
||||
// Fire the OnStopRequest out to the observer...
|
||||
nsCOMPtr<nsIStreamObserver> observer (do_QueryReferent(mObserver));
|
||||
if (observer) {
|
||||
if (mObserver) {
|
||||
PR_LOG(gLoadGroupLog, PR_LOG_DEBUG,
|
||||
("LOADGROUP [%x]: Firing OnStopRequest for channel %x."
|
||||
"(foreground count=%d).\n",
|
||||
this, channel, mForegroundCount));
|
||||
|
||||
rv = observer->OnStopRequest(channel, ctxt, status, errorMsg);
|
||||
rv = mObserver->OnStopRequest(channel, ctxt, status, errorMsg);
|
||||
if (NS_FAILED(rv)) {
|
||||
PR_LOG(gLoadGroupLog, PR_LOG_ERROR,
|
||||
("LOADGROUP [%x]: OnStopRequest for channel %x FAILED.\n",
|
||||
@@ -598,8 +590,7 @@ nsLoadGroup::SetGroupObserver(nsIStreamObserver* aObserver)
|
||||
eventQueue, aObserver);
|
||||
}
|
||||
#else
|
||||
//mObserver = aObserver;
|
||||
mObserver = getter_AddRefs(NS_GetWeakReference(aObserver));
|
||||
mObserver = aObserver;
|
||||
#endif
|
||||
|
||||
return rv;
|
||||
@@ -609,10 +600,10 @@ nsLoadGroup::SetGroupObserver(nsIStreamObserver* aObserver)
|
||||
NS_IMETHODIMP
|
||||
nsLoadGroup::GetGroupObserver(nsIStreamObserver* *aResult)
|
||||
{
|
||||
nsCOMPtr<nsIStreamObserver> observer (do_QueryReferent(mObserver));
|
||||
*aResult = observer;
|
||||
NS_IF_ADDREF(*aResult);
|
||||
return NS_OK;
|
||||
*aResult = mObserver;
|
||||
NS_IF_ADDREF(*aResult);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -67,8 +67,8 @@ protected:
|
||||
|
||||
nsISupportsArray* mChannels;
|
||||
|
||||
nsWeakPtr mObserver;
|
||||
// nsCOMPtr<nsIStreamObserver> mObserver;
|
||||
//// nsWeakPtr mObserver;
|
||||
nsCOMPtr<nsIStreamObserver> mObserver;
|
||||
nsCOMPtr<nsIChannel> mDefaultLoadChannel;
|
||||
|
||||
nsWeakPtr mGroupListenerFactory;
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include "nsNetModuleMgr.h"
|
||||
#include "nsNetModRegEntry.h"
|
||||
#include "nsEnumeratorUtils.h" // for nsArrayEnumerator
|
||||
#include "nsString.h"
|
||||
#include "nsString2.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsIEventQueue.h"
|
||||
|
||||
|
||||
@@ -114,10 +114,7 @@ nsNoAuthURLParser::ParseAtHost(const char* i_Spec, char* *o_Host,
|
||||
PRInt32 *o_Port, char* *o_Path)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
// There is no Host, but take care of a localhost
|
||||
if ((nsCRT::strcasecmp(i_Spec,"localhost")==0) ||
|
||||
(PL_strcasestr(i_Spec,"localhost/")==i_Spec))
|
||||
return ParseAtPath(i_Spec+9,o_Path);
|
||||
// There is no Host
|
||||
rv = ParseAtPath(i_Spec, o_Path);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ nsProtocolProxyService::CanUseProxy(nsIURI* aURI)
|
||||
char* np= mFilters;
|
||||
while (*np)
|
||||
{
|
||||
while (*np && (*np == ',' || nsCRT::IsAsciiSpace(*np)))
|
||||
while (*np && (*np == ',' || nsString::IsSpace(*np)))
|
||||
np++;
|
||||
|
||||
char* endproxy = np+1;
|
||||
@@ -167,7 +167,7 @@ nsProtocolProxyService::CanUseProxy(nsIURI* aURI)
|
||||
PRInt32 nport = 0; // no proxy port
|
||||
// find the end of this element.
|
||||
while (*endproxy && (*endproxy != ',' &&
|
||||
!nsCRT::IsAsciiSpace(*endproxy)))
|
||||
!nsString::IsSpace(*endproxy)))
|
||||
{
|
||||
if (*endproxy == ':')
|
||||
portLocation=endproxy;
|
||||
|
||||
@@ -80,10 +80,9 @@ nsSimpleURI::GetSpec(char* *result)
|
||||
nsAutoString string;
|
||||
// NS_LOCK_INSTANCE();
|
||||
|
||||
// STRING USE WARNING: perhaps |string| should be |nsCAutoString|? -- scc
|
||||
string.AssignWithConversion(mScheme);
|
||||
string.AppendWithConversion(':');
|
||||
string.AppendWithConversion(mPath);
|
||||
string.SetString(mScheme);
|
||||
string.Append(':');
|
||||
string.Append(mPath);
|
||||
|
||||
// NS_UNLOCK_INSTANCE();
|
||||
*result = string.ToNewCString();
|
||||
@@ -93,9 +92,7 @@ nsSimpleURI::GetSpec(char* *result)
|
||||
NS_IMETHODIMP
|
||||
nsSimpleURI::SetSpec(const char* aSpec)
|
||||
{
|
||||
nsAutoString spec;
|
||||
spec.AssignWithConversion(aSpec);
|
||||
|
||||
nsAutoString spec(aSpec);
|
||||
PRInt32 pos = spec.Find(":");
|
||||
if (pos == -1)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -106,12 +106,6 @@ enum nsSocketReadWriteInfo {
|
||||
eSocketDNS_Wait = 0x2020
|
||||
};
|
||||
|
||||
//
|
||||
// This is the default timeout value (in milliseconds) for sockets which have
|
||||
// no activity...
|
||||
//
|
||||
#define DEFAULT_SOCKET_CONNECT_TIMEOUT_IN_MS 35*1000
|
||||
|
||||
// Forward declarations...
|
||||
class nsSocketTransportService;
|
||||
class nsIInterfaceRequestor;
|
||||
@@ -143,7 +137,7 @@ public:
|
||||
|
||||
nsresult Process(PRInt16 aSelectFlags);
|
||||
|
||||
nsresult CheckForTimeout (PRIntervalTime aCurrentTime);
|
||||
nsresult CheckForTimeout(PRIntervalTime aCurrentTime);
|
||||
|
||||
// Close this socket either right away or once done with the transaction.
|
||||
nsresult CloseConnection(PRBool bNow=PR_TRUE);
|
||||
@@ -155,6 +149,8 @@ public:
|
||||
|
||||
static nsSocketTransport* GetInstance(PRCList* qp) { return (nsSocketTransport*)((char*)qp - offsetof(nsSocketTransport, mListLink)); }
|
||||
|
||||
static void SetSocketTimeout(PRIntervalTime aTimeoutInterval);
|
||||
|
||||
PRBool CanBeReused(void) { return
|
||||
(mCurrentState != eSocketState_Error) && !mCloseConnectionOnceDone;}
|
||||
|
||||
@@ -171,9 +167,6 @@ protected:
|
||||
nsresult GetSocketErrorString(PRUint32 iCode, PRUnichar** oString) const;
|
||||
|
||||
private:
|
||||
PRIntervalTime mSocketTimeout;
|
||||
PRIntervalTime mSocketConnectTimeout;
|
||||
|
||||
// Access methods for manipulating the ReadWriteInfo...
|
||||
inline void SetReadType(nsSocketReadWriteInfo aType) {
|
||||
mReadWriteState = (mReadWriteState & ~eSocketRead_Type_Mask) | aType;
|
||||
@@ -200,7 +193,7 @@ private:
|
||||
|
||||
protected:
|
||||
|
||||
nsresult mCancelStatus;
|
||||
PRBool mCancelOperation;
|
||||
PRBool mCloseConnectionOnceDone;
|
||||
nsSocketState mCurrentState;
|
||||
nsCOMPtr<nsIRequest> mDNSRequest;
|
||||
@@ -210,13 +203,12 @@ protected:
|
||||
PRIntervalTime mLastActiveTime;
|
||||
PRCList mListLink;
|
||||
PRUint32 mLoadAttributes;
|
||||
PRMonitor* mMonitor;
|
||||
PRLock* mLock;
|
||||
PRNetAddr mNetAddress;
|
||||
nsCOMPtr<nsISupports> mOpenContext;
|
||||
nsCOMPtr<nsIStreamObserver> mOpenObserver;
|
||||
nsSocketOperation mOperation;
|
||||
nsCOMPtr<nsISupports> mOwner;
|
||||
nsCOMPtr<nsISupports> mSecurityInfo;
|
||||
PRInt32 mPort;
|
||||
char* mPrintHost; // not the proxy
|
||||
nsCOMPtr<nsISupports> mReadContext;
|
||||
@@ -234,9 +226,7 @@ protected:
|
||||
PRInt32 mSuspendCount;
|
||||
PRInt32 mWriteCount;
|
||||
nsCOMPtr<nsISupports> mWriteContext;
|
||||
PRInt32 mBytesExpected;
|
||||
PRUint32 mReuseCount;
|
||||
PRUint32 mLastReuseCount;
|
||||
PRInt32 mBytesAllowed;
|
||||
|
||||
// The following four members are used when AsyncWrite(...) is called
|
||||
// with an nsIInputStream which does not also support the
|
||||
|
||||
@@ -49,6 +49,8 @@ nsSocketTransportService::nsSocketTransportService()
|
||||
mActiveTransportList = nsnull;
|
||||
|
||||
mThreadRunning = PR_FALSE;
|
||||
|
||||
SetSocketTimeoutInterval(PR_MillisecondsToInterval(DEFAULT_SOCKET_TIMEOUT_IN_MS));
|
||||
}
|
||||
|
||||
|
||||
@@ -105,8 +107,7 @@ nsSocketTransportService::Create(nsISupports *aOuter, REFNSIID aIID, void **aRes
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSocketTransportService::Init(void)
|
||||
nsresult nsSocketTransportService::Init(void)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
@@ -225,7 +226,6 @@ nsresult nsSocketTransportService::ProcessWorkQ(void)
|
||||
// available in the select set...
|
||||
//
|
||||
PR_Lock(mThreadLock);
|
||||
NS_ASSERTION(MAX_OPEN_CONNECTIONS > mSelectFDSetCount, "reached max open connections");
|
||||
while (!PR_CLIST_IS_EMPTY(&mWorkQ) &&
|
||||
(MAX_OPEN_CONNECTIONS > mSelectFDSetCount)) {
|
||||
nsSocketTransport* transport;
|
||||
@@ -270,7 +270,6 @@ nsresult nsSocketTransportService::AddToSelectList(nsSocketTransport* aTransport
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
NS_ASSERTION(MAX_OPEN_CONNECTIONS > mSelectFDSetCount, "reached max open connections");
|
||||
if (aTransport && (MAX_OPEN_CONNECTIONS > mSelectFDSetCount) ) {
|
||||
PRPollDesc* pfd;
|
||||
int i;
|
||||
@@ -343,6 +342,24 @@ nsresult nsSocketTransportService::RemoveFromSelectList(nsSocketTransport* aTran
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsSocketTransportService::GetSocketTimeoutInterval(PRIntervalTime* aResult)
|
||||
{
|
||||
*aResult = mSocketTimeoutInterval;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSocketTransportService::SetSocketTimeoutInterval(PRIntervalTime aTime)
|
||||
{
|
||||
mSocketTimeoutInterval = aTime;
|
||||
|
||||
// Update the timeout value in the socket transport...
|
||||
nsSocketTransport::SetSocketTimeout(aTime);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//
|
||||
// --------------------------------------------------------------------------
|
||||
// nsISupports implementation...
|
||||
@@ -369,7 +386,7 @@ nsSocketTransportService::Run(void)
|
||||
mSelectFDSet[0].fd = mThreadEvent;
|
||||
mSelectFDSet[0].in_flags = PR_POLL_READ;
|
||||
mSelectFDSetCount = 1;
|
||||
pollTimeout = PR_MillisecondsToInterval (DEFAULT_POLL_TIMEOUT_IN_MS);
|
||||
pollTimeout = mSocketTimeoutInterval;
|
||||
#else
|
||||
//
|
||||
// For now, rather than breaking out of the call to PR_Poll(...) just set
|
||||
|
||||
@@ -38,12 +38,17 @@
|
||||
#define USE_POLLABLE_EVENT
|
||||
#endif
|
||||
|
||||
//
|
||||
// This is the default timeout value (in milliseconds) for sockets which have
|
||||
// no activity...
|
||||
//
|
||||
#define DEFAULT_SOCKET_TIMEOUT_IN_MS 35*1000
|
||||
|
||||
//
|
||||
// This is the Maximum number of Socket Transport instances that can be active
|
||||
// at once...
|
||||
//
|
||||
#define MAX_OPEN_CONNECTIONS 50
|
||||
#define DEFAULT_POLL_TIMEOUT_IN_MS 35*1000
|
||||
|
||||
|
||||
// Forward declarations...
|
||||
@@ -64,6 +69,8 @@ public:
|
||||
static NS_METHOD
|
||||
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
nsresult Init(void);
|
||||
|
||||
nsresult AddToWorkQ(nsSocketTransport* aTransport);
|
||||
|
||||
// XXX: Should these use intervals or Milliseconds?
|
||||
@@ -84,6 +91,8 @@ protected:
|
||||
PRLock* mThreadLock;
|
||||
PRBool mThreadRunning;
|
||||
|
||||
PRIntervalTime mSocketTimeoutInterval;
|
||||
|
||||
PRCList mWorkQ;
|
||||
|
||||
PRInt32 mSelectFDSetCount;
|
||||
|
||||
@@ -197,8 +197,7 @@ nsStdURL::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
*aInstancePtr = GetInner();
|
||||
else if (aIID.Equals(kThisStdURLImplementationCID) || // used by Equals
|
||||
aIID.Equals(NS_GET_IID(nsIURL)) ||
|
||||
aIID.Equals(NS_GET_IID(nsIURI)) ||
|
||||
aIID.Equals(NS_GET_IID(nsIFileURL)))
|
||||
aIID.Equals(NS_GET_IID(nsIURI)))
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIURL*, this);
|
||||
else {
|
||||
*aInstancePtr = nsnull;
|
||||
@@ -219,7 +218,7 @@ nsStdURL::Equals(nsIURI *i_OtherURI, PRBool *o_Equals)
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = this->GetSpec(getter_Copies(spec2));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
eq = nsCAutoString(spec).Equals(spec2);
|
||||
eq = nsAutoString(spec).Equals(spec2);
|
||||
}
|
||||
*o_Equals = eq;
|
||||
return NS_OK;
|
||||
@@ -458,7 +457,7 @@ nsStdURL::SetDirectory(const char* i_Directory)
|
||||
if (mDirectory)
|
||||
nsCRT::free(mDirectory);
|
||||
|
||||
nsCAutoString dir;
|
||||
nsAutoString dir;
|
||||
if ('/' != *i_Directory)
|
||||
dir += "/";
|
||||
|
||||
@@ -1013,36 +1012,11 @@ nsStdURL::SetFile(nsIFile * aFile)
|
||||
|
||||
// set up this URL to denote the nsIFile
|
||||
SetScheme("file");
|
||||
CRTFREEIF(mUsername);
|
||||
CRTFREEIF(mPassword);
|
||||
CRTFREEIF(mHost);
|
||||
mPort = -1;
|
||||
|
||||
char* ePath = nsnull;
|
||||
nsCAutoString escPath;
|
||||
|
||||
rv = aFile->GetPath(&ePath);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
#if defined (XP_PC)
|
||||
// Replace \ with / to convert to an url
|
||||
char* s = ePath;
|
||||
while (*s)
|
||||
{
|
||||
if (*s == '\\')
|
||||
*s = '/';
|
||||
s++;
|
||||
}
|
||||
#endif
|
||||
#if defined( XP_MAC )
|
||||
// Swap the / and colons to convert to an url
|
||||
SwapSlashColon(ePath);
|
||||
#endif
|
||||
// Escape the path with the directory mask
|
||||
rv = nsURLEscape(ePath,nsIIOService::url_Directory+
|
||||
nsIIOService::url_Forced,escPath);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = SetPath(escPath.GetBuffer());
|
||||
}
|
||||
rv = SetPath(ePath);
|
||||
}
|
||||
CRTFREEIF(ePath);
|
||||
return rv;
|
||||
|
||||
@@ -25,9 +25,10 @@
|
||||
#include "nsIURL.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsProxiedService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIIOService.h"
|
||||
|
||||
static NS_DEFINE_CID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID);
|
||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsStreamLoader::Init(nsIURI* aURL,
|
||||
@@ -43,24 +44,23 @@ nsStreamLoader::Init(nsIURI* aURL,
|
||||
mObserver = observer;
|
||||
mContext = context;
|
||||
|
||||
rv = NS_OpenURI(this, nsnull, aURL, nsnull, aGroup, notificationCallbacks,
|
||||
loadAttributes, bufferSegmentSize, bufferMaxSize);
|
||||
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
rv = serv->NewChannelFromURI("load", aURL, aGroup, notificationCallbacks,
|
||||
loadAttributes, nsnull,
|
||||
bufferSegmentSize, bufferMaxSize, getter_AddRefs(channel));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = channel->AsyncRead(0, -1, nsnull, this);
|
||||
|
||||
if (NS_FAILED(rv) && mObserver) {
|
||||
// don't callback synchronously as it puts the caller
|
||||
// in a recursive situation and breaks the asynchronous
|
||||
// semantics of nsIStreamLoader
|
||||
nsresult rv2 = NS_OK;
|
||||
NS_WITH_SERVICE(nsIProxyObjectManager, pIProxyObjectManager,
|
||||
kProxyObjectManagerCID, &rv);
|
||||
if (NS_FAILED(rv2)) return rv2;
|
||||
|
||||
nsCOMPtr<nsIStreamLoaderObserver> pObserver;
|
||||
rv2 = pIProxyObjectManager->GetProxyObject(NS_CURRENT_EVENTQ,
|
||||
NS_GET_IID(nsIStreamLoaderObserver), observer,
|
||||
PROXY_ASYNC | PROXY_ALWAYS, getter_AddRefs(pObserver));
|
||||
if (NS_FAILED(rv2)) return rv2;
|
||||
|
||||
rv = pObserver->OnStreamComplete(this, mContext, rv, 0, nsnull);
|
||||
nsresult rv2 = mObserver->OnStreamComplete(this, mContext, rv,
|
||||
mData.Length(),
|
||||
mData.GetBuffer());
|
||||
if (NS_FAILED(rv2))
|
||||
rv = rv2; // take the user's error instead
|
||||
}
|
||||
|
||||
return rv;
|
||||
@@ -96,14 +96,6 @@ nsStreamLoader::GetNumBytesRead(PRUint32* aNumBytes)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsStreamLoader::GetOwner(nsISupports** aOwner)
|
||||
{
|
||||
*aOwner = mOwner.get();
|
||||
NS_IF_ADDREF(*aOwner);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsStreamLoader::OnStartRequest(nsIChannel* channel, nsISupports *ctxt)
|
||||
{
|
||||
@@ -114,7 +106,6 @@ NS_IMETHODIMP
|
||||
nsStreamLoader::OnStopRequest(nsIChannel* channel, nsISupports *ctxt,
|
||||
nsresult status, const PRUnichar *errorMsg)
|
||||
{
|
||||
(void)channel->GetOwner(getter_AddRefs(mOwner));
|
||||
nsresult rv = mObserver->OnStreamComplete(this, mContext, status,
|
||||
mData.Length(),
|
||||
mData.GetBuffer());
|
||||
@@ -132,11 +123,16 @@ nsStreamLoader::OnDataAvailable(nsIChannel* channel, nsISupports *ctxt,
|
||||
char buffer[BUF_SIZE];
|
||||
PRUint32 len, lenRead;
|
||||
|
||||
rv = inStr->Available(&len);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
inStr->Available(&len);
|
||||
|
||||
while (len > 0) {
|
||||
lenRead = PR_MIN(len, BUF_SIZE);
|
||||
if (len < BUF_SIZE) {
|
||||
lenRead = len;
|
||||
}
|
||||
else {
|
||||
lenRead = BUF_SIZE;
|
||||
}
|
||||
|
||||
rv = inStr->Read(buffer, lenRead, &lenRead);
|
||||
if (NS_FAILED(rv) || lenRead == 0) {
|
||||
return rv;
|
||||
|
||||
@@ -47,7 +47,6 @@ protected:
|
||||
nsCOMPtr<nsIStreamLoaderObserver> mObserver;
|
||||
nsCOMPtr<nsISupports> mContext; // the observer's context
|
||||
nsCString mData;
|
||||
nsCOMPtr<nsISupports> mOwner;
|
||||
/// nsCOMPtr<nsILoadGroup> mLoadGroup;
|
||||
};
|
||||
|
||||
|
||||
@@ -21,17 +21,16 @@
|
||||
#include "prprf.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIAllocator.h"
|
||||
#include "nsIIOService.h"
|
||||
|
||||
/* This array tells which chars have to be escaped */
|
||||
/* This array tells which chars has to be escaped */
|
||||
|
||||
const int EscapeChars[256] =
|
||||
/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x */
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1x */
|
||||
0,1023, 0, 512, 761, 0,1023, 0,1023,1023,1023,1023,1023,1023, 959, 912, /* 2x !"#$%&'()*+,-./ */
|
||||
1023,1023,1023,1023,1023,1023,1023,1023,1023,1023, 912, 896, 0,1008, 0, 768, /* 3x 0123456789:;<=>? */
|
||||
0,1023, 0, 512, 761, 0,1023, 0,1023,1023,1023,1023,1023,1023, 959,1016, /* 2x !"#$%&'()*+,-./ */
|
||||
1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1008, 896, 0,1008, 0, 768, /* 3x 0123456789:;<=>? */
|
||||
992,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023, /* 4x @ABCDEFGHIJKLMNO */
|
||||
1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023, 896, 896, 896, 896,1023, /* 5x PQRSTUVWXYZ[\]^_ */
|
||||
0,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023, /* 6x `abcdefghijklmno */
|
||||
@@ -53,30 +52,6 @@ const int EscapeChars[256] =
|
||||
#define HEX_ESCAPE '%'
|
||||
|
||||
/* returns an escaped string */
|
||||
|
||||
/* use the following masks to specify which
|
||||
part of an URL you want to escape:
|
||||
|
||||
url_Scheme = 1
|
||||
url_Username = 2
|
||||
url_Password = 4
|
||||
url_Host = 8
|
||||
url_Directory = 16
|
||||
url_FileBaseName = 32
|
||||
url_FileExtension = 64
|
||||
url_Param = 128
|
||||
url_Query = 256
|
||||
url_Ref = 512
|
||||
*/
|
||||
|
||||
/* by default this function will not escape parts of a string
|
||||
that already look escaped, which means it already includes
|
||||
a valid hexcode. This is done to avoid multiple escapes of
|
||||
a string. Use the following mask to force escaping of a
|
||||
string:
|
||||
|
||||
url_Forced = 1024
|
||||
*/
|
||||
NS_NET nsresult
|
||||
nsURLEscape(const char* str, PRInt16 mask, nsCString &result)
|
||||
{
|
||||
@@ -89,10 +64,6 @@ nsURLEscape(const char* str, PRInt16 mask, nsCString &result)
|
||||
char* hexChars = "0123456789ABCDEF";
|
||||
static const char CheckHexChars[] = "0123456789ABCDEFabcdef";
|
||||
int len = PL_strlen(str);
|
||||
PRBool forced = PR_FALSE;
|
||||
|
||||
if (mask & nsIIOService::url_Forced)
|
||||
forced = PR_TRUE;
|
||||
|
||||
register const unsigned char* src = (const unsigned char *) str;
|
||||
|
||||
@@ -117,7 +88,7 @@ nsURLEscape(const char* str, PRInt16 mask, nsCString &result)
|
||||
|
||||
/* if the char has not to be escaped or whatever follows % is
|
||||
a valid escaped string, just copy the char */
|
||||
if (IS_OK(c) || (c == HEX_ESCAPE && !(forced) && (pc1) && (pc2) &&
|
||||
if (IS_OK(c) || (c == HEX_ESCAPE && (pc1) && (pc2) &&
|
||||
PL_strpbrk(pc1, CheckHexChars) != 0 &&
|
||||
PL_strpbrk(pc2, CheckHexChars) != 0)) {
|
||||
tempBuffer[tempBufferPos++]=c;
|
||||
|
||||
@@ -30,30 +30,6 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
/* encode characters into % escaped hexcodes */
|
||||
|
||||
/* use the following masks to specify which
|
||||
part of an URL you want to escape:
|
||||
|
||||
url_Scheme = 1
|
||||
url_Username = 2
|
||||
url_Password = 4
|
||||
url_Host = 8
|
||||
url_Directory = 16
|
||||
url_FileBaseName = 32
|
||||
url_FileExtension = 64
|
||||
url_Param = 128
|
||||
url_Query = 256
|
||||
url_Ref = 512
|
||||
*/
|
||||
|
||||
/* by default this function will not escape parts of a string
|
||||
that already look escaped, which means it already includes
|
||||
a valid hexcode. This is done to avoid multiple escapes of
|
||||
a string. Use the following mask to force escaping of a
|
||||
string:
|
||||
|
||||
url_Forced = 1024
|
||||
*/
|
||||
NS_NET nsresult nsURLEscape (const char* str, PRInt16 mask, nsCString &result);
|
||||
|
||||
/* helper call function */
|
||||
@@ -82,3 +58,4 @@ NS_NET void ToLowerCase(char* str);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -105,13 +105,13 @@ static nsModuleComponentInfo gNetModuleInfo[] = {
|
||||
NS_LOADGROUP_CID,
|
||||
"component://netscape/network/load-group",
|
||||
nsLoadGroup::Create },
|
||||
{ NS_LOCALFILEINPUTSTREAM_CLASSNAME,
|
||||
NS_LOCALFILEINPUTSTREAM_CID,
|
||||
NS_LOCALFILEINPUTSTREAM_PROGID,
|
||||
{ NS_FILEINPUTSTREAM_CLASSNAME,
|
||||
NS_FILEINPUTSTREAM_CID,
|
||||
NS_FILEINPUTSTREAM_PROGID,
|
||||
nsFileInputStream::Create },
|
||||
{ NS_LOCALFILEOUTPUTSTREAM_CLASSNAME,
|
||||
NS_LOCALFILEOUTPUTSTREAM_CID,
|
||||
NS_LOCALFILEOUTPUTSTREAM_PROGID,
|
||||
{ NS_FILEOUTPUTSTREAM_CLASSNAME,
|
||||
NS_FILEOUTPUTSTREAM_CID,
|
||||
NS_FILEOUTPUTSTREAM_PROGID,
|
||||
nsFileOutputStream::Create },
|
||||
{ "StdURLParser",
|
||||
NS_STANDARDURLPARSER_CID,
|
||||
|
||||
11
mozilla/netwerk/cache/build/Makefile.in
vendored
11
mozilla/netwerk/cache/build/Makefile.in
vendored
@@ -24,17 +24,16 @@ include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = nkcache
|
||||
LIBRARY_NAME = necko_cache
|
||||
SHORT_LIBNAME = nkcache
|
||||
IS_COMPONENT = 1
|
||||
|
||||
CPPSRCS = nsNetDataCacheModule.cpp
|
||||
|
||||
SHARED_LIBRARY_LIBS = \
|
||||
$(DIST)/lib/libnkcachemgr_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/libnkfilecache_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/libnkmemcache_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/libmozdbm_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/libxpcomio_s.$(LIB_SUFFIX) \
|
||||
$(DIST)/lib/libnkcachemgr_s.a \
|
||||
$(DIST)/lib/libnkfilecache_s.a \
|
||||
$(DIST)/lib/libnkmemcache_s.a \
|
||||
$(DIST)/lib/libmozdbm_s.a \
|
||||
$(DIST)/lib/libxpcomio_s.a \
|
||||
$(NULL)
|
||||
|
||||
LOCAL_INCLUDES = \
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
#include "netCore.h"
|
||||
#include "nsIMIMEService.h"
|
||||
#include "nsISupportsUtils.h"
|
||||
#include "prio.h"
|
||||
|
||||
//static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID);
|
||||
@@ -46,12 +45,12 @@ class WriteStreamWrapper : public nsIOutputStream
|
||||
{
|
||||
public:
|
||||
WriteStreamWrapper(nsDiskCacheRecordChannel* aChannel,
|
||||
nsIOutputStream *aBaseStream);
|
||||
nsIOutputStream *aBaseStream) ;
|
||||
|
||||
virtual ~WriteStreamWrapper();
|
||||
virtual ~WriteStreamWrapper() ;
|
||||
|
||||
static nsresult
|
||||
Create(nsDiskCacheRecordChannel* aChannel, nsIOutputStream *aBaseStream, nsIOutputStream* *aWrapper);
|
||||
Create(nsDiskCacheRecordChannel* aChannel, nsIOutputStream *aBaseStream, nsIOutputStream* *aWrapper) ;
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIBASESTREAM
|
||||
@@ -60,7 +59,7 @@ class WriteStreamWrapper : public nsIOutputStream
|
||||
private:
|
||||
nsDiskCacheRecordChannel* mChannel;
|
||||
nsCOMPtr<nsIOutputStream> mBaseStream;
|
||||
};
|
||||
} ;
|
||||
|
||||
// implement nsISupports
|
||||
NS_IMPL_ISUPPORTS(WriteStreamWrapper, NS_GET_IID(nsIOutputStream))
|
||||
@@ -111,18 +110,17 @@ WriteStreamWrapper::Close()
|
||||
|
||||
nsDiskCacheRecordChannel::nsDiskCacheRecordChannel(nsDiskCacheRecord *aRecord,
|
||||
nsILoadGroup *aLoadGroup)
|
||||
: mRecord(aRecord),
|
||||
mLoadGroup(aLoadGroup),
|
||||
mStatus(NS_OK)
|
||||
: mRecord(aRecord) ,
|
||||
mLoadGroup(aLoadGroup)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_INIT_REFCNT() ;
|
||||
NS_ADDREF(mRecord);
|
||||
mRecord->mNumChannels++;
|
||||
mRecord->mNumChannels++ ;
|
||||
}
|
||||
|
||||
nsDiskCacheRecordChannel::~nsDiskCacheRecordChannel()
|
||||
{
|
||||
mRecord->mNumChannels--;
|
||||
mRecord->mNumChannels-- ;
|
||||
NS_RELEASE(mRecord);
|
||||
}
|
||||
|
||||
@@ -163,12 +161,13 @@ nsDiskCacheRecordChannel::Init(void)
|
||||
#endif
|
||||
#endif
|
||||
return rv ;
|
||||
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDiskCacheRecordChannel::NotifyStorageInUse(PRInt32 aBytesUsed)
|
||||
{
|
||||
return mRecord->mDiskCache->mStorageInUse += aBytesUsed;
|
||||
return mRecord->mDiskCache->mStorageInUse += aBytesUsed ;
|
||||
}
|
||||
|
||||
// implement nsISupports
|
||||
@@ -182,46 +181,38 @@ NS_IMPL_ISUPPORTS4(nsDiskCacheRecordChannel,
|
||||
NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::IsPending(PRBool *aIsPending)
|
||||
{
|
||||
*aIsPending = PR_FALSE;
|
||||
*aIsPending = PR_FALSE ;
|
||||
if(!mFileTransport)
|
||||
return NS_OK;
|
||||
return NS_OK ;
|
||||
|
||||
return mFileTransport->IsPending(aIsPending);
|
||||
return mFileTransport->IsPending(aIsPending) ;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::GetStatus(nsresult *status)
|
||||
nsDiskCacheRecordChannel::Cancel(void)
|
||||
{
|
||||
*status = mStatus;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::Cancel(nsresult status)
|
||||
{
|
||||
mStatus = status;
|
||||
if(!mFileTransport)
|
||||
return NS_ERROR_FAILURE;
|
||||
return NS_ERROR_FAILURE ;
|
||||
|
||||
return mFileTransport->Cancel(status);
|
||||
return mFileTransport->Cancel() ;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::Suspend(void)
|
||||
{
|
||||
if(!mFileTransport)
|
||||
return NS_ERROR_FAILURE;
|
||||
return NS_ERROR_FAILURE ;
|
||||
|
||||
return mFileTransport->Suspend();
|
||||
return mFileTransport->Suspend() ;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::Resume(void)
|
||||
{
|
||||
if(!mFileTransport)
|
||||
return NS_ERROR_FAILURE;
|
||||
return NS_ERROR_FAILURE ;
|
||||
|
||||
return mFileTransport->Resume();
|
||||
return mFileTransport->Resume() ;
|
||||
}
|
||||
|
||||
// implement nsIChannel
|
||||
@@ -230,107 +221,92 @@ NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::GetOriginalURI(nsIURI* *aURI)
|
||||
{
|
||||
// FUR - might need to implement this - not sure
|
||||
NS_NOTREACHED("nsDiskCacheRecordChannel::GetOriginalURI");
|
||||
return NS_ERROR_NOT_IMPLEMENTED ;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::SetOriginalURI(nsIURI* aURI)
|
||||
{
|
||||
// FUR - might need to implement this - not sure
|
||||
NS_NOTREACHED("nsDiskCacheRecordChannel::SetOriginalURI");
|
||||
return NS_ERROR_NOT_IMPLEMENTED ;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::GetURI(nsIURI* *aURI)
|
||||
nsDiskCacheRecordChannel::GetURI(nsIURI * *aURI)
|
||||
{
|
||||
if(!mFileTransport)
|
||||
return NS_ERROR_FAILURE;
|
||||
return NS_ERROR_FAILURE ;
|
||||
|
||||
return mFileTransport->GetURI(aURI);
|
||||
return mFileTransport->GetURI(aURI) ;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::SetURI(nsIURI* aURI)
|
||||
nsDiskCacheRecordChannel::OpenInputStream(PRUint32 aStartPosition,
|
||||
PRInt32 aReadCount,
|
||||
nsIInputStream* *aResult)
|
||||
{
|
||||
if(!mFileTransport)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return mFileTransport->SetURI(aURI);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::OpenInputStream(nsIInputStream* *aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
nsresult rv ;
|
||||
|
||||
if(mFileTransport)
|
||||
return NS_ERROR_IN_PROGRESS;
|
||||
return NS_ERROR_IN_PROGRESS ;
|
||||
|
||||
NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv);
|
||||
if(NS_FAILED(rv)) return rv;
|
||||
NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv) ;
|
||||
if(NS_FAILED(rv)) return rv ;
|
||||
// Made second parameter 0 since I really don't know what it is used for
|
||||
rv = fts->CreateTransport(mSpec, PR_RDONLY, PR_IRWXU,
|
||||
getter_AddRefs(mFileTransport));
|
||||
rv = fts->CreateTransport(mSpec,0, "load", 0, 0, getter_AddRefs(mFileTransport)) ;
|
||||
if(NS_FAILED(rv))
|
||||
return rv;
|
||||
return rv ;
|
||||
|
||||
// we don't need to worry about notification callbacks
|
||||
|
||||
rv = mFileTransport->OpenInputStream(aResult);
|
||||
rv = mFileTransport->OpenInputStream(aStartPosition, aReadCount, aResult) ;
|
||||
if(NS_FAILED(rv))
|
||||
mFileTransport = nsnull;
|
||||
mFileTransport = nsnull ;
|
||||
|
||||
return rv;
|
||||
return rv ;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::OpenOutputStream(nsIOutputStream* *aResult)
|
||||
nsDiskCacheRecordChannel::OpenOutputStream(PRUint32 startPosition,
|
||||
nsIOutputStream* *aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_ENSURE_ARG(aResult);
|
||||
nsresult rv ;
|
||||
NS_ENSURE_ARG(aResult) ;
|
||||
|
||||
if(mFileTransport)
|
||||
return NS_ERROR_IN_PROGRESS;
|
||||
return NS_ERROR_IN_PROGRESS ;
|
||||
|
||||
nsCOMPtr<nsIOutputStream> outputStream;
|
||||
nsCOMPtr<nsIOutputStream> outputStream ;
|
||||
|
||||
NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv);
|
||||
if(NS_FAILED(rv)) return rv;
|
||||
NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv) ;
|
||||
if(NS_FAILED(rv)) return rv ;
|
||||
// Made second parameter 0 since I really don't know what it is used for
|
||||
rv = fts->CreateTransport(mSpec, PR_WRONLY | PR_CREATE_FILE, PR_IRWXU,
|
||||
getter_AddRefs(mFileTransport));
|
||||
rv = fts->CreateTransport(mSpec,0, "load", 0, 0, getter_AddRefs(mFileTransport)) ;
|
||||
if(NS_FAILED(rv))
|
||||
return rv;
|
||||
return rv ;
|
||||
|
||||
// we don't need to worry about notification callbacks
|
||||
|
||||
rv = mFileTransport->OpenOutputStream(getter_AddRefs(outputStream));
|
||||
rv = mFileTransport->OpenOutputStream(startPosition, getter_AddRefs(outputStream)) ;
|
||||
if(NS_FAILED(rv)) {
|
||||
mFileTransport = nsnull;
|
||||
return rv;
|
||||
mFileTransport = nsnull ;
|
||||
return rv ;
|
||||
}
|
||||
|
||||
return WriteStreamWrapper::Create(this, outputStream, aResult);
|
||||
return WriteStreamWrapper::Create(this, outputStream, aResult) ;
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::AsyncOpen(nsIStreamObserver *observer,
|
||||
nsISupports *ctxt)
|
||||
{
|
||||
NS_NOTREACHED("nsDiskCacheRecordChannel::AsyncOpen");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
return NS_ERROR_NOT_IMPLEMENTED ;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::AsyncRead(nsIStreamListener *aListener,
|
||||
nsISupports *aContext)
|
||||
nsDiskCacheRecordChannel::AsyncRead(PRUint32 aStartPosition,
|
||||
PRInt32 aReadCount,
|
||||
nsISupports *aContext,
|
||||
nsIStreamListener *aListener)
|
||||
{
|
||||
nsresult rv;
|
||||
nsresult rv ;
|
||||
|
||||
if(mFileTransport)
|
||||
return NS_ERROR_IN_PROGRESS;
|
||||
return NS_ERROR_IN_PROGRESS ;
|
||||
|
||||
mRealListener = aListener;
|
||||
nsCOMPtr<nsIStreamListener> tempListener = this;
|
||||
@@ -358,13 +334,15 @@ nsDiskCacheRecordChannel::AsyncRead(nsIStreamListener *aListener,
|
||||
NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
// Made second parameter 0 since I really don't know what it is used for
|
||||
rv = fts->CreateTransport(mSpec, PR_RDONLY, PR_IRWXU,
|
||||
getter_AddRefs(mFileTransport));
|
||||
rv = fts->CreateTransport(mSpec,0, "load", 0, 0, getter_AddRefs(mFileTransport));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// no callbacks
|
||||
|
||||
rv = mFileTransport->AsyncRead(tempListener, aContext);
|
||||
rv = mFileTransport->AsyncRead(aStartPosition,
|
||||
aReadCount,
|
||||
aContext,
|
||||
tempListener);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
// release the transport so that we don't think we're in progress
|
||||
@@ -375,24 +353,25 @@ nsDiskCacheRecordChannel::AsyncRead(nsIStreamListener *aListener,
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::AsyncWrite(nsIInputStream *fromStream,
|
||||
nsIStreamObserver *observer,
|
||||
nsISupports *ctxt)
|
||||
PRUint32 startPosition,
|
||||
PRInt32 writeCount,
|
||||
nsISupports *ctxt,
|
||||
nsIStreamObserver *observer)
|
||||
|
||||
{
|
||||
/*
|
||||
if(!mFileTransport)
|
||||
return NS_ERROR_FAILURE;
|
||||
return NS_ERROR_FAILURE ;
|
||||
|
||||
return mFileTransport->AsyncWrite(fromStream,
|
||||
startPosition,
|
||||
writeCount,
|
||||
ctxt,
|
||||
observer);
|
||||
observer) ;
|
||||
*/
|
||||
|
||||
// I can't do this since the write is not monitored, and I won't be
|
||||
// able to updata the storage.
|
||||
NS_NOTREACHED("nsDiskCacheRecordChannel::AsyncWrite");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@@ -400,7 +379,7 @@ NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::GetLoadAttributes(nsLoadFlags *aLoadAttributes)
|
||||
{
|
||||
// Not required to be implemented, since it is implemented by cache manager
|
||||
NS_NOTREACHED("nsDiskCacheRecordChannel::GetLoadAttributes");
|
||||
NS_ASSERTION(0, "nsDiskCacheRecordChannel method unexpectedly called");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@@ -408,22 +387,23 @@ NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::SetLoadAttributes(nsLoadFlags aLoadAttributes)
|
||||
{
|
||||
// Not required to be implemented, since it is implemented by cache manager
|
||||
NS_NOTREACHED("nsDiskCacheRecordChannel::SetLoadAttributes");
|
||||
NS_ASSERTION(0, "nsDiskCacheRecordChannel method unexpectedly called");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
#define DUMMY_TYPE "application/x-unknown-content-type"
|
||||
#define DUMMY_TYPE "text/html"
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::GetContentType(char * *aContentType)
|
||||
{
|
||||
|
||||
// Not required to be implemented, since it is implemented by cache manager
|
||||
NS_NOTREACHED("nsDiskCacheRecordChannel::GetContentType");
|
||||
NS_ASSERTION(0, "nsDiskCacheRecordChannel method unexpectedly called");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
// This was the pre nsIFile stuff. Not sure if I have to implement this routines since
|
||||
// the memory cache doesn't
|
||||
#if 0
|
||||
nsresult rv;
|
||||
nsresult rv ;
|
||||
PRBool isDirectory;
|
||||
if ( NS_SUCCEEDED(mSpec->IsDirectory(&isDirectory)) && isDirectory) {
|
||||
*aContentType = nsCRT::strdup("application/http-index-format");
|
||||
@@ -433,8 +413,8 @@ nsDiskCacheRecordChannel::GetContentType(char * *aContentType)
|
||||
// I wish I can make this simplier
|
||||
|
||||
|
||||
char* urlStr;
|
||||
mRecord->mFile->GetURLString(&urlStr);
|
||||
char* urlStr ;
|
||||
mRecord->mFile->GetURLString(&urlStr) ;
|
||||
|
||||
// file: URLs (currently) have no additional structure beyond that provided by standard
|
||||
// URLs, so there is no "outer" given to CreateInstance
|
||||
@@ -443,7 +423,7 @@ nsDiskCacheRecordChannel::GetContentType(char * *aContentType)
|
||||
rv = nsComponentManager::CreateInstance(kStandardURLCID, nsnull,
|
||||
NS_GET_IID(nsIURI),
|
||||
//(void**)&url);
|
||||
getter_AddRefs(url));
|
||||
getter_AddRefs(url)) ;
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = url->SetSpec((char*)urlStr);
|
||||
@@ -458,19 +438,20 @@ nsDiskCacheRecordChannel::GetContentType(char * *aContentType)
|
||||
|
||||
}
|
||||
|
||||
|
||||
// if all else fails treat it as text/html?
|
||||
*aContentType = nsCRT::strdup(DUMMY_TYPE);
|
||||
if (!*aContentType) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
} else {
|
||||
return NS_OK;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDiskCacheRecordChannel::SetContentType(const char * aContentType)
|
||||
{
|
||||
NS_NOTREACHED("nsDiskCacheRecordChannel::SetContentType");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@@ -480,7 +461,7 @@ nsDiskCacheRecordChannel::GetContentLength(PRInt32 *aContentLength)
|
||||
PRUint32 length;
|
||||
|
||||
PRInt64 fileSize;
|
||||
rv = mRecord->mFile->GetFileSize( &fileSize);
|
||||
rv = mRecord->mFile->GetFileSize( &fileSize) ;
|
||||
LL_L2UI( length, fileSize );
|
||||
|
||||
|
||||
@@ -492,107 +473,19 @@ nsDiskCacheRecordChannel::GetContentLength(PRInt32 *aContentLength)
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::SetContentLength(PRInt32 aContentLength)
|
||||
{
|
||||
NS_NOTREACHED("nsDiskCacheRecordChannel::SetContentLength");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::GetTransferOffset(PRUint32 *aTransferOffset)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
if ( mFileTransport )
|
||||
rv = mFileTransport->GetTransferOffset( aTransferOffset );
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::SetTransferOffset(PRUint32 aTransferOffset)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if ( mFileTransport )
|
||||
rv = mFileTransport->SetTransferOffset( aTransferOffset );
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::GetTransferCount(PRInt32 *aTransferCount)
|
||||
{
|
||||
NS_NOTREACHED("nsDiskCacheRecordChannel::GetTransferCount");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::SetTransferCount(PRInt32 aTransferCount)
|
||||
{
|
||||
NS_NOTREACHED("nsDiskCacheRecordChannel::SetTransferCount");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::GetBufferSegmentSize(PRUint32 *aBufferSegmentSize)
|
||||
{
|
||||
NS_NOTREACHED("nsDiskCacheRecordChannel::GetBufferSegmentSize");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::SetBufferSegmentSize(PRUint32 aBufferSegmentSize)
|
||||
{
|
||||
NS_NOTREACHED("nsDiskCacheRecordChannel::SetBufferSegmentSize");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::GetBufferMaxSize(PRUint32 *aBufferMaxSize)
|
||||
{
|
||||
NS_NOTREACHED("nsDiskCacheRecordChannel::GetBufferMaxSize");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::SetBufferMaxSize(PRUint32 aBufferMaxSize)
|
||||
{
|
||||
NS_NOTREACHED("nsDiskCacheRecordChannel::SetBufferMaxSize");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::GetShouldCache(PRBool *aShouldCache)
|
||||
{
|
||||
*aShouldCache = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::GetPipeliningAllowed(PRBool *aPipeliningAllowed)
|
||||
{
|
||||
*aPipeliningAllowed = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::SetPipeliningAllowed(PRBool aPipeliningAllowed)
|
||||
{
|
||||
NS_NOTREACHED("SetPipeliningAllowed");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::GetOwner(nsISupports* *aOwner)
|
||||
{
|
||||
*aOwner = mOwner.get();
|
||||
NS_IF_ADDREF(*aOwner);
|
||||
return NS_OK;
|
||||
*aOwner = mOwner.get() ;
|
||||
NS_IF_ADDREF(*aOwner) ;
|
||||
return NS_OK ;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::SetOwner(nsISupports* aOwner)
|
||||
{
|
||||
mOwner = aOwner;
|
||||
return NS_OK;
|
||||
mOwner = aOwner ;
|
||||
return NS_OK ;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@@ -600,7 +493,7 @@ nsDiskCacheRecordChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup)
|
||||
{
|
||||
// Not required to be implemented, since it is implemented by cache manager
|
||||
NS_ASSERTION(0, "nsDiskCacheRecordChannel method unexpectedly called");
|
||||
return NS_OK;
|
||||
return NS_OK ;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@@ -615,7 +508,7 @@ NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::GetNotificationCallbacks(nsIInterfaceRequestor* *aNotificationCallbacks)
|
||||
{
|
||||
// Not required to be implemented, since it is implemented by cache manager
|
||||
NS_NOTREACHED("nsDiskCacheRecordChannel::GetNotificationCallbacks");
|
||||
NS_ASSERTION(0, "nsDiskCacheRecordChannel method unexpectedly called");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@@ -623,15 +516,8 @@ NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCallbacks)
|
||||
{
|
||||
// Not required to be implemented, since it is implemented by cache manager
|
||||
NS_NOTREACHED("nsDiskCacheRecordChannel::SetNotificationCallbacks");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDiskCacheRecordChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
|
||||
{
|
||||
*aSecurityInfo = nsnull;
|
||||
return NS_OK;
|
||||
NS_ASSERTION(0, "nsDiskCacheRecordChannel method unexpectedly called");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -681,7 +567,7 @@ nsDiskCacheRecordChannel::OnDataAvailable(nsIChannel* transportChannel, nsISuppo
|
||||
// for the consumer to empty the pipe...
|
||||
//
|
||||
if (NS_FAILED(rv)) {
|
||||
mFileTransport->Cancel(rv);
|
||||
mFileTransport->Cancel();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -66,9 +66,8 @@ class nsDiskCacheRecordChannel : public nsIChannel,
|
||||
nsCOMPtr<nsILoadGroup> mLoadGroup ;
|
||||
nsCOMPtr<nsISupports> mOwner ;
|
||||
nsCOMPtr<nsIChannel> mFileTransport ;
|
||||
nsCOMPtr< nsIFile > mSpec ;
|
||||
nsCOMPtr< nsIFile > mSpec ;
|
||||
nsCOMPtr<nsIStreamListener> mRealListener;
|
||||
nsresult mStatus;
|
||||
|
||||
friend class WriteStreamWrapper ;
|
||||
} ;
|
||||
|
||||
151
mozilla/netwerk/cache/filecache/nsNetDiskCache.cpp
vendored
151
mozilla/netwerk/cache/filecache/nsNetDiskCache.cpp
vendored
@@ -72,51 +72,6 @@ static const char * const DISK_CACHE_SIZE_PREF = "browser.cache.disk_cache_size
|
||||
static const char * const CACHE_DIR_PREF = "browser.cache.directory";
|
||||
static const char * const CACHE_ENABLE_PREF = "browser.cache.disk.enable";
|
||||
|
||||
|
||||
static int folderChanged(const char *pref, void *closure)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_PROGID, &rv);
|
||||
if ( NS_FAILED (rv ) )
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIFileSpec> folder;
|
||||
rv = prefs->GetFilePref(CACHE_DIR_PREF, getter_AddRefs( folder ) );
|
||||
|
||||
if ( NS_FAILED( rv ) )
|
||||
return rv;
|
||||
|
||||
// This is really wrong and should be fixed when the pref code is update
|
||||
// If someone has a system where path names are not unique they are going to
|
||||
// be in a world of hurt.
|
||||
|
||||
nsCOMPtr<nsILocalFile> cacheFolder;
|
||||
char* path = NULL;
|
||||
rv = folder->GetNativePath(& path );
|
||||
if ( NS_FAILED ( rv ) )
|
||||
return rv;
|
||||
|
||||
rv = NS_NewLocalFile( path, getter_AddRefs(cacheFolder));
|
||||
nsAllocator::Free( path );
|
||||
|
||||
return ( (nsNetDiskCache*)closure )->SetDiskCacheFolder( cacheFolder );
|
||||
}
|
||||
|
||||
static int enableChanged(const char *pref, void *closure)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_PROGID, &rv);
|
||||
if ( NS_FAILED (rv ) )
|
||||
return rv;
|
||||
|
||||
PRBool enabled;
|
||||
rv = prefs->GetBoolPref(CACHE_ENABLE_PREF, &enabled );
|
||||
if ( NS_FAILED( rv ) )
|
||||
return rv;
|
||||
|
||||
return ( (nsNetDiskCache*)closure )->SetEnabled( enabled );
|
||||
}
|
||||
|
||||
class nsDiskCacheRecord ;
|
||||
|
||||
nsNetDiskCache::nsNetDiskCache() :
|
||||
@@ -137,18 +92,11 @@ nsNetDiskCache::nsNetDiskCache() :
|
||||
|
||||
nsNetDiskCache::~nsNetDiskCache()
|
||||
{
|
||||
if ( mDB )
|
||||
SetSizeEntry();
|
||||
SetSizeEntry() ;
|
||||
|
||||
NS_IF_RELEASE(mDB) ;
|
||||
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_PROGID, &rv);
|
||||
if ( NS_SUCCEEDED (rv ) )
|
||||
{
|
||||
prefs->UnregisterCallback( CACHE_DIR_PREF, folderChanged, this );
|
||||
prefs->UnregisterCallback( CACHE_ENABLE_PREF, enableChanged, this );
|
||||
}
|
||||
|
||||
// FUR
|
||||
// I think that, eventually, we also want a distinguished key in the DB which
|
||||
// means "clean cache shutdown". You clear this flag when the db is first
|
||||
@@ -164,8 +112,8 @@ nsNetDiskCache::~nsNetDiskCache()
|
||||
if(mDBCorrupted) {
|
||||
|
||||
nsCOMPtr<nsISimpleEnumerator> directoryEnumerator;
|
||||
nsresult res = mDiskCacheFolder->GetDirectoryEntries( getter_AddRefs( directoryEnumerator) ) ;
|
||||
if ( NS_FAILED ( res ) )
|
||||
nsresult rv = mDiskCacheFolder->GetDirectoryEntries( getter_AddRefs( directoryEnumerator) ) ;
|
||||
if ( NS_FAILED ( rv ) )
|
||||
return;
|
||||
|
||||
nsCString trash("trash") ;
|
||||
@@ -184,7 +132,7 @@ nsNetDiskCache::~nsNetDiskCache()
|
||||
return;
|
||||
|
||||
|
||||
if( trash.CompareWithConversion( filename, PR_FALSE, 5 ) == 0)
|
||||
if( trash.Compare( filename, PR_FALSE, 5 ) == 0)
|
||||
file->Delete( PR_TRUE );
|
||||
|
||||
nsCRT::free(filename) ;
|
||||
@@ -193,6 +141,47 @@ nsNetDiskCache::~nsNetDiskCache()
|
||||
}
|
||||
|
||||
|
||||
static int folderChanged(const char *pref, void *closure)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_PROGID, &rv);
|
||||
if ( NS_FAILED (rv ) )
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIFileSpec> folder;
|
||||
rv = prefs->GetFilePref(CACHE_DIR_PREF, getter_AddRefs( folder ) );
|
||||
|
||||
if ( NS_FAILED( rv ) )
|
||||
return rv;
|
||||
|
||||
// This is really wrong and should be fixed when the pref code is update
|
||||
// If someone has a system where path names are not unique they are going to
|
||||
// be in a world of hurt.
|
||||
|
||||
nsCOMPtr<nsILocalFile> cacheFolder;
|
||||
char* path;
|
||||
folder->GetNativePath(& path );
|
||||
rv = NS_NewLocalFile( path, getter_AddRefs(cacheFolder));
|
||||
nsAllocator::Free( path );
|
||||
|
||||
return ( (nsNetDiskCache*)closure )->SetDiskCacheFolder( cacheFolder );
|
||||
}
|
||||
|
||||
static int enableChanged(const char *pref, void *closure)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_PROGID, &rv);
|
||||
if ( NS_FAILED (rv ) )
|
||||
return rv;
|
||||
|
||||
PRBool enabled;
|
||||
rv = prefs->GetBoolPref(CACHE_ENABLE_PREF, &enabled );
|
||||
if ( NS_FAILED( rv ) )
|
||||
return rv;
|
||||
|
||||
return ( (nsNetDiskCache*)closure )->SetEnabled( enabled );
|
||||
}
|
||||
|
||||
nsresult nsNetDiskCache::InitPrefs()
|
||||
{
|
||||
nsresult rv;
|
||||
@@ -256,10 +245,17 @@ NS_IMETHODIMP nsNetDiskCache::InitCacheFolder()
|
||||
NS_IMETHODIMP
|
||||
nsNetDiskCache::Init(void)
|
||||
{
|
||||
nsresult rv =InitPrefs();
|
||||
/// Couldn't find a meaningful pref value for the cache location so create one in the users profile
|
||||
|
||||
|
||||
|
||||
// Couldn't find a meaningful pref value for the cache location so create one in the users profile
|
||||
InitPrefs();
|
||||
|
||||
if (!mDiskCacheFolder.get() )
|
||||
{
|
||||
{
|
||||
|
||||
nsresult rv ;
|
||||
|
||||
nsCOMPtr<nsIFileSpec> cacheSubDir;
|
||||
rv = NS_NewFileSpec(getter_AddRefs(cacheSubDir));
|
||||
if(NS_FAILED(rv))
|
||||
@@ -283,19 +279,12 @@ nsNetDiskCache::Init(void)
|
||||
cacheSubDir->GetNativePath(& path );
|
||||
rv = NS_NewLocalFile( path, getter_AddRefs(cacheFolder));
|
||||
nsAllocator::Free( path );
|
||||
|
||||
PRBool exists;
|
||||
if ( NS_SUCCEEDED( cacheFolder->Exists(&exists ) ) && !exists)
|
||||
{
|
||||
rv = cacheFolder->Create( nsIFile::DIRECTORY_TYPE, PR_IRWXU );
|
||||
if ( NS_FAILED( rv ) )
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
mDiskCacheFolder = cacheFolder;
|
||||
rv =InitCacheFolder();
|
||||
|
||||
}
|
||||
return rv;
|
||||
|
||||
return InitCacheFolder();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@@ -312,7 +301,7 @@ nsNetDiskCache::InitDB(void)
|
||||
PRBool exists;
|
||||
if ( NS_SUCCEEDED( mDBFile->Exists(&exists ) ) && !exists)
|
||||
{
|
||||
mDBFile->Create( nsIFile::NORMAL_FILE_TYPE, PR_IRWXU );
|
||||
mDBFile->Create( nsIFile::NORMAL_FILE_TYPE, 0 );
|
||||
}
|
||||
#endif
|
||||
rv = mDB->Init(mDBFile) ;
|
||||
@@ -335,9 +324,7 @@ NS_IMPL_ISUPPORTS3(nsNetDiskCache,
|
||||
NS_IMETHODIMP
|
||||
nsNetDiskCache::GetDescription(PRUnichar* *aDescription)
|
||||
{
|
||||
nsAutoString description ;
|
||||
description.AssignWithConversion("Disk Cache") ;
|
||||
|
||||
nsAutoString description("Disk Cache") ;
|
||||
*aDescription = description.ToNewUnicode() ;
|
||||
if(!*aDescription)
|
||||
return NS_ERROR_OUT_OF_MEMORY ;
|
||||
@@ -584,9 +571,9 @@ nsNetDiskCache::RemoveAll(void)
|
||||
// Delete all the files in the cache directory
|
||||
// Could I just delete the cache folder????? --DJM
|
||||
nsCOMPtr<nsISimpleEnumerator> directoryEnumerator;
|
||||
nsresult res = mDiskCacheFolder->GetDirectoryEntries( getter_AddRefs( directoryEnumerator) ) ;
|
||||
if ( NS_FAILED ( res ) )
|
||||
return res;
|
||||
nsresult rv = mDiskCacheFolder->GetDirectoryEntries( getter_AddRefs( directoryEnumerator) ) ;
|
||||
if ( NS_FAILED ( rv ) )
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIFile> file;
|
||||
|
||||
@@ -601,8 +588,7 @@ nsNetDiskCache::RemoveAll(void)
|
||||
file->Delete( PR_TRUE );
|
||||
|
||||
}
|
||||
if ( mDBFile )
|
||||
mDBFile->Delete(PR_FALSE) ;
|
||||
|
||||
// reinitilize
|
||||
return InitCacheFolder() ;
|
||||
}
|
||||
@@ -671,7 +657,7 @@ nsNetDiskCache::CreateDir(nsIFile* dir_spec)
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = dir_spec->Create( nsIFile::DIRECTORY_TYPE, PR_IRWXU) ;
|
||||
rv = dir_spec->Create( nsIFile::DIRECTORY_TYPE, 0) ;
|
||||
return rv ;
|
||||
}
|
||||
|
||||
@@ -769,11 +755,8 @@ nsNetDiskCache::DBRecovery(void)
|
||||
|
||||
// reinitilize DB
|
||||
return InitDB() ;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// this routine will add string "trash" to current CacheSubDir names.
|
||||
// e.g. 00->trash00, 1f->trash1f. and update the mDBCorrupted.
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "nsINetDataDiskCache.h"
|
||||
#include "nsNetDiskCacheCID.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsDBAccessor.h"
|
||||
|
||||
class nsIURI; /* forward decl */
|
||||
|
||||
@@ -36,7 +36,7 @@ endif
|
||||
|
||||
LIBS = \
|
||||
-lmozjs \
|
||||
$(XPCOM_LIBS) \
|
||||
-lxpcom \
|
||||
-lmozdbm_s \
|
||||
$(MOZ_NECKO_UTIL_LIBS) \
|
||||
$(LOST_SYM_LIBS) \
|
||||
|
||||
@@ -71,9 +71,7 @@ NS_IMPL_ISUPPORTS(nsMemCache, NS_GET_IID(nsINetDataCache))
|
||||
NS_IMETHODIMP
|
||||
nsMemCache::GetDescription(PRUnichar * *aDescription)
|
||||
{
|
||||
nsAutoString description;
|
||||
description.AssignWithConversion("Memory Cache");
|
||||
|
||||
nsAutoString description("Memory Cache");
|
||||
*aDescription = description.ToNewUnicode();
|
||||
if (!*aDescription)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
221
mozilla/netwerk/cache/memcache/nsMemCacheChannel.cpp
vendored
221
mozilla/netwerk/cache/memcache/nsMemCacheChannel.cpp
vendored
@@ -52,7 +52,7 @@ class AsyncReadStreamAdaptor : public nsIInputStream,
|
||||
public:
|
||||
AsyncReadStreamAdaptor(nsMemCacheChannel* aChannel, nsIInputStream *aSyncStream):
|
||||
mSyncStream(aSyncStream), mDataAvailCursor(0),
|
||||
mRemaining(-1), mAvailable(0), mChannel(aChannel), mAbortStatus(NS_OK), mSuspended(PR_FALSE)
|
||||
mRemaining(0), mAvailable(0), mChannel(aChannel), mAborted(PR_FALSE), mSuspended(PR_FALSE)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF(mChannel);
|
||||
@@ -67,15 +67,15 @@ public:
|
||||
|
||||
nsresult
|
||||
IsPending(PRBool* aIsPending) {
|
||||
*aIsPending = (mRemaining != 0) && NS_SUCCEEDED(mAbortStatus);
|
||||
*aIsPending = (mRemaining != 0) && !mAborted;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
Cancel(nsresult status) {
|
||||
if (NS_SUCCEEDED(mAbortStatus)) {
|
||||
mAbortStatus = status;
|
||||
return mEventQueueStreamListener->OnStopRequest(mChannel, mContext, status, nsnull);
|
||||
Cancel(void) {
|
||||
if (!mAborted) {
|
||||
mAborted = PR_TRUE;
|
||||
return mEventQueueStreamListener->OnStopRequest(mChannel, mContext, NS_BINDING_ABORTED, nsnull);
|
||||
} else {
|
||||
// Cancel has already been called... Do not fire another OnStopRequest!
|
||||
return NS_OK;
|
||||
@@ -108,10 +108,10 @@ public:
|
||||
|
||||
rv = mDownstreamListener->OnDataAvailable(mChannel, aContext, inStr, sourceOffset, count);
|
||||
if (NS_FAILED(rv)) {
|
||||
Cancel(rv);
|
||||
Cancel();
|
||||
return rv;
|
||||
}
|
||||
if (!mSuspended && NS_SUCCEEDED(mAbortStatus)) {
|
||||
if (!mSuspended && !mAborted) {
|
||||
rv = NextListenerEvent();
|
||||
if (NS_FAILED(rv)) {
|
||||
Fail();
|
||||
@@ -132,7 +132,7 @@ public:
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
Cancel(rv);
|
||||
Cancel();
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -160,8 +160,8 @@ public:
|
||||
|
||||
NS_IMETHOD
|
||||
Read(char* aBuf, PRUint32 aCount, PRUint32 *aBytesRead) {
|
||||
if (NS_FAILED(mAbortStatus))
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
if (mAborted)
|
||||
return NS_ERROR_ABORT;
|
||||
|
||||
*aBytesRead = 0;
|
||||
aCount = PR_MIN(aCount, mAvailable);
|
||||
@@ -186,26 +186,16 @@ public:
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHOD
|
||||
GetTransferCount(nsLoadFlags *aTransferCount) {
|
||||
*aTransferCount = mRemaining;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD
|
||||
SetTransferCount(nsLoadFlags aTransferCount) {
|
||||
mRemaining = aTransferCount;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
AsyncRead(nsIStreamListener* aListener, nsISupports* aContext) {
|
||||
AsyncRead(PRUint32 aStartPosition, PRInt32 aReadCount,
|
||||
nsISupports* aContext, nsIStreamListener* aListener) {
|
||||
|
||||
nsresult rv;
|
||||
nsIEventQueue *eventQ;
|
||||
|
||||
mContext = aContext;
|
||||
mDownstreamListener = aListener;
|
||||
mRemaining = aReadCount;
|
||||
|
||||
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
@@ -216,8 +206,8 @@ public:
|
||||
rv = eventQService->GetThreadEventQueue(PR_CurrentThread(), &eventQ);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = NS_NewAsyncStreamListener(getter_AddRefs(mEventQueueStreamListener),
|
||||
NS_STATIC_CAST(nsIStreamListener*, this), eventQ);
|
||||
rv = NS_NewAsyncStreamListener(NS_STATIC_CAST(nsIStreamListener*, this), eventQ,
|
||||
getter_AddRefs(mEventQueueStreamListener));
|
||||
NS_RELEASE(eventQ);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
@@ -231,7 +221,7 @@ protected:
|
||||
|
||||
nsresult
|
||||
Fail(void) {
|
||||
mAbortStatus = NS_BINDING_ABORTED;
|
||||
mAborted = PR_TRUE;
|
||||
return mEventQueueStreamListener->OnStopRequest(mChannel, mContext, NS_BINDING_FAILED, nsnull);
|
||||
}
|
||||
|
||||
@@ -274,7 +264,7 @@ private:
|
||||
PRUint32 mAvailable; // Number of bytes for which OnDataAvailable fired
|
||||
nsMemCacheChannel* mChannel; // Associated memory cache channel, strong link
|
||||
// but can not use nsCOMPtr
|
||||
nsresult mAbortStatus; // Abort() has been called
|
||||
PRBool mAborted; // Abort() has been called
|
||||
PRBool mSuspended; // Suspend() has been called
|
||||
};
|
||||
|
||||
@@ -328,7 +318,7 @@ private:
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(MemCacheWriteStreamWrapper, nsIOutputStream)
|
||||
|
||||
nsMemCacheChannel::nsMemCacheChannel(nsMemCacheRecord *aRecord, nsILoadGroup *aLoadGroup)
|
||||
: mRecord(aRecord), mStartOffset(0), mStatus(NS_OK)
|
||||
: mRecord(aRecord)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mRecord->mNumChannels++;
|
||||
@@ -349,19 +339,11 @@ nsMemCacheChannel::IsPending(PRBool* aIsPending)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemCacheChannel::GetStatus(nsresult *status)
|
||||
nsMemCacheChannel::Cancel(void)
|
||||
{
|
||||
*status = mStatus;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemCacheChannel::Cancel(nsresult status)
|
||||
{
|
||||
mStatus = status;
|
||||
if (!mAsyncReadStream)
|
||||
return NS_ERROR_FAILURE;
|
||||
return mAsyncReadStream->Cancel(status);
|
||||
return mAsyncReadStream->Cancel();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@@ -381,54 +363,37 @@ nsMemCacheChannel::Resume(void)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemCacheChannel::GetOriginalURI(nsIURI* *aURI)
|
||||
nsMemCacheChannel::GetOriginalURI(nsIURI * *aURI)
|
||||
{
|
||||
// Not required
|
||||
NS_NOTREACHED("nsMemCacheChannel::GetOriginalURI");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemCacheChannel::SetOriginalURI(nsIURI* aURI)
|
||||
{
|
||||
// Not required
|
||||
NS_NOTREACHED("nsMemCacheChannel::SetOriginalURI");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemCacheChannel::GetURI(nsIURI* *aURI)
|
||||
nsMemCacheChannel::GetURI(nsIURI * *aURI)
|
||||
{
|
||||
// Not required to be implemented, since it is implemented by cache manager
|
||||
NS_NOTREACHED("nsMemCacheChannel::GetURI");
|
||||
NS_ASSERTION(0, "nsMemCacheChannel method unexpectedly called");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemCacheChannel::SetURI(nsIURI* aURI)
|
||||
{
|
||||
// Not required to be implemented, since it is implemented by cache manager
|
||||
NS_NOTREACHED("nsMemCacheChannel::SetURI");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemCacheChannel::OpenInputStream(nsIInputStream* *aResult)
|
||||
nsMemCacheChannel::OpenInputStream(PRUint32 aStartPosition, PRInt32 aReadCount,
|
||||
nsIInputStream* *aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_ENSURE_ARG(aResult);
|
||||
if (mInputStream)
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
rv = mRecord->mStorageStream->NewInputStream(mStartOffset, getter_AddRefs(mInputStream));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = mRecord->mStorageStream->NewInputStream(aStartPosition, getter_AddRefs(mInputStream));
|
||||
*aResult = mInputStream;
|
||||
NS_ADDREF(*aResult);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemCacheChannel::OpenOutputStream(nsIOutputStream* *aResult)
|
||||
nsMemCacheChannel::OpenOutputStream(PRUint32 startPosition, nsIOutputStream* *aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_ENSURE_ARG(aResult);
|
||||
@@ -437,10 +402,10 @@ nsMemCacheChannel::OpenOutputStream(nsIOutputStream* *aResult)
|
||||
|
||||
PRUint32 oldLength;
|
||||
mRecord->mStorageStream->GetLength(&oldLength);
|
||||
rv = mRecord->mStorageStream->GetOutputStream(mStartOffset, getter_AddRefs(outputStream));
|
||||
rv = mRecord->mStorageStream->GetOutputStream(startPosition, getter_AddRefs(outputStream));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (mStartOffset < oldLength)
|
||||
NotifyStorageInUse(mStartOffset - oldLength);
|
||||
if (startPosition < oldLength)
|
||||
NotifyStorageInUse(startPosition - oldLength);
|
||||
|
||||
return MemCacheWriteStreamWrapper::Create(this, outputStream, aResult);
|
||||
}
|
||||
@@ -449,15 +414,15 @@ NS_IMETHODIMP
|
||||
nsMemCacheChannel::AsyncOpen(nsIStreamObserver *observer, nsISupports *ctxt)
|
||||
{
|
||||
// Not required
|
||||
NS_NOTREACHED("nsMemCacheChannel::AsyncOpen");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemCacheChannel::AsyncRead(nsIStreamListener *aListener, nsISupports *aContext)
|
||||
nsMemCacheChannel::AsyncRead(PRUint32 aStartPosition, PRInt32 aReadCount,
|
||||
nsISupports *aContext, nsIStreamListener *aListener)
|
||||
{
|
||||
nsCOMPtr<nsIInputStream> inputStream;
|
||||
nsresult rv = OpenInputStream(getter_AddRefs(inputStream));
|
||||
nsresult rv = OpenInputStream(aStartPosition, aReadCount, getter_AddRefs(inputStream));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
AsyncReadStreamAdaptor *asyncReadStreamAdaptor;
|
||||
@@ -467,102 +432,19 @@ nsMemCacheChannel::AsyncRead(nsIStreamListener *aListener, nsISupports *aContext
|
||||
NS_ADDREF(asyncReadStreamAdaptor);
|
||||
mAsyncReadStream = asyncReadStreamAdaptor;
|
||||
|
||||
rv = asyncReadStreamAdaptor->AsyncRead(aListener, aContext);
|
||||
rv = asyncReadStreamAdaptor->AsyncRead(aStartPosition, aReadCount, aContext, aListener);
|
||||
if (NS_FAILED(rv))
|
||||
delete asyncReadStreamAdaptor;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemCacheChannel::AsyncWrite(nsIInputStream *fromStream,
|
||||
nsIStreamObserver *observer, nsISupports *ctxt)
|
||||
nsMemCacheChannel::AsyncWrite(nsIInputStream *fromStream, PRUint32 startPosition,
|
||||
PRInt32 writeCount, nsISupports *ctxt,
|
||||
nsIStreamObserver *observer)
|
||||
{
|
||||
// Not required to be implemented
|
||||
NS_NOTREACHED("nsMemCacheChannel::AsyncWrite");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemCacheChannel::GetTransferOffset(PRUint32 *aTransferOffset)
|
||||
{
|
||||
*aTransferOffset = mStartOffset;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemCacheChannel::SetTransferOffset(PRUint32 aTransferOffset)
|
||||
{
|
||||
mStartOffset = aTransferOffset;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemCacheChannel::GetTransferCount(PRInt32 *aTransferCount)
|
||||
{
|
||||
NS_NOTREACHED("nsMemCacheChannel::GetTransferCount");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemCacheChannel::SetTransferCount(PRInt32 aTransferCount)
|
||||
{
|
||||
NS_NOTREACHED("nsMemCacheChannel::SetTransferCount");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemCacheChannel::GetBufferSegmentSize(PRUint32 *aBufferSegmentSize)
|
||||
{
|
||||
NS_NOTREACHED("nsMemCacheChannel::GetBufferSegmentSize");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemCacheChannel::SetBufferSegmentSize(PRUint32 aBufferSegmentSize)
|
||||
{
|
||||
NS_NOTREACHED("nsMemCacheChannel::SetBufferSegmentSize");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemCacheChannel::GetBufferMaxSize(PRUint32 *aBufferMaxSize)
|
||||
{
|
||||
NS_NOTREACHED("nsMemCacheChannel::GetBufferMaxSize");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemCacheChannel::SetBufferMaxSize(PRUint32 aBufferMaxSize)
|
||||
{
|
||||
NS_NOTREACHED("nsMemCacheChannel::SetBufferMaxSize");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemCacheChannel::GetShouldCache(PRBool *aShouldCache)
|
||||
{
|
||||
*aShouldCache = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemCacheChannel::GetPipeliningAllowed(PRBool *aPipeliningAllowed)
|
||||
{
|
||||
*aPipeliningAllowed = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemCacheChannel::SetPipeliningAllowed(PRBool aPipeliningAllowed)
|
||||
{
|
||||
NS_NOTREACHED("SetPipeliningAllowed");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemCacheChannel::SetContentLength(PRInt32 aContentLength)
|
||||
{
|
||||
NS_NOTREACHED("nsMemCacheChannel::SetContentLength");
|
||||
NS_ASSERTION(0, "nsMemCacheChannel method unexpectedly called");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@@ -570,7 +452,7 @@ NS_IMETHODIMP
|
||||
nsMemCacheChannel::GetLoadAttributes(nsLoadFlags *aLoadAttributes)
|
||||
{
|
||||
// Not required to be implemented, since it is implemented by cache manager
|
||||
NS_NOTREACHED("nsMemCacheChannel::GetLoadAttributes");
|
||||
NS_ASSERTION(0, "nsMemCacheChannel method unexpectedly called");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@@ -578,7 +460,7 @@ NS_IMETHODIMP
|
||||
nsMemCacheChannel::SetLoadAttributes(nsLoadFlags aLoadAttributes)
|
||||
{
|
||||
// Not required to be implemented, since it is implemented by cache manager
|
||||
NS_NOTREACHED("nsMemCacheChannel::SetLoadAttributes");
|
||||
NS_ASSERTION(0, "nsMemCacheChannel method unexpectedly called");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@@ -586,7 +468,7 @@ NS_IMETHODIMP
|
||||
nsMemCacheChannel::GetContentType(char* *aContentType)
|
||||
{
|
||||
// Not required to be implemented, since it is implemented by cache manager
|
||||
NS_NOTREACHED("nsMemCacheChannel::GetContentType");
|
||||
NS_ASSERTION(0, "nsMemCacheChannel method unexpectedly called");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@@ -594,7 +476,7 @@ NS_IMETHODIMP
|
||||
nsMemCacheChannel::SetContentType(const char *aContentType)
|
||||
{
|
||||
// Not required to be implemented, since it is implemented by cache manager
|
||||
NS_NOTREACHED("nsMemCacheChannel::SetContentType");
|
||||
NS_ASSERTION(0, "nsMemCacheChannel method unexpectedly called");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@@ -602,7 +484,7 @@ NS_IMETHODIMP
|
||||
nsMemCacheChannel::GetContentLength(PRInt32 *aContentLength)
|
||||
{
|
||||
// Not required to be implemented, since it is implemented by cache manager
|
||||
NS_NOTREACHED("nsMemCacheChannel::GetContentLength");
|
||||
NS_ASSERTION(0, "nsMemCacheChannel method unexpectedly called");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@@ -626,7 +508,7 @@ NS_IMETHODIMP
|
||||
nsMemCacheChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup)
|
||||
{
|
||||
// Not required to be implemented, since it is implemented by cache manager
|
||||
NS_NOTREACHED("nsMemCacheChannel::GetLoadGroup");
|
||||
NS_ASSERTION(0, "nsMemCacheChannel method unexpectedly called");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@@ -634,7 +516,7 @@ NS_IMETHODIMP
|
||||
nsMemCacheChannel::SetLoadGroup(nsILoadGroup* aLoadGroup)
|
||||
{
|
||||
// Not required to be implemented, since it is implemented by cache manager
|
||||
NS_NOTREACHED("nsMemCacheChannel::SetLoadGroup");
|
||||
NS_ASSERTION(0, "nsMemCacheChannel method unexpectedly called");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@@ -642,7 +524,7 @@ NS_IMETHODIMP
|
||||
nsMemCacheChannel::GetNotificationCallbacks(nsIInterfaceRequestor* *aNotificationCallbacks)
|
||||
{
|
||||
// Not required to be implemented, since it is implemented by cache manager
|
||||
NS_NOTREACHED("nsMemCacheChannel::GetNotificationCallbacks");
|
||||
NS_ASSERTION(0, "nsMemCacheChannel method unexpectedly called");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@@ -650,13 +532,6 @@ NS_IMETHODIMP
|
||||
nsMemCacheChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCallbacks)
|
||||
{
|
||||
// Not required to be implemented, since it is implemented by cache manager
|
||||
NS_NOTREACHED("nsMemCacheChannel::SetNotificationCallbacks");
|
||||
NS_ASSERTION(0, "nsMemCacheChannel method unexpectedly called");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemCacheChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
|
||||
{
|
||||
*aSecurityInfo = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -53,8 +53,6 @@ protected:
|
||||
nsCOMPtr<nsIInputStream> mInputStream;
|
||||
nsCOMPtr<nsISupports> mOwner;
|
||||
AsyncReadStreamAdaptor* mAsyncReadStream; // non-owning pointer
|
||||
PRUint32 mStartOffset;
|
||||
nsresult mStatus;
|
||||
|
||||
friend class MemCacheWriteStreamWrapper;
|
||||
friend class AsyncReadStreamAdaptor;
|
||||
|
||||
@@ -30,14 +30,9 @@
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsIAllocator.h"
|
||||
|
||||
nsCacheEntryChannel::nsCacheEntryChannel(
|
||||
nsCachedNetData* aCacheEntry,
|
||||
nsIChannel* aChannel,
|
||||
nsILoadGroup* aLoadGroup):
|
||||
nsChannelProxy(aChannel),
|
||||
mCacheEntry(aCacheEntry),
|
||||
mLoadGroup(aLoadGroup),
|
||||
mLoadAttributes(0)
|
||||
nsCacheEntryChannel::nsCacheEntryChannel(nsCachedNetData* aCacheEntry, nsIChannel* aChannel,
|
||||
nsILoadGroup* aLoadGroup):
|
||||
nsChannelProxy(aChannel), mCacheEntry(aCacheEntry), mLoadGroup(aLoadGroup), mLoadAttributes(0)
|
||||
{
|
||||
NS_ASSERTION(aCacheEntry->mChannelCount < 0xFF, "Overflowed channel counter");
|
||||
mCacheEntry->mChannelCount++;
|
||||
@@ -49,20 +44,14 @@ nsCacheEntryChannel::~nsCacheEntryChannel()
|
||||
mCacheEntry->mChannelCount--;
|
||||
}
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS3(nsCacheEntryChannel,
|
||||
nsISupports,
|
||||
nsIChannel,
|
||||
nsIRequest)
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS3(nsCacheEntryChannel, nsISupports, nsIChannel, nsIRequest)
|
||||
|
||||
// A proxy for nsIOutputStream
|
||||
class CacheOutputStream : public nsIOutputStream {
|
||||
|
||||
public:
|
||||
CacheOutputStream(nsIOutputStream *aOutputStream,
|
||||
nsCachedNetData *aCacheEntry):
|
||||
mOutputStream(aOutputStream),
|
||||
mCacheEntry(aCacheEntry),
|
||||
mStartTime(PR_IntervalNow())
|
||||
CacheOutputStream(nsIOutputStream *aOutputStream, nsCachedNetData *aCacheEntry):
|
||||
mOutputStream(aOutputStream), mCacheEntry(aCacheEntry), mStartTime(PR_IntervalNow())
|
||||
{ NS_INIT_REFCNT(); }
|
||||
|
||||
virtual ~CacheOutputStream() {
|
||||
@@ -101,41 +90,17 @@ protected:
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(CacheOutputStream, nsIOutputStream)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryChannel::GetTransferOffset(PRUint32 *aStartPosition)
|
||||
{
|
||||
return mChannel->GetTransferOffset(aStartPosition);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryChannel::SetTransferOffset(PRUint32 aStartPosition)
|
||||
{
|
||||
mCacheEntry->mLogicalLength = aStartPosition;
|
||||
return mChannel->SetTransferOffset(aStartPosition);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryChannel::GetTransferCount(PRInt32 *aReadCount)
|
||||
{
|
||||
return mChannel->GetTransferCount(aReadCount);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryChannel::SetTransferCount(PRInt32 aReadCount)
|
||||
{
|
||||
return mChannel->SetTransferCount(aReadCount);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryChannel::OpenOutputStream(nsIOutputStream* *aOutputStream)
|
||||
nsCacheEntryChannel::OpenOutputStream(PRUint32 aStartPosition, nsIOutputStream* *aOutputStream)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIOutputStream> baseOutputStream;
|
||||
|
||||
rv = mChannel->OpenOutputStream(getter_AddRefs(baseOutputStream));
|
||||
rv = mChannel->OpenOutputStream(aStartPosition, getter_AddRefs(baseOutputStream));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
mCacheEntry->NoteUpdate();
|
||||
mCacheEntry->NoteAccess();
|
||||
mCacheEntry->mLogicalLength = aStartPosition;
|
||||
|
||||
*aOutputStream = new CacheOutputStream(baseOutputStream, mCacheEntry);
|
||||
if (!*aOutputStream)
|
||||
@@ -145,15 +110,16 @@ nsCacheEntryChannel::OpenOutputStream(nsIOutputStream* *aOutputStream)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryChannel::OpenInputStream(nsIInputStream* *aInputStream)
|
||||
nsCacheEntryChannel::OpenInputStream(PRUint32 aStartPosition, PRInt32 aReadCount,
|
||||
nsIInputStream* *aInputStream)
|
||||
{
|
||||
mCacheEntry->NoteAccess();
|
||||
|
||||
return mChannel->OpenInputStream(aInputStream);
|
||||
return mChannel->OpenInputStream(aStartPosition, aReadCount, aInputStream);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryChannel::AsyncRead(nsIStreamListener *aListener, nsISupports *aContext)
|
||||
nsCacheEntryChannel::AsyncRead(PRUint32 aStartPosition, PRInt32 aReadCount,
|
||||
nsISupports *aContext, nsIStreamListener *aListener)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
@@ -165,18 +131,17 @@ nsCacheEntryChannel::AsyncRead(nsIStreamListener *aListener, nsISupports *aConte
|
||||
mLoadGroup->GetDefaultLoadAttributes(&mLoadAttributes);
|
||||
}
|
||||
|
||||
rv = mChannel->AsyncRead(aListener, aContext);
|
||||
rv = mChannel->AsyncRead(aStartPosition, aReadCount, aContext, aListener);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
// No async writes allowed to the cache yet
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryChannel::AsyncWrite(nsIInputStream *aFromStream,
|
||||
nsIStreamObserver *aObserver,
|
||||
nsISupports *aContext)
|
||||
nsCacheEntryChannel::AsyncWrite(nsIInputStream *aFromStream, PRUint32 aStartPosition,
|
||||
PRInt32 aWriteCount, nsISupports *aContext,
|
||||
nsIStreamObserver *aObserver)
|
||||
{
|
||||
NS_NOTREACHED("nsCacheEntryChannel::AsyncWrite");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@@ -215,7 +180,7 @@ nsCacheEntryChannel::GetURI(nsIURI * *aURI)
|
||||
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = serv->NewURI(spec, nsnull, aURI);
|
||||
rv = serv->NewURI(spec, 0, aURI);
|
||||
nsAllocator::Free(spec);
|
||||
return rv;
|
||||
}
|
||||
@@ -224,6 +189,5 @@ NS_IMETHODIMP
|
||||
nsCacheEntryChannel::GetOriginalURI(nsIURI * *aURI)
|
||||
{
|
||||
// FIXME - should return original URI passed into NewChannel() ?
|
||||
NS_NOTREACHED("nsCacheEntryChannel::GetOriginalURI");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
18
mozilla/netwerk/cache/mgr/nsCacheEntryChannel.h
vendored
18
mozilla/netwerk/cache/mgr/nsCacheEntryChannel.h
vendored
@@ -52,15 +52,14 @@ class nsCacheEntryChannel : public nsChannelProxy {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD GetTransferOffset(PRUint32 *aStartPosition);
|
||||
NS_IMETHOD SetTransferOffset(PRUint32 aStartPosition);
|
||||
NS_IMETHOD GetTransferCount(PRInt32 *aReadCount);
|
||||
NS_IMETHOD SetTransferCount(PRInt32 aReadCount);
|
||||
NS_IMETHOD OpenOutputStream(nsIOutputStream* *aOutputStream);
|
||||
NS_IMETHOD OpenInputStream(nsIInputStream* *aInputStream);
|
||||
NS_IMETHOD AsyncRead(nsIStreamListener *aListener, nsISupports *aContext);
|
||||
NS_IMETHOD AsyncWrite(nsIInputStream *aFromStream,
|
||||
nsIStreamObserver *aObserver, nsISupports *aContext);
|
||||
NS_IMETHOD OpenOutputStream(PRUint32 aStartPosition, nsIOutputStream* *aOutputStream);
|
||||
NS_IMETHOD OpenInputStream(PRUint32 aStartPosition, PRInt32 aReadCount,
|
||||
nsIInputStream* *aInputStream);
|
||||
NS_IMETHOD AsyncRead(PRUint32 aStartPosition, PRInt32 aReadCount,
|
||||
nsISupports *aContext, nsIStreamListener *aListener);
|
||||
NS_IMETHOD AsyncWrite(nsIInputStream *aFromStream, PRUint32 aStartPosition,
|
||||
PRInt32 aWriteCount, nsISupports *aContext,
|
||||
nsIStreamObserver *aObserver);
|
||||
NS_IMETHOD GetLoadAttributes(nsLoadFlags *aLoadAttributes);
|
||||
NS_IMETHOD SetLoadAttributes(nsLoadFlags aLoadAttributes);
|
||||
NS_IMETHOD GetLoadGroup(nsILoadGroup* *aLoadGroup);
|
||||
@@ -76,6 +75,7 @@ protected:
|
||||
private:
|
||||
nsCOMPtr<nsCachedNetData> mCacheEntry;
|
||||
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
||||
nsCOMPtr<nsIChannel> mProxyChannel;
|
||||
nsLoadFlags mLoadAttributes;
|
||||
};
|
||||
|
||||
|
||||
58
mozilla/netwerk/cache/mgr/nsCacheManager.cpp
vendored
58
mozilla/netwerk/cache/mgr/nsCacheManager.cpp
vendored
@@ -33,7 +33,7 @@
|
||||
#include "nsINetDataDiskCache.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#define FILE_CACHE_IS_READY
|
||||
//#define FILE_CACHE_IS_READY
|
||||
// Limit the number of entries in the cache to conserve memory space
|
||||
// in the nsReplacementPolicy code
|
||||
#define MAX_MEM_CACHE_ENTRIES 800
|
||||
@@ -45,29 +45,6 @@
|
||||
const char* CACHE_MEM_CAPACITY = "browser.cache.memory_cache_size";
|
||||
const char* CACHE_DISK_CAPACITY = "browser.cache.disk_cache_size";
|
||||
|
||||
static int diskCacheSizeChanged(const char *pref, void *closure)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_PROGID, &rv);
|
||||
PRInt32 capacity = DEFAULT_DISK_CACHE_CAPACITY;
|
||||
if ( NS_SUCCEEDED (rv ) )
|
||||
{
|
||||
rv = prefs->GetIntPref(CACHE_DISK_CAPACITY, &capacity );
|
||||
}
|
||||
return ( (nsCacheManager*)closure )->SetDiskCacheCapacity( capacity );
|
||||
}
|
||||
|
||||
static int memCacheSizeChanged(const char *pref, void *closure)
|
||||
{
|
||||
nsresult rv;
|
||||
PRInt32 capacity = DEFAULT_MEMORY_CACHE_CAPACITY ;
|
||||
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_PROGID, &rv);
|
||||
if ( NS_SUCCEEDED (rv ) )
|
||||
{
|
||||
rv = prefs->GetIntPref(CACHE_MEM_CAPACITY, &capacity );
|
||||
}
|
||||
return ( (nsCacheManager*)closure )->SetMemCacheCapacity( capacity );
|
||||
}
|
||||
|
||||
#define CACHE_HIGH_WATER_MARK(capacity) ((PRUint32)(0.98 * (capacity)))
|
||||
#define CACHE_LOW_WATER_MARK(capacity) ((PRUint32)(0.97 * (capacity)))
|
||||
@@ -92,16 +69,33 @@ nsCacheManager::~nsCacheManager()
|
||||
delete mActiveCacheRecords;
|
||||
delete mMemSpaceManager;
|
||||
delete mDiskSpaceManager;
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_PROGID, &rv);
|
||||
if ( NS_SUCCEEDED (rv ) )
|
||||
{
|
||||
prefs->UnregisterCallback( CACHE_DISK_CAPACITY, diskCacheSizeChanged, this);
|
||||
prefs->UnregisterCallback( CACHE_MEM_CAPACITY, memCacheSizeChanged, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int diskCacheSizeChanged(const char *pref, void *closure)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_PROGID, &rv);
|
||||
PRInt32 capacity = DEFAULT_DISK_CACHE_CAPACITY;
|
||||
if ( NS_SUCCEEDED (rv ) )
|
||||
{
|
||||
rv = prefs->GetIntPref(CACHE_DISK_CAPACITY, &capacity );
|
||||
}
|
||||
return ( (nsCacheManager*)closure )->SetDiskCacheCapacity( capacity );
|
||||
}
|
||||
|
||||
static int memCacheSizeChanged(const char *pref, void *closure)
|
||||
{
|
||||
nsresult rv;
|
||||
PRInt32 capacity = DEFAULT_MEMORY_CACHE_CAPACITY ;
|
||||
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_PROGID, &rv);
|
||||
if ( NS_SUCCEEDED (rv ) )
|
||||
{
|
||||
rv = prefs->GetIntPref(CACHE_MEM_CAPACITY, &capacity );
|
||||
}
|
||||
return ( (nsCacheManager*)closure )->SetMemCacheCapacity( capacity );
|
||||
}
|
||||
|
||||
nsresult nsCacheManager::InitPrefs()
|
||||
{
|
||||
nsresult rv;
|
||||
@@ -204,7 +198,7 @@ nsresult nsCacheManager::GetCacheAndReplacementPolicy( PRUint32 aFlags, nsINetDa
|
||||
PRBool diskCacheEnabled = PR_FALSE;
|
||||
if ( mDiskCache.get() )
|
||||
mDiskCache->GetEnabled( &diskCacheEnabled );
|
||||
|
||||
|
||||
if (aFlags & CACHE_AS_FILE) {
|
||||
if ( diskCacheEnabled )
|
||||
cache = mDiskCache;
|
||||
|
||||
16
mozilla/netwerk/cache/mgr/nsCachedNetData.cpp
vendored
16
mozilla/netwerk/cache/mgr/nsCachedNetData.cpp
vendored
@@ -156,7 +156,8 @@ class CacheMetaData {
|
||||
|
||||
if (mOpaqueBytes)
|
||||
nsAllocator::Free(mOpaqueBytes);
|
||||
delete mNext;
|
||||
if (mNext)
|
||||
delete mNext;
|
||||
}
|
||||
|
||||
protected:
|
||||
@@ -450,7 +451,7 @@ nsCachedNetData::Deserialize(PRBool aDeserializeFlags)
|
||||
nsAllocator::Free(metaData);
|
||||
|
||||
nsCOMPtr<nsISupports> stringStreamSupports;
|
||||
rv = NS_NewCStringInputStream(getter_AddRefs(stringStreamSupports), metaDataCStr);
|
||||
rv = NS_NewStringInputStream(getter_AddRefs(stringStreamSupports), metaDataCStr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIInputStream> inputStream = do_QueryInterface(stringStreamSupports);
|
||||
@@ -478,7 +479,6 @@ nsCachedNetData::Deserialize(PRBool aDeserializeFlags)
|
||||
|
||||
CacheMetaData *annotation;
|
||||
annotation = new CacheMetaData(tag);
|
||||
nsAllocator::Free(tag);
|
||||
if (!annotation)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
@@ -1035,7 +1035,7 @@ nsCachedNetData::GetCache(nsINetDataCache* *aCache)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCachedNetData::NewChannel(nsILoadGroup* aLoadGroup, nsIChannel* *aChannel)
|
||||
nsCachedNetData::NewChannel(nsILoadGroup* aLoadGroup, nsIChannel* aProxyChannel, nsIChannel* *aChannel)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
@@ -1049,6 +1049,7 @@ nsCachedNetData::NewChannel(nsILoadGroup* aLoadGroup, nsIChannel* *aChannel)
|
||||
cacheEntryChannel = new nsCacheEntryChannel(this, channel, aLoadGroup);
|
||||
if (!cacheEntryChannel)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
cacheEntryChannel->mProxyChannel = aProxyChannel;
|
||||
|
||||
*aChannel = cacheEntryChannel;
|
||||
NS_ADDREF(*aChannel);
|
||||
@@ -1088,13 +1089,10 @@ public:
|
||||
// Just in case the protocol handler forgot to set this flag...
|
||||
mCacheEntry->SetFlag(nsCachedNetData::UPDATE_IN_PROGRESS);
|
||||
|
||||
rv = mCacheEntry->NewChannel(0, getter_AddRefs(mChannel));
|
||||
rv = mCacheEntry->NewChannel(0, 0, getter_AddRefs(mChannel));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = mChannel->SetTransferOffset(aStartingOffset);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return mChannel->OpenOutputStream(getter_AddRefs(mCacheStream));
|
||||
return mChannel->OpenOutputStream(aStartingOffset, getter_AddRefs(mCacheStream));
|
||||
}
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
15
mozilla/netwerk/cache/mgr/nsCachedNetData.h
vendored
15
mozilla/netwerk/cache/mgr/nsCachedNetData.h
vendored
@@ -20,19 +20,6 @@
|
||||
*
|
||||
* Contributor(s):
|
||||
* Scott Furman, fur@netscape.com
|
||||
*
|
||||
*
|
||||
* This Original Code has been modified by IBM Corporation.
|
||||
* Modifications made by IBM described herein are
|
||||
* Copyright (c) International Business Machines
|
||||
* Corporation, 2000
|
||||
*
|
||||
* Modifications to Mozilla code or documentation
|
||||
* identified per MPL Section 3.3
|
||||
*
|
||||
* Date Modified by Description of modification
|
||||
* 03/27/2000 IBM Corp. Added PR_CALLBACK for Optlink
|
||||
* use in OS2
|
||||
*/
|
||||
|
||||
#ifndef _nsCachedNetData_h_
|
||||
@@ -118,7 +105,7 @@ protected:
|
||||
nsresult ClearFlag(Flag aFlag) { return SetFlag(PR_FALSE, aFlag); }
|
||||
|
||||
void ComputeProfit(PRUint32 aCurrentTime);
|
||||
static int PR_CALLBACK Compare(const void *a, const void *b, void *unused);
|
||||
static int Compare(const void *a, const void *b, void *unused);
|
||||
|
||||
void NoteAccess();
|
||||
void NoteUpdate();
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
|
||||
nsReplacementPolicy::nsReplacementPolicy()
|
||||
: mRankedEntries(0), mCaches(0), mRecordsRemovedSinceLastRanking(0),
|
||||
mNumEntries(0), mCapacityRankedEntriesArray(0), mLastRankTime(0), mLoadedAllDatabaseRecords( PR_FALSE ) {}
|
||||
mNumEntries(0), mCapacityRankedEntriesArray(0), mLastRankTime(0) {}
|
||||
|
||||
nsReplacementPolicy::~nsReplacementPolicy()
|
||||
{
|
||||
@@ -46,7 +46,6 @@ nsReplacementPolicy::~nsReplacementPolicy()
|
||||
nsAllocator::Free(mRankedEntries);
|
||||
if (mMapRecordIdToEntry)
|
||||
nsAllocator::Free(mMapRecordIdToEntry);
|
||||
delete mCaches;
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
||||
@@ -210,9 +210,12 @@ interface nsICachedNetData : nsISupports
|
||||
*
|
||||
* Though nsIChannel provides for both async and synchronous I/O APIs, both
|
||||
* may not be implemented. Only AsyncRead() and OpenOutputStream() is
|
||||
* required.
|
||||
* required. The aProxyChannel argument allows another channel to be
|
||||
* specified as the proffered argument to nsIStreamListener methods rather
|
||||
* than the cache's own channel.
|
||||
*/
|
||||
nsIChannel newChannel(in nsILoadGroup aLoadGroup);
|
||||
nsIChannel newChannel(in nsILoadGroup aLoadGroup,
|
||||
in nsIChannel aProxyChannel);
|
||||
|
||||
/**
|
||||
* This method can be used by a caching protocol handler to store data in
|
||||
|
||||
@@ -40,11 +40,9 @@ interface nsIDNSListener;
|
||||
[scriptable, uuid(598f2f80-206f-11d3-9348-00104ba0fd40)]
|
||||
interface nsIDNSService : nsISupports
|
||||
{
|
||||
nsIRequest lookup(in string hostname,
|
||||
in nsIDNSListener listener,
|
||||
in nsISupports ctxt);
|
||||
nsIRequest lookup(in nsISupports ctxt, in string hostname,
|
||||
in nsIDNSListener listener);
|
||||
|
||||
void init();
|
||||
void shutdown();
|
||||
};
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -26,7 +26,7 @@
|
||||
#include "nsIDNSService.h"
|
||||
#include "nsIRunnable.h"
|
||||
#include "nsIThread.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsVoidArray.h"
|
||||
#if defined(XP_MAC)
|
||||
#include <OSUtils.h>
|
||||
#include <OpenTransport.h>
|
||||
@@ -36,8 +36,6 @@
|
||||
#include <Winsock2.h>
|
||||
#endif
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsHashtable.h"
|
||||
#include "prmon.h"
|
||||
|
||||
//#ifdef DEBUG
|
||||
#define DNS_TIMING 1 // XXX remove later
|
||||
@@ -52,30 +50,33 @@ class nsDNSService : public nsIDNSService,
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIRUNNABLE
|
||||
NS_DECL_NSIDNSSERVICE
|
||||
|
||||
// nsDNSService methods:
|
||||
nsDNSService();
|
||||
virtual ~nsDNSService();
|
||||
nsresult Init();
|
||||
nsresult LateInit();
|
||||
nsresult InitDNSThread();
|
||||
|
||||
// Define a Create method to be used with a factory:
|
||||
static NS_METHOD
|
||||
Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult);
|
||||
|
||||
// nsIDNSService methods:
|
||||
NS_DECL_NSIDNSSERVICE
|
||||
|
||||
protected:
|
||||
friend class nsDNSLookup;
|
||||
|
||||
protected:
|
||||
nsresult LateInit();
|
||||
nsresult InitDNSThread();
|
||||
nsresult GetLookupEntry(const char* hostName, nsDNSLookup* *result);
|
||||
|
||||
static nsDNSService * gService;
|
||||
static PRBool gNeedLateInitialization;
|
||||
|
||||
nsCOMPtr<nsIThread> mThread;
|
||||
PRLock * mThreadLock;
|
||||
nsresult mState;
|
||||
PRMonitor* mMonitor;
|
||||
nsSupportsHashtable mLookups; // of nsDNSLookups
|
||||
|
||||
// nsDNSLookup cache? - list of nsDNSLookups, hash table (nsHashTable, nsStringKey)
|
||||
// list of nsDNSLookups in order of expiration (PRCList?)
|
||||
|
||||
#if defined(XP_MAC)
|
||||
friend pascal void nsDnsServiceNotifierRoutine(void * contextPtr, OTEventCode code, OTResult result, void * cookie);
|
||||
@@ -93,8 +94,8 @@ protected:
|
||||
void FreeMsgID(PRUint32 msgID);
|
||||
|
||||
friend static LRESULT CALLBACK nsDNSEventProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||
LRESULT LookupComplete(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||
HWND mDNSWindow;
|
||||
nsVoidArray mCompletionQueue;
|
||||
PRUint32 mMsgIDBitVector[4];
|
||||
#endif /* XP_PC */
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -32,7 +32,6 @@ XPIDL_MODULE = mimetype
|
||||
XPIDLSRCS = \
|
||||
nsIMIMEService.idl \
|
||||
nsIMIMEInfo.idl \
|
||||
nsIMIMEDataSource.idl \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
|
||||
@@ -29,7 +29,6 @@ XPIDL_MODULE = mimetype
|
||||
XPIDLSRCS = \
|
||||
.\nsIMIMEInfo.idl \
|
||||
.\nsIMIMEService.idl \
|
||||
.\nsIMIMEDataSource.idl \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
/* -*- Mode: IDL; 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.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Judson Valeski
|
||||
* : David Matiskella
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIMIMEInfo.idl"
|
||||
#include "nsIEnumerator.idl"
|
||||
#include "nsIFile.idl"
|
||||
%{C++
|
||||
#define NS_XMLMIMEDATASOURCE_CID \
|
||||
{ /* {41654483-fa5b-11d3-a12b-a7aef7a2f2fc} */ \
|
||||
0x41654483, \
|
||||
0xfa5b, \
|
||||
0x11d3, \
|
||||
{ 0xa1, 0x2b, 0xa7, 0xae, 0xf7, 0xa2, 0xf2, 0xfc } \
|
||||
}
|
||||
#define NS_XMLMIMEDATASOURCE_PROGID \
|
||||
"component:||netscape|mimexmldatasource"
|
||||
|
||||
|
||||
#define NS_NATIVEMIMEDATASOURCE_PROGID \
|
||||
"component:||netscape|mimenativedatasource"
|
||||
%}
|
||||
|
||||
|
||||
[scriptable, uuid(41654481-fa5b-11d3-a12b-a7aef7a2f2fc)]
|
||||
interface nsIMIMEDataSource : nsISupports {
|
||||
/*
|
||||
Routines for retriving nsIMIMEInfo data given either
|
||||
a mimetype, file extension, or a mac codes;
|
||||
*/
|
||||
nsIMIMEInfo GetFromMIMEType( in string aType );
|
||||
nsIMIMEInfo GetFromExtension( in string aFileExt );
|
||||
nsIMIMEInfo GetFromTypeCreator( in PRUint32 aType, in PRUint32 aCreator, in string aFileExt );
|
||||
|
||||
/*
|
||||
Routines to Add and Remove elements and to get an enumerator on the data source
|
||||
*/
|
||||
void Add( in nsIMIMEInfo aInfo );
|
||||
void Remove( in string aType );
|
||||
nsISimpleEnumerator GetEnumerator();
|
||||
void Serialize();
|
||||
};
|
||||
@@ -31,18 +31,6 @@
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIURI.idl"
|
||||
|
||||
%{C++
|
||||
#define NS_MIMEINFO_CID \
|
||||
{ /* {95df6583-0001-11d4-a12b-a66ef662f0bc} */ \
|
||||
0x95df6583, \
|
||||
0x0001, \
|
||||
0x11d4, \
|
||||
{ 0xa1, 0x2b, 0xa6, 0x6e, 0xf6, 0x62, 0xf0, 0xbc } \
|
||||
}
|
||||
#define NS_MIMEINFO_PROGID \
|
||||
"component:||netscape|mimeinfo"
|
||||
%}
|
||||
|
||||
[scriptable, uuid(6A57EAE0-2FE8-11d3-A164-0050041CAF44)]
|
||||
interface nsIMIMEInfo : nsISupports {
|
||||
/* Gives you an array of file types associated with this type.
|
||||
@@ -67,23 +55,18 @@ interface nsIMIMEInfo : nsISupports {
|
||||
* @return The first extension.
|
||||
*/
|
||||
string FirstExtension();
|
||||
|
||||
/*
|
||||
* Append a given extension to the set of extensions
|
||||
*/
|
||||
void AppendExtension(in string aExtension);
|
||||
|
||||
/* The MIME type of this MIMEInfo.
|
||||
*
|
||||
* @return String representing the MIME type.
|
||||
*/
|
||||
attribute string MIMEType;
|
||||
readonly attribute string MIMEType;
|
||||
|
||||
/* A human readable description of the MIME info
|
||||
*
|
||||
* @return The description
|
||||
*/
|
||||
attribute wstring Description;
|
||||
readonly attribute wstring Description;
|
||||
|
||||
/* Gives you arbitrary data about the MIMEInfo. An example
|
||||
* of this is a generic image graphically representing
|
||||
@@ -93,13 +76,7 @@ interface nsIMIMEInfo : nsISupports {
|
||||
* @return A URI representing the data location.
|
||||
*/
|
||||
readonly attribute nsIURI DataURI;
|
||||
|
||||
/*
|
||||
* Mac Type and creator types
|
||||
*/
|
||||
attribute PRUint32 MacType;
|
||||
attribute PRUint32 MacCreator;
|
||||
|
||||
|
||||
/* Returns whether or not these two MIME infos are logically
|
||||
* equivelent maintaining the one-to-many relationship between
|
||||
* MIME types and file extensions.
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Judson Valeski
|
||||
* : David Matiskella
|
||||
*/
|
||||
|
||||
/* The MIME service is responsible for mapping file extensions to MIME-types
|
||||
@@ -35,8 +34,7 @@
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIMIMEInfo.idl"
|
||||
#include "nsIURI.idl"
|
||||
#include "nsIMIMEDataSource.idl"
|
||||
#include "nsIFile.idl"
|
||||
#include "nsISupportsArray.idl"
|
||||
|
||||
%{C++
|
||||
#define NS_MIMESERVICE_CID \
|
||||
@@ -83,15 +81,51 @@ interface nsIMIMEService : nsISupports {
|
||||
* @return The MIME type, if any.
|
||||
*/
|
||||
string GetTypeFromURI(in nsIURI aURI);
|
||||
|
||||
//
|
||||
string GetTypeFromFile ( in nsIFile aFile );
|
||||
|
||||
|
||||
/*
|
||||
* The data sources
|
||||
*/
|
||||
readonly attribute nsIMIMEDataSource XMLDataSource;
|
||||
readonly attribute nsIMIMEDataSource NativeDataSource;
|
||||
|
||||
|
||||
/* Adds a MIME mapping to the database.
|
||||
*
|
||||
* @param MIME type to be registered.
|
||||
* @param File extension to be associated.
|
||||
* @param Description of this MIME type.
|
||||
* @param Data URI typically used to retrieve an image
|
||||
* graphically representing the MIME type.
|
||||
*
|
||||
*/
|
||||
void AddMapping(in string aMIMEType, in string aExtension, in string aDesc, in nsIURI aURI);
|
||||
|
||||
/* Removes a MIME mapping from the database. All file extensions
|
||||
* associated with this mapping are removed as well.
|
||||
*
|
||||
* @param MIME type to be removed.
|
||||
* @return NS_OK
|
||||
*/
|
||||
void RemoveMapping(in string aMIMEType);
|
||||
|
||||
/* Maps a file extension (don't include leading dot) to a MIME entry.
|
||||
*
|
||||
* @param MIME type to associate this extension with.
|
||||
* @param File extension to associate with MIME type.
|
||||
* @return NS_ERROR_FAILURE if the MIME entry doesn't exist, or for
|
||||
* general fialure. NS_OK otherwise.
|
||||
*/
|
||||
void AppendExtension(in string aMIMEType, in string aExtension);
|
||||
|
||||
/* Removes a file extension association with a MIME entry.
|
||||
*
|
||||
* @param The file extension to be removed.
|
||||
* @return NS_ERROR_FAILURE if the MIME entry doesn't exist, or for
|
||||
* general failure. NS_OK otherwise.
|
||||
*/
|
||||
void RemoveExtension(in string aExtension);
|
||||
|
||||
/* Enumerates all the MIME types in the database. Each entry
|
||||
* is represented as an nsIMIMEInfo interface.
|
||||
*
|
||||
* @return All the registered MIME types.
|
||||
*/
|
||||
nsIBidirectionalEnumerator EnumerateEntries();
|
||||
|
||||
/* Makes the current mappings persistent.
|
||||
*/
|
||||
void Serialize();
|
||||
};
|
||||
|
||||
@@ -36,7 +36,6 @@ CPPSRCS = \
|
||||
nsMIMEInfoImpl.cpp \
|
||||
nsMIMEService.cpp \
|
||||
nsMIMEServiceModule.cpp \
|
||||
nsXMLMIMEDataSource.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_LIBS)
|
||||
|
||||
@@ -38,7 +38,6 @@ CPP_OBJS = \
|
||||
.\$(OBJDIR)\nsMIMEInfoImpl.obj \
|
||||
.\$(OBJDIR)\nsMIMEService.obj \
|
||||
.\$(OBJDIR)\nsMIMEServiceModule.obj \
|
||||
.\$(OBJDIR)\nsXMLMIMEDataSource.obj \
|
||||
$(NULL)
|
||||
|
||||
LOCAL_INCLUDES=-I.
|
||||
|
||||
@@ -27,12 +27,9 @@
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsMIMEInfoImpl, nsIMIMEInfo);
|
||||
|
||||
// nsMIMEInfoImpl methods
|
||||
nsMIMEInfoImpl::nsMIMEInfoImpl() {
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsMIMEInfoImpl::nsMIMEInfoImpl(const char *aMIMEType): mMIMEType( aMIMEType ) {
|
||||
nsMIMEInfoImpl::nsMIMEInfoImpl(const char *aMIMEType) {
|
||||
NS_INIT_REFCNT();
|
||||
mMIMEType = getter_AddRefs(NS_NewAtom(aMIMEType));
|
||||
}
|
||||
|
||||
PRUint32
|
||||
@@ -69,7 +66,7 @@ nsMIMEInfoImpl::ExtensionExists(const char *aExtension, PRBool *_retval) {
|
||||
if (!aExtension) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
for (PRUint8 i=0; i < extCount; i++) {
|
||||
nsCString* ext = (nsCString*)mExtensions.CStringAt(i);
|
||||
nsString* ext = (nsString*)mExtensions.CStringAt(i);
|
||||
if (ext->Equals(aExtension)) {
|
||||
found = PR_TRUE;
|
||||
break;
|
||||
@@ -90,29 +87,17 @@ nsMIMEInfoImpl::FirstExtension(char **_retval) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::AppendExtension(const char *aExtension)
|
||||
{
|
||||
mExtensions.AppendCString( aExtension );
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoImpl::GetMIMEType(char * *aMIMEType) {
|
||||
if (!aMIMEType) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aMIMEType = mMIMEType.ToNewCString();
|
||||
nsAutoString strMIMEType;
|
||||
mMIMEType->ToString(strMIMEType);
|
||||
*aMIMEType = strMIMEType.ToNewCString();
|
||||
if (!*aMIMEType) return NS_ERROR_OUT_OF_MEMORY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoImpl::SetMIMEType(const char* aMIMEType) {
|
||||
if (!aMIMEType) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
mMIMEType = aMIMEType;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoImpl::GetDescription(PRUnichar * *aDescription) {
|
||||
if (!aDescription) return NS_ERROR_NULL_POINTER;
|
||||
@@ -122,12 +107,6 @@ nsMIMEInfoImpl::GetDescription(PRUnichar * *aDescription) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::SetDescription(const PRUnichar * aDescription)
|
||||
{
|
||||
mDescription = aDescription;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoImpl::GetDataURI(nsIURI * *aDataURI) {
|
||||
return mURI->Clone(aDataURI);
|
||||
@@ -141,31 +120,8 @@ nsMIMEInfoImpl::Equals(nsIMIMEInfo *aMIMEInfo, PRBool *_retval) {
|
||||
nsresult rv = aMIMEInfo->GetMIMEType(getter_Copies(type));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*_retval = mMIMEType.EqualsWithConversion(type);
|
||||
|
||||
nsAutoString type1;
|
||||
mMIMEType->ToString(type1);
|
||||
*_retval = type1.Equals(type);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::GetMacType(PRUint32 *aMacType)
|
||||
{
|
||||
*aMacType = mMacType;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::SetMacType(PRUint32 aMacType)
|
||||
{
|
||||
mMacType = aMacType;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::GetMacCreator(PRUint32 *aMacCreator)
|
||||
{
|
||||
*aMacCreator = mMacCreator;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::SetMacCreator(PRUint32 aMacCreator)
|
||||
{
|
||||
mMacCreator = aMacCreator;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#include "nsIMIMEInfo.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsString.h"
|
||||
#include "nsString2.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
@@ -34,7 +34,6 @@ class nsMIMEInfoImpl : public nsIMIMEInfo {
|
||||
NS_DECL_NSIMIMEINFO
|
||||
|
||||
// nsMIMEInfoImpl methods
|
||||
nsMIMEInfoImpl();
|
||||
nsMIMEInfoImpl(const char *aMIMEType);
|
||||
virtual ~nsMIMEInfoImpl() {};
|
||||
PRUint32 GetExtCount(); // returns the number of extensions associated.
|
||||
@@ -43,9 +42,9 @@ class nsMIMEInfoImpl : public nsIMIMEInfo {
|
||||
nsCStringArray mExtensions; // array of file extensions associated w/ this MIME obj
|
||||
nsAutoString mDescription; // human readable description
|
||||
nsCOMPtr<nsIURI> mURI; // URI pointing to data associated w/ this obj
|
||||
PRUint32 mMacType, mMacCreator; // Mac file type and creator
|
||||
|
||||
protected:
|
||||
nsString mMIMEType;
|
||||
nsCOMPtr<nsIAtom> mMIMEType;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -17,36 +17,25 @@
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Judson Valeski
|
||||
*
|
||||
* This Original Code has been modified by IBM Corporation.
|
||||
* Modifications made by IBM described herein are
|
||||
* Copyright (c) International Business Machines
|
||||
* Corporation, 2000
|
||||
*
|
||||
* Modifications to Mozilla code or documentation
|
||||
* identified per MPL Section 3.3
|
||||
*
|
||||
* Date Modified by Description of modification
|
||||
* 03/27/2000 IBM Corp. Added PR_CALLBACK for Optlink
|
||||
* use in OS2
|
||||
* Contributor(s): Judson Valeski
|
||||
*/
|
||||
|
||||
#include "nsMIMEService.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsString.h"
|
||||
#include "nsString2.h"
|
||||
#include "nsMIMEInfoImpl.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsMimeTypes.h"
|
||||
|
||||
|
||||
#ifdef XP_MAC
|
||||
#include "nsILocalFileMac.h"
|
||||
#endif
|
||||
|
||||
|
||||
// Hash table helper functions
|
||||
PRBool DeleteEntry(nsHashKey *aKey, void *aData, void* closure) {
|
||||
nsMIMEInfoImpl *entry = (nsMIMEInfoImpl*)aData;
|
||||
NS_ASSERTION(entry, "mapping problem");
|
||||
NS_RELEASE(entry);
|
||||
return PR_TRUE;
|
||||
};
|
||||
|
||||
// nsISupports methods
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsMIMEService, nsIMIMEService);
|
||||
@@ -69,56 +58,299 @@ nsMIMEService::nsMIMEService() {
|
||||
}
|
||||
|
||||
nsMIMEService::~nsMIMEService() {
|
||||
mInfoObjects->Reset(DeleteEntry, nsnull);
|
||||
delete mInfoObjects;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMIMEService::Init() {
|
||||
nsresult rv = NS_OK;
|
||||
rv = nsComponentManager::CreateInstance(NS_XMLMIMEDATASOURCE_PROGID, nsnull, nsIMIMEDataSource::GetIID(), getter_AddRefs(mXML) );
|
||||
|
||||
// Create native
|
||||
nsComponentManager::CreateInstance(NS_NATIVEMIMEDATASOURCE_PROGID, nsnull, nsIMIMEDataSource::GetIID(), getter_AddRefs(mNative) );
|
||||
return rv;
|
||||
mInfoObjects = new nsHashtable();
|
||||
if (!mInfoObjects) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
rv = NS_NewISupportsArray(getter_AddRefs(mInfoArray));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return InitFromHack();
|
||||
}
|
||||
|
||||
/* This bad boy needs to retrieve a url, and parse the data coming back, and
|
||||
* add entries into the mInfoArray.
|
||||
*/
|
||||
nsresult
|
||||
nsMIMEService::InitFromURI(nsIURI *aUri) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMIMEService::InitFromFile(const char *aFileName) {
|
||||
#if 0
|
||||
nsFileSpec dirSpec;
|
||||
nsIFileSpec* spec = NS_LocateFileOrDirectory(nsSpecialFileSpec::App_UserProfileDirectory50);
|
||||
if (!spec) return NS_ERROR_FAILURE;
|
||||
spec->GetFileSpec(&dirSpec);
|
||||
|
||||
nsInputFileStream inStream(dirSpec + aFileName);
|
||||
if (!inStream.is_open()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// digest the file.
|
||||
#endif
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEService::AddMapping(const char* mimeType,
|
||||
const char* extension,
|
||||
const char* description,
|
||||
nsIURI* dataURI)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
// setup the new MIMEInfo object.
|
||||
nsMIMEInfoImpl* anInfo = new nsMIMEInfoImpl(mimeType);
|
||||
if (!anInfo) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
anInfo->mExtensions.AppendCString(extension);
|
||||
anInfo->mDescription = description;
|
||||
anInfo->mURI = dataURI;
|
||||
|
||||
// The entry is mapped many-to-one and the MIME type is the root mapping.
|
||||
|
||||
// First remove any existing mapping.
|
||||
rv = RemoveMapping(mimeType);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Next add the new root MIME mapping.
|
||||
nsStringKey key(mimeType);
|
||||
nsMIMEInfoImpl* oldInfo = (nsMIMEInfoImpl*)mInfoObjects->Put(&key, anInfo);
|
||||
NS_ASSERTION(!oldInfo, "we just removed the entry, we shouldn't have one");
|
||||
NS_ADDREF(anInfo);
|
||||
|
||||
rv = mInfoArray->AppendElement(anInfo); // update the root array.
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Finally add an extension mapping.
|
||||
key = extension;
|
||||
oldInfo = (nsMIMEInfoImpl*)mInfoObjects->Put(&key, anInfo);
|
||||
NS_ASSERTION(!oldInfo, "file extension mappings should have been cleaned up in the RemoveMapping call");
|
||||
NS_ADDREF(anInfo);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// used to cleanup any file extension mappings when
|
||||
// a root MIME entry is removed.
|
||||
PRBool removeExts(nsCString& aElement, void *aData) {
|
||||
nsHashtable* infoObjects = (nsHashtable*)aData;
|
||||
NS_ASSERTION(infoObjects, "hash table botched up");
|
||||
|
||||
nsStringKey key(aElement);
|
||||
nsMIMEInfoImpl* info = (nsMIMEInfoImpl*)infoObjects->Remove(&key);
|
||||
NS_RELEASE(info);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEService::RemoveMapping(const char* aMIMEType) {
|
||||
nsresult rv = NS_OK;
|
||||
nsStringKey key(aMIMEType);
|
||||
|
||||
// First remove the root MIME mapping.
|
||||
nsMIMEInfoImpl* info = (nsMIMEInfoImpl*)mInfoObjects->Remove(&key);
|
||||
if (!info) return NS_OK;
|
||||
|
||||
rv = mInfoArray->RemoveElement(info); // update the root array.
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Next remove any file association mappings.
|
||||
rv = info->mExtensions.EnumerateForwards(removeExts, mInfoObjects);
|
||||
NS_RELEASE(info);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEService::AppendExtension(const char* mimeType, const char* extension) {
|
||||
nsStringKey key(mimeType);
|
||||
|
||||
nsMIMEInfoImpl* info = (nsMIMEInfoImpl*)mInfoObjects->Get(&key);
|
||||
if (!info) return NS_ERROR_FAILURE;
|
||||
|
||||
info->mExtensions.AppendCString(extension);
|
||||
|
||||
// Add another file extension mapping.
|
||||
key = extension;
|
||||
nsMIMEInfoImpl* oldInfo = (nsMIMEInfoImpl*)mInfoObjects->Put(&key, info);
|
||||
NS_IF_RELEASE(oldInfo); // overwrite any existing mapping.
|
||||
NS_ADDREF(info);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEService::RemoveExtension(const char* aExtension) {
|
||||
nsresult rv = NS_OK;
|
||||
nsStringKey key(aExtension);
|
||||
|
||||
// First remove the extension mapping.
|
||||
nsMIMEInfoImpl* info = (nsMIMEInfoImpl*)mInfoObjects->Remove(&key);
|
||||
if (!info) return NS_ERROR_FAILURE;
|
||||
|
||||
// Next remove the root MIME mapping from the array and hash
|
||||
// IFF this was the only file extension mapping left.
|
||||
PRBool removed = info->mExtensions.RemoveCString(key.GetString());
|
||||
NS_ASSERTION(removed, "mapping problem");
|
||||
|
||||
if (info->GetExtCount() == 0) {
|
||||
// it's empty, remove the root mapping from hash and array.
|
||||
nsXPIDLCString mimeType;
|
||||
rv = info->GetMIMEType(getter_Copies(mimeType));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
key = (const char*)mimeType;
|
||||
nsMIMEInfoImpl* rootEntry = (nsMIMEInfoImpl*)mInfoObjects->Remove(&key);
|
||||
NS_ASSERTION(rootEntry, "mapping miss-hap");
|
||||
|
||||
rv = mInfoArray->RemoveElement(rootEntry); // update the root array
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_RELEASE(rootEntry);
|
||||
}
|
||||
|
||||
NS_RELEASE(info);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEService::EnumerateEntries(nsIBidirectionalEnumerator* *aEnumerator) {
|
||||
return NS_NewISupportsArrayEnumerator(mInfoArray, aEnumerator);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEService::Serialize() {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMIMEService::InitFromHack() {
|
||||
nsresult rv;
|
||||
|
||||
rv = AddMapping(TEXT_PLAIN, "txt", "Text File", nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = AppendExtension(TEXT_PLAIN, "text");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AddMapping(APPLICATION_OCTET_STREAM, "exe", "Binary Executable", nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = AppendExtension(APPLICATION_OCTET_STREAM, "bin");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
#if defined(VMS)
|
||||
rv = AppendExtension(APPLICATION_OCTET_STREAM, "sav");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = AppendExtension(APPLICATION_OCTET_STREAM, "bck");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = AppendExtension(APPLICATION_OCTET_STREAM, "pcsi");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = AppendExtension(APPLICATION_OCTET_STREAM, "pcsi-dcx_axpexe");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = AppendExtension(APPLICATION_OCTET_STREAM, "pcsi-dcx_vaxexe");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
#endif
|
||||
|
||||
rv = AddMapping(TEXT_HTML, "htm", "Hyper Text Markup Language", nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = AppendExtension(TEXT_HTML, "html");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = AppendExtension(TEXT_HTML, "shtml");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AddMapping(TEXT_RDF, "rdf", "Resource Description Framework", nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AddMapping(TEXT_XUL, "xul", "XML-Based User Interface Language", nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AddMapping(TEXT_XML, "xml", "Extensible Markup Language", nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AddMapping(TEXT_CSS, "css", "Style Sheet", nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AddMapping(APPLICATION_JAVASCRIPT, "js", "Javascript Source File", nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AddMapping(MESSAGE_RFC822, "eml", "RFC-822 data", nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AddMapping(IMAGE_GIF, "gif", "GIF Image", nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AddMapping(IMAGE_JPG, "jpeg", "JPEG Image", nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = AppendExtension(IMAGE_JPG, "jpg");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AddMapping(IMAGE_PNG, "png", "PNG Image", nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AddMapping(IMAGE_ART, "art", "ART Image", nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AddMapping(IMAGE_TIFF, "tiff", "TIFF Image", nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = AppendExtension(IMAGE_TIFF, "tif");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AddMapping(APPLICATION_POSTSCRIPT, "ps", "Postscript File", nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = AppendExtension(APPLICATION_POSTSCRIPT, "eps");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = AppendExtension(APPLICATION_POSTSCRIPT, "ai");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AddMapping(TEXT_RTF, "rtf", "Rich Text Format", nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = AppendExtension(TEXT_RTF, "rtf");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AddMapping(TEXT_CPP, "cpp", "CPP file", nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = AppendExtension(TEXT_CPP, "cpp");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
// nsIMIMEService methods
|
||||
NS_IMETHODIMP
|
||||
nsMIMEService::GetFromExtension(const char *aFileExt, nsIMIMEInfo **_retval) {
|
||||
nsresult rv;
|
||||
if( !mXML || NS_FAILED (rv = mXML->GetFromExtension( aFileExt, _retval ) ) )
|
||||
{
|
||||
if ( mNative )
|
||||
rv = mNative->GetFromExtension( aFileExt, _retval );
|
||||
}
|
||||
return rv;
|
||||
// for now we're assuming file extensions are case insensitive.
|
||||
nsCAutoString fileExt(aFileExt);
|
||||
fileExt.ToLowerCase();
|
||||
|
||||
nsStringKey key(fileExt.GetBuffer());
|
||||
|
||||
nsMIMEInfoImpl *entry = (nsMIMEInfoImpl*)mInfoObjects->Get(&key);
|
||||
if (!entry) return NS_ERROR_FAILURE;
|
||||
NS_ADDREF(entry);
|
||||
*_retval = NS_STATIC_CAST(nsIMIMEInfo*, entry);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEService::GetFromMIMEType(const char *aMIMEType, nsIMIMEInfo **_retval) {
|
||||
nsresult rv =NS_ERROR_FAILURE;
|
||||
if( !mXML || NS_FAILED (rv = mXML->GetFromMIMEType( aMIMEType, _retval ) ) )
|
||||
{
|
||||
if ( mNative )
|
||||
rv = mNative->GetFromMIMEType( aMIMEType, _retval );
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Helper routines implemented in terms of the above
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEService::GetTypeFromExtension(const char *aFileExt, char **aContentType) {
|
||||
nsresult rv = NS_OK;;
|
||||
nsCOMPtr<nsIMIMEInfo> info;
|
||||
rv = GetFromExtension(aFileExt, getter_AddRefs(info));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return info->GetMIMEType(aContentType);
|
||||
|
||||
rv = info->GetMIMEType(aContentType);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@@ -127,29 +359,6 @@ nsMIMEService::GetTypeFromURI(nsIURI *aURI, char **aContentType) {
|
||||
// first try to get a url out of the uri so we can skip post
|
||||
// filename stuff (i.e. query string)
|
||||
nsCOMPtr<nsIURL> url = do_QueryInterface(aURI, &rv);
|
||||
|
||||
#ifdef XP_MAC
|
||||
if ( NS_SUCCEEDED( rv ) )
|
||||
{
|
||||
nsXPIDLCString fileExt;
|
||||
url->GetFileExtension(getter_Copies(fileExt));
|
||||
|
||||
nsresult rv2;
|
||||
nsCOMPtr<nsIFileURL> fileurl = do_QueryInterface( url, &rv2 );
|
||||
if ( NS_SUCCEEDED ( rv2 ) )
|
||||
{
|
||||
nsCOMPtr <nsIFile> file;
|
||||
rv2 = fileurl->GetFile( getter_AddRefs( file ) );
|
||||
if ( NS_SUCCEEDED( rv2 ) )
|
||||
{
|
||||
rv2 = GetTypeFromFile( file, aContentType );
|
||||
if( NS_SUCCEEDED ( rv2 ) )
|
||||
return rv2;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsXPIDLCString ext;
|
||||
rv = url->GetFileExtension(getter_Copies(ext));
|
||||
@@ -163,7 +372,7 @@ nsMIMEService::GetTypeFromURI(nsIURI *aURI, char **aContentType) {
|
||||
rv = aURI->GetSpec(getter_Copies(cStrSpec));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsAutoString specStr; specStr.AssignWithConversion(cStrSpec);
|
||||
nsAutoString specStr(cStrSpec);
|
||||
|
||||
// find the file extension (if any)
|
||||
nsAutoString extStr;
|
||||
@@ -180,67 +389,16 @@ nsMIMEService::GetTypeFromURI(nsIURI *aURI, char **aContentType) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEService::GetTypeFromFile( nsIFile* aFile, char **aContentType )
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIMIMEInfo> info;
|
||||
|
||||
// Get the Extension
|
||||
char* fileName;
|
||||
const char* ext = nsnull;
|
||||
rv = aFile->GetLeafName(&fileName);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (fileName != nsnull) {
|
||||
PRInt32 len = nsCRT::strlen(fileName);
|
||||
for (PRInt32 i = len; i >= 0; i--) {
|
||||
if (fileName[i] == '.') {
|
||||
ext = &fileName[i + 1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
nsCString fileExt( ext );
|
||||
nsCRT::free(fileName);
|
||||
// Handle the mac case
|
||||
#ifdef XP_MAC
|
||||
nsCOMPtr<nsILocalFileMac> macFile;
|
||||
|
||||
macFile = do_QueryInterface( aFile, &rv );
|
||||
if ( NS_SUCCEEDED( rv ) )
|
||||
{
|
||||
PRUint32 type, creator;
|
||||
macFile->GetFileTypeAndCreator( (OSType*)&type,(OSType*) &creator );
|
||||
if( !mXML || NS_FAILED (rv = mXML->GetFromTypeCreator( type, creator, fileExt, getter_AddRefs(info) ) ) )
|
||||
{
|
||||
if ( mNative )
|
||||
rv = mNative->GetFromTypeCreator( type, creator, fileExt, getter_AddRefs(info) );
|
||||
}
|
||||
|
||||
if ( NS_SUCCEEDED( rv) )
|
||||
{
|
||||
return info->GetMIMEType(aContentType);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// Windows, unix and mac when no type match occured.
|
||||
|
||||
|
||||
return GetTypeFromExtension( fileExt, aContentType );
|
||||
}
|
||||
|
||||
// get a specific data source
|
||||
NS_IMETHODIMP
|
||||
nsMIMEService::GetXMLDataSource(nsIMIMEDataSource * *aXMLDataSource){
|
||||
*aXMLDataSource = mXML;
|
||||
NS_IF_ADDREF( *aXMLDataSource );
|
||||
return NS_OK;
|
||||
}
|
||||
nsMIMEService::GetFromMIMEType(const char *aMIMEType, nsIMIMEInfo **_retval) {
|
||||
nsCAutoString MIMEType(aMIMEType);
|
||||
MIMEType.ToLowerCase();
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEService::GetNativeDataSource(nsIMIMEDataSource * *aNativeDataSource)
|
||||
{
|
||||
*aNativeDataSource = mNative;
|
||||
NS_IF_ADDREF( *aNativeDataSource );
|
||||
return NS_OK;
|
||||
}
|
||||
nsStringKey key(MIMEType.GetBuffer());
|
||||
|
||||
nsMIMEInfoImpl *entry = (nsMIMEInfoImpl*)mInfoObjects->Get(&key);
|
||||
if (!entry) return NS_ERROR_FAILURE;
|
||||
NS_ADDREF(entry);
|
||||
*_retval = NS_STATIC_CAST(nsIMIMEInfo*, entry);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Judson Valeski
|
||||
* : David Matiskella
|
||||
*/
|
||||
|
||||
/*
|
||||
@@ -30,8 +29,11 @@
|
||||
#define ___nsIMIMEService__h___
|
||||
|
||||
#include "nsIMIMEService.h"
|
||||
#include "nsIMIMEDataSource.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsHashtable.h"
|
||||
#include "nsISupportsArray.h"
|
||||
|
||||
|
||||
class nsMIMEService : public nsIMIMEService {
|
||||
|
||||
@@ -41,12 +43,19 @@ class nsMIMEService : public nsIMIMEService {
|
||||
// nsMIMEService methods
|
||||
nsMIMEService();
|
||||
virtual ~nsMIMEService();
|
||||
nsresult Init();
|
||||
static NS_METHOD Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult);
|
||||
|
||||
private:
|
||||
nsresult Init();
|
||||
nsCOMPtr<nsIMIMEDataSource> mXML;
|
||||
nsCOMPtr<nsIMIMEDataSource> mNative;
|
||||
nsresult InitFromURI(nsIURI *aUri);
|
||||
nsresult InitFromFile(const char *aFileName);
|
||||
nsresult InitFromHack();
|
||||
|
||||
|
||||
nsHashtable *mInfoObjects; // used for fast access and
|
||||
// multi index lookups
|
||||
|
||||
nsCOMPtr<nsISupportsArray> mInfoArray; // used for enumeration
|
||||
};
|
||||
|
||||
#endif // ___nsIMIMEService__h___
|
||||
|
||||
@@ -22,26 +22,13 @@
|
||||
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsMIMEService.h"
|
||||
#include "nsXMLMIMEDataSource.h"
|
||||
#include "nsMIMEInfoImpl.h"
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMIMEInfoImpl);
|
||||
|
||||
static nsModuleComponentInfo gResComponents[] = {
|
||||
{ "The MIME mapping service",
|
||||
NS_MIMESERVICE_CID,
|
||||
"component:||netscape|mime",
|
||||
nsMIMEService::Create
|
||||
},
|
||||
{ "xml mime datasource",
|
||||
NS_XMLMIMEDATASOURCE_CID,
|
||||
NS_XMLMIMEDATASOURCE_PROGID,
|
||||
nsXMLMIMEDataSource::Create
|
||||
},
|
||||
{ "xml mime INFO",
|
||||
NS_MIMEINFO_CID,
|
||||
NS_MIMEINFO_PROGID,
|
||||
nsMIMEInfoImplConstructor
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE("nsMIMEService", gResComponents)
|
||||
|
||||
@@ -1,619 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Judson Valeski
|
||||
* : David Matiskella
|
||||
*/
|
||||
#include "nsXMLMIMEDataSource.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsString2.h"
|
||||
#include "nsMIMEInfoImpl.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsEnumeratorUtils.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsIFileTransportService.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "nsFileLocations.h"
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsMimeTypes.h"
|
||||
// Crap
|
||||
#include "nsIFileSpec.h"
|
||||
#include "nsFileSpec.h"
|
||||
|
||||
const char* kMIME="mime";
|
||||
const char* kMIMEType="mimetype";
|
||||
const char* kDescription="description";
|
||||
const char* kExtensions="extensions";
|
||||
|
||||
static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID);
|
||||
// Hash table helper functions
|
||||
PRBool DeleteEntry(nsHashKey *aKey, void *aData, void* closure) {
|
||||
nsMIMEInfoImpl *entry = (nsMIMEInfoImpl*)aData;
|
||||
NS_ASSERTION(entry, "mapping problem");
|
||||
NS_RELEASE(entry);
|
||||
return PR_TRUE;
|
||||
};
|
||||
|
||||
// nsISupports methods
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsXMLMIMEDataSource, nsIMIMEDataSource);
|
||||
|
||||
NS_METHOD
|
||||
nsXMLMIMEDataSource::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult) {
|
||||
nsXMLMIMEDataSource* service = new nsXMLMIMEDataSource();
|
||||
if (!service) return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(service);
|
||||
nsresult rv = service->Init();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = service->QueryInterface(aIID, aResult);
|
||||
NS_RELEASE(service);
|
||||
return rv;
|
||||
}
|
||||
|
||||
// nsXMLMIMEDataSource methods
|
||||
nsXMLMIMEDataSource::nsXMLMIMEDataSource() {
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsXMLMIMEDataSource::~nsXMLMIMEDataSource() {
|
||||
mInfoObjects->Reset(DeleteEntry, nsnull);
|
||||
delete mInfoObjects;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsXMLMIMEDataSource::Init() {
|
||||
nsresult rv = NS_OK;
|
||||
mInfoObjects = new nsHashtable();
|
||||
if (!mInfoObjects) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
rv = NS_NewISupportsArray(getter_AddRefs(mInfoArray));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return InitFromHack();
|
||||
}
|
||||
|
||||
/* This bad boy needs to retrieve a url, and parse the data coming back, and
|
||||
* add entries into the mInfoArray.
|
||||
*/
|
||||
nsresult
|
||||
nsXMLMIMEDataSource::InitFromURI(nsIURI *aUri) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsXMLMIMEDataSource::InitFromFile( nsIFile* /* aFile */ )
|
||||
{
|
||||
#if 0
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv) ;
|
||||
if(NS_FAILED(rv)) return rv ;
|
||||
// Made second parameter 0 since I really don't know what it is used for
|
||||
rv = fts->CreateTransport(aFile,0, "load", 0, 0, getter_AddRefs(channel)) ;
|
||||
if(NS_FAILED(rv))
|
||||
return rv ;
|
||||
|
||||
// we don't need to worry about notification callbacks
|
||||
nsCOMPtr<nsIInputStream> stream;
|
||||
rv = channel->OpenInputStream(0, 0, getter_AddRefs( stream ) ) ;
|
||||
#endif
|
||||
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsXMLMIMEDataSource::AddMapping(const char* mimeType,
|
||||
const char* extension,
|
||||
const char* description,
|
||||
nsIURI* dataURI, PRUint32 type, PRUint32 creator)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
// setup the new MIMEInfo object.
|
||||
nsMIMEInfoImpl* anInfo = new nsMIMEInfoImpl(mimeType);
|
||||
if (!anInfo) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
anInfo->mExtensions.AppendCString(extension);
|
||||
anInfo->mDescription = description;
|
||||
anInfo->mURI = dataURI;
|
||||
|
||||
anInfo->mMacType = type;
|
||||
anInfo->mMacCreator = creator;
|
||||
// The entry is mapped many-to-one and the MIME type is the root mapping.
|
||||
|
||||
// First remove any existing mapping.
|
||||
rv = Remove(mimeType);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Next add the new root MIME mapping.
|
||||
nsStringKey key(mimeType);
|
||||
nsMIMEInfoImpl* oldInfo = (nsMIMEInfoImpl*)mInfoObjects->Put(&key, anInfo);
|
||||
NS_ASSERTION(!oldInfo, "we just removed the entry, we shouldn't have one");
|
||||
NS_ADDREF(anInfo);
|
||||
|
||||
rv = mInfoArray->AppendElement(anInfo); // update the root array.
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Finally add an extension mapping.
|
||||
key = extension;
|
||||
oldInfo = (nsMIMEInfoImpl*)mInfoObjects->Put(&key, anInfo);
|
||||
NS_ASSERTION(!oldInfo, "file extension mappings should have been cleaned up in the RemoveMapping call");
|
||||
|
||||
NS_ADDREF(anInfo);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXMLMIMEDataSource::Add( nsIMIMEInfo* aMapper )
|
||||
{
|
||||
if ( !aMapper )
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
nsXPIDLCString mimeType;
|
||||
rv = aMapper->GetMIMEType( getter_Copies( mimeType ) );
|
||||
if ( NS_FAILED( rv ) )
|
||||
return rv;
|
||||
// First remove any existing mapping.
|
||||
rv = Remove(mimeType);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Next add the new root MIME mapping.
|
||||
nsStringKey key(mimeType);
|
||||
nsMIMEInfoImpl* oldInfo = (nsMIMEInfoImpl*)mInfoObjects->Put(&key, aMapper);
|
||||
NS_ASSERTION(!oldInfo, "we just removed the entry, we shouldn't have one");
|
||||
NS_ADDREF(aMapper);
|
||||
|
||||
rv = mInfoArray->AppendElement(aMapper); // update the root array.
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Finally add an extension mapping.
|
||||
char** extensions;
|
||||
PRInt32 count;
|
||||
rv = aMapper->GetFileExtensions(& count, &extensions );
|
||||
if ( NS_FAILED ( rv ) )
|
||||
return rv;
|
||||
for ( PRInt32 i = 0; i<count; i++ )
|
||||
{
|
||||
key = extensions[i];
|
||||
oldInfo = (nsMIMEInfoImpl*)mInfoObjects->Put(&key, aMapper);
|
||||
NS_ASSERTION(!oldInfo, "file extension mappings should have been cleaned up in the RemoveMapping call");
|
||||
NS_ADDREF(aMapper);
|
||||
nsAllocator::Free( extensions[i] );
|
||||
}
|
||||
nsAllocator::Free( extensions );
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// used to cleanup any file extension mappings when
|
||||
// a root MIME entry is removed.
|
||||
PRBool removeExts(nsCString& aElement, void *aData) {
|
||||
nsHashtable* infoObjects = (nsHashtable*)aData;
|
||||
NS_ASSERTION(infoObjects, "hash table botched up");
|
||||
|
||||
nsStringKey key(aElement);
|
||||
nsMIMEInfoImpl* info = (nsMIMEInfoImpl*)infoObjects->Remove(&key);
|
||||
NS_RELEASE(info);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXMLMIMEDataSource::Remove(const char* aMIMEType) {
|
||||
nsresult rv = NS_OK;
|
||||
nsStringKey key(aMIMEType);
|
||||
|
||||
// First remove the root MIME mapping.
|
||||
nsMIMEInfoImpl* info = (nsMIMEInfoImpl*)mInfoObjects->Remove(&key);
|
||||
if (!info) return NS_OK;
|
||||
|
||||
rv = mInfoArray->RemoveElement(info); // update the root array.
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Next remove any file association mappings.
|
||||
rv = info->mExtensions.EnumerateForwards(removeExts, mInfoObjects);
|
||||
NS_RELEASE(info);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// mMacCache is potentially invalid
|
||||
mMacCache.Reset();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsXMLMIMEDataSource::AppendExtension(const char* mimeType, const char* extension) {
|
||||
nsStringKey key(mimeType);
|
||||
|
||||
nsMIMEInfoImpl* info = (nsMIMEInfoImpl*)mInfoObjects->Get(&key);
|
||||
if (!info) return NS_ERROR_FAILURE;
|
||||
|
||||
info->mExtensions.AppendCString(extension);
|
||||
|
||||
// Add another file extension mapping.
|
||||
key = extension;
|
||||
nsMIMEInfoImpl* oldInfo = (nsMIMEInfoImpl*)mInfoObjects->Put(&key, info);
|
||||
NS_IF_RELEASE(oldInfo); // overwrite any existing mapping.
|
||||
NS_ADDREF(info);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsXMLMIMEDataSource::RemoveExtension(const char* aExtension) {
|
||||
nsresult rv = NS_OK;
|
||||
nsStringKey key(aExtension);
|
||||
|
||||
// First remove the extension mapping.
|
||||
nsMIMEInfoImpl* info = (nsMIMEInfoImpl*)mInfoObjects->Remove(&key);
|
||||
if (!info) return NS_ERROR_FAILURE;
|
||||
|
||||
// Next remove the root MIME mapping from the array and hash
|
||||
// IFF this was the only file extension mapping left.
|
||||
PRBool removed = info->mExtensions.RemoveCString(key.GetString());
|
||||
NS_ASSERTION(removed, "mapping problem");
|
||||
|
||||
if (info->GetExtCount() == 0) {
|
||||
// it's empty, remove the root mapping from hash and array.
|
||||
nsXPIDLCString mimeType;
|
||||
rv = info->GetMIMEType(getter_Copies(mimeType));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
key = (const char*)mimeType;
|
||||
nsMIMEInfoImpl* rootEntry = (nsMIMEInfoImpl*)mInfoObjects->Remove(&key);
|
||||
NS_ASSERTION(rootEntry, "mapping miss-hap");
|
||||
|
||||
rv = mInfoArray->RemoveElement(rootEntry); // update the root array
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_RELEASE(rootEntry);
|
||||
}
|
||||
|
||||
NS_RELEASE(info);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXMLMIMEDataSource::GetEnumerator(nsISimpleEnumerator* *aEnumerator) {
|
||||
return NS_NewArrayEnumerator( aEnumerator, mInfoArray);
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXMLMIMEDataSource::Serialize() {
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
#if 0
|
||||
// Init mFile Hack
|
||||
// Lovely hack until the filespec and nsIFile stuff is merged together
|
||||
// nsFileSpec dirSpec;
|
||||
// nsCOMPtr<nsIFileSpec> spec = NS_LocateFileOrDirectory(nsSpecialFileSpec::App_UserProfileDirectory50);
|
||||
// if (!spec) return NS_ERROR_FAILURE;
|
||||
// spec->GetFileSpec(&dirSpec);
|
||||
nsCOMPtr<nsILocalFile> file;
|
||||
// char* path;
|
||||
// spec->GetNativePath(& path );
|
||||
const char* path = "development:";
|
||||
rv = NS_NewLocalFile( path, getter_AddRefs(file));
|
||||
|
||||
if ( NS_SUCCEEDED( rv ) )
|
||||
{
|
||||
|
||||
file->Append("mime.xml");
|
||||
mFile = file;
|
||||
file->SetLeafName("mime.temp");
|
||||
}
|
||||
mFile = file;
|
||||
//
|
||||
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv) ;
|
||||
if(NS_FAILED(rv)) return rv ;
|
||||
|
||||
rv = fts->CreateTransport( mFile,0, "load", 0, 0, getter_AddRefs(channel)) ;
|
||||
if(NS_FAILED(rv))
|
||||
return rv ;
|
||||
|
||||
// we don't need to worry about notification callbacks
|
||||
nsCOMPtr<nsIOutputStream> stream;
|
||||
rv = channel->OpenOutputStream( 0, getter_AddRefs( stream ) ) ;
|
||||
|
||||
nsCOMPtr<nsISimpleEnumerator> enumerator;
|
||||
rv = GetEnumerator( getter_AddRefs( enumerator ) );
|
||||
if ( NS_FAILED( rv ) )
|
||||
return rv;
|
||||
nsCString buffer;
|
||||
nsXPIDLCString cdata;
|
||||
nsXPIDLString unidata;
|
||||
|
||||
buffer="<?xml version=\"1.0\"?>\r";
|
||||
PRUint32 bytesWritten;
|
||||
PRBool more;
|
||||
|
||||
rv = stream->Write( buffer , buffer.Length(), &bytesWritten );
|
||||
|
||||
while ( NS_SUCCEEDED( enumerator->HasMoreElements(& more ) )&& more )
|
||||
{
|
||||
nsCOMPtr<nsIMIMEInfo> info;
|
||||
rv = enumerator->GetNext( getter_AddRefs( info ) );
|
||||
if ( NS_FAILED ( rv ) )
|
||||
return rv;
|
||||
|
||||
buffer="<mimetype ";
|
||||
rv = info->GetDescription( getter_Copies( unidata ) );
|
||||
if ( NS_FAILED ( rv ) )
|
||||
return rv;
|
||||
buffer+= kDescription;
|
||||
buffer+="=\"";
|
||||
nsString temp = unidata;
|
||||
char* utf8 = temp.ToNewUTF8String();
|
||||
buffer+=utf8;
|
||||
nsAllocator::Free( utf8 );
|
||||
buffer+="\" ";
|
||||
|
||||
rv = info->GetMIMEType( getter_Copies( cdata ) );
|
||||
if ( NS_FAILED ( rv ) )
|
||||
return rv;
|
||||
buffer+=kMIMEType;
|
||||
buffer+="=\"";
|
||||
buffer+=cdata;
|
||||
buffer+="\" ";
|
||||
|
||||
char** extensions;
|
||||
PRInt32 count;
|
||||
rv = info->GetFileExtensions(& count, &extensions );
|
||||
if ( NS_FAILED ( rv ) )
|
||||
return rv;
|
||||
buffer+=kExtensions;
|
||||
buffer+="=\"";
|
||||
for ( PRInt32 i = 0; i<(count-1); i++ )
|
||||
{
|
||||
buffer+=extensions[i];
|
||||
buffer+=",";
|
||||
nsAllocator::Free( extensions[i] );
|
||||
}
|
||||
buffer+=extensions[count-1];
|
||||
buffer+="\" ";
|
||||
nsAllocator::Free( extensions[count-1] );
|
||||
nsAllocator::Free( extensions );
|
||||
|
||||
buffer+="/>\r";
|
||||
|
||||
rv = stream->Write( buffer , buffer.Length(), &bytesWritten );
|
||||
|
||||
if ( NS_FAILED( rv ) )
|
||||
return rv;
|
||||
}
|
||||
rv = stream->Close();
|
||||
// Now delete the old file and rename the new one
|
||||
mFile->Delete( PR_FALSE);
|
||||
file->MoveTo( NULL, "mime.xml");
|
||||
#endif
|
||||
return rv;
|
||||
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsXMLMIMEDataSource::InitFromHack() {
|
||||
nsresult rv;
|
||||
|
||||
rv = AddMapping(TEXT_PLAIN, "txt", "Text File", nsnull, 'TEXT','ttxt');
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = AppendExtension(TEXT_PLAIN, "text");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AddMapping(APPLICATION_OCTET_STREAM, "exe", "Binary Executable", nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = AppendExtension(APPLICATION_OCTET_STREAM, "bin");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
#if defined(VMS)
|
||||
rv = AppendExtension(APPLICATION_OCTET_STREAM, "sav");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = AppendExtension(APPLICATION_OCTET_STREAM, "bck");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = AppendExtension(APPLICATION_OCTET_STREAM, "pcsi");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = AppendExtension(APPLICATION_OCTET_STREAM, "pcsi-dcx_axpexe");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = AppendExtension(APPLICATION_OCTET_STREAM, "pcsi-dcx_vaxexe");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
#endif
|
||||
|
||||
rv = AddMapping(TEXT_HTML, "htm", "Hyper Text Markup Language", nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = AppendExtension(TEXT_HTML, "html");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = AppendExtension(TEXT_HTML, "shtml");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AppendExtension(TEXT_HTML, "ehtml");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AddMapping(TEXT_RDF, "rdf", "Resource Description Framework", nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AddMapping(TEXT_XUL, "xul", "XML-Based User Interface Language", nsnull, 'TEXT','ttxt' );
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AddMapping(TEXT_XML, "xml", "Extensible Markup Language", nsnull, 'TEXT','ttxt');
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AddMapping(TEXT_CSS, "css", "Style Sheet", nsnull, 'TEXT','ttxt');
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AddMapping(APPLICATION_JAVASCRIPT, "js", "Javascript Source File", nsnull, 'TEXT','ttxt');
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AddMapping(MESSAGE_RFC822, "eml", "RFC-822 data", nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AddMapping(APPLICATION_GZIP2, "gz", "gzip", nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
||||
rv = AddMapping(IMAGE_GIF, "gif", "GIF Image", nsnull, 'GIFf','GCon' );
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AddMapping(IMAGE_JPG, "jpeg", "JPEG Image", nsnull, 'JPEG', 'GCon' );
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = AppendExtension(IMAGE_JPG, "jpg");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AddMapping(IMAGE_PNG, "png", "PNG Image", nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AddMapping(IMAGE_ART, "art", "ART Image", nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AddMapping(IMAGE_TIFF, "tiff", "TIFF Image", nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = AppendExtension(IMAGE_TIFF, "tif");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AddMapping(APPLICATION_POSTSCRIPT, "ps", "Postscript File", nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = AppendExtension(APPLICATION_POSTSCRIPT, "eps");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AppendExtension(APPLICATION_POSTSCRIPT, "ai");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = AddMapping(TEXT_RTF, "rtf", "Rich Text Format", nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
||||
rv = AddMapping(TEXT_CPP, "cpp", "CPP file", nsnull, 'TEXT','CWIE');
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
||||
rv = AddMapping( "application/x-arj", "arj", "ARJ file", nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
// nsIMIMEService methods
|
||||
NS_IMETHODIMP
|
||||
nsXMLMIMEDataSource::GetFromExtension(const char *aFileExt, nsIMIMEInfo **_retval) {
|
||||
// for now we're assuming file extensions are case insensitive.
|
||||
nsCAutoString fileExt(aFileExt);
|
||||
fileExt.ToLowerCase();
|
||||
|
||||
nsStringKey key(fileExt.GetBuffer());
|
||||
|
||||
nsMIMEInfoImpl *entry = (nsMIMEInfoImpl*)mInfoObjects->Get(&key);
|
||||
if (!entry) return NS_ERROR_FAILURE;
|
||||
NS_ADDREF(entry);
|
||||
*_retval = NS_STATIC_CAST(nsIMIMEInfo*, entry);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXMLMIMEDataSource::GetFromMIMEType(const char *aMIMEType, nsIMIMEInfo **_retval) {
|
||||
nsCAutoString MIMEType(aMIMEType);
|
||||
MIMEType.ToLowerCase();
|
||||
|
||||
nsStringKey key(MIMEType.GetBuffer());
|
||||
|
||||
nsMIMEInfoImpl *entry = (nsMIMEInfoImpl*)mInfoObjects->Get(&key);
|
||||
if (!entry) return NS_ERROR_FAILURE;
|
||||
NS_ADDREF(entry);
|
||||
*_retval = NS_STATIC_CAST(nsIMIMEInfo*, entry);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXMLMIMEDataSource::GetFromTypeCreator(PRUint32 aType, PRUint32 aCreator, const char* aExt, nsIMIMEInfo **_retval)
|
||||
{
|
||||
PRUint32 buf[2];
|
||||
buf[0] = aType;
|
||||
buf[1] = aCreator;
|
||||
nsAutoString keyString( (char*)buf,8 );
|
||||
keyString+=aExt;
|
||||
nsStringKey key( keyString );
|
||||
// Check if in cache for real quick look up of common ( html,js, xul, ...) types
|
||||
nsIMIMEInfo *entry = (nsIMIMEInfo*)mMacCache.Get(&key);
|
||||
if (entry)
|
||||
{
|
||||
NS_ADDREF(entry);
|
||||
*_retval = entry;
|
||||
return NS_OK;
|
||||
}
|
||||
// iterate through looking for a match
|
||||
// must match type, bonus points for ext, and app
|
||||
// use the same scoring as IC
|
||||
PRInt32 score = 0;
|
||||
nsCOMPtr<nsISimpleEnumerator> enumerator;
|
||||
nsresult rv = GetEnumerator( getter_AddRefs( enumerator ) );
|
||||
if ( NS_FAILED( rv ) )
|
||||
return rv;
|
||||
nsCOMPtr< nsIMIMEInfo> info;
|
||||
nsCOMPtr<nsIMIMEInfo> bestMatch;
|
||||
PRBool hasMore;
|
||||
nsCString extString ( aExt );
|
||||
while( NS_SUCCEEDED(enumerator->HasMoreElements( & hasMore ) ) && hasMore )
|
||||
{
|
||||
enumerator->GetNext( getter_AddRefs( info ) );
|
||||
PRUint32 type, creator;
|
||||
info->GetMacType( &type );
|
||||
info->GetMacCreator( &creator );
|
||||
|
||||
PRInt32 scoreOfElement = 0;
|
||||
if ( type == aType )
|
||||
{
|
||||
scoreOfElement=2;
|
||||
}
|
||||
|
||||
|
||||
if ( creator == aCreator )
|
||||
scoreOfElement++;
|
||||
|
||||
PRBool tempBool = PR_FALSE;
|
||||
info->ExtensionExists( aExt, &tempBool );
|
||||
if ( tempBool )
|
||||
scoreOfElement+= 4;
|
||||
|
||||
if ( scoreOfElement > score )
|
||||
{
|
||||
score = scoreOfElement;
|
||||
bestMatch = info;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( score != 0 )
|
||||
{
|
||||
*_retval = bestMatch;
|
||||
NS_ADDREF( *_retval );
|
||||
|
||||
// Add to cache
|
||||
mMacCache.Put( &key, bestMatch.get() );
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Judson Valeski
|
||||
*/
|
||||
|
||||
/*
|
||||
* There is a 1-to-many relationship between MIME-types and file extensions
|
||||
* I.e. there can be many file extensions that have the same mime type.
|
||||
*/
|
||||
|
||||
#ifndef ___nsXMLMIMEDataSource__h___
|
||||
#define ___nsXMLMIMEDataSource__h___
|
||||
|
||||
#include "nsIMIMEDataSource.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsHashtable.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsIFile.h"
|
||||
class nsIFile;
|
||||
|
||||
class nsXMLMIMEDataSource : public nsIMIMEDataSource {
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIMIMEDATASOURCE
|
||||
|
||||
// nsMIMEService methods
|
||||
nsXMLMIMEDataSource();
|
||||
virtual ~nsXMLMIMEDataSource();
|
||||
nsresult Init();
|
||||
static NS_METHOD Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult);
|
||||
|
||||
private:
|
||||
nsresult AddMapping(const char* mimeType,
|
||||
const char* extension,
|
||||
const char* description,
|
||||
nsIURI* dataURI, PRUint32 type=PRUint32(0x3F3F3F3F), PRUint32 creator=PRUint32(0x3F3F3F3F));
|
||||
nsresult AppendExtension(const char* mimeType, const char* extension);
|
||||
nsresult RemoveExtension(const char* aExtension);
|
||||
|
||||
nsresult InitFromURI(nsIURI *aUri);
|
||||
nsresult InitFromHack();
|
||||
nsresult InitFromFile( nsIFile* /* aFile */ );
|
||||
|
||||
nsCOMPtr<nsIFile> mFile; // File to load the datasource from
|
||||
nsHashtable *mInfoObjects; // used for fast access and
|
||||
// multi index lookups
|
||||
|
||||
nsHashtable mMacCache; // Cache for lookup of file creator types
|
||||
|
||||
nsCOMPtr<nsISupportsArray> mInfoArray; // used for enumeration
|
||||
};
|
||||
|
||||
#endif // ___nsXMLMIMEDataSource__h___
|
||||
@@ -26,7 +26,7 @@ VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = about data file ftp http keyword jar res \
|
||||
DIRS = about data file resource ftp http keyword jar res \
|
||||
datetime finger
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
@@ -31,17 +31,14 @@ interface nsIEventQueue;
|
||||
[scriptable, uuid(692303c0-2f83-11d3-8cd0-0060b0fc14a3)]
|
||||
interface nsIAboutModule : nsISupports
|
||||
{
|
||||
/**
|
||||
* Constructs a new channel for the about protocol module.
|
||||
*
|
||||
* @param originalURI - Specifies the original URI which caused the creation
|
||||
* of this channel. This can occur when the construction of one channel
|
||||
* (e.g. for resource:) causes another channel to be created on its behalf
|
||||
* (e.g. a file: channel), or if a redirect occurs, causing the current
|
||||
* URL to become different from the original URL. If NULL, the aURI parameter
|
||||
* will be used as the originalURI instead.
|
||||
*/
|
||||
nsIChannel newChannel(in nsIURI aURI);
|
||||
nsIChannel newChannel(in string verb,
|
||||
in nsIURI aURI,
|
||||
in nsILoadGroup aLoadGroup,
|
||||
in nsIInterfaceRequestor notificationCallbacks,
|
||||
in nsLoadFlags loadAttributes,
|
||||
in nsIURI originalURI,
|
||||
in unsigned long bufferSegmentSize,
|
||||
in unsigned long bufferMaxSize);
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
||||
@@ -28,7 +28,6 @@ include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = necko
|
||||
LIBRARY_NAME = necko_about
|
||||
SHORT_LIBNAME = neckoabt
|
||||
IS_COMPONENT = 1
|
||||
|
||||
REQUIRES = xpcom necko
|
||||
|
||||
@@ -33,12 +33,20 @@ NS_IMPL_ISUPPORTS(nsAboutBlank, NS_GET_IID(nsIAboutModule));
|
||||
static const char kBlankPage[] = "";
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAboutBlank::NewChannel(nsIURI *aURI, nsIChannel **result)
|
||||
nsAboutBlank::NewChannel(const char *verb,
|
||||
nsIURI *aURI,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize,
|
||||
nsIChannel **result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsIChannel* channel;
|
||||
nsISupports* s;
|
||||
rv = NS_NewCStringInputStream(&s, kBlankPage);
|
||||
rv = NS_NewStringInputStream(&s, kBlankPage);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsIInputStream* in;
|
||||
|
||||
@@ -46,8 +54,11 @@ nsAboutBlank::NewChannel(nsIURI *aURI, nsIChannel **result)
|
||||
NS_RELEASE(s);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = NS_NewInputStreamChannel(&channel, aURI, in, "text/html",
|
||||
nsCRT::strlen(kBlankPage));
|
||||
rv = NS_NewInputStreamChannel(aURI, "text/html",
|
||||
nsCRT::strlen(kBlankPage),
|
||||
in, aLoadGroup, notificationCallbacks,
|
||||
loadAttributes, originalURI,
|
||||
bufferSegmentSize, bufferMaxSize, &channel);
|
||||
NS_RELEASE(in);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
||||
@@ -42,7 +42,15 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
NS_IMPL_ISUPPORTS(nsAboutBloat, NS_GET_IID(nsIAboutModule));
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAboutBloat::NewChannel(nsIURI *aURI, nsIChannel **result)
|
||||
nsAboutBloat::NewChannel(const char *verb,
|
||||
nsIURI *aURI,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize,
|
||||
nsIChannel **result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsXPIDLCString path;
|
||||
@@ -73,7 +81,7 @@ nsAboutBloat::NewChannel(nsIURI *aURI, nsIChannel **result)
|
||||
|
||||
nsCOMPtr<nsISupports> s;
|
||||
const char* msg = "Bloat statistics cleared.";
|
||||
rv = NS_NewCStringInputStream(getter_AddRefs(s), msg);
|
||||
rv = NS_NewStringInputStream(getter_AddRefs(s), msg);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
size = nsCRT::strlen(msg);
|
||||
@@ -87,7 +95,7 @@ nsAboutBloat::NewChannel(nsIURI *aURI, nsIChannel **result)
|
||||
|
||||
nsCOMPtr<nsISupports> s;
|
||||
const char* msg = "Memory leaks dumped.";
|
||||
rv = NS_NewCStringInputStream(getter_AddRefs(s), msg);
|
||||
rv = NS_NewStringInputStream(getter_AddRefs(s), msg);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
size = nsCRT::strlen(msg);
|
||||
@@ -142,12 +150,15 @@ nsAboutBloat::NewChannel(nsIURI *aURI, nsIChannel **result)
|
||||
rv = file->GetFileSize(&bigSize);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = NS_NewLocalFileInputStream(getter_AddRefs(inStr), file);
|
||||
rv = NS_NewFileInputStream(file, getter_AddRefs(inStr));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
nsIChannel* channel;
|
||||
rv = NS_NewInputStreamChannel(&channel, aURI, inStr, "text/plain", size);
|
||||
rv = NS_NewInputStreamChannel(aURI, "text/plain",
|
||||
size, inStr, aLoadGroup, notificationCallbacks,
|
||||
loadAttributes, originalURI,
|
||||
bufferSegmentSize, bufferMaxSize, &channel);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*result = channel;
|
||||
|
||||
@@ -30,17 +30,28 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsAboutCredits, NS_GET_IID(nsIAboutModule));
|
||||
|
||||
static const char kCreditsPage[] = "http://www.mozilla.org/credits/";
|
||||
static const char kCreditsPage[] = "http://www.mozilla.org/credits";
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAboutCredits::NewChannel(nsIURI *aURI, nsIChannel **result)
|
||||
nsAboutCredits::NewChannel(const char *verb,
|
||||
nsIURI *aURI,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize,
|
||||
nsIChannel **result)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIIOService, ioService, kIOServiceCID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = ioService->NewChannel(kCreditsPage, nsnull, result);
|
||||
return rv;
|
||||
return rv;
|
||||
rv = ioService->NewChannel(verb, kCreditsPage, NULL, aLoadGroup,
|
||||
notificationCallbacks, loadAttributes,
|
||||
originalURI, bufferSegmentSize, bufferMaxSize,
|
||||
result);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
|
||||
@@ -121,7 +121,14 @@ nsAboutProtocolHandler::NewURI(const char *aSpec, nsIURI *aBaseURI,
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAboutProtocolHandler::NewChannel(nsIURI* uri, nsIChannel* *result)
|
||||
nsAboutProtocolHandler::NewChannel(const char* verb, nsIURI* uri,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize,
|
||||
nsIChannel* *result)
|
||||
{
|
||||
// about:what you ask?
|
||||
nsresult rv;
|
||||
@@ -130,14 +137,13 @@ nsAboutProtocolHandler::NewChannel(nsIURI* uri, nsIChannel* *result)
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// look up a handler to deal with "whatStr"
|
||||
nsAutoString progID; progID.AssignWithConversion(NS_ABOUT_MODULE_PROGID_PREFIX);
|
||||
nsAutoString what; what.AssignWithConversion(whatStr);
|
||||
nsAutoString progID(NS_ABOUT_MODULE_PROGID_PREFIX);
|
||||
nsAutoString what(whatStr);
|
||||
nsCRT::free(whatStr);
|
||||
|
||||
// only take up to a question-mark if there is one:
|
||||
PRInt32 amt = what.Find("?");
|
||||
// STRING USE WARNING: this use needs to be examined -- scc
|
||||
progID.Append(what.GetUnicode(), amt); // if amt == -1, take it all
|
||||
progID.Append(what, amt); // if amt == -1, take it all
|
||||
|
||||
char* progIDStr = progID.ToNewCString();
|
||||
if (progIDStr == nsnull)
|
||||
@@ -146,7 +152,9 @@ nsAboutProtocolHandler::NewChannel(nsIURI* uri, nsIChannel* *result)
|
||||
nsCRT::free(progIDStr);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// The standard return case:
|
||||
return aboutMod->NewChannel(uri, result);
|
||||
return aboutMod->NewChannel(verb, uri, aLoadGroup, notificationCallbacks,
|
||||
loadAttributes, originalURI, bufferSegmentSize,
|
||||
bufferMaxSize, result);
|
||||
}
|
||||
|
||||
// mumble...
|
||||
|
||||
@@ -28,7 +28,6 @@ include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = necko
|
||||
LIBRARY_NAME = necko_data
|
||||
SHORT_LIBNAME = neckodat
|
||||
IS_COMPONENT = 1
|
||||
|
||||
CPPSRCS = \
|
||||
|
||||
@@ -53,13 +53,32 @@ NS_IMPL_ISUPPORTS3(nsDataChannel,
|
||||
nsIRequest)
|
||||
|
||||
nsresult
|
||||
nsDataChannel::Init(nsIURI* uri)
|
||||
nsDataChannel::Init(const char* verb,
|
||||
nsIURI* uri,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize)
|
||||
{
|
||||
// we don't care about event sinks in data
|
||||
nsresult rv;
|
||||
|
||||
rv = SetLoadAttributes(loadAttributes);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = SetLoadGroup(aLoadGroup);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = SetNotificationCallbacks(notificationCallbacks);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Data urls contain all the data within the url string itself.
|
||||
mOriginalURI = originalURI ? originalURI : uri;
|
||||
mUrl = uri;
|
||||
mBufferSegmentSize = bufferSegmentSize;
|
||||
mBufferMaxSize = bufferMaxSize;
|
||||
|
||||
rv = ParseData();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
@@ -156,17 +175,11 @@ nsDataChannel::ParseData() {
|
||||
|
||||
if (lBase64) {
|
||||
*base64 = 'b';
|
||||
PRInt32 resultLen = 0;
|
||||
if (comma[dataLen-1] == '=')
|
||||
if (comma[dataLen-2] == '=')
|
||||
resultLen = dataLen-2;
|
||||
else
|
||||
resultLen = dataLen-1;
|
||||
|
||||
char * decodedData = PL_Base64Decode(comma+1, dataLen, nsnull);
|
||||
if (!decodedData) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
dataToWrite->dataLen = resultLen;
|
||||
dataToWrite->dataLen = PL_strlen(decodedData);
|
||||
dataToWrite->data = decodedData;
|
||||
|
||||
rv = bufOutStream->WriteSegments(nsReadData, dataToWrite, dataToWrite->dataLen, &wrote);
|
||||
@@ -210,35 +223,24 @@ nsDataChannel::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult)
|
||||
NS_IMETHODIMP
|
||||
nsDataChannel::IsPending(PRBool *result)
|
||||
{
|
||||
NS_NOTREACHED("nsDataChannel::IsPending");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDataChannel::GetStatus(nsresult *status)
|
||||
nsDataChannel::Cancel(void)
|
||||
{
|
||||
*status = NS_OK;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDataChannel::Cancel(nsresult status)
|
||||
{
|
||||
NS_NOTREACHED("nsDataChannel::Cancel");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDataChannel::Suspend(void)
|
||||
{
|
||||
NS_NOTREACHED("nsDataChannel::Suspend");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDataChannel::Resume(void)
|
||||
{
|
||||
NS_NOTREACHED("nsDataChannel::Resume");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@@ -246,39 +248,26 @@ nsDataChannel::Resume(void)
|
||||
// nsIChannel methods:
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDataChannel::GetOriginalURI(nsIURI* *aURI)
|
||||
nsDataChannel::GetOriginalURI(nsIURI * *aURI)
|
||||
{
|
||||
*aURI = mOriginalURI ? mOriginalURI : mUrl;
|
||||
*aURI = mOriginalURI;
|
||||
NS_ADDREF(*aURI);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDataChannel::SetOriginalURI(nsIURI* aURI)
|
||||
{
|
||||
mOriginalURI = aURI;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDataChannel::GetURI(nsIURI* *aURI)
|
||||
nsDataChannel::GetURI(nsIURI * *aURI)
|
||||
{
|
||||
*aURI = mUrl;
|
||||
NS_IF_ADDREF(*aURI);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDataChannel::SetURI(nsIURI* aURI)
|
||||
{
|
||||
mUrl = aURI;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// This class
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDataChannel::OpenInputStream(nsIInputStream **_retval)
|
||||
nsDataChannel::OpenInputStream(PRUint32 startPosition, PRInt32 readCount,
|
||||
nsIInputStream **_retval)
|
||||
{
|
||||
// XXX we should honor the startPosition and count passed in.
|
||||
|
||||
@@ -289,22 +278,22 @@ nsDataChannel::OpenInputStream(nsIInputStream **_retval)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDataChannel::OpenOutputStream(nsIOutputStream **_retval)
|
||||
nsDataChannel::OpenOutputStream(PRUint32 startPosition, nsIOutputStream **_retval)
|
||||
{
|
||||
// you can't write to a data url
|
||||
NS_NOTREACHED("nsDataChannel::OpenOutputStream");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDataChannel::AsyncOpen(nsIStreamObserver *observer, nsISupports* ctxt)
|
||||
{
|
||||
NS_NOTREACHED("nsDataChannel::AsyncOpen");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDataChannel::AsyncRead(nsIStreamListener *aListener, nsISupports *ctxt)
|
||||
nsDataChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
|
||||
nsISupports *ctxt,
|
||||
nsIStreamListener *aListener)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIEventQueue> eventQ;
|
||||
@@ -318,7 +307,7 @@ nsDataChannel::AsyncRead(nsIStreamListener *aListener, nsISupports *ctxt)
|
||||
|
||||
// we'll just fire everything off at once because we've already got all
|
||||
// the data.
|
||||
rv = NS_NewAsyncStreamListener(getter_AddRefs(listener), aListener, eventQ);
|
||||
rv = NS_NewAsyncStreamListener(aListener, eventQ, getter_AddRefs(listener));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = listener->OnStartRequest(this, ctxt);
|
||||
@@ -338,11 +327,12 @@ nsDataChannel::AsyncRead(nsIStreamListener *aListener, nsISupports *ctxt)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDataChannel::AsyncWrite(nsIInputStream *fromStream,
|
||||
nsIStreamObserver *observer,
|
||||
nsISupports *ctxt)
|
||||
PRUint32 startPosition,
|
||||
PRInt32 writeCount,
|
||||
nsISupports *ctxt,
|
||||
nsIStreamObserver *observer)
|
||||
{
|
||||
// you can't write to a data url
|
||||
NS_NOTREACHED("nsDataChannel::AsyncWrite");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@@ -390,90 +380,6 @@ nsDataChannel::GetContentLength(PRInt32 *aContentLength)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDataChannel::SetContentLength(PRInt32 aContentLength)
|
||||
{
|
||||
mContentLength = aContentLength;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDataChannel::GetTransferOffset(PRUint32 *aTransferOffset)
|
||||
{
|
||||
NS_NOTREACHED("nsDataChannel::GetTransferOffset");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDataChannel::SetTransferOffset(PRUint32 aTransferOffset)
|
||||
{
|
||||
NS_NOTREACHED("nsDataChannel::SetTransferOffset");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDataChannel::GetTransferCount(PRInt32 *aTransferCount)
|
||||
{
|
||||
NS_NOTREACHED("nsDataChannel::GetTransferCount");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDataChannel::SetTransferCount(PRInt32 aTransferCount)
|
||||
{
|
||||
NS_NOTREACHED("nsDataChannel::SetTransferCount");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDataChannel::GetBufferSegmentSize(PRUint32 *aBufferSegmentSize)
|
||||
{
|
||||
*aBufferSegmentSize = mBufferSegmentSize;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDataChannel::SetBufferSegmentSize(PRUint32 aBufferSegmentSize)
|
||||
{
|
||||
mBufferSegmentSize = aBufferSegmentSize;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDataChannel::GetBufferMaxSize(PRUint32 *aBufferMaxSize)
|
||||
{
|
||||
*aBufferMaxSize = mBufferMaxSize;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDataChannel::SetBufferMaxSize(PRUint32 aBufferMaxSize)
|
||||
{
|
||||
mBufferMaxSize = aBufferMaxSize;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDataChannel::GetShouldCache(PRBool *aShouldCache)
|
||||
{
|
||||
*aShouldCache = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDataChannel::GetPipeliningAllowed(PRBool *aPipeliningAllowed)
|
||||
{
|
||||
*aPipeliningAllowed = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDataChannel::SetPipeliningAllowed(PRBool aPipeliningAllowed)
|
||||
{
|
||||
NS_NOTREACHED("SetPipeliningAllowed");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDataChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup)
|
||||
{
|
||||
@@ -519,9 +425,3 @@ nsDataChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCall
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDataChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
|
||||
{
|
||||
*aSecurityInfo = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
#include "nsIDataChannel.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsString.h"
|
||||
#include "nsString2.h"
|
||||
#include "nsIEventQueue.h"
|
||||
#include "nsILoadGroup.h"
|
||||
#include "nsIStreamListener.h"
|
||||
@@ -50,7 +50,14 @@ public:
|
||||
static NS_METHOD
|
||||
Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult);
|
||||
|
||||
nsresult Init(nsIURI* uri);
|
||||
nsresult Init(const char* verb,
|
||||
nsIURI* uri,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize);
|
||||
nsresult ParseData();
|
||||
|
||||
protected:
|
||||
|
||||
@@ -96,7 +96,14 @@ nsDataHandler::NewURI(const char *aSpec, nsIURI *aBaseURI,
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDataHandler::NewChannel(nsIURI* url, nsIChannel* *result)
|
||||
nsDataHandler::NewChannel(const char* verb, nsIURI* url,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize,
|
||||
nsIChannel* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
@@ -104,7 +111,8 @@ nsDataHandler::NewChannel(nsIURI* url, nsIChannel* *result)
|
||||
rv = nsDataChannel::Create(nsnull, NS_GET_IID(nsIDataChannel), (void**)&channel);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = channel->Init(url);
|
||||
rv = channel->Init(verb, url, aLoadGroup, notificationCallbacks,
|
||||
loadAttributes, originalURI, bufferSegmentSize, bufferMaxSize);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(channel);
|
||||
return rv;
|
||||
|
||||
@@ -28,7 +28,6 @@ include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = necko
|
||||
LIBRARY_NAME = necko_datetime
|
||||
SHORT_LIBNAME = neckodtm
|
||||
IS_COMPONENT = 1
|
||||
|
||||
CPPSRCS = \
|
||||
|
||||
@@ -44,12 +44,20 @@ nsDateTimeChannel::~nsDateTimeChannel() {
|
||||
NS_IMPL_ISUPPORTS4(nsDateTimeChannel, nsIChannel, nsIRequest, nsIStreamListener, nsIStreamObserver)
|
||||
|
||||
nsresult
|
||||
nsDateTimeChannel::Init(nsIURI* uri)
|
||||
nsDateTimeChannel::Init(const char* verb,
|
||||
nsIURI* uri,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
NS_ASSERTION(uri, "no uri");
|
||||
|
||||
mOriginalURI = originalURI ? originalURI : uri;
|
||||
mUrl = uri;
|
||||
|
||||
rv = mUrl->GetPort(&mPort);
|
||||
@@ -61,6 +69,13 @@ nsDateTimeChannel::Init(nsIURI* uri)
|
||||
|
||||
if (!*(const char *)mHost) return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
rv = SetLoadAttributes(loadAttributes);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = SetLoadGroup(aLoadGroup);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = SetNotificationCallbacks(notificationCallbacks);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -82,35 +97,24 @@ nsDateTimeChannel::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::IsPending(PRBool *result)
|
||||
{
|
||||
NS_NOTREACHED("nsDateTimeChannel::IsPending");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::GetStatus(nsresult *status)
|
||||
nsDateTimeChannel::Cancel(void)
|
||||
{
|
||||
*status = NS_OK;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::Cancel(nsresult status)
|
||||
{
|
||||
NS_NOTREACHED("nsDateTimeChannel::Cancel");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::Suspend(void)
|
||||
{
|
||||
NS_NOTREACHED("nsDateTimeChannel::Suspend");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::Resume(void)
|
||||
{
|
||||
NS_NOTREACHED("nsDateTimeChannel::Resume");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@@ -118,22 +122,15 @@ nsDateTimeChannel::Resume(void)
|
||||
// nsIChannel methods:
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::GetOriginalURI(nsIURI* *aURI)
|
||||
nsDateTimeChannel::GetOriginalURI(nsIURI * *aURI)
|
||||
{
|
||||
*aURI = mOriginalURI ? mOriginalURI : mUrl;
|
||||
*aURI = mOriginalURI;
|
||||
NS_ADDREF(*aURI);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::SetOriginalURI(nsIURI* aURI)
|
||||
{
|
||||
mOriginalURI = aURI;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::GetURI(nsIURI* *aURI)
|
||||
nsDateTimeChannel::GetURI(nsIURI * *aURI)
|
||||
{
|
||||
*aURI = mUrl;
|
||||
NS_IF_ADDREF(*aURI);
|
||||
@@ -141,14 +138,8 @@ nsDateTimeChannel::GetURI(nsIURI* *aURI)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::SetURI(nsIURI* aURI)
|
||||
{
|
||||
mUrl = aURI;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::OpenInputStream(nsIInputStream **_retval)
|
||||
nsDateTimeChannel::OpenInputStream(PRUint32 startPosition, PRInt32 readCount,
|
||||
nsIInputStream **_retval)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
@@ -162,13 +153,12 @@ nsDateTimeChannel::OpenInputStream(nsIInputStream **_retval)
|
||||
rv = channel->SetNotificationCallbacks(mCallbacks);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return channel->OpenInputStream(_retval);
|
||||
return channel->OpenInputStream(startPosition, readCount, _retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::OpenOutputStream(nsIOutputStream **_retval)
|
||||
nsDateTimeChannel::OpenOutputStream(PRUint32 startPosition, nsIOutputStream **_retval)
|
||||
{
|
||||
NS_NOTREACHED("nsDateTimeChannel::OpenOutputStream");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@@ -191,8 +181,9 @@ nsDateTimeChannel::AsyncOpen(nsIStreamObserver *observer, nsISupports* ctxt)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::AsyncRead(nsIStreamListener *aListener,
|
||||
nsISupports *ctxt)
|
||||
nsDateTimeChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
|
||||
nsISupports *ctxt,
|
||||
nsIStreamListener *aListener)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
@@ -208,15 +199,16 @@ nsDateTimeChannel::AsyncRead(nsIStreamListener *aListener,
|
||||
|
||||
mListener = aListener;
|
||||
|
||||
return channel->AsyncRead(this, ctxt);
|
||||
return channel->AsyncRead(startPosition, readCount, ctxt, this);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::AsyncWrite(nsIInputStream *fromStream,
|
||||
nsIStreamObserver *observer,
|
||||
nsISupports *ctxt)
|
||||
PRUint32 startPosition,
|
||||
PRInt32 writeCount,
|
||||
nsISupports *ctxt,
|
||||
nsIStreamObserver *observer)
|
||||
{
|
||||
NS_NOTREACHED("nsDateTimeChannel::AsyncWrite");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@@ -260,90 +252,6 @@ nsDateTimeChannel::GetContentLength(PRInt32 *aContentLength)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::SetContentLength(PRInt32 aContentLength)
|
||||
{
|
||||
NS_NOTREACHED("nsDateTimeChannel::SetContentLength");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::GetTransferOffset(PRUint32 *aTransferOffset)
|
||||
{
|
||||
NS_NOTREACHED("nsDateTimeChannel::GetTransferOffset");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::SetTransferOffset(PRUint32 aTransferOffset)
|
||||
{
|
||||
NS_NOTREACHED("nsDateTimeChannel::SetTransferOffset");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::GetTransferCount(PRInt32 *aTransferCount)
|
||||
{
|
||||
NS_NOTREACHED("nsDateTimeChannel::GetTransferCount");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::SetTransferCount(PRInt32 aTransferCount)
|
||||
{
|
||||
NS_NOTREACHED("nsDateTimeChannel::SetTransferCount");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::GetBufferSegmentSize(PRUint32 *aBufferSegmentSize)
|
||||
{
|
||||
NS_NOTREACHED("nsDateTimeChannel::GetBufferSegmentSize");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::SetBufferSegmentSize(PRUint32 aBufferSegmentSize)
|
||||
{
|
||||
NS_NOTREACHED("nsDateTimeChannel::SetBufferSegmentSize");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::GetBufferMaxSize(PRUint32 *aBufferMaxSize)
|
||||
{
|
||||
NS_NOTREACHED("nsDateTimeChannel::GetBufferMaxSize");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::SetBufferMaxSize(PRUint32 aBufferMaxSize)
|
||||
{
|
||||
NS_NOTREACHED("nsDateTimeChannel::SetBufferMaxSize");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::GetShouldCache(PRBool *aShouldCache)
|
||||
{
|
||||
*aShouldCache = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::GetPipeliningAllowed(PRBool *aPipeliningAllowed)
|
||||
{
|
||||
*aPipeliningAllowed = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::SetPipeliningAllowed(PRBool aPipeliningAllowed)
|
||||
{
|
||||
NS_NOTREACHED("SetPipeliningAllowed");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup)
|
||||
{
|
||||
@@ -395,12 +303,6 @@ nsDateTimeChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotification
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
|
||||
{
|
||||
*aSecurityInfo = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsIStreamObserver methods
|
||||
NS_IMETHODIMP
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#ifndef nsDateTimeChannel_h___
|
||||
#define nsDateTimeChannel_h___
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsString2.h"
|
||||
#include "nsILoadGroup.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
@@ -55,7 +55,14 @@ public:
|
||||
static NS_METHOD
|
||||
Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult);
|
||||
|
||||
nsresult Init(nsIURI* uri);
|
||||
nsresult Init(const char* verb,
|
||||
nsIURI* uri,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize);
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
|
||||
|
||||
@@ -95,7 +95,14 @@ nsDateTimeHandler::NewURI(const char *aSpec, nsIURI *aBaseURI,
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeHandler::NewChannel(nsIURI* url, nsIChannel* *result)
|
||||
nsDateTimeHandler::NewChannel(const char* verb, nsIURI* url,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize,
|
||||
nsIChannel* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
@@ -103,7 +110,8 @@ nsDateTimeHandler::NewChannel(nsIURI* url, nsIChannel* *result)
|
||||
rv = nsDateTimeChannel::Create(nsnull, NS_GET_IID(nsIChannel), (void**)&channel);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = channel->Init(url);
|
||||
rv = channel->Init(verb, url, aLoadGroup, notificationCallbacks,
|
||||
loadAttributes, originalURI, bufferSegmentSize, bufferMaxSize);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(channel);
|
||||
return rv;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user