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 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "nsHtml5StreamListener.h" |
michael@0 | 6 | |
michael@0 | 7 | NS_IMPL_ADDREF(nsHtml5StreamListener) |
michael@0 | 8 | NS_IMPL_RELEASE(nsHtml5StreamListener) |
michael@0 | 9 | |
michael@0 | 10 | NS_INTERFACE_MAP_BEGIN(nsHtml5StreamListener) |
michael@0 | 11 | NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIRequestObserver) |
michael@0 | 12 | NS_INTERFACE_MAP_ENTRY(nsIRequestObserver) |
michael@0 | 13 | NS_INTERFACE_MAP_ENTRY(nsIStreamListener) |
michael@0 | 14 | NS_INTERFACE_MAP_ENTRY(nsIThreadRetargetableStreamListener) |
michael@0 | 15 | NS_INTERFACE_MAP_END_THREADSAFE |
michael@0 | 16 | |
michael@0 | 17 | nsHtml5StreamListener::nsHtml5StreamListener(nsHtml5StreamParser* aDelegate) |
michael@0 | 18 | : mDelegate(aDelegate) |
michael@0 | 19 | { |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | nsHtml5StreamListener::~nsHtml5StreamListener() |
michael@0 | 23 | { |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | void |
michael@0 | 27 | nsHtml5StreamListener::DropDelegate() |
michael@0 | 28 | { |
michael@0 | 29 | MOZ_ASSERT(NS_IsMainThread(), |
michael@0 | 30 | "Must not call DropDelegate from non-main threads."); |
michael@0 | 31 | mDelegate = nullptr; |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | NS_IMETHODIMP |
michael@0 | 35 | nsHtml5StreamListener::CheckListenerChain() |
michael@0 | 36 | { |
michael@0 | 37 | if (MOZ_UNLIKELY(!mDelegate)) { |
michael@0 | 38 | return NS_ERROR_NOT_AVAILABLE; |
michael@0 | 39 | } |
michael@0 | 40 | return mDelegate->CheckListenerChain(); |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | NS_IMETHODIMP |
michael@0 | 44 | nsHtml5StreamListener::OnStartRequest(nsIRequest* aRequest, |
michael@0 | 45 | nsISupports* aContext) |
michael@0 | 46 | { |
michael@0 | 47 | if (MOZ_UNLIKELY(!mDelegate)) { |
michael@0 | 48 | return NS_ERROR_NOT_AVAILABLE; |
michael@0 | 49 | } |
michael@0 | 50 | return mDelegate->OnStartRequest(aRequest, aContext); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | NS_IMETHODIMP |
michael@0 | 54 | nsHtml5StreamListener::OnStopRequest(nsIRequest* aRequest, |
michael@0 | 55 | nsISupports* aContext, |
michael@0 | 56 | nsresult aStatus) |
michael@0 | 57 | { |
michael@0 | 58 | if (MOZ_UNLIKELY(!mDelegate)) { |
michael@0 | 59 | return NS_ERROR_NOT_AVAILABLE; |
michael@0 | 60 | } |
michael@0 | 61 | return mDelegate->OnStopRequest(aRequest, |
michael@0 | 62 | aContext, |
michael@0 | 63 | aStatus); |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | NS_IMETHODIMP |
michael@0 | 67 | nsHtml5StreamListener::OnDataAvailable(nsIRequest* aRequest, |
michael@0 | 68 | nsISupports* aContext, |
michael@0 | 69 | nsIInputStream* aInStream, |
michael@0 | 70 | uint64_t aSourceOffset, |
michael@0 | 71 | uint32_t aLength) |
michael@0 | 72 | { |
michael@0 | 73 | if (MOZ_UNLIKELY(!mDelegate)) { |
michael@0 | 74 | return NS_ERROR_NOT_AVAILABLE; |
michael@0 | 75 | } |
michael@0 | 76 | return mDelegate->OnDataAvailable(aRequest, |
michael@0 | 77 | aContext, |
michael@0 | 78 | aInStream, |
michael@0 | 79 | aSourceOffset, |
michael@0 | 80 | aLength); |
michael@0 | 81 | } |
michael@0 | 82 |