1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsSimpleStreamListener.h"
12 //----------------------------------------------------------------------------
13 // nsISupports implementation...
14 //----------------------------------------------------------------------------
16 NS_IMPL_ISUPPORTS(nsSimpleStreamListener
, nsISimpleStreamListener
,
17 nsIStreamListener
, nsIRequestObserver
)
20 //----------------------------------------------------------------------------
21 // nsIRequestObserver implementation...
22 //----------------------------------------------------------------------------
25 nsSimpleStreamListener::OnStartRequest(nsIRequest
* aRequest
) {
26 return mObserver
? mObserver
->OnStartRequest(aRequest
) : NS_OK
;
30 nsSimpleStreamListener::OnStopRequest(nsIRequest
* request
, nsresult aStatus
) {
31 return mObserver
? mObserver
->OnStopRequest(request
, aStatus
) : NS_OK
;
35 //----------------------------------------------------------------------------
36 // nsIStreamListener implementation...
37 //----------------------------------------------------------------------------
40 nsSimpleStreamListener::OnDataAvailable(nsIRequest
* request
,
41 nsIInputStream
* aSource
,
42 uint64_t aOffset
, uint32_t aCount
) {
44 nsresult rv
= mSink
->WriteFrom(aSource
, aCount
, &writeCount
);
46 // Equate zero bytes read and NS_SUCCEEDED to stopping the read.
48 if (NS_SUCCEEDED(rv
) && (writeCount
== 0)) return NS_BASE_STREAM_CLOSED
;
53 //----------------------------------------------------------------------------
54 // nsISimpleStreamListener implementation...
55 //----------------------------------------------------------------------------
58 nsSimpleStreamListener::Init(nsIOutputStream
* aSink
,
59 nsIRequestObserver
* aObserver
) {
60 MOZ_ASSERT(aSink
, "null output stream");
63 mObserver
= aObserver
;
69 } // namespace mozilla