Make nsJSChannel follow the nsIChannel interface contract better. Bug 343850,

r=darin, sr=jst
This commit is contained in:
bzbarsky%mit.edu 2006-07-19 00:53:11 +00:00
Родитель 2836c4c742
Коммит 64f82c69be
2 изменённых файлов: 64 добавлений и 3 удалений

Просмотреть файл

@ -332,7 +332,8 @@ nsresult nsJSThunk::BringUpConsole(nsIDOMWindow *aDomWindow)
////////////////////////////////////////////////////////////////////////////////
class nsJSChannel : public nsIChannel
class nsJSChannel : public nsIChannel,
public nsIStreamListener
{
public:
nsJSChannel();
@ -340,6 +341,8 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSIREQUEST
NS_DECL_NSICHANNEL
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER
nsresult Init(nsIURI *aURI);
@ -353,6 +356,7 @@ protected:
protected:
nsCOMPtr<nsIChannel> mStreamChannel;
nsCOMPtr<nsIStreamListener> mListener; // Our final listener
nsLoadFlags mLoadFlags;
@ -426,6 +430,8 @@ NS_INTERFACE_MAP_BEGIN(nsJSChannel)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIChannel)
NS_INTERFACE_MAP_ENTRY(nsIRequest)
NS_INTERFACE_MAP_ENTRY(nsIChannel)
NS_INTERFACE_MAP_ENTRY(nsIRequestObserver)
NS_INTERFACE_MAP_ENTRY(nsIStreamListener)
NS_INTERFACE_MAP_END
//
@ -510,7 +516,12 @@ nsJSChannel::Open(nsIInputStream **aResult)
NS_IMETHODIMP
nsJSChannel::AsyncOpen(nsIStreamListener *aListener, nsISupports *aContext)
{
return InternalOpen(PR_TRUE, aListener, aContext, nsnull);
mListener = aListener;
nsresult rv = InternalOpen(PR_TRUE, this, aContext, nsnull);
if (NS_FAILED(rv)) {
mListener = nsnull;
}
return rv;
}
nsresult
@ -714,6 +725,40 @@ nsJSChannel::SetContentLength(PRInt32 aContentLength)
return mStreamChannel->SetContentLength(aContentLength);
}
NS_IMETHODIMP
nsJSChannel::OnStartRequest(nsIRequest* aRequest,
nsISupports* aContext)
{
NS_ENSURE_TRUE(aRequest == mStreamChannel, NS_ERROR_UNEXPECTED);
return mListener->OnStartRequest(this, aContext);
}
NS_IMETHODIMP
nsJSChannel::OnDataAvailable(nsIRequest* aRequest,
nsISupports* aContext,
nsIInputStream* aInputStream,
PRUint32 aOffset,
PRUint32 aCount)
{
NS_ENSURE_TRUE(aRequest == mStreamChannel, NS_ERROR_UNEXPECTED);
return mListener->OnDataAvailable(this, aContext, aInputStream, aOffset,
aCount);
}
NS_IMETHODIMP
nsJSChannel::OnStopRequest(nsIRequest* aRequest,
nsISupports* aContext,
nsresult aStatus)
{
// Make sure to drop our ref to mListener
nsCOMPtr<nsIStreamListener> listener;
listener.swap(mListener);
NS_ENSURE_TRUE(aRequest == mStreamChannel, NS_ERROR_UNEXPECTED);
return listener->OnStopRequest(this, aContext, aStatus);
}
////////////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -172,10 +172,26 @@ interface nsIChannel : nsIRequest
* Asynchronously open this channel. Data is fed to the specified stream
* listener as it becomes available. The stream listener's methods are
* called on the thread that calls asyncOpen and are not called until
* after asyncOpen returns.
* after asyncOpen returns. If asyncOpen returns successfully, the
* channel promises to call at least onStartRequest and onStopRequest.
*
* If the nsIRequest object passed to the stream listener's methods is not
* this channel, an appropriate onChannelRedirect notification needs to be
* sent to the notification callbacks before onStartRequest is called.
* Once onStartRequest is called, all following method calls on aListener
* will get the request that was passed to onStartRequest.
*
* If the channel's and loadgroup's notification callbacks do not provide
* an nsIChannelEventSink when onChannelRedirect would be called, that's
* equivalent to having called onChannelRedirect.
*
* If asyncOpen returns successfully, the channel is responsible for
* keeping itself alive until it has called onStopRequest on aListener or
* called onChannelRedirect.
*
* @param aListener the nsIStreamListener implementation
* @param aContext an opaque parameter forwarded to aListener's methods
* @see nsIChannelEventSink for onChannelRedirect
*/
void asyncOpen(in nsIStreamListener aListener, in nsISupports aContext);