/src/mozilla-central/netwerk/protocol/http/InterceptedChannel.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim:set expandtab ts=2 sw=2 sts=2 cin: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef InterceptedChannel_h |
8 | | #define InterceptedChannel_h |
9 | | |
10 | | #include "nsINetworkInterceptController.h" |
11 | | #include "mozilla/RefPtr.h" |
12 | | #include "mozilla/Maybe.h" |
13 | | |
14 | | class nsICacheEntry; |
15 | | class nsInputStreamPump; |
16 | | class nsIStreamListener; |
17 | | |
18 | | namespace mozilla { |
19 | | namespace net { |
20 | | |
21 | | class nsHttpChannel; |
22 | | class HttpChannelChild; |
23 | | class nsHttpResponseHead; |
24 | | class InterceptStreamListener; |
25 | | |
26 | | // An object representing a channel that has been intercepted. This avoids complicating |
27 | | // the actual channel implementation with the details of synthesizing responses. |
28 | | class InterceptedChannelBase : public nsIInterceptedChannel { |
29 | | protected: |
30 | | // The interception controller to notify about the successful channel interception |
31 | | nsCOMPtr<nsINetworkInterceptController> mController; |
32 | | |
33 | | // Response head for use when synthesizing |
34 | | Maybe<nsAutoPtr<nsHttpResponseHead>> mSynthesizedResponseHead; |
35 | | |
36 | | nsCOMPtr<nsIConsoleReportCollector> mReportCollector; |
37 | | nsCOMPtr<nsISupports> mReleaseHandle; |
38 | | |
39 | | bool mClosed; |
40 | | |
41 | | void EnsureSynthesizedResponse(); |
42 | | void DoNotifyController(); |
43 | | MOZ_MUST_USE nsresult DoSynthesizeStatus(uint16_t aStatus, |
44 | | const nsACString& aReason); |
45 | | MOZ_MUST_USE nsresult DoSynthesizeHeader(const nsACString& aName, |
46 | | const nsACString& aValue); |
47 | | |
48 | | TimeStamp mLaunchServiceWorkerStart; |
49 | | TimeStamp mLaunchServiceWorkerEnd; |
50 | | TimeStamp mDispatchFetchEventStart; |
51 | | TimeStamp mDispatchFetchEventEnd; |
52 | | TimeStamp mHandleFetchEventStart; |
53 | | TimeStamp mHandleFetchEventEnd; |
54 | | |
55 | | TimeStamp mFinishResponseStart; |
56 | | TimeStamp mFinishResponseEnd; |
57 | | enum { |
58 | | Invalid = 0, |
59 | | Synthesized, |
60 | | Reset |
61 | | } mSynthesizedOrReset; |
62 | | |
63 | 0 | virtual ~InterceptedChannelBase() = default; |
64 | | public: |
65 | | explicit InterceptedChannelBase(nsINetworkInterceptController* aController); |
66 | | |
67 | | // Notify the interception controller that the channel has been intercepted |
68 | | // and prepare the response body output stream. |
69 | | virtual void NotifyController() = 0; |
70 | | |
71 | | NS_DECL_ISUPPORTS |
72 | | |
73 | | NS_IMETHOD GetConsoleReportCollector(nsIConsoleReportCollector** aCollectorOut) override; |
74 | | NS_IMETHOD SetReleaseHandle(nsISupports* aHandle) override; |
75 | | |
76 | | NS_IMETHODIMP |
77 | | SetLaunchServiceWorkerStart(TimeStamp aTimeStamp) override |
78 | 0 | { |
79 | 0 | mLaunchServiceWorkerStart = aTimeStamp; |
80 | 0 | return NS_OK; |
81 | 0 | } |
82 | | |
83 | | NS_IMETHODIMP |
84 | | GetLaunchServiceWorkerStart(TimeStamp* aTimeStamp) override |
85 | 0 | { |
86 | 0 | MOZ_DIAGNOSTIC_ASSERT(aTimeStamp); |
87 | 0 | *aTimeStamp = mLaunchServiceWorkerStart; |
88 | 0 | return NS_OK; |
89 | 0 | } |
90 | | |
91 | | NS_IMETHODIMP |
92 | | SetLaunchServiceWorkerEnd(TimeStamp aTimeStamp) override |
93 | 0 | { |
94 | 0 | mLaunchServiceWorkerEnd = aTimeStamp; |
95 | 0 | return NS_OK; |
96 | 0 | } |
97 | | |
98 | | NS_IMETHODIMP |
99 | | GetLaunchServiceWorkerEnd(TimeStamp* aTimeStamp) override |
100 | 0 | { |
101 | 0 | MOZ_DIAGNOSTIC_ASSERT(aTimeStamp); |
102 | 0 | *aTimeStamp = mLaunchServiceWorkerEnd; |
103 | 0 | return NS_OK; |
104 | 0 | } |
105 | | |
106 | | NS_IMETHODIMP |
107 | | SetDispatchFetchEventStart(TimeStamp aTimeStamp) override |
108 | 0 | { |
109 | 0 | mDispatchFetchEventStart = aTimeStamp; |
110 | 0 | return NS_OK; |
111 | 0 | } |
112 | | |
113 | | NS_IMETHODIMP |
114 | | SetDispatchFetchEventEnd(TimeStamp aTimeStamp) override |
115 | 0 | { |
116 | 0 | mDispatchFetchEventEnd = aTimeStamp; |
117 | 0 | return NS_OK; |
118 | 0 | } |
119 | | |
120 | | NS_IMETHODIMP |
121 | | SetHandleFetchEventStart(TimeStamp aTimeStamp) override |
122 | 0 | { |
123 | 0 | mHandleFetchEventStart = aTimeStamp; |
124 | 0 | return NS_OK; |
125 | 0 | } |
126 | | |
127 | | NS_IMETHODIMP |
128 | | SetHandleFetchEventEnd(TimeStamp aTimeStamp) override |
129 | 0 | { |
130 | 0 | mHandleFetchEventEnd = aTimeStamp; |
131 | 0 | return NS_OK; |
132 | 0 | } |
133 | | |
134 | | NS_IMETHODIMP |
135 | | SetFinishResponseStart(TimeStamp aTimeStamp) override |
136 | 0 | { |
137 | 0 | mFinishResponseStart = aTimeStamp; |
138 | 0 | return NS_OK; |
139 | 0 | } |
140 | | |
141 | | NS_IMETHODIMP |
142 | | SetFinishSynthesizedResponseEnd(TimeStamp aTimeStamp) override |
143 | 0 | { |
144 | 0 | MOZ_ASSERT(mSynthesizedOrReset == Invalid); |
145 | 0 | mSynthesizedOrReset = Synthesized; |
146 | 0 | mFinishResponseEnd = aTimeStamp; |
147 | 0 | return NS_OK; |
148 | 0 | } |
149 | | |
150 | | NS_IMETHODIMP |
151 | | SetChannelResetEnd(TimeStamp aTimeStamp) override |
152 | 0 | { |
153 | 0 | MOZ_ASSERT(mSynthesizedOrReset == Invalid); |
154 | 0 | mSynthesizedOrReset = Reset; |
155 | 0 | mFinishResponseEnd = aTimeStamp; |
156 | 0 | return NS_OK; |
157 | 0 | } |
158 | | |
159 | | NS_IMETHODIMP SaveTimeStamps() override; |
160 | | |
161 | | static already_AddRefed<nsIURI> |
162 | | SecureUpgradeChannelURI(nsIChannel* aChannel); |
163 | | }; |
164 | | |
165 | | class InterceptedChannelContent : public InterceptedChannelBase |
166 | | { |
167 | | // The actual channel being intercepted. |
168 | | RefPtr<HttpChannelChild> mChannel; |
169 | | |
170 | | // Listener for the synthesized response to fix up the notifications before they reach |
171 | | // the actual channel. |
172 | | RefPtr<InterceptStreamListener> mStreamListener; |
173 | | |
174 | | // Set for intercepted channels that have gone through a secure upgrade. |
175 | | bool mSecureUpgrade; |
176 | | public: |
177 | | InterceptedChannelContent(HttpChannelChild* aChannel, |
178 | | nsINetworkInterceptController* aController, |
179 | | InterceptStreamListener* aListener, |
180 | | bool aSecureUpgrade); |
181 | | |
182 | | NS_IMETHOD ResetInterception() override; |
183 | | NS_IMETHOD StartSynthesizedResponse(nsIInputStream* aBody, |
184 | | nsIInterceptedBodyCallback* aBodyCallback, |
185 | | nsICacheInfoChannel* aChannel, |
186 | | const nsACString& aFinalURLSpec, |
187 | | bool aResponseRedirected) override; |
188 | | NS_IMETHOD FinishSynthesizedResponse() override; |
189 | | NS_IMETHOD GetChannel(nsIChannel** aChannel) override; |
190 | | NS_IMETHOD GetSecureUpgradedChannelURI(nsIURI** aURI) override; |
191 | | NS_IMETHOD SynthesizeStatus(uint16_t aStatus, const nsACString& aReason) override; |
192 | | NS_IMETHOD SynthesizeHeader(const nsACString& aName, const nsACString& aValue) override; |
193 | | NS_IMETHOD CancelInterception(nsresult aStatus) override; |
194 | | NS_IMETHOD SetChannelInfo(mozilla::dom::ChannelInfo* aChannelInfo) override; |
195 | | NS_IMETHOD GetInternalContentPolicyType(nsContentPolicyType *aInternalContentPolicyType) override; |
196 | | |
197 | | virtual void NotifyController() override; |
198 | | }; |
199 | | |
200 | | } // namespace net |
201 | | } // namespace mozilla |
202 | | |
203 | | #endif // InterceptedChannel_h |