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