michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsHtml5StreamListener.h" michael@0: michael@0: NS_IMPL_ADDREF(nsHtml5StreamListener) michael@0: NS_IMPL_RELEASE(nsHtml5StreamListener) michael@0: michael@0: NS_INTERFACE_MAP_BEGIN(nsHtml5StreamListener) michael@0: NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIRequestObserver) michael@0: NS_INTERFACE_MAP_ENTRY(nsIRequestObserver) michael@0: NS_INTERFACE_MAP_ENTRY(nsIStreamListener) michael@0: NS_INTERFACE_MAP_ENTRY(nsIThreadRetargetableStreamListener) michael@0: NS_INTERFACE_MAP_END_THREADSAFE michael@0: michael@0: nsHtml5StreamListener::nsHtml5StreamListener(nsHtml5StreamParser* aDelegate) michael@0: : mDelegate(aDelegate) michael@0: { michael@0: } michael@0: michael@0: nsHtml5StreamListener::~nsHtml5StreamListener() michael@0: { michael@0: } michael@0: michael@0: void michael@0: nsHtml5StreamListener::DropDelegate() michael@0: { michael@0: MOZ_ASSERT(NS_IsMainThread(), michael@0: "Must not call DropDelegate from non-main threads."); michael@0: mDelegate = nullptr; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsHtml5StreamListener::CheckListenerChain() michael@0: { michael@0: if (MOZ_UNLIKELY(!mDelegate)) { michael@0: return NS_ERROR_NOT_AVAILABLE; michael@0: } michael@0: return mDelegate->CheckListenerChain(); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsHtml5StreamListener::OnStartRequest(nsIRequest* aRequest, michael@0: nsISupports* aContext) michael@0: { michael@0: if (MOZ_UNLIKELY(!mDelegate)) { michael@0: return NS_ERROR_NOT_AVAILABLE; michael@0: } michael@0: return mDelegate->OnStartRequest(aRequest, aContext); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsHtml5StreamListener::OnStopRequest(nsIRequest* aRequest, michael@0: nsISupports* aContext, michael@0: nsresult aStatus) michael@0: { michael@0: if (MOZ_UNLIKELY(!mDelegate)) { michael@0: return NS_ERROR_NOT_AVAILABLE; michael@0: } michael@0: return mDelegate->OnStopRequest(aRequest, michael@0: aContext, michael@0: aStatus); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsHtml5StreamListener::OnDataAvailable(nsIRequest* aRequest, michael@0: nsISupports* aContext, michael@0: nsIInputStream* aInStream, michael@0: uint64_t aSourceOffset, michael@0: uint32_t aLength) michael@0: { michael@0: if (MOZ_UNLIKELY(!mDelegate)) { michael@0: return NS_ERROR_NOT_AVAILABLE; michael@0: } michael@0: return mDelegate->OnDataAvailable(aRequest, michael@0: aContext, michael@0: aInStream, michael@0: aSourceOffset, michael@0: aLength); michael@0: } michael@0: