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
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "nsSimpleStreamListener.h" |
michael@0 | 7 | |
michael@0 | 8 | // |
michael@0 | 9 | //---------------------------------------------------------------------------- |
michael@0 | 10 | // nsISupports implementation... |
michael@0 | 11 | //---------------------------------------------------------------------------- |
michael@0 | 12 | // |
michael@0 | 13 | NS_IMPL_ISUPPORTS(nsSimpleStreamListener, |
michael@0 | 14 | nsISimpleStreamListener, |
michael@0 | 15 | nsIStreamListener, |
michael@0 | 16 | nsIRequestObserver) |
michael@0 | 17 | |
michael@0 | 18 | // |
michael@0 | 19 | //---------------------------------------------------------------------------- |
michael@0 | 20 | // nsIRequestObserver implementation... |
michael@0 | 21 | //---------------------------------------------------------------------------- |
michael@0 | 22 | // |
michael@0 | 23 | NS_IMETHODIMP |
michael@0 | 24 | nsSimpleStreamListener::OnStartRequest(nsIRequest *aRequest, |
michael@0 | 25 | nsISupports *aContext) |
michael@0 | 26 | { |
michael@0 | 27 | return mObserver ? |
michael@0 | 28 | mObserver->OnStartRequest(aRequest, aContext) : NS_OK; |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | NS_IMETHODIMP |
michael@0 | 32 | nsSimpleStreamListener::OnStopRequest(nsIRequest* request, |
michael@0 | 33 | nsISupports *aContext, |
michael@0 | 34 | nsresult aStatus) |
michael@0 | 35 | { |
michael@0 | 36 | return mObserver ? |
michael@0 | 37 | mObserver->OnStopRequest(request, aContext, aStatus) : NS_OK; |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | // |
michael@0 | 41 | //---------------------------------------------------------------------------- |
michael@0 | 42 | // nsIStreamListener implementation... |
michael@0 | 43 | //---------------------------------------------------------------------------- |
michael@0 | 44 | // |
michael@0 | 45 | NS_IMETHODIMP |
michael@0 | 46 | nsSimpleStreamListener::OnDataAvailable(nsIRequest* request, |
michael@0 | 47 | nsISupports *aContext, |
michael@0 | 48 | nsIInputStream *aSource, |
michael@0 | 49 | uint64_t aOffset, |
michael@0 | 50 | uint32_t aCount) |
michael@0 | 51 | { |
michael@0 | 52 | uint32_t writeCount; |
michael@0 | 53 | nsresult rv = mSink->WriteFrom(aSource, aCount, &writeCount); |
michael@0 | 54 | // |
michael@0 | 55 | // Equate zero bytes read and NS_SUCCEEDED to stopping the read. |
michael@0 | 56 | // |
michael@0 | 57 | if (NS_SUCCEEDED(rv) && (writeCount == 0)) |
michael@0 | 58 | return NS_BASE_STREAM_CLOSED; |
michael@0 | 59 | return rv; |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | // |
michael@0 | 63 | //---------------------------------------------------------------------------- |
michael@0 | 64 | // nsISimpleStreamListener implementation... |
michael@0 | 65 | //---------------------------------------------------------------------------- |
michael@0 | 66 | // |
michael@0 | 67 | NS_IMETHODIMP |
michael@0 | 68 | nsSimpleStreamListener::Init(nsIOutputStream *aSink, |
michael@0 | 69 | nsIRequestObserver *aObserver) |
michael@0 | 70 | { |
michael@0 | 71 | NS_PRECONDITION(aSink, "null output stream"); |
michael@0 | 72 | |
michael@0 | 73 | mSink = aSink; |
michael@0 | 74 | mObserver = aObserver; |
michael@0 | 75 | |
michael@0 | 76 | return NS_OK; |
michael@0 | 77 | } |