The file channel needs to implement nsIProgressEventSink, so the channel parameter is *not* the file transport. Doing this means that the FileChannel also needs to implement nsIInterfaceRequestor...

This commit is contained in:
rpotts%netscape.com 2000-06-02 05:19:16 +00:00
Родитель 08dc824141
Коммит 74ac421980
2 изменённых файлов: 70 добавлений и 7 удалений

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

@ -83,12 +83,14 @@ nsFileChannel::~nsFileChannel()
{
}
NS_IMPL_THREADSAFE_ISUPPORTS5(nsFileChannel,
NS_IMPL_THREADSAFE_ISUPPORTS7(nsFileChannel,
nsIFileChannel,
nsIChannel,
nsIRequest,
nsIStreamListener,
nsIStreamObserver)
nsIStreamObserver,
nsIProgressEventSink,
nsIInterfaceRequestor)
NS_METHOD
nsFileChannel::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult)
@ -222,7 +224,7 @@ nsFileChannel::EnsureTransport()
if (NS_FAILED(rv)) return rv;
}
if (mCallbacks) {
rv = mFileTransport->SetNotificationCallbacks(mCallbacks);
rv = mFileTransport->SetNotificationCallbacks(this);
if (NS_FAILED(rv)) return rv;
}
if (mTransferOffset) {
@ -586,6 +588,13 @@ NS_IMETHODIMP
nsFileChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCallbacks)
{
mCallbacks = aNotificationCallbacks;
// Cache the new nsIProgressEventSink instance...
if (mCallbacks) {
(void)mCallbacks->GetInterface(NS_GET_IID(nsIProgressEventSink),
getter_AddRefs(mProgress));
}
return NS_OK;
}
@ -661,6 +670,57 @@ nsFileChannel::OnDataAvailable(nsIChannel* transportChannel, nsISupports* contex
return rv;
}
////////////////////////////////////////////////////////////////////////////////
// From nsIInterfaceRequestor
////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP
nsFileChannel::GetInterface(const nsIID &anIID, void **aResult )
{
// capture the progress event sink stuff. pass the rest through.
if (anIID.Equals(NS_GET_IID(nsIProgressEventSink))) {
*aResult = NS_STATIC_CAST(nsIProgressEventSink*, this);
NS_ADDREF(this);
return NS_OK;
}
else if (mCallbacks) {
return mCallbacks->GetInterface(anIID, aResult);
}
return NS_ERROR_NO_INTERFACE;
}
////////////////////////////////////////////////////////////////////////////////
// From nsIProgressEventSink
////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP
nsFileChannel::OnStatus(nsIChannel *aChannel,
nsISupports *aContext,
const PRUnichar *aMsg)
{
nsresult rv = NS_OK;
if (mProgress) {
mProgress->OnStatus(this, aContext, aMsg);
}
return rv;
}
NS_IMETHODIMP
nsFileChannel::OnProgress(nsIChannel* aChannel,
nsISupports* aContext,
PRUint32 aProgress,
PRUint32 aProgressMax)
{
nsresult rv = NS_OK;
if (mProgress) {
rv = mProgress->OnProgress(this, aContext, aProgress, aProgressMax);
}
return rv;
}
////////////////////////////////////////////////////////////////////////////////
// From nsIFileChannel
////////////////////////////////////////////////////////////////////////////////

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

@ -27,7 +27,6 @@
#include "nsIInterfaceRequestor.h"
#include "nsILoadGroup.h"
#include "nsIStreamListener.h"
#include "nsIChannel.h"
#include "nsFileSpec.h"
#include "nsIURI.h"
#include "nsCOMPtr.h"
@ -36,21 +35,24 @@
#include "prlock.h"
#include "nsIEventQueueService.h"
#include "nsIPipe.h"
#include "nsILoadGroup.h"
#include "nsIStreamListener.h"
#include "nsCOMPtr.h"
#include "nsIFile.h" /* Solaris/gcc needed this here. */
#include "nsIProgressEventSink.h"
class nsFileChannel : public nsIFileChannel,
public nsIStreamListener
public nsIInterfaceRequestor,
public nsIStreamListener,
public nsIProgressEventSink
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIREQUEST
NS_DECL_NSICHANNEL
NS_DECL_NSIFILECHANNEL
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSISTREAMOBSERVER
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSIPROGRESSEVENTSINK
nsFileChannel();
// Always make the destructor virtual:
@ -81,6 +83,7 @@ protected:
PRUint32 mBufferSegmentSize;
PRUint32 mBufferMaxSize;
nsresult mStatus;
nsCOMPtr<nsIProgressEventSink> mProgress;
#ifdef DEBUG
PRThread* mInitiator;
#endif