michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsSimpleStreamListener.h" michael@0: michael@0: // michael@0: //---------------------------------------------------------------------------- michael@0: // nsISupports implementation... michael@0: //---------------------------------------------------------------------------- michael@0: // michael@0: NS_IMPL_ISUPPORTS(nsSimpleStreamListener, michael@0: nsISimpleStreamListener, michael@0: nsIStreamListener, michael@0: nsIRequestObserver) michael@0: michael@0: // michael@0: //---------------------------------------------------------------------------- michael@0: // nsIRequestObserver implementation... michael@0: //---------------------------------------------------------------------------- michael@0: // michael@0: NS_IMETHODIMP michael@0: nsSimpleStreamListener::OnStartRequest(nsIRequest *aRequest, michael@0: nsISupports *aContext) michael@0: { michael@0: return mObserver ? michael@0: mObserver->OnStartRequest(aRequest, aContext) : NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsSimpleStreamListener::OnStopRequest(nsIRequest* request, michael@0: nsISupports *aContext, michael@0: nsresult aStatus) michael@0: { michael@0: return mObserver ? michael@0: mObserver->OnStopRequest(request, aContext, aStatus) : NS_OK; michael@0: } michael@0: michael@0: // michael@0: //---------------------------------------------------------------------------- michael@0: // nsIStreamListener implementation... michael@0: //---------------------------------------------------------------------------- michael@0: // michael@0: NS_IMETHODIMP michael@0: nsSimpleStreamListener::OnDataAvailable(nsIRequest* request, michael@0: nsISupports *aContext, michael@0: nsIInputStream *aSource, michael@0: uint64_t aOffset, michael@0: uint32_t aCount) michael@0: { michael@0: uint32_t writeCount; michael@0: nsresult rv = mSink->WriteFrom(aSource, aCount, &writeCount); michael@0: // michael@0: // Equate zero bytes read and NS_SUCCEEDED to stopping the read. michael@0: // michael@0: if (NS_SUCCEEDED(rv) && (writeCount == 0)) michael@0: return NS_BASE_STREAM_CLOSED; michael@0: return rv; michael@0: } michael@0: michael@0: // michael@0: //---------------------------------------------------------------------------- michael@0: // nsISimpleStreamListener implementation... michael@0: //---------------------------------------------------------------------------- michael@0: // michael@0: NS_IMETHODIMP michael@0: nsSimpleStreamListener::Init(nsIOutputStream *aSink, michael@0: nsIRequestObserver *aObserver) michael@0: { michael@0: NS_PRECONDITION(aSink, "null output stream"); michael@0: michael@0: mSink = aSink; michael@0: mObserver = aObserver; michael@0: michael@0: return NS_OK; michael@0: }