parser/html/nsHtml5StreamListener.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/parser/html/nsHtml5StreamListener.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,82 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#include "nsHtml5StreamListener.h"
     1.9 +
    1.10 +NS_IMPL_ADDREF(nsHtml5StreamListener)
    1.11 +NS_IMPL_RELEASE(nsHtml5StreamListener)
    1.12 +
    1.13 +NS_INTERFACE_MAP_BEGIN(nsHtml5StreamListener)
    1.14 +  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIRequestObserver)
    1.15 +  NS_INTERFACE_MAP_ENTRY(nsIRequestObserver)
    1.16 +  NS_INTERFACE_MAP_ENTRY(nsIStreamListener)
    1.17 +  NS_INTERFACE_MAP_ENTRY(nsIThreadRetargetableStreamListener)
    1.18 +NS_INTERFACE_MAP_END_THREADSAFE
    1.19 +
    1.20 +nsHtml5StreamListener::nsHtml5StreamListener(nsHtml5StreamParser* aDelegate)
    1.21 + : mDelegate(aDelegate)
    1.22 +{
    1.23 +}
    1.24 +
    1.25 +nsHtml5StreamListener::~nsHtml5StreamListener()
    1.26 +{
    1.27 +}
    1.28 +
    1.29 +void
    1.30 +nsHtml5StreamListener::DropDelegate()
    1.31 +{
    1.32 +  MOZ_ASSERT(NS_IsMainThread(),
    1.33 +             "Must not call DropDelegate from non-main threads.");
    1.34 +  mDelegate = nullptr;
    1.35 +}
    1.36 +
    1.37 +NS_IMETHODIMP
    1.38 +nsHtml5StreamListener::CheckListenerChain()
    1.39 +{
    1.40 +  if (MOZ_UNLIKELY(!mDelegate)) {
    1.41 +    return NS_ERROR_NOT_AVAILABLE;
    1.42 +  }
    1.43 +  return mDelegate->CheckListenerChain();
    1.44 +}
    1.45 +
    1.46 +NS_IMETHODIMP
    1.47 +nsHtml5StreamListener::OnStartRequest(nsIRequest* aRequest,
    1.48 +                                      nsISupports* aContext)
    1.49 +{
    1.50 +  if (MOZ_UNLIKELY(!mDelegate)) {
    1.51 +    return NS_ERROR_NOT_AVAILABLE;
    1.52 +  }
    1.53 +  return mDelegate->OnStartRequest(aRequest, aContext);
    1.54 +}
    1.55 +
    1.56 +NS_IMETHODIMP
    1.57 +nsHtml5StreamListener::OnStopRequest(nsIRequest* aRequest,
    1.58 +                                     nsISupports* aContext,
    1.59 +                                     nsresult aStatus)
    1.60 +{
    1.61 +  if (MOZ_UNLIKELY(!mDelegate)) {
    1.62 +    return NS_ERROR_NOT_AVAILABLE;
    1.63 +  }
    1.64 +  return mDelegate->OnStopRequest(aRequest,
    1.65 +                                  aContext,
    1.66 +                                  aStatus);
    1.67 +}
    1.68 +
    1.69 +NS_IMETHODIMP
    1.70 +nsHtml5StreamListener::OnDataAvailable(nsIRequest* aRequest,
    1.71 +                                       nsISupports* aContext,
    1.72 +                                       nsIInputStream* aInStream,
    1.73 +                                       uint64_t aSourceOffset,
    1.74 +                                       uint32_t aLength)
    1.75 +{
    1.76 +  if (MOZ_UNLIKELY(!mDelegate)) {
    1.77 +    return NS_ERROR_NOT_AVAILABLE;
    1.78 +  }
    1.79 +  return mDelegate->OnDataAvailable(aRequest,
    1.80 +                                    aContext,
    1.81 +                                    aInStream,
    1.82 +                                    aSourceOffset,
    1.83 +                                    aLength);
    1.84 +}
    1.85 +

mercurial