|
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 NS_IMPL_ADDREF(nsHtml5StreamListener) |
|
8 NS_IMPL_RELEASE(nsHtml5StreamListener) |
|
9 |
|
10 NS_INTERFACE_MAP_BEGIN(nsHtml5StreamListener) |
|
11 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIRequestObserver) |
|
12 NS_INTERFACE_MAP_ENTRY(nsIRequestObserver) |
|
13 NS_INTERFACE_MAP_ENTRY(nsIStreamListener) |
|
14 NS_INTERFACE_MAP_ENTRY(nsIThreadRetargetableStreamListener) |
|
15 NS_INTERFACE_MAP_END_THREADSAFE |
|
16 |
|
17 nsHtml5StreamListener::nsHtml5StreamListener(nsHtml5StreamParser* aDelegate) |
|
18 : mDelegate(aDelegate) |
|
19 { |
|
20 } |
|
21 |
|
22 nsHtml5StreamListener::~nsHtml5StreamListener() |
|
23 { |
|
24 } |
|
25 |
|
26 void |
|
27 nsHtml5StreamListener::DropDelegate() |
|
28 { |
|
29 MOZ_ASSERT(NS_IsMainThread(), |
|
30 "Must not call DropDelegate from non-main threads."); |
|
31 mDelegate = nullptr; |
|
32 } |
|
33 |
|
34 NS_IMETHODIMP |
|
35 nsHtml5StreamListener::CheckListenerChain() |
|
36 { |
|
37 if (MOZ_UNLIKELY(!mDelegate)) { |
|
38 return NS_ERROR_NOT_AVAILABLE; |
|
39 } |
|
40 return mDelegate->CheckListenerChain(); |
|
41 } |
|
42 |
|
43 NS_IMETHODIMP |
|
44 nsHtml5StreamListener::OnStartRequest(nsIRequest* aRequest, |
|
45 nsISupports* aContext) |
|
46 { |
|
47 if (MOZ_UNLIKELY(!mDelegate)) { |
|
48 return NS_ERROR_NOT_AVAILABLE; |
|
49 } |
|
50 return mDelegate->OnStartRequest(aRequest, aContext); |
|
51 } |
|
52 |
|
53 NS_IMETHODIMP |
|
54 nsHtml5StreamListener::OnStopRequest(nsIRequest* aRequest, |
|
55 nsISupports* aContext, |
|
56 nsresult aStatus) |
|
57 { |
|
58 if (MOZ_UNLIKELY(!mDelegate)) { |
|
59 return NS_ERROR_NOT_AVAILABLE; |
|
60 } |
|
61 return mDelegate->OnStopRequest(aRequest, |
|
62 aContext, |
|
63 aStatus); |
|
64 } |
|
65 |
|
66 NS_IMETHODIMP |
|
67 nsHtml5StreamListener::OnDataAvailable(nsIRequest* aRequest, |
|
68 nsISupports* aContext, |
|
69 nsIInputStream* aInStream, |
|
70 uint64_t aSourceOffset, |
|
71 uint32_t aLength) |
|
72 { |
|
73 if (MOZ_UNLIKELY(!mDelegate)) { |
|
74 return NS_ERROR_NOT_AVAILABLE; |
|
75 } |
|
76 return mDelegate->OnDataAvailable(aRequest, |
|
77 aContext, |
|
78 aInStream, |
|
79 aSourceOffset, |
|
80 aLength); |
|
81 } |
|
82 |