1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/base/src/nsSimpleStreamListener.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,77 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "nsSimpleStreamListener.h" 1.10 + 1.11 +// 1.12 +//---------------------------------------------------------------------------- 1.13 +// nsISupports implementation... 1.14 +//---------------------------------------------------------------------------- 1.15 +// 1.16 +NS_IMPL_ISUPPORTS(nsSimpleStreamListener, 1.17 + nsISimpleStreamListener, 1.18 + nsIStreamListener, 1.19 + nsIRequestObserver) 1.20 + 1.21 +// 1.22 +//---------------------------------------------------------------------------- 1.23 +// nsIRequestObserver implementation... 1.24 +//---------------------------------------------------------------------------- 1.25 +// 1.26 +NS_IMETHODIMP 1.27 +nsSimpleStreamListener::OnStartRequest(nsIRequest *aRequest, 1.28 + nsISupports *aContext) 1.29 +{ 1.30 + return mObserver ? 1.31 + mObserver->OnStartRequest(aRequest, aContext) : NS_OK; 1.32 +} 1.33 + 1.34 +NS_IMETHODIMP 1.35 +nsSimpleStreamListener::OnStopRequest(nsIRequest* request, 1.36 + nsISupports *aContext, 1.37 + nsresult aStatus) 1.38 +{ 1.39 + return mObserver ? 1.40 + mObserver->OnStopRequest(request, aContext, aStatus) : NS_OK; 1.41 +} 1.42 + 1.43 +// 1.44 +//---------------------------------------------------------------------------- 1.45 +// nsIStreamListener implementation... 1.46 +//---------------------------------------------------------------------------- 1.47 +// 1.48 +NS_IMETHODIMP 1.49 +nsSimpleStreamListener::OnDataAvailable(nsIRequest* request, 1.50 + nsISupports *aContext, 1.51 + nsIInputStream *aSource, 1.52 + uint64_t aOffset, 1.53 + uint32_t aCount) 1.54 +{ 1.55 + uint32_t writeCount; 1.56 + nsresult rv = mSink->WriteFrom(aSource, aCount, &writeCount); 1.57 + // 1.58 + // Equate zero bytes read and NS_SUCCEEDED to stopping the read. 1.59 + // 1.60 + if (NS_SUCCEEDED(rv) && (writeCount == 0)) 1.61 + return NS_BASE_STREAM_CLOSED; 1.62 + return rv; 1.63 +} 1.64 + 1.65 +// 1.66 +//---------------------------------------------------------------------------- 1.67 +// nsISimpleStreamListener implementation... 1.68 +//---------------------------------------------------------------------------- 1.69 +// 1.70 +NS_IMETHODIMP 1.71 +nsSimpleStreamListener::Init(nsIOutputStream *aSink, 1.72 + nsIRequestObserver *aObserver) 1.73 +{ 1.74 + NS_PRECONDITION(aSink, "null output stream"); 1.75 + 1.76 + mSink = aSink; 1.77 + mObserver = aObserver; 1.78 + 1.79 + return NS_OK; 1.80 +}