forked from mirrors/gecko-dev
Backed out changeset 3ceaf46f8f55 (bug 1851992) Backed out changeset c9d322362e22 (bug 1851992) Backed out changeset 673df3f83249 (bug 1851992) Backed out changeset 46e18c56dd39 (bug 1851992) Backed out changeset f9f9143ac713 (bug 1851992) Backed out changeset 38c40d735ab7 (bug 1851992)
92 lines
3.1 KiB
C++
92 lines
3.1 KiB
C++
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "nsHtml5StreamListener.h"
|
|
|
|
#include "nsHtml5StreamParserReleaser.h"
|
|
|
|
NS_IMPL_ADDREF(nsHtml5StreamListener)
|
|
NS_IMPL_RELEASE(nsHtml5StreamListener)
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsHtml5StreamListener)
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIRequestObserver)
|
|
NS_INTERFACE_MAP_ENTRY(nsIRequestObserver)
|
|
NS_INTERFACE_MAP_ENTRY(nsIStreamListener)
|
|
NS_INTERFACE_MAP_ENTRY(nsIThreadRetargetableStreamListener)
|
|
NS_INTERFACE_MAP_END
|
|
|
|
nsHtml5StreamListener::nsHtml5StreamListener(nsHtml5StreamParser* aDelegate)
|
|
: mDelegateMonitor("nsHtml5StreamListener mDelegateMonitor"),
|
|
mDelegate(aDelegate) {
|
|
MOZ_ASSERT(aDelegate, "Must have delegate");
|
|
aDelegate->AddRef();
|
|
}
|
|
|
|
nsHtml5StreamListener::~nsHtml5StreamListener() { DropDelegateImpl(); }
|
|
|
|
void nsHtml5StreamListener::DropDelegate() {
|
|
MOZ_ASSERT(NS_IsMainThread(),
|
|
"Must not call DropDelegate from non-main threads.");
|
|
DropDelegateImpl();
|
|
}
|
|
|
|
void nsHtml5StreamListener::DropDelegateImpl() {
|
|
mozilla::ReentrantMonitorAutoEnter autoEnter(mDelegateMonitor);
|
|
if (mDelegate) {
|
|
nsCOMPtr<nsIRunnable> releaser = new nsHtml5StreamParserReleaser(mDelegate);
|
|
if (NS_FAILED(((nsHtml5StreamParser*)mDelegate)
|
|
->DispatchToMain(releaser.forget()))) {
|
|
NS_WARNING("Failed to dispatch releaser event.");
|
|
}
|
|
mDelegate = nullptr;
|
|
}
|
|
}
|
|
|
|
nsHtml5StreamParser* nsHtml5StreamListener::GetDelegate() {
|
|
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
|
|
// Since this can be called only on the main
|
|
// thread and DropDelegate() can only be called on the main thread
|
|
// it's OK that the monitor here doesn't protect the use of the
|
|
// return value.
|
|
return mDelegate;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsHtml5StreamListener::CheckListenerChain() {
|
|
if (MOZ_UNLIKELY(!mDelegate)) {
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsHtml5StreamListener::OnStartRequest(nsIRequest* aRequest) {
|
|
mozilla::ReentrantMonitorAutoEnter autoEnter(mDelegateMonitor);
|
|
if (MOZ_UNLIKELY(!mDelegate)) {
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
}
|
|
return ((nsHtml5StreamParser*)mDelegate)->OnStartRequest(aRequest);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsHtml5StreamListener::OnStopRequest(nsIRequest* aRequest, nsresult aStatus) {
|
|
mozilla::ReentrantMonitorAutoEnter autoEnter(mDelegateMonitor);
|
|
if (MOZ_UNLIKELY(!mDelegate)) {
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
}
|
|
return ((nsHtml5StreamParser*)mDelegate)->OnStopRequest(aRequest, aStatus);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsHtml5StreamListener::OnDataAvailable(nsIRequest* aRequest,
|
|
nsIInputStream* aInStream,
|
|
uint64_t aSourceOffset,
|
|
uint32_t aLength) {
|
|
mozilla::ReentrantMonitorAutoEnter autoEnter(mDelegateMonitor);
|
|
if (MOZ_UNLIKELY(!mDelegate)) {
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
}
|
|
return ((nsHtml5StreamParser*)mDelegate)
|
|
->OnDataAvailable(aRequest, aInStream, aSourceOffset, aLength);
|
|
}
|