Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
8 //
9 //----------------------------------------------------------------------------
10 // nsISupports implementation...
11 //----------------------------------------------------------------------------
12 //
13 NS_IMPL_ISUPPORTS(nsSimpleStreamListener,
14 nsISimpleStreamListener,
15 nsIStreamListener,
16 nsIRequestObserver)
18 //
19 //----------------------------------------------------------------------------
20 // nsIRequestObserver implementation...
21 //----------------------------------------------------------------------------
22 //
23 NS_IMETHODIMP
24 nsSimpleStreamListener::OnStartRequest(nsIRequest *aRequest,
25 nsISupports *aContext)
26 {
27 return mObserver ?
28 mObserver->OnStartRequest(aRequest, aContext) : NS_OK;
29 }
31 NS_IMETHODIMP
32 nsSimpleStreamListener::OnStopRequest(nsIRequest* request,
33 nsISupports *aContext,
34 nsresult aStatus)
35 {
36 return mObserver ?
37 mObserver->OnStopRequest(request, aContext, aStatus) : NS_OK;
38 }
40 //
41 //----------------------------------------------------------------------------
42 // nsIStreamListener implementation...
43 //----------------------------------------------------------------------------
44 //
45 NS_IMETHODIMP
46 nsSimpleStreamListener::OnDataAvailable(nsIRequest* request,
47 nsISupports *aContext,
48 nsIInputStream *aSource,
49 uint64_t aOffset,
50 uint32_t aCount)
51 {
52 uint32_t writeCount;
53 nsresult rv = mSink->WriteFrom(aSource, aCount, &writeCount);
54 //
55 // Equate zero bytes read and NS_SUCCEEDED to stopping the read.
56 //
57 if (NS_SUCCEEDED(rv) && (writeCount == 0))
58 return NS_BASE_STREAM_CLOSED;
59 return rv;
60 }
62 //
63 //----------------------------------------------------------------------------
64 // nsISimpleStreamListener implementation...
65 //----------------------------------------------------------------------------
66 //
67 NS_IMETHODIMP
68 nsSimpleStreamListener::Init(nsIOutputStream *aSink,
69 nsIRequestObserver *aObserver)
70 {
71 NS_PRECONDITION(aSink, "null output stream");
73 mSink = aSink;
74 mObserver = aObserver;
76 return NS_OK;
77 }