Revising nsIChannel to allow for overlapped i/o. This consists of three parts:

1. Factoring nsIChannel into a protocol specific part, the nsIChannel, and a socket specific, the nsITransport.
2. Derive the nsIChannel from a nsIRequest.
2. Changes the notification system from necko and the URILoader to pass the nsIRequest interface instead of nsIChannel interface.

This goal stems from wanting to be able to have active AsyncRead and AsyncWrite operations on nsSocketTransport.
This is desired because it would greatly simplify the task of maintaining persistent/reusable socket connections
for FTP, HTTP, and Imap (and potentially other protocols).  The problem with the existing nsIChannel interface is
that it does not allow one to selectively suspend just one of the read or write operations while keeping the other active.

The full details of the change on written up in the netlib newsgroup.

r=darin@netscape.com
sr=rpotts@netscape.com
This commit is contained in:
dougt@netscape.com
2001-02-10 00:16:26 +00:00
parent b762af79b0
commit a70fce6f87
218 changed files with 5596 additions and 6769 deletions

View File

@@ -116,27 +116,25 @@ public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
// nsIRequest // nsIRequest
NS_IMETHOD GetName(PRUnichar* *result) { NS_IMETHOD GetName(PRUnichar* *result) { return NS_ERROR_NOT_IMPLEMENTED; }
NS_NOTREACHED("nsCachedChromeChannel::GetName");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHOD IsPending(PRBool *_retval) { *_retval = PR_TRUE; return NS_OK; } NS_IMETHOD IsPending(PRBool *_retval) { *_retval = PR_TRUE; return NS_OK; }
NS_IMETHOD GetStatus(nsresult *status) { *status = mStatus; return NS_OK; } NS_IMETHOD GetStatus(nsresult *status) { *status = mStatus; return NS_OK; }
NS_IMETHOD Cancel(nsresult status) { mStatus = status; return NS_OK; } NS_IMETHOD Cancel(nsresult status) { mStatus = status; return NS_OK; }
NS_IMETHOD Suspend(void) { return NS_OK; } NS_IMETHOD Suspend(void) { return NS_OK; }
NS_IMETHOD Resume(void) { return NS_OK; } NS_IMETHOD Resume(void) { return NS_OK; }
// nsIChannel // nsIChannel
NS_DECL_NSICHANNEL NS_DECL_NSICHANNEL
}; };
#ifdef PR_LOGGING #ifdef PR_LOGGING
PRLogModuleInfo* nsCachedChromeChannel::gLog; PRLogModuleInfo* nsCachedChromeChannel::gLog;
#endif #endif
NS_IMPL_ADDREF(nsCachedChromeChannel); NS_IMPL_ISUPPORTS2(nsCachedChromeChannel,
NS_IMPL_RELEASE(nsCachedChromeChannel); nsIChannel,
NS_IMPL_QUERY_INTERFACE2(nsCachedChromeChannel, nsIRequest, nsIChannel); nsIRequest);
nsresult nsresult
nsCachedChromeChannel::Create(nsIURI* aURI, nsIChannel** aResult) nsCachedChromeChannel::Create(nsIURI* aURI, nsIChannel** aResult)
@@ -211,7 +209,7 @@ nsCachedChromeChannel::SetURI(nsIURI* aURI)
} }
NS_IMETHODIMP NS_IMETHODIMP
nsCachedChromeChannel::OpenInputStream(nsIInputStream **_retval) nsCachedChromeChannel::Open(nsIInputStream **_retval)
{ {
// NS_NOTREACHED("don't do that"); // NS_NOTREACHED("don't do that");
*_retval = nsnull; *_retval = nsnull;
@@ -219,15 +217,7 @@ nsCachedChromeChannel::OpenInputStream(nsIInputStream **_retval)
} }
NS_IMETHODIMP NS_IMETHODIMP
nsCachedChromeChannel::OpenOutputStream(nsIOutputStream **_retval) nsCachedChromeChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctxt)
{
NS_NOTREACHED("don't do that");
*_retval = nsnull;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsCachedChromeChannel::AsyncRead(nsIStreamListener *listener, nsISupports *ctxt)
{ {
if (listener) { if (listener) {
nsresult rv; nsresult rv;
@@ -237,7 +227,7 @@ nsCachedChromeChannel::AsyncRead(nsIStreamListener *listener, nsISupports *ctxt)
("nsCachedChromeChannel[%p]: adding self to load group %p", ("nsCachedChromeChannel[%p]: adding self to load group %p",
this, mLoadGroup.get())); this, mLoadGroup.get()));
rv = mLoadGroup->AddChannel(this, nsnull); rv = mLoadGroup->AddRequest(this, nsnull);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
} }
@@ -257,7 +247,7 @@ nsCachedChromeChannel::AsyncRead(nsIStreamListener *listener, nsISupports *ctxt)
("nsCachedChromeChannel[%p]: removing self from load group %p", ("nsCachedChromeChannel[%p]: removing self from load group %p",
this, mLoadGroup.get())); this, mLoadGroup.get()));
(void) mLoadGroup->RemoveChannel(this, nsnull, nsnull, nsnull); (void) mLoadGroup->RemoveRequest(this, nsnull, nsnull, nsnull);
} }
return rv; return rv;
@@ -271,10 +261,9 @@ nsCachedChromeChannel::AsyncRead(nsIStreamListener *listener, nsISupports *ctxt)
} }
NS_IMETHODIMP NS_IMETHODIMP
nsCachedChromeChannel::AsyncWrite(nsIStreamProvider *provider, nsISupports *ctxt) nsCachedChromeChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
{ {
NS_NOTREACHED("don't do that"); return NS_ERROR_NOT_IMPLEMENTED;
return NS_ERROR_FAILURE;
} }
NS_IMETHODIMP NS_IMETHODIMP
@@ -291,113 +280,6 @@ nsCachedChromeChannel::SetLoadAttributes(nsLoadFlags aLoadAttributes)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
nsCachedChromeChannel::GetContentType(char * *aContentType)
{
*aContentType = nsXPIDLCString::Copy("text/cached-xul");
return *aContentType ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
NS_IMETHODIMP
nsCachedChromeChannel::SetContentType(const char *aContentType)
{
// Do not allow the content-type to be changed.
NS_NOTREACHED("don't do that");
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsCachedChromeChannel::GetContentLength(PRInt32 *aContentLength)
{
NS_NOTREACHED("don't do that");
*aContentLength = 0;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsCachedChromeChannel::SetContentLength(PRInt32 aContentLength)
{
NS_NOTREACHED("nsCachedChromeChannel::SetContentLength");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsCachedChromeChannel::GetTransferOffset(PRUint32 *aTransferOffset)
{
NS_NOTREACHED("nsCachedChromeChannel::GetTransferOffset");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsCachedChromeChannel::SetTransferOffset(PRUint32 aTransferOffset)
{
NS_NOTREACHED("nsCachedChromeChannel::SetTransferOffset");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsCachedChromeChannel::GetTransferCount(PRInt32 *aTransferCount)
{
NS_NOTREACHED("nsCachedChromeChannel::GetTransferCount");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsCachedChromeChannel::SetTransferCount(PRInt32 aTransferCount)
{
NS_NOTREACHED("nsCachedChromeChannel::SetTransferCount");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsCachedChromeChannel::GetBufferSegmentSize(PRUint32 *aBufferSegmentSize)
{
NS_NOTREACHED("nsCachedChromeChannel::GetBufferSegmentSize");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsCachedChromeChannel::SetBufferSegmentSize(PRUint32 aBufferSegmentSize)
{
NS_NOTREACHED("nsCachedChromeChannel::SetBufferSegmentSize");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsCachedChromeChannel::GetBufferMaxSize(PRUint32 *aBufferMaxSize)
{
NS_NOTREACHED("nsCachedChromeChannel::GetBufferMaxSize");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsCachedChromeChannel::SetBufferMaxSize(PRUint32 aBufferMaxSize)
{
NS_NOTREACHED("nsCachedChromeChannel::SetBufferMaxSize");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsCachedChromeChannel::GetLocalFile(nsIFile* *file)
{
*file = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsCachedChromeChannel::GetPipeliningAllowed(PRBool *aPipeliningAllowed)
{
*aPipeliningAllowed = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
nsCachedChromeChannel::SetPipeliningAllowed(PRBool aPipeliningAllowed)
{
NS_NOTREACHED("SetPipeliningAllowed");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP NS_IMETHODIMP
nsCachedChromeChannel::GetOwner(nsISupports * *aOwner) nsCachedChromeChannel::GetOwner(nsISupports * *aOwner)
{ {
@@ -441,12 +323,34 @@ nsCachedChromeChannel::SetNotificationCallbacks(nsIInterfaceRequestor * aNotific
return NS_OK; // ignored return NS_OK; // ignored
} }
NS_IMETHODIMP
nsCachedChromeChannel::GetContentType(char * *aContentType)
{
*aContentType = nsXPIDLCString::Copy("text/cached-xul");
return *aContentType ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
NS_IMETHODIMP NS_IMETHODIMP
nsCachedChromeChannel::GetSecurityInfo(nsISupports * *aSecurityInfo) nsCachedChromeChannel::SetContentType(const char *aContentType)
{ {
*aSecurityInfo = nsnull; // Do not allow the content-type to be changed.
return NS_OK; NS_NOTREACHED("don't do that");
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsCachedChromeChannel::GetContentLength(PRInt32 *aContentLength)
{
NS_NOTREACHED("don't do that");
*aContentLength = 0;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsCachedChromeChannel::SetContentLength(PRInt32 aContentLength)
{
NS_NOTREACHED("nsCachedChromeChannel::SetContentLength");
return NS_ERROR_NOT_IMPLEMENTED;
} }
nsresult nsresult
@@ -523,12 +427,14 @@ nsCachedChromeChannel::HandleStopLoadEvent(PLEvent* aEvent)
// remove it from the load group. // remove it from the load group.
LoadEvent* event = NS_REINTERPRET_CAST(LoadEvent*, aEvent); LoadEvent* event = NS_REINTERPRET_CAST(LoadEvent*, aEvent);
nsCachedChromeChannel* channel = event->mChannel; nsCachedChromeChannel* channel = event->mChannel;
nsIRequest* request = NS_REINTERPRET_CAST(nsIRequest*, channel);
PR_LOG(gLog, PR_LOG_DEBUG, PR_LOG(gLog, PR_LOG_DEBUG,
("nsCachedChromeChannel[%p]: firing OnStopRequest for %p", ("nsCachedChromeChannel[%p]: firing OnStopRequest for %p",
channel, channel->mListener.get())); channel, channel->mListener.get()));
(void) channel->mListener->OnStopRequest(channel, channel->mContext, (void) channel->mListener->OnStopRequest(request, channel->mContext,
channel->mStatus, nsnull); channel->mStatus, nsnull);
if (channel->mLoadGroup) { if (channel->mLoadGroup) {
@@ -536,7 +442,7 @@ nsCachedChromeChannel::HandleStopLoadEvent(PLEvent* aEvent)
("nsCachedChromeChannel[%p]: removing self from load group %p", ("nsCachedChromeChannel[%p]: removing self from load group %p",
channel, channel->mLoadGroup.get())); channel, channel->mLoadGroup.get()));
(void) channel->mLoadGroup->RemoveChannel(channel, nsnull, nsnull, nsnull); (void) channel->mLoadGroup->RemoveRequest(request, nsnull, nsnull, nsnull);
} }
channel->mListener = nsnull; channel->mListener = nsnull;

View File

@@ -298,7 +298,7 @@ nsSyncLoader::LoadDocument(nsIURI* documentURI, nsIDOMDocument **_retval)
} }
// Start reading from the channel // Start reading from the channel
rv = channel->AsyncRead(listener, nsnull); rv = channel->AsyncOpen(listener, nsnull);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
if (modalEventQueue) { if (modalEventQueue) {

View File

@@ -4715,8 +4715,12 @@ HTMLContentSink::OnStreamComplete(nsIStreamLoader* aLoader,
nsCOMPtr<nsIHTTPChannel> httpChannel; nsCOMPtr<nsIHTTPChannel> httpChannel;
nsCOMPtr<nsIChannel> channel; nsCOMPtr<nsIChannel> channel;
rv = aLoader->GetChannel(getter_AddRefs(channel)); nsCOMPtr<nsIRequest> request;
NS_ASSERTION(channel, "StreamLoader's channel went away prematurely"); rv = aLoader->GetRequest(getter_AddRefs(request));
NS_ASSERTION(request, "StreamLoader's request went away prematurely");
if (NS_FAILED(rv)) return rv;
channel = do_QueryInterface(request);
if (channel) { if (channel) {
httpChannel = do_QueryInterface(channel); httpChannel = do_QueryInterface(channel);

View File

@@ -585,7 +585,8 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
nsCOMPtr<nsIFile> file; nsCOMPtr<nsIFile> file;
rv = fileChannel->GetFile(getter_AddRefs(file)); rv = fileChannel->GetFile(getter_AddRefs(file));
if (NS_FAILED(rv)) { return rv; } if (NS_SUCCEEDED(rv))
{
// if we failed to get a last modification date, then we don't want to necessarily // if we failed to get a last modification date, then we don't want to necessarily
// fail to create a document for this file. Just don't set the last modified date on it... // fail to create a document for this file. Just don't set the last modified date on it...
rv = file->GetLastModificationDate(&modDate); rv = file->GetLastModificationDate(&modDate);
@@ -603,16 +604,17 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
// non-y2k with msvc; '%#c' requests that a full year be used in the // non-y2k with msvc; '%#c' requests that a full year be used in the
// result string. Other OSes just use "%c". // result string. Other OSes just use "%c".
PR_FormatTime(buf, sizeof buf, PR_FormatTime(buf, sizeof buf,
#if defined(XP_PC) && !defined(XP_OS2) #if defined(XP_PC) && !defined(XP_OS2)
"%#c", "%#c",
#else #else
"%c", "%c",
#endif #endif
&prtime); &prtime);
lastModified.AssignWithConversion(buf); lastModified.AssignWithConversion(buf);
SetLastModified(lastModified); SetLastModified(lastModified);
} }
} }
}
static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID); static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);

View File

@@ -121,10 +121,14 @@ ImageListener::~ImageListener()
NS_IMPL_THREADSAFE_ISUPPORTS(ImageListener, NS_GET_IID(nsIStreamListener)) NS_IMPL_THREADSAFE_ISUPPORTS(ImageListener, NS_GET_IID(nsIStreamListener))
NS_IMETHODIMP NS_IMETHODIMP
ImageListener::OnStartRequest(nsIChannel* channel, nsISupports *ctxt) ImageListener::OnStartRequest(nsIRequest* request, nsISupports *ctxt)
{ {
nsresult rv; nsresult rv;
nsIURI* uri; nsIURI* uri;
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
if (!channel) return NS_ERROR_NULL_POINTER;
rv = channel->GetURI(&uri); rv = channel->GetURI(&uri);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
@@ -133,11 +137,11 @@ ImageListener::OnStartRequest(nsIChannel* channel, nsISupports *ctxt)
if (nsnull == mNextStream) { if (nsnull == mNextStream) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
return mNextStream->OnStartRequest(channel, ctxt); return mNextStream->OnStartRequest(request, ctxt);
} }
NS_IMETHODIMP NS_IMETHODIMP
ImageListener::OnStopRequest(nsIChannel* channel, nsISupports *ctxt, ImageListener::OnStopRequest(nsIRequest* request, nsISupports *ctxt,
nsresult status, const PRUnichar *errorMsg) nsresult status, const PRUnichar *errorMsg)
{ {
if(mDocument){ if(mDocument){
@@ -147,17 +151,17 @@ ImageListener::OnStopRequest(nsIChannel* channel, nsISupports *ctxt,
if (nsnull == mNextStream) { if (nsnull == mNextStream) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
return mNextStream->OnStopRequest(channel, ctxt, status, errorMsg); return mNextStream->OnStopRequest(request, ctxt, status, errorMsg);
} }
NS_IMETHODIMP NS_IMETHODIMP
ImageListener::OnDataAvailable(nsIChannel* channel, nsISupports *ctxt, ImageListener::OnDataAvailable(nsIRequest* request, nsISupports *ctxt,
nsIInputStream *inStr, PRUint32 sourceOffset, PRUint32 count) nsIInputStream *inStr, PRUint32 sourceOffset, PRUint32 count)
{ {
if (nsnull == mNextStream) { if (nsnull == mNextStream) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
return mNextStream->OnDataAvailable(channel, ctxt, inStr, sourceOffset, count); return mNextStream->OnDataAvailable(request, ctxt, inStr, sourceOffset, count);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@@ -260,37 +260,36 @@ nsXBLStreamListener::~nsXBLStreamListener()
} }
} }
/* void onDataAvailable (in nsIChannel channel, in nsISupports ctxt, in nsIInputStream inStr, in unsigned long sourceOffset, in unsigned long count); */
NS_IMETHODIMP NS_IMETHODIMP
nsXBLStreamListener::OnDataAvailable(nsIChannel* aChannel, nsISupports* aCtxt, nsIInputStream* aInStr, nsXBLStreamListener::OnDataAvailable(nsIRequest *request, nsISupports* aCtxt, nsIInputStream* aInStr,
PRUint32 aSourceOffset, PRUint32 aCount) PRUint32 aSourceOffset, PRUint32 aCount)
{ {
if (mInner) if (mInner)
return mInner->OnDataAvailable(aChannel, aCtxt, aInStr, aSourceOffset, aCount); return mInner->OnDataAvailable(request, aCtxt, aInStr, aSourceOffset, aCount);
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
/* void onStartRequest (in nsIChannel channel, in nsISupports ctxt); */
NS_IMETHODIMP NS_IMETHODIMP
nsXBLStreamListener::OnStartRequest(nsIChannel* aChannel, nsISupports* aCtxt) nsXBLStreamListener::OnStartRequest(nsIRequest* request, nsISupports* aCtxt)
{ {
if (mInner) if (mInner)
return mInner->OnStartRequest(aChannel, aCtxt); return mInner->OnStartRequest(request, aCtxt);
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
/* void onStopRequest (in nsIChannel channel, in nsISupports ctxt, in nsresult status, in wstring statusArg); */
NS_IMETHODIMP NS_IMETHODIMP
nsXBLStreamListener::OnStopRequest(nsIChannel* aChannel, nsISupports* aCtxt, nsresult aStatus, const PRUnichar* aStatusArg) nsXBLStreamListener::OnStopRequest(nsIRequest* request, nsISupports* aCtxt, nsresult aStatus, const PRUnichar* aStatusArg)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
if (mInner) { if (mInner) {
rv = mInner->OnStopRequest(aChannel, aCtxt, aStatus, aStatusArg); rv = mInner->OnStopRequest(request, aCtxt, aStatus, aStatusArg);
} }
if (NS_FAILED(rv) || NS_FAILED(aStatus)) if (NS_FAILED(rv) || NS_FAILED(aStatus))
{ {
nsCOMPtr<nsIChannel> aChannel = do_QueryInterface(request);
if (aChannel) if (aChannel)
{ {
nsCOMPtr<nsIURI> channelURI; nsCOMPtr<nsIURI> channelURI;
@@ -1191,7 +1190,7 @@ nsXBLService::FetchBindingDocument(nsIContent* aBoundElement, nsIDocument* aBoun
nsCOMPtr<nsILoadGroup> loadGroup; nsCOMPtr<nsILoadGroup> loadGroup;
if (aBoundDocument) if (aBoundDocument)
aBoundDocument->GetDocumentLoadGroup(getter_AddRefs(loadGroup)); aBoundDocument->GetDocumentLoadGroup(getter_AddRefs(loadGroup));
nsCOMPtr<nsIRequest> request;
nsCOMPtr<nsIChannel> channel; nsCOMPtr<nsIChannel> channel;
rv = NS_OpenURI(getter_AddRefs(channel), aURI, nsnull, loadGroup); rv = NS_OpenURI(getter_AddRefs(channel), aURI, nsnull, loadGroup);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
@@ -1233,18 +1232,22 @@ nsXBLService::FetchBindingDocument(nsIContent* aBoundElement, nsIDocument* aBoun
xblListener->AddRequest(req); xblListener->AddRequest(req);
// Now kick off the async read. // Now kick off the async read.
channel->AsyncRead(xblListener, nsnull); channel->AsyncOpen(xblListener, nsnull);
return NS_OK; return NS_OK;
} }
// Now do a blocking synchronous parse of the file. // Now do a blocking synchronous parse of the file.
nsCOMPtr<nsIInputStream> in; nsCOMPtr<nsIInputStream> in;
PRUint32 sourceOffset = 0; PRUint32 sourceOffset = 0;
rv = channel->OpenInputStream(getter_AddRefs(in)); rv = channel->Open(getter_AddRefs(in));
// If we couldn't open the channel, then just return. // If we couldn't open the channel, then just return.
if (NS_FAILED(rv)) return NS_OK; if (NS_FAILED(rv)) return NS_OK;
request = do_QueryInterface(channel);
NS_ASSERTION(request != nsnull, "no request info");
NS_ASSERTION(in != nsnull, "no input stream"); NS_ASSERTION(in != nsnull, "no input stream");
if (! in) return NS_ERROR_FAILURE; if (! in) return NS_ERROR_FAILURE;
@@ -1253,7 +1256,7 @@ nsXBLService::FetchBindingDocument(nsIContent* aBoundElement, nsIDocument* aBoun
if (! proxy) if (! proxy)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
listener->OnStartRequest(channel, nsnull); listener->OnStartRequest(request, nsnull);
while (PR_TRUE) { while (PR_TRUE) {
char buf[1024]; char buf[1024];
PRUint32 readCount; PRUint32 readCount;
@@ -1266,12 +1269,12 @@ nsXBLService::FetchBindingDocument(nsIContent* aBoundElement, nsIDocument* aBoun
proxy->SetBuffer(buf, readCount); proxy->SetBuffer(buf, readCount);
rv = listener->OnDataAvailable(channel, nsnull, proxy, sourceOffset, readCount); rv = listener->OnDataAvailable(request, nsnull, proxy, sourceOffset, readCount);
sourceOffset += readCount; sourceOffset += readCount;
if (NS_FAILED(rv)) if (NS_FAILED(rv))
break; break;
} }
listener->OnStopRequest(channel, nsnull, NS_OK, nsnull); listener->OnStopRequest(request, nsnull, NS_OK, nsnull);
// don't leak proxy! // don't leak proxy!
proxy->Close(); proxy->Close();

View File

@@ -1669,7 +1669,11 @@ nsXMLContentSink::OnStreamComplete(nsIStreamLoader* aLoader,
if (NS_OK == aStatus) { if (NS_OK == aStatus) {
{ // scope in block so nsCOMPtr released at one point { // scope in block so nsCOMPtr released at one point
nsCOMPtr<nsIChannel> channel; nsCOMPtr<nsIChannel> channel;
aLoader->GetChannel(getter_AddRefs(channel)); nsCOMPtr<nsIRequest> request;
aLoader->GetRequest(getter_AddRefs(request));
if (request)
channel = do_QueryInterface(request);
nsCOMPtr<nsIURI> url; nsCOMPtr<nsIURI> url;
if (channel) { if (channel) {
channel->GetURI(getter_AddRefs(url)); channel->GetURI(getter_AddRefs(url));

View File

@@ -74,6 +74,11 @@
#include "nsIPrincipal.h" #include "nsIPrincipal.h"
#include "nsIAggregatePrincipal.h" #include "nsIAggregatePrincipal.h"
#include "nsCExternalHandlerService.h"
#include "nsIMIMEService.h"
#include "nsNetUtil.h"
#include "nsMimeTypes.h"
// XXX The XML world depends on the html atoms // XXX The XML world depends on the html atoms
#include "nsHTMLAtoms.h" #include "nsHTMLAtoms.h"
@@ -351,7 +356,7 @@ nsXMLDocument::Load(const nsAReadableString& aUrl)
} }
// Start an asynchronous read of the XML document // Start an asynchronous read of the XML document
rv = channel->AsyncRead(listener, nsnull); rv = channel->AsyncOpen(listener, nsnull);
return rv; return rv;
} }
@@ -381,7 +386,9 @@ nsXMLDocument::StartDocumentLoad(const char* aCommand,
rv = aChannel->GetURI(getter_AddRefs(aUrl)); rv = aChannel->GetURI(getter_AddRefs(aUrl));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
rv = aChannel->GetContentType(&aContentType); nsCOMPtr<nsIMIMEService> MIMEService (do_GetService(NS_MIMESERVICE_CONTRACTID, &rv));
if (NS_FAILED(rv)) return rv;
rv = MIMEService->GetTypeFromURI(aUrl, &aContentType);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
if ( 0 == PL_strcmp(aContentType, "text/html")) { if ( 0 == PL_strcmp(aContentType, "text/html")) {

View File

@@ -52,7 +52,7 @@ public:
NS_IMETHOD GetContentType(nsAWritableString& aContentType) const; NS_IMETHOD GetContentType(nsAWritableString& aContentType) const;
NS_IMETHOD StartDocumentLoad(const char* aCommand, NS_IMETHOD StartDocumentLoad(const char* aCommand,
nsIChannel* aChannel, nsIChannel* channel,
nsILoadGroup* aLoadGroup, nsILoadGroup* aLoadGroup,
nsISupports* aContainer, nsISupports* aContainer,
nsIStreamListener **aDocListener, nsIStreamListener **aDocListener,

View File

@@ -127,6 +127,10 @@
#include "nsIDOMDocumentType.h" #include "nsIDOMDocumentType.h"
#include "nsIXBLService.h" #include "nsIXBLService.h"
#include "nsReadableUtils.h" #include "nsReadableUtils.h"
#include "nsCExternalHandlerService.h"
#include "nsIMIMEService.h"
#include "nsNetUtil.h"
#include "nsMimeTypes.h"
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@@ -313,19 +317,19 @@ NS_IMPL_ISUPPORTS1(nsProxyLoadStream, nsIInputStream);
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// //
// PlaceholderChannel // PlaceholderRequest
// //
// This is a dummy channel implementation that we add to the load // This is a dummy request implementation that we add to the load
// group. It ensures that EndDocumentLoad() in the docshell doesn't // group. It ensures that EndDocumentLoad() in the docshell doesn't
// fire before we've finished building the complete document content // fire before we've finished building the complete document content
// model. // model.
// //
class PlaceholderChannel : public nsIChannel class PlaceHolderRequest : public nsIChannel
{ {
protected: protected:
PlaceholderChannel(); PlaceHolderRequest();
virtual ~PlaceholderChannel(); virtual ~PlaceHolderRequest();
static PRInt32 gRefCnt; static PRInt32 gRefCnt;
static nsIURI* gURI; static nsIURI* gURI;
@@ -334,13 +338,12 @@ protected:
public: public:
static nsresult static nsresult
Create(nsIChannel** aResult); Create(nsIRequest** aResult);
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
// nsIRequest // nsIRequest
NS_IMETHOD GetName(PRUnichar* *result) { NS_IMETHOD GetName(PRUnichar* *result) {
NS_NOTREACHED("PlaceholderChannel::GetName");
return NS_ERROR_NOT_IMPLEMENTED; return NS_ERROR_NOT_IMPLEMENTED;
} }
NS_IMETHOD IsPending(PRBool *_retval) { *_retval = PR_TRUE; return NS_OK; } NS_IMETHOD IsPending(PRBool *_retval) { *_retval = PR_TRUE; return NS_OK; }
@@ -354,58 +357,45 @@ public:
NS_IMETHOD SetOriginalURI(nsIURI* aOriginalURI) { gURI = aOriginalURI; NS_ADDREF(gURI); return NS_OK; } NS_IMETHOD SetOriginalURI(nsIURI* aOriginalURI) { gURI = aOriginalURI; NS_ADDREF(gURI); return NS_OK; }
NS_IMETHOD GetURI(nsIURI* *aURI) { *aURI = gURI; NS_ADDREF(*aURI); return NS_OK; } NS_IMETHOD GetURI(nsIURI* *aURI) { *aURI = gURI; NS_ADDREF(*aURI); return NS_OK; }
NS_IMETHOD SetURI(nsIURI* aURI) { gURI = aURI; NS_ADDREF(gURI); return NS_OK; } NS_IMETHOD SetURI(nsIURI* aURI) { gURI = aURI; NS_ADDREF(gURI); return NS_OK; }
NS_IMETHOD OpenInputStream(nsIInputStream **_retval) { *_retval = nsnull; return NS_OK; } NS_IMETHOD Open(nsIInputStream **_retval) { *_retval = nsnull; return NS_OK; }
NS_IMETHOD OpenOutputStream(nsIOutputStream **_retval) { *_retval = nsnull; return NS_OK; } NS_IMETHOD AsyncOpen(nsIStreamListener *listener, nsISupports *ctxt) { return NS_OK; }
NS_IMETHOD AsyncOpen(nsIStreamObserver *observer, nsISupports *ctxt) { return NS_OK; }
NS_IMETHOD AsyncRead(nsIStreamListener *listener, nsISupports *ctxt) { return NS_OK; }
NS_IMETHOD AsyncWrite(nsIStreamProvider *provider, nsISupports *ctxt) { return NS_OK; }
NS_IMETHOD GetLoadAttributes(nsLoadFlags *aLoadAttributes) { *aLoadAttributes = nsIChannel::LOAD_NORMAL; return NS_OK; } NS_IMETHOD GetLoadAttributes(nsLoadFlags *aLoadAttributes) { *aLoadAttributes = nsIChannel::LOAD_NORMAL; return NS_OK; }
NS_IMETHOD SetLoadAttributes(nsLoadFlags aLoadAttributes) { return NS_OK; } NS_IMETHOD SetLoadAttributes(nsLoadFlags aLoadAttributes) { return NS_OK; }
NS_IMETHOD GetContentType(char * *aContentType) { *aContentType = nsnull; return NS_OK; }
NS_IMETHOD SetContentType(const char *aContentType) { return NS_OK; }
NS_IMETHOD GetContentLength(PRInt32 *aContentLength) { *aContentLength = 0; return NS_OK; }
NS_IMETHOD SetContentLength(PRInt32 aContentLength) { NS_NOTREACHED("SetContentLength"); NS_NOTREACHED("NOTREACHED"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD GetTransferOffset(PRUint32 *aTransferOffset) { NS_NOTREACHED("GetTransferOffset"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD SetTransferOffset(PRUint32 aTransferOffset) { NS_NOTREACHED("SetTransferOffset"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD GetTransferCount(PRInt32 *aTransferCount) { NS_NOTREACHED("GetTransferCount"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD SetTransferCount(PRInt32 aTransferCount) { NS_NOTREACHED("SetTransferCount"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD GetBufferSegmentSize(PRUint32 *aBufferSegmentSize) { NS_NOTREACHED("GetBufferSegmentSize"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD SetBufferSegmentSize(PRUint32 aBufferSegmentSize) { NS_NOTREACHED("SetBufferSegmentSize"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD GetBufferMaxSize(PRUint32 *aBufferMaxSize) { NS_NOTREACHED("GetBufferMaxSize"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD SetBufferMaxSize(PRUint32 aBufferMaxSize) { NS_NOTREACHED("SetBufferMaxSize"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD GetLocalFile(nsIFile* *result) { NS_NOTREACHED("GetLocalFile"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD GetPipeliningAllowed(PRBool *aPipeliningAllowed) { *aPipeliningAllowed = PR_FALSE; return NS_OK; }
NS_IMETHOD SetPipeliningAllowed(PRBool aPipeliningAllowed) { NS_NOTREACHED("SetPipeliningAllowed"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD GetOwner(nsISupports * *aOwner) { *aOwner = nsnull; return NS_OK; } NS_IMETHOD GetOwner(nsISupports * *aOwner) { *aOwner = nsnull; return NS_OK; }
NS_IMETHOD SetOwner(nsISupports * aOwner) { return NS_OK; } NS_IMETHOD SetOwner(nsISupports * aOwner) { return NS_OK; }
NS_IMETHOD GetLoadGroup(nsILoadGroup * *aLoadGroup) { *aLoadGroup = mLoadGroup; NS_IF_ADDREF(*aLoadGroup); return NS_OK; } NS_IMETHOD GetLoadGroup(nsILoadGroup * *aLoadGroup) { *aLoadGroup = mLoadGroup; NS_IF_ADDREF(*aLoadGroup); return NS_OK; }
NS_IMETHOD SetLoadGroup(nsILoadGroup * aLoadGroup) { mLoadGroup = aLoadGroup; return NS_OK; } NS_IMETHOD SetLoadGroup(nsILoadGroup * aLoadGroup) { mLoadGroup = aLoadGroup; return NS_OK; }
NS_IMETHOD GetNotificationCallbacks(nsIInterfaceRequestor * *aNotificationCallbacks) { *aNotificationCallbacks = nsnull; return NS_OK; } NS_IMETHOD GetNotificationCallbacks(nsIInterfaceRequestor * *aNotificationCallbacks) { *aNotificationCallbacks = nsnull; return NS_OK; }
NS_IMETHOD SetNotificationCallbacks(nsIInterfaceRequestor * aNotificationCallbacks) { return NS_OK; } NS_IMETHOD SetNotificationCallbacks(nsIInterfaceRequestor * aNotificationCallbacks) { return NS_OK; }
NS_IMETHOD GetSecurityInfo(nsISupports **info) {*info = nsnull; return NS_OK;} NS_IMETHOD GetSecurityInfo(nsISupports * *aSecurityInfo) { *aSecurityInfo = nsnull; return NS_OK; }
NS_IMETHOD GetContentType(char * *aContentType) { *aContentType = nsnull; return NS_OK; }
NS_IMETHOD SetContentType(const char * aContentType) { return NS_OK; }
NS_IMETHOD GetContentLength(PRInt32 *aContentLength) { return NS_OK; }
NS_IMETHOD SetContentLength(PRInt32 aContentLength) { return NS_OK; }
}; };
PRInt32 PlaceholderChannel::gRefCnt; PRInt32 PlaceHolderRequest::gRefCnt;
nsIURI* PlaceholderChannel::gURI; nsIURI* PlaceHolderRequest::gURI;
NS_IMPL_ADDREF(PlaceholderChannel); NS_IMPL_ADDREF(PlaceHolderRequest);
NS_IMPL_RELEASE(PlaceholderChannel); NS_IMPL_RELEASE(PlaceHolderRequest);
NS_IMPL_QUERY_INTERFACE2(PlaceholderChannel, nsIRequest, nsIChannel); NS_IMPL_QUERY_INTERFACE2(PlaceHolderRequest, nsIRequest, nsIChannel);
nsresult nsresult
PlaceholderChannel::Create(nsIChannel** aResult) PlaceHolderRequest::Create(nsIRequest** aResult)
{ {
PlaceholderChannel* channel = new PlaceholderChannel(); PlaceHolderRequest* request = new PlaceHolderRequest();
if (! channel) if (! request)
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
*aResult = channel; *aResult = request;
NS_ADDREF(*aResult); NS_ADDREF(*aResult);
return NS_OK; return NS_OK;
} }
PlaceholderChannel::PlaceholderChannel() PlaceHolderRequest::PlaceHolderRequest()
{ {
NS_INIT_REFCNT(); NS_INIT_REFCNT();
@@ -417,7 +407,7 @@ PlaceholderChannel::PlaceholderChannel()
} }
PlaceholderChannel::~PlaceholderChannel() PlaceHolderRequest::~PlaceHolderRequest()
{ {
if (--gRefCnt == 0) { if (--gRefCnt == 0) {
NS_IF_RELEASE(gURI); NS_IF_RELEASE(gURI);
@@ -773,8 +763,9 @@ nsXULDocument::StartDocumentLoad(const char* aCommand,
// certain hacks (cough, the directory viewer) need to be able to // certain hacks (cough, the directory viewer) need to be able to
// StartDocumentLoad() before the channel's content type has been // StartDocumentLoad() before the channel's content type has been
// detected. // detected.
nsXPIDLCString contentType; nsXPIDLCString contentType;
(void) aChannel->GetContentType(getter_Copies(contentType)); aChannel->GetContentType(getter_Copies(contentType));
if (contentType && PL_strcmp(contentType, "text/cached-xul") == 0) { if (contentType && PL_strcmp(contentType, "text/cached-xul") == 0) {
// Look in the chrome cache: we've got this puppy loaded // Look in the chrome cache: we've got this puppy loaded
@@ -4943,16 +4934,16 @@ nsXULDocument::PrepareToWalk()
// Add a dummy channel to the load group as a placeholder for the document // Add a dummy channel to the load group as a placeholder for the document
// load // load
rv = PlaceholderChannel::Create(getter_AddRefs(mPlaceholderChannel)); rv = PlaceHolderRequest::Create(getter_AddRefs(mPlaceHolderRequest));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsILoadGroup> group = do_QueryReferent(mDocumentLoadGroup); nsCOMPtr<nsILoadGroup> group = do_QueryReferent(mDocumentLoadGroup);
if (group) { if (group) {
rv = mPlaceholderChannel->SetLoadGroup(group); nsCOMPtr<nsIChannel> channel = do_QueryInterface(mPlaceHolderRequest);
rv = channel->SetLoadGroup(group);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
rv = group->AddRequest(mPlaceHolderRequest, nsnull);
rv = group->AddChannel(mPlaceholderChannel, nsnull);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
} }
} }
@@ -5296,10 +5287,10 @@ nsXULDocument::ResumeWalk()
// docshell, and run the onload handlers, etc. // docshell, and run the onload handlers, etc.
nsCOMPtr<nsILoadGroup> group = do_QueryReferent(mDocumentLoadGroup); nsCOMPtr<nsILoadGroup> group = do_QueryReferent(mDocumentLoadGroup);
if (group) { if (group) {
rv = group->RemoveChannel(mPlaceholderChannel, nsnull, NS_OK, nsnull); rv = group->RemoveRequest(mPlaceHolderRequest, nsnull, NS_OK, nsnull);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
mPlaceholderChannel = nsnull; mPlaceHolderRequest = nsnull;
} }
return rv; return rv;
} }
@@ -5361,8 +5352,11 @@ nsXULDocument::OnStreamComplete(nsIStreamLoader* aLoader,
{ {
if (aLoader) if (aLoader)
{ {
nsCOMPtr<nsIRequest> request;
nsCOMPtr<nsIChannel> channel; nsCOMPtr<nsIChannel> channel;
aLoader->GetChannel(getter_AddRefs(channel)); aLoader->GetRequest(getter_AddRefs(request));
if (request)
channel = do_QueryInterface(request);
if (channel) if (channel)
{ {
nsCOMPtr<nsIURI> uri; nsCOMPtr<nsIURI> uri;
@@ -6527,14 +6521,14 @@ nsXULDocument::CachedChromeStreamListener::~CachedChromeStreamListener()
NS_IMPL_ISUPPORTS2(nsXULDocument::CachedChromeStreamListener, nsIStreamObserver, nsIStreamListener); NS_IMPL_ISUPPORTS2(nsXULDocument::CachedChromeStreamListener, nsIStreamObserver, nsIStreamListener);
NS_IMETHODIMP NS_IMETHODIMP
nsXULDocument::CachedChromeStreamListener::OnStartRequest(nsIChannel* aChannel, nsISupports* acontext) nsXULDocument::CachedChromeStreamListener::OnStartRequest(nsIRequest *request, nsISupports* acontext)
{ {
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsXULDocument::CachedChromeStreamListener::OnStopRequest(nsIChannel* aChannel, nsXULDocument::CachedChromeStreamListener::OnStopRequest(nsIRequest *request,
nsISupports* aContext, nsISupports* aContext,
nsresult aStatus, nsresult aStatus,
const PRUnichar* aErrorMsg) const PRUnichar* aErrorMsg)
@@ -6549,7 +6543,7 @@ nsXULDocument::CachedChromeStreamListener::OnStopRequest(nsIChannel* aChannel,
NS_IMETHODIMP NS_IMETHODIMP
nsXULDocument::CachedChromeStreamListener::OnDataAvailable(nsIChannel* aChannel, nsXULDocument::CachedChromeStreamListener::OnDataAvailable(nsIRequest *request,
nsISupports* aContext, nsISupports* aContext,
nsIInputStream* aInStr, nsIInputStream* aInStr,
PRUint32 aSourceOffset, PRUint32 aSourceOffset,
@@ -6579,14 +6573,14 @@ nsXULDocument::ParserObserver::~ParserObserver()
NS_IMPL_ISUPPORTS1(nsXULDocument::ParserObserver, nsIStreamObserver); NS_IMPL_ISUPPORTS1(nsXULDocument::ParserObserver, nsIStreamObserver);
NS_IMETHODIMP NS_IMETHODIMP
nsXULDocument::ParserObserver::OnStartRequest(nsIChannel* aChannel, nsXULDocument::ParserObserver::OnStartRequest(nsIRequest *request,
nsISupports* aContext) nsISupports* aContext)
{ {
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsXULDocument::ParserObserver::OnStopRequest(nsIChannel* aChannel, nsXULDocument::ParserObserver::OnStopRequest(nsIRequest *request,
nsISupports* aContext, nsISupports* aContext,
nsresult aStatus, nsresult aStatus,
const PRUnichar* aErrorMsg) const PRUnichar* aErrorMsg)
@@ -6598,6 +6592,10 @@ nsXULDocument::ParserObserver::OnStopRequest(nsIChannel* aChannel,
// walk along. // walk along.
#define YELL_IF_MISSING_OVERLAY 1 #define YELL_IF_MISSING_OVERLAY 1
#if defined(DEBUG) || defined(YELL_IF_MISSING_OVERLAY) #if defined(DEBUG) || defined(YELL_IF_MISSING_OVERLAY)
nsCOMPtr<nsIChannel> aChannel = do_QueryInterface(request);
if (!aChannel) return NS_ERROR_FAILURE;
nsCOMPtr<nsIURI> uri; nsCOMPtr<nsIURI> uri;
aChannel->GetOriginalURI(getter_AddRefs(uri)); aChannel->GetOriginalURI(getter_AddRefs(uri));

View File

@@ -119,7 +119,7 @@ public:
NS_IMETHOD GetContentType(nsAWritableString& aContentType) const; NS_IMETHOD GetContentType(nsAWritableString& aContentType) const;
NS_IMETHOD StartDocumentLoad(const char* aCommand, NS_IMETHOD StartDocumentLoad(const char* aCommand,
nsIChannel* aChannel, nsIChannel *channel,
nsILoadGroup* aLoadGroup, nsILoadGroup* aLoadGroup,
nsISupports* aContainer, nsISupports* aContainer,
nsIStreamListener **aDocListener, nsIStreamListener **aDocListener,
@@ -642,7 +642,7 @@ protected:
* A "dummy" channel that is used as a placeholder to signal document load * A "dummy" channel that is used as a placeholder to signal document load
* completion. * completion.
*/ */
nsCOMPtr<nsIChannel> mPlaceholderChannel; nsCOMPtr<nsIRequest> mPlaceHolderRequest;
/** /**
* Create a XUL template builder on the specified node if a 'datasources' * Create a XUL template builder on the specified node if a 'datasources'

View File

@@ -80,7 +80,7 @@ NS_IMETHODIMP nsDSURIContentListener::GetProtocolHandler(nsIURI* aURI,
NS_IMETHODIMP nsDSURIContentListener::DoContent(const char* aContentType, NS_IMETHODIMP nsDSURIContentListener::DoContent(const char* aContentType,
nsURILoadCommand aCommand, const char* aWindowTarget, nsURILoadCommand aCommand, const char* aWindowTarget,
nsIChannel* aOpenedChannel, nsIStreamListener** aContentHandler, nsIRequest* request, nsIStreamListener** aContentHandler,
PRBool* aAbortProcess) PRBool* aAbortProcess)
{ {
NS_ENSURE_ARG_POINTER(aContentHandler); NS_ENSURE_ARG_POINTER(aContentHandler);
@@ -89,6 +89,8 @@ NS_IMETHODIMP nsDSURIContentListener::DoContent(const char* aContentType,
// determine if the channel has just been retargeted to us... // determine if the channel has just been retargeted to us...
nsLoadFlags loadAttribs = 0; nsLoadFlags loadAttribs = 0;
nsCOMPtr<nsIChannel> aOpenedChannel = do_QueryInterface(request);
aOpenedChannel->GetLoadAttributes(&loadAttribs); aOpenedChannel->GetLoadAttributes(&loadAttribs);
PRUint32 loadType = mDocShell->ConvertDocShellLoadInfoToLoadType((nsDocShellInfoLoadType) aCommand); PRUint32 loadType = mDocShell->ConvertDocShellLoadInfoToLoadType((nsDocShellInfoLoadType) aCommand);
@@ -100,7 +102,7 @@ NS_IMETHODIMP nsDSURIContentListener::DoContent(const char* aContentType,
} }
nsresult rv = mDocShell->CreateContentViewer(aContentType, nsresult rv = mDocShell->CreateContentViewer(aContentType,
aOpenedChannel, aContentHandler); request, aContentHandler);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE; // it's okay if we don't know how to handle the content if (NS_FAILED(rv)) return NS_ERROR_FAILURE; // it's okay if we don't know how to handle the content
if(loadAttribs & nsIChannel::LOAD_RETARGETED_DOCUMENT_URI) if(loadAttribs & nsIChannel::LOAD_RETARGETED_DOCUMENT_URI)

View File

@@ -2751,7 +2751,7 @@ NS_IMETHODIMP nsDocShell::CreateAboutBlankContentViewer()
} }
NS_IMETHODIMP nsDocShell::CreateContentViewer(const char* aContentType, NS_IMETHODIMP nsDocShell::CreateContentViewer(const char* aContentType,
nsIChannel* aOpenedChannel, nsIStreamListener** aContentHandler) nsIRequest *request, nsIStreamListener** aContentHandler)
{ {
// Can we check the content type of the current content viewer // Can we check the content type of the current content viewer
// and reuse it without destroying it and re-creating it? // and reuse it without destroying it and re-creating it?
@@ -2761,12 +2761,17 @@ NS_IMETHODIMP nsDocShell::CreateContentViewer(const char* aContentType,
// Instantiate the content viewer object // Instantiate the content viewer object
nsCOMPtr<nsIContentViewer> viewer; nsCOMPtr<nsIContentViewer> viewer;
if(NS_FAILED(NewContentViewerObj(aContentType, aOpenedChannel, loadGroup, nsresult rv = NewContentViewerObj(aContentType, request, loadGroup,
aContentHandler, getter_AddRefs(viewer)))) aContentHandler, getter_AddRefs(viewer));
if(NS_FAILED(rv))
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
// we've created a new document so go ahead and call OnLoadingSite // we've created a new document so go ahead and call OnLoadingSite
mURIResultedInDocument = PR_TRUE; mURIResultedInDocument = PR_TRUE;
nsCOMPtr<nsIChannel> aOpenedChannel = do_QueryInterface(request);
OnLoadingSite(aOpenedChannel); OnLoadingSite(aOpenedChannel);
// let's try resetting the load group if we need to... // let's try resetting the load group if we need to...
@@ -2797,9 +2802,9 @@ NS_IMETHODIMP nsDocShell::CreateContentViewer(const char* aContentType,
aOpenedChannel->SetLoadAttributes(loadAttribs); aOpenedChannel->SetLoadAttributes(loadAttribs);
loadGroup->AddChannel(aOpenedChannel, nsnull); loadGroup->AddRequest(request, nsnull);
if(currentLoadGroup) if(currentLoadGroup)
currentLoadGroup->RemoveChannel(aOpenedChannel, nsnull, nsnull, nsnull); currentLoadGroup->RemoveRequest(request, nsnull, nsnull, nsnull);
} }
#ifdef SH_IN_FRAMES #ifdef SH_IN_FRAMES
@@ -2813,7 +2818,7 @@ NS_IMETHODIMP nsDocShell::CreateContentViewer(const char* aContentType,
} }
nsresult nsDocShell::NewContentViewerObj(const char* aContentType, nsresult nsDocShell::NewContentViewerObj(const char* aContentType,
nsIChannel* aOpenedChannel, nsILoadGroup* aLoadGroup, nsIRequest *request, nsILoadGroup* aLoadGroup,
nsIStreamListener** aContentHandler, nsIContentViewer** aViewer) nsIStreamListener** aContentHandler, nsIContentViewer** aViewer)
{ {
//XXX This should probably be some category thing.... //XXX This should probably be some category thing....
@@ -2841,6 +2846,8 @@ nsresult nsDocShell::NewContentViewerObj(const char* aContentType,
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
nsCOMPtr<nsIChannel> aOpenedChannel = do_QueryInterface(request);
// Now create an instance of the content viewer // Now create an instance of the content viewer
NS_ENSURE_SUCCESS(docLoaderFactory->CreateInstance( NS_ENSURE_SUCCESS(docLoaderFactory->CreateInstance(
(viewSource == mViewMode) ? "view-source" : "view", (viewSource == mViewMode) ? "view-source" : "view",

View File

@@ -191,9 +191,9 @@ protected:
NS_IMETHOD EnsureDeviceContext(); NS_IMETHOD EnsureDeviceContext();
NS_IMETHOD CreateAboutBlankContentViewer(); NS_IMETHOD CreateAboutBlankContentViewer();
NS_IMETHOD CreateContentViewer(const char* aContentType, NS_IMETHOD CreateContentViewer(const char* aContentType,
nsIChannel* aOpenedChannel, nsIStreamListener** aContentHandler); nsIRequest *request, nsIStreamListener** aContentHandler);
NS_IMETHOD NewContentViewerObj(const char* aContentType, NS_IMETHOD NewContentViewerObj(const char* aContentType,
nsIChannel* aOpenedChannel, nsILoadGroup* aLoadGroup, nsIRequest *request, nsILoadGroup* aLoadGroup,
nsIStreamListener** aContentHandler, nsIContentViewer** aViewer); nsIStreamListener** aContentHandler, nsIContentViewer** aViewer);
NS_IMETHOD SetupNewViewer(nsIContentViewer* aNewViewer); NS_IMETHOD SetupNewViewer(nsIContentViewer* aNewViewer);

View File

@@ -891,10 +891,10 @@ nsWebShell::GetLinkState(const char* aLinkURI, nsLinkState& aState)
// are cleaned up. // are cleaned up.
// //
NS_IMETHODIMP NS_IMETHODIMP
nsWebShell::OnStateChange(nsIWebProgress *aProgress, nsIRequest *aRequest, nsWebShell::OnStateChange(nsIWebProgress *aProgress, nsIRequest *request,
PRInt32 aStateFlags, nsresult aStatus) PRInt32 aStateFlags, nsresult aStatus)
{ {
if (!aRequest) { if (!request) {
return NS_OK; return NS_OK;
} }
@@ -903,7 +903,8 @@ nsWebShell::OnStateChange(nsIWebProgress *aProgress, nsIRequest *aRequest,
if (aProgress == webProgress.get()) { if (aProgress == webProgress.get()) {
nsCOMPtr<nsIURI> url; nsCOMPtr<nsIURI> url;
nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
nsCOMPtr<nsIDocumentLoaderObserver> dlObserver; nsCOMPtr<nsIDocumentLoaderObserver> dlObserver;
(void) channel->GetURI(getter_AddRefs(url)); (void) channel->GetURI(getter_AddRefs(url));
@@ -936,21 +937,21 @@ nsWebShell::OnStateChange(nsIWebProgress *aProgress, nsIRequest *aRequest,
* Fire the OnEndDocumentLoad of the DocLoaderobserver * Fire the OnEndDocumentLoad of the DocLoaderobserver
*/ */
if(dlObserver && url) { if(dlObserver && url) {
dlObserver->OnEndDocumentLoad(mDocLoader, channel, aStatus); dlObserver->OnEndDocumentLoad(mDocLoader, request, aStatus);
} }
} }
} }
} }
if (aStateFlags & STATE_IS_REQUEST) { if (aStateFlags & STATE_IS_REQUEST) {
nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest)); nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
if (aStateFlags & STATE_START) { if (aStateFlags & STATE_START) {
/* /*
*Fire the OnStartDocumentLoad of the webshell observer *Fire the OnStartDocumentLoad of the webshell observer
*/ */
if ((nsnull != mContainer) && (nsnull != mDocLoaderObserver)) { if ((nsnull != mContainer) && (nsnull != mDocLoaderObserver)) {
mDocLoaderObserver->OnStartURLLoad(mDocLoader, channel); mDocLoaderObserver->OnStartURLLoad(mDocLoader, request);
} }
} }
else if (aStateFlags & STATE_STOP) { else if (aStateFlags & STATE_STOP) {
@@ -958,27 +959,26 @@ nsWebShell::OnStateChange(nsIWebProgress *aProgress, nsIRequest *aRequest,
*Fire the OnEndDocumentLoad of the webshell observer *Fire the OnEndDocumentLoad of the webshell observer
*/ */
if ((nsnull != mContainer) && (nsnull != mDocLoaderObserver)) { if ((nsnull != mContainer) && (nsnull != mDocLoaderObserver)) {
mDocLoaderObserver->OnEndURLLoad(mDocLoader, channel, aStatus); mDocLoaderObserver->OnEndURLLoad(mDocLoader, request, aStatus);
} }
} }
} }
return nsDocShell::OnStateChange(aProgress, aRequest, aStateFlags, aStatus); return nsDocShell::OnStateChange(aProgress, request, aStateFlags, aStatus);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
nsresult nsWebShell::EndPageLoad(nsIWebProgress *aProgress, nsresult nsWebShell::EndPageLoad(nsIWebProgress *aProgress,
nsIChannel *aChannel, nsIChannel* channel,
nsresult aStatus) nsresult aStatus)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
if(!aChannel) if(!channel)
return NS_ERROR_NULL_POINTER; return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIURI> url; nsCOMPtr<nsIURI> url;
rv = channel->GetURI(getter_AddRefs(url));
rv = aChannel->GetURI(getter_AddRefs(url));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
// clean up reload state for meta charset // clean up reload state for meta charset
@@ -993,7 +993,7 @@ nsresult nsWebShell::EndPageLoad(nsIWebProgress *aProgress,
// during this load handler. // during this load handler.
// //
nsCOMPtr<nsIWebShell> kungFuDeathGrip(this); nsCOMPtr<nsIWebShell> kungFuDeathGrip(this);
nsDocShell::EndPageLoad(aProgress, aChannel, aStatus); nsDocShell::EndPageLoad(aProgress, channel, aStatus);
// //
// If the page load failed, then deal with the error condition... // If the page load failed, then deal with the error condition...

View File

@@ -138,7 +138,7 @@ protected:
// sub-documents - ie. frames) has been completely loaded. // sub-documents - ie. frames) has been completely loaded.
// //
virtual nsresult EndPageLoad(nsIWebProgress *aProgress, virtual nsresult EndPageLoad(nsIWebProgress *aProgress,
nsIChannel *aChannel, nsIChannel* channel,
nsresult aStatus); nsresult aStatus);
nsIEventQueue* mThreadEventQueue; nsIEventQueue* mThreadEventQueue;
@@ -156,7 +156,7 @@ protected:
nsresult FireUnloadForChildren(); nsresult FireUnloadForChildren();
nsresult CreateViewer(nsIChannel* aChannel, nsresult CreateViewer(nsIRequest* request,
const char* aContentType, const char* aContentType,
const char* aCommand, const char* aCommand,
nsIStreamListener** aResult); nsIStreamListener** aResult);

View File

@@ -4904,7 +4904,7 @@ NS_IMETHODIMP nsEditorShell::GetProtocolHandler(nsIURI *aURI, nsIProtocolHandler
} }
/* void doContent (in string aContentType, in nsURILoadCommand aCommand, in string aWindowTarget, in nsIChannel aOpenedChannel, out nsIStreamListener aContentHandler, out boolean aAbortProcess); */ /* void doContent (in string aContentType, in nsURILoadCommand aCommand, in string aWindowTarget, in nsIChannel aOpenedChannel, out nsIStreamListener aContentHandler, out boolean aAbortProcess); */
NS_IMETHODIMP nsEditorShell::DoContent(const char *aContentType, nsURILoadCommand aCommand, const char *aWindowTarget, nsIChannel *aOpenedChannel, nsIStreamListener **aContentHandler, PRBool *aAbortProcess) NS_IMETHODIMP nsEditorShell::DoContent(const char *aContentType, nsURILoadCommand aCommand, const char *aWindowTarget, nsIRequest* request, nsIStreamListener **aContentHandler, PRBool *aAbortProcess)
{ {
NS_ENSURE_ARG_POINTER(aContentHandler); NS_ENSURE_ARG_POINTER(aContentHandler);
NS_ENSURE_ARG_POINTER(aAbortProcess); NS_ENSURE_ARG_POINTER(aAbortProcess);

View File

@@ -4904,7 +4904,7 @@ NS_IMETHODIMP nsEditorShell::GetProtocolHandler(nsIURI *aURI, nsIProtocolHandler
} }
/* void doContent (in string aContentType, in nsURILoadCommand aCommand, in string aWindowTarget, in nsIChannel aOpenedChannel, out nsIStreamListener aContentHandler, out boolean aAbortProcess); */ /* void doContent (in string aContentType, in nsURILoadCommand aCommand, in string aWindowTarget, in nsIChannel aOpenedChannel, out nsIStreamListener aContentHandler, out boolean aAbortProcess); */
NS_IMETHODIMP nsEditorShell::DoContent(const char *aContentType, nsURILoadCommand aCommand, const char *aWindowTarget, nsIChannel *aOpenedChannel, nsIStreamListener **aContentHandler, PRBool *aAbortProcess) NS_IMETHODIMP nsEditorShell::DoContent(const char *aContentType, nsURILoadCommand aCommand, const char *aWindowTarget, nsIRequest* request, nsIStreamListener **aContentHandler, PRBool *aAbortProcess)
{ {
NS_ENSURE_ARG_POINTER(aContentHandler); NS_ENSURE_ARG_POINTER(aContentHandler);
NS_ENSURE_ARG_POINTER(aAbortProcess); NS_ENSURE_ARG_POINTER(aAbortProcess);

View File

@@ -35,4 +35,5 @@ ifdef MOZ_ENABLE_PHOTON
DIRS += photon DIRS += photon
endif endif
include $(topsrcdir)/config/rules.mk include $(topsrcdir)/config/rules.mk

View File

@@ -388,8 +388,8 @@ NS_IMETHODIMP CWebBrowserContainer::GetProtocolHandler(nsIURI *aURI, nsIProtocol
} }
/* void doContent (in string aContentType, in nsURILoadCommand aCommand, in string aWindowTarget, in nsIChannel aOpenedChannel, out nsIStreamListener aContentHandler, out boolean aAbortProcess); */ /* void doContent (in string aContentType, in nsURILoadCommand aCommand, in string aWindowTarget, in nsIRequest request, out nsIStreamListener aContentHandler, out boolean aAbortProcess); */
NS_IMETHODIMP CWebBrowserContainer::DoContent(const char *aContentType, nsURILoadCommand aCommand, const char *aWindowTarget, nsIChannel *aOpenedChannel, nsIStreamListener **aContentHandler, PRBool *aAbortProcess) NS_IMETHODIMP CWebBrowserContainer::DoContent(const char *aContentType, nsURILoadCommand aCommand, const char *aWindowTarget, nsIRequest *request, nsIStreamListener **aContentHandler, PRBool *aAbortProcess)
{ {
return NS_ERROR_NOT_IMPLEMENTED; return NS_ERROR_NOT_IMPLEMENTED;
} }
@@ -714,7 +714,7 @@ CWebBrowserContainer::GetPersistence(PRBool* aPersistX, PRBool* aPersistY,
NS_IMETHODIMP NS_IMETHODIMP
CWebBrowserContainer::OnStartRequest(nsIChannel* aChannel, nsISupports* aContext) CWebBrowserContainer::OnStartRequest(nsIRequest *request, nsISupports* aContext)
{ {
USES_CONVERSION; USES_CONVERSION;
NG_TRACE(_T("CWebBrowserContainer::OnStartRequest(...)\n")); NG_TRACE(_T("CWebBrowserContainer::OnStartRequest(...)\n"));
@@ -724,7 +724,7 @@ CWebBrowserContainer::OnStartRequest(nsIChannel* aChannel, nsISupports* aContext
NS_IMETHODIMP NS_IMETHODIMP
CWebBrowserContainer::OnStopRequest(nsIChannel* aChannel, nsISupports* aContext, nsresult aStatus, const PRUnichar* aMsg) CWebBrowserContainer::OnStopRequest(nsIRequest *request, nsISupports* aContext, nsresult aStatus, const PRUnichar* aMsg)
{ {
USES_CONVERSION; USES_CONVERSION;
NG_TRACE(_T("CWebBrowserContainer::OnStopRequest(..., %d, \"%s\")\n"), (int) aStatus, W2T((PRUnichar *) aMsg)); NG_TRACE(_T("CWebBrowserContainer::OnStopRequest(..., %d, \"%s\")\n"), (int) aStatus, W2T((PRUnichar *) aMsg));
@@ -758,7 +758,7 @@ CWebBrowserContainer::OnStartDocumentLoad(nsIDocumentLoader* loader, nsIURI* pUR
// we need this to fire the document complete // we need this to fire the document complete
NS_IMETHODIMP NS_IMETHODIMP
CWebBrowserContainer::OnEndDocumentLoad(nsIDocumentLoader* loader, nsIChannel *aChannel, nsresult aStatus) CWebBrowserContainer::OnEndDocumentLoad(nsIDocumentLoader* loader, nsIRequest *request, nsresult aStatus)
{ {
NG_TRACE(_T("CWebBrowserContainer::OnEndDocumentLoad(..., \"\")\n")); NG_TRACE(_T("CWebBrowserContainer::OnEndDocumentLoad(..., \"\")\n"));
@@ -776,6 +776,9 @@ CWebBrowserContainer::OnEndDocumentLoad(nsIDocumentLoader* loader, nsIChannel *a
char* aString = nsnull; char* aString = nsnull;
nsIURI* pURI = nsnull; nsIURI* pURI = nsnull;
nsCOMPtr<nsIChannel> aChannel = do_QueryInterface(request);
if (!aChannel) return NS_ERROR_NULL_POINTER;
aChannel->GetURI(&pURI); aChannel->GetURI(&pURI);
if (pURI == nsnull) if (pURI == nsnull)
{ {
@@ -804,7 +807,7 @@ CWebBrowserContainer::OnEndDocumentLoad(nsIDocumentLoader* loader, nsIChannel *a
NS_IMETHODIMP NS_IMETHODIMP
CWebBrowserContainer::OnStartURLLoad(nsIDocumentLoader* loader, nsIChannel* aChannel) CWebBrowserContainer::OnStartURLLoad(nsIDocumentLoader* loader, nsIRequest *request)
{ {
NG_TRACE(_T("CWebBrowserContainer::OnStartURLLoad(..., \"\")\n")); NG_TRACE(_T("CWebBrowserContainer::OnStartURLLoad(..., \"\")\n"));
@@ -815,7 +818,7 @@ CWebBrowserContainer::OnStartURLLoad(nsIDocumentLoader* loader, nsIChannel* aCha
NS_IMETHODIMP NS_IMETHODIMP
CWebBrowserContainer::OnProgressURLLoad(nsIDocumentLoader* loader, nsIChannel* aChannel, PRUint32 aProgress, PRUint32 aProgressMax) CWebBrowserContainer::OnProgressURLLoad(nsIDocumentLoader* loader, nsIRequest *request, PRUint32 aProgress, PRUint32 aProgressMax)
{ {
USES_CONVERSION; USES_CONVERSION;
NG_TRACE(_T("CWebBrowserContainer::OnProgress(..., \"%d\", \"%d\")\n"), (int) aProgress, (int) aProgressMax); NG_TRACE(_T("CWebBrowserContainer::OnProgress(..., \"%d\", \"%d\")\n"), (int) aProgress, (int) aProgressMax);
@@ -825,7 +828,7 @@ CWebBrowserContainer::OnProgressURLLoad(nsIDocumentLoader* loader, nsIChannel* a
NS_IMETHODIMP NS_IMETHODIMP
CWebBrowserContainer::OnStatusURLLoad(nsIDocumentLoader* loader, nsIChannel* aChannel, nsString& aMsg) CWebBrowserContainer::OnStatusURLLoad(nsIDocumentLoader* loader, nsIRequest *request, nsString& aMsg)
{ {
NG_TRACE(_T("CWebBrowserContainer::OnStatusURLLoad(..., \"\")\n")); NG_TRACE(_T("CWebBrowserContainer::OnStatusURLLoad(..., \"\")\n"));
@@ -840,7 +843,7 @@ CWebBrowserContainer::OnStatusURLLoad(nsIDocumentLoader* loader, nsIChannel* aCh
NS_IMETHODIMP NS_IMETHODIMP
CWebBrowserContainer::OnEndURLLoad(nsIDocumentLoader* loader, nsIChannel* channel, nsresult aStatus) CWebBrowserContainer::OnEndURLLoad(nsIDocumentLoader* loader, nsIRequest *request, nsresult aStatus)
{ {
NG_TRACE(_T("CWebBrowserContainer::OnEndURLLoad(..., \"\")\n")); NG_TRACE(_T("CWebBrowserContainer::OnEndURLLoad(..., \"\")\n"));

View File

@@ -264,7 +264,8 @@ NS_IMETHODIMP GtkMozEmbedChrome::OpenStream (const char *aBaseURI, const char *a
return rv; return rv;
// start our request // start our request
rv = mStreamListener->OnStartRequest(mChannel, NULL); nsCOMPtr<nsIRequest> request = do_QueryInterface(mChannel);
rv = mStreamListener->OnStartRequest(request, NULL);
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; return rv;
@@ -281,7 +282,8 @@ NS_IMETHODIMP GtkMozEmbedChrome::AppendToStream (const char *aData, gint32 aLen)
rv = embedStream->Append(aData, aLen); rv = embedStream->Append(aData, aLen);
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; return rv;
rv = mStreamListener->OnDataAvailable(mChannel, nsCOMPtr<nsIRequest> request = do_QueryInterface(mChannel);
rv = mStreamListener->OnDataAvailable(request,
NULL, NULL,
mStream, mStream,
mOffset, /* offset */ mOffset, /* offset */
@@ -297,7 +299,8 @@ NS_IMETHODIMP GtkMozEmbedChrome::CloseStream (void)
nsresult rv; nsresult rv;
NS_ENSURE_STATE(mDoingStream); NS_ENSURE_STATE(mDoingStream);
mDoingStream = PR_FALSE; mDoingStream = PR_FALSE;
rv = mStreamListener->OnStopRequest(mChannel, nsCOMPtr<nsIRequest> request = do_QueryInterface(mChannel);
rv = mStreamListener->OnStopRequest(request,
NULL, NULL,
NS_OK, NS_OK,
NULL); NULL);
@@ -531,7 +534,7 @@ NS_IMETHODIMP GtkMozEmbedChrome::GetProtocolHandler(nsIURI *aURI, nsIProtocolHan
} }
NS_IMETHODIMP GtkMozEmbedChrome::DoContent(const char *aContentType, nsURILoadCommand aCommand, NS_IMETHODIMP GtkMozEmbedChrome::DoContent(const char *aContentType, nsURILoadCommand aCommand,
const char *aWindowTarget, nsIChannel *aOpenedChannel, const char *aWindowTarget, nsIRequest *request,
nsIStreamListener **aContentHandler, PRBool *aAbortProcess) nsIStreamListener **aContentHandler, PRBool *aAbortProcess)
{ {
PR_LOG(mozEmbedLm, PR_LOG_DEBUG, ("GtkMozEmbedChrome::DoContent\n")); PR_LOG(mozEmbedLm, PR_LOG_DEBUG, ("GtkMozEmbedChrome::DoContent\n"));

View File

@@ -93,7 +93,7 @@ NS_IMETHODIMP nsWBURIContentListener::GetProtocolHandler(nsIURI* aURI,
NS_IMETHODIMP nsWBURIContentListener::DoContent(const char* aContentType, NS_IMETHODIMP nsWBURIContentListener::DoContent(const char* aContentType,
nsURILoadCommand aCommand, const char* aWindowTarget, nsURILoadCommand aCommand, const char* aWindowTarget,
nsIChannel* aOpenedChannel, nsIStreamListener** aContentHandler, nsIRequest* request, nsIStreamListener** aContentHandler,
PRBool* aAbortProcess) PRBool* aAbortProcess)
{ {
NS_ERROR("Hmmmm, why is this getting called on this object?"); NS_ERROR("Hmmmm, why is this getting called on this object?");

View File

@@ -86,7 +86,7 @@ void nsWebBrowserPersist::CleanUp()
mOutputStream->Close(); mOutputStream->Close();
mOutputStream = nsnull; mOutputStream = nsnull;
} }
mOutputChannel = nsnull; mOutputTransport = nsnull;
} }
NS_IMPL_ADDREF(nsWebBrowserPersist) NS_IMPL_ADDREF(nsWebBrowserPersist)
@@ -162,10 +162,6 @@ NS_IMETHODIMP nsWebBrowserPersist::SaveURI(nsIURI *aURI, nsIInputStream *aPostDa
} }
} }
// Query the content type
nsXPIDLCString contentType;
inputChannel->GetContentType(getter_Copies(contentType));
NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID); NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID);
NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv); NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv);
@@ -188,7 +184,7 @@ NS_IMETHODIMP nsWebBrowserPersist::SaveURI(nsIURI *aURI, nsIInputStream *aPostDa
} }
// Open a channel on the local file // Open a channel on the local file
nsCOMPtr<nsIChannel> outputChannel; nsCOMPtr<nsITransport> outputChannel;
rv = fts->CreateTransport(file, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, rv = fts->CreateTransport(file, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE,
0664, getter_AddRefs(outputChannel)); 0664, getter_AddRefs(outputChannel));
if (NS_FAILED(rv)) if (NS_FAILED(rv))
@@ -197,10 +193,12 @@ NS_IMETHODIMP nsWebBrowserPersist::SaveURI(nsIURI *aURI, nsIInputStream *aPostDa
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
mOutputChannel = outputChannel; mOutputTransport = outputChannel;
//dougt wtf?! why both a async and sync read?
// Read from the input channel // Read from the input channel
rv = inputChannel->AsyncRead(this, nsnull); rv = inputChannel->AsyncOpen(this, nsnull);
if (NS_FAILED(rv)) if (NS_FAILED(rv))
{ {
OnEndDownload(); OnEndDownload();
@@ -208,7 +206,7 @@ NS_IMETHODIMP nsWebBrowserPersist::SaveURI(nsIURI *aURI, nsIInputStream *aPostDa
} }
nsCOMPtr<nsIInputStream> inStream; nsCOMPtr<nsIInputStream> inStream;
rv = inputChannel->OpenInputStream(getter_AddRefs(inStream)); rv = inputChannel->Open(getter_AddRefs(inStream));
if (NS_FAILED(rv)) if (NS_FAILED(rv))
{ {
OnEndDownload(); OnEndDownload();
@@ -219,7 +217,10 @@ NS_IMETHODIMP nsWebBrowserPersist::SaveURI(nsIURI *aURI, nsIInputStream *aPostDa
mInputStream = inStream; mInputStream = inStream;
// Get the output channel ready for writing // Get the output channel ready for writing
rv = NS_AsyncWriteFromStream(outputChannel, inStream, NS_STATIC_CAST(nsIStreamObserver *, this), nsnull); nsCOMPtr<nsIRequest> writeRequest;
rv = NS_AsyncWriteFromStream(getter_AddRefs(writeRequest),
outputChannel, inStream, 0, 0, 0,
NS_STATIC_CAST(nsIStreamObserver*, this), nsnull);
if (NS_FAILED(rv)) if (NS_FAILED(rv))
{ {
OnEndDownload(); OnEndDownload();
@@ -394,15 +395,13 @@ NS_IMETHODIMP nsWebBrowserPersist::OnProgress(PRUint32 aStatus, nsIURI *aURI, PR
//***************************************************************************** //*****************************************************************************
/* void onStartRequest (in nsIChannel channel, in nsISupports ctxt); */ NS_IMETHODIMP nsWebBrowserPersist::OnStartRequest(nsIRequest* request, nsISupports *ctxt)
NS_IMETHODIMP nsWebBrowserPersist::OnStartRequest(nsIChannel *channel, nsISupports *ctxt)
{ {
nsresult rv = mOutputChannel->OpenOutputStream(getter_AddRefs(mOutputStream)); nsresult rv = mOutputTransport->OpenOutputStream(0, -1, 0, getter_AddRefs(mOutputStream));
return rv; return rv;
} }
/* void onStopRequest (in nsIChannel channel, in nsISupports ctxt, in nsresult status, in wstring statusArg); */ NS_IMETHODIMP nsWebBrowserPersist::OnStopRequest(nsIRequest* request, nsISupports *ctxt, nsresult status, const PRUnichar *statusArg)
NS_IMETHODIMP nsWebBrowserPersist::OnStopRequest(nsIChannel *channel, nsISupports *ctxt, nsresult status, const PRUnichar *statusArg)
{ {
OnEndDownload(); OnEndDownload();
CleanUp(); CleanUp();
@@ -415,7 +414,7 @@ NS_IMETHODIMP nsWebBrowserPersist::OnStopRequest(nsIChannel *channel, nsISupport
//***************************************************************************** //*****************************************************************************
NS_IMETHODIMP nsWebBrowserPersist::OnDataAvailable(nsIChannel *aChannel, nsISupports *aContext, nsIInputStream *aIStream, PRUint32 aOffset, PRUint32 aLength) NS_IMETHODIMP nsWebBrowserPersist::OnDataAvailable(nsIRequest* request, nsISupports *aContext, nsIInputStream *aIStream, PRUint32 aOffset, PRUint32 aLength)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
unsigned long bytesRemaining = aLength; unsigned long bytesRemaining = aLength;
@@ -453,9 +452,9 @@ NS_IMETHODIMP nsWebBrowserPersist::OnDataAvailable(nsIChannel *aChannel, nsISupp
// Cancel reading? // Cancel reading?
if (cancel) if (cancel)
{ {
if (aChannel) if (request)
{ {
aChannel->Cancel(NS_BINDING_ABORTED); request->Cancel(NS_BINDING_ABORTED);
} }
CleanUp(); CleanUp();
OnEndDownload(); OnEndDownload();
@@ -544,8 +543,6 @@ nsWebBrowserPersist::CleanupURIMap(nsHashKey *aKey, void *aData, void* closure)
nsresult nsresult
nsWebBrowserPersist::OnWalkDOMNode(nsIDOMNode *aNode, PRBool *aAbort) nsWebBrowserPersist::OnWalkDOMNode(nsIDOMNode *aNode, PRBool *aAbort)
{ {
nsresult rv = NS_OK;
// Test the node to see if it's an image, frame, iframe, css, js // Test the node to see if it's an image, frame, iframe, css, js
nsCOMPtr<nsIDOMHTMLImageElement> nodeAsImage = do_QueryInterface(aNode); nsCOMPtr<nsIDOMHTMLImageElement> nodeAsImage = do_QueryInterface(aNode);
if (nodeAsImage) if (nodeAsImage)
@@ -613,8 +610,6 @@ nsWebBrowserPersist::OnWalkDOMNode(nsIDOMNode *aNode, PRBool *aAbort)
nsresult nsresult
nsWebBrowserPersist::CloneNodeWithFixedUpURIAttributes(nsIDOMNode *aNodeIn, nsIDOMNode **aNodeOut) nsWebBrowserPersist::CloneNodeWithFixedUpURIAttributes(nsIDOMNode *aNodeIn, nsIDOMNode **aNodeOut)
{ {
nsresult rv = NS_OK;
*aNodeOut = nsnull; *aNodeOut = nsnull;
// Test the node to see if it's an image, frame, iframe, css, js // Test the node to see if it's an image, frame, iframe, css, js
@@ -892,13 +887,20 @@ nsWebBrowserPersist::MakeAndStoreLocalFilenameInURIMap(const char *aURI, nsStrin
// Create a unique file name for the uri // Create a unique file name for the uri
MakeFilenameFromURI(uri, inputChannel, filename); MakeFilenameFromURI(uri, inputChannel, filename);
// Query the content type if (!mMIMEService)
nsXPIDLCString contentType; {
inputChannel->GetContentType(getter_Copies(contentType)); mMIMEService = do_GetService(NS_MIMESERVICE_CONTRACTID);
if (!mMIMEService)
return NS_ERROR_FAILURE;
}
// Strap on the file extension using the mime lookup service // Strap on the file extension using the mime lookup service
if (mMIMEService)
{ nsXPIDLCString contentType;
rv = mMIMEService->GetTypeFromURI(uri, getter_Copies(contentType));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIMIMEInfo> mimeInfo; nsCOMPtr<nsIMIMEInfo> mimeInfo;
mMIMEService->GetFromMIMEType(contentType, getter_AddRefs(mimeInfo)); mMIMEService->GetFromMIMEType(contentType, getter_AddRefs(mimeInfo));
if (mimeInfo) if (mimeInfo)
@@ -914,7 +916,6 @@ nsWebBrowserPersist::MakeAndStoreLocalFilenameInURIMap(const char *aURI, nsStrin
filename.Append(newExt); filename.Append(newExt);
} }
} }
}
// Store the file name // Store the file name
URIData *data = new URIData; URIData *data = new URIData;

View File

@@ -32,7 +32,7 @@
#include "nsIChannel.h" #include "nsIChannel.h"
#include "nsIStyleSheet.h" #include "nsIStyleSheet.h"
#include "nsIDocumentEncoder.h" #include "nsIDocumentEncoder.h"
#include "nsITransport.h"
#include "nsHashtable.h" #include "nsHashtable.h"
#include "nsIWebBrowserPersist.h" #include "nsIWebBrowserPersist.h"
@@ -95,7 +95,7 @@ private:
nsCOMPtr<nsIMIMEService> mMIMEService; nsCOMPtr<nsIMIMEService> mMIMEService;
nsCOMPtr<nsIChannel> mInputChannel; nsCOMPtr<nsIChannel> mInputChannel;
nsCOMPtr<nsIInputStream> mInputStream; nsCOMPtr<nsIInputStream> mInputStream;
nsCOMPtr<nsIChannel> mOutputChannel; nsCOMPtr<nsITransport> mOutputTransport;
nsCOMPtr<nsIOutputStream> mOutputStream; nsCOMPtr<nsIOutputStream> mOutputStream;
nsCOMPtr<nsIURI> mBaseURI; nsCOMPtr<nsIURI> mBaseURI;
nsCOMPtr<nsIURI> mURI; nsCOMPtr<nsIURI> mURI;

View File

@@ -162,8 +162,10 @@ nsCookieHTTPNotify::ModifyRequest(nsISupports *aContext)
nsCOMPtr<nsIChannel> pChannel; nsCOMPtr<nsIChannel> pChannel;
if (pLoadGroup) { if (pLoadGroup) {
rv = pLoadGroup->GetDefaultLoadChannel(getter_AddRefs(pChannel)); nsCOMPtr<nsIRequest> pRequest;
if (NS_FAILED(rv)) return rv; rv = pLoadGroup->GetDefaultLoadRequest(getter_AddRefs(pRequest));
if (pRequest)
pChannel = do_QueryInterface(pRequest);
} }
nsCOMPtr<nsIURI> pFirstURL; nsCOMPtr<nsIURI> pFirstURL;
@@ -222,8 +224,10 @@ nsCookieHTTPNotify::AsyncExamineResponse(nsISupports *aContext)
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIChannel> pChannel; nsCOMPtr<nsIChannel> pChannel;
if (pLoadGroup) { if (pLoadGroup) {
rv = pLoadGroup->GetDefaultLoadChannel(getter_AddRefs(pChannel)); nsCOMPtr<nsIRequest> pRequest;
rv = pLoadGroup->GetDefaultLoadRequest(getter_AddRefs(pRequest));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
pChannel = do_QueryInterface(pRequest);
} }
nsCOMPtr<nsIURI> pFirstURL; nsCOMPtr<nsIURI> pFirstURL;
if (pChannel) { if (pChannel) {

View File

@@ -147,11 +147,11 @@ public:
// nsIDocumentLoaderObserver // nsIDocumentLoaderObserver
NS_IMETHOD OnStartDocumentLoad(nsIDocumentLoader* loader, nsIURI* aURL, const char* aCommand); NS_IMETHOD OnStartDocumentLoad(nsIDocumentLoader* loader, nsIURI* aURL, const char* aCommand);
NS_IMETHOD OnEndDocumentLoad(nsIDocumentLoader* loader, nsIChannel* channel, nsresult aStatus); NS_IMETHOD OnEndDocumentLoad(nsIDocumentLoader* loader, nsIRequest *request, nsresult aStatus);
NS_IMETHOD OnStartURLLoad(nsIDocumentLoader* loader, nsIChannel* channel); NS_IMETHOD OnStartURLLoad(nsIDocumentLoader* loader, nsIRequest *request);
NS_IMETHOD OnProgressURLLoad(nsIDocumentLoader* loader, nsIChannel* channel, PRUint32 aProgress, PRUint32 aProgressMax); NS_IMETHOD OnProgressURLLoad(nsIDocumentLoader* loader, nsIRequest *request, PRUint32 aProgress, PRUint32 aProgressMax);
NS_IMETHOD OnStatusURLLoad(nsIDocumentLoader* loader, nsIChannel* channel, nsString& aMsg); NS_IMETHOD OnStatusURLLoad(nsIDocumentLoader* loader, nsIRequest *request, nsString& aMsg);
NS_IMETHOD OnEndURLLoad(nsIDocumentLoader* loader, nsIChannel* channel, nsresult aStatus); NS_IMETHOD OnEndURLLoad(nsIDocumentLoader* loader, nsIRequest *request, nsresult aStatus);
// NS_IMETHOD OnConnectionsComplete(); // NS_IMETHOD OnConnectionsComplete();
@@ -696,7 +696,7 @@ nsPICS::OnStartDocumentLoad(nsIDocumentLoader* loader,
NS_IMETHODIMP NS_IMETHODIMP
nsPICS::OnEndDocumentLoad(nsIDocumentLoader* loader, nsPICS::OnEndDocumentLoad(nsIDocumentLoader* loader,
nsIChannel* channel, nsIRequest *request,
nsresult aStatus) nsresult aStatus)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
@@ -719,10 +719,14 @@ nsPICS::OnEndDocumentLoad(nsIDocumentLoader* loader,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsPICS::OnStartURLLoad(nsIDocumentLoader* loader, nsIChannel* channel) nsPICS::OnStartURLLoad(nsIDocumentLoader* loader, nsIRequest *request)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
if (!channel)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIURI> aURL; nsCOMPtr<nsIURI> aURL;
rv = channel->GetURI(getter_AddRefs(aURL)); rv = channel->GetURI(getter_AddRefs(aURL));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
@@ -798,7 +802,7 @@ nsPICS::OnStartURLLoad(nsIDocumentLoader* loader, nsIChannel* channel)
NS_IMETHODIMP NS_IMETHODIMP
nsPICS::OnProgressURLLoad(nsIDocumentLoader* loader, nsPICS::OnProgressURLLoad(nsIDocumentLoader* loader,
nsIChannel* channel, nsIRequest *request,
PRUint32 aProgress, PRUint32 aProgress,
PRUint32 aProgressMax) PRUint32 aProgressMax)
{ {
@@ -809,7 +813,7 @@ nsPICS::OnProgressURLLoad(nsIDocumentLoader* loader,
NS_IMETHODIMP NS_IMETHODIMP
nsPICS::OnStatusURLLoad(nsIDocumentLoader* loader, nsPICS::OnStatusURLLoad(nsIDocumentLoader* loader,
nsIChannel* channel, nsIRequest *request,
nsString& aMsg) nsString& aMsg)
{ {
if(!mPICSRatingsEnabled) if(!mPICSRatingsEnabled)
@@ -819,11 +823,13 @@ nsPICS::OnStatusURLLoad(nsIDocumentLoader* loader,
NS_IMETHODIMP NS_IMETHODIMP
nsPICS::OnEndURLLoad(nsIDocumentLoader* loader, nsPICS::OnEndURLLoad(nsIDocumentLoader* loader,
nsIChannel* channel, nsIRequest *request,
nsresult aStatus) nsresult aStatus)
{ {
nsresult rv; nsresult rv;
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
nsCOMPtr<nsIURI> aURL; nsCOMPtr<nsIURI> aURL;
rv = channel->GetURI(getter_AddRefs(aURL)); rv = channel->GetURI(getter_AddRefs(aURL));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;

View File

@@ -9,3 +9,5 @@ pref("security.warn_entering_secure", true);
pref("security.warn_leaving_secure", true); pref("security.warn_leaving_secure", true);
pref("security.warn_viewing_mixed", true); pref("security.warn_viewing_mixed", true);
pref("security.warn_submit_insecure", true); pref("security.warn_submit_insecure", true);
pref("security.ui.enable", true);

View File

@@ -719,12 +719,15 @@ NS_IMPL_ISUPPORTS(CertDownloader,NS_GET_IID(nsIStreamListener));
const PRInt32 kDefaultCertAllocLength = 2048; const PRInt32 kDefaultCertAllocLength = 2048;
NS_IMETHODIMP NS_IMETHODIMP
CertDownloader::OnStartRequest(nsIChannel* channel, nsISupports* context) CertDownloader::OnStartRequest(nsIRequest *request, nsISupports* context)
{ {
nsresult rv; nsresult rv = NS_OK;
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
if (channel)
rv = channel->GetContentLength(&mContentLength); rv = channel->GetContentLength(&mContentLength);
if (rv != NS_OK || mContentLength == -1)
if (!channel || rv != NS_OK || mContentLength == -1)
mContentLength = kDefaultCertAllocLength; mContentLength = kDefaultCertAllocLength;
mBufferOffset = 0; mBufferOffset = 0;
@@ -737,7 +740,7 @@ CertDownloader::OnStartRequest(nsIChannel* channel, nsISupports* context)
NS_IMETHODIMP NS_IMETHODIMP
CertDownloader::OnDataAvailable(nsIChannel* channel, CertDownloader::OnDataAvailable(nsIRequest *request,
nsISupports* context, nsISupports* context,
nsIInputStream *aIStream, nsIInputStream *aIStream,
PRUint32 aSourceOffset, PRUint32 aSourceOffset,
@@ -776,7 +779,7 @@ CertDownloader::OnDataAvailable(nsIChannel* channel,
NS_IMETHODIMP NS_IMETHODIMP
CertDownloader::OnStopRequest(nsIChannel* channel, CertDownloader::OnStopRequest(nsIRequest *request,
nsISupports* context, nsISupports* context,
nsresult aStatus, nsresult aStatus,
const PRUnichar* aMsg) const PRUnichar* aMsg)
@@ -857,19 +860,22 @@ nsPSMComponent::HandleContent(const char * aContentType,
const char * aCommand, const char * aCommand,
const char * aWindowTarget, const char * aWindowTarget,
nsISupports* aWindowContext, nsISupports* aWindowContext,
nsIChannel * aChannel) nsIRequest *request)
{ {
// We were called via CI. We better protect ourselves and addref. // We were called via CI. We better protect ourselves and addref.
NS_ADDREF_THIS(); NS_ADDREF_THIS();
nsresult rv = NS_OK; nsresult rv = NS_OK;
if (!aChannel) return NS_ERROR_NULL_POINTER; if (!request) return NS_ERROR_NULL_POINTER;
CMUint32 type = getPSMCertType(aContentType); CMUint32 type = getPSMCertType(aContentType);
if (type != -1) if (type != -1)
{ {
// I can't directly open the passed channel cause it fails :-( nsCOMPtr<nsIChannel> aChannel = do_QueryInterface(request);
if (!aChannel)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIURI> uri; nsCOMPtr<nsIURI> uri;
rv = aChannel->GetURI(getter_AddRefs(uri)); rv = aChannel->GetURI(getter_AddRefs(uri));
@@ -879,10 +885,11 @@ nsPSMComponent::HandleContent(const char * aContentType,
rv = NS_OpenURI(getter_AddRefs(channel), uri); rv = NS_OpenURI(getter_AddRefs(channel), uri);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
return channel->AsyncRead(new CertDownloader(type), NS_STATIC_CAST(nsIPSMComponent*,this)); return channel->AsyncOpen(new CertDownloader(type), NS_STATIC_CAST(nsIPSMComponent*,this));
} }
return NS_ERROR_NOT_IMPLEMENTED; return NS_ERROR_FAILURE;
} }
NS_IMPL_ISUPPORTS(CertContentListener, NS_GET_IID(nsIURIContentListener)); NS_IMPL_ISUPPORTS(CertContentListener, NS_GET_IID(nsIURIContentListener));
@@ -957,7 +964,7 @@ NS_IMETHODIMP
CertContentListener::DoContent(const char * aContentType, CertContentListener::DoContent(const char * aContentType,
nsURILoadCommand aCommand, nsURILoadCommand aCommand,
const char * aWindowTarget, const char * aWindowTarget,
nsIChannel * aOpenedChannel, nsIRequest * request,
nsIStreamListener ** aContentHandler, nsIStreamListener ** aContentHandler,
PRBool * aAbortProcess) PRBool * aAbortProcess)
{ {

View File

@@ -298,7 +298,7 @@ nsSyncLoader::LoadDocument(nsIURI* documentURI, nsIDOMDocument **_retval)
} }
// Start reading from the channel // Start reading from the channel
rv = channel->AsyncRead(listener, nsnull); rv = channel->AsyncOpen(listener, nsnull);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
if (modalEventQueue) { if (modalEventQueue) {

View File

@@ -114,10 +114,12 @@ function (iid) {
} }
TelnetContentHandler.prototype.handleContent = TelnetContentHandler.prototype.handleContent =
function (aContentType, aCommand, aWindowTarget, aSourceContext, aChannel) function (aContentType, aCommand, aWindowTarget, aSourceContext, aRequest)
{ {
var e; var e;
var aChannel = aRequest.QueryInterface(Components.interfaces.nsIChannel);
dump ("telnetLoader.handleContent (" + aContentType + ", " + dump ("telnetLoader.handleContent (" + aContentType + ", " +
aCommand + ", " + aWindowTarget + ", " + aSourceContext + ", " + aCommand + ", " + aWindowTarget + ", " + aSourceContext + ", " +
aChannel.URI.spec + ")\n"); aChannel.URI.spec + ")\n");
@@ -218,7 +220,10 @@ function (aURI)
//dump("gSystemPrincipal="+gSystemPrincipal+"\n"); //dump("gSystemPrincipal="+gSystemPrincipal+"\n");
// Cancel XUL request and release channel // Cancel XUL request and release channel
temChannel.cancel(Components.results.NS_BINDING_ABORTED);
// why are you canceling here?! you have not even opened anything yet - dougt.
// temChannel.cancel(Components.results.NS_BINDING_ABORTED);
temChannel = null; temChannel = null;
// Get current process directory // Get current process directory
@@ -279,8 +284,6 @@ function (iid) {
} }
/* nsIChannel */ /* nsIChannel */
BogusChannel.prototype.transferOffset = 0;
BogusChannel.prototype.transferCount = 0;
BogusChannel.prototype.loadAttributes = null; BogusChannel.prototype.loadAttributes = null;
BogusChannel.prototype.contentType = "x-application-telnet"; BogusChannel.prototype.contentType = "x-application-telnet";
BogusChannel.prototype.contentLength = 0; BogusChannel.prototype.contentLength = 0;
@@ -288,14 +291,10 @@ BogusChannel.prototype.owner = null;
BogusChannel.prototype.loadGroup = null; BogusChannel.prototype.loadGroup = null;
BogusChannel.prototype.notificationCallbacks = null; BogusChannel.prototype.notificationCallbacks = null;
BogusChannel.prototype.securityInfo = null; BogusChannel.prototype.securityInfo = null;
BogusChannel.prototype.bufferSegmentSize = 0;
BogusChannel.prototype.bufferMaxSize = 0;
BogusChannel.prototype.shouldCache = false; BogusChannel.prototype.shouldCache = false;
BogusChannel.prototype.pipeliningAllowed = false;
BogusChannel.prototype.openInputStream = BogusChannel.prototype.open =
BogusChannel.prototype.openOutputStream = BogusChannel.prototype.asyncOpen =
BogusChannel.prototype.asyncWrite =
function () function ()
{ {
throw Components.results.NS_ERROR_NOT_IMPLEMENTED; throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
@@ -307,12 +306,6 @@ function (observer, ctxt)
observer.onStartRequest (this, ctxt); observer.onStartRequest (this, ctxt);
} }
BogusChannel.prototype.asyncRead =
function (listener, ctxt)
{
return listener.onStartRequest (this, ctxt);
}
/* nsIRequest */ /* nsIRequest */
BogusChannel.prototype.isPending = BogusChannel.prototype.isPending =
function () function ()
@@ -328,6 +321,7 @@ function (aStatus)
this.status = aStatus; this.status = aStatus;
} }
BogusChannel.prototype.parent =
BogusChannel.prototype.suspend = BogusChannel.prototype.suspend =
BogusChannel.prototype.resume = BogusChannel.prototype.resume =
function () function ()

View File

@@ -98,7 +98,7 @@ public:
virtual int GetContentLength(ilIURL * aURL); virtual int GetContentLength(ilIURL * aURL);
nsresult RemoveRequest(ImageConsumer *aConsumer); nsresult RemoveRequest(ImageConsumer *aConsumer);
nsresult RequestDone(ImageConsumer *aConsumer, nsIChannel* channel, nsresult RequestDone(ImageConsumer *aConsumer, nsIRequest* request,
nsISupports* ctxt, nsresult status, const PRUnichar* aMsg); nsISupports* ctxt, nsresult status, const PRUnichar* aMsg);
nsVoidArray *mRequests; // WEAK references to |ImageConsumer|s nsVoidArray *mRequests; // WEAK references to |ImageConsumer|s
@@ -121,10 +121,10 @@ public:
NS_DECL_NSIURICONTENTLISTENER NS_DECL_NSIURICONTENTLISTENER
NS_DECL_NSIINTERFACEREQUESTOR NS_DECL_NSIINTERFACEREQUESTOR
void SetKeepPumpingData(nsIChannel* channel, nsISupports* context) { void SetKeepPumpingData(nsIRequest* request, nsISupports* context) {
NS_ADDREF(channel); NS_ADDREF(request);
NS_IF_RELEASE(mChannel); NS_IF_RELEASE(mRequest);
mChannel = channel; mRequest = request;
NS_IF_ADDREF(context); NS_IF_ADDREF(context);
NS_IF_RELEASE(mUserContext); NS_IF_RELEASE(mUserContext);
@@ -145,7 +145,7 @@ protected:
PRBool mFirstRead; PRBool mFirstRead;
char *mBuffer; char *mBuffer;
PRInt32 mStatus; PRInt32 mStatus;
nsIChannel* mChannel; nsIRequest* mRequest;
nsISupports* mUserContext; nsISupports* mUserContext;
PRBool mIsMulti; PRBool mIsMulti;
}; };
@@ -162,7 +162,7 @@ ImageConsumer::ImageConsumer(ilIURL *aURL, ImageNetContextImpl *aContext)
mStream = nsnull; mStream = nsnull;
mBuffer = nsnull; mBuffer = nsnull;
mStatus = 0; mStatus = 0;
mChannel = nsnull; mRequest = nsnull;
mUserContext = nsnull; mUserContext = nsnull;
mIsMulti = PR_FALSE; mIsMulti = PR_FALSE;
} }
@@ -262,7 +262,7 @@ NS_IMETHODIMP
ImageConsumer::DoContent(const char * aContentType, ImageConsumer::DoContent(const char * aContentType,
nsURILoadCommand aCommand, nsURILoadCommand aCommand,
const char * aWindowTarget, const char * aWindowTarget,
nsIChannel * aOpenedChannel, nsIRequest * aOpenedChannel,
nsIStreamListener ** aContentHandler, nsIStreamListener ** aContentHandler,
PRBool * aAbortProcess) PRBool * aAbortProcess)
{ {
@@ -294,8 +294,10 @@ ImageConsumer::DoContent(const char * aContentType,
NS_IMETHODIMP NS_IMETHODIMP
ImageConsumer::OnStartRequest(nsIChannel* channel, nsISupports* aContext) ImageConsumer::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext)
{ {
nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
PRUint32 httpStatus; PRUint32 httpStatus;
if (mInterrupted) { if (mInterrupted) {
mStatus = MK_INTERRUPTED; mStatus = MK_INTERRUPTED;
@@ -318,7 +320,7 @@ ImageConsumer::OnStartRequest(nsIChannel* channel, nsISupports* aContext)
} }
ilINetReader *reader = mURL->GetReader(); //ptn test: nsCOMPtr?? ilINetReader *reader = mURL->GetReader(); //ptn test: nsCOMPtr??
nsresult err= reader->FlushImgBuffer(); //flush current data in buffer before starting /*nsresult err=*/ reader->FlushImgBuffer(); //flush current data in buffer before starting
nsresult rv = NS_OK; nsresult rv = NS_OK;
char* aContentType = NULL; char* aContentType = NULL;
@@ -353,13 +355,15 @@ ImageConsumer::OnStartRequest(nsIChannel* channel, nsISupports* aContext)
NS_IMETHODIMP NS_IMETHODIMP
ImageConsumer::OnDataAvailable(nsIChannel* channel, nsISupports* aContext, nsIInputStream *pIStream, ImageConsumer::OnDataAvailable(nsIRequest* request, nsISupports* aContext,
PRUint32 offset, PRUint32 length) nsIInputStream *pIStream, PRUint32 offset, PRUint32 length)
{ {
PRUint32 max_read=0; PRUint32 max_read=0;
PRUint32 bytes_read = 0; PRUint32 bytes_read = 0;
ilINetReader *reader = mURL->GetReader(); ilINetReader *reader = mURL->GetReader();
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
if (mInterrupted || mStatus != 0) { if (mInterrupted || mStatus != 0) {
mStatus = MK_INTERRUPTED; mStatus = MK_INTERRUPTED;
reader->StreamAbort(mStatus); reader->StreamAbort(mStatus);
@@ -482,12 +486,12 @@ ImageConsumer::KeepPumpingStream(nsITimer *aTimer, void *aClosure)
ImageConsumer *consumer = (ImageConsumer *)aClosure; ImageConsumer *consumer = (ImageConsumer *)aClosure;
nsAutoString status; nsAutoString status;
consumer->OnStopRequest(consumer->mChannel, consumer->mUserContext, consumer->OnStopRequest(consumer->mRequest, consumer->mUserContext,
NS_BINDING_SUCCEEDED, status.GetUnicode()); NS_BINDING_SUCCEEDED, status.GetUnicode());
} }
NS_IMETHODIMP NS_IMETHODIMP
ImageConsumer::OnStopRequest(nsIChannel* channel, nsISupports* aContext, nsresult status, const PRUnichar* aMsg) ImageConsumer::OnStopRequest(nsIRequest* request, nsISupports* aContext, nsresult status, const PRUnichar* aMsg)
{ {
if (mTimer) { if (mTimer) {
mTimer->Cancel(); mTimer->Cancel();
@@ -506,12 +510,12 @@ ImageConsumer::OnStopRequest(nsIChannel* channel, nsISupports* aContext, nsresul
nsresult err = mStream->Available(&str_length); nsresult err = mStream->Available(&str_length);
if (NS_SUCCEEDED(err)) { if (NS_SUCCEEDED(err)) {
NS_ASSERTION((str_length > 0), "No data left in the stream!"); NS_ASSERTION((str_length > 0), "No data left in the stream!");
err = OnDataAvailable(channel, aContext, mStream, 0, str_length); // XXX fix offset err = OnDataAvailable(request, aContext, mStream, 0, str_length); // XXX fix offset
if (NS_SUCCEEDED(err)) { if (NS_SUCCEEDED(err)) {
// If we still have the stream, there's still data to be // If we still have the stream, there's still data to be
// pumped, so we set a timer to call us back again. // pumped, so we set a timer to call us back again.
if (mStream) { if (mStream) {
SetKeepPumpingData(channel, aContext); SetKeepPumpingData(request, aContext);
nsresult rv; nsresult rv;
mTimer = do_CreateInstance("@mozilla.org/timer;1", &rv); mTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
@@ -550,7 +554,7 @@ ImageConsumer::OnStopRequest(nsIChannel* channel, nsISupports* aContext, nsresul
reader->NetRequestDone(mURL, mStatus); reader->NetRequestDone(mURL, mStatus);
NS_RELEASE(reader); NS_RELEASE(reader);
return mContext->RequestDone(this, channel, aContext, status, aMsg); return mContext->RequestDone(this, request, aContext, status, aMsg);
} }
void void
@@ -583,7 +587,7 @@ ImageConsumer::~ImageConsumer()
if (mBuffer != nsnull) { if (mBuffer != nsnull) {
PR_DELETE(mBuffer); PR_DELETE(mBuffer);
} }
NS_IF_RELEASE(mChannel); NS_IF_RELEASE(mRequest);
NS_IF_RELEASE(mUserContext); NS_IF_RELEASE(mUserContext);
} }
@@ -722,8 +726,10 @@ ImageNetContextImpl::GetContentLength (ilIURL * aURL)
rv = NS_OpenURI(getter_AddRefs(channel), nsurl, nsnull, group, sink); rv = NS_OpenURI(getter_AddRefs(channel), nsurl, nsnull, group, sink);
if (NS_FAILED(rv)) return 0; if (NS_FAILED(rv)) return 0;
// Why would this code ever return anything but zero. we don't do asyncread
rv = channel->GetContentLength(&content_length); // on the channel we create?
// Commenting this line for now TODO -gagan
//rv = channel->GetContentLength(&content_length);
return content_length; return content_length;
} }
@@ -785,14 +791,16 @@ ImageNetContextImpl::GetURL (ilIURL * aURL,
nsCOMPtr<nsIHTTPChannel> httpChannel = do_QueryInterface(channel); nsCOMPtr<nsIHTTPChannel> httpChannel = do_QueryInterface(channel);
if (httpChannel) if (httpChannel)
{ {
// Get the defloadchannel from the loadgroup- // Get the defloadRequest from the loadgroup-
nsCOMPtr<nsIChannel> defLoadChannel; nsCOMPtr<nsIRequest> defLoadRequest;
if (NS_SUCCEEDED(group->GetDefaultLoadChannel( if (NS_SUCCEEDED(group->GetDefaultLoadRequest(
getter_AddRefs(defLoadChannel))) && defLoadChannel) getter_AddRefs(defLoadRequest))) && defLoadRequest)
{ {
nsCOMPtr<nsIChannel> reqchannel = do_QueryInterface(defLoadRequest);
// Get the referrer from the loadchannel- // Get the referrer from the loadchannel-
nsCOMPtr<nsIURI> referrer; nsCOMPtr<nsIURI> referrer;
if (NS_SUCCEEDED(defLoadChannel->GetURI(getter_AddRefs(referrer)))) if (NS_SUCCEEDED(reqchannel->GetURI(getter_AddRefs(referrer))))
{ {
// Set the referrer- // Set the referrer-
httpChannel->SetReferrer(referrer, httpChannel->SetReferrer(referrer,
@@ -826,7 +834,7 @@ ImageNetContextImpl::GetURL (ilIURL * aURL,
rv = pURILoader->OpenURI(channel, loadCmd, nsnull /* window target */, rv = pURILoader->OpenURI(channel, loadCmd, nsnull /* window target */,
window); window);
} }
// rv = channel->AsyncRead(ic, nsnull); // rv = channel->AsyncOpen(ic, nsnull);
if (NS_FAILED(rv)) goto error; if (NS_FAILED(rv)) goto error;
} }
@@ -851,7 +859,7 @@ ImageNetContextImpl::RemoveRequest(ImageConsumer *aConsumer)
} }
nsresult nsresult
ImageNetContextImpl::RequestDone(ImageConsumer *aConsumer, nsIChannel* channel, ImageNetContextImpl::RequestDone(ImageConsumer *aConsumer, nsIRequest* request,
nsISupports* ctxt, nsresult status, const PRUnichar* aMsg) nsISupports* ctxt, nsresult status, const PRUnichar* aMsg)
{ {
RemoveRequest(aConsumer); RemoveRequest(aConsumer);
@@ -879,14 +887,18 @@ NS_NewImageNetContext(ilINetContext **aInstancePtrResult,
if(aLoadContext){ if(aLoadContext){
nsCOMPtr<nsILoadGroup> group (do_GetInterface(aLoadContext)); nsCOMPtr<nsILoadGroup> group (do_GetInterface(aLoadContext));
nsresult rv = group->GetDefaultLoadAttributes(&necko_attribs); /*nsresult rv = */group->GetDefaultLoadAttributes(&necko_attribs);
/* /*
Need code to check freshness of necko cache. Need code to check freshness of necko cache.
*/ */
nsCOMPtr<nsIChannel> defLoadChannel; nsCOMPtr<nsIRequest> defLoadRequest;
if (NS_SUCCEEDED(group->GetDefaultLoadChannel( nsCOMPtr<nsIChannel> channel;
getter_AddRefs(defLoadChannel))) && defLoadChannel) if (NS_SUCCEEDED(group->GetDefaultLoadRequest(
defLoadChannel->GetLoadAttributes(&defchan_attribs); getter_AddRefs(defLoadRequest))) && defLoadRequest)
{
channel = do_QueryInterface(defLoadRequest);
if (channel) channel->GetLoadAttributes(&defchan_attribs);
}
#if defined( DEBUG ) #if defined( DEBUG )
if (image_net_context_async_log_module == NULL) { if (image_net_context_async_log_module == NULL) {

View File

@@ -218,6 +218,9 @@ ImageNetContextSyncImpl::GetURL(ilIURL* aURL,
if(aContentType){ if(aContentType){
nsCRT::free(aContentType); nsCRT::free(aContentType);
} }
}
if (!aContentType) {
aContentType = nsCRT::strdup("unknown"); aContentType = nsCRT::strdup("unknown");
} }
if(nsCRT::strlen(aContentType) > 50){ if(nsCRT::strlen(aContentType) > 50){
@@ -227,7 +230,7 @@ ImageNetContextSyncImpl::GetURL(ilIURL* aURL,
aContentType = nsCRT::strdup("unknown"); aContentType = nsCRT::strdup("unknown");
} }
rv = channel->OpenInputStream(&stream); rv = channel->Open( &stream);
NS_RELEASE(channel); NS_RELEASE(channel);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {

View File

@@ -152,7 +152,7 @@ CStreamListener::OnStartDocumentLoad(nsIDocumentLoader* loader,
NS_IMETHODIMP NS_IMETHODIMP
CStreamListener::OnEndDocumentLoad(nsIDocumentLoader* loader, CStreamListener::OnEndDocumentLoad(nsIDocumentLoader* loader,
nsIChannel* channel, nsIRequest *request,
nsresult aStatus) nsresult aStatus)
{ {
fputs("done.\n",stdout); fputs("done.\n",stdout);
@@ -162,14 +162,14 @@ CStreamListener::OnEndDocumentLoad(nsIDocumentLoader* loader,
NS_IMETHODIMP NS_IMETHODIMP
CStreamListener::OnStartURLLoad(nsIDocumentLoader* loader, CStreamListener::OnStartURLLoad(nsIDocumentLoader* loader,
nsIChannel* channel) nsIRequest *request)
{ {
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
CStreamListener::OnProgressURLLoad(nsIDocumentLoader* loader, CStreamListener::OnProgressURLLoad(nsIDocumentLoader* loader,
nsIChannel* channel, nsIRequest *request,
PRUint32 aProgress, PRUint32 aProgress,
PRUint32 aProgressMax) PRUint32 aProgressMax)
{ {
@@ -178,7 +178,7 @@ CStreamListener::OnProgressURLLoad(nsIDocumentLoader* loader,
NS_IMETHODIMP NS_IMETHODIMP
CStreamListener::OnStatusURLLoad(nsIDocumentLoader* loader, CStreamListener::OnStatusURLLoad(nsIDocumentLoader* loader,
nsIChannel* channel, nsIRequest *request,
nsString& aMsg) nsString& aMsg)
{ {
return NS_OK; return NS_OK;
@@ -186,7 +186,7 @@ CStreamListener::OnStatusURLLoad(nsIDocumentLoader* loader,
NS_IMETHODIMP NS_IMETHODIMP
CStreamListener::OnEndURLLoad(nsIDocumentLoader* loader, CStreamListener::OnEndURLLoad(nsIDocumentLoader* loader,
nsIChannel* channel, nsIRequest *request,
nsresult aStatus) nsresult aStatus)
{ {
return NS_OK; return NS_OK;

View File

@@ -61,7 +61,7 @@ CParserContext::CParserContext(nsScanner* aScanner,
mContextType=eCTNone; mContextType=eCTNone;
mCopyUnused=aCopyUnused; mCopyUnused=aCopyUnused;
mParserCommand=aCommand; mParserCommand=aCommand;
mChannel=0; mRequest=0;
mValidator=0; mValidator=0;
} }
@@ -92,7 +92,7 @@ CParserContext::CParserContext(const CParserContext &aContext) : mMimeType() {
mStreamListenerState=aContext.mStreamListenerState; mStreamListenerState=aContext.mStreamListenerState;
mMultipart=aContext.mMultipart; mMultipart=aContext.mMultipart;
mContextType=aContext.mContextType; mContextType=aContext.mContextType;
mChannel=aContext.mChannel; mRequest=aContext.mRequest;
mParserCommand=aContext.mParserCommand; mParserCommand=aContext.mParserCommand;
SetMimeType(aContext.mMimeType); SetMimeType(aContext.mMimeType);
} }

View File

@@ -72,7 +72,7 @@ public:
eContextType mContextType; eContextType mContextType;
eAutoDetectResult mAutoDetectStatus; eAutoDetectResult mAutoDetectStatus;
eParserCommands mParserCommand; //tells us to viewcontent/viewsource/viewerrors... eParserCommands mParserCommand; //tells us to viewcontent/viewsource/viewerrors...
nsIChannel* mChannel; // provided by necko to differnciate different input streams nsIRequest* mRequest; // provided by necko to differnciate different input streams
nsScanner* mScanner; nsScanner* mScanner;
nsIDTD* mDTD; nsIDTD* mDTD;

View File

@@ -2062,11 +2062,11 @@ nsITokenizer* nsParser::GetTokenizer(void) {
* @return error code -- 0 if ok, non-zero if error. * @return error code -- 0 if ok, non-zero if error.
*/ */
nsresult nsresult
nsParser::OnProgress(nsIChannel* channel, nsISupports* aContext, PRUint32 aProgress, PRUint32 aProgressMax) nsParser::OnProgress(nsIRequest *request, nsISupports* aContext, PRUint32 aProgress, PRUint32 aProgressMax)
{ {
nsresult result=0; nsresult result=0;
if (nsnull != mProgressEventSink) { if (nsnull != mProgressEventSink) {
mProgressEventSink->OnProgress(channel, aContext, aProgress, aProgressMax); mProgressEventSink->OnProgress(request, aContext, aProgress, aProgressMax);
} }
return result; return result;
} }
@@ -2079,12 +2079,12 @@ nsParser::OnProgress(nsIChannel* channel, nsISupports* aContext, PRUint32 aProgr
* @return error code -- 0 if ok, non-zero if error. * @return error code -- 0 if ok, non-zero if error.
*/ */
nsresult nsresult
nsParser::OnStatus(nsIChannel* channel, nsISupports* aContext, nsParser::OnStatus(nsIRequest *request, nsISupports* aContext,
nsresult aStatus, const PRUnichar* aStatusArg) nsresult aStatus, const PRUnichar* aStatusArg)
{ {
nsresult rv; nsresult rv;
if (nsnull != mProgressEventSink) { if (nsnull != mProgressEventSink) {
rv = mProgressEventSink->OnStatus(channel, aContext, aStatus, aStatusArg); rv = mProgressEventSink->OnStatus(request, aContext, aStatus, aStatusArg);
NS_ASSERTION(NS_SUCCEEDED(rv), "dropping error result"); NS_ASSERTION(NS_SUCCEEDED(rv), "dropping error result");
} }
return NS_OK; return NS_OK;
@@ -2102,19 +2102,22 @@ nsParser::OnStatus(nsIChannel* channel, nsISupports* aContext,
* @param * @param
* @return error code -- 0 if ok, non-zero if error. * @return error code -- 0 if ok, non-zero if error.
*/ */
nsresult nsParser::OnStartRequest(nsIChannel* channel, nsISupports* aContext) { nsresult nsParser::OnStartRequest(nsIRequest *request, nsISupports* aContext) {
NS_PRECONDITION((eNone==mParserContext->mStreamListenerState),kBadListenerInit); NS_PRECONDITION((eNone==mParserContext->mStreamListenerState),kBadListenerInit);
if (nsnull != mObserver) { if (nsnull != mObserver) {
mObserver->OnStartRequest(channel, aContext); mObserver->OnStartRequest(request, aContext);
} }
mParserContext->mStreamListenerState=eOnStart; mParserContext->mStreamListenerState=eOnStart;
mParserContext->mAutoDetectStatus=eUnknownDetect; mParserContext->mAutoDetectStatus=eUnknownDetect;
mParserContext->mChannel=channel; mParserContext->mRequest=request;
mParserContext->mDTD=0; mParserContext->mDTD=0;
nsresult rv; nsresult rv;
char* contentType = nsnull; char* contentType = nsnull;
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
NS_ASSERTION(channel, "parser needs a channel to find a dtd");
rv = channel->GetContentType(&contentType); rv = channel->GetContentType(&contentType);
if (NS_SUCCEEDED(rv)) if (NS_SUCCEEDED(rv))
{ {
@@ -2310,7 +2313,7 @@ ParserWriteFunc(nsIInputStream* in,
* @return error code (usually 0) * @return error code (usually 0)
*/ */
nsresult nsParser::OnDataAvailable(nsIChannel* channel, nsISupports* aContext, nsresult nsParser::OnDataAvailable(nsIRequest *request, nsISupports* aContext,
nsIInputStream *pIStream, PRUint32 sourceOffset, PRUint32 aLength) nsIInputStream *pIStream, PRUint32 sourceOffset, PRUint32 aLength)
{ {
@@ -2322,12 +2325,12 @@ NS_PRECONDITION(((eOnStart==mParserContext->mStreamListenerState)||(eOnDataAvail
CParserContext *theContext=mParserContext; CParserContext *theContext=mParserContext;
while(theContext) { while(theContext) {
if(theContext->mChannel!=channel && theContext->mPrevContext) if(theContext->mRequest!=request && theContext->mPrevContext)
theContext=theContext->mPrevContext; theContext=theContext->mPrevContext;
else break; else break;
} }
if(theContext && theContext->mChannel==channel) { if(theContext && theContext->mRequest==request) {
theContext->mStreamListenerState=eOnDataAvail; theContext->mStreamListenerState=eOnDataAvail;
@@ -2366,7 +2369,7 @@ NS_PRECONDITION(((eOnStart==mParserContext->mStreamListenerState)||(eOnDataAvail
* @param * @param
* @return * @return
*/ */
nsresult nsParser::OnStopRequest(nsIChannel* channel, nsISupports* aContext, nsresult nsParser::OnStopRequest(nsIRequest *request, nsISupports* aContext,
nsresult status, const PRUnichar* aMsg) nsresult status, const PRUnichar* aMsg)
{ {
@@ -2398,7 +2401,7 @@ nsresult nsParser::OnStopRequest(nsIChannel* channel, nsISupports* aContext,
// XXX Should we wait to notify our observers as well if the // XXX Should we wait to notify our observers as well if the
// parser isn't yet enabled? // parser isn't yet enabled?
if (nsnull != mObserver) { if (nsnull != mObserver) {
mObserver->OnStopRequest(channel, aContext, status, aMsg); mObserver->OnStopRequest(request, aContext, status, aMsg);
} }
#ifdef rickgdebug #ifdef rickgdebug

View File

@@ -237,7 +237,7 @@ PageGrabber::Grab(const nsString& aURL)
if(copier) { if(copier) {
NS_ADDREF(copier); NS_ADDREF(copier);
rv = channel->AsyncRead(copier, nsnull); rv = channel->AsyncOpen(copier, nsnull);
if (NS_OK != rv) { if (NS_OK != rv) {
NS_RELEASE(copier); NS_RELEASE(copier);

View File

@@ -238,8 +238,11 @@ nsStringBundle::OnStreamComplete(nsIStreamLoader* aLoader,
nsXPIDLCString uriSpec; nsXPIDLCString uriSpec;
if (NS_FAILED(aStatus)) { if (NS_FAILED(aStatus)) {
if (aLoader) { if (aLoader) {
nsCOMPtr<nsIRequest> request;
nsCOMPtr<nsIChannel> channel; nsCOMPtr<nsIChannel> channel;
aLoader->GetChannel(getter_AddRefs(channel)); aLoader->GetRequest(getter_AddRefs(request));
request = do_QueryInterface(channel);
if (channel) { if (channel) {
nsCOMPtr<nsIURI> uri; nsCOMPtr<nsIURI> uri;
channel->GetURI(getter_AddRefs(uri)); channel->GetURI(getter_AddRefs(uri));

View File

@@ -634,13 +634,12 @@ protected:
public: public:
static nsresult static nsresult
Create(nsIChannel** aResult, nsIPresShell* aPresShell); Create(nsIRequest** aResult, nsIPresShell* aPresShell);
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
// nsIRequest // nsIRequest
NS_IMETHOD GetName(PRUnichar* *result) { NS_IMETHOD GetName(PRUnichar* *result) {
NS_NOTREACHED("DummyLayoutRequest::GetName");
return NS_ERROR_NOT_IMPLEMENTED; return NS_ERROR_NOT_IMPLEMENTED;
} }
NS_IMETHOD IsPending(PRBool *_retval) { *_retval = PR_TRUE; return NS_OK; } NS_IMETHOD IsPending(PRBool *_retval) { *_retval = PR_TRUE; return NS_OK; }
@@ -654,34 +653,22 @@ public:
NS_IMETHOD SetOriginalURI(nsIURI* aOriginalURI) { gURI = aOriginalURI; NS_ADDREF(gURI); return NS_OK; } NS_IMETHOD SetOriginalURI(nsIURI* aOriginalURI) { gURI = aOriginalURI; NS_ADDREF(gURI); return NS_OK; }
NS_IMETHOD GetURI(nsIURI* *aURI) { *aURI = gURI; NS_ADDREF(*aURI); return NS_OK; } NS_IMETHOD GetURI(nsIURI* *aURI) { *aURI = gURI; NS_ADDREF(*aURI); return NS_OK; }
NS_IMETHOD SetURI(nsIURI* aURI) { gURI = aURI; NS_ADDREF(gURI); return NS_OK; } NS_IMETHOD SetURI(nsIURI* aURI) { gURI = aURI; NS_ADDREF(gURI); return NS_OK; }
NS_IMETHOD OpenInputStream(nsIInputStream **_retval) { *_retval = nsnull; return NS_OK; } NS_IMETHOD Open(nsIInputStream **_retval) { *_retval = nsnull; return NS_OK; }
NS_IMETHOD OpenOutputStream(nsIOutputStream **_retval) { *_retval = nsnull; return NS_OK; } NS_IMETHOD AsyncOpen(nsIStreamListener *listener, nsISupports *ctxt) { return NS_OK; }
NS_IMETHOD AsyncRead(nsIStreamListener *listener, nsISupports *ctxt) { return NS_OK; }
NS_IMETHOD AsyncWrite(nsIStreamProvider *provider, nsISupports *ctxt) { return NS_OK; }
NS_IMETHOD GetLoadAttributes(nsLoadFlags *aLoadAttributes) { *aLoadAttributes = nsIChannel::LOAD_NORMAL; return NS_OK; } NS_IMETHOD GetLoadAttributes(nsLoadFlags *aLoadAttributes) { *aLoadAttributes = nsIChannel::LOAD_NORMAL; return NS_OK; }
NS_IMETHOD SetLoadAttributes(nsLoadFlags aLoadAttributes) { return NS_OK; } NS_IMETHOD SetLoadAttributes(nsLoadFlags aLoadAttributes) { return NS_OK; }
NS_IMETHOD GetContentType(char * *aContentType) { *aContentType = nsnull; return NS_OK; }
NS_IMETHOD SetContentType(const char *aContentType) { return NS_OK; }
NS_IMETHOD GetContentLength(PRInt32 *aContentLength) { *aContentLength = 0; return NS_OK; }
NS_IMETHOD SetContentLength(PRInt32 aContentLength) { NS_NOTREACHED("SetContentLength"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD GetTransferOffset(PRUint32 *aTransferOffset) { NS_NOTREACHED("GetTransferOffset"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD SetTransferOffset(PRUint32 aTransferOffset) { NS_NOTREACHED("SetTransferOffset"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD GetTransferCount(PRInt32 *aTransferCount) { NS_NOTREACHED("GetTransferCount"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD SetTransferCount(PRInt32 aTransferCount) { NS_NOTREACHED("SetTransferCount"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD GetBufferSegmentSize(PRUint32 *aBufferSegmentSize) { NS_NOTREACHED("GetBufferSegmentSize"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD SetBufferSegmentSize(PRUint32 aBufferSegmentSize) { NS_NOTREACHED("SetBufferSegmentSize"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD GetBufferMaxSize(PRUint32 *aBufferMaxSize) { NS_NOTREACHED("GetBufferMaxSize"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD SetBufferMaxSize(PRUint32 aBufferMaxSize) { NS_NOTREACHED("SetBufferMaxSize"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD GetLocalFile(nsIFile* *result) { NS_NOTREACHED("GetLocalFile"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD GetPipeliningAllowed(PRBool *aPipeliningAllowed) { *aPipeliningAllowed = PR_FALSE; return NS_OK; }
NS_IMETHOD SetPipeliningAllowed(PRBool aPipeliningAllowed) { NS_NOTREACHED("SetPipeliningAllowed"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD GetOwner(nsISupports * *aOwner) { *aOwner = nsnull; return NS_OK; } NS_IMETHOD GetOwner(nsISupports * *aOwner) { *aOwner = nsnull; return NS_OK; }
NS_IMETHOD SetOwner(nsISupports * aOwner) { return NS_OK; } NS_IMETHOD SetOwner(nsISupports * aOwner) { return NS_OK; }
NS_IMETHOD GetLoadGroup(nsILoadGroup * *aLoadGroup) { *aLoadGroup = mLoadGroup; NS_IF_ADDREF(*aLoadGroup); return NS_OK; } NS_IMETHOD GetLoadGroup(nsILoadGroup * *aLoadGroup) { *aLoadGroup = mLoadGroup; NS_IF_ADDREF(*aLoadGroup); return NS_OK; }
NS_IMETHOD SetLoadGroup(nsILoadGroup * aLoadGroup) { mLoadGroup = aLoadGroup; return NS_OK; } NS_IMETHOD SetLoadGroup(nsILoadGroup * aLoadGroup) { mLoadGroup = aLoadGroup; return NS_OK; }
NS_IMETHOD GetNotificationCallbacks(nsIInterfaceRequestor * *aNotificationCallbacks) { *aNotificationCallbacks = nsnull; return NS_OK; } NS_IMETHOD GetNotificationCallbacks(nsIInterfaceRequestor * *aNotificationCallbacks) { *aNotificationCallbacks = nsnull; return NS_OK; }
NS_IMETHOD SetNotificationCallbacks(nsIInterfaceRequestor * aNotificationCallbacks) { return NS_OK; } NS_IMETHOD SetNotificationCallbacks(nsIInterfaceRequestor * aNotificationCallbacks) { return NS_OK; }
NS_IMETHOD GetSecurityInfo(nsISupports **info) {*info = nsnull; return NS_OK;} NS_IMETHOD GetSecurityInfo(nsISupports * *aSecurityInfo) { *aSecurityInfo = nsnull; return NS_OK; }
NS_IMETHOD GetContentType(char * *aContentType) { *aContentType = nsnull; return NS_OK; }
NS_IMETHOD SetContentType(const char * aContentType) { return NS_OK; }
NS_IMETHOD GetContentLength(PRInt32 *aContentLength) { return NS_OK; }
NS_IMETHOD SetContentLength(PRInt32 aContentLength) { return NS_OK; }
}; };
PRInt32 DummyLayoutRequest::gRefCnt; PRInt32 DummyLayoutRequest::gRefCnt;
@@ -692,7 +679,7 @@ NS_IMPL_RELEASE(DummyLayoutRequest);
NS_IMPL_QUERY_INTERFACE2(DummyLayoutRequest, nsIRequest, nsIChannel); NS_IMPL_QUERY_INTERFACE2(DummyLayoutRequest, nsIRequest, nsIChannel);
nsresult nsresult
DummyLayoutRequest::Create(nsIChannel** aResult, nsIPresShell* aPresShell) DummyLayoutRequest::Create(nsIRequest** aResult, nsIPresShell* aPresShell)
{ {
DummyLayoutRequest* request = new DummyLayoutRequest(aPresShell); DummyLayoutRequest* request = new DummyLayoutRequest(aPresShell);
if (!request) if (!request)
@@ -1065,7 +1052,7 @@ protected:
nsCOMPtr<nsIObserverService> mObserverService; // Observer service for reflow events nsCOMPtr<nsIObserverService> mObserverService; // Observer service for reflow events
nsCOMPtr<nsIDragService> mDragService; nsCOMPtr<nsIDragService> mDragService;
PRInt32 mRCCreatedDuringLoad; // Counter to keep track of reflow commands created during doc PRInt32 mRCCreatedDuringLoad; // Counter to keep track of reflow commands created during doc
nsCOMPtr<nsIChannel> mDummyLayoutRequest; nsCOMPtr<nsIRequest> mDummyLayoutRequest;
// used for list of posted events and attribute changes. To be done // used for list of posted events and attribute changes. To be done
// after reflow. // after reflow.
@@ -5343,10 +5330,10 @@ PresShell::AddDummyLayoutRequest(void)
} }
if (loadGroup) { if (loadGroup) {
rv = mDummyLayoutRequest->SetLoadGroup(loadGroup); nsCOMPtr<nsIChannel> channel = do_QueryInterface(mDummyLayoutRequest);
rv = channel->SetLoadGroup(loadGroup);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
rv = loadGroup->AddRequest(mDummyLayoutRequest, nsnull);
rv = loadGroup->AddChannel(mDummyLayoutRequest, nsnull);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
} }
@@ -5370,7 +5357,7 @@ PresShell::RemoveDummyLayoutRequest(void)
} }
if (loadGroup && mDummyLayoutRequest) { if (loadGroup && mDummyLayoutRequest) {
rv = loadGroup->RemoveChannel(mDummyLayoutRequest, nsnull, NS_OK, nsnull); rv = loadGroup->RemoveRequest(mDummyLayoutRequest, nsnull, NS_OK, nsnull);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
mDummyLayoutRequest = nsnull; mDummyLayoutRequest = nsnull;

View File

@@ -634,13 +634,12 @@ protected:
public: public:
static nsresult static nsresult
Create(nsIChannel** aResult, nsIPresShell* aPresShell); Create(nsIRequest** aResult, nsIPresShell* aPresShell);
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
// nsIRequest // nsIRequest
NS_IMETHOD GetName(PRUnichar* *result) { NS_IMETHOD GetName(PRUnichar* *result) {
NS_NOTREACHED("DummyLayoutRequest::GetName");
return NS_ERROR_NOT_IMPLEMENTED; return NS_ERROR_NOT_IMPLEMENTED;
} }
NS_IMETHOD IsPending(PRBool *_retval) { *_retval = PR_TRUE; return NS_OK; } NS_IMETHOD IsPending(PRBool *_retval) { *_retval = PR_TRUE; return NS_OK; }
@@ -654,34 +653,22 @@ public:
NS_IMETHOD SetOriginalURI(nsIURI* aOriginalURI) { gURI = aOriginalURI; NS_ADDREF(gURI); return NS_OK; } NS_IMETHOD SetOriginalURI(nsIURI* aOriginalURI) { gURI = aOriginalURI; NS_ADDREF(gURI); return NS_OK; }
NS_IMETHOD GetURI(nsIURI* *aURI) { *aURI = gURI; NS_ADDREF(*aURI); return NS_OK; } NS_IMETHOD GetURI(nsIURI* *aURI) { *aURI = gURI; NS_ADDREF(*aURI); return NS_OK; }
NS_IMETHOD SetURI(nsIURI* aURI) { gURI = aURI; NS_ADDREF(gURI); return NS_OK; } NS_IMETHOD SetURI(nsIURI* aURI) { gURI = aURI; NS_ADDREF(gURI); return NS_OK; }
NS_IMETHOD OpenInputStream(nsIInputStream **_retval) { *_retval = nsnull; return NS_OK; } NS_IMETHOD Open(nsIInputStream **_retval) { *_retval = nsnull; return NS_OK; }
NS_IMETHOD OpenOutputStream(nsIOutputStream **_retval) { *_retval = nsnull; return NS_OK; } NS_IMETHOD AsyncOpen(nsIStreamListener *listener, nsISupports *ctxt) { return NS_OK; }
NS_IMETHOD AsyncRead(nsIStreamListener *listener, nsISupports *ctxt) { return NS_OK; }
NS_IMETHOD AsyncWrite(nsIStreamProvider *provider, nsISupports *ctxt) { return NS_OK; }
NS_IMETHOD GetLoadAttributes(nsLoadFlags *aLoadAttributes) { *aLoadAttributes = nsIChannel::LOAD_NORMAL; return NS_OK; } NS_IMETHOD GetLoadAttributes(nsLoadFlags *aLoadAttributes) { *aLoadAttributes = nsIChannel::LOAD_NORMAL; return NS_OK; }
NS_IMETHOD SetLoadAttributes(nsLoadFlags aLoadAttributes) { return NS_OK; } NS_IMETHOD SetLoadAttributes(nsLoadFlags aLoadAttributes) { return NS_OK; }
NS_IMETHOD GetContentType(char * *aContentType) { *aContentType = nsnull; return NS_OK; }
NS_IMETHOD SetContentType(const char *aContentType) { return NS_OK; }
NS_IMETHOD GetContentLength(PRInt32 *aContentLength) { *aContentLength = 0; return NS_OK; }
NS_IMETHOD SetContentLength(PRInt32 aContentLength) { NS_NOTREACHED("SetContentLength"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD GetTransferOffset(PRUint32 *aTransferOffset) { NS_NOTREACHED("GetTransferOffset"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD SetTransferOffset(PRUint32 aTransferOffset) { NS_NOTREACHED("SetTransferOffset"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD GetTransferCount(PRInt32 *aTransferCount) { NS_NOTREACHED("GetTransferCount"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD SetTransferCount(PRInt32 aTransferCount) { NS_NOTREACHED("SetTransferCount"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD GetBufferSegmentSize(PRUint32 *aBufferSegmentSize) { NS_NOTREACHED("GetBufferSegmentSize"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD SetBufferSegmentSize(PRUint32 aBufferSegmentSize) { NS_NOTREACHED("SetBufferSegmentSize"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD GetBufferMaxSize(PRUint32 *aBufferMaxSize) { NS_NOTREACHED("GetBufferMaxSize"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD SetBufferMaxSize(PRUint32 aBufferMaxSize) { NS_NOTREACHED("SetBufferMaxSize"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD GetLocalFile(nsIFile* *result) { NS_NOTREACHED("GetLocalFile"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD GetPipeliningAllowed(PRBool *aPipeliningAllowed) { *aPipeliningAllowed = PR_FALSE; return NS_OK; }
NS_IMETHOD SetPipeliningAllowed(PRBool aPipeliningAllowed) { NS_NOTREACHED("SetPipeliningAllowed"); return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD GetOwner(nsISupports * *aOwner) { *aOwner = nsnull; return NS_OK; } NS_IMETHOD GetOwner(nsISupports * *aOwner) { *aOwner = nsnull; return NS_OK; }
NS_IMETHOD SetOwner(nsISupports * aOwner) { return NS_OK; } NS_IMETHOD SetOwner(nsISupports * aOwner) { return NS_OK; }
NS_IMETHOD GetLoadGroup(nsILoadGroup * *aLoadGroup) { *aLoadGroup = mLoadGroup; NS_IF_ADDREF(*aLoadGroup); return NS_OK; } NS_IMETHOD GetLoadGroup(nsILoadGroup * *aLoadGroup) { *aLoadGroup = mLoadGroup; NS_IF_ADDREF(*aLoadGroup); return NS_OK; }
NS_IMETHOD SetLoadGroup(nsILoadGroup * aLoadGroup) { mLoadGroup = aLoadGroup; return NS_OK; } NS_IMETHOD SetLoadGroup(nsILoadGroup * aLoadGroup) { mLoadGroup = aLoadGroup; return NS_OK; }
NS_IMETHOD GetNotificationCallbacks(nsIInterfaceRequestor * *aNotificationCallbacks) { *aNotificationCallbacks = nsnull; return NS_OK; } NS_IMETHOD GetNotificationCallbacks(nsIInterfaceRequestor * *aNotificationCallbacks) { *aNotificationCallbacks = nsnull; return NS_OK; }
NS_IMETHOD SetNotificationCallbacks(nsIInterfaceRequestor * aNotificationCallbacks) { return NS_OK; } NS_IMETHOD SetNotificationCallbacks(nsIInterfaceRequestor * aNotificationCallbacks) { return NS_OK; }
NS_IMETHOD GetSecurityInfo(nsISupports **info) {*info = nsnull; return NS_OK;} NS_IMETHOD GetSecurityInfo(nsISupports * *aSecurityInfo) { *aSecurityInfo = nsnull; return NS_OK; }
NS_IMETHOD GetContentType(char * *aContentType) { *aContentType = nsnull; return NS_OK; }
NS_IMETHOD SetContentType(const char * aContentType) { return NS_OK; }
NS_IMETHOD GetContentLength(PRInt32 *aContentLength) { return NS_OK; }
NS_IMETHOD SetContentLength(PRInt32 aContentLength) { return NS_OK; }
}; };
PRInt32 DummyLayoutRequest::gRefCnt; PRInt32 DummyLayoutRequest::gRefCnt;
@@ -692,7 +679,7 @@ NS_IMPL_RELEASE(DummyLayoutRequest);
NS_IMPL_QUERY_INTERFACE2(DummyLayoutRequest, nsIRequest, nsIChannel); NS_IMPL_QUERY_INTERFACE2(DummyLayoutRequest, nsIRequest, nsIChannel);
nsresult nsresult
DummyLayoutRequest::Create(nsIChannel** aResult, nsIPresShell* aPresShell) DummyLayoutRequest::Create(nsIRequest** aResult, nsIPresShell* aPresShell)
{ {
DummyLayoutRequest* request = new DummyLayoutRequest(aPresShell); DummyLayoutRequest* request = new DummyLayoutRequest(aPresShell);
if (!request) if (!request)
@@ -1065,7 +1052,7 @@ protected:
nsCOMPtr<nsIObserverService> mObserverService; // Observer service for reflow events nsCOMPtr<nsIObserverService> mObserverService; // Observer service for reflow events
nsCOMPtr<nsIDragService> mDragService; nsCOMPtr<nsIDragService> mDragService;
PRInt32 mRCCreatedDuringLoad; // Counter to keep track of reflow commands created during doc PRInt32 mRCCreatedDuringLoad; // Counter to keep track of reflow commands created during doc
nsCOMPtr<nsIChannel> mDummyLayoutRequest; nsCOMPtr<nsIRequest> mDummyLayoutRequest;
// used for list of posted events and attribute changes. To be done // used for list of posted events and attribute changes. To be done
// after reflow. // after reflow.
@@ -5343,10 +5330,10 @@ PresShell::AddDummyLayoutRequest(void)
} }
if (loadGroup) { if (loadGroup) {
rv = mDummyLayoutRequest->SetLoadGroup(loadGroup); nsCOMPtr<nsIChannel> channel = do_QueryInterface(mDummyLayoutRequest);
rv = channel->SetLoadGroup(loadGroup);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
rv = loadGroup->AddRequest(mDummyLayoutRequest, nsnull);
rv = loadGroup->AddChannel(mDummyLayoutRequest, nsnull);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
} }
@@ -5370,7 +5357,7 @@ PresShell::RemoveDummyLayoutRequest(void)
} }
if (loadGroup && mDummyLayoutRequest) { if (loadGroup && mDummyLayoutRequest) {
rv = loadGroup->RemoveChannel(mDummyLayoutRequest, nsnull, NS_OK, nsnull); rv = loadGroup->RemoveRequest(mDummyLayoutRequest, nsnull, NS_OK, nsnull);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
mDummyLayoutRequest = nsnull; mDummyLayoutRequest = nsnull;

View File

@@ -4715,8 +4715,12 @@ HTMLContentSink::OnStreamComplete(nsIStreamLoader* aLoader,
nsCOMPtr<nsIHTTPChannel> httpChannel; nsCOMPtr<nsIHTTPChannel> httpChannel;
nsCOMPtr<nsIChannel> channel; nsCOMPtr<nsIChannel> channel;
rv = aLoader->GetChannel(getter_AddRefs(channel)); nsCOMPtr<nsIRequest> request;
NS_ASSERTION(channel, "StreamLoader's channel went away prematurely"); rv = aLoader->GetRequest(getter_AddRefs(request));
NS_ASSERTION(request, "StreamLoader's request went away prematurely");
if (NS_FAILED(rv)) return rv;
channel = do_QueryInterface(request);
if (channel) { if (channel) {
httpChannel = do_QueryInterface(channel); httpChannel = do_QueryInterface(channel);

View File

@@ -585,7 +585,8 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
nsCOMPtr<nsIFile> file; nsCOMPtr<nsIFile> file;
rv = fileChannel->GetFile(getter_AddRefs(file)); rv = fileChannel->GetFile(getter_AddRefs(file));
if (NS_FAILED(rv)) { return rv; } if (NS_SUCCEEDED(rv))
{
// if we failed to get a last modification date, then we don't want to necessarily // if we failed to get a last modification date, then we don't want to necessarily
// fail to create a document for this file. Just don't set the last modified date on it... // fail to create a document for this file. Just don't set the last modified date on it...
rv = file->GetLastModificationDate(&modDate); rv = file->GetLastModificationDate(&modDate);
@@ -603,16 +604,17 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
// non-y2k with msvc; '%#c' requests that a full year be used in the // non-y2k with msvc; '%#c' requests that a full year be used in the
// result string. Other OSes just use "%c". // result string. Other OSes just use "%c".
PR_FormatTime(buf, sizeof buf, PR_FormatTime(buf, sizeof buf,
#if defined(XP_PC) && !defined(XP_OS2) #if defined(XP_PC) && !defined(XP_OS2)
"%#c", "%#c",
#else #else
"%c", "%c",
#endif #endif
&prtime); &prtime);
lastModified.AssignWithConversion(buf); lastModified.AssignWithConversion(buf);
SetLastModified(lastModified); SetLastModified(lastModified);
} }
} }
}
static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID); static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);

View File

@@ -121,10 +121,14 @@ ImageListener::~ImageListener()
NS_IMPL_THREADSAFE_ISUPPORTS(ImageListener, NS_GET_IID(nsIStreamListener)) NS_IMPL_THREADSAFE_ISUPPORTS(ImageListener, NS_GET_IID(nsIStreamListener))
NS_IMETHODIMP NS_IMETHODIMP
ImageListener::OnStartRequest(nsIChannel* channel, nsISupports *ctxt) ImageListener::OnStartRequest(nsIRequest* request, nsISupports *ctxt)
{ {
nsresult rv; nsresult rv;
nsIURI* uri; nsIURI* uri;
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
if (!channel) return NS_ERROR_NULL_POINTER;
rv = channel->GetURI(&uri); rv = channel->GetURI(&uri);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
@@ -133,11 +137,11 @@ ImageListener::OnStartRequest(nsIChannel* channel, nsISupports *ctxt)
if (nsnull == mNextStream) { if (nsnull == mNextStream) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
return mNextStream->OnStartRequest(channel, ctxt); return mNextStream->OnStartRequest(request, ctxt);
} }
NS_IMETHODIMP NS_IMETHODIMP
ImageListener::OnStopRequest(nsIChannel* channel, nsISupports *ctxt, ImageListener::OnStopRequest(nsIRequest* request, nsISupports *ctxt,
nsresult status, const PRUnichar *errorMsg) nsresult status, const PRUnichar *errorMsg)
{ {
if(mDocument){ if(mDocument){
@@ -147,17 +151,17 @@ ImageListener::OnStopRequest(nsIChannel* channel, nsISupports *ctxt,
if (nsnull == mNextStream) { if (nsnull == mNextStream) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
return mNextStream->OnStopRequest(channel, ctxt, status, errorMsg); return mNextStream->OnStopRequest(request, ctxt, status, errorMsg);
} }
NS_IMETHODIMP NS_IMETHODIMP
ImageListener::OnDataAvailable(nsIChannel* channel, nsISupports *ctxt, ImageListener::OnDataAvailable(nsIRequest* request, nsISupports *ctxt,
nsIInputStream *inStr, PRUint32 sourceOffset, PRUint32 count) nsIInputStream *inStr, PRUint32 sourceOffset, PRUint32 count)
{ {
if (nsnull == mNextStream) { if (nsnull == mNextStream) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
return mNextStream->OnDataAvailable(channel, ctxt, inStr, sourceOffset, count); return mNextStream->OnDataAvailable(request, ctxt, inStr, sourceOffset, count);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@@ -260,37 +260,36 @@ nsXBLStreamListener::~nsXBLStreamListener()
} }
} }
/* void onDataAvailable (in nsIChannel channel, in nsISupports ctxt, in nsIInputStream inStr, in unsigned long sourceOffset, in unsigned long count); */
NS_IMETHODIMP NS_IMETHODIMP
nsXBLStreamListener::OnDataAvailable(nsIChannel* aChannel, nsISupports* aCtxt, nsIInputStream* aInStr, nsXBLStreamListener::OnDataAvailable(nsIRequest *request, nsISupports* aCtxt, nsIInputStream* aInStr,
PRUint32 aSourceOffset, PRUint32 aCount) PRUint32 aSourceOffset, PRUint32 aCount)
{ {
if (mInner) if (mInner)
return mInner->OnDataAvailable(aChannel, aCtxt, aInStr, aSourceOffset, aCount); return mInner->OnDataAvailable(request, aCtxt, aInStr, aSourceOffset, aCount);
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
/* void onStartRequest (in nsIChannel channel, in nsISupports ctxt); */
NS_IMETHODIMP NS_IMETHODIMP
nsXBLStreamListener::OnStartRequest(nsIChannel* aChannel, nsISupports* aCtxt) nsXBLStreamListener::OnStartRequest(nsIRequest* request, nsISupports* aCtxt)
{ {
if (mInner) if (mInner)
return mInner->OnStartRequest(aChannel, aCtxt); return mInner->OnStartRequest(request, aCtxt);
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
/* void onStopRequest (in nsIChannel channel, in nsISupports ctxt, in nsresult status, in wstring statusArg); */
NS_IMETHODIMP NS_IMETHODIMP
nsXBLStreamListener::OnStopRequest(nsIChannel* aChannel, nsISupports* aCtxt, nsresult aStatus, const PRUnichar* aStatusArg) nsXBLStreamListener::OnStopRequest(nsIRequest* request, nsISupports* aCtxt, nsresult aStatus, const PRUnichar* aStatusArg)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
if (mInner) { if (mInner) {
rv = mInner->OnStopRequest(aChannel, aCtxt, aStatus, aStatusArg); rv = mInner->OnStopRequest(request, aCtxt, aStatus, aStatusArg);
} }
if (NS_FAILED(rv) || NS_FAILED(aStatus)) if (NS_FAILED(rv) || NS_FAILED(aStatus))
{ {
nsCOMPtr<nsIChannel> aChannel = do_QueryInterface(request);
if (aChannel) if (aChannel)
{ {
nsCOMPtr<nsIURI> channelURI; nsCOMPtr<nsIURI> channelURI;
@@ -1191,7 +1190,7 @@ nsXBLService::FetchBindingDocument(nsIContent* aBoundElement, nsIDocument* aBoun
nsCOMPtr<nsILoadGroup> loadGroup; nsCOMPtr<nsILoadGroup> loadGroup;
if (aBoundDocument) if (aBoundDocument)
aBoundDocument->GetDocumentLoadGroup(getter_AddRefs(loadGroup)); aBoundDocument->GetDocumentLoadGroup(getter_AddRefs(loadGroup));
nsCOMPtr<nsIRequest> request;
nsCOMPtr<nsIChannel> channel; nsCOMPtr<nsIChannel> channel;
rv = NS_OpenURI(getter_AddRefs(channel), aURI, nsnull, loadGroup); rv = NS_OpenURI(getter_AddRefs(channel), aURI, nsnull, loadGroup);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
@@ -1233,18 +1232,22 @@ nsXBLService::FetchBindingDocument(nsIContent* aBoundElement, nsIDocument* aBoun
xblListener->AddRequest(req); xblListener->AddRequest(req);
// Now kick off the async read. // Now kick off the async read.
channel->AsyncRead(xblListener, nsnull); channel->AsyncOpen(xblListener, nsnull);
return NS_OK; return NS_OK;
} }
// Now do a blocking synchronous parse of the file. // Now do a blocking synchronous parse of the file.
nsCOMPtr<nsIInputStream> in; nsCOMPtr<nsIInputStream> in;
PRUint32 sourceOffset = 0; PRUint32 sourceOffset = 0;
rv = channel->OpenInputStream(getter_AddRefs(in)); rv = channel->Open(getter_AddRefs(in));
// If we couldn't open the channel, then just return. // If we couldn't open the channel, then just return.
if (NS_FAILED(rv)) return NS_OK; if (NS_FAILED(rv)) return NS_OK;
request = do_QueryInterface(channel);
NS_ASSERTION(request != nsnull, "no request info");
NS_ASSERTION(in != nsnull, "no input stream"); NS_ASSERTION(in != nsnull, "no input stream");
if (! in) return NS_ERROR_FAILURE; if (! in) return NS_ERROR_FAILURE;
@@ -1253,7 +1256,7 @@ nsXBLService::FetchBindingDocument(nsIContent* aBoundElement, nsIDocument* aBoun
if (! proxy) if (! proxy)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
listener->OnStartRequest(channel, nsnull); listener->OnStartRequest(request, nsnull);
while (PR_TRUE) { while (PR_TRUE) {
char buf[1024]; char buf[1024];
PRUint32 readCount; PRUint32 readCount;
@@ -1266,12 +1269,12 @@ nsXBLService::FetchBindingDocument(nsIContent* aBoundElement, nsIDocument* aBoun
proxy->SetBuffer(buf, readCount); proxy->SetBuffer(buf, readCount);
rv = listener->OnDataAvailable(channel, nsnull, proxy, sourceOffset, readCount); rv = listener->OnDataAvailable(request, nsnull, proxy, sourceOffset, readCount);
sourceOffset += readCount; sourceOffset += readCount;
if (NS_FAILED(rv)) if (NS_FAILED(rv))
break; break;
} }
listener->OnStopRequest(channel, nsnull, NS_OK, nsnull); listener->OnStopRequest(request, nsnull, NS_OK, nsnull);
// don't leak proxy! // don't leak proxy!
proxy->Close(); proxy->Close();

View File

@@ -1669,7 +1669,11 @@ nsXMLContentSink::OnStreamComplete(nsIStreamLoader* aLoader,
if (NS_OK == aStatus) { if (NS_OK == aStatus) {
{ // scope in block so nsCOMPtr released at one point { // scope in block so nsCOMPtr released at one point
nsCOMPtr<nsIChannel> channel; nsCOMPtr<nsIChannel> channel;
aLoader->GetChannel(getter_AddRefs(channel)); nsCOMPtr<nsIRequest> request;
aLoader->GetRequest(getter_AddRefs(request));
if (request)
channel = do_QueryInterface(request);
nsCOMPtr<nsIURI> url; nsCOMPtr<nsIURI> url;
if (channel) { if (channel) {
channel->GetURI(getter_AddRefs(url)); channel->GetURI(getter_AddRefs(url));

View File

@@ -74,6 +74,11 @@
#include "nsIPrincipal.h" #include "nsIPrincipal.h"
#include "nsIAggregatePrincipal.h" #include "nsIAggregatePrincipal.h"
#include "nsCExternalHandlerService.h"
#include "nsIMIMEService.h"
#include "nsNetUtil.h"
#include "nsMimeTypes.h"
// XXX The XML world depends on the html atoms // XXX The XML world depends on the html atoms
#include "nsHTMLAtoms.h" #include "nsHTMLAtoms.h"
@@ -351,7 +356,7 @@ nsXMLDocument::Load(const nsAReadableString& aUrl)
} }
// Start an asynchronous read of the XML document // Start an asynchronous read of the XML document
rv = channel->AsyncRead(listener, nsnull); rv = channel->AsyncOpen(listener, nsnull);
return rv; return rv;
} }
@@ -381,7 +386,9 @@ nsXMLDocument::StartDocumentLoad(const char* aCommand,
rv = aChannel->GetURI(getter_AddRefs(aUrl)); rv = aChannel->GetURI(getter_AddRefs(aUrl));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
rv = aChannel->GetContentType(&aContentType); nsCOMPtr<nsIMIMEService> MIMEService (do_GetService(NS_MIMESERVICE_CONTRACTID, &rv));
if (NS_FAILED(rv)) return rv;
rv = MIMEService->GetTypeFromURI(aUrl, &aContentType);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
if ( 0 == PL_strcmp(aContentType, "text/html")) { if ( 0 == PL_strcmp(aContentType, "text/html")) {

View File

@@ -52,7 +52,7 @@ public:
NS_IMETHOD GetContentType(nsAWritableString& aContentType) const; NS_IMETHOD GetContentType(nsAWritableString& aContentType) const;
NS_IMETHOD StartDocumentLoad(const char* aCommand, NS_IMETHOD StartDocumentLoad(const char* aCommand,
nsIChannel* aChannel, nsIChannel* channel,
nsILoadGroup* aLoadGroup, nsILoadGroup* aLoadGroup,
nsISupports* aContainer, nsISupports* aContainer,
nsIStreamListener **aDocListener, nsIStreamListener **aDocListener,

View File

@@ -31,6 +31,7 @@
#include "nsMimeTypes.h" #include "nsMimeTypes.h"
#include "nsScriptSecurityManager.h" #include "nsScriptSecurityManager.h"
#include "nsIAggregatePrincipal.h" #include "nsIAggregatePrincipal.h"
#include "nsIProgressEventSink.h"
#include "nsXPIDLString.h" #include "nsXPIDLString.h"
static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID); static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID);
@@ -60,13 +61,9 @@ PRLogModuleInfo* gJarProtocolLog = nsnull;
nsJARChannel::nsJARChannel() nsJARChannel::nsJARChannel()
: mLoadAttributes(LOAD_NORMAL), : mLoadAttributes(LOAD_NORMAL),
mStartPosition(0),
mReadCount(-1),
mContentType(nsnull), mContentType(nsnull),
mContentLength(-1), mContentLength(-1),
mJAREntry(nsnull), mJAREntry(nsnull),
mBufferSegmentSize(NS_DEFAULT_JAR_BUFFER_SEGMENT_SIZE),
mBufferMaxSize(NS_DEFAULT_JAR_BUFFER_MAX_SIZE),
mStatus(NS_OK), mStatus(NS_OK),
mMonitor(nsnull) mMonitor(nsnull)
{ {
@@ -255,12 +252,12 @@ nsJARChannel::OpenJARElement()
rv = Open(nsnull, nsnull); rv = Open(nsnull, nsnull);
if (NS_SUCCEEDED(rv)) if (NS_SUCCEEDED(rv))
rv = GetInputStream(getter_AddRefs(mSynchronousInputStream)); rv = GetInputStream(getter_AddRefs(mSynchronousInputStream));
mon.Notify(); // wake up OpenInputStream mon.Notify(); // wake up nsIChannel::Open
return rv; return rv;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsJARChannel::OpenInputStream(nsIInputStream* *result) nsJARChannel::Open(nsIInputStream* *result)
{ {
nsAutoCMonitor mon(this); nsAutoCMonitor mon(this);
nsresult rv; nsresult rv;
@@ -273,7 +270,7 @@ nsJARChannel::OpenInputStream(nsIInputStream* *result)
{ {
*result = mSynchronousInputStream; // Result of GetInputStream called on transport thread *result = mSynchronousInputStream; // Result of GetInputStream called on transport thread
NS_ADDREF(*result); NS_ADDREF(*result);
mSynchronousInputStream = null_nsCOMPtr(); mSynchronousInputStream = 0;
return NS_OK; return NS_OK;
} }
else else
@@ -281,14 +278,7 @@ nsJARChannel::OpenInputStream(nsIInputStream* *result)
} }
NS_IMETHODIMP NS_IMETHODIMP
nsJARChannel::OpenOutputStream(nsIOutputStream* *result) nsJARChannel::AsyncOpen(nsIStreamListener* listener, nsISupports* ctxt)
{
NS_NOTREACHED("nsJARChannel::OpenOutputStream");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsJARChannel::AsyncRead(nsIStreamListener* listener, nsISupports* ctxt)
{ {
nsresult rv; nsresult rv;
mUserContext = ctxt; mUserContext = ctxt;
@@ -310,7 +300,7 @@ nsJARChannel::AsyncRead(nsIStreamListener* listener, nsISupports* ctxt)
} }
} }
} }
rv = mLoadGroup->AddChannel(this, nsnull); rv = mLoadGroup->AddRequest(this, nsnull);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
} }
@@ -342,7 +332,7 @@ nsJARChannel::EnsureJARFileAvailable()
rv = NS_NewDownloader(getter_AddRefs(mDownloader), rv = NS_NewDownloader(getter_AddRefs(mDownloader),
mJARBaseURI, this, nsnull, mSynchronousRead, mLoadGroup, mCallbacks, mJARBaseURI, this, nsnull, mSynchronousRead, mLoadGroup, mCallbacks,
mLoadAttributes, mBufferSegmentSize, mBufferMaxSize); mLoadAttributes);
// if DownloadComplete() was called early, need to release the reference. // if DownloadComplete() was called early, need to release the reference.
if (mSynchronousRead && mSynchronousInputStream) if (mSynchronousRead && mSynchronousInputStream)
@@ -350,7 +340,7 @@ nsJARChannel::EnsureJARFileAvailable()
error: error:
if (NS_FAILED(rv) && mLoadGroup) { if (NS_FAILED(rv) && mLoadGroup) {
nsresult rv2 = mLoadGroup->RemoveChannel(this, nsnull, NS_OK, nsnull); nsresult rv2 = mLoadGroup->RemoveRequest(this, nsnull, NS_OK, nsnull);
NS_ASSERTION(NS_SUCCEEDED(rv2), "RemoveChannel failed"); NS_ASSERTION(NS_SUCCEEDED(rv2), "RemoveChannel failed");
} }
return rv; return rv;
@@ -366,20 +356,16 @@ nsJARChannel::AsyncReadJARElement()
NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv); NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
rv = fts->CreateTransportFromStreamIO(this, nsCOMPtr<nsITransport> jarTransport;
getter_AddRefs(mJarExtractionTransport)); rv = fts->CreateTransportFromStreamIO(this, getter_AddRefs(jarTransport));
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;
rv = mJarExtractionTransport->SetTransferOffset(mStartPosition);
if (NS_FAILED(rv)) return rv;
rv = mJarExtractionTransport->SetTransferCount(mReadCount);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
if (mCallbacks) {
nsCOMPtr<nsIProgressEventSink> sink = do_GetInterface(mCallbacks);
if (sink)
jarTransport->SetProgressEventSink(sink);
}
#ifdef PR_LOGGING #ifdef PR_LOGGING
nsXPIDLCString jarURLStr; nsXPIDLCString jarURLStr;
mURI->GetSpec(getter_Copies(jarURLStr)); mURI->GetSpec(getter_Copies(jarURLStr));
@@ -387,18 +373,10 @@ nsJARChannel::AsyncReadJARElement()
("nsJarProtocol: AsyncRead jar entry %s", (const char*)jarURLStr)); ("nsJarProtocol: AsyncRead jar entry %s", (const char*)jarURLStr));
#endif #endif
rv = mJarExtractionTransport->AsyncRead(this, nsnull); rv = jarTransport->AsyncRead(this, nsnull, 0, -1, 0, getter_AddRefs(mJarExtractionTransport));
return rv; return rv;
} }
NS_IMETHODIMP
nsJARChannel::AsyncWrite(nsIStreamProvider* provider,
nsISupports* ctxt)
{
NS_NOTREACHED("nsJARChannel::AsyncWrite");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP NS_IMETHODIMP
nsJARChannel::GetLoadAttributes(PRUint32* aLoadFlags) nsJARChannel::GetLoadAttributes(PRUint32* aLoadFlags)
{ {
@@ -491,83 +469,6 @@ nsJARChannel::SetContentLength(PRInt32 aContentLength)
return NS_ERROR_NOT_IMPLEMENTED; 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::GetLocalFile(nsIFile* *file)
{
*file = nsnull;
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 NS_IMETHODIMP
nsJARChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup) nsJARChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup)
{ {
@@ -667,7 +568,7 @@ nsJARChannel::OnDownloadComplete(nsIDownloader* aDownloader, nsISupports* aClosu
else else
rv = AsyncReadJARElement(); rv = AsyncReadJARElement();
} }
mDownloader = null_nsCOMPtr(); mDownloader = 0;
return rv; return rv;
} }
@@ -675,14 +576,14 @@ nsJARChannel::OnDownloadComplete(nsIDownloader* aDownloader, nsISupports* aClosu
// nsIStreamObserver methods: // nsIStreamObserver methods:
NS_IMETHODIMP NS_IMETHODIMP
nsJARChannel::OnStartRequest(nsIChannel* jarExtractionTransport, nsJARChannel::OnStartRequest(nsIRequest* jarExtractionTransport,
nsISupports* context) nsISupports* context)
{ {
return mUserListener->OnStartRequest(this, mUserContext); return mUserListener->OnStartRequest(this, mUserContext);
} }
NS_IMETHODIMP NS_IMETHODIMP
nsJARChannel::OnStopRequest(nsIChannel* jarExtractionTransport, nsISupports* context, nsJARChannel::OnStopRequest(nsIRequest* jarExtractionTransport, nsISupports* context,
nsresult aStatus, const PRUnichar* aStatusArg) nsresult aStatus, const PRUnichar* aStatusArg)
{ {
nsresult rv; nsresult rv;
@@ -701,7 +602,7 @@ nsJARChannel::OnStopRequest(nsIChannel* jarExtractionTransport, nsISupports* con
if (mLoadGroup) { if (mLoadGroup) {
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
mLoadGroup->RemoveChannel(this, context, aStatus, aStatusArg); mLoadGroup->RemoveRequest(this, context, aStatus, aStatusArg);
} }
} }
@@ -715,7 +616,7 @@ nsJARChannel::OnStopRequest(nsIChannel* jarExtractionTransport, nsISupports* con
// nsIStreamListener methods: // nsIStreamListener methods:
NS_IMETHODIMP NS_IMETHODIMP
nsJARChannel::OnDataAvailable(nsIChannel* jarCacheTransport, nsJARChannel::OnDataAvailable(nsIRequest* jarCacheTransport,
nsISupports* context, nsISupports* context,
nsIInputStream *inStr, nsIInputStream *inStr,
PRUint32 sourceOffset, PRUint32 sourceOffset,

View File

@@ -89,8 +89,6 @@ protected:
nsLoadFlags mLoadAttributes; nsLoadFlags mLoadAttributes;
nsCOMPtr<nsISupports> mOwner; nsCOMPtr<nsISupports> mOwner;
PRUint32 mStartPosition;
PRInt32 mReadCount;
nsCOMPtr<nsISupports> mUserContext; nsCOMPtr<nsISupports> mUserContext;
nsCOMPtr<nsIStreamListener> mUserListener; nsCOMPtr<nsIStreamListener> mUserListener;
@@ -100,15 +98,13 @@ protected:
char* mJAREntry; char* mJAREntry;
nsCOMPtr<nsIZipReader> mJAR; nsCOMPtr<nsIZipReader> mJAR;
nsCOMPtr<nsIFile> mDownloadedJARFile; nsCOMPtr<nsIFile> mDownloadedJARFile;
PRUint32 mBufferSegmentSize;
PRUint32 mBufferMaxSize;
nsresult mStatus; nsresult mStatus;
PRBool mSynchronousRead; PRBool mSynchronousRead;
nsCOMPtr<nsIInputStream> mSynchronousInputStream; nsCOMPtr<nsIInputStream> mSynchronousInputStream;
PRMonitor* mMonitor; PRMonitor* mMonitor;
nsCOMPtr<nsIDownloader> mDownloader; nsCOMPtr<nsIDownloader> mDownloader;
nsCOMPtr<nsIChannel> mJarExtractionTransport; nsCOMPtr<nsIRequest> mJarExtractionTransport;
}; };

View File

@@ -953,7 +953,7 @@ public:
private: private:
nsresult SetUpCache(nsIURI* aURL); nsresult SetUpCache(nsIURI* aURL);
nsresult SetUpStreamListener(nsIChannel *channel, nsIURI* aURL); nsresult SetUpStreamListener(nsIRequest* request, nsIURI* aURL);
nsIURI *mURL; nsIURI *mURL;
nsIPluginInstanceOwner *mOwner; nsIPluginInstanceOwner *mOwner;
@@ -1014,13 +1014,13 @@ nsPluginCacheListener::~nsPluginCacheListener()
NS_IMPL_ISUPPORTS(nsPluginCacheListener, kIStreamListenerIID); NS_IMPL_ISUPPORTS(nsPluginCacheListener, kIStreamListenerIID);
NS_IMETHODIMP NS_IMETHODIMP
nsPluginCacheListener::OnStartRequest(nsIChannel* channel, nsISupports* ctxt) nsPluginCacheListener::OnStartRequest(nsIRequest *request, nsISupports* ctxt)
{ {
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsPluginCacheListener::OnDataAvailable(nsIChannel* channel, nsISupports* ctxt, nsPluginCacheListener::OnDataAvailable(nsIRequest *request, nsISupports* ctxt,
nsIInputStream* aIStream, nsIInputStream* aIStream,
PRUint32 sourceOffset, PRUint32 sourceOffset,
PRUint32 aLength) PRUint32 aLength)
@@ -1043,7 +1043,7 @@ nsPluginCacheListener::OnDataAvailable(nsIChannel* channel, nsISupports* ctxt,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsPluginCacheListener::OnStopRequest(nsIChannel* channel, nsPluginCacheListener::OnStopRequest(nsIRequest *request,
nsISupports* aContext, nsISupports* aContext,
nsresult aStatus, nsresult aStatus,
const PRUnichar* aMsg) const PRUnichar* aMsg)
@@ -1211,10 +1211,15 @@ nsresult nsPluginStreamListenerPeer::InitializeFullPage(nsIPluginInstance *aInst
NS_IMETHODIMP NS_IMETHODIMP
nsPluginStreamListenerPeer::OnStartRequest(nsIChannel* channel, nsISupports* aContext) nsPluginStreamListenerPeer::OnStartRequest(nsIRequest *request, nsISupports* aContext)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
if (!channel)
return NS_ERROR_FAILURE;
char* aContentType = nsnull; char* aContentType = nsnull;
rv = channel->GetContentType(&aContentType); rv = channel->GetContentType(&aContentType);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
@@ -1287,14 +1292,14 @@ nsPluginStreamListenerPeer::OnStartRequest(nsIChannel* channel, nsISupports* aCo
} }
rv = SetUpStreamListener(channel, aURL); rv = SetUpStreamListener(request, aURL);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
return rv; return rv;
} }
NS_IMETHODIMP nsPluginStreamListenerPeer::OnProgress(nsIChannel* channel, NS_IMETHODIMP nsPluginStreamListenerPeer::OnProgress(nsIRequest *request,
nsISupports* aContext, nsISupports* aContext,
PRUint32 aProgress, PRUint32 aProgress,
PRUint32 aProgressMax) PRUint32 aProgressMax)
@@ -1303,7 +1308,7 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnProgress(nsIChannel* channel,
return rv; return rv;
} }
NS_IMETHODIMP nsPluginStreamListenerPeer::OnStatus(nsIChannel* channel, NS_IMETHODIMP nsPluginStreamListenerPeer::OnStatus(nsIRequest *request,
nsISupports* aContext, nsISupports* aContext,
nsresult aStatus, nsresult aStatus,
const PRUnichar* aStatusArg) const PRUnichar* aStatusArg)
@@ -1311,7 +1316,7 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnStatus(nsIChannel* channel,
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP nsPluginStreamListenerPeer::OnDataAvailable(nsIChannel* channel, NS_IMETHODIMP nsPluginStreamListenerPeer::OnDataAvailable(nsIRequest *request,
nsISupports* aContext, nsISupports* aContext,
nsIInputStream *aIStream, nsIInputStream *aIStream,
PRUint32 sourceOffset, PRUint32 sourceOffset,
@@ -1319,6 +1324,9 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnDataAvailable(nsIChannel* channel,
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsCOMPtr<nsIURI> aURL; nsCOMPtr<nsIURI> aURL;
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
if (!channel) return NS_ERROR_FAILURE;
rv = channel->GetURI(getter_AddRefs(aURL)); rv = channel->GetURI(getter_AddRefs(aURL));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
@@ -1340,7 +1348,7 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnDataAvailable(nsIChannel* channel,
// if a plugin returns an error, the peer must kill the stream // if a plugin returns an error, the peer must kill the stream
// else the stream and PluginStreamListener leak // else the stream and PluginStreamListener leak
if (NS_FAILED(rv)) if (NS_FAILED(rv))
channel->Cancel(rv); request->Cancel(rv);
} }
else else
{ {
@@ -1353,13 +1361,15 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnDataAvailable(nsIChannel* channel,
return rv; return rv;
} }
NS_IMETHODIMP nsPluginStreamListenerPeer::OnStopRequest(nsIChannel* channel, NS_IMETHODIMP nsPluginStreamListenerPeer::OnStopRequest(nsIRequest *request,
nsISupports* aContext, nsISupports* aContext,
nsresult aStatus, nsresult aStatus,
const PRUnichar* aMsg) const PRUnichar* aMsg)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsCOMPtr<nsIURI> aURL; nsCOMPtr<nsIURI> aURL;
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
if (!channel) return NS_ERROR_FAILURE;
rv = channel->GetURI(getter_AddRefs(aURL)); rv = channel->GetURI(getter_AddRefs(aURL));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
@@ -1367,7 +1377,11 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnStopRequest(nsIChannel* channel,
{ {
char* urlString; char* urlString;
nsCOMPtr<nsIFile> localFile; nsCOMPtr<nsIFile> localFile;
rv = channel->GetLocalFile(getter_AddRefs(localFile)); nsCOMPtr<nsIFileChannel> fileChannel = do_QueryInterface(channel);
if (fileChannel)
rv = fileChannel->GetFile(getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv) && localFile) if (NS_SUCCEEDED(rv) && localFile)
{ {
char* pathAndFilename; char* pathAndFilename;
@@ -1422,7 +1436,7 @@ nsresult nsPluginStreamListenerPeer::SetUpCache(nsIURI* aURL)
return NS_OpenURI(cacheListener, nsnull, aURL, nsnull); return NS_OpenURI(cacheListener, nsnull, aURL, nsnull);
} }
nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIChannel* channel, nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIRequest *request,
nsIURI* aURL) nsIURI* aURL)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
@@ -1454,6 +1468,8 @@ nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIChannel* channel,
nsCOMPtr<nsIHTTPHeaderListener> headerListener = nsCOMPtr<nsIHTTPHeaderListener> headerListener =
do_QueryInterface(mPStreamListener); do_QueryInterface(mPStreamListener);
if (headerListener) { if (headerListener) {
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
nsCOMPtr<nsIHTTPChannel> httpChannel = do_QueryInterface(channel); nsCOMPtr<nsIHTTPChannel> httpChannel = do_QueryInterface(channel);
if (httpChannel) { if (httpChannel) {
ReadHeadersFromChannelAndPostToListener(httpChannel, headerListener); ReadHeadersFromChannelAndPostToListener(httpChannel, headerListener);
@@ -1465,6 +1481,8 @@ nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIChannel* channel,
mPluginStreamInfo->SetSeekable(PR_FALSE); mPluginStreamInfo->SetSeekable(PR_FALSE);
// get Last-Modified header for plugin info // get Last-Modified header for plugin info
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
nsCOMPtr<nsIHTTPChannel> theHTTPChannel = do_QueryInterface(channel); nsCOMPtr<nsIHTTPChannel> theHTTPChannel = do_QueryInterface(channel);
if (theHTTPChannel) { if (theHTTPChannel) {
char * lastModified; char * lastModified;
@@ -3806,8 +3824,7 @@ NS_IMETHODIMP nsPluginHostImpl::NewPluginURLStream(const nsString& aURL,
} }
} }
rv = channel->AsyncOpen(listenerPeer, nsnull);
rv = channel->AsyncRead(listenerPeer, nsnull);
} }
NS_RELEASE(listenerPeer); NS_RELEASE(listenerPeer);

View File

@@ -37,6 +37,7 @@ class ns4xPlugin;
class nsFileSpec; class nsFileSpec;
class nsIComponentManager; class nsIComponentManager;
class nsIFile; class nsIFile;
class nsIChannel;
/** /**
* A linked-list of plugin information that is used for * A linked-list of plugin information that is used for

View File

@@ -157,14 +157,14 @@ public:
virtual ~PluginViewerImpl(); virtual ~PluginViewerImpl();
nsresult CreatePlugin(nsIPluginHost* aHost, const nsRect& aBounds, nsresult CreatePlugin(nsIRequest* request, nsIPluginHost* aHost, const nsRect& aBounds,
nsIStreamListener*& aResult); nsIStreamListener*& aResult);
nsresult MakeWindow(nsNativeWidget aParent, nsresult MakeWindow(nsNativeWidget aParent,
nsIDeviceContext* aDeviceContext, nsIDeviceContext* aDeviceContext,
const nsRect& aBounds); const nsRect& aBounds);
nsresult StartLoad(nsIChannel* channel, nsIStreamListener*& aResult); nsresult StartLoad(nsIRequest* request, nsIStreamListener*& aResult);
void ForceRefresh(void); void ForceRefresh(void);
@@ -307,15 +307,18 @@ PluginViewerImpl::Init(nsIWidget* aParentWidget,
} }
nsresult nsresult
PluginViewerImpl::StartLoad(nsIChannel* channel, nsIStreamListener*& aResult) PluginViewerImpl::StartLoad(nsIRequest* request, nsIStreamListener*& aResult)
{ {
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
if (!channel) return NS_ERROR_FAILURE;
NS_IF_RELEASE(mChannel); NS_IF_RELEASE(mChannel);
mChannel = channel; mChannel = channel;
NS_ADDREF(mChannel); NS_ADDREF(mChannel);
#ifdef DEBUG #ifdef DEBUG
char* contentType; char* contentType;
mChannel->GetContentType(&contentType); channel->GetContentType(&contentType);
printf("PluginViewerImpl::StartLoad: content-type=%s\n", contentType); printf("PluginViewerImpl::StartLoad: content-type=%s\n", contentType);
nsCRT::free(contentType); nsCRT::free(contentType);
#endif #endif
@@ -331,14 +334,14 @@ PluginViewerImpl::StartLoad(nsIChannel* channel, nsIStreamListener*& aResult)
{ {
nsRect r; nsRect r;
mWindow->GetClientBounds(r); mWindow->GetClientBounds(r);
rv = CreatePlugin(host, nsRect(0, 0, r.width, r.height), aResult); rv = CreatePlugin(request, host, nsRect(0, 0, r.width, r.height), aResult);
} }
return rv; return rv;
} }
nsresult nsresult
PluginViewerImpl::CreatePlugin(nsIPluginHost* aHost, const nsRect& aBounds, PluginViewerImpl::CreatePlugin(nsIRequest* request, nsIPluginHost* aHost, const nsRect& aBounds,
nsIStreamListener*& aResult) nsIStreamListener*& aResult)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
@@ -372,7 +375,9 @@ PluginViewerImpl::CreatePlugin(nsIPluginHost* aHost, const nsRect& aBounds,
nsCRT::free(spec); nsCRT::free(spec);
char* ct; char* ct;
rv = mChannel->GetContentType(&ct);
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
channel->GetContentType(&ct);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
rv = aHost->InstantiateFullPagePlugin(ct, str, aResult, mOwner); rv = aHost->InstantiateFullPagePlugin(ct, str, aResult, mOwner);
delete[] ct; delete[] ct;
@@ -692,43 +697,45 @@ PluginListener::~PluginListener()
NS_IMPL_ISUPPORTS(PluginListener, kIStreamListenerIID) NS_IMPL_ISUPPORTS(PluginListener, kIStreamListenerIID)
NS_IMETHODIMP NS_IMETHODIMP
PluginListener::OnStartRequest(nsIChannel* channel, nsISupports *ctxt) PluginListener::OnStartRequest(nsIRequest *request, nsISupports *ctxt)
{ {
nsresult rv; nsresult rv;
char* contentType = nsnull; char* contentType = nsnull;
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
rv = channel->GetContentType(&contentType); rv = channel->GetContentType(&contentType);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
return rv; return rv;
} }
rv = mViewer->StartLoad(channel, mNextStream); rv = mViewer->StartLoad(request, mNextStream);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
return rv; return rv;
} }
if (nsnull == mNextStream) if (nsnull == mNextStream)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
return mNextStream->OnStartRequest(channel, ctxt); return mNextStream->OnStartRequest(request, ctxt);
} }
NS_IMETHODIMP NS_IMETHODIMP
PluginListener::OnStopRequest(nsIChannel* channel, nsISupports *ctxt, PluginListener::OnStopRequest(nsIRequest *request, nsISupports *ctxt,
nsresult status, const PRUnichar *errorMsg) nsresult status, const PRUnichar *errorMsg)
{ {
if (nsnull == mNextStream) { if (nsnull == mNextStream) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
return mNextStream->OnStopRequest(channel, ctxt, status, errorMsg); return mNextStream->OnStopRequest(request, ctxt, status, errorMsg);
} }
NS_IMETHODIMP NS_IMETHODIMP
PluginListener::OnDataAvailable(nsIChannel* channel, nsISupports *ctxt, PluginListener::OnDataAvailable(nsIRequest *request, nsISupports *ctxt,
nsIInputStream *inStr, PRUint32 sourceOffset, PRUint32 count) nsIInputStream *inStr, PRUint32 sourceOffset, PRUint32 count)
{ {
if (nsnull == mNextStream) { if (nsnull == mNextStream) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
return mNextStream->OnDataAvailable(channel, ctxt, inStr, sourceOffset, count); return mNextStream->OnDataAvailable(request, ctxt, inStr, sourceOffset, count);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@@ -953,7 +953,7 @@ public:
private: private:
nsresult SetUpCache(nsIURI* aURL); nsresult SetUpCache(nsIURI* aURL);
nsresult SetUpStreamListener(nsIChannel *channel, nsIURI* aURL); nsresult SetUpStreamListener(nsIRequest* request, nsIURI* aURL);
nsIURI *mURL; nsIURI *mURL;
nsIPluginInstanceOwner *mOwner; nsIPluginInstanceOwner *mOwner;
@@ -1014,13 +1014,13 @@ nsPluginCacheListener::~nsPluginCacheListener()
NS_IMPL_ISUPPORTS(nsPluginCacheListener, kIStreamListenerIID); NS_IMPL_ISUPPORTS(nsPluginCacheListener, kIStreamListenerIID);
NS_IMETHODIMP NS_IMETHODIMP
nsPluginCacheListener::OnStartRequest(nsIChannel* channel, nsISupports* ctxt) nsPluginCacheListener::OnStartRequest(nsIRequest *request, nsISupports* ctxt)
{ {
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsPluginCacheListener::OnDataAvailable(nsIChannel* channel, nsISupports* ctxt, nsPluginCacheListener::OnDataAvailable(nsIRequest *request, nsISupports* ctxt,
nsIInputStream* aIStream, nsIInputStream* aIStream,
PRUint32 sourceOffset, PRUint32 sourceOffset,
PRUint32 aLength) PRUint32 aLength)
@@ -1043,7 +1043,7 @@ nsPluginCacheListener::OnDataAvailable(nsIChannel* channel, nsISupports* ctxt,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsPluginCacheListener::OnStopRequest(nsIChannel* channel, nsPluginCacheListener::OnStopRequest(nsIRequest *request,
nsISupports* aContext, nsISupports* aContext,
nsresult aStatus, nsresult aStatus,
const PRUnichar* aMsg) const PRUnichar* aMsg)
@@ -1211,10 +1211,15 @@ nsresult nsPluginStreamListenerPeer::InitializeFullPage(nsIPluginInstance *aInst
NS_IMETHODIMP NS_IMETHODIMP
nsPluginStreamListenerPeer::OnStartRequest(nsIChannel* channel, nsISupports* aContext) nsPluginStreamListenerPeer::OnStartRequest(nsIRequest *request, nsISupports* aContext)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
if (!channel)
return NS_ERROR_FAILURE;
char* aContentType = nsnull; char* aContentType = nsnull;
rv = channel->GetContentType(&aContentType); rv = channel->GetContentType(&aContentType);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
@@ -1287,14 +1292,14 @@ nsPluginStreamListenerPeer::OnStartRequest(nsIChannel* channel, nsISupports* aCo
} }
rv = SetUpStreamListener(channel, aURL); rv = SetUpStreamListener(request, aURL);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
return rv; return rv;
} }
NS_IMETHODIMP nsPluginStreamListenerPeer::OnProgress(nsIChannel* channel, NS_IMETHODIMP nsPluginStreamListenerPeer::OnProgress(nsIRequest *request,
nsISupports* aContext, nsISupports* aContext,
PRUint32 aProgress, PRUint32 aProgress,
PRUint32 aProgressMax) PRUint32 aProgressMax)
@@ -1303,7 +1308,7 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnProgress(nsIChannel* channel,
return rv; return rv;
} }
NS_IMETHODIMP nsPluginStreamListenerPeer::OnStatus(nsIChannel* channel, NS_IMETHODIMP nsPluginStreamListenerPeer::OnStatus(nsIRequest *request,
nsISupports* aContext, nsISupports* aContext,
nsresult aStatus, nsresult aStatus,
const PRUnichar* aStatusArg) const PRUnichar* aStatusArg)
@@ -1311,7 +1316,7 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnStatus(nsIChannel* channel,
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP nsPluginStreamListenerPeer::OnDataAvailable(nsIChannel* channel, NS_IMETHODIMP nsPluginStreamListenerPeer::OnDataAvailable(nsIRequest *request,
nsISupports* aContext, nsISupports* aContext,
nsIInputStream *aIStream, nsIInputStream *aIStream,
PRUint32 sourceOffset, PRUint32 sourceOffset,
@@ -1319,6 +1324,9 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnDataAvailable(nsIChannel* channel,
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsCOMPtr<nsIURI> aURL; nsCOMPtr<nsIURI> aURL;
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
if (!channel) return NS_ERROR_FAILURE;
rv = channel->GetURI(getter_AddRefs(aURL)); rv = channel->GetURI(getter_AddRefs(aURL));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
@@ -1340,7 +1348,7 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnDataAvailable(nsIChannel* channel,
// if a plugin returns an error, the peer must kill the stream // if a plugin returns an error, the peer must kill the stream
// else the stream and PluginStreamListener leak // else the stream and PluginStreamListener leak
if (NS_FAILED(rv)) if (NS_FAILED(rv))
channel->Cancel(rv); request->Cancel(rv);
} }
else else
{ {
@@ -1353,13 +1361,15 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnDataAvailable(nsIChannel* channel,
return rv; return rv;
} }
NS_IMETHODIMP nsPluginStreamListenerPeer::OnStopRequest(nsIChannel* channel, NS_IMETHODIMP nsPluginStreamListenerPeer::OnStopRequest(nsIRequest *request,
nsISupports* aContext, nsISupports* aContext,
nsresult aStatus, nsresult aStatus,
const PRUnichar* aMsg) const PRUnichar* aMsg)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsCOMPtr<nsIURI> aURL; nsCOMPtr<nsIURI> aURL;
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
if (!channel) return NS_ERROR_FAILURE;
rv = channel->GetURI(getter_AddRefs(aURL)); rv = channel->GetURI(getter_AddRefs(aURL));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
@@ -1367,7 +1377,11 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnStopRequest(nsIChannel* channel,
{ {
char* urlString; char* urlString;
nsCOMPtr<nsIFile> localFile; nsCOMPtr<nsIFile> localFile;
rv = channel->GetLocalFile(getter_AddRefs(localFile)); nsCOMPtr<nsIFileChannel> fileChannel = do_QueryInterface(channel);
if (fileChannel)
rv = fileChannel->GetFile(getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv) && localFile) if (NS_SUCCEEDED(rv) && localFile)
{ {
char* pathAndFilename; char* pathAndFilename;
@@ -1422,7 +1436,7 @@ nsresult nsPluginStreamListenerPeer::SetUpCache(nsIURI* aURL)
return NS_OpenURI(cacheListener, nsnull, aURL, nsnull); return NS_OpenURI(cacheListener, nsnull, aURL, nsnull);
} }
nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIChannel* channel, nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIRequest *request,
nsIURI* aURL) nsIURI* aURL)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
@@ -1454,6 +1468,8 @@ nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIChannel* channel,
nsCOMPtr<nsIHTTPHeaderListener> headerListener = nsCOMPtr<nsIHTTPHeaderListener> headerListener =
do_QueryInterface(mPStreamListener); do_QueryInterface(mPStreamListener);
if (headerListener) { if (headerListener) {
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
nsCOMPtr<nsIHTTPChannel> httpChannel = do_QueryInterface(channel); nsCOMPtr<nsIHTTPChannel> httpChannel = do_QueryInterface(channel);
if (httpChannel) { if (httpChannel) {
ReadHeadersFromChannelAndPostToListener(httpChannel, headerListener); ReadHeadersFromChannelAndPostToListener(httpChannel, headerListener);
@@ -1465,6 +1481,8 @@ nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIChannel* channel,
mPluginStreamInfo->SetSeekable(PR_FALSE); mPluginStreamInfo->SetSeekable(PR_FALSE);
// get Last-Modified header for plugin info // get Last-Modified header for plugin info
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
nsCOMPtr<nsIHTTPChannel> theHTTPChannel = do_QueryInterface(channel); nsCOMPtr<nsIHTTPChannel> theHTTPChannel = do_QueryInterface(channel);
if (theHTTPChannel) { if (theHTTPChannel) {
char * lastModified; char * lastModified;
@@ -3806,8 +3824,7 @@ NS_IMETHODIMP nsPluginHostImpl::NewPluginURLStream(const nsString& aURL,
} }
} }
rv = channel->AsyncOpen(listenerPeer, nsnull);
rv = channel->AsyncRead(listenerPeer, nsnull);
} }
NS_RELEASE(listenerPeer); NS_RELEASE(listenerPeer);

View File

@@ -37,6 +37,7 @@ class ns4xPlugin;
class nsFileSpec; class nsFileSpec;
class nsIComponentManager; class nsIComponentManager;
class nsIFile; class nsIFile;
class nsIChannel;
/** /**
* A linked-list of plugin information that is used for * A linked-list of plugin information that is used for

View File

@@ -157,14 +157,14 @@ public:
virtual ~PluginViewerImpl(); virtual ~PluginViewerImpl();
nsresult CreatePlugin(nsIPluginHost* aHost, const nsRect& aBounds, nsresult CreatePlugin(nsIRequest* request, nsIPluginHost* aHost, const nsRect& aBounds,
nsIStreamListener*& aResult); nsIStreamListener*& aResult);
nsresult MakeWindow(nsNativeWidget aParent, nsresult MakeWindow(nsNativeWidget aParent,
nsIDeviceContext* aDeviceContext, nsIDeviceContext* aDeviceContext,
const nsRect& aBounds); const nsRect& aBounds);
nsresult StartLoad(nsIChannel* channel, nsIStreamListener*& aResult); nsresult StartLoad(nsIRequest* request, nsIStreamListener*& aResult);
void ForceRefresh(void); void ForceRefresh(void);
@@ -307,15 +307,18 @@ PluginViewerImpl::Init(nsIWidget* aParentWidget,
} }
nsresult nsresult
PluginViewerImpl::StartLoad(nsIChannel* channel, nsIStreamListener*& aResult) PluginViewerImpl::StartLoad(nsIRequest* request, nsIStreamListener*& aResult)
{ {
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
if (!channel) return NS_ERROR_FAILURE;
NS_IF_RELEASE(mChannel); NS_IF_RELEASE(mChannel);
mChannel = channel; mChannel = channel;
NS_ADDREF(mChannel); NS_ADDREF(mChannel);
#ifdef DEBUG #ifdef DEBUG
char* contentType; char* contentType;
mChannel->GetContentType(&contentType); channel->GetContentType(&contentType);
printf("PluginViewerImpl::StartLoad: content-type=%s\n", contentType); printf("PluginViewerImpl::StartLoad: content-type=%s\n", contentType);
nsCRT::free(contentType); nsCRT::free(contentType);
#endif #endif
@@ -331,14 +334,14 @@ PluginViewerImpl::StartLoad(nsIChannel* channel, nsIStreamListener*& aResult)
{ {
nsRect r; nsRect r;
mWindow->GetClientBounds(r); mWindow->GetClientBounds(r);
rv = CreatePlugin(host, nsRect(0, 0, r.width, r.height), aResult); rv = CreatePlugin(request, host, nsRect(0, 0, r.width, r.height), aResult);
} }
return rv; return rv;
} }
nsresult nsresult
PluginViewerImpl::CreatePlugin(nsIPluginHost* aHost, const nsRect& aBounds, PluginViewerImpl::CreatePlugin(nsIRequest* request, nsIPluginHost* aHost, const nsRect& aBounds,
nsIStreamListener*& aResult) nsIStreamListener*& aResult)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
@@ -372,7 +375,9 @@ PluginViewerImpl::CreatePlugin(nsIPluginHost* aHost, const nsRect& aBounds,
nsCRT::free(spec); nsCRT::free(spec);
char* ct; char* ct;
rv = mChannel->GetContentType(&ct);
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
channel->GetContentType(&ct);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
rv = aHost->InstantiateFullPagePlugin(ct, str, aResult, mOwner); rv = aHost->InstantiateFullPagePlugin(ct, str, aResult, mOwner);
delete[] ct; delete[] ct;
@@ -692,43 +697,45 @@ PluginListener::~PluginListener()
NS_IMPL_ISUPPORTS(PluginListener, kIStreamListenerIID) NS_IMPL_ISUPPORTS(PluginListener, kIStreamListenerIID)
NS_IMETHODIMP NS_IMETHODIMP
PluginListener::OnStartRequest(nsIChannel* channel, nsISupports *ctxt) PluginListener::OnStartRequest(nsIRequest *request, nsISupports *ctxt)
{ {
nsresult rv; nsresult rv;
char* contentType = nsnull; char* contentType = nsnull;
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
rv = channel->GetContentType(&contentType); rv = channel->GetContentType(&contentType);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
return rv; return rv;
} }
rv = mViewer->StartLoad(channel, mNextStream); rv = mViewer->StartLoad(request, mNextStream);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
return rv; return rv;
} }
if (nsnull == mNextStream) if (nsnull == mNextStream)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
return mNextStream->OnStartRequest(channel, ctxt); return mNextStream->OnStartRequest(request, ctxt);
} }
NS_IMETHODIMP NS_IMETHODIMP
PluginListener::OnStopRequest(nsIChannel* channel, nsISupports *ctxt, PluginListener::OnStopRequest(nsIRequest *request, nsISupports *ctxt,
nsresult status, const PRUnichar *errorMsg) nsresult status, const PRUnichar *errorMsg)
{ {
if (nsnull == mNextStream) { if (nsnull == mNextStream) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
return mNextStream->OnStopRequest(channel, ctxt, status, errorMsg); return mNextStream->OnStopRequest(request, ctxt, status, errorMsg);
} }
NS_IMETHODIMP NS_IMETHODIMP
PluginListener::OnDataAvailable(nsIChannel* channel, nsISupports *ctxt, PluginListener::OnDataAvailable(nsIRequest *request, nsISupports *ctxt,
nsIInputStream *inStr, PRUint32 sourceOffset, PRUint32 count) nsIInputStream *inStr, PRUint32 sourceOffset, PRUint32 count)
{ {
if (nsnull == mNextStream) { if (nsnull == mNextStream) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
return mNextStream->OnDataAvailable(channel, ctxt, inStr, sourceOffset, count); return mNextStream->OnDataAvailable(request, ctxt, inStr, sourceOffset, count);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@@ -16,6 +16,7 @@ nsIRequest.idl
nsISocketTransportService.idl nsISocketTransportService.idl
nsIStreamIO.idl nsIStreamIO.idl
nsIStreamListener.idl nsIStreamListener.idl
nsITransport.idl
nsIStreamLoader.idl nsIStreamLoader.idl
nsIDownloader.idl nsIDownloader.idl
nsIStreamObserver.idl nsIStreamObserver.idl

View File

@@ -55,6 +55,7 @@ XPIDLSRCS = \
nsIStreamListener.idl \ nsIStreamListener.idl \
nsIStreamProvider.idl \ nsIStreamProvider.idl \
nsIStreamLoader.idl \ nsIStreamLoader.idl \
nsITransport.idl \
nsISocketTransport.idl \ nsISocketTransport.idl \
nsIURI.idl \ nsIURI.idl \
nsIURL.idl \ nsIURL.idl \

View File

@@ -53,11 +53,13 @@ XPIDLSRCS = \
.\nsISocketTransport.idl \ .\nsISocketTransport.idl \
.\nsISocketTransportService.idl \ .\nsISocketTransportService.idl \
.\nsIStreamIO.idl \ .\nsIStreamIO.idl \
.\nsIStreamObserver.idl \
.\nsIStreamListener.idl \ .\nsIStreamListener.idl \
.\nsIStreamProvider.idl \ .\nsIStreamProvider.idl \
.\nsIStreamLoader.idl \ .\nsIStreamLoader.idl \
.\nsIStreamProvider.idl \
.\nsITransport.idl \
.\nsIDownloader.idl \ .\nsIDownloader.idl \
.\nsIStreamObserver.idl \
.\nsIURI.idl \ .\nsIURI.idl \
.\nsIURL.idl \ .\nsIURL.idl \
.\nsIURLParser.idl \ .\nsIURLParser.idl \

View File

@@ -36,35 +36,24 @@ interface nsIStreamIO;
typedef unsigned long nsLoadFlags; typedef unsigned long nsLoadFlags;
/** /**
* The nsIChannel interface allows the user to construct I/O requests for * The nsIChannel interface allows the user to construct get requests for
* specific protocols, and manage them in a uniform way. Once a channel * specific protocols, and manage them in a uniform way. Once a channel
* is created (via nsIIOService::NewChannel), parameters for that request * is created (via nsIIOService::NewChannel), parameters for that request
* may be set by using the channel attributes, or by QueryInterfacing to a * may be set by using the channel attributes, or by QueryInterfacing to a
* subclass of nsIChannel for protocol-specific parameters. Then the actual * subclass of nsIChannel for protocol-specific parameters. Then the actual
* request can be issued in one of several ways: * request can be issued in one of several ways:
* *
* - AsyncRead and AsyncWrite allow for asynchronous requests, calling * - AsyncOpen is used for asynchronous reading, calling back the
* back the user's stream listener or provider, * user's stream listener.
* - OpenInputStream and OpenOutputStream allow for synchronous reads * - Open is used for synchronous read on the underlying channel.
* and writes on the underlying channel.
* *
* After a request has been completed, the channel is still valid for * After a request has been completed, the channel is still valid for
* accessing protocol-specific results. For example, QueryInterfacing to * accessing protocol-specific results. For example, QueryInterfacing to
* nsIHTTPChannel allows response headers to be retrieved that result from * nsIHTTPChannel allows response headers to be retrieved that result from
* http transactions. * 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.
*/ */
[scriptable, uuid(1788e79e-f947-11d3-8cda-0060b0fc14a3)] [scriptable, uuid(1788e79e-f947-11d3-8cda-0060b0fc14a3)]
interface nsIChannel : nsIRequest interface nsIChannel : nsIRequest
{ {
@@ -91,52 +80,6 @@ interface nsIChannel : nsIRequest
*/ */
attribute nsIURI URI; 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 * Accesses the owner corresponding to the entity that is
* responsible for this channel. Used by security code to grant * responsible for this channel. Used by security code to grant
@@ -153,6 +96,15 @@ interface nsIChannel : nsIRequest
*/ */
attribute nsILoadGroup loadGroup; attribute nsILoadGroup loadGroup;
/**
* 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;
/** /**
* Accesses the capabilities callbacks of the channel. This is set by clients * 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 * who wish to provide a means to receive progress, status and protocol-specific
@@ -166,37 +118,31 @@ interface nsIChannel : nsIRequest
readonly attribute nsISupports securityInfo; readonly attribute nsISupports securityInfo;
/** /**
* Accesses the buffer segment size. The buffer segment size is used as * Returns the content MIME type of the channel if available. Note that the
* the initial size for any transfer buffers, and the increment size for * content type can often be wrongly specified (wrong file extension, wrong
* whenever the buffer space needs to be grown. * MIME type, wrong document type stored on a server, etc.) and the caller
* (Note this parameter is passed along to any underlying nsIPipe objects.) * most likely wants to verify with the actual data.
* If unspecified, the channel implementation picks a default.
*/ */
attribute unsigned long bufferSegmentSize; attribute string contentType;
/** /**
* Accesses the buffer maximum size. The buffer maximum size is the limit * Returns the length of the data associated with the channel if available.
* size that buffer will be grown to before suspending the channel. * If the length is unknown then -1 is returned.
* (Note this parameter is passed along to any underlying nsIPipe objects.)
* If unspecified, the channel implementation picks a default.
*/ */
attribute unsigned long bufferMaxSize; attribute long contentLength;
/** /**
* Returns a local file to the channel's data if one exists, null otherwise. * Open is used for synchronous read on the channel.
*/ **/
readonly attribute nsIFile localFile; nsIInputStream open();
/** /** AsyncOpen is used for asynchronous reading, calling back the
* Setting pipeliningAllowed causes the load of a URL (issued via * user's stream listener.
* asyncRead or asyncWrite) to be deferred in order to allow the request to **/
* be pipelined for greater throughput efficiency. Pipelined requests will void asyncOpen(in nsIStreamListener listener, in nsISupports ctxt);
* be forced to load when the first non-pipelined request is issued.
*/
attribute boolean pipeliningAllowed;
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Load attribute flags. These may be or'd together. // Below are Load attribute flags which may be or'd together.
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
/** /**
* Note that more will follow for each protocol's implementation of a channel, * Note that more will follow for each protocol's implementation of a channel,
@@ -287,41 +233,7 @@ interface nsIChannel : nsIRequest
*/ */
const unsigned long LOAD_REPLACE = 1 << 16; const unsigned long LOAD_REPLACE = 1 << 16;
////////////////////////////////////////////////////////////////////////////
// nsIChannel operations
////////////////////////////////////////////////////////////////////////////
/**
* Opens a blocking input stream to the URI's specified source. This
* call may block until the input stream is available.
*/
nsIInputStream openInputStream();
/**
* Opens a blocking output stream to the URI's specified destination. This
* call may block until the output stream is available.
*/
nsIOutputStream openOutputStream();
/**
* Reads asynchronously from the URI's specified source. Notifications
* are provided to the stream listener on the calling thread.
*
* @param listener - notification handler.
* @param ctxt - application context passed to methods invoked on listener.
*/
void asyncRead(in nsIStreamListener listener,
in nsISupports ctxt);
/**
* Writes asynchronously to the URI's specified destination. Notifications
* are provided to the stream provider on the calling thread.
*
* @param provider - notification handler.
* @param ctxt - application context passed to methods invoked on provider.
*/
void asyncWrite(in nsIStreamProvider provider,
in nsISupports ctxt);
}; };
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -334,8 +246,7 @@ interface nsIChannel : nsIRequest
[scriptable, uuid(308362ce-0d06-11d4-986e-00c04fa0cf4a)] [scriptable, uuid(308362ce-0d06-11d4-986e-00c04fa0cf4a)]
interface nsIStreamIOChannel : nsIChannel interface nsIStreamIOChannel : nsIChannel
{ {
void init(in nsIURI uri, void init(in nsIURI uri, in nsIStreamIO io);
in nsIStreamIO io);
}; };
%{C++ %{C++

View File

@@ -48,9 +48,7 @@ interface nsIDownloader : nsISupports
in boolean synchronous, in boolean synchronous,
in nsILoadGroup loadGroup, in nsILoadGroup loadGroup,
in nsIInterfaceRequestor notificationCallbacks, in nsIInterfaceRequestor notificationCallbacks,
in nsLoadFlags loadAttributes, in nsLoadFlags loadAttributes);
in unsigned long bufferSegmentSize,
in unsigned long bufferMaxSize);
}; };
%{C++ %{C++

View File

@@ -25,7 +25,7 @@
#include "nsFileSpec.h" #include "nsFileSpec.h"
%} %}
interface nsIChannel; interface nsITransport;
interface nsIEventSinkGetter; interface nsIEventSinkGetter;
interface nsIInputStream; interface nsIInputStream;
interface nsIRunnable; interface nsIRunnable;
@@ -35,18 +35,18 @@ interface nsIStreamIO;
[scriptable, uuid(57211a60-8c45-11d3-93ac-00104ba0fd40)] [scriptable, uuid(57211a60-8c45-11d3-93ac-00104ba0fd40)]
interface nsIFileTransportService : nsISupports interface nsIFileTransportService : nsISupports
{ {
nsIChannel createTransport(in nsIFile file, nsITransport createTransport(in nsIFile file,
in long ioFlags, in long ioFlags,
in long perm); in long perm);
// This version can be used with an existing input stream to serve // This version can be used with an existing input stream to serve
// as a data pump: // as a data pump:
nsIChannel createTransportFromStream(in string name, nsITransport createTransportFromStream(in string name,
in nsIInputStream fromStream, in nsIInputStream fromStream,
in string contentType, in string contentType,
in long contentLength); in long contentLength);
nsIChannel createTransportFromStreamIO(in nsIStreamIO io); nsITransport createTransportFromStreamIO(in nsIStreamIO io);
void dispatchRequest(in nsIRunnable runnable); void dispatchRequest(in nsIRunnable runnable);
void processPendingRequests(); void processPendingRequests();

View File

@@ -104,15 +104,6 @@ interface nsIIOService : nsISupports
*/ */
attribute boolean offline; attribute boolean offline;
/**
* Consumes all input from the channel, feading data to the specified stream
* listener. The function does not return until either all the data is
* consumed, or an error occurs.
*/
void consumeInput(in nsIChannel channel,
in nsISupports ctxt,
in nsIStreamListener consumer);
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// URL parsing utilities // URL parsing utilities

View File

@@ -23,6 +23,7 @@
#include "nsIRequest.idl" #include "nsIRequest.idl"
interface nsIChannel; interface nsIChannel;
interface nsIRequest;
interface nsISimpleEnumerator; interface nsISimpleEnumerator;
interface nsIStreamObserver; interface nsIStreamObserver;
interface nsIStreamListener; interface nsIStreamListener;
@@ -52,35 +53,35 @@ interface nsILoadGroup : nsIRequest
/** /**
* Accesses the default load channel for the group. Each time a number * Accesses the default load channel for the group. Each time a number
* of channels are added to a group, the DefaultLoadChannel may be set * of request are added to a group, the DefaultLoadChannel may be set
* to indicate that all of the channels are related to a particular URL. * to indicate that all of the requests are related to a particular URL.
*/ */
attribute nsIChannel defaultLoadChannel; attribute nsIRequest defaultLoadRequest;
/** /**
* Adds a new channel to the group. This will cause the default load * Adds a new request to the group. This will cause the default load
* attributes to be applied to that channel. If the channel added is * attributes to be applied to that request. If the request added is
* the first channel in the group, the group's observer's OnStartRequest * the first request in the group, the group's observer's OnStartRequest
* method is called. * method is called.
*/ */
void addChannel(in nsIChannel channel, void addRequest(in nsIRequest request,
in nsISupports ctxt); in nsISupports ctxt);
/** /**
* Removes a channel from the group. If the channel removed is * Removes a request from the group. If the request removed is
* the last channel in the group, the group's observer's OnStopRequest * the last request in the group, the group's observer's OnStopRequest
* method is called. * method is called.
*/ */
void removeChannel(in nsIChannel channel, void removeRequest(in nsIRequest request,
in nsISupports ctxt, in nsISupports ctxt,
in nsresult status, in nsresult status,
in wstring statusArg); in wstring statusArg);
/** /**
* Returns the channels contained directly in this group. * Returns the requests contained directly in this group.
* Enumerator element type: nsIChannel. * Enumerator element type: nsIRequest.
*/ */
readonly attribute nsISimpleEnumerator channels; readonly attribute nsISimpleEnumerator requests;
attribute nsIStreamObserver groupObserver; attribute nsIStreamObserver groupObserver;

View File

@@ -23,7 +23,7 @@
#include "nsISupports.idl" #include "nsISupports.idl"
interface nsIURI; interface nsIURI;
interface nsIChannel; interface nsIRequest;
/** /**
* An instance of nsIFfpEventSink should be passed as the eventSink * An instance of nsIFfpEventSink should be passed as the eventSink
@@ -34,9 +34,9 @@ interface nsIChannel;
interface nsIProgressEventSink : nsISupports interface nsIProgressEventSink : nsISupports
{ {
/** /**
* Notify the EventSink that progress as occurred for the URL load.<BR> * Notify the EventSink that progress has occurred for the URL load.<BR>
*/ */
void onProgress(in nsIChannel channel, void onProgress(in nsIRequest request,
in nsISupports ctxt, in nsISupports ctxt,
in unsigned long aProgress, in unsigned long aProgress,
in unsigned long aProgressMax); in unsigned long aProgressMax);
@@ -52,7 +52,7 @@ interface nsIProgressEventSink : nsISupports
* message. Multiple arguments can be passed by delimiting them * message. Multiple arguments can be passed by delimiting them
* with newline ('\n') characters. * with newline ('\n') characters.
*/ */
void onStatus(in nsIChannel channel, void onStatus(in nsIRequest request,
in nsISupports ctxt, in nsISupports ctxt,
in nsresult status, in nsresult status,
in wstring statusArg); in wstring statusArg);

View File

@@ -20,11 +20,14 @@
* Contributor(s): * Contributor(s):
*/ */
#include "nsISupports.idl" #include "nsITransport.idl"
[scriptable, uuid(785CA0F0-C39E-11d3-9ED6-0010A4053FD0)] [scriptable, uuid(785CA0F0-C39E-11d3-9ED6-0010A4053FD0)]
interface nsISocketTransport : nsISupports interface nsISocketTransport : nsITransport
{ {
readonly attribute string host;
readonly attribute long port;
/** /**
* *
*/ */

View File

@@ -22,8 +22,9 @@
#include "nsISupports.idl" #include "nsISupports.idl"
interface nsIChannel; interface nsITransport;
interface nsIEventSinkGetter; interface nsIEventSinkGetter;
interface nsIChannel;
[scriptable, uuid(05331390-6884-11d3-9382-00104ba0fd40)] [scriptable, uuid(05331390-6884-11d3-9382-00104ba0fd40)]
interface nsISocketTransportService : nsISupports interface nsISocketTransportService : nsISupports
@@ -36,14 +37,14 @@ interface nsISocketTransportService : nsISupports
* etc. The printHost contains the actual hostname (and not the * etc. The printHost contains the actual hostname (and not the
* proxy) for displaying in status messages. * proxy) for displaying in status messages.
*/ */
nsIChannel createTransport(in string host, nsITransport createTransport(in string host,
in long port, in long port,
in string proxyHost, in string proxyHost,
in long proxyPort, in long proxyPort,
in unsigned long bufferSegmentSize, in unsigned long bufferSegmentSize,
in unsigned long bufferMaxSize); in unsigned long bufferMaxSize);
nsIChannel createTransportOfType(in string socketType, nsITransport createTransportOfType(in string socketType,
in string host, in string host,
in long port, in long port,
in string proxyHost, in string proxyHost,
@@ -51,7 +52,7 @@ interface nsISocketTransportService : nsISupports
in unsigned long bufferSegmentSize, in unsigned long bufferSegmentSize,
in unsigned long bufferMaxSize); in unsigned long bufferMaxSize);
nsIChannel createTransportOfTypes(in unsigned long typeCount, nsITransport createTransportOfTypes(in unsigned long typeCount,
[array, size_is(typeCount)] in string socketTypes, [array, size_is(typeCount)] in string socketTypes,
in string host, in string host,
in long port, in long port,
@@ -66,11 +67,11 @@ interface nsISocketTransportService : nsISupports
* include- an error including server resets, an explicit * include- an error including server resets, an explicit
* Connection: close header (for HTTP) and timeouts! * Connection: close header (for HTTP) and timeouts!
*/ */
boolean reuseTransport(in nsIChannel i_Transport); boolean reuseTransport(in nsITransport i_Transport);
void init (); void init ();
void shutdown(); void shutdown();
void wakeup (in nsIChannel i_Transport); void wakeup (in nsITransport i_Transport);
/** /**
* Total number of nsSocketTransport objects currently alive * Total number of nsSocketTransport objects currently alive

View File

@@ -22,7 +22,7 @@
#include "nsIStreamObserver.idl" #include "nsIStreamObserver.idl"
interface nsIChannel; interface nsIRequest;
interface nsIInputStream; interface nsIInputStream;
interface nsIOutputStream; interface nsIOutputStream;
interface nsIEventQueue; interface nsIEventQueue;
@@ -37,7 +37,7 @@ interface nsIStreamListener : nsIStreamObserver
/** /**
* Called when there is data to be read from the channel. * Called when there is data to be read from the channel.
* *
* @param channel - the channel being read * @param request - the request returned by AsyncRead
* @param ctxt - opaque parameter passed to AsyncRead * @param ctxt - opaque parameter passed to AsyncRead
* @param input - temporary input stream for reading data chunk * @param input - temporary input stream for reading data chunk
* @param offset - current stream position (informational) * @param offset - current stream position (informational)
@@ -52,7 +52,7 @@ interface nsIStreamListener : nsIStreamObserver
* becomes available. * becomes available.
* @return <other-error> - if failure. * @return <other-error> - if failure.
*/ */
void onDataAvailable(in nsIChannel channel, void onDataAvailable(in nsIRequest request,
in nsISupports ctxt, in nsISupports ctxt,
in nsIInputStream input, in nsIInputStream input,
in unsigned long offset, in unsigned long offset,

View File

@@ -23,6 +23,7 @@
#include "nsISupports.idl" #include "nsISupports.idl"
#include "nsIChannel.idl" #include "nsIChannel.idl"
interface nsIRequest;
interface nsIURI; interface nsIURI;
interface nsILoadGroup; interface nsILoadGroup;
interface nsIStreamObserver; interface nsIStreamObserver;
@@ -47,9 +48,7 @@ interface nsIStreamLoader : nsISupports
in nsISupports ctxt, in nsISupports ctxt,
in nsILoadGroup loadGroup, in nsILoadGroup loadGroup,
in nsIInterfaceRequestor notificationCallbacks, in nsIInterfaceRequestor notificationCallbacks,
in nsLoadFlags loadAttributes, in nsLoadFlags loadAttributes);
in unsigned long bufferSegmentSize,
in unsigned long bufferMaxSize);
/** /**
* Gets the number of bytes read so far. * Gets the number of bytes read so far.
@@ -57,9 +56,9 @@ interface nsIStreamLoader : nsISupports
readonly attribute unsigned long numBytesRead; readonly attribute unsigned long numBytesRead;
/** /**
* Gets the channel that loaded this file * Gets the request that loaded this file
*/ */
readonly attribute nsIChannel channel; readonly attribute nsIRequest request;
}; };

View File

@@ -22,7 +22,7 @@
#include "nsISupports.idl" #include "nsISupports.idl"
interface nsIChannel; interface nsIRequest;
interface nsIEventQueue; interface nsIEventQueue;
[scriptable, uuid(fd91e2e0-1481-11d3-9333-00104ba0fd40)] [scriptable, uuid(fd91e2e0-1481-11d3-9333-00104ba0fd40)]
@@ -31,22 +31,22 @@ interface nsIStreamObserver : nsISupports
/** /**
* Called to signify the beginning of an asynchronous request. * Called to signify the beginning of an asynchronous request.
* *
* @param channel - channel being observed * @param request - request being observed
* @param ctxt - user specified data passed to AsyncRead/Write * @param ctxt - user specified data passed to AsyncRead/Write
*/ */
void onStartRequest(in nsIChannel channel, void onStartRequest(in nsIRequest request,
in nsISupports ctxt); in nsISupports ctxt);
/** /**
* Called to signify the end of an asynchronous request. This * Called to signify the end of an asynchronous request. This
* call is always preceded by a call to onStartRequest. * call is always preceded by a call to onStartRequest.
* *
* @param channel - channel being observed * @param request - request being observed
* @param ctxt - user specified data passed to AsyncRead/Write * @param ctxt - user specified data passed to AsyncRead/Write
* @param statusCode - reason for stopping (NS_OK if completed successfully) * @param statusCode - reason for stopping (NS_OK if completed successfully)
* @param statusText - human readable reason for stopping (can be NULL) * @param statusText - human readable reason for stopping (can be NULL)
*/ */
void onStopRequest(in nsIChannel channel, void onStopRequest(in nsIRequest request,
in nsISupports ctxt, in nsISupports ctxt,
in nsresult statusCode, in nsresult statusCode,
in wstring statusText); in wstring statusText);

View File

@@ -37,7 +37,7 @@ interface nsIStreamProvider : nsIStreamObserver
/** /**
* Called when data may be written to the channel. * Called when data may be written to the channel.
* *
* @param channel - the channel being written to * @param request - the request returned by AsyncWrite
* @param ctxt - opaque parameter passed to AsyncWrite * @param ctxt - opaque parameter passed to AsyncWrite
* @param output - output stream for writing data chunk * @param output - output stream for writing data chunk
* @param offset - current stream position (informational) * @param offset - current stream position (informational)
@@ -52,7 +52,7 @@ interface nsIStreamProvider : nsIStreamObserver
* becomes available. * becomes available.
* @return <other-error> - if failure. * @return <other-error> - if failure.
*/ */
void onDataWritable(in nsIChannel channel, void onDataWritable(in nsIRequest request,
in nsISupports ctxt, in nsISupports ctxt,
in nsIOutputStream output, in nsIOutputStream output,
in unsigned long offset, in unsigned long offset,

View File

@@ -0,0 +1,105 @@
/* -*- Mode: C++; tab-width: 2; 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):
*/
#include "nsISupports.idl"
#include "nsIRequest.idl"
interface nsIStreamListener;
interface nsIStreamProvider;
interface nsIInputStream;
interface nsIOutputStream;
interface nsIProgressEventSink;
[scriptable, uuid(fd01f9a4-d492-4cf8-b76e-160ffc8c01e8)]
interface nsITransport : nsISupports
{
/**
* Get security info for this transport.
*/
readonly attribute nsISupports securityInfo;
/**
* Get/set the progress event sink for this transport.
*/
attribute nsIProgressEventSink progressEventSink;
/**
* Open an input stream on this transport.
*
* @param offset - read starting at this offset
* @param count - read this many bytes
* @param flags - optional transport specific flags
*/
nsIInputStream openInputStream(in unsigned long offset,
in unsigned long count,
in unsigned long flags);
/**
* Open an output stream on this transport.
*
* @param offset - write starting at this offset
* @param count - write no more than this many bytes
* @param flags - optional transport specific flags
*/
nsIOutputStream openOutputStream(in unsigned long offset,
in unsigned long count,
in unsigned long flags);
/**
* Asynchronously read data from the transport.
*
* @param listener - notify this listener when data is available
* @param ctxt - opaque parameter passed to listener methods
* @param offset - read starting at this offset
* @param count - read this many bytes
* @param flags - optional transport specific flags
*/
nsIRequest asyncRead(in nsIStreamListener listener,
in nsISupports ctxt,
in unsigned long offset,
in unsigned long count,
in unsigned long flags);
/**
* Asynchronously write data to the transport.
*
* @param provider - notify this provider when data can be written
* @param ctxt - opaque parameter passed to provider methods
* @param offset - write starting at this offset
* @param count - write this many bytes
* @param flags - optional transport specific flags
*/
nsIRequest asyncWrite(in nsIStreamProvider provider,
in nsISupports ctxt,
in unsigned long offset,
in unsigned long count,
in unsigned long flags);
};
[scriptable, uuid(d7abf5a4-ce72-482a-9217-a219a905c019)]
interface nsITransportRequest : nsIRequest
{
/**
* Get the transport associated with this request.
*/
readonly attribute nsITransport transport;
};

View File

@@ -36,6 +36,7 @@
#include "nsIIOService.h" #include "nsIIOService.h"
#include "nsIServiceManager.h" #include "nsIServiceManager.h"
#include "nsIChannel.h" #include "nsIChannel.h"
#include "nsITransport.h"
#include "nsMemory.h" #include "nsMemory.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsIHTTPProtocolHandler.h" #include "nsIHTTPProtocolHandler.h"
@@ -94,9 +95,7 @@ NS_OpenURI(nsIChannel* *result,
nsIIOService* ioService = nsnull, // pass in nsIIOService to optimize callers nsIIOService* ioService = nsnull, // pass in nsIIOService to optimize callers
nsILoadGroup* loadGroup = nsnull, nsILoadGroup* loadGroup = nsnull,
nsIInterfaceRequestor* notificationCallbacks = nsnull, nsIInterfaceRequestor* notificationCallbacks = nsnull,
nsLoadFlags loadAttributes = NS_STATIC_CAST(nsLoadFlags, nsIChannel::LOAD_NORMAL), nsLoadFlags loadAttributes = NS_STATIC_CAST(nsLoadFlags, nsIChannel::LOAD_NORMAL))
PRUint32 bufferSegmentSize = 0,
PRUint32 bufferMaxSize = 0)
{ {
nsresult rv; nsresult rv;
@@ -123,14 +122,6 @@ NS_OpenURI(nsIChannel* *result,
rv = channel->SetLoadAttributes(loadAttributes); rv = channel->SetLoadAttributes(loadAttributes);
if (NS_FAILED(rv)) return rv; 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;
}
*result = channel; *result = channel;
return rv; return rv;
@@ -148,20 +139,17 @@ NS_OpenURI(nsIInputStream* *result,
nsIIOService* ioService = nsnull, // pass in nsIIOService to optimize callers nsIIOService* ioService = nsnull, // pass in nsIIOService to optimize callers
nsILoadGroup* loadGroup = nsnull, nsILoadGroup* loadGroup = nsnull,
nsIInterfaceRequestor* notificationCallbacks = nsnull, nsIInterfaceRequestor* notificationCallbacks = nsnull,
nsLoadFlags loadAttributes = NS_STATIC_CAST(nsLoadFlags, nsIChannel::LOAD_NORMAL), nsLoadFlags loadAttributes = NS_STATIC_CAST(nsLoadFlags, nsIChannel::LOAD_NORMAL))
PRUint32 bufferSegmentSize = 0,
PRUint32 bufferMaxSize = 0)
{ {
nsresult rv; nsresult rv;
nsCOMPtr<nsIChannel> channel; nsCOMPtr<nsIChannel> channel;
rv = NS_OpenURI(getter_AddRefs(channel), uri, ioService, rv = NS_OpenURI(getter_AddRefs(channel), uri, ioService,
loadGroup, notificationCallbacks, loadAttributes, loadGroup, notificationCallbacks, loadAttributes);
bufferSegmentSize, bufferMaxSize);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
nsIInputStream* inStr; nsIInputStream* inStr;
rv = channel->OpenInputStream(&inStr); rv = channel->Open(&inStr);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
*result = inStr; *result = inStr;
@@ -175,19 +163,16 @@ NS_OpenURI(nsIStreamListener* aConsumer,
nsIIOService* ioService = nsnull, // pass in nsIIOService to optimize callers nsIIOService* ioService = nsnull, // pass in nsIIOService to optimize callers
nsILoadGroup* loadGroup = nsnull, nsILoadGroup* loadGroup = nsnull,
nsIInterfaceRequestor* notificationCallbacks = nsnull, nsIInterfaceRequestor* notificationCallbacks = nsnull,
nsLoadFlags loadAttributes = NS_STATIC_CAST(nsLoadFlags, nsIChannel::LOAD_NORMAL), nsLoadFlags loadAttributes = NS_STATIC_CAST(nsLoadFlags, nsIChannel::LOAD_NORMAL))
PRUint32 bufferSegmentSize = 0,
PRUint32 bufferMaxSize = 0)
{ {
nsresult rv; nsresult rv;
nsCOMPtr<nsIChannel> channel; nsCOMPtr<nsIChannel> channel;
rv = NS_OpenURI(getter_AddRefs(channel), uri, ioService, rv = NS_OpenURI(getter_AddRefs(channel), uri, ioService,
loadGroup, notificationCallbacks, loadAttributes, loadGroup, notificationCallbacks, loadAttributes);
bufferSegmentSize, bufferMaxSize);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
rv = channel->AsyncRead(aConsumer, context); rv = channel->AsyncOpen(aConsumer, context);
return rv; return rv;
} }
@@ -326,9 +311,7 @@ NS_NewDownloader(nsIDownloader* *result,
PRBool synchronous = PR_FALSE, PRBool synchronous = PR_FALSE,
nsILoadGroup* loadGroup = nsnull, nsILoadGroup* loadGroup = nsnull,
nsIInterfaceRequestor* notificationCallbacks = nsnull, nsIInterfaceRequestor* notificationCallbacks = nsnull,
nsLoadFlags loadAttributes = NS_STATIC_CAST(nsLoadFlags, nsIChannel::LOAD_NORMAL), nsLoadFlags loadAttributes = NS_STATIC_CAST(nsLoadFlags, nsIChannel::LOAD_NORMAL))
PRUint32 bufferSegmentSize = 0,
PRUint32 bufferMaxSize = 0)
{ {
nsresult rv; nsresult rv;
nsCOMPtr<nsIDownloader> downloader; nsCOMPtr<nsIDownloader> downloader;
@@ -338,8 +321,8 @@ NS_NewDownloader(nsIDownloader* *result,
NS_GET_IID(nsIDownloader), NS_GET_IID(nsIDownloader),
getter_AddRefs(downloader)); getter_AddRefs(downloader));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
rv = downloader->Init(uri, observer, context, synchronous, loadGroup, notificationCallbacks, rv = downloader->Init(uri, observer, context, synchronous, loadGroup,
loadAttributes, bufferSegmentSize, bufferMaxSize); notificationCallbacks, loadAttributes);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
*result = downloader; *result = downloader;
NS_ADDREF(*result); NS_ADDREF(*result);
@@ -353,9 +336,7 @@ NS_NewStreamLoader(nsIStreamLoader* *result,
nsISupports* context = nsnull, nsISupports* context = nsnull,
nsILoadGroup* loadGroup = nsnull, nsILoadGroup* loadGroup = nsnull,
nsIInterfaceRequestor* notificationCallbacks = nsnull, nsIInterfaceRequestor* notificationCallbacks = nsnull,
nsLoadFlags loadAttributes = NS_STATIC_CAST(nsLoadFlags, nsIChannel::LOAD_NORMAL), nsLoadFlags loadAttributes = NS_STATIC_CAST(nsLoadFlags, nsIChannel::LOAD_NORMAL))
PRUint32 bufferSegmentSize = 0,
PRUint32 bufferMaxSize = 0)
{ {
nsresult rv; nsresult rv;
nsCOMPtr<nsIStreamLoader> loader; nsCOMPtr<nsIStreamLoader> loader;
@@ -365,8 +346,9 @@ NS_NewStreamLoader(nsIStreamLoader* *result,
NS_GET_IID(nsIStreamLoader), NS_GET_IID(nsIStreamLoader),
getter_AddRefs(loader)); getter_AddRefs(loader));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
rv = loader->Init(uri, observer, context, loadGroup, notificationCallbacks, loadAttributes, rv = loader->Init(uri, observer, context, loadGroup,
bufferSegmentSize, bufferMaxSize); notificationCallbacks, loadAttributes);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
*result = loader; *result = loader;
NS_ADDREF(*result); NS_ADDREF(*result);
@@ -393,9 +375,7 @@ NS_NewStreamObserverProxy(nsIStreamObserver **aResult,
rv = proxy->Init(aObserver, aEventQ); rv = proxy->Init(aObserver, aEventQ);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
*aResult = proxy; NS_ADDREF(*aResult = proxy);
NS_ADDREF(*aResult);
return NS_OK; return NS_OK;
} }
@@ -421,9 +401,7 @@ NS_NewStreamListenerProxy(nsIStreamListener **aResult,
rv = proxy->Init(aListener, aEventQ, aBufferSegmentSize, aBufferMaxSize); rv = proxy->Init(aListener, aEventQ, aBufferSegmentSize, aBufferMaxSize);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
*aResult = proxy; NS_ADDREF(*aResult = proxy);
NS_ADDREF(*aResult);
return NS_OK; return NS_OK;
} }
@@ -449,9 +427,7 @@ NS_NewStreamProviderProxy(nsIStreamProvider **aResult,
rv = proxy->Init(aProvider, aEventQ, aBufferSegmentSize, aBufferMaxSize); rv = proxy->Init(aProvider, aEventQ, aBufferSegmentSize, aBufferMaxSize);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
*aResult = proxy; NS_ADDREF(*aResult = proxy);
NS_ADDREF(*aResult);
return NS_OK; return NS_OK;
} }
@@ -474,9 +450,7 @@ NS_NewSimpleStreamListener(nsIStreamListener **aResult,
rv = listener->Init(aSink, aObserver); rv = listener->Init(aSink, aObserver);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
*aResult = listener.get(); NS_ADDREF(*aResult = listener);
NS_ADDREF(*aResult);
return NS_OK; return NS_OK;
} }
@@ -499,9 +473,7 @@ NS_NewSimpleStreamProvider(nsIStreamProvider **aResult,
rv = provider->Init(aSource, aObserver); rv = provider->Init(aSource, aObserver);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
*aResult = provider.get(); NS_ADDREF(*aResult = provider);
NS_ADDREF(*aResult);
return NS_OK; return NS_OK;
} }
@@ -522,8 +494,7 @@ NS_NewAsyncStreamObserver(nsIStreamObserver **result,
rv = obs->Init(receiver, eventQueue); rv = obs->Init(receiver, eventQueue);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
*result = obs; NS_ADDREF(*result = obs);
NS_ADDREF(*result);
return NS_OK; return NS_OK;
} }
@@ -544,8 +515,7 @@ NS_NewAsyncStreamListener(nsIStreamListener **result,
rv = lsnr->Init(receiver, eventQueue); rv = lsnr->Init(receiver, eventQueue);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
*result = lsnr; NS_ADDREF(*result = lsnr);
NS_ADDREF(*result);
return NS_OK; return NS_OK;
} }
@@ -572,25 +542,26 @@ NS_NewSyncStreamListener(nsIInputStream **aInStream,
rv = NS_NewSimpleStreamListener(aResult, pipeOut); rv = NS_NewSimpleStreamListener(aResult, pipeOut);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
*aInStream = pipeIn; NS_ADDREF(*aInStream = pipeIn);
NS_ADDREF(*aInStream); NS_ADDREF(*aOutStream = pipeOut);
*aOutStream = pipeOut;
NS_ADDREF(*aOutStream);
return NS_OK; return NS_OK;
} }
// //
// Calls AsyncWrite on the specified channel, with a stream provider that // Calls AsyncWrite on the specified transport, with a stream provider that
// reads data from the specified input stream. // reads data from the specified input stream.
// //
inline nsresult inline nsresult
NS_AsyncWriteFromStream(nsIChannel *aChannel, NS_AsyncWriteFromStream(nsIRequest **aRequest,
nsITransport *aTransport,
nsIInputStream *aSource, nsIInputStream *aSource,
PRUint32 aOffset=0,
PRUint32 aCount=0,
PRUint32 aFlags=0,
nsIStreamObserver *aObserver=NULL, nsIStreamObserver *aObserver=NULL,
nsISupports *aContext=NULL) nsISupports *aContext=NULL)
{ {
NS_ENSURE_ARG_POINTER(aChannel); NS_ENSURE_ARG_POINTER(aTransport);
nsresult rv; nsresult rv;
nsCOMPtr<nsIStreamProvider> provider; nsCOMPtr<nsIStreamProvider> provider;
@@ -599,20 +570,28 @@ NS_AsyncWriteFromStream(nsIChannel *aChannel,
aObserver); aObserver);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
return aChannel->AsyncWrite(provider, aContext); return aTransport->AsyncWrite(provider, aContext,
aOffset,
aCount,
aFlags,
getter_AddRefs(aRequest));
} }
// //
// Calls AsyncRead on the specified channel, with a stream listener that // Calls AsyncRead on the specified transport, with a stream listener that
// writes data to the specified output stream. // writes data to the specified output stream.
// //
inline nsresult inline nsresult
NS_AsyncReadToStream(nsIChannel *aChannel, NS_AsyncReadToStream(nsIRequest **aRequest,
nsITransport *aTransport,
nsIOutputStream *aSink, nsIOutputStream *aSink,
PRUint32 aOffset=0,
PRUint32 aCount=0,
PRUint32 aFlags=0,
nsIStreamObserver *aObserver=NULL, nsIStreamObserver *aObserver=NULL,
nsISupports *aContext=NULL) nsISupports *aContext=NULL)
{ {
NS_ENSURE_ARG_POINTER(aChannel); NS_ENSURE_ARG_POINTER(aTransport);
nsresult rv; nsresult rv;
nsCOMPtr<nsIStreamListener> listener; nsCOMPtr<nsIStreamListener> listener;
@@ -621,7 +600,11 @@ NS_AsyncReadToStream(nsIChannel *aChannel,
aObserver); aObserver);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
return aChannel->AsyncRead(listener, aContext); return aTransport->AsyncRead(listener, aContext,
aOffset,
aCount,
aFlags,
getter_AddRefs(aRequest));
} }
#endif // nsNetUtil_h__ #endif // nsNetUtil_h__

View File

@@ -9,3 +9,7 @@ pref("security.warn_entering_secure", true);
pref("security.warn_leaving_secure", true); pref("security.warn_leaving_secure", true);
pref("security.warn_viewing_mixed", true); pref("security.warn_viewing_mixed", true);
pref("security.warn_submit_insecure", true); pref("security.warn_submit_insecure", true);
pref("security.ui.enable", true);

View File

@@ -48,7 +48,7 @@ class nsStreamListenerEvent
{ {
public: public:
nsStreamListenerEvent(nsAsyncStreamObserver* listener, nsStreamListenerEvent(nsAsyncStreamObserver* listener,
nsIChannel* channel, nsISupports* context); nsIRequest* request, nsISupports* context);
virtual ~nsStreamListenerEvent(); virtual ~nsStreamListenerEvent();
nsresult Fire(nsIEventQueue* aEventQ); nsresult Fire(nsIEventQueue* aEventQ);
@@ -60,7 +60,7 @@ protected:
static void PR_CALLBACK DestroyPLEvent(PLEvent* aEvent); static void PR_CALLBACK DestroyPLEvent(PLEvent* aEvent);
nsAsyncStreamObserver* mListener; nsAsyncStreamObserver* mListener;
nsIChannel* mChannel; nsIRequest* mRequest;
nsISupports* mContext; nsISupports* mContext;
PLEvent mEvent; PLEvent mEvent;
}; };
@@ -71,13 +71,13 @@ protected:
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
nsStreamListenerEvent::nsStreamListenerEvent(nsAsyncStreamObserver* listener, nsStreamListenerEvent::nsStreamListenerEvent(nsAsyncStreamObserver* listener,
nsIChannel* channel, nsISupports* context) nsIRequest* request, nsISupports* context)
: mListener(listener), mChannel(channel), mContext(context) : mListener(listener), mRequest(request), mContext(context)
{ {
MOZ_COUNT_CTOR(nsStreamListenerEvent); MOZ_COUNT_CTOR(nsStreamListenerEvent);
NS_IF_ADDREF(mListener); NS_IF_ADDREF(mListener);
NS_IF_ADDREF(mChannel); NS_IF_ADDREF(mRequest);
NS_IF_ADDREF(mContext); NS_IF_ADDREF(mContext);
} }
@@ -86,7 +86,7 @@ nsStreamListenerEvent::~nsStreamListenerEvent()
MOZ_COUNT_DTOR(nsStreamListenerEvent); MOZ_COUNT_DTOR(nsStreamListenerEvent);
NS_IF_RELEASE(mListener); NS_IF_RELEASE(mListener);
NS_IF_RELEASE(mChannel); NS_IF_RELEASE(mRequest);
NS_IF_RELEASE(mContext); NS_IF_RELEASE(mContext);
} }
@@ -105,7 +105,7 @@ void PR_CALLBACK nsStreamListenerEvent::HandlePLEvent(PLEvent* aEvent)
// the pipe to empty... // the pipe to empty...
// //
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
nsresult cancelRv = ev->mChannel->Cancel(rv); nsresult cancelRv = ev->mRequest->Cancel(rv);
NS_ASSERTION(NS_SUCCEEDED(cancelRv), "Cancel failed"); NS_ASSERTION(NS_SUCCEEDED(cancelRv), "Cancel failed");
} }
} }
@@ -182,8 +182,8 @@ class nsOnStartRequestEvent : public nsStreamListenerEvent
{ {
public: public:
nsOnStartRequestEvent(nsAsyncStreamObserver* listener, nsOnStartRequestEvent(nsAsyncStreamObserver* listener,
nsIChannel* channel, nsISupports* context) nsIRequest* request, nsISupports* context)
: nsStreamListenerEvent(listener, channel, context) {} : nsStreamListenerEvent(listener, request, context) {}
virtual ~nsOnStartRequestEvent() {} virtual ~nsOnStartRequestEvent() {}
NS_IMETHOD HandleEvent(); NS_IMETHOD HandleEvent();
@@ -205,19 +205,19 @@ nsOnStartRequestEvent::HandleEvent()
} }
nsresult status; nsresult status;
nsresult rv = mChannel->GetStatus(&status); nsresult rv = mRequest->GetStatus(&status);
NS_ASSERTION(NS_SUCCEEDED(rv), "GetStatus failed"); NS_ASSERTION(NS_SUCCEEDED(rv), "GetStatus failed");
rv = receiver->OnStartRequest(mChannel, mContext); rv = receiver->OnStartRequest(mRequest, mContext);
return rv; return rv;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsAsyncStreamObserver::OnStartRequest(nsIChannel* channel, nsISupports* context) nsAsyncStreamObserver::OnStartRequest(nsIRequest *request, nsISupports* context)
{ {
nsresult rv; nsresult rv;
nsOnStartRequestEvent* event = nsOnStartRequestEvent* event =
new nsOnStartRequestEvent(this, channel, context); new nsOnStartRequestEvent(this, request, context);
if (event == nsnull) if (event == nsnull)
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
@@ -252,8 +252,8 @@ class nsOnStopRequestEvent : public nsStreamListenerEvent
{ {
public: public:
nsOnStopRequestEvent(nsAsyncStreamObserver* listener, nsOnStopRequestEvent(nsAsyncStreamObserver* listener,
nsISupports* context, nsIChannel* channel) nsISupports* context, nsIRequest* request)
: nsStreamListenerEvent(listener, channel, context), : nsStreamListenerEvent(listener, request, context),
mStatus(NS_OK) {} mStatus(NS_OK) {}
virtual ~nsOnStopRequestEvent(); virtual ~nsOnStopRequestEvent();
@@ -293,7 +293,7 @@ nsOnStopRequestEvent::HandleEvent()
} }
nsresult status = NS_OK; nsresult status = NS_OK;
nsresult rv = mChannel->GetStatus(&status); nsresult rv = mRequest->GetStatus(&status);
NS_ASSERTION(NS_SUCCEEDED(rv), "GetStatus failed"); NS_ASSERTION(NS_SUCCEEDED(rv), "GetStatus failed");
// //
@@ -303,14 +303,14 @@ nsOnStopRequestEvent::HandleEvent()
if (NS_SUCCEEDED(rv) && NS_FAILED(status)) { if (NS_SUCCEEDED(rv) && NS_FAILED(status)) {
mStatus = status; mStatus = status;
} }
rv = receiver->OnStopRequest(mChannel, mContext, mStatus, mStatusArg.GetUnicode()); rv = receiver->OnStopRequest(mRequest, mContext, mStatus, mStatusArg.GetUnicode());
// Call clear on the listener to make sure it's cleanup is done on the correct thread // Call clear on the listener to make sure it's cleanup is done on the correct thread
mListener->Clear(); mListener->Clear();
return rv; return rv;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsAsyncStreamObserver::OnStopRequest(nsIChannel* channel, nsISupports* context, nsAsyncStreamObserver::OnStopRequest(nsIRequest* request, nsISupports* context,
nsresult aStatus, const PRUnichar* aStatusArg) nsresult aStatus, const PRUnichar* aStatusArg)
{ {
nsresult rv; nsresult rv;
@@ -320,7 +320,7 @@ nsAsyncStreamObserver::OnStopRequest(nsIChannel* channel, nsISupports* context,
// Status is... // Status is...
// //
nsOnStopRequestEvent* event = nsOnStopRequestEvent* event =
new nsOnStopRequestEvent(this, context, channel); new nsOnStopRequestEvent(this, context, request);
if (event == nsnull) if (event == nsnull)
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
@@ -354,8 +354,8 @@ class nsOnDataAvailableEvent : public nsStreamListenerEvent
{ {
public: public:
nsOnDataAvailableEvent(nsAsyncStreamObserver* listener, nsOnDataAvailableEvent(nsAsyncStreamObserver* listener,
nsIChannel* channel, nsISupports* context) nsIRequest* request, nsISupports* context)
: nsStreamListenerEvent(listener, channel, context), : nsStreamListenerEvent(listener, request, context),
mIStream(nsnull), mLength(0) {} mIStream(nsnull), mLength(0) {}
virtual ~nsOnDataAvailableEvent(); virtual ~nsOnDataAvailableEvent();
@@ -401,7 +401,7 @@ nsOnDataAvailableEvent::HandleEvent()
} }
nsresult status; nsresult status;
nsresult rv = mChannel->GetStatus(&status); nsresult rv = mRequest->GetStatus(&status);
NS_ASSERTION(NS_SUCCEEDED(rv), "GetStatus failed"); NS_ASSERTION(NS_SUCCEEDED(rv), "GetStatus failed");
// //
@@ -409,7 +409,7 @@ nsOnDataAvailableEvent::HandleEvent()
// have succeeded... // have succeeded...
// //
if (NS_SUCCEEDED(rv) && NS_SUCCEEDED(status)) { if (NS_SUCCEEDED(rv) && NS_SUCCEEDED(status)) {
rv = receiver->OnDataAvailable(mChannel, mContext, rv = receiver->OnDataAvailable(mRequest, mContext,
mIStream, mSourceOffset, mLength); mIStream, mSourceOffset, mLength);
} }
else { else {
@@ -419,14 +419,14 @@ nsOnDataAvailableEvent::HandleEvent()
} }
NS_IMETHODIMP NS_IMETHODIMP
nsAsyncStreamListener::OnDataAvailable(nsIChannel* channel, nsISupports* context, nsAsyncStreamListener::OnDataAvailable(nsIRequest* request, nsISupports* context,
nsIInputStream *aIStream, nsIInputStream *aIStream,
PRUint32 aSourceOffset, PRUint32 aSourceOffset,
PRUint32 aLength) PRUint32 aLength)
{ {
nsresult rv; nsresult rv;
nsOnDataAvailableEvent* event = nsOnDataAvailableEvent* event =
new nsOnDataAvailableEvent(this, channel, context); new nsOnDataAvailableEvent(this, request, context);
if (event == nsnull) if (event == nsnull)
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;

View File

@@ -28,7 +28,7 @@
#include "nsIEventQueue.h" #include "nsIEventQueue.h"
#include "nsIStreamObserver.h" #include "nsIStreamObserver.h"
#include "nsIStreamListener.h" #include "nsIStreamListener.h"
#include "nsIRequest.h"
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
class nsAsyncStreamObserver : public nsIAsyncStreamObserver class nsAsyncStreamObserver : public nsIAsyncStreamObserver
@@ -66,20 +66,20 @@ public:
NS_DECL_ISUPPORTS_INHERITED NS_DECL_ISUPPORTS_INHERITED
// nsIStreamListener methods: // nsIStreamListener methods:
NS_IMETHOD OnStartRequest(nsIChannel* channel, NS_IMETHOD OnStartRequest(nsIRequest* request,
nsISupports* context) nsISupports* context)
{ {
return nsAsyncStreamObserver::OnStartRequest(channel, context); return nsAsyncStreamObserver::OnStartRequest(request, context);
} }
NS_IMETHOD OnStopRequest(nsIChannel* channel, NS_IMETHOD OnStopRequest(nsIRequest* request,
nsISupports* context, nsISupports* context,
nsresult aStatus, const PRUnichar* aStatusArg) nsresult aStatus, const PRUnichar* aStatusArg)
{ {
return nsAsyncStreamObserver::OnStopRequest(channel, context, aStatus, aStatusArg); return nsAsyncStreamObserver::OnStopRequest(request, context, aStatus, aStatusArg);
} }
NS_IMETHOD OnDataAvailable(nsIChannel* channel, nsISupports* context, NS_IMETHOD OnDataAvailable(nsIRequest* request, nsISupports* context,
nsIInputStream *aIStream, nsIInputStream *aIStream,
PRUint32 aSourceOffset, PRUint32 aSourceOffset,
PRUint32 aLength); PRUint32 aLength);

View File

@@ -43,9 +43,7 @@ nsDownloader::Init(nsIURI* aURL,
PRBool aIsSynchronous, PRBool aIsSynchronous,
nsILoadGroup* aGroup, nsILoadGroup* aGroup,
nsIInterfaceRequestor* aNotificationCallbacks, nsIInterfaceRequestor* aNotificationCallbacks,
nsLoadFlags aLoadAttributes, nsLoadFlags aLoadAttributes)
PRUint32 aBufferSegmentSize,
PRUint32 aBufferMaxSize)
{ {
nsresult rv; nsresult rv;
mObserver = aObserver; mObserver = aObserver;
@@ -55,10 +53,13 @@ nsDownloader::Init(nsIURI* aURL,
aLoadAttributes |= nsIChannel::CACHE_AS_FILE; aLoadAttributes |= nsIChannel::CACHE_AS_FILE;
rv = NS_OpenURI(getter_AddRefs(channel), aURL, nsnull, aGroup, aNotificationCallbacks, rv = NS_OpenURI(getter_AddRefs(channel), aURL, nsnull, aGroup, aNotificationCallbacks,
aLoadAttributes, aBufferSegmentSize, aBufferMaxSize); aLoadAttributes);
if (NS_SUCCEEDED(rv) && channel) if (NS_SUCCEEDED(rv) && channel)
rv = channel->GetLocalFile(getter_AddRefs(localFile)); {
nsCOMPtr<nsIFileChannel> fc = do_QueryInterface(channel);
if (fc)
rv = fc->GetFile(getter_AddRefs(localFile));
}
if (mObserver && (NS_FAILED(rv) || localFile)) if (mObserver && (NS_FAILED(rv) || localFile))
{ {
if (aIsSynchronous) if (aIsSynchronous)
@@ -81,8 +82,7 @@ nsDownloader::Init(nsIURI* aURL,
return pObserver->OnDownloadComplete(this, mContext, rv, localFile); return pObserver->OnDownloadComplete(this, mContext, rv, localFile);
} }
} }
return channel->AsyncOpen(this, aContext);
return channel->AsyncRead(this, aContext);
} }
NS_METHOD NS_METHOD
@@ -103,13 +103,13 @@ NS_IMPL_ISUPPORTS3(nsDownloader, nsIDownloader,
nsIStreamObserver, nsIStreamListener) nsIStreamObserver, nsIStreamListener)
NS_IMETHODIMP NS_IMETHODIMP
nsDownloader::OnStartRequest(nsIChannel* channel, nsISupports *ctxt) nsDownloader::OnStartRequest(nsIRequest *request, nsISupports *ctxt)
{ {
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsDownloader::OnStopRequest(nsIChannel* channel, nsISupports *ctxt, nsDownloader::OnStopRequest(nsIRequest *request, nsISupports *ctxt,
nsresult aStatus, const PRUnichar* aStatusArg) nsresult aStatus, const PRUnichar* aStatusArg)
{ {
nsCOMPtr<nsIFile> file; nsCOMPtr<nsIFile> file;
@@ -117,6 +117,10 @@ nsDownloader::OnStopRequest(nsIChannel* channel, nsISupports *ctxt,
{ {
nsresult rv; nsresult rv;
nsCOMPtr<nsIURI> uri; nsCOMPtr<nsIURI> uri;
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request, &rv);
if (NS_FAILED(rv)) return rv;
rv = channel->GetURI(getter_AddRefs(uri)); rv = channel->GetURI(getter_AddRefs(uri));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
nsXPIDLCString spec; nsXPIDLCString spec;
@@ -147,7 +151,7 @@ nsDownloader::OnStopRequest(nsIChannel* channel, nsISupports *ctxt,
#define BUF_SIZE 1024 #define BUF_SIZE 1024
NS_IMETHODIMP NS_IMETHODIMP
nsDownloader::OnDataAvailable(nsIChannel* channel, nsISupports *ctxt, nsDownloader::OnDataAvailable(nsIRequest *request, nsISupports *ctxt,
nsIInputStream *inStr, nsIInputStream *inStr,
PRUint32 sourceOffset, PRUint32 count) PRUint32 sourceOffset, PRUint32 count)
{ {

View File

@@ -208,7 +208,6 @@ nsFileTransport::nsFileTransport()
mOffset(0), mOffset(0),
mTotalAmount(-1), mTotalAmount(-1),
mTransferAmount(-1), mTransferAmount(-1),
mLoadAttributes(LOAD_NORMAL),
mSourceWrapper(nsnull), mSourceWrapper(nsnull),
mSinkWrapper(nsnull), mSinkWrapper(nsnull),
mService(nsnull) mService(nsnull)
@@ -283,8 +282,9 @@ nsFileTransport::~nsFileTransport()
PR_AtomicDecrement(&mService->mTotalTransports); PR_AtomicDecrement(&mService->mTotalTransports);
} }
NS_IMPL_THREADSAFE_ISUPPORTS3(nsFileTransport, NS_IMPL_THREADSAFE_ISUPPORTS4(nsFileTransport,
nsIChannel, nsITransport,
nsITransportRequest,
nsIRequest, nsIRequest,
nsIRunnable) nsIRunnable)
@@ -384,52 +384,80 @@ nsFileTransport::Resume()
return NS_OK; return NS_OK;
} }
////////////////////////////////////////////////////////////////////////////////
// From nsITransportRequest
////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP
nsFileTransport::GetTransport(nsITransport **result)
{
NS_ENSURE_ARG_POINTER(result);
NS_ADDREF(*result = this);
return NS_OK;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// From nsITransport // From nsITransport
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP NS_IMETHODIMP
nsFileTransport::OpenInputStream(nsIInputStream **result) nsFileTransport::OpenInputStream(PRUint32 aTransferOffset,
PRUint32 aTransferCount,
PRUint32 aFlags,
nsIInputStream **aResult)
{ {
NS_ENSURE_ARG_POINTER(aResult);
nsresult rv; nsresult rv;
nsCOMPtr<nsIInputStream> in; nsCOMPtr<nsIInputStream> in;
rv = mStreamIO->GetInputStream(getter_AddRefs(in)); rv = mStreamIO->GetInputStream(getter_AddRefs(in));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
NS_ASSERTION(mTransferAmount == -1, "need to wrap input stream in one that truncates"); NS_ASSERTION(aTransferCount == (PRUint32) -1, "need to wrap input stream in one that truncates");
if (mOffset > 0) { if (aTransferOffset > 0) {
nsCOMPtr<nsISeekableStream> seekable = do_QueryInterface(in, &rv); nsCOMPtr<nsISeekableStream> seekable = do_QueryInterface(in, &rv);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, mOffset); rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, aTransferOffset);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
} }
*result = in; NS_ADDREF(*aResult = in);
NS_ADDREF(*result);
return rv; return rv;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsFileTransport::OpenOutputStream(nsIOutputStream **result) nsFileTransport::OpenOutputStream(PRUint32 aTransferOffset,
PRUint32 aTransferCount,
PRUint32 aFlags,
nsIOutputStream **aResult)
{ {
return mStreamIO->GetOutputStream(result); NS_ASSERTION(aTransferOffset == 0, "need to seek to specified offset");
NS_ASSERTION(aTransferCount == (PRUint32) -1, "need to wrap output stream in one that truncates");
return mStreamIO->GetOutputStream(aResult);
} }
NS_IMETHODIMP NS_IMETHODIMP
nsFileTransport::AsyncRead(nsIStreamListener *listener, nsISupports *ctxt) nsFileTransport::AsyncRead(nsIStreamListener *aListener,
nsISupports *aContext,
PRUint32 aTransferOffset,
PRUint32 aTransferCount,
PRUint32 aFlags,
nsIRequest **aResult)
{ {
NS_ENSURE_ARG_POINTER(aResult);
nsresult rv = NS_OK; nsresult rv = NS_OK;
if (mXferState != CLOSED) if (mXferState != CLOSED)
return NS_ERROR_IN_PROGRESS; return NS_ERROR_IN_PROGRESS;
NS_ASSERTION(listener, "need to supply an nsIStreamListener"); NS_ASSERTION(aListener, "need to supply an nsIStreamListener");
rv = NS_NewStreamListenerProxy(getter_AddRefs(mListener), rv = NS_NewStreamListenerProxy(getter_AddRefs(mListener),
listener, nsnull, aListener, nsnull,
mBufferSegmentSize, mBufferSegmentSize,
mBufferMaxSize); mBufferMaxSize);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
NS_ASSERTION(mContext == nsnull, "context not released"); NS_ASSERTION(mContext == nsnull, "context not released");
mContext = ctxt; mContext = aContext;
mOffset = aTransferOffset;
mTransferAmount = aTransferCount;
mXferState = OPEN_FOR_READ; mXferState = OPEN_FOR_READ;
LOG(("nsFileTransport: AsyncRead [this=%x %s] mOffset=%d mTransferAmount=%d\n", LOG(("nsFileTransport: AsyncRead [this=%x %s] mOffset=%d mTransferAmount=%d\n",
@@ -441,27 +469,38 @@ nsFileTransport::AsyncRead(nsIStreamListener *listener, nsISupports *ctxt)
rv = mService->DispatchRequest(this); rv = mService->DispatchRequest(this);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
NS_ADDREF(*aResult = this);
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsFileTransport::AsyncWrite(nsIStreamProvider *provider, nsFileTransport::AsyncWrite(nsIStreamProvider *aProvider,
nsISupports *ctxt) nsISupports *aContext,
PRUint32 aTransferOffset,
PRUint32 aTransferCount,
PRUint32 aFlags,
nsIRequest **aResult)
{ {
NS_ENSURE_ARG_POINTER(aResult);
nsresult rv = NS_OK; nsresult rv = NS_OK;
LOG(("nsFileTransport: AsyncWrite [this=%x, provider=%x]\n", LOG(("nsFileTransport: AsyncWrite [this=%x, provider=%x]\n",
this, provider)); this, aProvider));
if (mXferState != CLOSED) if (mXferState != CLOSED)
return NS_ERROR_IN_PROGRESS; return NS_ERROR_IN_PROGRESS;
NS_ASSERTION(provider, "need to supply an nsIStreamProvider"); NS_ASSERTION(aProvider, "need to supply an nsIStreamProvider");
rv = NS_NewStreamProviderProxy(getter_AddRefs(mProvider), provider); rv = NS_NewStreamProviderProxy(getter_AddRefs(mProvider),
aProvider, nsnull,
mBufferSegmentSize,
mBufferMaxSize);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
NS_ASSERTION(mContext == nsnull, "context not released"); NS_ASSERTION(mContext == nsnull, "context not released");
mContext = ctxt; mContext = aContext;
mOffset = aTransferOffset;
mTransferAmount = aTransferCount;
mXferState = OPEN_FOR_WRITE; mXferState = OPEN_FOR_WRITE;
LOG(("nsFileTransport: AsyncWrite [this=%x %s] mOffset=%d mTransferAmount=%d\n", LOG(("nsFileTransport: AsyncWrite [this=%x %s] mOffset=%d mTransferAmount=%d\n",
@@ -473,6 +512,7 @@ nsFileTransport::AsyncWrite(nsIStreamProvider *provider,
rv = mService->DispatchRequest(this); rv = mService->DispatchRequest(this);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
NS_ADDREF(*aResult = this);
return NS_OK; return NS_OK;
} }
@@ -671,8 +711,8 @@ nsFileTransport::Process(void)
LOG(("nsFileTransport: READING [this=%x %s] read %u bytes [offset=%u]\n", LOG(("nsFileTransport: READING [this=%x %s] read %u bytes [offset=%u]\n",
this, mStreamName.GetBuffer(), total, mOffset)); this, mStreamName.GetBuffer(), total, mOffset));
if (mProgress && !(mLoadAttributes & LOAD_BACKGROUND) // what about check for background flags! dougt
&& (mTransferAmount >= 0)) { if (mProgress && (mTransferAmount >= 0)) {
mProgress->OnProgress(this, mContext, mProgress->OnProgress(this, mContext,
mTotalAmount - mTransferAmount, mTotalAmount - mTransferAmount,
mTotalAmount); mTotalAmount);
@@ -704,7 +744,8 @@ nsFileTransport::Process(void)
mListener->OnStopRequest(this, mContext, mStatus, nsnull); mListener->OnStopRequest(this, mContext, mStatus, nsnull);
mListener = 0; mListener = 0;
} }
if (mProgress && !(mLoadAttributes & LOAD_BACKGROUND)) { // what about check for background flag! dougt
if (mProgress) {
nsAutoString fileName; nsAutoString fileName;
fileName.AssignWithConversion(mStreamName); fileName.AssignWithConversion(mStreamName);
mProgress->OnStatus(this, mContext, mProgress->OnStatus(this, mContext,
@@ -717,7 +758,6 @@ nsFileTransport::Process(void)
mSource = 0; mSource = 0;
NS_IF_RELEASE(mSourceWrapper); NS_IF_RELEASE(mSourceWrapper);
mSourceWrapper = nsnull; mSourceWrapper = nsnull;
mXferState = CLOSING; mXferState = CLOSING;
break; break;
} }
@@ -843,9 +883,8 @@ nsFileTransport::Process(void)
else else
LOG(("nsFileTransport: WRITING [this=%x %s] wrote %u bytes [offset=%u]\n", LOG(("nsFileTransport: WRITING [this=%x %s] wrote %u bytes [offset=%u]\n",
this, mStreamName.GetBuffer(), total, mOffset)); this, mStreamName.GetBuffer(), total, mOffset));
// what about check for background flag dougt!
if (mProgress && !(mLoadAttributes & LOAD_BACKGROUND) if (mProgress && (mTransferAmount >= 0))
&& (mTransferAmount >= 0))
mProgress->OnProgress(this, mContext, mProgress->OnProgress(this, mContext,
mTotalAmount - mTransferAmount, mTotalAmount - mTransferAmount,
mTotalAmount); mTotalAmount);
@@ -875,14 +914,13 @@ nsFileTransport::Process(void)
NS_IF_RELEASE(mSinkWrapper); NS_IF_RELEASE(mSinkWrapper);
mSinkWrapper = nsnull; mSinkWrapper = nsnull;
nsresult rv;
if (mProvider) { if (mProvider) {
mProvider->OnStopRequest(this, mContext, mStatus, nsnull); mProvider->OnStopRequest(this, mContext, mStatus, nsnull);
mProvider = 0; mProvider = 0;
} }
if (mProgress && !(mLoadAttributes & LOAD_BACKGROUND)) { if (mProgress) {
nsAutoString fileName; fileName.AssignWithConversion(mStreamName); nsAutoString fileName; fileName.AssignWithConversion(mStreamName);
rv = mProgress->OnStatus(this, mContext, nsresult rv = mProgress->OnStatus(this, mContext,
NS_NET_STATUS_WROTE_TO, NS_NET_STATUS_WROTE_TO,
fileName.GetUnicode()); fileName.GetUnicode());
NS_ASSERTION(NS_SUCCEEDED(rv), "unexpected OnStatus failure"); NS_ASSERTION(NS_SUCCEEDED(rv), "unexpected OnStatus failure");
@@ -928,6 +966,7 @@ nsFileTransport::DoClose(void)
// other nsIChannel methods: // other nsIChannel methods:
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#if 0
NS_IMETHODIMP NS_IMETHODIMP
nsFileTransport::GetOriginalURI(nsIURI* *aURI) nsFileTransport::GetOriginalURI(nsIURI* *aURI)
{ {
@@ -1005,90 +1044,6 @@ nsFileTransport::SetContentLength(PRInt32 aContentLength)
return NS_ERROR_NOT_IMPLEMENTED; 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::GetLocalFile(nsIFile* *file)
{
nsresult rv;
nsCOMPtr<nsIFileIO> fileIO = do_QueryInterface(mStreamIO, &rv);
if (NS_FAILED(rv)) return rv;
rv = fileIO->GetFile(file);
if (NS_FAILED(rv)) {
*file = nsnull;
}
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 NS_IMETHODIMP
nsFileTransport::GetOwner(nsISupports * *aOwner) nsFileTransport::GetOwner(nsISupports * *aOwner)
{ {
@@ -1151,6 +1106,7 @@ nsFileTransport::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCa
return NS_OK; return NS_OK;
} }
#endif
NS_IMETHODIMP NS_IMETHODIMP
nsFileTransport::GetSecurityInfo(nsISupports * *aSecurityInfo) nsFileTransport::GetSecurityInfo(nsISupports * *aSecurityInfo)
@@ -1159,4 +1115,34 @@ nsFileTransport::GetSecurityInfo(nsISupports * *aSecurityInfo)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
nsFileTransport::GetProgressEventSink(nsIProgressEventSink **aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
NS_IF_ADDREF(*aResult = mProgress);
return NS_OK;
}
NS_IMETHODIMP
nsFileTransport::SetProgressEventSink(nsIProgressEventSink *aProgress)
{
mProgress = nsnull;
if (aProgress) {
// Now generate a proxied event sink
nsresult rv;
NS_WITH_SERVICE(nsIProxyObjectManager,
proxyMgr, kProxyObjectManagerCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = proxyMgr->GetProxyForObject(NS_UI_THREAD_EVENTQ, // primordial thread - should change?
NS_GET_IID(nsIProgressEventSink),
aProgress,
PROXY_ASYNC | PROXY_ALWAYS,
getter_AddRefs(mProgress));
}
return NS_OK;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@@ -23,7 +23,8 @@
#ifndef nsFileTransport_h__ #ifndef nsFileTransport_h__
#define nsFileTransport_h__ #define nsFileTransport_h__
#include "nsIChannel.h" #include "nsITransport.h"
#include "nsIRequest.h"
#include "nsIRunnable.h" #include "nsIRunnable.h"
#include "nsFileSpec.h" #include "nsFileSpec.h"
#include "prlock.h" #include "prlock.h"
@@ -49,13 +50,15 @@ class nsIInterfaceRequestor;
class nsFileTransportSourceWrapper; class nsFileTransportSourceWrapper;
class nsFileTransportSinkWrapper; class nsFileTransportSinkWrapper;
class nsFileTransport : public nsIChannel, class nsFileTransport : public nsITransport,
public nsITransportRequest,
public nsIRunnable public nsIRunnable
{ {
public: public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
NS_DECL_NSITRANSPORT
NS_DECL_NSIREQUEST NS_DECL_NSIREQUEST
NS_DECL_NSICHANNEL NS_DECL_NSITRANSPORTREQUEST
NS_DECL_NSIRUNNABLE NS_DECL_NSIRUNNABLE
nsFileTransport(); nsFileTransport();
@@ -98,7 +101,6 @@ public:
}; };
protected: protected:
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
nsCOMPtr<nsIProgressEventSink> mProgress; nsCOMPtr<nsIProgressEventSink> mProgress;
nsCOMPtr<nsIStreamIO> mStreamIO; nsCOMPtr<nsIStreamIO> mStreamIO;
char *mContentType; char *mContentType;
@@ -125,7 +127,6 @@ protected:
PRUint32 mOffset; PRUint32 mOffset;
PRInt32 mTotalAmount; PRInt32 mTotalAmount;
PRInt32 mTransferAmount; PRInt32 mTransferAmount;
nsLoadFlags mLoadAttributes;
// reading state variables: // reading state variables:
nsCOMPtr<nsIStreamListener> mListener; nsCOMPtr<nsIStreamListener> mListener;

View File

@@ -88,7 +88,7 @@ NS_IMETHODIMP
nsFileTransportService::CreateTransport(nsIFile* file, nsFileTransportService::CreateTransport(nsIFile* file,
PRInt32 ioFlags, PRInt32 ioFlags,
PRInt32 perm, PRInt32 perm,
nsIChannel** result) nsITransport** result)
{ {
nsresult rv; nsresult rv;
nsFileTransport* trans = new nsFileTransport(); nsFileTransport* trans = new nsFileTransport();
@@ -109,7 +109,7 @@ nsFileTransportService::CreateTransportFromStream(const char* name,
nsIInputStream *fromStream, nsIInputStream *fromStream,
const char* contentType, const char* contentType,
PRInt32 contentLength, PRInt32 contentLength,
nsIChannel** result) nsITransport** result)
{ {
nsresult rv; nsresult rv;
nsFileTransport* trans = new nsFileTransport(); nsFileTransport* trans = new nsFileTransport();
@@ -127,7 +127,7 @@ nsFileTransportService::CreateTransportFromStream(const char* name,
NS_IMETHODIMP NS_IMETHODIMP
nsFileTransportService::CreateTransportFromStreamIO(nsIStreamIO *io, nsFileTransportService::CreateTransportFromStreamIO(nsIStreamIO *io,
nsIChannel **result) nsITransport **result)
{ {
nsresult rv; nsresult rv;
nsFileTransport* trans = new nsFileTransport(); nsFileTransport* trans = new nsFileTransport();

View File

@@ -368,40 +368,6 @@ nsIOService::SetOffline(PRBool offline)
} }
NS_IMETHODIMP
nsIOService::ConsumeInput(nsIChannel* channel, nsISupports* context,
nsIStreamListener* consumer)
{
nsresult rv;
nsCOMPtr<nsIInputStream> in;
rv = channel->OpenInputStream(getter_AddRefs(in));
if (NS_FAILED(rv)) return rv;
rv = consumer->OnStartRequest(channel, context);
if (NS_FAILED(rv)) return rv;
PRUint32 sourceOffset = 0;
while (1) {
char buf[1024];
PRUint32 readCount;
rv = in->Read(buf, sizeof(buf), &readCount);
if (NS_FAILED(rv))
break;
if (readCount == 0) // eof
break;
rv = consumer->OnDataAvailable(channel, context, 0, sourceOffset, readCount);
sourceOffset += readCount;
if (NS_FAILED(rv))
break;
}
rv = consumer->OnStopRequest(channel, context, rv, nsnull);
if (NS_FAILED(rv)) return rv;
return rv;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// URL parsing utilities // URL parsing utilities

View File

@@ -170,9 +170,6 @@ nsStreamIOChannel::Init(nsIURI* uri, nsIStreamIO* io)
return NS_OK; return NS_OK;
} }
NS_IMPL_THREADSAFE_ADDREF(nsStreamIOChannel)
NS_IMPL_THREADSAFE_RELEASE(nsStreamIOChannel)
NS_INTERFACE_MAP_BEGIN(nsStreamIOChannel) NS_INTERFACE_MAP_BEGIN(nsStreamIOChannel)
NS_INTERFACE_MAP_ENTRY(nsIStreamIOChannel) NS_INTERFACE_MAP_ENTRY(nsIStreamIOChannel)
NS_INTERFACE_MAP_ENTRY(nsIChannel) NS_INTERFACE_MAP_ENTRY(nsIChannel)
@@ -183,8 +180,8 @@ NS_INTERFACE_MAP_BEGIN(nsStreamIOChannel)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStreamListener) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStreamListener)
NS_INTERFACE_MAP_END_THREADSAFE NS_INTERFACE_MAP_END_THREADSAFE
//////////////////////////////////////////////////////////////////////////////// NS_IMPL_THREADSAFE_ADDREF(nsStreamIOChannel)
// nsIRequest methods: NS_IMPL_THREADSAFE_RELEASE(nsStreamIOChannel)
NS_IMETHODIMP NS_IMETHODIMP
nsStreamIOChannel::GetName(PRUnichar* *result) nsStreamIOChannel::GetName(PRUnichar* *result)
@@ -202,8 +199,8 @@ nsStreamIOChannel::GetName(PRUnichar* *result)
NS_IMETHODIMP NS_IMETHODIMP
nsStreamIOChannel::IsPending(PRBool *result) nsStreamIOChannel::IsPending(PRBool *result)
{ {
if (mFileTransport) if (mRequest)
return mFileTransport->IsPending(result); return mRequest->IsPending(result);
*result = PR_FALSE; *result = PR_FALSE;
return NS_OK; return NS_OK;
} }
@@ -215,8 +212,8 @@ nsStreamIOChannel::GetStatus(nsresult *status)
// if we don't have a status error of our own to report // if we don't have a status error of our own to report
// then we should propogate the status error of the underlying // then we should propogate the status error of the underlying
// file transport (if we have one) // file transport (if we have one)
if (NS_SUCCEEDED(mStatus) && mFileTransport) if (NS_SUCCEEDED(mStatus) && mRequest)
mFileTransport->GetStatus(status); mRequest->GetStatus(status);
return NS_OK; return NS_OK;
} }
@@ -226,29 +223,30 @@ nsStreamIOChannel::Cancel(nsresult status)
{ {
NS_ASSERTION(NS_FAILED(status), "shouldn't cancel with a success code"); NS_ASSERTION(NS_FAILED(status), "shouldn't cancel with a success code");
mStatus = status; mStatus = status;
if (mFileTransport) if (mRequest)
return mFileTransport->Cancel(status); return mRequest->Cancel(status);
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsStreamIOChannel::Suspend(void) nsStreamIOChannel::Suspend(void)
{ {
if (mFileTransport) if (mRequest)
return mFileTransport->Suspend(); return mRequest->Suspend();
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsStreamIOChannel::Resume(void) nsStreamIOChannel::Resume(void)
{ {
if (mFileTransport) if (mRequest)
return mFileTransport->Resume(); return mRequest->Resume();
return NS_OK; return NS_OK;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// nsIChannel methods: // nsIChannel implementation:
////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP NS_IMETHODIMP
nsStreamIOChannel::GetOriginalURI(nsIURI* *aURI) nsStreamIOChannel::GetOriginalURI(nsIURI* *aURI)
@@ -281,19 +279,13 @@ nsStreamIOChannel::SetURI(nsIURI* aURI)
} }
NS_IMETHODIMP NS_IMETHODIMP
nsStreamIOChannel::OpenInputStream(nsIInputStream **result) nsStreamIOChannel::Open(nsIInputStream **result)
{ {
return mStreamIO->GetInputStream(result); return mStreamIO->GetInputStream(result);
} }
NS_IMETHODIMP NS_IMETHODIMP
nsStreamIOChannel::OpenOutputStream(nsIOutputStream **result) nsStreamIOChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctxt)
{
return mStreamIO->GetOutputStream(result);
}
NS_IMETHODIMP
nsStreamIOChannel::AsyncRead(nsIStreamListener *listener, nsISupports *ctxt)
{ {
nsresult rv; nsresult rv;
@@ -315,7 +307,7 @@ nsStreamIOChannel::AsyncRead(nsIStreamListener *listener, nsISupports *ctxt)
} }
} }
rv = mLoadGroup->AddChannel(this, nsnull); rv = mLoadGroup->AddRequest(this, nsnull);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
} }
@@ -325,14 +317,6 @@ nsStreamIOChannel::AsyncRead(nsIStreamListener *listener, nsISupports *ctxt)
rv = fts->CreateTransportFromStreamIO(mStreamIO, getter_AddRefs(mFileTransport)); rv = fts->CreateTransportFromStreamIO(mStreamIO, getter_AddRefs(mFileTransport));
if (NS_FAILED(rv)) goto done; if (NS_FAILED(rv)) goto done;
if (mBufferSegmentSize > 0) {
rv = mFileTransport->SetBufferSegmentSize(mBufferSegmentSize);
if (NS_FAILED(rv)) goto done;
}
if (mBufferMaxSize > 0) {
rv = mFileTransport->SetBufferMaxSize(mBufferMaxSize);
if (NS_FAILED(rv)) goto done;
}
} }
#if 0 #if 0
@@ -341,78 +325,13 @@ nsStreamIOChannel::AsyncRead(nsIStreamListener *listener, nsISupports *ctxt)
if (NS_FAILED(rv)) goto done; if (NS_FAILED(rv)) goto done;
} }
#endif #endif
rv = mFileTransport->AsyncRead(this, ctxt); rv = mFileTransport->AsyncRead(this, ctxt, 0, -1, 0, getter_AddRefs(mRequest));
done: done:
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
nsresult rv2; nsresult rv2;
rv2 = mLoadGroup->RemoveChannel(this, ctxt, rv, nsnull); rv2 = mLoadGroup->RemoveRequest(this, ctxt, rv, nsnull);
NS_ASSERTION(NS_SUCCEEDED(rv2), "RemoveChannel failed"); NS_ASSERTION(NS_SUCCEEDED(rv2), "RemoveRequest failed");
// release the transport so that we don't think we're in progress
mFileTransport = nsnull;
}
return rv;
}
NS_IMETHODIMP
nsStreamIOChannel::AsyncWrite(nsIStreamProvider *provider, nsISupports *ctxt)
{
nsresult rv;
NS_ASSERTION(provider, "no provider");
SetProvider(provider);
if (mLoadGroup) {
nsCOMPtr<nsILoadGroupListenerFactory> factory;
//
// Create a load group "proxy" listener...
//
rv = mLoadGroup->GetGroupListenerFactory(getter_AddRefs(factory));
if (factory) {
NS_WARNING("load group proxy listener not implemented for AsyncWrite");
#if 0
nsIStreamListener *newListener;
rv = factory->CreateLoadGroupListener(GetListener(), &newListener);
if (NS_SUCCEEDED(rv)) {
mUserObserver = newListener;
NS_RELEASE(newListener);
}
#endif
}
rv = mLoadGroup->AddChannel(this, nsnull);
if (NS_FAILED(rv)) return rv;
}
if (mFileTransport == nsnull) {
NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv);
if (NS_FAILED(rv)) goto done;
rv = fts->CreateTransportFromStreamIO(mStreamIO, getter_AddRefs(mFileTransport));
if (NS_FAILED(rv)) goto done;
if (mBufferSegmentSize > 0) {
rv = mFileTransport->SetBufferSegmentSize(mBufferSegmentSize);
if (NS_FAILED(rv)) goto done;
}
if (mBufferMaxSize > 0) {
rv = mFileTransport->SetBufferMaxSize(mBufferMaxSize);
if (NS_FAILED(rv)) goto done;
}
}
#if 0
if (mContentType == nsnull) {
rv = mStreamIO->Open(&mContentType, &mContentLength);
if (NS_FAILED(rv)) goto done;
}
#endif
rv = mFileTransport->AsyncWrite(this, ctxt);
done:
if (NS_FAILED(rv)) {
nsresult rv2;
rv2 = mLoadGroup->RemoveChannel(this, ctxt, rv, nsnull);
NS_ASSERTION(NS_SUCCEEDED(rv2), "RemoveChannel failed");
// release the transport so that we don't think we're in progress // release the transport so that we don't think we're in progress
mFileTransport = nsnull; mFileTransport = nsnull;
} }
@@ -433,127 +352,6 @@ nsStreamIOChannel::SetLoadAttributes(nsLoadFlags aLoadAttributes)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
nsStreamIOChannel::GetContentType(char * *aContentType)
{
nsresult rv;
if (mContentType == nsnull) {
rv = mStreamIO->Open(&mContentType, &mContentLength);
if (NS_FAILED(rv)) return rv;
}
*aContentType = nsCRT::strdup(mContentType);
if (*aContentType == nsnull) {
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
NS_IMETHODIMP
nsStreamIOChannel::SetContentType(const char *aContentType)
{
mContentType = nsCRT::strdup(aContentType);
if (*aContentType == nsnull) {
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
NS_IMETHODIMP
nsStreamIOChannel::GetContentLength(PRInt32 *aContentLength)
{
nsresult rv;
if (mContentType == nsnull) {
rv = mStreamIO->Open(&mContentType, &mContentLength);
if (NS_FAILED(rv)) return rv;
}
*aContentLength = mContentLength;
return NS_OK;
}
NS_IMETHODIMP
nsStreamIOChannel::SetContentLength(PRInt32 aContentLength)
{
mContentLength = aContentLength;
return NS_OK;
}
NS_IMETHODIMP
nsStreamIOChannel::GetTransferOffset(PRUint32 *aTransferOffset)
{
NS_NOTREACHED("nsStreamIOChannel::GetTransferOffset");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsStreamIOChannel::SetTransferOffset(PRUint32 aTransferOffset)
{
NS_NOTREACHED("nsStreamIOChannel::SetTransferOffset");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsStreamIOChannel::GetTransferCount(PRInt32 *aTransferCount)
{
NS_NOTREACHED("nsStreamIOChannel::GetTransferCount");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsStreamIOChannel::SetTransferCount(PRInt32 aTransferCount)
{
NS_NOTREACHED("nsStreamIOChannel::SetTransferCount");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsStreamIOChannel::GetBufferSegmentSize(PRUint32 *aBufferSegmentSize)
{
*aBufferSegmentSize = mBufferSegmentSize;
return NS_OK;
}
NS_IMETHODIMP
nsStreamIOChannel::SetBufferSegmentSize(PRUint32 aBufferSegmentSize)
{
mBufferSegmentSize = aBufferSegmentSize;
return NS_OK;
}
NS_IMETHODIMP
nsStreamIOChannel::GetBufferMaxSize(PRUint32 *aBufferMaxSize)
{
*aBufferMaxSize = mBufferMaxSize;
return NS_OK;
}
NS_IMETHODIMP
nsStreamIOChannel::SetBufferMaxSize(PRUint32 aBufferMaxSize)
{
mBufferMaxSize = aBufferMaxSize;
return NS_OK;
}
NS_IMETHODIMP
nsStreamIOChannel::GetLocalFile(nsIFile* *file)
{
*file = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsStreamIOChannel::GetPipeliningAllowed(PRBool *aPipeliningAllowed)
{
*aPipeliningAllowed = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
nsStreamIOChannel::SetPipeliningAllowed(PRBool aPipeliningAllowed)
{
NS_NOTREACHED("nsStreamIOChannel::SetPipeliningAllowed");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP NS_IMETHODIMP
nsStreamIOChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup) nsStreamIOChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup)
{ {
@@ -599,7 +397,6 @@ nsStreamIOChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotification
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsStreamIOChannel::GetSecurityInfo(nsISupports * *aSecurityInfo) nsStreamIOChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
{ {
@@ -607,19 +404,63 @@ nsStreamIOChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
nsStreamIOChannel::GetContentType(char * *aContentType)
{
nsresult rv;
if (mContentType == nsnull) {
rv = mStreamIO->Open(&mContentType, &mContentLength);
if (NS_FAILED(rv)) return rv;
}
*aContentType = nsCRT::strdup(mContentType);
if (*aContentType == nsnull) {
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
NS_IMETHODIMP
nsStreamIOChannel::SetContentType(const char *aContentType)
{
mContentType = nsCRT::strdup(aContentType);
if (*aContentType == nsnull) {
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
NS_IMETHODIMP
nsStreamIOChannel::GetContentLength(PRInt32 *aContentLength)
{
nsresult rv;
if (mContentType == nsnull) {
rv = mStreamIO->Open(&mContentType, &mContentLength);
if (NS_FAILED(rv)) return rv;
}
*aContentLength = mContentLength;
return NS_OK;
}
NS_IMETHODIMP
nsStreamIOChannel::SetContentLength(PRInt32 aContentLength)
{
mContentLength = aContentLength;
return NS_OK;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// nsIStreamObserver implementation: // nsIStreamObserver implementation:
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP NS_IMETHODIMP
nsStreamIOChannel::OnStartRequest(nsIChannel* transportChannel, nsISupports* context) nsStreamIOChannel::OnStartRequest(nsIRequest *request, nsISupports* context)
{ {
NS_ASSERTION(mUserObserver, "No listener..."); NS_ASSERTION(mUserObserver, "No listener...");
return mUserObserver->OnStartRequest(this, context); return mUserObserver->OnStartRequest(this, context);
} }
NS_IMETHODIMP NS_IMETHODIMP
nsStreamIOChannel::OnStopRequest(nsIChannel* transportChannel, nsISupports* context, nsStreamIOChannel::OnStopRequest(nsIRequest *request, nsISupports* context,
nsresult aStatus, const PRUnichar* aStatusArg) nsresult aStatus, const PRUnichar* aStatusArg)
{ {
nsresult rv; nsresult rv;
@@ -631,7 +472,7 @@ nsStreamIOChannel::OnStopRequest(nsIChannel* transportChannel, nsISupports* cont
if (mLoadGroup) { if (mLoadGroup) {
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
rv = mLoadGroup->RemoveChannel(this, context, aStatus, aStatusArg); rv = mLoadGroup->RemoveRequest(this, context, aStatus, aStatusArg);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
} }
} }
@@ -648,7 +489,7 @@ nsStreamIOChannel::OnStopRequest(nsIChannel* transportChannel, nsISupports* cont
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP NS_IMETHODIMP
nsStreamIOChannel::OnDataAvailable(nsIChannel* transportChannel, nsISupports* context, nsStreamIOChannel::OnDataAvailable(nsIRequest *request, nsISupports* context,
nsIInputStream *aIStream, PRUint32 aSourceOffset, nsIInputStream *aIStream, PRUint32 aSourceOffset,
PRUint32 aLength) PRUint32 aLength)
{ {
@@ -661,9 +502,9 @@ nsStreamIOChannel::OnDataAvailable(nsIChannel* transportChannel, nsISupports* co
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP NS_IMETHODIMP
nsStreamIOChannel::OnDataWritable(nsIChannel* transportChannel, nsISupports* context, nsStreamIOChannel::OnDataWritable(nsIRequest *request, nsISupports *context,
nsIOutputStream *aOStream, PRUint32 aOffset, nsIOutputStream *aOStream,
PRUint32 aLength) PRUint32 aOffset, PRUint32 aLength)
{ {
return GetProvider()->OnDataWritable(this, context, aOStream, return GetProvider()->OnDataWritable(this, context, aOStream,
aOffset, aLength); aOffset, aLength);

View File

@@ -32,6 +32,7 @@
#include "nsIStreamProvider.h" #include "nsIStreamProvider.h"
#include "nsIInterfaceRequestor.h" #include "nsIInterfaceRequestor.h"
#include "nsIStreamIO.h" #include "nsIStreamIO.h"
#include "nsITransport.h"
class nsInputStreamIO : public nsIInputStreamIO class nsInputStreamIO : public nsIInputStreamIO
{ {
@@ -90,7 +91,8 @@ protected:
nsCOMPtr<nsIStreamIO> mStreamIO; nsCOMPtr<nsIStreamIO> mStreamIO;
nsCOMPtr<nsILoadGroup> mLoadGroup; nsCOMPtr<nsILoadGroup> mLoadGroup;
nsCOMPtr<nsISupports> mOwner; nsCOMPtr<nsISupports> mOwner;
nsCOMPtr<nsIChannel> mFileTransport; nsCOMPtr<nsITransport> mFileTransport;
nsCOMPtr<nsIRequest> mRequest;
nsCOMPtr<nsIStreamObserver> mUserObserver; nsCOMPtr<nsIStreamObserver> mUserObserver;
PRUint32 mBufferSegmentSize; PRUint32 mBufferSegmentSize;
PRUint32 mBufferMaxSize; PRUint32 mBufferMaxSize;

View File

@@ -56,7 +56,7 @@ PRLogModuleInfo* gLoadGroupLog = nsnull;
nsLoadGroup::nsLoadGroup(nsISupports* outer) nsLoadGroup::nsLoadGroup(nsISupports* outer)
: mDefaultLoadAttributes(nsIChannel::LOAD_NORMAL), : mDefaultLoadAttributes(nsIChannel::LOAD_NORMAL),
mForegroundCount(0), mForegroundCount(0),
mChannels(nsnull), mRequests(nsnull),
mStatus(NS_OK) mStatus(NS_OK)
{ {
NS_INIT_AGGREGATED(outer); NS_INIT_AGGREGATED(outer);
@@ -82,8 +82,8 @@ nsLoadGroup::~nsLoadGroup()
rv = Cancel(NS_BINDING_ABORTED); rv = Cancel(NS_BINDING_ABORTED);
NS_ASSERTION(NS_SUCCEEDED(rv), "Cancel failed"); NS_ASSERTION(NS_SUCCEEDED(rv), "Cancel failed");
NS_IF_RELEASE(mChannels); NS_IF_RELEASE(mRequests);
mDefaultLoadChannel = null_nsCOMPtr(); mDefaultLoadRequest = null_nsCOMPtr();
PR_LOG(gLoadGroupLog, PR_LOG_DEBUG, PR_LOG(gLoadGroupLog, PR_LOG_DEBUG,
("LOADGROUP [%x]: Destroyed.\n", this)); ("LOADGROUP [%x]: Destroyed.\n", this));
@@ -92,7 +92,7 @@ nsLoadGroup::~nsLoadGroup()
nsresult nsLoadGroup::Init() nsresult nsLoadGroup::Init()
{ {
return NS_NewISupportsArray(&mChannels); return NS_NewISupportsArray(&mRequests);
} }
@@ -157,19 +157,20 @@ NS_IMETHODIMP
nsLoadGroup::GetName(PRUnichar* *result) nsLoadGroup::GetName(PRUnichar* *result)
{ {
// XXX is this the right "name" for a load group? // XXX is this the right "name" for a load group?
nsresult rv; *result = nsnull;
nsXPIDLCString urlStr;
if (mDefaultLoadChannel) { if (mDefaultLoadRequest) {
nsCOMPtr<nsIURI> url; nsXPIDLString nameStr;
rv = mDefaultLoadChannel->GetURI(getter_AddRefs(url)); nsresult rv = mDefaultLoadRequest->GetName(getter_Copies(nameStr));
if (NS_FAILED(rv)) return rv; if (NS_SUCCEEDED(rv)) {
rv = url->GetSpec(getter_Copies(urlStr));
if (NS_FAILED(rv)) return rv;
}
nsString name; nsString name;
name.AppendWithConversion(urlStr); name.Assign(nameStr);
*result = name.ToNewUnicode(); *result = name.ToNewUnicode();
return *result ? NS_OK : NS_ERROR_OUT_OF_MEMORY; return *result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
}
return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
@@ -187,8 +188,8 @@ nsLoadGroup::IsPending(PRBool *aResult)
NS_IMETHODIMP NS_IMETHODIMP
nsLoadGroup::GetStatus(nsresult *status) nsLoadGroup::GetStatus(nsresult *status)
{ {
if (NS_SUCCEEDED(mStatus) && mDefaultLoadChannel) if (NS_SUCCEEDED(mStatus) && mDefaultLoadRequest)
return mDefaultLoadChannel->GetStatus(status); return mDefaultLoadRequest->GetStatus(status);
*status = mStatus; *status = mStatus;
return NS_OK; return NS_OK;
@@ -206,67 +207,57 @@ nsLoadGroup::Cancel(nsresult status)
mStatus = status; mStatus = status;
rv = mChannels->Count(&count); rv = mRequests->Count(&count);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
firstError = NS_OK; firstError = NS_OK;
if (count) { if (count) {
nsIChannel* channel; nsIRequest* request;
// //
// Operate the elements from back to front so that if items get // Operate the elements from back to front so that if items get
// get removed from the list it won't affect our iteration // get removed from the list it won't affect our iteration
// //
while (count > 0) { while (count > 0) {
channel = NS_STATIC_CAST(nsIChannel*, mChannels->ElementAt(--count)); request = NS_STATIC_CAST(nsIRequest*, mRequests->ElementAt(--count));
NS_ASSERTION(channel, "NULL channel found in list."); NS_ASSERTION(request, "NULL request found in list.");
if (!channel) { if (!request) {
continue; continue;
} }
#if defined(PR_LOGGING) #if defined(PR_LOGGING)
char* uriStr; nsXPIDLString nameStr;
nsCOMPtr<nsIURI> uri; request->GetName(getter_Copies(nameStr));
rv = channel->GetURI(getter_AddRefs(uri));
if (NS_SUCCEEDED(rv)) {
rv = uri->GetSpec(&uriStr);
}
if (NS_FAILED(rv)) {
uriStr = nsCRT::strdup("?");
}
PR_LOG(gLoadGroupLog, PR_LOG_DEBUG, PR_LOG(gLoadGroupLog, PR_LOG_DEBUG,
("LOADGROUP [%x]: Canceling channel %x %s.\n", ("LOADGROUP [%x]: Canceling request %x %s.\n",
this, channel, uriStr)); this, request, NS_ConvertUCS2toUTF8(nameStr).get()));
nsCRT::free(uriStr);
#endif /* PR_LOGGING */ #endif /* PR_LOGGING */
// //
// Remove the channel from the load group... This may cause // Remove the request from the load group... This may cause
// the OnStopRequest notification to fire... // the OnStopRequest notification to fire...
// //
// XXX: What should the context and error message be? // XXX: What should the context and error message be?
// //
(void)RemoveChannel(channel, nsnull, status, nsnull); (void)RemoveRequest(request, nsnull, status, nsnull);
// Cancel the channel... // Cancel the request...
rv = channel->Cancel(status); rv = request->Cancel(status);
// Remember the first failure and return it... // Remember the first failure and return it...
if (NS_FAILED(rv) && NS_SUCCEEDED(firstError)) { if (NS_FAILED(rv) && NS_SUCCEEDED(firstError)) {
firstError = rv; firstError = rv;
} }
NS_RELEASE(channel); NS_RELEASE(request);
} }
#if defined(DEBUG) #if defined(DEBUG)
(void)mChannels->Count(&count); (void)mRequests->Count(&count);
NS_ASSERTION(count == 0, "Channel list is not empty."); NS_ASSERTION(count == 0, "Request list is not empty.");
NS_ASSERTION(mForegroundCount == 0, "Foreground URLs are active."); NS_ASSERTION(mForegroundCount == 0, "Foreground URLs are active.");
#endif /* DEBUG */ #endif /* DEBUG */
} }
@@ -282,7 +273,7 @@ nsLoadGroup::Suspend()
nsresult rv, firstError; nsresult rv, firstError;
PRUint32 count; PRUint32 count;
rv = mChannels->Count(&count); rv = mRequests->Count(&count);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
firstError = NS_OK; firstError = NS_OK;
@@ -291,42 +282,30 @@ nsLoadGroup::Suspend()
// get removed from the list it won't affect our iteration // get removed from the list it won't affect our iteration
// //
while (count > 0) { while (count > 0) {
nsIChannel* channel; nsIRequest* request = NS_STATIC_CAST(nsIRequest*, mRequests->ElementAt(--count));
channel = NS_STATIC_CAST(nsIChannel*, mChannels->ElementAt(--count)); NS_ASSERTION(request, "NULL request found in list.");
if (!request) {
NS_ASSERTION(channel, "NULL channel found in list.");
if (!channel) {
continue; continue;
} }
#if defined(PR_LOGGING) #if defined(PR_LOGGING)
char* uriStr; nsXPIDLString nameStr;
nsCOMPtr<nsIURI> uri; request->GetName(getter_Copies(nameStr));
rv = channel->GetURI(getter_AddRefs(uri));
if (NS_SUCCEEDED(rv)) {
rv = uri->GetSpec(&uriStr);
}
if (NS_FAILED(rv)) {
uriStr = nsCRT::strdup("?");
}
PR_LOG(gLoadGroupLog, PR_LOG_DEBUG, PR_LOG(gLoadGroupLog, PR_LOG_DEBUG,
("LOADGROUP [%x]: Suspending channel %x %s.\n", ("LOADGROUP [%x]: Suspending request %x %s.\n",
this, channel, uriStr)); this, request, NS_ConvertUCS2toUTF8(nameStr).get()));
nsCRT::free(uriStr);
#endif /* PR_LOGGING */ #endif /* PR_LOGGING */
// Suspend the channel... // Suspend the request...
rv = channel->Suspend(); rv = request->Suspend();
// Remember the first failure and return it... // Remember the first failure and return it...
if (NS_FAILED(rv) && NS_SUCCEEDED(firstError)) { if (NS_FAILED(rv) && NS_SUCCEEDED(firstError)) {
firstError = rv; firstError = rv;
} }
NS_RELEASE(channel); NS_RELEASE(request);
} }
return firstError; return firstError;
@@ -339,7 +318,7 @@ nsLoadGroup::Resume()
nsresult rv, firstError; nsresult rv, firstError;
PRUint32 count; PRUint32 count;
rv = mChannels->Count(&count); rv = mRequests->Count(&count);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
firstError = NS_OK; firstError = NS_OK;
@@ -348,42 +327,30 @@ nsLoadGroup::Resume()
// get removed from the list it won't affect our iteration // get removed from the list it won't affect our iteration
// //
while (count > 0) { while (count > 0) {
nsIChannel* channel; nsIRequest* request = NS_STATIC_CAST(nsIRequest*, mRequests->ElementAt(--count));
channel = NS_STATIC_CAST(nsIChannel*, mChannels->ElementAt(--count)); NS_ASSERTION(request, "NULL request found in list.");
if (!request) {
NS_ASSERTION(channel, "NULL channel found in list.");
if (!channel) {
continue; continue;
} }
#if defined(PR_LOGGING) #if defined(PR_LOGGING)
char* uriStr; nsXPIDLString nameStr;
nsCOMPtr<nsIURI> uri; request->GetName(getter_Copies(nameStr));
rv = channel->GetURI(getter_AddRefs(uri));
if (NS_SUCCEEDED(rv)) {
rv = uri->GetSpec(&uriStr);
}
if (NS_FAILED(rv)) {
uriStr = nsCRT::strdup("?");
}
PR_LOG(gLoadGroupLog, PR_LOG_DEBUG, PR_LOG(gLoadGroupLog, PR_LOG_DEBUG,
("LOADGROUP [%x]: Resuming channel %x %s.\n", ("LOADGROUP [%x]: Resuming request %x %s.\n",
this, channel, uriStr)); this, request, NS_ConvertUCS2toUTF8(nameStr).get()));
nsCRT::free(uriStr);
#endif /* PR_LOGGING */ #endif /* PR_LOGGING */
// Resume the channel... // Resume the request...
rv = channel->Resume(); rv = request->Resume();
// Remember the first failure and return it... // Remember the first failure and return it...
if (NS_FAILED(rv) && NS_SUCCEEDED(firstError)) { if (NS_FAILED(rv) && NS_SUCCEEDED(firstError)) {
firstError = rv; firstError = rv;
} }
NS_RELEASE(channel); NS_RELEASE(request);
} }
return firstError; return firstError;
@@ -417,58 +384,46 @@ nsLoadGroup::SetDefaultLoadAttributes(PRUint32 aDefaultLoadAttributes)
} }
NS_IMETHODIMP NS_IMETHODIMP
nsLoadGroup::GetDefaultLoadChannel(nsIChannel * *aChannel) nsLoadGroup::GetDefaultLoadRequest(nsIRequest * *aRequest)
{ {
*aChannel = mDefaultLoadChannel; *aRequest = mDefaultLoadRequest;
NS_IF_ADDREF(*aChannel); NS_IF_ADDREF(*aRequest);
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsLoadGroup::SetDefaultLoadChannel(nsIChannel *aChannel) nsLoadGroup::SetDefaultLoadRequest(nsIRequest *aRequest)
{ {
mDefaultLoadChannel = aChannel; mDefaultLoadRequest = aRequest;
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsLoadGroup::AddChannel(nsIChannel *channel, nsISupports* ctxt) nsLoadGroup::AddRequest(nsIRequest *request, nsISupports* ctxt)
{ {
nsresult rv; nsresult rv;
#if defined(PR_LOGGING) #if defined(PR_LOGGING)
{ PRUint32 count = 0;
PRUint32 count; (void)mRequests->Count(&count);
char* uriStr; nsXPIDLString nameStr;
nsCOMPtr<nsIURI> uri; request->GetName(getter_Copies(nameStr));
rv = channel->GetURI(getter_AddRefs(uri));
if (NS_SUCCEEDED(rv))
rv = uri->GetSpec(&uriStr);
if (NS_FAILED(rv))
uriStr = nsCRT::strdup("?");
(void)mChannels->Count(&count);
PR_LOG(gLoadGroupLog, PR_LOG_DEBUG, PR_LOG(gLoadGroupLog, PR_LOG_DEBUG,
("LOADGROUP [%x]: Adding channel %x %s (count=%d).\n", ("LOADGROUP [%x]: Adding request %x %s (count=%d).\n",
this, channel, uriStr, count)); this, request, NS_ConvertUCS2toUTF8(nameStr).get(), count));
nsCRT::free(uriStr);
}
#endif /* PR_LOGGING */ #endif /* PR_LOGGING */
nsLoadFlags flags; nsLoadFlags flags;
rv = MergeLoadAttributes(request, flags);
MergeLoadAttributes(channel);
rv = channel->GetLoadAttributes(&flags);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
// //
// Add the channel to the list of active channels... // Add the request to the list of active requests...
// //
// XXX this method incorrectly returns a bool // XXX this method incorrectly returns a bool
// //
rv = mChannels->AppendElement(channel) ? NS_OK : NS_ERROR_FAILURE; rv = mRequests->AppendElement(request) ? NS_OK : NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
if (!(flags & nsIChannel::LOAD_BACKGROUND)) { if (!(flags & nsIChannel::LOAD_BACKGROUND)) {
@@ -478,28 +433,28 @@ nsLoadGroup::AddChannel(nsIChannel *channel, nsISupports* ctxt)
// //
// Fire the OnStartRequest notification out to the observer... // Fire the OnStartRequest notification out to the observer...
// //
// If the notification fails then DO NOT add the channel to // If the notification fails then DO NOT add the request to
// the load group. // the load group.
// //
nsCOMPtr<nsIStreamObserver> observer (do_QueryReferent(mObserver)); nsCOMPtr<nsIStreamObserver> observer (do_QueryReferent(mObserver));
if (observer) { if (observer) {
PR_LOG(gLoadGroupLog, PR_LOG_DEBUG, PR_LOG(gLoadGroupLog, PR_LOG_DEBUG,
("LOADGROUP [%x]: Firing OnStartRequest for channel %x." ("LOADGROUP [%x]: Firing OnStartRequest for request %x."
"(foreground count=%d).\n", "(foreground count=%d).\n",
this, channel, mForegroundCount)); this, request, mForegroundCount));
rv = observer->OnStartRequest(channel, ctxt); rv = observer->OnStartRequest(request, ctxt);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
PR_LOG(gLoadGroupLog, PR_LOG_ERROR, PR_LOG(gLoadGroupLog, PR_LOG_ERROR,
("LOADGROUP [%x]: OnStartRequest for channel %x FAILED.\n", ("LOADGROUP [%x]: OnStartRequest for request %x FAILED.\n",
this, channel)); this, request));
// //
// The URI load has been canceled by the observer. Clean up // The URI load has been canceled by the observer. Clean up
// the damage... // the damage...
// //
// XXX this method incorrectly returns a bool // XXX this method incorrectly returns a bool
// //
rv = mChannels->RemoveElement(channel) ? NS_OK : NS_ERROR_FAILURE; rv = mRequests->RemoveElement(request) ? NS_OK : NS_ERROR_FAILURE;
mForegroundCount -= 1; mForegroundCount -= 1;
} }
} }
@@ -509,56 +464,43 @@ nsLoadGroup::AddChannel(nsIChannel *channel, nsISupports* ctxt)
} }
NS_IMETHODIMP NS_IMETHODIMP
nsLoadGroup::RemoveChannel(nsIChannel *channel, nsISupports* ctxt, nsLoadGroup::RemoveRequest(nsIRequest *request, nsISupports* ctxt,
nsresult aStatus, const PRUnichar* aStatusArg) nsresult aStatus, const PRUnichar* aStatusArg)
{ {
nsresult rv; nsresult rv;
#if defined(PR_LOGGING) #if defined(PR_LOGGING)
{
PRUint32 count = 0; PRUint32 count = 0;
char* uriStr; (void)mRequests->Count(&count);
nsCOMPtr<nsIURI> uri; nsXPIDLString nameStr;
request->GetName(getter_Copies(nameStr));
if (channel) {
rv = channel->GetURI(getter_AddRefs(uri));
}
else {
rv = NS_ERROR_NULL_POINTER;
}
if (NS_SUCCEEDED(rv))
rv = uri->GetSpec(&uriStr);
if (NS_FAILED(rv))
uriStr = nsCRT::strdup("?");
(void)mChannels->Count(&count);
PR_LOG(gLoadGroupLog, PR_LOG_DEBUG, PR_LOG(gLoadGroupLog, PR_LOG_DEBUG,
("LOADGROUP [%x]: Removing channel %x %s status %x (count=%d).\n", ("LOADGROUP [%x]: Removing request %x %s status %x (count=%d).\n",
this, channel, uriStr, aStatus, count-1)); this, request, NS_ConvertUCS2toUTF8(nameStr).get(), aStatus, count-1));
nsCRT::free(uriStr);
}
#endif /* PR_LOGGING */ #endif /* PR_LOGGING */
// //
// Remove the channel from the group. If this fails, it means that // Remove the request from the group. If this fails, it means that
// the channel was *not* in the group so do not update the foreground // the request was *not* in the group so do not update the foreground
// count or it will get messed up... // count or it will get messed up...
// //
// //
// XXX this method incorrectly returns a bool // XXX this method incorrectly returns a bool
// //
rv = mChannels->RemoveElement(channel) ? NS_OK : NS_ERROR_FAILURE; rv = mRequests->RemoveElement(request) ? NS_OK : NS_ERROR_FAILURE;
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
PR_LOG(gLoadGroupLog, PR_LOG_ERROR, PR_LOG(gLoadGroupLog, PR_LOG_ERROR,
("LOADGROUP [%x]: Unable to remove channel %x. Not in group!\n", ("LOADGROUP [%x]: Unable to remove request %x. Not in group!\n",
this, channel)); this, request));
return rv; return rv;
} }
nsLoadFlags flags; nsLoadFlags flags;
rv = channel->GetLoadAttributes(&flags); nsCOMPtr<nsIChannel> aChannel = do_QueryInterface(request, &rv);
if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
rv = aChannel->GetLoadAttributes(&flags);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
if (!(flags & nsIChannel::LOAD_BACKGROUND)) { if (!(flags & nsIChannel::LOAD_BACKGROUND)) {
@@ -569,15 +511,15 @@ nsLoadGroup::RemoveChannel(nsIChannel *channel, nsISupports* ctxt,
nsCOMPtr<nsIStreamObserver> observer (do_QueryReferent(mObserver)); nsCOMPtr<nsIStreamObserver> observer (do_QueryReferent(mObserver));
if (observer) { if (observer) {
PR_LOG(gLoadGroupLog, PR_LOG_DEBUG, PR_LOG(gLoadGroupLog, PR_LOG_DEBUG,
("LOADGROUP [%x]: Firing OnStopRequest for channel %x." ("LOADGROUP [%x]: Firing OnStopRequest for request %x."
"(foreground count=%d).\n", "(foreground count=%d).\n",
this, channel, mForegroundCount)); this, request, mForegroundCount));
rv = observer->OnStopRequest(channel, ctxt, aStatus, aStatusArg); rv = observer->OnStopRequest(request, ctxt, aStatus, aStatusArg);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
PR_LOG(gLoadGroupLog, PR_LOG_ERROR, PR_LOG(gLoadGroupLog, PR_LOG_ERROR,
("LOADGROUP [%x]: OnStopRequest for channel %x FAILED.\n", ("LOADGROUP [%x]: OnStopRequest for request %x FAILED.\n",
this, channel)); this, request));
} }
} }
} }
@@ -588,9 +530,9 @@ nsLoadGroup::RemoveChannel(nsIChannel *channel, nsISupports* ctxt,
NS_IMETHODIMP NS_IMETHODIMP
nsLoadGroup::GetChannels(nsISimpleEnumerator * *aChannels) nsLoadGroup::GetRequests(nsISimpleEnumerator * *aRequests)
{ {
return NS_NewArrayEnumerator(aChannels, mChannels); return NS_NewArrayEnumerator(aRequests, mRequests);
} }
@@ -659,13 +601,18 @@ nsLoadGroup::GetActiveCount(PRUint32* aResult)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
nsresult nsLoadGroup::MergeLoadAttributes(nsIChannel *aChannel) nsresult nsLoadGroup::MergeLoadAttributes(nsIRequest *aRequest, nsLoadFlags& outFlags)
{ {
nsresult rv; nsresult rv;
nsLoadFlags flags, oldFlags; nsLoadFlags flags, oldFlags;
nsCOMPtr<nsIChannel> aChannel = do_QueryInterface(aRequest, &rv);
if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
rv = aChannel->GetLoadAttributes(&flags); rv = aChannel->GetLoadAttributes(&flags);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv))
return rv;
oldFlags = flags; oldFlags = flags;
// //
@@ -707,6 +654,7 @@ nsresult nsLoadGroup::MergeLoadAttributes(nsIChannel *aChannel)
rv = aChannel->SetLoadAttributes(flags); rv = aChannel->SetLoadAttributes(flags);
} }
outFlags = flags;
return rv; return rv;
} }

View File

@@ -59,20 +59,19 @@ protected:
virtual ~nsLoadGroup(); virtual ~nsLoadGroup();
nsresult Init(); nsresult Init();
nsresult MergeLoadAttributes(nsIChannel *aChannel); nsresult MergeLoadAttributes(nsIRequest *aRequest, nsLoadFlags& flags);
protected: protected:
PRUint32 mDefaultLoadAttributes; PRUint32 mDefaultLoadAttributes;
PRUint32 mForegroundCount; PRUint32 mForegroundCount;
nsISupportsArray* mChannels; nsCOMPtr<nsIRequest> mDefaultLoadRequest;
nsISupportsArray* mRequests;
nsWeakPtr mObserver; nsWeakPtr mObserver;
// nsCOMPtr<nsIStreamObserver> mObserver; // nsCOMPtr<nsIStreamObserver> mObserver;
nsCOMPtr<nsIChannel> mDefaultLoadChannel;
nsWeakPtr mGroupListenerFactory; nsWeakPtr mGroupListenerFactory;
nsresult mStatus; nsresult mStatus;
}; };

View File

@@ -38,21 +38,21 @@ NS_IMPL_ISUPPORTS3(nsSimpleStreamListener,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// //
NS_IMETHODIMP NS_IMETHODIMP
nsSimpleStreamListener::OnStartRequest(nsIChannel *aChannel, nsSimpleStreamListener::OnStartRequest(nsIRequest *aRequest,
nsISupports *aContext) nsISupports *aContext)
{ {
return mObserver ? return mObserver ?
mObserver->OnStartRequest(aChannel, aContext) : NS_OK; mObserver->OnStartRequest(aRequest, aContext) : NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsSimpleStreamListener::OnStopRequest(nsIChannel *aChannel, nsSimpleStreamListener::OnStopRequest(nsIRequest* request,
nsISupports *aContext, nsISupports *aContext,
nsresult aStatus, nsresult aStatus,
const PRUnichar *aStatusText) const PRUnichar *aStatusText)
{ {
return mObserver ? return mObserver ?
mObserver->OnStopRequest(aChannel, aContext, aStatus, aStatusText) : NS_OK; mObserver->OnStopRequest(request, aContext, aStatus, aStatusText) : NS_OK;
} }
// //
@@ -61,7 +61,7 @@ nsSimpleStreamListener::OnStopRequest(nsIChannel *aChannel,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// //
NS_IMETHODIMP NS_IMETHODIMP
nsSimpleStreamListener::OnDataAvailable(nsIChannel *aChannel, nsSimpleStreamListener::OnDataAvailable(nsIRequest* request,
nsISupports *aContext, nsISupports *aContext,
nsIInputStream *aSource, nsIInputStream *aSource,
PRUint32 aOffset, PRUint32 aOffset,

View File

@@ -39,21 +39,21 @@ NS_IMPL_ISUPPORTS3(nsSimpleStreamProvider,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// //
NS_IMETHODIMP NS_IMETHODIMP
nsSimpleStreamProvider::OnStartRequest(nsIChannel *aChannel, nsSimpleStreamProvider::OnStartRequest(nsIRequest *request,
nsISupports *aContext) nsISupports *aContext)
{ {
return mObserver ? return mObserver ?
mObserver->OnStartRequest(aChannel, aContext) : NS_OK; mObserver->OnStartRequest(request, aContext) : NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsSimpleStreamProvider::OnStopRequest(nsIChannel *aChannel, nsSimpleStreamProvider::OnStopRequest(nsIRequest* request,
nsISupports *aContext, nsISupports *aContext,
nsresult aStatus, nsresult aStatus,
const PRUnichar *aStatusText) const PRUnichar *aStatusText)
{ {
return mObserver ? return mObserver ?
mObserver->OnStopRequest(aChannel, aContext, aStatus, aStatusText) : NS_OK; mObserver->OnStopRequest(request, aContext, aStatus, aStatusText) : NS_OK;
} }
// //
@@ -62,7 +62,7 @@ nsSimpleStreamProvider::OnStopRequest(nsIChannel *aChannel,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// //
NS_IMETHODIMP NS_IMETHODIMP
nsSimpleStreamProvider::OnDataWritable(nsIChannel *aChannel, nsSimpleStreamProvider::OnDataWritable(nsIRequest *request,
nsISupports *aContext, nsISupports *aContext,
nsIOutputStream *aOutput, nsIOutputStream *aOutput,
PRUint32 aOffset, PRUint32 aOffset,

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- /*
*
* The contents of this file are subject to the Netscape Public * The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file * License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of * except in compliance with the License. You may obtain a copy of
@@ -29,17 +28,15 @@
#include "prinrval.h" #include "prinrval.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsISocketTransport.h" #include "nsISocketTransport.h"
#include "nsIChannel.h"
#include "nsIInputStream.h"
#include "nsIInputStream.h" #include "nsIInputStream.h"
#include "nsIOutputStream.h" #include "nsIOutputStream.h"
#include "nsIEventQueueService.h" #include "nsIEventQueueService.h"
#include "nsIStreamListener.h" #include "nsIStreamListener.h"
#include "nsIStreamProvider.h" #include "nsIStreamProvider.h"
#include "nsIDNSListener.h" #include "nsIDNSListener.h"
#include "nsIDNSService.h"
#include "nsIPipe.h" #include "nsIPipe.h"
#include "nsIProgressEventSink.h" #include "nsIProgressEventSink.h"
#include "nsIInterfaceRequestor.h"
#define NS_SOCKET_TRANSPORT_SEGMENT_SIZE (2*1024) #define NS_SOCKET_TRANSPORT_SEGMENT_SIZE (2*1024)
#define NS_SOCKET_TRANSPORT_BUFFER_SIZE (8*1024) #define NS_SOCKET_TRANSPORT_BUFFER_SIZE (8*1024)
@@ -115,23 +112,23 @@ enum nsSocketReadWriteInfo {
// Forward declarations... // Forward declarations...
class nsSocketTransportService; class nsSocketTransportService;
class nsSocketInputStream; class nsSocketBS; // base class for blocking streams
class nsSocketOutputStream; class nsSocketBIS; // blocking input stream
class nsIInterfaceRequestor; class nsSocketBOS; // blocking output stream
class nsSocketIS; // input stream
class nsSocketOS; // output stream
class nsSocketRequest;
class nsSocketReadRequest;
class nsSocketWriteRequest;
class nsSocketTransport : public nsISocketTransport, class nsSocketTransport : public nsISocketTransport,
public nsIChannel, public nsIDNSListener
public nsIDNSListener,
public nsIInputStreamObserver,
public nsIOutputStreamObserver
{ {
public: public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
NS_DECL_NSITRANSPORT
NS_DECL_NSISOCKETTRANSPORT NS_DECL_NSISOCKETTRANSPORT
NS_DECL_NSIREQUEST
NS_DECL_NSICHANNEL
NS_DECL_NSIINPUTSTREAMOBSERVER
NS_DECL_NSIOUTPUTSTREAMOBSERVER
NS_DECL_NSIDNSLISTENER NS_DECL_NSIDNSLISTENER
// nsSocketTransport methods: // nsSocketTransport methods:
@@ -150,6 +147,8 @@ public:
nsresult Process(PRInt16 aSelectFlags); nsresult Process(PRInt16 aSelectFlags);
nsresult Cancel(nsresult status);
nsresult CheckForTimeout (PRIntervalTime aCurrentTime); nsresult CheckForTimeout (PRIntervalTime aCurrentTime);
// Close this socket either right away or once done with the transaction. // Close this socket either right away or once done with the transaction.
@@ -165,20 +164,25 @@ public:
PRBool CanBeReused(void) { return PRBool CanBeReused(void) { return
(mCurrentState != eSocketState_Error) && !mCloseConnectionOnceDone;} (mCurrentState != eSocketState_Error) && !mCloseConnectionOnceDone;}
//
// request helpers
//
nsresult GetName(PRUnichar **);
nsresult Dispatch(nsSocketRequest *);
nsresult OnProgress(nsSocketRequest *, nsISupports *ctxt, PRUint32 offset);
nsresult OnStatus(nsSocketRequest *, nsISupports *ctxt, nsresult message);
protected: protected:
nsresult doConnection(PRInt16 aSelectFlags); nsresult doConnection(PRInt16 aSelectFlags);
nsresult doResolveHost(void); nsresult doBlockingConnection();
nsresult doRead(PRInt16 aSelectFlags); nsresult doReadWrite(PRInt16 aSelectFlags);
nsresult doReadAsync(PRInt16 aSelectFlags); nsresult doResolveHost();
nsresult doWrite(PRInt16 aSelectFlags);
nsresult doWriteAsync(PRInt16 aSelectFlags);
nsresult doWriteFromBuffer(PRUint32 *aCount); nsresult OnStatus(nsresult message); // with either request
nsresult doWriteFromStream(PRUint32 *aCount);
nsresult fireStatus(PRUint32 aCode); void CompleteAsyncRead();
void CompleteAsyncWrite();
private:
PRIntervalTime mSocketTimeout; PRIntervalTime mSocketTimeout;
PRIntervalTime mSocketConnectTimeout; PRIntervalTime mSocketConnectTimeout;
@@ -206,70 +210,233 @@ private:
mReadWriteState &= ~aFlag; mReadWriteState &= ~aFlag;
} }
PRBool mOnStartWriteFired;
PRBool mOnStartReadFired;
protected: protected:
nsresult mCancelStatus;
PRBool mCloseConnectionOnceDone;
nsSocketState mCurrentState; nsSocketState mCurrentState;
nsCOMPtr<nsIRequest> mDNSRequest; nsCOMPtr<nsIRequest> mDNSRequest;
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
nsCOMPtr<nsIProgressEventSink> mEventSink; nsCOMPtr<nsIProgressEventSink> mEventSink;
char* mHostName; char* mHostName;
PRInt32 mPort; PRInt32 mPort;
PRIntervalTime mLastActiveTime; PRIntervalTime mLastActiveTime;
PRCList mListLink; PRCList mListLink;
PRUint32 mLoadAttributes;
PRMonitor* mMonitor; PRMonitor* mMonitor;
PRNetAddr mNetAddress; PRNetAddr mNetAddress;
nsSocketOperation mOperation; nsSocketOperation mOperation;
nsCOMPtr<nsISupports> mOwner;
nsCOMPtr<nsISupports> mSecurityInfo; nsCOMPtr<nsISupports> mSecurityInfo;
PRInt32 mProxyPort; PRInt32 mProxyPort;
char* mProxyHost; char* mProxyHost;
PRBool mProxyTransparent; PRPackedBool mProxyTransparent;
PRBool mSSLProxy; PRPackedBool mSSLProxy;
nsSocketTransportService* mService; nsSocketTransportService* mService;
PRUint32 mReadWriteState; PRUint32 mReadWriteState;
PRInt16 mSelectFlags; PRInt16 mSelectFlags;
nsresult mStatus; nsresult mStatus;
PRInt32 mSuspendCount;
PRFileDesc* mSocketFD; PRFileDesc* mSocketFD;
PRUint32 mSocketTypeCount; PRUint32 mSocketTypeCount;
char* *mSocketTypes; char* *mSocketTypes;
nsCOMPtr<nsIStreamListener> mReadListener;
nsCOMPtr<nsISupports> mReadContext;
PRUint32 mReadOffset;
nsCOMPtr<nsIStreamProvider> mWriteProvider;
nsCOMPtr<nsISupports> mWriteContext;
PRUint32 mWriteOffset;
PRInt32 mWriteCount;
PRInt32 mBytesExpected; PRInt32 mBytesExpected;
PRUint32 mReuseCount; PRUint32 mReuseCount;
PRUint32 mLastReuseCount; PRUint32 mLastReuseCount;
nsSocketInputStream *mSocketInputStream;
nsSocketOutputStream *mSocketOutputStream;
nsCOMPtr<nsIInputStream> mReadPipeIn;
nsCOMPtr<nsIOutputStream> mReadPipeOut;
nsCOMPtr<nsIInputStream> mWritePipeIn;
nsCOMPtr<nsIOutputStream> mWritePipeOut;
PRUint32 mBufferSegmentSize; PRUint32 mBufferSegmentSize;
PRUint32 mBufferMaxSize; PRUint32 mBufferMaxSize;
PRUint32 mIdleTimeoutInSeconds; PRUint32 mIdleTimeoutInSeconds;
PRBool mWasConnected;
nsSocketBIS *mBIS;
nsSocketBOS *mBOS;
nsSocketReadRequest *mReadRequest;
nsSocketWriteRequest *mWriteRequest;
PRPackedBool mCloseConnectionOnceDone;
PRPackedBool mWasConnected;
}; };
/**
* base blocking stream ...
*/
class nsSocketBS
{
public:
nsSocketBS();
virtual ~nsSocketBS();
void SetTransport(nsSocketTransport *);
void SetSocket(PRFileDesc *aSock) { mSock = aSock; }
nsresult Poll(PRInt16 event);
protected:
nsSocketTransport *mTransport;
PRFileDesc *mSock;
};
/**
* blocking input stream, returned by nsITransport::OpenInputStream()
*/
class nsSocketBIS : public nsSocketBS
, public nsIInputStream
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIINPUTSTREAM
nsSocketBIS();
virtual ~nsSocketBIS();
};
/**
* blocking output stream, returned by nsITransport::OpenOutputStream()
*/
class nsSocketBOS : public nsSocketBS
, public nsIOutputStream
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOUTPUTSTREAM
nsSocketBOS();
virtual ~nsSocketBOS();
};
/**
* input stream, passed to nsIStreamListener::OnDataAvailable()
*/
class nsSocketIS : public nsIInputStream
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIINPUTSTREAM
nsSocketIS();
virtual ~nsSocketIS() { }
void SetSocket(PRFileDesc *aSock) { mSock = aSock; }
PRUint32 GetOffset() { return mOffset; }
void SetOffset(PRUint32 o) { mOffset = o; }
PRBool GotWouldBlock() { return mError == PR_WOULD_BLOCK_ERROR; }
PRBool GotError() { return mError != 0; }
PRErrorCode GetError() { return mError; }
private:
PRUint32 mOffset;
PRFileDesc *mSock;
PRErrorCode mError;
};
/**
* output stream, passed to nsIStreamProvider::OnDataWritable()
*/
class nsSocketOS : public nsIOutputStream
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOUTPUTSTREAM
nsSocketOS();
virtual ~nsSocketOS() { }
void SetSocket(PRFileDesc *aSock) { mSock = aSock; }
PRUint32 GetOffset() { return mOffset; }
void SetOffset(PRUint32 o) { mOffset = o; }
PRBool GotWouldBlock() { return mError == PR_WOULD_BLOCK_ERROR; }
PRBool GotError() { return mError != 0; }
PRErrorCode GetError() { return mError; }
private:
PRUint32 mOffset;
PRFileDesc *mSock;
PRErrorCode mError;
};
/**
* base request
*/
class nsSocketRequest : public nsITransportRequest
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIREQUEST
NS_DECL_NSITRANSPORTREQUEST
nsSocketRequest();
virtual ~nsSocketRequest();
PRBool IsSuspended() { return mSuspendCount > 0; }
PRBool IsCanceled() { return mCanceled; }
void SetTransport(nsSocketTransport *);
void SetStatus(nsresult status) { mStatus = status; }
virtual nsISupports *GetContext() = 0;
virtual nsresult OnStart() = 0;
virtual nsresult OnStop() = 0;
protected:
nsresult OnStart(nsIStreamObserver *, nsISupports *);
nsresult OnStop(nsIStreamObserver *, nsISupports *);
nsSocketTransport *mTransport;
nsresult mStatus;
PRIntn mSuspendCount;
PRPackedBool mCanceled;
PRPackedBool mStartFired;
};
/**
* read request, returned by nsITransport::AsyncRead()
*/
class nsSocketReadRequest : public nsSocketRequest
{
public:
nsSocketReadRequest();
virtual ~nsSocketReadRequest();
void SetSocket(PRFileDesc *);
void SetListener(nsIStreamListener *l) { mListener = l; }
void SetListenerContext(nsISupports *c) { mListenerContext = c; }
nsISupports *GetContext() { return mListenerContext; }
nsresult OnStart() { return nsSocketRequest::OnStart(mListener, mListenerContext); }
nsresult OnStop() { return nsSocketRequest::OnStop(mListener, mListenerContext); }
nsresult OnRead();
private:
nsSocketIS *mInputStream;
nsCOMPtr<nsIStreamListener> mListener;
nsCOMPtr<nsISupports> mListenerContext;
};
/**
* write request, returned by nsITransport::AsyncWrite()
*/
class nsSocketWriteRequest : public nsSocketRequest
{
public:
nsSocketWriteRequest();
virtual ~nsSocketWriteRequest();
void SetSocket(PRFileDesc *);
void SetProvider(nsIStreamProvider *p) { mProvider = p; }
void SetProviderContext(nsISupports *c) { mProviderContext = c; }
nsISupports *GetContext() { return mProviderContext; }
nsresult OnStart() { return nsSocketRequest::OnStart(mProvider, mProviderContext); }
nsresult OnStop() { return nsSocketRequest::OnStop(mProvider, mProviderContext); }
nsresult OnWrite();
private:
nsSocketOS *mOutputStream;
nsCOMPtr<nsIStreamProvider> mProvider;
nsCOMPtr<nsISupports> mProviderContext;
};
#endif /* nsSocketTransport_h___ */ #endif /* nsSocketTransport_h___ */

View File

@@ -283,7 +283,7 @@ nsresult nsSocketTransportService::AddToSelectList(nsSocketTransport* aTransport
} }
// Initialize/update the info in the entry... // Initialize/update the info in the entry...
pfd = &mSelectFDSet[i]; pfd = &mSelectFDSet[i];
pfd->fd = aTransport->GetSocket();; pfd->fd = aTransport->GetSocket();
pfd->in_flags = aTransport->GetSelectFlags(); pfd->in_flags = aTransport->GetSelectFlags();
pfd->out_flags = 0; pfd->out_flags = 0;
// Add the FileDesc to the PRPollDesc list... // Add the FileDesc to the PRPollDesc list...
@@ -499,7 +499,7 @@ nsSocketTransportService::CreateTransport(const char* aHost,
PRInt32 proxyPort, PRInt32 proxyPort,
PRUint32 bufferSegmentSize, PRUint32 bufferSegmentSize,
PRUint32 bufferMaxSize, PRUint32 bufferMaxSize,
nsIChannel** aResult) nsITransport** aResult)
{ {
return CreateTransportOfTypes(0, nsnull, aHost, aPort, proxyHost, proxyPort, return CreateTransportOfTypes(0, nsnull, aHost, aPort, proxyHost, proxyPort,
bufferSegmentSize, bufferMaxSize, aResult); bufferSegmentSize, bufferMaxSize, aResult);
@@ -513,7 +513,7 @@ nsSocketTransportService::CreateTransportOfType(const char* aSocketType,
PRInt32 proxyPort, PRInt32 proxyPort,
PRUint32 bufferSegmentSize, PRUint32 bufferSegmentSize,
PRUint32 bufferMaxSize, PRUint32 bufferMaxSize,
nsIChannel** aResult) nsITransport** aResult)
{ {
const char * types[] = { aSocketType }; const char * types[] = { aSocketType };
return CreateTransportOfTypes(1, types, aHost, aPort, proxyHost, proxyPort, return CreateTransportOfTypes(1, types, aHost, aPort, proxyHost, proxyPort,
@@ -529,7 +529,7 @@ nsSocketTransportService::CreateTransportOfTypes(PRUint32 socketTypeCount,
PRInt32 proxyPort, PRInt32 proxyPort,
PRUint32 bufferSegmentSize, PRUint32 bufferSegmentSize,
PRUint32 bufferMaxSize, PRUint32 bufferMaxSize,
nsIChannel** aResult) nsITransport** aResult)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
@@ -572,7 +572,7 @@ nsSocketTransportService::CreateTransportOfTypes(PRUint32 socketTypeCount,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsSocketTransportService::ReuseTransport(nsIChannel* i_Transport, nsSocketTransportService::ReuseTransport(nsITransport* i_Transport,
PRBool * o_Reuse) PRBool * o_Reuse)
{ {
nsresult rv = NS_ERROR_FAILURE; nsresult rv = NS_ERROR_FAILURE;
@@ -590,7 +590,7 @@ nsSocketTransportService::ReuseTransport(nsIChannel* i_Transport,
*/ */
NS_IMETHODIMP NS_IMETHODIMP
nsSocketTransportService::Wakeup (nsIChannel* i_Transport) nsSocketTransportService::Wakeup (nsITransport* i_Transport)
{ {
nsSocketTransport *transport = NS_STATIC_CAST (nsSocketTransport *, i_Transport); nsSocketTransport *transport = NS_STATIC_CAST (nsSocketTransport *, i_Transport);

View File

@@ -35,17 +35,17 @@
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// Design Overview // Design Overview
// //
// A stream listener proxy maintains a pipe. When the channel makes data // A stream listener proxy maintains a pipe. When the request makes data
// available, the proxy copies as much of that data as possible into the pipe. // available, the proxy copies as much of that data as possible into the pipe.
// If data was written to the pipe, then the proxy posts an asynchronous event // If data was written to the pipe, then the proxy posts an asynchronous event
// corresponding to the amount of data written. If no data could be written, // corresponding to the amount of data written. If no data could be written,
// because the pipe was full, then WOULD_BLOCK is returned to the channel, // because the pipe was full, then WOULD_BLOCK is returned to the request,
// indicating that the channel should suspend itself. // indicating that the request should suspend itself.
// //
// Once suspended in this manner, the channel is only resumed when the pipe is // Once suspended in this manner, the request is only resumed when the pipe is
// emptied. // emptied.
// //
// XXX The current design does NOT allow the channel to be "externally" // XXX The current design does NOT allow the request to be "externally"
// suspended!! For the moment this is not a problem, but it should be fixed. // suspended!! For the moment this is not a problem, but it should be fixed.
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// //
@@ -86,11 +86,11 @@ class nsOnDataAvailableEvent : public nsStreamObserverEvent
{ {
public: public:
nsOnDataAvailableEvent(nsStreamProxyBase *aProxy, nsOnDataAvailableEvent(nsStreamProxyBase *aProxy,
nsIChannel *aChannel, nsIRequest *aRequest,
nsISupports *aContext, nsISupports *aContext,
nsIInputStream *aSource, nsIInputStream *aSource,
PRUint32 aOffset) PRUint32 aOffset)
: nsStreamObserverEvent(aProxy, aChannel, aContext) : nsStreamObserverEvent(aProxy, aRequest, aContext)
, mSource(aSource) , mSource(aSource)
, mOffset(aOffset) , mOffset(aOffset)
{ {
@@ -112,33 +112,33 @@ protected:
NS_IMETHODIMP NS_IMETHODIMP
nsOnDataAvailableEvent::HandleEvent() nsOnDataAvailableEvent::HandleEvent()
{ {
LOG(("nsOnDataAvailableEvent: HandleEvent [event=%x, chan=%x]", this, mChannel.get())); LOG(("nsOnDataAvailableEvent: HandleEvent [event=%x, chan=%x]", this, mRequest.get()));
nsStreamListenerProxy *listenerProxy = nsStreamListenerProxy *listenerProxy =
NS_STATIC_CAST(nsStreamListenerProxy *, mProxy); NS_STATIC_CAST(nsStreamListenerProxy *, mProxy);
if (NS_FAILED(listenerProxy->GetListenerStatus())) { if (NS_FAILED(listenerProxy->GetListenerStatus())) {
LOG(("nsOnDataAvailableEvent: Discarding event [listener_status=%x, chan=%x]\n", LOG(("nsOnDataAvailableEvent: Discarding event [listener_status=%x, chan=%x]\n",
listenerProxy->GetListenerStatus(), mChannel.get())); listenerProxy->GetListenerStatus(), mRequest.get()));
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
nsCOMPtr<nsIStreamListener> listener = listenerProxy->GetListener(); nsCOMPtr<nsIStreamListener> listener = listenerProxy->GetListener();
if (!listener) { if (!listener) {
LOG(("nsOnDataAvailableEvent: Already called OnStopRequest (listener is NULL), [chan=%x]\n", LOG(("nsOnDataAvailableEvent: Already called OnStopRequest (listener is NULL), [chan=%x]\n",
mChannel.get())); mRequest.get()));
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
nsresult status = NS_OK; nsresult status = NS_OK;
nsresult rv = mChannel->GetStatus(&status); nsresult rv = mRequest->GetStatus(&status);
NS_ASSERTION(NS_SUCCEEDED(rv), "GetStatus failed"); NS_ASSERTION(NS_SUCCEEDED(rv), "GetStatus failed");
// //
// We should only forward this event to the listener if the channel is // We should only forward this event to the listener if the request is
// still in a "good" state. Because these events are being processed // still in a "good" state. Because these events are being processed
// asynchronously, there is a very real chance that the listener might // asynchronously, there is a very real chance that the listener might
// have cancelled the channel after _this_ event was triggered. // have cancelled the request after _this_ event was triggered.
// //
if (NS_SUCCEEDED(status)) { if (NS_SUCCEEDED(status)) {
// //
@@ -152,21 +152,21 @@ nsOnDataAvailableEvent::HandleEvent()
mSource->Available(&avail); mSource->Available(&avail);
LOG(("nsOnDataAvailableEvent: Calling the consumer's OnDataAvailable " LOG(("nsOnDataAvailableEvent: Calling the consumer's OnDataAvailable "
"[offset=%u count=%u avail=%u chan=%x]\n", "[offset=%u count=%u avail=%u chan=%x]\n",
mOffset, count, avail, mChannel.get())); mOffset, count, avail, mRequest.get()));
} }
#endif #endif
// Forward call to listener // Forward call to listener
rv = listener->OnDataAvailable(mChannel, mContext, mSource, mOffset, count); rv = listener->OnDataAvailable(mRequest, mContext, mSource, mOffset, count);
LOG(("nsOnDataAvailableEvent: Done with the consumer's OnDataAvailable " LOG(("nsOnDataAvailableEvent: Done with the consumer's OnDataAvailable "
"[rv=%x, chan=%x]\n", "[rv=%x, chan=%x]\n",
rv, mChannel.get())); rv, mRequest.get()));
// //
// XXX Need to suspend the underlying channel... must consider // XXX Need to suspend the underlying request... must consider
// other pending events (such as OnStopRequest). These // other pending events (such as OnStopRequest). These
// should not be forwarded to the listener if the channel // should not be forwarded to the listener if the request
// is suspended. Also, handling the Resume could be tricky. // is suspended. Also, handling the Resume could be tricky.
// //
if (rv == NS_BASE_STREAM_WOULD_BLOCK) { if (rv == NS_BASE_STREAM_WOULD_BLOCK) {
@@ -182,7 +182,7 @@ nsOnDataAvailableEvent::HandleEvent()
} }
else else
LOG(("nsOnDataAvailableEvent: Not calling OnDataAvailable [chan=%x]", LOG(("nsOnDataAvailableEvent: Not calling OnDataAvailable [chan=%x]",
mChannel.get())); mRequest.get()));
return NS_OK; return NS_OK;
} }
@@ -203,15 +203,15 @@ NS_IMPL_ISUPPORTS_INHERITED3(nsStreamListenerProxy,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// //
NS_IMETHODIMP NS_IMETHODIMP
nsStreamListenerProxy::OnStartRequest(nsIChannel *aChannel, nsStreamListenerProxy::OnStartRequest(nsIRequest *aRequest,
nsISupports *aContext) nsISupports *aContext)
{ {
return nsStreamProxyBase::OnStartRequest(aChannel, aContext); return nsStreamProxyBase::OnStartRequest(aRequest, aContext);
} }
NS_IMETHODIMP NS_IMETHODIMP
nsStreamListenerProxy::OnStopRequest(nsIChannel *aChannel, nsStreamListenerProxy::OnStopRequest(nsIRequest *aRequest,
nsISupports *aContext, nsISupports *aContext,
nsresult aStatus, nsresult aStatus,
const PRUnichar *aStatusText) const PRUnichar *aStatusText)
@@ -222,7 +222,7 @@ nsStreamListenerProxy::OnStopRequest(nsIChannel *aChannel,
mPipeIn = 0; mPipeIn = 0;
mPipeOut = 0; mPipeOut = 0;
return nsStreamProxyBase::OnStopRequest(aChannel, aContext, return nsStreamProxyBase::OnStopRequest(aRequest, aContext,
aStatus, aStatusText); aStatus, aStatusText);
} }
@@ -232,7 +232,7 @@ nsStreamListenerProxy::OnStopRequest(nsIChannel *aChannel,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// //
NS_IMETHODIMP NS_IMETHODIMP
nsStreamListenerProxy::OnDataAvailable(nsIChannel *aChannel, nsStreamListenerProxy::OnDataAvailable(nsIRequest *aRequest,
nsISupports *aContext, nsISupports *aContext,
nsIInputStream *aSource, nsIInputStream *aSource,
PRUint32 aOffset, PRUint32 aOffset,
@@ -242,9 +242,9 @@ nsStreamListenerProxy::OnDataAvailable(nsIChannel *aChannel,
PRUint32 bytesWritten=0; PRUint32 bytesWritten=0;
LOG(("nsStreamListenerProxy: OnDataAvailable [offset=%u count=%u chan=%x]\n", LOG(("nsStreamListenerProxy: OnDataAvailable [offset=%u count=%u chan=%x]\n",
aOffset, aCount, aChannel)); aOffset, aCount, aRequest));
NS_PRECONDITION(mChannelToResume == 0, "Unexpected call to OnDataAvailable"); NS_PRECONDITION(mRequestToResume == 0, "Unexpected call to OnDataAvailable");
NS_PRECONDITION(mPipeIn, "Pipe not initialized"); NS_PRECONDITION(mPipeIn, "Pipe not initialized");
NS_PRECONDITION(mPipeOut, "Pipe not initialized"); NS_PRECONDITION(mPipeOut, "Pipe not initialized");
@@ -254,7 +254,7 @@ nsStreamListenerProxy::OnDataAvailable(nsIChannel *aChannel,
{ {
nsresult status = mListenerStatus; nsresult status = mListenerStatus;
if (NS_FAILED(status)) { if (NS_FAILED(status)) {
LOG(("nsStreamListenerProxy: Listener failed [status=%x chan=%x]\n", status, aChannel)); LOG(("nsStreamListenerProxy: Listener failed [status=%x chan=%x]\n", status, aRequest));
return status; return status;
} }
} }
@@ -265,29 +265,29 @@ nsStreamListenerProxy::OnDataAvailable(nsIChannel *aChannel,
// Try to copy data into the pipe. // Try to copy data into the pipe.
// //
// If the pipe is full, then we return NS_BASE_STREAM_WOULD_BLOCK // If the pipe is full, then we return NS_BASE_STREAM_WOULD_BLOCK
// so the calling channel can suspend itself. If, however, we detect // so the calling request can suspend itself. If, however, we detect
// that the pipe was emptied during this time, we retry copying data // that the pipe was emptied during this time, we retry copying data
// into the pipe. // into the pipe.
// //
rv = mPipeOut->WriteFrom(aSource, aCount, &bytesWritten); rv = mPipeOut->WriteFrom(aSource, aCount, &bytesWritten);
LOG(("nsStreamListenerProxy: Wrote data to pipe [rv=%x count=%u bytesWritten=%u chan=%x]\n", LOG(("nsStreamListenerProxy: Wrote data to pipe [rv=%x count=%u bytesWritten=%u chan=%x]\n",
rv, aCount, bytesWritten, aChannel)); rv, aCount, bytesWritten, aRequest));
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
if (rv == NS_BASE_STREAM_WOULD_BLOCK) { if (rv == NS_BASE_STREAM_WOULD_BLOCK) {
nsAutoLock lock(mLock); nsAutoLock lock(mLock);
if (mPipeEmptied) { if (mPipeEmptied) {
LOG(("nsStreamListenerProxy: Pipe emptied; looping back [chan=%x]\n", aChannel)); LOG(("nsStreamListenerProxy: Pipe emptied; looping back [chan=%x]\n", aRequest));
continue; continue;
} }
LOG(("nsStreamListenerProxy: Pipe full; setting channel to resume [chan=%x]\n", aChannel)); LOG(("nsStreamListenerProxy: Pipe full; setting request to resume [chan=%x]\n", aRequest));
mChannelToResume = aChannel; mRequestToResume = aRequest;
} }
return rv; return rv;
} }
if (bytesWritten == 0) { if (bytesWritten == 0) {
LOG(("nsStreamListenerProxy: Copied zero bytes; not posting an event [chan=%x]\n", aChannel)); LOG(("nsStreamListenerProxy: Copied zero bytes; not posting an event [chan=%x]\n", aRequest));
return NS_OK; return NS_OK;
} }
@@ -301,7 +301,7 @@ nsStreamListenerProxy::OnDataAvailable(nsIChannel *aChannel,
PRUint32 total = PR_AtomicAdd((PRInt32 *) &mPendingCount, bytesWritten); PRUint32 total = PR_AtomicAdd((PRInt32 *) &mPendingCount, bytesWritten);
if (total > bytesWritten) { if (total > bytesWritten) {
LOG(("nsStreamListenerProxy: Piggy-backing pending event [total=%u, chan=%x]\n", LOG(("nsStreamListenerProxy: Piggy-backing pending event [total=%u, chan=%x]\n",
total, aChannel)); total, aRequest));
return NS_OK; return NS_OK;
} }
@@ -309,7 +309,7 @@ nsStreamListenerProxy::OnDataAvailable(nsIChannel *aChannel,
// Post an event for the number of bytes actually written. // Post an event for the number of bytes actually written.
// //
nsOnDataAvailableEvent *ev = nsOnDataAvailableEvent *ev =
new nsOnDataAvailableEvent(this, aChannel, aContext, mPipeIn, aOffset); new nsOnDataAvailableEvent(this, aRequest, aContext, mPipeIn, aOffset);
if (!ev) return NS_ERROR_OUT_OF_MEMORY; if (!ev) return NS_ERROR_OUT_OF_MEMORY;
rv = ev->FireEvent(GetEventQueue()); rv = ev->FireEvent(GetEventQueue());
@@ -374,23 +374,23 @@ nsStreamListenerProxy::OnEmpty(nsIInputStream *aInputStream)
{ {
LOG(("nsStreamListenerProxy: OnEmpty\n")); LOG(("nsStreamListenerProxy: OnEmpty\n"));
// //
// The pipe has been emptied by the listener. If the channel // The pipe has been emptied by the listener. If the request
// has been suspended (waiting for the pipe to be emptied), then // has been suspended (waiting for the pipe to be emptied), then
// go ahead and resume it. But take care not to resume while // go ahead and resume it. But take care not to resume while
// holding the "ChannelToResume" lock. // holding the "ChannelToResume" lock.
// //
nsCOMPtr<nsIChannel> chan; nsCOMPtr<nsIRequest> req;
{ {
nsAutoLock lock(mLock); nsAutoLock lock(mLock);
if (mChannelToResume) { if (mRequestToResume) {
chan = mChannelToResume; req = mRequestToResume;
mChannelToResume = 0; mRequestToResume = 0;
} }
mPipeEmptied = PR_TRUE; // Flag this call mPipeEmptied = PR_TRUE; // Flag this call
} }
if (chan) { if (req) {
LOG(("nsStreamListenerProxy: Resuming channel\n")); LOG(("nsStreamListenerProxy: Resuming request\n"));
chan->Resume(); req->Resume();
} }
return NS_OK; return NS_OK;
} }

View File

@@ -42,7 +42,7 @@ public:
protected: protected:
nsCOMPtr<nsIInputStream> mPipeIn; nsCOMPtr<nsIInputStream> mPipeIn;
nsCOMPtr<nsIOutputStream> mPipeOut; nsCOMPtr<nsIOutputStream> mPipeOut;
nsCOMPtr<nsIChannel> mChannelToResume; nsCOMPtr<nsIRequest> mRequestToResume;
PRLock *mLock; PRLock *mLock;
PRUint32 mPendingCount; PRUint32 mPendingCount;
PRBool mPipeEmptied; PRBool mPipeEmptied;

View File

@@ -35,16 +35,14 @@ nsStreamLoader::Init(nsIURI* aURL,
nsISupports* context, nsISupports* context,
nsILoadGroup* aGroup, nsILoadGroup* aGroup,
nsIInterfaceRequestor* notificationCallbacks, nsIInterfaceRequestor* notificationCallbacks,
nsLoadFlags loadAttributes, nsLoadFlags loadAttributes)
PRUint32 bufferSegmentSize,
PRUint32 bufferMaxSize)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
mObserver = observer; mObserver = observer;
mContext = context; mContext = context;
rv = NS_OpenURI(this, nsnull, aURL, nsnull, aGroup, notificationCallbacks, rv = NS_OpenURI(this, nsnull, aURL, nsnull, aGroup, notificationCallbacks,
loadAttributes, bufferSegmentSize, bufferMaxSize); loadAttributes);
if (NS_FAILED(rv) && mObserver) { if (NS_FAILED(rv) && mObserver) {
// don't callback synchronously as it puts the caller // don't callback synchronously as it puts the caller
// in a recursive situation and breaks the asynchronous // in a recursive situation and breaks the asynchronous
@@ -96,26 +94,27 @@ nsStreamLoader::GetNumBytesRead(PRUint32* aNumBytes)
return NS_OK; return NS_OK;
} }
/* readonly attribute nsIRequest request; */
NS_IMETHODIMP NS_IMETHODIMP
nsStreamLoader::GetChannel(nsIChannel** aChannel) nsStreamLoader::GetRequest(nsIRequest * *aRequest)
{ {
*aChannel = mChannel.get(); NS_IF_ADDREF(*aRequest=mRequest);
NS_IF_ADDREF(*aChannel);
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsStreamLoader::OnStartRequest(nsIChannel* channel, nsISupports *ctxt) nsStreamLoader::OnStartRequest(nsIRequest* request, nsISupports *ctxt)
{ {
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsStreamLoader::OnStopRequest(nsIChannel* channel, nsISupports *ctxt, nsStreamLoader::OnStopRequest(nsIRequest* request, nsISupports *ctxt,
nsresult aStatus, const PRUnichar* aStatusArg) nsresult aStatus, const PRUnichar* aStatusArg)
{ {
nsresult rv; nsresult rv;
mChannel = channel; mRequest = request;
rv = mObserver->OnStreamComplete(this, mContext, aStatus, rv = mObserver->OnStreamComplete(this, mContext, aStatus,
mData.Length(), mData.Length(),
mData.GetBuffer()); mData.GetBuffer());
@@ -125,7 +124,7 @@ nsStreamLoader::OnStopRequest(nsIChannel* channel, nsISupports *ctxt,
#define BUF_SIZE 1024 #define BUF_SIZE 1024
NS_IMETHODIMP NS_IMETHODIMP
nsStreamLoader::OnDataAvailable(nsIChannel* channel, nsISupports *ctxt, nsStreamLoader::OnDataAvailable(nsIRequest* request, nsISupports *ctxt,
nsIInputStream *inStr, nsIInputStream *inStr,
PRUint32 sourceOffset, PRUint32 count) PRUint32 sourceOffset, PRUint32 count)
{ {

View File

@@ -47,7 +47,7 @@ protected:
nsCOMPtr<nsIStreamLoaderObserver> mObserver; nsCOMPtr<nsIStreamLoaderObserver> mObserver;
nsCOMPtr<nsISupports> mContext; // the observer's context nsCOMPtr<nsISupports> mContext; // the observer's context
nsCString mData; nsCString mData;
nsCOMPtr<nsIChannel> mChannel; nsCOMPtr<nsIRequest> mRequest;
/// nsCOMPtr<nsILoadGroup> mLoadGroup; /// nsCOMPtr<nsILoadGroup> mLoadGroup;
}; };

View File

@@ -39,10 +39,10 @@ static NS_DEFINE_CID(kEventQueueService, NS_EVENTQUEUESERVICE_CID);
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// //
nsStreamObserverEvent::nsStreamObserverEvent(nsStreamProxyBase *aProxy, nsStreamObserverEvent::nsStreamObserverEvent(nsStreamProxyBase *aProxy,
nsIChannel *aChannel, nsIRequest *aRequest,
nsISupports *aContext) nsISupports *aContext)
: mProxy(aProxy) : mProxy(aProxy)
, mChannel(aChannel) , mRequest(aRequest)
, mContext(aContext) , mContext(aContext)
{ {
NS_IF_ADDREF(mProxy); NS_IF_ADDREF(mProxy);
@@ -94,9 +94,9 @@ class nsOnStartRequestEvent : public nsStreamObserverEvent
{ {
public: public:
nsOnStartRequestEvent(nsStreamProxyBase *aProxy, nsOnStartRequestEvent(nsStreamProxyBase *aProxy,
nsIChannel *aChannel, nsIRequest *aRequest,
nsISupports *aContext) nsISupports *aContext)
: nsStreamObserverEvent(aProxy, aChannel, aContext) : nsStreamObserverEvent(aProxy, aRequest, aContext)
{ {
MOZ_COUNT_CTOR(nsOnStartRequestEvent); MOZ_COUNT_CTOR(nsOnStartRequestEvent);
} }
@@ -112,8 +112,8 @@ public:
NS_IMETHODIMP NS_IMETHODIMP
nsOnStartRequestEvent::HandleEvent() nsOnStartRequestEvent::HandleEvent()
{ {
LOG(("nsOnStartRequestEvent: HandleEvent [event=%x chan=%x]\n", LOG(("nsOnStartRequestEvent: HandleEvent [event=%x req=%x]\n",
this, mChannel.get())); this, mRequest.get()));
nsCOMPtr<nsIStreamObserver> observer = mProxy->GetReceiver(); nsCOMPtr<nsIStreamObserver> observer = mProxy->GetReceiver();
if (!observer) { if (!observer) {
@@ -121,7 +121,7 @@ nsOnStartRequestEvent::HandleEvent()
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
return observer->OnStartRequest(mChannel, mContext); return observer->OnStartRequest(mRequest, mContext);
} }
// //
@@ -133,9 +133,9 @@ class nsOnStopRequestEvent : public nsStreamObserverEvent
{ {
public: public:
nsOnStopRequestEvent(nsStreamProxyBase *aProxy, nsOnStopRequestEvent(nsStreamProxyBase *aProxy,
nsIChannel *aChannel, nsISupports *aContext, nsIRequest *aRequest, nsISupports *aContext,
nsresult aStatus, const PRUnichar *aStatusText) nsresult aStatus, const PRUnichar *aStatusText)
: nsStreamObserverEvent(aProxy, aChannel, aContext) : nsStreamObserverEvent(aProxy, aRequest, aContext)
, mStatus(aStatus) , mStatus(aStatus)
, mStatusText(aStatusText) , mStatusText(aStatusText)
{ {
@@ -157,8 +157,8 @@ protected:
NS_IMETHODIMP NS_IMETHODIMP
nsOnStopRequestEvent::HandleEvent() nsOnStopRequestEvent::HandleEvent()
{ {
LOG(("nsOnStopRequestEvent: HandleEvent [event=%x chan=%x]\n", LOG(("nsOnStopRequestEvent: HandleEvent [event=%x req=%x]\n",
this, mChannel.get())); this, mRequest.get()));
nsCOMPtr<nsIStreamObserver> observer = mProxy->GetReceiver(); nsCOMPtr<nsIStreamObserver> observer = mProxy->GetReceiver();
if (!observer) { if (!observer) {
@@ -171,7 +171,7 @@ nsOnStopRequestEvent::HandleEvent()
// //
mProxy->SetReceiver(nsnull); mProxy->SetReceiver(nsnull);
return observer->OnStopRequest(mChannel, return observer->OnStopRequest(mRequest,
mContext, mContext,
mStatus, mStatus,
mStatusText.GetUnicode()); mStatusText.GetUnicode());
@@ -191,12 +191,12 @@ NS_IMPL_THREADSAFE_ISUPPORTS1(nsStreamProxyBase,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// //
NS_IMETHODIMP NS_IMETHODIMP
nsStreamProxyBase::OnStartRequest(nsIChannel *aChannel, nsStreamProxyBase::OnStartRequest(nsIRequest *aRequest,
nsISupports *aContext) nsISupports *aContext)
{ {
LOG(("nsStreamProxyBase: OnStartRequest [this=%x chan=%x]\n", this, aChannel)); LOG(("nsStreamProxyBase: OnStartRequest [this=%x req=%x]\n", this, aRequest));
nsOnStartRequestEvent *ev = nsOnStartRequestEvent *ev =
new nsOnStartRequestEvent(this, aChannel, aContext); new nsOnStartRequestEvent(this, aRequest, aContext);
if (!ev) if (!ev)
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
@@ -207,15 +207,15 @@ nsStreamProxyBase::OnStartRequest(nsIChannel *aChannel,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsStreamProxyBase::OnStopRequest(nsIChannel *aChannel, nsStreamProxyBase::OnStopRequest(nsIRequest *aRequest,
nsISupports *aContext, nsISupports *aContext,
nsresult aStatus, nsresult aStatus,
const PRUnichar *aStatusText) const PRUnichar *aStatusText)
{ {
LOG(("nsStreamProxyBase: OnStopRequest [this=%x chan=%x status=%x]\n", LOG(("nsStreamProxyBase: OnStopRequest [this=%x req=%x status=%x]\n",
this, aChannel, aStatus)); this, aRequest, aStatus));
nsOnStopRequestEvent *ev = nsOnStopRequestEvent *ev =
new nsOnStopRequestEvent(this, aChannel, aContext, aStatus, aStatusText); new nsOnStopRequestEvent(this, aRequest, aContext, aStatus, aStatusText);
if (!ev) if (!ev)
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;

View File

@@ -70,7 +70,7 @@ class nsStreamObserverEvent
{ {
public: public:
nsStreamObserverEvent(nsStreamProxyBase *proxy, nsStreamObserverEvent(nsStreamProxyBase *proxy,
nsIChannel *channel, nsISupports *context); nsIRequest *request, nsISupports *context);
virtual ~nsStreamObserverEvent(); virtual ~nsStreamObserverEvent();
nsresult FireEvent(nsIEventQueue *); nsresult FireEvent(nsIEventQueue *);
@@ -82,7 +82,7 @@ protected:
PLEvent mEvent; PLEvent mEvent;
nsStreamProxyBase *mProxy; nsStreamProxyBase *mProxy;
nsCOMPtr<nsIChannel> mChannel; nsCOMPtr<nsIRequest> mRequest;
nsCOMPtr<nsISupports> mContext; nsCOMPtr<nsISupports> mContext;
}; };

View File

@@ -33,12 +33,12 @@
// Design Overview // Design Overview
// //
// A stream provider proxy maintains a pipe. When requested to provide data // A stream provider proxy maintains a pipe. When requested to provide data
// to the channel, whatever data is in the pipe (up to the amount requested) // to the request, whatever data is in the pipe (up to the amount requested)
// is provided to the channel. If there is no data in the pipe, then the // is provided to the request. If there is no data in the pipe, then the
// proxy posts an asynchronous event for more data, and returns WOULD_BLOCK // proxy posts an asynchronous event for more data, and returns WOULD_BLOCK
// indicating that the channel should suspend itself. // indicating that the request should suspend itself.
// //
// The channel is only resumed once the event has been successfully handled; // The request is only resumed once the event has been successfully handled;
// meaning that data has been written to the pipe. // meaning that data has been written to the pipe.
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// //
@@ -59,12 +59,12 @@ class nsOnDataWritableEvent : public nsStreamObserverEvent
{ {
public: public:
nsOnDataWritableEvent(nsStreamProxyBase *aProxy, nsOnDataWritableEvent(nsStreamProxyBase *aProxy,
nsIChannel *aChannel, nsIRequest *aRequest,
nsISupports *aContext, nsISupports *aContext,
nsIOutputStream *aSink, nsIOutputStream *aSink,
PRUint32 aOffset, PRUint32 aOffset,
PRUint32 aCount) PRUint32 aCount)
: nsStreamObserverEvent(aProxy, aChannel, aContext) : nsStreamObserverEvent(aProxy, aRequest, aContext)
, mSink(aSink) , mSink(aSink)
, mOffset(aOffset) , mOffset(aOffset)
, mCount(aCount) , mCount(aCount)
@@ -89,7 +89,7 @@ NS_IMETHODIMP
nsOnDataWritableEvent::HandleEvent() nsOnDataWritableEvent::HandleEvent()
{ {
LOG(("nsOnDataWritableEvent: HandleEvent [event=%x chan=%x]", LOG(("nsOnDataWritableEvent: HandleEvent [event=%x chan=%x]",
this, mChannel.get())); this, mRequest.get()));
nsStreamProviderProxy *providerProxy = nsStreamProviderProxy *providerProxy =
NS_STATIC_CAST(nsStreamProviderProxy *, mProxy); NS_STATIC_CAST(nsStreamProviderProxy *, mProxy);
@@ -101,18 +101,18 @@ nsOnDataWritableEvent::HandleEvent()
} }
nsresult status = NS_OK; nsresult status = NS_OK;
nsresult rv = mChannel->GetStatus(&status); nsresult rv = mRequest->GetStatus(&status);
NS_ASSERTION(NS_SUCCEEDED(rv), "GetStatus failed"); NS_ASSERTION(NS_SUCCEEDED(rv), "GetStatus failed");
// //
// We should only forward this event to the provider if the channel is // We should only forward this event to the provider if the request is
// still in a "good" state. Because these events are being processed // still in a "good" state. Because these events are being processed
// asynchronously, there is a very real chance that the provider might // asynchronously, there is a very real chance that the provider might
// have cancelled the channel after _this_ event was triggered. // have cancelled the request after _this_ event was triggered.
// //
if (NS_SUCCEEDED(status)) { if (NS_SUCCEEDED(status)) {
LOG(("nsOnDataWritableEvent: Calling the consumer's OnDataWritable\n")); LOG(("nsOnDataWritableEvent: Calling the consumer's OnDataWritable\n"));
rv = provider->OnDataWritable(mChannel, mContext, mSink, mOffset, mCount); rv = provider->OnDataWritable(mRequest, mContext, mSink, mOffset, mCount);
LOG(("nsOnDataWritableEvent: Done with the consumer's OnDataWritable [rv=%x]\n", rv)); LOG(("nsOnDataWritableEvent: Done with the consumer's OnDataWritable [rv=%x]\n", rv));
// //
@@ -122,11 +122,11 @@ nsOnDataWritableEvent::HandleEvent()
rv != NS_BASE_STREAM_WOULD_BLOCK ? rv : NS_OK); rv != NS_BASE_STREAM_WOULD_BLOCK ? rv : NS_OK);
// //
// The channel is already suspended, so unless the provider returned // The request is already suspended, so unless the provider returned
// NS_BASE_STREAM_WOULD_BLOCK, we should wake up the channel. // NS_BASE_STREAM_WOULD_BLOCK, we should wake up the request.
// //
if (rv != NS_BASE_STREAM_WOULD_BLOCK) if (rv != NS_BASE_STREAM_WOULD_BLOCK)
mChannel->Resume(); mRequest->Resume();
} }
else else
LOG(("nsOnDataWritableEvent: Not calling OnDataWritable")); LOG(("nsOnDataWritableEvent: Not calling OnDataWritable"));
@@ -149,14 +149,14 @@ NS_IMPL_ISUPPORTS_INHERITED2(nsStreamProviderProxy,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// //
NS_IMETHODIMP NS_IMETHODIMP
nsStreamProviderProxy::OnStartRequest(nsIChannel *aChannel, nsStreamProviderProxy::OnStartRequest(nsIRequest *request,
nsISupports *aContext) nsISupports *aContext)
{ {
return nsStreamProxyBase::OnStartRequest(aChannel, aContext); return nsStreamProxyBase::OnStartRequest(request, aContext);
} }
NS_IMETHODIMP NS_IMETHODIMP
nsStreamProviderProxy::OnStopRequest(nsIChannel *aChannel, nsStreamProviderProxy::OnStopRequest(nsIRequest* request,
nsISupports *aContext, nsISupports *aContext,
nsresult aStatus, nsresult aStatus,
const PRUnichar *aStatusText) const PRUnichar *aStatusText)
@@ -167,7 +167,7 @@ nsStreamProviderProxy::OnStopRequest(nsIChannel *aChannel,
mPipeIn = 0; mPipeIn = 0;
mPipeOut = 0; mPipeOut = 0;
return nsStreamProxyBase::OnStopRequest(aChannel, aContext, return nsStreamProxyBase::OnStopRequest(request, aContext,
aStatus, aStatusText); aStatus, aStatusText);
} }
@@ -189,7 +189,7 @@ nsWriteToSink(nsIInputStream *source,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsStreamProviderProxy::OnDataWritable(nsIChannel *aChannel, nsStreamProviderProxy::OnDataWritable(nsIRequest *aRequest,
nsISupports *aContext, nsISupports *aContext,
nsIOutputStream *aSink, nsIOutputStream *aSink,
PRUint32 aOffset, PRUint32 aOffset,
@@ -215,7 +215,7 @@ nsStreamProviderProxy::OnDataWritable(nsIChannel *aChannel,
} }
// //
// Provide the channel with whatever data is already in the pipe (not // Provide the request with whatever data is already in the pipe (not
// exceeding aCount). // exceeding aCount).
// //
PRUint32 count; PRUint32 count;
@@ -236,7 +236,7 @@ nsStreamProviderProxy::OnDataWritable(nsIChannel *aChannel,
// Post an event requesting the provider for more data. // Post an event requesting the provider for more data.
// //
nsOnDataWritableEvent *ev = nsOnDataWritableEvent *ev =
new nsOnDataWritableEvent(this, aChannel, aContext, new nsOnDataWritableEvent(this, aRequest, aContext,
mPipeOut, aOffset, aCount); mPipeOut, aOffset, aCount);
if (!ev) if (!ev)
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;

View File

@@ -55,13 +55,13 @@ NS_IMPL_THREADSAFE_ISUPPORTS3(nsSyncStreamListener,
nsIStreamObserver) nsIStreamObserver)
NS_IMETHODIMP NS_IMETHODIMP
nsSyncStreamListener::OnStartRequest(nsIChannel* channel, nsISupports* context) nsSyncStreamListener::OnStartRequest(nsIRequest* request, nsISupports* context)
{ {
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsSyncStreamListener::OnStopRequest(nsIChannel* channel, nsISupports* context, nsSyncStreamListener::OnStopRequest(nsIRequest* request, nsISupports* context,
nsresult aStatus, const PRUnichar* aStatusArg) nsresult aStatus, const PRUnichar* aStatusArg)
{ {
// XXX what do we do with the status and error message? // XXX what do we do with the status and error message?
@@ -69,7 +69,7 @@ nsSyncStreamListener::OnStopRequest(nsIChannel* channel, nsISupports* context,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsSyncStreamListener::OnDataAvailable(nsIChannel* channel, nsSyncStreamListener::OnDataAvailable(nsIRequest* request,
nsISupports* context, nsISupports* context,
nsIInputStream *aIStream, nsIInputStream *aIStream,
PRUint32 aSourceOffset, PRUint32 aSourceOffset,

View File

@@ -68,7 +68,7 @@ nsDiskCacheRecord::nsDiskCacheRecord(nsIDBAccessor* db, nsNetDiskCache* aCache)
mDB(db) , mDB(db) ,
mInfo(0) , mInfo(0) ,
mInfoSize(0) , mInfoSize(0) ,
mNumChannels(0) , mNumTransports(0) ,
mDiskCache(aCache) mDiskCache(aCache)
{ {
NS_INIT_REFCNT(); NS_INIT_REFCNT();
@@ -284,7 +284,7 @@ nsDiskCacheRecord::SetSecurityInfo (nsISupports * o_SecurityInfo)
NS_IMETHODIMP NS_IMETHODIMP
nsDiskCacheRecord::Delete(void) nsDiskCacheRecord::Delete(void)
{ {
if(mNumChannels) if(mNumTransports)
return NS_ERROR_NOT_AVAILABLE ; return NS_ERROR_NOT_AVAILABLE ;
// Delete any file associated with this entry. Remember we might // Delete any file associated with this entry. Remember we might
@@ -333,19 +333,20 @@ nsDiskCacheRecord::GetFile(nsIFile * *aFile)
} }
NS_IMETHODIMP NS_IMETHODIMP
nsDiskCacheRecord::NewChannel(nsILoadGroup *loadGroup, nsIChannel **_retval) nsDiskCacheRecord::NewTransport(nsILoadGroup *loadGroup, nsITransport **_retval)
{ {
nsDiskCacheRecordChannel* channel = new nsDiskCacheRecordChannel(this, loadGroup) ; nsDiskCacheRecordTransport* transport =
if(!channel) new nsDiskCacheRecordTransport(this, loadGroup);
return NS_ERROR_OUT_OF_MEMORY ; if(!transport)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = channel->Init() ; nsresult rv = transport->Init();
if(NS_FAILED(rv)) if(NS_FAILED(rv))
return rv ; return rv;
NS_ADDREF(channel) ; NS_ADDREF(transport);
*_retval = NS_STATIC_CAST(nsIChannel*, channel) ; *_retval = NS_STATIC_CAST(nsITransport*, transport);
return NS_OK ; return NS_OK;
} }
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@@ -561,3 +562,4 @@ nsDiskCacheRecord::UpdateFileInfo()
mFile = spec; mFile = spec;
return rv; return rv;
} }

View File

@@ -34,8 +34,7 @@
class nsDiskCacheRecord : public nsINetDataCacheRecord class nsDiskCacheRecord : public nsINetDataCacheRecord
{ {
public: public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
NS_DECL_NSINETDATACACHERECORD NS_DECL_NSINETDATACACHERECORD
@@ -46,15 +45,15 @@ class nsDiskCacheRecord : public nsINetDataCacheRecord
// we need to invalidate the mFile's stat cache. // we need to invalidate the mFile's stat cache.
NS_IMETHOD WriteComplete(); NS_IMETHOD WriteComplete();
protected: protected:
nsDiskCacheRecord(nsIDBAccessor* db, nsNetDiskCache* aCache) ; nsDiskCacheRecord(nsIDBAccessor* db, nsNetDiskCache* aCache);
virtual ~nsDiskCacheRecord() ; virtual ~nsDiskCacheRecord();
NS_IMETHOD RetrieveInfo(void* aInfo, PRUint32 aInfoLength) ; NS_IMETHOD RetrieveInfo(void* aInfo, PRUint32 aInfoLength);
NS_IMETHOD Init(const char* key, PRUint32 length, PRInt32 ID) ; NS_IMETHOD Init(const char* key, PRUint32 length, PRInt32 ID);
nsresult GenInfo(void) ; nsresult GenInfo(void);
// The mFile we store might be out of date. Atlease // The mFile we store might be out of date. Atlease
@@ -64,23 +63,23 @@ class nsDiskCacheRecord : public nsINetDataCacheRecord
// file info. // file info.
NS_IMETHOD UpdateFileInfo(); NS_IMETHOD UpdateFileInfo();
private: private:
char* mKey ; char* mKey;
PRUint32 mKeyLength ; PRUint32 mKeyLength;
PRInt32 mRecordID ; PRInt32 mRecordID;
char* mMetaData ; char* mMetaData;
PRUint32 mMetaDataLength ; PRUint32 mMetaDataLength;
nsCOMPtr<nsIFile> mFile ; nsCOMPtr<nsIFile> mFile;
nsCOMPtr<nsIDBAccessor> mDB ; nsCOMPtr<nsIDBAccessor> mDB;
void* mInfo ; void* mInfo;
PRUint32 mInfoSize ; PRUint32 mInfoSize;
PRUint32 mNumChannels ; PRUint32 mNumTransports;
nsNetDiskCache* mDiskCache ; nsNetDiskCache* mDiskCache;
friend class nsDiskCacheRecordChannel ; friend class nsDiskCacheRecordTransport;
friend class nsDBEnumerator ; friend class nsDBEnumerator;
friend class nsNetDiskCache ; friend class nsNetDiskCache;
} ; };
#endif // _NET_CACHEDDISKDATA_H_ #endif // _NET_CACHEDDISKDATA_H_

View File

@@ -45,19 +45,19 @@ static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID);
class WriteStreamWrapper : public nsIOutputStream class WriteStreamWrapper : public nsIOutputStream
{ {
public: public:
WriteStreamWrapper(nsDiskCacheRecordChannel* aChannel, WriteStreamWrapper(nsDiskCacheRecordTransport* aTransport,
nsIOutputStream *aBaseStream); nsIOutputStream *aBaseStream);
virtual ~WriteStreamWrapper(); virtual ~WriteStreamWrapper();
static nsresult static nsresult
Create(nsDiskCacheRecordChannel* aChannel, nsIOutputStream *aBaseStream, nsIOutputStream* *aWrapper); Create(nsDiskCacheRecordTransport* aTransport, nsIOutputStream *aBaseStream, nsIOutputStream* *aWrapper);
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
NS_DECL_NSIOUTPUTSTREAM NS_DECL_NSIOUTPUTSTREAM
private: private:
nsDiskCacheRecordChannel* mChannel; nsDiskCacheRecordTransport* mTransport;
nsCOMPtr<nsIOutputStream> mBaseStream; nsCOMPtr<nsIOutputStream> mBaseStream;
PRUint32 mTotalSize; PRUint32 mTotalSize;
PRUint32 mOldLength; PRUint32 mOldLength;
@@ -66,24 +66,24 @@ class WriteStreamWrapper : public nsIOutputStream
// implement nsISupports // implement nsISupports
NS_IMPL_THREADSAFE_ISUPPORTS1(WriteStreamWrapper, nsIOutputStream) NS_IMPL_THREADSAFE_ISUPPORTS1(WriteStreamWrapper, nsIOutputStream)
WriteStreamWrapper::WriteStreamWrapper(nsDiskCacheRecordChannel* aChannel, WriteStreamWrapper::WriteStreamWrapper(nsDiskCacheRecordTransport* aTransport,
nsIOutputStream *aBaseStream) nsIOutputStream *aBaseStream)
: mChannel(aChannel), mBaseStream(aBaseStream), mTotalSize(0), mOldLength(0) : mTransport(aTransport), mBaseStream(aBaseStream), mTotalSize(0), mOldLength(0)
{ {
NS_INIT_REFCNT(); NS_INIT_REFCNT();
NS_ADDREF(mChannel); NS_ADDREF(mTransport);
mChannel->mRecord->GetStoredContentLength(&mOldLength); mTransport->mRecord->GetStoredContentLength(&mOldLength);
} }
WriteStreamWrapper::~WriteStreamWrapper() WriteStreamWrapper::~WriteStreamWrapper()
{ {
NS_RELEASE(mChannel); NS_RELEASE(mTransport);
} }
nsresult nsresult
WriteStreamWrapper::Create(nsDiskCacheRecordChannel*aChannel, nsIOutputStream *aBaseStream, nsIOutputStream* * aWrapper) WriteStreamWrapper::Create(nsDiskCacheRecordTransport*aTransport, nsIOutputStream *aBaseStream, nsIOutputStream* * aWrapper)
{ {
WriteStreamWrapper *wrapper = new WriteStreamWrapper(aChannel, aBaseStream); WriteStreamWrapper *wrapper = new WriteStreamWrapper(aTransport, aBaseStream);
if (!wrapper) return NS_ERROR_OUT_OF_MEMORY; if (!wrapper) return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(wrapper); NS_ADDREF(wrapper);
*aWrapper = wrapper; *aWrapper = wrapper;
@@ -153,36 +153,35 @@ WriteStreamWrapper::Close()
nsresult rv = mBaseStream->Close(); nsresult rv = mBaseStream->Close();
// Tell the record we finished write to the file // Tell the record we finished write to the file
mChannel->mRecord->WriteComplete(); mTransport->mRecord->WriteComplete();
if (mTotalSize < mOldLength) { if (mTotalSize < mOldLength) {
// Truncate the file if we have to. It should have been already but that // Truncate the file if we have to. It should have been already but that
// would be too easy wouldn't it!!! // would be too easy wouldn't it!!!
mChannel->mRecord->SetStoredContentLength(mTotalSize); mTransport->mRecord->SetStoredContentLength(mTotalSize);
} else if (mTotalSize > mOldLength) { } else if (mTotalSize > mOldLength) {
mChannel->NotifyStorageInUse(mTotalSize - mOldLength); mTransport->NotifyStorageInUse(mTotalSize - mOldLength);
} }
return rv; return rv;
} }
nsDiskCacheRecordChannel::nsDiskCacheRecordChannel(nsDiskCacheRecord *aRecord, nsDiskCacheRecordTransport::nsDiskCacheRecordTransport(nsDiskCacheRecord *aRecord,
nsILoadGroup *aLoadGroup) nsILoadGroup *aLoadGroup)
: mRecord(aRecord), : mRecord(aRecord),
mLoadGroup(aLoadGroup), mLoadGroup(aLoadGroup),
mLoadAttributes(nsIChannel::LOAD_NORMAL),
mStatus(NS_OK) mStatus(NS_OK)
{ {
NS_INIT_REFCNT(); NS_INIT_REFCNT();
NS_ADDREF(mRecord); NS_ADDREF(mRecord);
mRecord->mNumChannels++; mRecord->mNumTransports++;
} }
nsDiskCacheRecordChannel::~nsDiskCacheRecordChannel() nsDiskCacheRecordTransport::~nsDiskCacheRecordTransport()
{ {
mRecord->mNumChannels--; mRecord->mNumTransports--;
NS_RELEASE(mRecord); NS_RELEASE(mRecord);
} }
@@ -205,7 +204,7 @@ nsDiskCacheRecordChannel::~nsDiskCacheRecordChannel()
// conversions for every cache file we open. // conversions for every cache file we open.
nsresult nsresult
nsDiskCacheRecordChannel::Init(void) nsDiskCacheRecordTransport::Init(void)
{ {
nsresult rv = mRecord->mFile->Clone(getter_AddRefs(mSpec)) ; nsresult rv = mRecord->mFile->Clone(getter_AddRefs(mSpec)) ;
#if 0 #if 0
@@ -226,110 +225,125 @@ nsDiskCacheRecordChannel::Init(void)
} }
nsresult nsresult
nsDiskCacheRecordChannel::NotifyStorageInUse(PRInt32 aBytesUsed) nsDiskCacheRecordTransport::NotifyStorageInUse(PRInt32 aBytesUsed)
{ {
return mRecord->mDiskCache->mStorageInUse += aBytesUsed; return mRecord->mDiskCache->mStorageInUse += aBytesUsed;
} }
// implement nsISupports // implement nsISupports
NS_IMPL_THREADSAFE_ISUPPORTS4(nsDiskCacheRecordChannel, NS_IMPL_THREADSAFE_ISUPPORTS5(nsDiskCacheRecordTransport,
nsIChannel, nsITransport,
nsITransportRequest,
nsIRequest, nsIRequest,
nsIStreamListener, nsIStreamListener,
nsIStreamObserver) nsIStreamObserver)
// implement nsIRequest // implement nsIRequest
NS_IMETHODIMP NS_IMETHODIMP
nsDiskCacheRecordChannel::GetName(PRUnichar* *result) nsDiskCacheRecordTransport::GetName(PRUnichar* *result)
{ {
NS_NOTREACHED("nsDiskCacheRecordChannel::GetName"); NS_NOTREACHED("nsDiskCacheRecordTransport::GetName");
return NS_ERROR_NOT_IMPLEMENTED; return NS_ERROR_NOT_IMPLEMENTED;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsDiskCacheRecordChannel::IsPending(PRBool *aIsPending) nsDiskCacheRecordTransport::IsPending(PRBool *aIsPending)
{ {
*aIsPending = PR_FALSE; *aIsPending = PR_FALSE;
if(!mFileTransport) if(!mCurrentReadRequest)
return NS_OK; return NS_OK;
return mFileTransport->IsPending(aIsPending); return mCurrentReadRequest->IsPending(aIsPending);
} }
NS_IMETHODIMP NS_IMETHODIMP
nsDiskCacheRecordChannel::GetStatus(nsresult *status) nsDiskCacheRecordTransport::GetStatus(nsresult *status)
{ {
*status = mStatus; *status = mStatus;
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsDiskCacheRecordChannel::Cancel(nsresult status) nsDiskCacheRecordTransport::Cancel(nsresult status)
{ {
NS_ASSERTION(NS_FAILED(status), "shouldn't cancel with a success code"); NS_ASSERTION(NS_FAILED(status), "shouldn't cancel with a success code");
mStatus = status; mStatus = status;
if(!mFileTransport) if(!mCurrentReadRequest)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
return mFileTransport->Cancel(status); return mCurrentReadRequest->Cancel(status);
} }
NS_IMETHODIMP NS_IMETHODIMP
nsDiskCacheRecordChannel::Suspend(void) nsDiskCacheRecordTransport::Suspend(void)
{ {
if(!mFileTransport) if(!mCurrentReadRequest)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
return mFileTransport->Suspend(); return mCurrentReadRequest->Suspend();
} }
NS_IMETHODIMP NS_IMETHODIMP
nsDiskCacheRecordChannel::Resume(void) nsDiskCacheRecordTransport::Resume(void)
{ {
if(!mFileTransport) if(!mCurrentReadRequest)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
return mFileTransport->Resume(); return mCurrentReadRequest->Resume();
} }
NS_IMETHODIMP
nsDiskCacheRecordTransport::GetTransport(nsITransport **result)
{
NS_ENSURE_ARG_POINTER(result);
NS_ADDREF(*result = this);
return NS_OK;
}
#if 0
// implement nsIChannel // implement nsIChannel
NS_IMETHODIMP NS_IMETHODIMP
nsDiskCacheRecordChannel::GetOriginalURI(nsIURI* *aURI) nsDiskCacheRecordTransport::GetOriginalURI(nsIURI* *aURI)
{ {
// FUR - might need to implement this - not sure // FUR - might need to implement this - not sure
NS_NOTREACHED("nsDiskCacheRecordChannel::GetOriginalURI"); NS_NOTREACHED("nsDiskCacheRecordTransport::GetOriginalURI");
return NS_ERROR_NOT_IMPLEMENTED ; return NS_ERROR_NOT_IMPLEMENTED ;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsDiskCacheRecordChannel::SetOriginalURI(nsIURI* aURI) nsDiskCacheRecordTransport::SetOriginalURI(nsIURI* aURI)
{ {
// FUR - might need to implement this - not sure // FUR - might need to implement this - not sure
NS_NOTREACHED("nsDiskCacheRecordChannel::SetOriginalURI"); NS_NOTREACHED("nsDiskCacheRecordTransport::SetOriginalURI");
return NS_ERROR_NOT_IMPLEMENTED ; return NS_ERROR_NOT_IMPLEMENTED ;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsDiskCacheRecordChannel::GetURI(nsIURI* *aURI) nsDiskCacheRecordTransport::GetURI(nsIURI* *aURI)
{ {
if(!mFileTransport) if(!mFileTransport)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
return mFileTransport->GetURI(aURI); return mFileTransport->GetURI(aURI); // no-op
} }
NS_IMETHODIMP NS_IMETHODIMP
nsDiskCacheRecordChannel::SetURI(nsIURI* aURI) nsDiskCacheRecordTransport::SetURI(nsIURI* aURI)
{ {
if(!mFileTransport) if(!mFileTransport)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
return mFileTransport->SetURI(aURI); return mFileTransport->SetURI(aURI); // no-op
} }
#endif
NS_IMETHODIMP NS_IMETHODIMP
nsDiskCacheRecordChannel::OpenInputStream(nsIInputStream* *aResult) nsDiskCacheRecordTransport::OpenInputStream(PRUint32 transferOffset,
PRUint32 transferCount,
PRUint32 transferFlags,
nsIInputStream* *aResult)
{ {
nsresult rv; nsresult rv;
@@ -339,14 +353,19 @@ nsDiskCacheRecordChannel::OpenInputStream(nsIInputStream* *aResult)
NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv); NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv);
if(NS_FAILED(rv)) return rv; if(NS_FAILED(rv)) return rv;
rv = fts->CreateTransport(mSpec, PR_RDONLY, PR_IRUSR | PR_IWUSR, rv = fts->CreateTransport(mSpec,
PR_RDONLY,
PR_IRUSR | PR_IWUSR,
getter_AddRefs(mFileTransport)); getter_AddRefs(mFileTransport));
if(NS_FAILED(rv)) if(NS_FAILED(rv))
return rv; return rv;
// we don't need to worry about notification callbacks // we don't need to worry about progress notification
rv = mFileTransport->OpenInputStream(aResult); rv = mFileTransport->OpenInputStream(transferOffset,
transferCount,
transferFlags,
aResult);
if(NS_FAILED(rv)) if(NS_FAILED(rv))
mFileTransport = nsnull; mFileTransport = nsnull;
@@ -354,7 +373,10 @@ nsDiskCacheRecordChannel::OpenInputStream(nsIInputStream* *aResult)
} }
NS_IMETHODIMP NS_IMETHODIMP
nsDiskCacheRecordChannel::OpenOutputStream(nsIOutputStream* *aResult) nsDiskCacheRecordTransport::OpenOutputStream(PRUint32 transferOffset,
PRUint32 transferCount,
PRUint32 transferFlags,
nsIOutputStream* *aResult)
{ {
nsresult rv; nsresult rv;
NS_ENSURE_ARG(aResult); NS_ENSURE_ARG(aResult);
@@ -367,14 +389,19 @@ nsDiskCacheRecordChannel::OpenOutputStream(nsIOutputStream* *aResult)
NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv); NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv);
if(NS_FAILED(rv)) return rv; if(NS_FAILED(rv)) return rv;
rv = fts->CreateTransport(mSpec, PR_WRONLY | PR_CREATE_FILE, PR_IRUSR | PR_IWUSR, rv = fts->CreateTransport(mSpec,
PR_WRONLY | PR_CREATE_FILE,
PR_IRUSR | PR_IWUSR,
getter_AddRefs(mFileTransport)); getter_AddRefs(mFileTransport));
if(NS_FAILED(rv)) if(NS_FAILED(rv))
return rv; return rv;
// we don't need to worry about notification callbacks // we don't need to worry about notification callbacks
rv = mFileTransport->OpenOutputStream(getter_AddRefs(outputStream)); rv = mFileTransport->OpenOutputStream(transferOffset,
transferCount,
transferFlags,
getter_AddRefs(outputStream));
if(NS_FAILED(rv)) { if(NS_FAILED(rv)) {
mFileTransport = nsnull; mFileTransport = nsnull;
return rv; return rv;
@@ -384,8 +411,12 @@ nsDiskCacheRecordChannel::OpenOutputStream(nsIOutputStream* *aResult)
} }
NS_IMETHODIMP NS_IMETHODIMP
nsDiskCacheRecordChannel::AsyncRead(nsIStreamListener *aListener, nsDiskCacheRecordTransport::AsyncRead(nsIStreamListener *aListener,
nsISupports *aContext) nsISupports *aContext,
PRUint32 transferOffset,
PRUint32 transferCount,
PRUint32 transferFlags,
nsIRequest **_retval)
{ {
nsresult rv; nsresult rv;
@@ -395,6 +426,8 @@ nsDiskCacheRecordChannel::AsyncRead(nsIStreamListener *aListener,
mRealListener = aListener; mRealListener = aListener;
nsCOMPtr<nsIStreamListener> tempListener = this; nsCOMPtr<nsIStreamListener> tempListener = this;
// XXX Only channels are added to load groups
#if 0
if (mLoadGroup) { if (mLoadGroup) {
nsCOMPtr<nsILoadGroupListenerFactory> factory; nsCOMPtr<nsILoadGroupListenerFactory> factory;
// //
@@ -410,33 +443,45 @@ nsDiskCacheRecordChannel::AsyncRead(nsIStreamListener *aListener,
} }
} }
rv = mLoadGroup->AddChannel(this, nsnull); rv = mLoadGroup->AddRequest(this, nsnull);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
} }
#endif
NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv); NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
rv = fts->CreateTransport(mSpec, PR_RDONLY, PR_IRUSR | PR_IWUSR, rv = fts->CreateTransport(mSpec,
PR_RDONLY,
PR_IRUSR | PR_IWUSR,
getter_AddRefs(mFileTransport)); getter_AddRefs(mFileTransport));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
// no callbacks // no callbacks
rv = mFileTransport->AsyncRead(tempListener, aContext); rv = mFileTransport->AsyncRead(tempListener, aContext,
transferOffset,
transferCount,
transferFlags,
getter_AddRefs(mCurrentReadRequest));
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
// release the transport so that we don't think we're in progress // release the transport so that we don't think we're in progress
mFileTransport = nsnull; mFileTransport = nsnull;
} }
NS_ADDREF(*_retval=this);
return rv; return rv;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsDiskCacheRecordChannel::AsyncWrite(nsIStreamProvider *provider, nsDiskCacheRecordTransport::AsyncWrite(nsIStreamProvider *provider,
nsISupports *ctxt) nsISupports *ctxt,
PRUint32 transferOffset,
PRUint32 transferCount,
PRUint32 transferFlags,
nsIRequest **_retval)
{ {
/* /*
if(!mFileTransport) if(!mFileTransport)
@@ -451,279 +496,66 @@ nsDiskCacheRecordChannel::AsyncWrite(nsIStreamProvider *provider,
// I can't do this since the write is not monitored, and I won't be // I can't do this since the write is not monitored, and I won't be
// able to updata the storage. // able to updata the storage.
NS_NOTREACHED("nsDiskCacheRecordChannel::AsyncWrite"); NS_NOTREACHED("nsDiskCacheRecordTransport::AsyncWrite");
return NS_ERROR_NOT_IMPLEMENTED; return NS_ERROR_NOT_IMPLEMENTED;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsDiskCacheRecordChannel::GetLoadAttributes(nsLoadFlags *aLoadAttributes) nsDiskCacheRecordTransport::GetSecurityInfo(nsISupports * *aSecurityInfo)
{
*aLoadAttributes = mLoadAttributes;
return NS_OK;
}
NS_IMETHODIMP
nsDiskCacheRecordChannel::SetLoadAttributes(nsLoadFlags aLoadAttributes)
{
mLoadAttributes = aLoadAttributes;
return NS_OK;
}
#define DUMMY_TYPE "application/x-unknown-content-type"
NS_IMETHODIMP
nsDiskCacheRecordChannel::GetContentType(char * *aContentType)
{
// Not required to be implemented, since it is implemented by cache manager
NS_NOTREACHED("nsDiskCacheRecordChannel::GetContentType");
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;
PRBool isDirectory;
if ( NS_SUCCEEDED(mSpec->IsDirectory(&isDirectory)) && isDirectory) {
*aContentType = nsCRT::strdup("application/http-index-format");
return *aContentType ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
else {
// I wish I can make this simplier
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
nsCOMPtr<nsIURI> url;
rv = nsComponentManager::CreateInstance(kStandardURLCID, nsnull,
NS_GET_IID(nsIURI),
//(void**)&url);
getter_AddRefs(url));
if (NS_FAILED(rv)) return rv;
rv = url->SetSpec((char*)urlStr);
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIMIMEService> MIMEService (do_GetService(NS_MIMESERVICE_CONTRACTID, &rv));
if (NS_FAILED(rv)) return rv;
rv = MIMEService->GetTypeFromURI(url, aContentType);
if (NS_SUCCEEDED(rv)) return rv;
}
*aContentType = nsCRT::strdup(DUMMY_TYPE);
if (!*aContentType) {
return NS_ERROR_OUT_OF_MEMORY;
} else {
return NS_OK;
}
#endif
}
NS_IMETHODIMP nsDiskCacheRecordChannel::SetContentType(const char * aContentType)
{
NS_NOTREACHED("nsDiskCacheRecordChannel::SetContentType");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDiskCacheRecordChannel::GetContentLength(PRInt32 *aContentLength)
{
nsresult rv;
PRUint32 length;
PRInt64 fileSize;
rv = mRecord->mFile->GetFileSize( &fileSize);
LL_L2UI( length, fileSize );
if (NS_SUCCEEDED(rv)) {
*aContentLength = (PRInt32)length;
} else {
*aContentLength = -1;
}
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::GetLocalFile(nsIFile* *file)
{
*file = mSpec;
NS_ADDREF(*file);
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;
}
NS_IMETHODIMP
nsDiskCacheRecordChannel::SetOwner(nsISupports* aOwner)
{
mOwner = aOwner;
return NS_OK;
}
NS_IMETHODIMP
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;
}
NS_IMETHODIMP
nsDiskCacheRecordChannel::SetLoadGroup(nsILoadGroup* aLoadGroup)
{
// Not required to be implemented, since it is implemented by cache manager
NS_ASSERTION(0, "nsDiskCacheRecordChannel method unexpectedly called");
return NS_OK;
}
NS_IMETHODIMP
nsDiskCacheRecordChannel::GetNotificationCallbacks(nsIInterfaceRequestor* *aNotificationCallbacks)
{
// Not required to be implemented, since it is implemented by cache manager
NS_NOTREACHED("nsDiskCacheRecordChannel::GetNotificationCallbacks");
return NS_ERROR_NOT_IMPLEMENTED;
}
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; *aSecurityInfo = nsnull;
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
nsDiskCacheRecordTransport::GetProgressEventSink(nsIProgressEventSink **aResult)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDiskCacheRecordTransport::SetProgressEventSink(nsIProgressEventSink *aProgress)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// nsIStreamListener methods: // nsIStreamListener methods:
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP NS_IMETHODIMP
nsDiskCacheRecordChannel::OnStartRequest(nsIChannel* transportChannel, nsISupports* context) nsDiskCacheRecordTransport::OnStartRequest(nsIRequest *request, nsISupports* context)
{ {
NS_ASSERTION(mRealListener, "No listener..."); NS_ASSERTION(mRealListener, "No listener...");
return mRealListener->OnStartRequest(this, context); return mRealListener->OnStartRequest(this, context);
} }
NS_IMETHODIMP NS_IMETHODIMP
nsDiskCacheRecordChannel::OnStopRequest(nsIChannel* transportChannel, nsISupports* context, nsDiskCacheRecordTransport::OnStopRequest(nsIRequest *request, nsISupports* context,
nsresult aStatus, const PRUnichar* aStatusArg) nsresult aStatus, const PRUnichar* aStatusArg)
{ {
nsresult rv; nsresult rv;
rv = mRealListener->OnStopRequest(this, context, aStatus, aStatusArg); rv = mRealListener->OnStopRequest(this, context, aStatus, aStatusArg);
// XXX Only channels are added to load groups
#if 0
if (mLoadGroup) { if (mLoadGroup) {
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
mLoadGroup->RemoveChannel(this, context, aStatus, aStatusArg); mLoadGroup->RemoveRequest(this, context, aStatus, aStatusArg);
} }
} }
#endif
// Release the reference to the consumer stream listener... // Release the reference to the consumer stream listener...
mRealListener = null_nsCOMPtr(); mRealListener = 0;
mFileTransport = null_nsCOMPtr(); mFileTransport = 0;
mCurrentReadRequest = 0;
return rv; return rv;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsDiskCacheRecordChannel::OnDataAvailable(nsIChannel* transportChannel, nsISupports* context, nsDiskCacheRecordTransport::OnDataAvailable(nsIRequest *request, nsISupports* context,
nsIInputStream *aIStream, PRUint32 aSourceOffset, nsIInputStream *aIStream, PRUint32 aSourceOffset,
PRUint32 aLength) PRUint32 aLength)
{ {
@@ -737,9 +569,44 @@ nsDiskCacheRecordChannel::OnDataAvailable(nsIChannel* transportChannel, nsISuppo
// insure that the transport will go away even if it is blocked waiting // insure that the transport will go away even if it is blocked waiting
// for the consumer to empty the pipe... // for the consumer to empty the pipe...
// //
if (NS_FAILED(rv) && mFileTransport) { if (NS_FAILED(rv) && mCurrentReadRequest) {
mFileTransport->Cancel(rv); mCurrentReadRequest->Cancel(rv);
} }
return rv; return rv;
} }
// XXX No reason to implement nsIFileChannel
#if 0
/* void init (in nsIFile file, in long ioFlags, in long perm); */
NS_IMETHODIMP nsDiskCacheRecordTransport::Init(nsIFile *file, PRInt32 ioFlags, PRInt32 perm)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute nsIFile file; */
NS_IMETHODIMP nsDiskCacheRecordTransport::GetFile(nsIFile * *result)
{
NS_ADDREF(*result = mSpec);
return NS_OK;
}
/* attribute long ioFlags; */
NS_IMETHODIMP nsDiskCacheRecordTransport::GetIoFlags(PRInt32 *aIoFlags)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsDiskCacheRecordTransport::SetIoFlags(PRInt32 aIoFlags)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute long permissions; */
NS_IMETHODIMP nsDiskCacheRecordTransport::GetPermissions(PRInt32 *aPermissions)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsDiskCacheRecordTransport::SetPermissions(PRInt32 aPermissions)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
#endif

Some files were not shown because too many files have changed in this diff Show More