/src/mozilla-central/netwerk/protocol/viewsource/nsViewSourceChannel.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* vim:set ts=4 sw=4 sts=4 et: */ |
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 | | #include "nsViewSourceChannel.h" |
8 | | #include "nsIIOService.h" |
9 | | #include "nsMimeTypes.h" |
10 | | #include "nsNetUtil.h" |
11 | | #include "nsContentUtils.h" |
12 | | #include "nsIHttpHeaderVisitor.h" |
13 | | #include "nsContentSecurityManager.h" |
14 | | #include "nsServiceManagerUtils.h" |
15 | | #include "nsIInputStreamChannel.h" |
16 | | #include "mozilla/DebugOnly.h" |
17 | | #include "mozilla/NullPrincipal.h" |
18 | | |
19 | | NS_IMPL_ADDREF(nsViewSourceChannel) |
20 | | NS_IMPL_RELEASE(nsViewSourceChannel) |
21 | | /* |
22 | | This QI uses NS_INTERFACE_MAP_ENTRY_CONDITIONAL to check for |
23 | | non-nullness of mHttpChannel, mCachingChannel, and mUploadChannel. |
24 | | */ |
25 | 0 | NS_INTERFACE_MAP_BEGIN(nsViewSourceChannel) |
26 | 0 | NS_INTERFACE_MAP_ENTRY(nsIViewSourceChannel) |
27 | 0 | NS_INTERFACE_MAP_ENTRY(nsIStreamListener) |
28 | 0 | NS_INTERFACE_MAP_ENTRY(nsIRequestObserver) |
29 | 0 | NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIHttpChannel, mHttpChannel) |
30 | 0 | NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIHttpChannelInternal, mHttpChannelInternal) |
31 | 0 | NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsICachingChannel, mCachingChannel) |
32 | 0 | NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsICacheInfoChannel, mCacheInfoChannel) |
33 | 0 | NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIApplicationCacheChannel, mApplicationCacheChannel) |
34 | 0 | NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIUploadChannel, mUploadChannel) |
35 | 0 | NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIFormPOSTActionChannel, mPostChannel) |
36 | 0 | NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIRequest, nsIViewSourceChannel) |
37 | 0 | NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIChannel, nsIViewSourceChannel) |
38 | 0 | NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIViewSourceChannel) |
39 | 0 | NS_INTERFACE_MAP_END |
40 | | |
41 | | nsresult |
42 | | nsViewSourceChannel::Init(nsIURI* uri) |
43 | 0 | { |
44 | 0 | mOriginalURI = uri; |
45 | 0 |
|
46 | 0 | nsAutoCString path; |
47 | 0 | nsresult rv = uri->GetPathQueryRef(path); |
48 | 0 | if (NS_FAILED(rv)) |
49 | 0 | return rv; |
50 | 0 | |
51 | 0 | nsCOMPtr<nsIIOService> pService(do_GetIOService(&rv)); |
52 | 0 | if (NS_FAILED(rv)) return rv; |
53 | 0 | |
54 | 0 | nsAutoCString scheme; |
55 | 0 | rv = pService->ExtractScheme(path, scheme); |
56 | 0 | if (NS_FAILED(rv)) |
57 | 0 | return rv; |
58 | 0 | |
59 | 0 | // prevent viewing source of javascript URIs (see bug 204779) |
60 | 0 | if (scheme.EqualsLiteral("javascript")) { |
61 | 0 | NS_WARNING("blocking view-source:javascript:"); |
62 | 0 | return NS_ERROR_INVALID_ARG; |
63 | 0 | } |
64 | 0 |
|
65 | 0 | // This function is called from within nsViewSourceHandler::NewChannel2 |
66 | 0 | // and sets the right loadInfo right after returning from this function. |
67 | 0 | // Until then we follow the principal of least privilege and use |
68 | 0 | // nullPrincipal as the loadingPrincipal and the least permissive |
69 | 0 | // securityflag. |
70 | 0 | nsCOMPtr<nsIPrincipal> nullPrincipal = |
71 | 0 | mozilla::NullPrincipal::CreateWithoutOriginAttributes(); |
72 | 0 |
|
73 | 0 | rv = pService->NewChannel2(path, |
74 | 0 | nullptr, // aOriginCharset |
75 | 0 | nullptr, // aCharSet |
76 | 0 | nullptr, // aLoadingNode |
77 | 0 | nullPrincipal, |
78 | 0 | nullptr, // aTriggeringPrincipal |
79 | 0 | nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_IS_BLOCKED, |
80 | 0 | nsIContentPolicy::TYPE_OTHER, |
81 | 0 | getter_AddRefs(mChannel)); |
82 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
83 | 0 |
|
84 | 0 | mIsSrcdocChannel = false; |
85 | 0 |
|
86 | 0 | mChannel->SetOriginalURI(mOriginalURI); |
87 | 0 | mHttpChannel = do_QueryInterface(mChannel); |
88 | 0 | mHttpChannelInternal = do_QueryInterface(mChannel); |
89 | 0 | mCachingChannel = do_QueryInterface(mChannel); |
90 | 0 | mCacheInfoChannel = do_QueryInterface(mChannel); |
91 | 0 | mApplicationCacheChannel = do_QueryInterface(mChannel); |
92 | 0 | mUploadChannel = do_QueryInterface(mChannel); |
93 | 0 | mPostChannel = do_QueryInterface(mChannel); |
94 | 0 |
|
95 | 0 | return NS_OK; |
96 | 0 | } |
97 | | |
98 | | nsresult |
99 | | nsViewSourceChannel::InitSrcdoc(nsIURI* aURI, |
100 | | nsIURI* aBaseURI, |
101 | | const nsAString &aSrcdoc, |
102 | | nsILoadInfo* aLoadInfo) |
103 | 0 | { |
104 | 0 | nsresult rv; |
105 | 0 |
|
106 | 0 | nsCOMPtr<nsIURI> inStreamURI; |
107 | 0 | // Need to strip view-source: from the URI. Hardcoded to |
108 | 0 | // about:srcdoc as this is the only permissible URI for srcdoc |
109 | 0 | // loads |
110 | 0 | rv = NS_NewURI(getter_AddRefs(inStreamURI), |
111 | 0 | NS_LITERAL_STRING("about:srcdoc")); |
112 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
113 | 0 |
|
114 | 0 | rv = NS_NewInputStreamChannelInternal(getter_AddRefs(mChannel), |
115 | 0 | inStreamURI, |
116 | 0 | aSrcdoc, |
117 | 0 | NS_LITERAL_CSTRING("text/html"), |
118 | 0 | aLoadInfo, |
119 | 0 | true); |
120 | 0 |
|
121 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
122 | 0 | mOriginalURI = aURI; |
123 | 0 | mIsSrcdocChannel = true; |
124 | 0 |
|
125 | 0 | mChannel->SetOriginalURI(mOriginalURI); |
126 | 0 | mHttpChannel = do_QueryInterface(mChannel); |
127 | 0 | mHttpChannelInternal = do_QueryInterface(mChannel); |
128 | 0 | mCachingChannel = do_QueryInterface(mChannel); |
129 | 0 | mCacheInfoChannel = do_QueryInterface(mChannel); |
130 | 0 | mApplicationCacheChannel = do_QueryInterface(mChannel); |
131 | 0 | mUploadChannel = do_QueryInterface(mChannel); |
132 | 0 |
|
133 | 0 | rv = UpdateLoadInfoResultPrincipalURI(); |
134 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
135 | 0 |
|
136 | 0 | nsCOMPtr<nsIInputStreamChannel> isc = do_QueryInterface(mChannel); |
137 | 0 | MOZ_ASSERT(isc); |
138 | 0 | isc->SetBaseURI(aBaseURI); |
139 | 0 | return NS_OK; |
140 | 0 | } |
141 | | |
142 | | nsresult |
143 | | nsViewSourceChannel::UpdateLoadInfoResultPrincipalURI() |
144 | 0 | { |
145 | 0 | nsresult rv; |
146 | 0 |
|
147 | 0 | MOZ_ASSERT(mChannel); |
148 | 0 |
|
149 | 0 | nsCOMPtr<nsILoadInfo> channelLoadInfo = mChannel->GetLoadInfo(); |
150 | 0 | if (!channelLoadInfo) { |
151 | 0 | return NS_OK; |
152 | 0 | } |
153 | 0 | |
154 | 0 | nsCOMPtr<nsIURI> channelResultPrincipalURI; |
155 | 0 | rv = channelLoadInfo->GetResultPrincipalURI(getter_AddRefs(channelResultPrincipalURI)); |
156 | 0 | if (NS_FAILED(rv)) { |
157 | 0 | return rv; |
158 | 0 | } |
159 | 0 | |
160 | 0 | if (!channelResultPrincipalURI) { |
161 | 0 | mChannel->GetOriginalURI(getter_AddRefs(channelResultPrincipalURI)); |
162 | 0 | return NS_OK; |
163 | 0 | } |
164 | 0 | |
165 | 0 | if (!channelResultPrincipalURI) { |
166 | 0 | return NS_ERROR_UNEXPECTED; |
167 | 0 | } |
168 | 0 | |
169 | 0 | bool alreadyViewSource; |
170 | 0 | if (NS_SUCCEEDED(channelResultPrincipalURI->SchemeIs("view-source", &alreadyViewSource)) && |
171 | 0 | alreadyViewSource) { |
172 | 0 | return NS_OK; |
173 | 0 | } |
174 | 0 | |
175 | 0 | nsCOMPtr<nsIURI> updatedResultPrincipalURI; |
176 | 0 | rv = BuildViewSourceURI(channelResultPrincipalURI, |
177 | 0 | getter_AddRefs(updatedResultPrincipalURI)); |
178 | 0 | if (NS_FAILED(rv)) { |
179 | 0 | return rv; |
180 | 0 | } |
181 | 0 | |
182 | 0 | rv = channelLoadInfo->SetResultPrincipalURI(updatedResultPrincipalURI); |
183 | 0 | if (NS_FAILED(rv)) { |
184 | 0 | return rv; |
185 | 0 | } |
186 | 0 | |
187 | 0 | return NS_OK; |
188 | 0 | } |
189 | | |
190 | | nsresult |
191 | | nsViewSourceChannel::BuildViewSourceURI(nsIURI * aURI, nsIURI ** aResult) |
192 | 0 | { |
193 | 0 | nsresult rv; |
194 | 0 |
|
195 | 0 | // protect ourselves against broken channel implementations |
196 | 0 | if (!aURI) { |
197 | 0 | NS_ERROR("no URI to build view-source uri!"); |
198 | 0 | return NS_ERROR_UNEXPECTED; |
199 | 0 | } |
200 | 0 |
|
201 | 0 | nsAutoCString spec; |
202 | 0 | rv = aURI->GetSpec(spec); |
203 | 0 | if (NS_FAILED(rv)) { |
204 | 0 | return rv; |
205 | 0 | } |
206 | 0 | |
207 | 0 | return NS_NewURI(aResult, NS_LITERAL_CSTRING("view-source:") + spec); |
208 | 0 | } |
209 | | |
210 | | //////////////////////////////////////////////////////////////////////////////// |
211 | | // nsIRequest methods: |
212 | | |
213 | | NS_IMETHODIMP |
214 | | nsViewSourceChannel::GetName(nsACString &result) |
215 | 0 | { |
216 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
217 | 0 | } |
218 | | |
219 | | NS_IMETHODIMP |
220 | | nsViewSourceChannel::GetTransferSize(uint64_t *aTransferSize) |
221 | 0 | { |
222 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
223 | 0 | } |
224 | | |
225 | | NS_IMETHODIMP |
226 | | nsViewSourceChannel::GetDecodedBodySize(uint64_t *aDecodedBodySize) |
227 | 0 | { |
228 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
229 | 0 | } |
230 | | |
231 | | NS_IMETHODIMP |
232 | | nsViewSourceChannel::GetEncodedBodySize(uint64_t *aEncodedBodySize) |
233 | 0 | { |
234 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
235 | 0 | } |
236 | | |
237 | | NS_IMETHODIMP |
238 | | nsViewSourceChannel::IsPending(bool *result) |
239 | 0 | { |
240 | 0 | NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); |
241 | 0 |
|
242 | 0 | return mChannel->IsPending(result); |
243 | 0 | } |
244 | | |
245 | | NS_IMETHODIMP |
246 | | nsViewSourceChannel::GetStatus(nsresult *status) |
247 | 0 | { |
248 | 0 | NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); |
249 | 0 |
|
250 | 0 | return mChannel->GetStatus(status); |
251 | 0 | } |
252 | | |
253 | | NS_IMETHODIMP |
254 | | nsViewSourceChannel::Cancel(nsresult status) |
255 | 0 | { |
256 | 0 | NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); |
257 | 0 |
|
258 | 0 | return mChannel->Cancel(status); |
259 | 0 | } |
260 | | |
261 | | NS_IMETHODIMP |
262 | | nsViewSourceChannel::Suspend(void) |
263 | 0 | { |
264 | 0 | NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); |
265 | 0 |
|
266 | 0 | return mChannel->Suspend(); |
267 | 0 | } |
268 | | |
269 | | NS_IMETHODIMP |
270 | | nsViewSourceChannel::Resume(void) |
271 | 0 | { |
272 | 0 | NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); |
273 | 0 |
|
274 | 0 | return mChannel->Resume(); |
275 | 0 | } |
276 | | |
277 | | //////////////////////////////////////////////////////////////////////////////// |
278 | | // nsIChannel methods: |
279 | | |
280 | | NS_IMETHODIMP |
281 | | nsViewSourceChannel::GetOriginalURI(nsIURI* *aURI) |
282 | 0 | { |
283 | 0 | NS_ASSERTION(aURI, "Null out param!"); |
284 | 0 | *aURI = mOriginalURI; |
285 | 0 | NS_ADDREF(*aURI); |
286 | 0 | return NS_OK; |
287 | 0 | } |
288 | | |
289 | | NS_IMETHODIMP |
290 | | nsViewSourceChannel::SetOriginalURI(nsIURI* aURI) |
291 | 0 | { |
292 | 0 | NS_ENSURE_ARG_POINTER(aURI); |
293 | 0 | mOriginalURI = aURI; |
294 | 0 | return NS_OK; |
295 | 0 | } |
296 | | |
297 | | NS_IMETHODIMP |
298 | | nsViewSourceChannel::GetURI(nsIURI* *aURI) |
299 | 0 | { |
300 | 0 | NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); |
301 | 0 |
|
302 | 0 | nsCOMPtr<nsIURI> uri; |
303 | 0 | nsresult rv = mChannel->GetURI(getter_AddRefs(uri)); |
304 | 0 | if (NS_FAILED(rv)) { |
305 | 0 | return rv; |
306 | 0 | } |
307 | 0 | |
308 | 0 | return BuildViewSourceURI(uri, aURI); |
309 | 0 | } |
310 | | |
311 | | NS_IMETHODIMP |
312 | | nsViewSourceChannel::Open(nsIInputStream **_retval) |
313 | 0 | { |
314 | 0 | NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); |
315 | 0 |
|
316 | 0 | nsresult rv = NS_MaybeOpenChannelUsingOpen2(mChannel, _retval); |
317 | 0 | if (NS_SUCCEEDED(rv)) { |
318 | 0 | mOpened = true; |
319 | 0 | } |
320 | 0 | return rv; |
321 | 0 | } |
322 | | |
323 | | NS_IMETHODIMP |
324 | | nsViewSourceChannel::Open2(nsIInputStream** aStream) |
325 | 0 | { |
326 | 0 | NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); |
327 | 0 | nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo(); |
328 | 0 | if(!loadInfo) { |
329 | 0 | MOZ_ASSERT(loadInfo, "can not enforce security without loadInfo"); |
330 | 0 | return NS_ERROR_UNEXPECTED; |
331 | 0 | } |
332 | 0 | // setting the flag on the loadInfo indicates that the underlying |
333 | 0 | // channel will be openend using Open2() and hence performs |
334 | 0 | // the necessary security checks. |
335 | 0 | loadInfo->SetEnforceSecurity(true); |
336 | 0 | return Open(aStream); |
337 | 0 | } |
338 | | |
339 | | NS_IMETHODIMP |
340 | | nsViewSourceChannel::AsyncOpen(nsIStreamListener *aListener, nsISupports *ctxt) |
341 | 0 | { |
342 | | #ifdef DEBUG |
343 | | { |
344 | | nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo(); |
345 | | MOZ_ASSERT(!loadInfo || loadInfo->GetSecurityMode() == 0 || |
346 | | loadInfo->GetEnforceSecurity(), |
347 | | "security flags in loadInfo but asyncOpen2() not called"); |
348 | | } |
349 | | #endif |
350 | |
|
351 | 0 | NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); |
352 | 0 |
|
353 | 0 | mListener = aListener; |
354 | 0 |
|
355 | 0 | /* |
356 | 0 | * We want to add ourselves to the loadgroup before opening |
357 | 0 | * mChannel, since we want to make sure we're in the loadgroup |
358 | 0 | * when mChannel finishes and fires OnStopRequest() |
359 | 0 | */ |
360 | 0 |
|
361 | 0 | nsCOMPtr<nsILoadGroup> loadGroup; |
362 | 0 | mChannel->GetLoadGroup(getter_AddRefs(loadGroup)); |
363 | 0 | if (loadGroup) |
364 | 0 | loadGroup->AddRequest(static_cast<nsIViewSourceChannel*> |
365 | 0 | (this), nullptr); |
366 | 0 |
|
367 | 0 | nsresult rv = NS_OK; |
368 | 0 | nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo(); |
369 | 0 | if (loadInfo && loadInfo->GetEnforceSecurity()) { |
370 | 0 | rv = mChannel->AsyncOpen2(this); |
371 | 0 | } |
372 | 0 | else { |
373 | 0 | rv = mChannel->AsyncOpen(this, ctxt); |
374 | 0 | } |
375 | 0 |
|
376 | 0 | if (NS_FAILED(rv) && loadGroup) |
377 | 0 | loadGroup->RemoveRequest(static_cast<nsIViewSourceChannel*> |
378 | 0 | (this), |
379 | 0 | nullptr, rv); |
380 | 0 |
|
381 | 0 | if (NS_SUCCEEDED(rv)) { |
382 | 0 | mOpened = true; |
383 | 0 | } |
384 | 0 |
|
385 | 0 | return rv; |
386 | 0 | } |
387 | | |
388 | | NS_IMETHODIMP |
389 | | nsViewSourceChannel::AsyncOpen2(nsIStreamListener *aListener) |
390 | 0 | { |
391 | 0 | nsCOMPtr<nsILoadInfo> loadInfo = mChannel->GetLoadInfo(); |
392 | 0 | if(!loadInfo) { |
393 | 0 | MOZ_ASSERT(loadInfo, "can not enforce security without loadInfo"); |
394 | 0 | return NS_ERROR_UNEXPECTED; |
395 | 0 | } |
396 | 0 | // setting the flag on the loadInfo indicates that the underlying |
397 | 0 | // channel will be openend using AsyncOpen2() and hence performs |
398 | 0 | // the necessary security checks. |
399 | 0 | loadInfo->SetEnforceSecurity(true); |
400 | 0 | return AsyncOpen(aListener, nullptr); |
401 | 0 | } |
402 | | /* |
403 | | * Both the view source channel and mChannel are added to the |
404 | | * loadgroup. There should never be more than one request in the |
405 | | * loadgroup that has LOAD_DOCUMENT_URI set. The one that has this |
406 | | * flag set is the request whose URI is used to refetch the document, |
407 | | * so it better be the viewsource channel. |
408 | | * |
409 | | * Therefore, we need to make sure that |
410 | | * 1) The load flags on mChannel _never_ include LOAD_DOCUMENT_URI |
411 | | * 2) The load flags on |this| include LOAD_DOCUMENT_URI when it was |
412 | | * set via SetLoadFlags (mIsDocument keeps track of this flag). |
413 | | */ |
414 | | |
415 | | NS_IMETHODIMP |
416 | | nsViewSourceChannel::GetLoadFlags(uint32_t *aLoadFlags) |
417 | 0 | { |
418 | 0 | NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); |
419 | 0 |
|
420 | 0 | nsresult rv = mChannel->GetLoadFlags(aLoadFlags); |
421 | 0 | if (NS_FAILED(rv)) |
422 | 0 | return rv; |
423 | 0 | |
424 | 0 | // This should actually be just LOAD_DOCUMENT_URI but the win32 compiler |
425 | 0 | // fails to deal due to amiguous inheritance. nsIChannel::LOAD_DOCUMENT_URI |
426 | 0 | // also fails; the Win32 compiler thinks that's supposed to be a method. |
427 | 0 | if (mIsDocument) |
428 | 0 | *aLoadFlags |= ::nsIChannel::LOAD_DOCUMENT_URI; |
429 | 0 |
|
430 | 0 | return rv; |
431 | 0 | } |
432 | | |
433 | | NS_IMETHODIMP |
434 | | nsViewSourceChannel::SetLoadFlags(uint32_t aLoadFlags) |
435 | 0 | { |
436 | 0 | NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); |
437 | 0 |
|
438 | 0 | // "View source" always wants the currently cached content. |
439 | 0 | // We also want to have _this_ channel, not mChannel to be the |
440 | 0 | // 'document' channel in the loadgroup. |
441 | 0 |
|
442 | 0 | // These should actually be just LOAD_FROM_CACHE and LOAD_DOCUMENT_URI but |
443 | 0 | // the win32 compiler fails to deal due to amiguous inheritance. |
444 | 0 | // nsIChannel::LOAD_DOCUMENT_URI/nsIRequest::LOAD_FROM_CACHE also fails; the |
445 | 0 | // Win32 compiler thinks that's supposed to be a method. |
446 | 0 | mIsDocument = (aLoadFlags & ::nsIChannel::LOAD_DOCUMENT_URI) ? true : false; |
447 | 0 |
|
448 | 0 | nsresult rv = mChannel->SetLoadFlags((aLoadFlags | |
449 | 0 | ::nsIRequest::LOAD_FROM_CACHE) & |
450 | 0 | ~::nsIChannel::LOAD_DOCUMENT_URI); |
451 | 0 | if (NS_WARN_IF(NS_FAILED(rv))) { |
452 | 0 | return rv; |
453 | 0 | } |
454 | 0 | |
455 | 0 | if (mHttpChannel) { |
456 | 0 | rv = mHttpChannel->SetIsMainDocumentChannel(aLoadFlags & ::nsIChannel::LOAD_DOCUMENT_URI); |
457 | 0 | MOZ_ASSERT(NS_SUCCEEDED(rv)); |
458 | 0 | } |
459 | 0 |
|
460 | 0 | return NS_OK; |
461 | 0 | } |
462 | | |
463 | | NS_IMETHODIMP |
464 | | nsViewSourceChannel::GetContentType(nsACString &aContentType) |
465 | 0 | { |
466 | 0 | NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); |
467 | 0 |
|
468 | 0 | aContentType.Truncate(); |
469 | 0 |
|
470 | 0 | if (mContentType.IsEmpty()) |
471 | 0 | { |
472 | 0 | // Get the current content type |
473 | 0 | nsresult rv; |
474 | 0 | nsAutoCString contentType; |
475 | 0 | rv = mChannel->GetContentType(contentType); |
476 | 0 | if (NS_FAILED(rv)) return rv; |
477 | 0 | |
478 | 0 | // If we don't know our type, just say so. The unknown |
479 | 0 | // content decoder will then kick in automatically, and it |
480 | 0 | // will call our SetOriginalContentType method instead of our |
481 | 0 | // SetContentType method to set the type it determines. |
482 | 0 | if (!contentType.EqualsLiteral(UNKNOWN_CONTENT_TYPE)) { |
483 | 0 | contentType = VIEWSOURCE_CONTENT_TYPE; |
484 | 0 | } |
485 | 0 |
|
486 | 0 | mContentType = contentType; |
487 | 0 | } |
488 | 0 |
|
489 | 0 | aContentType = mContentType; |
490 | 0 | return NS_OK; |
491 | 0 | } |
492 | | |
493 | | NS_IMETHODIMP |
494 | | nsViewSourceChannel::SetContentType(const nsACString &aContentType) |
495 | 0 | { |
496 | 0 | // Our GetContentType() currently returns VIEWSOURCE_CONTENT_TYPE |
497 | 0 | // |
498 | 0 | // However, during the parsing phase the parser calls our |
499 | 0 | // channel's GetContentType(). Returning the string above trips up |
500 | 0 | // the parser. In order to avoid messy changes and not to have the |
501 | 0 | // parser depend on nsIViewSourceChannel Vidur proposed the |
502 | 0 | // following solution: |
503 | 0 | // |
504 | 0 | // The ViewSourceChannel initially returns a content type of |
505 | 0 | // VIEWSOURCE_CONTENT_TYPE. Based on this type decisions to |
506 | 0 | // create a viewer for doing a view source are made. After the |
507 | 0 | // viewer is created, nsLayoutDLF::CreateInstance() calls this |
508 | 0 | // SetContentType() with the original content type. When it's |
509 | 0 | // time for the parser to find out the content type it will call |
510 | 0 | // our channel's GetContentType() and it will get the original |
511 | 0 | // content type, such as, text/html and everything is kosher from |
512 | 0 | // then on. |
513 | 0 |
|
514 | 0 | if (!mOpened) { |
515 | 0 | // We do not take hints |
516 | 0 | return NS_ERROR_NOT_AVAILABLE; |
517 | 0 | } |
518 | 0 | |
519 | 0 | mContentType = aContentType; |
520 | 0 | return NS_OK; |
521 | 0 | } |
522 | | |
523 | | NS_IMETHODIMP |
524 | | nsViewSourceChannel::GetContentCharset(nsACString &aContentCharset) |
525 | 0 | { |
526 | 0 | NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); |
527 | 0 |
|
528 | 0 | return mChannel->GetContentCharset(aContentCharset); |
529 | 0 | } |
530 | | |
531 | | NS_IMETHODIMP |
532 | | nsViewSourceChannel::SetContentCharset(const nsACString &aContentCharset) |
533 | 0 | { |
534 | 0 | NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); |
535 | 0 |
|
536 | 0 | return mChannel->SetContentCharset(aContentCharset); |
537 | 0 | } |
538 | | |
539 | | // We don't forward these methods becacuse content-disposition isn't whitelisted |
540 | | // (see GetResponseHeader/VisitResponseHeaders). |
541 | | NS_IMETHODIMP |
542 | | nsViewSourceChannel::GetContentDisposition(uint32_t *aContentDisposition) |
543 | 0 | { |
544 | 0 | return NS_ERROR_NOT_AVAILABLE; |
545 | 0 | } |
546 | | |
547 | | NS_IMETHODIMP |
548 | | nsViewSourceChannel::SetContentDisposition(uint32_t aContentDisposition) |
549 | 0 | { |
550 | 0 | return NS_ERROR_NOT_AVAILABLE; |
551 | 0 | } |
552 | | |
553 | | NS_IMETHODIMP |
554 | | nsViewSourceChannel::GetContentDispositionFilename(nsAString &aContentDispositionFilename) |
555 | 0 | { |
556 | 0 | return NS_ERROR_NOT_AVAILABLE; |
557 | 0 | } |
558 | | |
559 | | NS_IMETHODIMP |
560 | | nsViewSourceChannel::SetContentDispositionFilename(const nsAString &aContentDispositionFilename) |
561 | 0 | { |
562 | 0 | return NS_ERROR_NOT_AVAILABLE; |
563 | 0 | } |
564 | | |
565 | | NS_IMETHODIMP |
566 | | nsViewSourceChannel::GetContentDispositionHeader(nsACString &aContentDispositionHeader) |
567 | 0 | { |
568 | 0 | return NS_ERROR_NOT_AVAILABLE; |
569 | 0 | } |
570 | | |
571 | | NS_IMETHODIMP |
572 | | nsViewSourceChannel::GetContentLength(int64_t *aContentLength) |
573 | 0 | { |
574 | 0 | NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); |
575 | 0 |
|
576 | 0 | return mChannel->GetContentLength(aContentLength); |
577 | 0 | } |
578 | | |
579 | | NS_IMETHODIMP |
580 | | nsViewSourceChannel::SetContentLength(int64_t aContentLength) |
581 | 0 | { |
582 | 0 | NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); |
583 | 0 |
|
584 | 0 | return mChannel->SetContentLength(aContentLength); |
585 | 0 | } |
586 | | |
587 | | NS_IMETHODIMP |
588 | | nsViewSourceChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup) |
589 | 0 | { |
590 | 0 | NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); |
591 | 0 |
|
592 | 0 | return mChannel->GetLoadGroup(aLoadGroup); |
593 | 0 | } |
594 | | |
595 | | NS_IMETHODIMP |
596 | | nsViewSourceChannel::SetLoadGroup(nsILoadGroup* aLoadGroup) |
597 | 0 | { |
598 | 0 | NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); |
599 | 0 |
|
600 | 0 | return mChannel->SetLoadGroup(aLoadGroup); |
601 | 0 | } |
602 | | |
603 | | NS_IMETHODIMP |
604 | | nsViewSourceChannel::GetOwner(nsISupports* *aOwner) |
605 | 0 | { |
606 | 0 | NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); |
607 | 0 |
|
608 | 0 | return mChannel->GetOwner(aOwner); |
609 | 0 | } |
610 | | |
611 | | NS_IMETHODIMP |
612 | | nsViewSourceChannel::SetOwner(nsISupports* aOwner) |
613 | 0 | { |
614 | 0 | NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); |
615 | 0 |
|
616 | 0 | return mChannel->SetOwner(aOwner); |
617 | 0 | } |
618 | | |
619 | | NS_IMETHODIMP |
620 | | nsViewSourceChannel::GetLoadInfo(nsILoadInfo* *aLoadInfo) |
621 | 0 | { |
622 | 0 | NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); |
623 | 0 |
|
624 | 0 | return mChannel->GetLoadInfo(aLoadInfo); |
625 | 0 | } |
626 | | |
627 | | NS_IMETHODIMP |
628 | | nsViewSourceChannel::SetLoadInfo(nsILoadInfo* aLoadInfo) |
629 | 0 | { |
630 | 0 | NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); |
631 | 0 |
|
632 | 0 | return mChannel->SetLoadInfo(aLoadInfo); |
633 | 0 | } |
634 | | |
635 | | NS_IMETHODIMP |
636 | | nsViewSourceChannel::GetIsDocument(bool *aIsDocument) |
637 | 0 | { |
638 | 0 | NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); |
639 | 0 |
|
640 | 0 | return mChannel->GetIsDocument(aIsDocument); |
641 | 0 | } |
642 | | |
643 | | NS_IMETHODIMP |
644 | | nsViewSourceChannel::GetNotificationCallbacks(nsIInterfaceRequestor* *aNotificationCallbacks) |
645 | 0 | { |
646 | 0 | NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); |
647 | 0 |
|
648 | 0 | return mChannel->GetNotificationCallbacks(aNotificationCallbacks); |
649 | 0 | } |
650 | | |
651 | | NS_IMETHODIMP |
652 | | nsViewSourceChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCallbacks) |
653 | 0 | { |
654 | 0 | NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); |
655 | 0 |
|
656 | 0 | return mChannel->SetNotificationCallbacks(aNotificationCallbacks); |
657 | 0 | } |
658 | | |
659 | | NS_IMETHODIMP |
660 | | nsViewSourceChannel::GetSecurityInfo(nsISupports * *aSecurityInfo) |
661 | 0 | { |
662 | 0 | NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); |
663 | 0 |
|
664 | 0 | return mChannel->GetSecurityInfo(aSecurityInfo); |
665 | 0 | } |
666 | | |
667 | | // nsIViewSourceChannel methods |
668 | | NS_IMETHODIMP |
669 | | nsViewSourceChannel::GetOriginalContentType(nsACString &aContentType) |
670 | 0 | { |
671 | 0 | NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); |
672 | 0 |
|
673 | 0 | return mChannel->GetContentType(aContentType); |
674 | 0 | } |
675 | | |
676 | | NS_IMETHODIMP |
677 | | nsViewSourceChannel::SetOriginalContentType(const nsACString &aContentType) |
678 | 0 | { |
679 | 0 | NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); |
680 | 0 |
|
681 | 0 | // clear our cached content-type value |
682 | 0 | mContentType.Truncate(); |
683 | 0 |
|
684 | 0 | return mChannel->SetContentType(aContentType); |
685 | 0 | } |
686 | | |
687 | | NS_IMETHODIMP |
688 | | nsViewSourceChannel::GetIsSrcdocChannel(bool* aIsSrcdocChannel) |
689 | 0 | { |
690 | 0 | *aIsSrcdocChannel = mIsSrcdocChannel; |
691 | 0 | return NS_OK; |
692 | 0 | } |
693 | | |
694 | | NS_IMETHODIMP |
695 | | nsViewSourceChannel::GetBaseURI(nsIURI** aBaseURI) |
696 | 0 | { |
697 | 0 | if (mIsSrcdocChannel) { |
698 | 0 | nsCOMPtr<nsIInputStreamChannel> isc = do_QueryInterface(mChannel); |
699 | 0 | if (isc) { |
700 | 0 | return isc->GetBaseURI(aBaseURI); |
701 | 0 | } |
702 | 0 | } |
703 | 0 | *aBaseURI = mBaseURI; |
704 | 0 | NS_IF_ADDREF(*aBaseURI); |
705 | 0 | return NS_OK; |
706 | 0 | } |
707 | | |
708 | | NS_IMETHODIMP |
709 | | nsViewSourceChannel::SetBaseURI(nsIURI* aBaseURI) |
710 | 0 | { |
711 | 0 | mBaseURI = aBaseURI; |
712 | 0 | return NS_OK; |
713 | 0 | } |
714 | | |
715 | | NS_IMETHODIMP |
716 | | nsViewSourceChannel::GetProtocolVersion(nsACString& aProtocolVersion) |
717 | 0 | { |
718 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
719 | 0 | } |
720 | | |
721 | | // nsIRequestObserver methods |
722 | | NS_IMETHODIMP |
723 | | nsViewSourceChannel::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext) |
724 | 0 | { |
725 | 0 | NS_ENSURE_TRUE(mListener, NS_ERROR_FAILURE); |
726 | 0 | // The channel may have gotten redirected... Time to update our info |
727 | 0 | mChannel = do_QueryInterface(aRequest); |
728 | 0 | mHttpChannel = do_QueryInterface(aRequest); |
729 | 0 | mCachingChannel = do_QueryInterface(aRequest); |
730 | 0 | mCacheInfoChannel = do_QueryInterface(mChannel); |
731 | 0 | mUploadChannel = do_QueryInterface(aRequest); |
732 | 0 |
|
733 | 0 | nsresult rv = UpdateLoadInfoResultPrincipalURI(); |
734 | 0 | if (NS_FAILED(rv)) { |
735 | 0 | Cancel(rv); |
736 | 0 | } |
737 | 0 |
|
738 | 0 | return mListener->OnStartRequest(static_cast<nsIViewSourceChannel*> |
739 | 0 | (this), |
740 | 0 | aContext); |
741 | 0 | } |
742 | | |
743 | | |
744 | | NS_IMETHODIMP |
745 | | nsViewSourceChannel::OnStopRequest(nsIRequest *aRequest, nsISupports* aContext, |
746 | | nsresult aStatus) |
747 | 0 | { |
748 | 0 | NS_ENSURE_TRUE(mListener, NS_ERROR_FAILURE); |
749 | 0 | if (mChannel) |
750 | 0 | { |
751 | 0 | nsCOMPtr<nsILoadGroup> loadGroup; |
752 | 0 | mChannel->GetLoadGroup(getter_AddRefs(loadGroup)); |
753 | 0 | if (loadGroup) |
754 | 0 | { |
755 | 0 | loadGroup->RemoveRequest(static_cast<nsIViewSourceChannel*> |
756 | 0 | (this), |
757 | 0 | nullptr, aStatus); |
758 | 0 | } |
759 | 0 | } |
760 | 0 | return mListener->OnStopRequest(static_cast<nsIViewSourceChannel*> |
761 | 0 | (this), |
762 | 0 | aContext, aStatus); |
763 | 0 | } |
764 | | |
765 | | |
766 | | // nsIStreamListener methods |
767 | | NS_IMETHODIMP |
768 | | nsViewSourceChannel::OnDataAvailable(nsIRequest *aRequest, nsISupports* aContext, |
769 | | nsIInputStream *aInputStream, |
770 | | uint64_t aSourceOffset, |
771 | | uint32_t aLength) |
772 | 0 | { |
773 | 0 | NS_ENSURE_TRUE(mListener, NS_ERROR_FAILURE); |
774 | 0 | return mListener->OnDataAvailable(static_cast<nsIViewSourceChannel*> |
775 | 0 | (this), |
776 | 0 | aContext, aInputStream, |
777 | 0 | aSourceOffset, aLength); |
778 | 0 | } |
779 | | |
780 | | |
781 | | // nsIHttpChannel methods |
782 | | |
783 | | // We want to forward most of nsIHttpChannel over to mHttpChannel, but we want |
784 | | // to override GetRequestHeader and VisitHeaders. The reason is that we don't |
785 | | // want various headers like Link: and Refresh: applying to view-source. |
786 | | NS_IMETHODIMP |
787 | | nsViewSourceChannel::GetChannelId(uint64_t *aChannelId) |
788 | 0 | { |
789 | 0 | NS_ENSURE_ARG_POINTER(aChannelId); |
790 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
791 | 0 | mHttpChannel->GetChannelId(aChannelId); |
792 | 0 | } |
793 | | |
794 | | NS_IMETHODIMP |
795 | | nsViewSourceChannel::SetChannelId(uint64_t aChannelId) |
796 | 0 | { |
797 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
798 | 0 | mHttpChannel->SetChannelId(aChannelId); |
799 | 0 | } |
800 | | |
801 | | NS_IMETHODIMP |
802 | | nsViewSourceChannel::GetTopLevelContentWindowId(uint64_t *aWindowId) |
803 | 0 | { |
804 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
805 | 0 | mHttpChannel->GetTopLevelContentWindowId(aWindowId); |
806 | 0 | } |
807 | | |
808 | | NS_IMETHODIMP |
809 | | nsViewSourceChannel::SetTopLevelContentWindowId(uint64_t aWindowId) |
810 | 0 | { |
811 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
812 | 0 | mHttpChannel->SetTopLevelContentWindowId(aWindowId); |
813 | 0 | } |
814 | | |
815 | | NS_IMETHODIMP |
816 | | nsViewSourceChannel::GetTopLevelOuterContentWindowId(uint64_t *aWindowId) |
817 | 0 | { |
818 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
819 | 0 | mHttpChannel->GetTopLevelOuterContentWindowId(aWindowId); |
820 | 0 | } |
821 | | |
822 | | NS_IMETHODIMP |
823 | | nsViewSourceChannel::SetTopLevelOuterContentWindowId(uint64_t aWindowId) |
824 | 0 | { |
825 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
826 | 0 | mHttpChannel->SetTopLevelOuterContentWindowId(aWindowId); |
827 | 0 | } |
828 | | |
829 | | NS_IMETHODIMP |
830 | | nsViewSourceChannel::GetIsTrackingResource(bool* aIsTrackingResource) |
831 | 0 | { |
832 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
833 | 0 | mHttpChannel->GetIsTrackingResource(aIsTrackingResource); |
834 | 0 | } |
835 | | |
836 | | NS_IMETHODIMP |
837 | | nsViewSourceChannel::GetIsThirdPartyTrackingResource(bool* aIsTrackingResource) |
838 | 0 | { |
839 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
840 | 0 | mHttpChannel->GetIsThirdPartyTrackingResource(aIsTrackingResource); |
841 | 0 | } |
842 | | |
843 | | NS_IMETHODIMP |
844 | | nsViewSourceChannel::OverrideTrackingFlagsForDocumentCookieAccessor(nsIHttpChannel* aDocumentChannel) |
845 | 0 | { |
846 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
847 | 0 | mHttpChannel->OverrideTrackingFlagsForDocumentCookieAccessor(aDocumentChannel); |
848 | 0 | } |
849 | | |
850 | | NS_IMETHODIMP |
851 | | nsViewSourceChannel::GetRequestMethod(nsACString & aRequestMethod) |
852 | 0 | { |
853 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
854 | 0 | mHttpChannel->GetRequestMethod(aRequestMethod); |
855 | 0 | } |
856 | | |
857 | | NS_IMETHODIMP |
858 | | nsViewSourceChannel::SetRequestMethod(const nsACString & aRequestMethod) |
859 | 0 | { |
860 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
861 | 0 | mHttpChannel->SetRequestMethod(aRequestMethod); |
862 | 0 | } |
863 | | |
864 | | NS_IMETHODIMP |
865 | | nsViewSourceChannel::GetReferrer(nsIURI * *aReferrer) |
866 | 0 | { |
867 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
868 | 0 | mHttpChannel->GetReferrer(aReferrer); |
869 | 0 | } |
870 | | |
871 | | NS_IMETHODIMP |
872 | | nsViewSourceChannel::SetReferrer(nsIURI * aReferrer) |
873 | 0 | { |
874 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
875 | 0 | mHttpChannel->SetReferrer(aReferrer); |
876 | 0 | } |
877 | | |
878 | | NS_IMETHODIMP |
879 | | nsViewSourceChannel::GetReferrerPolicy(uint32_t *aReferrerPolicy) |
880 | 0 | { |
881 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
882 | 0 | mHttpChannel->GetReferrerPolicy(aReferrerPolicy); |
883 | 0 | } |
884 | | |
885 | | NS_IMETHODIMP |
886 | | nsViewSourceChannel::SetReferrerWithPolicy(nsIURI * aReferrer, |
887 | | uint32_t aReferrerPolicy) |
888 | 0 | { |
889 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
890 | 0 | mHttpChannel->SetReferrerWithPolicy(aReferrer, aReferrerPolicy); |
891 | 0 | } |
892 | | |
893 | | NS_IMETHODIMP |
894 | | nsViewSourceChannel::GetRequestHeader(const nsACString & aHeader, |
895 | | nsACString & aValue) |
896 | 0 | { |
897 | 0 | aValue.Truncate(); |
898 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
899 | 0 | mHttpChannel->GetRequestHeader(aHeader, aValue); |
900 | 0 | } |
901 | | |
902 | | NS_IMETHODIMP |
903 | | nsViewSourceChannel::SetRequestHeader(const nsACString & aHeader, |
904 | | const nsACString & aValue, |
905 | | bool aMerge) |
906 | 0 | { |
907 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
908 | 0 | mHttpChannel->SetRequestHeader(aHeader, aValue, aMerge); |
909 | 0 | } |
910 | | |
911 | | NS_IMETHODIMP |
912 | | nsViewSourceChannel::SetEmptyRequestHeader(const nsACString & aHeader) |
913 | 0 | { |
914 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
915 | 0 | mHttpChannel->SetEmptyRequestHeader(aHeader); |
916 | 0 | } |
917 | | |
918 | | NS_IMETHODIMP |
919 | | nsViewSourceChannel::VisitRequestHeaders(nsIHttpHeaderVisitor *aVisitor) |
920 | 0 | { |
921 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
922 | 0 | mHttpChannel->VisitRequestHeaders(aVisitor); |
923 | 0 | } |
924 | | |
925 | | NS_IMETHODIMP |
926 | | nsViewSourceChannel::VisitNonDefaultRequestHeaders(nsIHttpHeaderVisitor *aVisitor) |
927 | 0 | { |
928 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
929 | 0 | mHttpChannel->VisitNonDefaultRequestHeaders(aVisitor); |
930 | 0 | } |
931 | | |
932 | | NS_IMETHODIMP |
933 | | nsViewSourceChannel::GetAllowPipelining(bool *aAllowPipelining) |
934 | 0 | { |
935 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
936 | 0 | mHttpChannel->GetAllowPipelining(aAllowPipelining); |
937 | 0 | } |
938 | | |
939 | | NS_IMETHODIMP |
940 | | nsViewSourceChannel::SetAllowPipelining(bool aAllowPipelining) |
941 | 0 | { |
942 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
943 | 0 | mHttpChannel->SetAllowPipelining(aAllowPipelining); |
944 | 0 | } |
945 | | |
946 | | NS_IMETHODIMP |
947 | | nsViewSourceChannel::GetAllowSTS(bool *aAllowSTS) |
948 | 0 | { |
949 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
950 | 0 | mHttpChannel->GetAllowSTS(aAllowSTS); |
951 | 0 | } |
952 | | |
953 | | NS_IMETHODIMP |
954 | | nsViewSourceChannel::SetAllowSTS(bool aAllowSTS) |
955 | 0 | { |
956 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
957 | 0 | mHttpChannel->SetAllowSTS(aAllowSTS); |
958 | 0 | } |
959 | | |
960 | | NS_IMETHODIMP |
961 | | nsViewSourceChannel::GetRedirectionLimit(uint32_t *aRedirectionLimit) |
962 | 0 | { |
963 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
964 | 0 | mHttpChannel->GetRedirectionLimit(aRedirectionLimit); |
965 | 0 | } |
966 | | |
967 | | NS_IMETHODIMP |
968 | | nsViewSourceChannel::SetRedirectionLimit(uint32_t aRedirectionLimit) |
969 | 0 | { |
970 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
971 | 0 | mHttpChannel->SetRedirectionLimit(aRedirectionLimit); |
972 | 0 | } |
973 | | |
974 | | NS_IMETHODIMP |
975 | | nsViewSourceChannel::GetResponseStatus(uint32_t *aResponseStatus) |
976 | 0 | { |
977 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
978 | 0 | mHttpChannel->GetResponseStatus(aResponseStatus); |
979 | 0 | } |
980 | | |
981 | | NS_IMETHODIMP |
982 | | nsViewSourceChannel::GetResponseStatusText(nsACString & aResponseStatusText) |
983 | 0 | { |
984 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
985 | 0 | mHttpChannel->GetResponseStatusText(aResponseStatusText); |
986 | 0 | } |
987 | | |
988 | | NS_IMETHODIMP |
989 | | nsViewSourceChannel::GetRequestSucceeded(bool *aRequestSucceeded) |
990 | 0 | { |
991 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
992 | 0 | mHttpChannel->GetRequestSucceeded(aRequestSucceeded); |
993 | 0 | } |
994 | | |
995 | | NS_IMETHODIMP |
996 | | nsViewSourceChannel::GetResponseHeader(const nsACString & aHeader, |
997 | | nsACString & aValue) |
998 | 0 | { |
999 | 0 | aValue.Truncate(); |
1000 | 0 | if (!mHttpChannel) |
1001 | 0 | return NS_ERROR_NULL_POINTER; |
1002 | 0 | |
1003 | 0 | if (!aHeader.Equals(NS_LITERAL_CSTRING("Content-Type"), |
1004 | 0 | nsCaseInsensitiveCStringComparator()) && |
1005 | 0 | !aHeader.Equals(NS_LITERAL_CSTRING("Content-Security-Policy"), |
1006 | 0 | nsCaseInsensitiveCStringComparator()) && |
1007 | 0 | !aHeader.Equals(NS_LITERAL_CSTRING("Content-Security-Policy-Report-Only"), |
1008 | 0 | nsCaseInsensitiveCStringComparator()) && |
1009 | 0 | !aHeader.Equals(NS_LITERAL_CSTRING("X-Frame-Options"), |
1010 | 0 | nsCaseInsensitiveCStringComparator())) { |
1011 | 0 | // We simulate the NS_ERROR_NOT_AVAILABLE error which is produced by |
1012 | 0 | // GetResponseHeader via nsHttpHeaderArray::GetHeader when the entry is |
1013 | 0 | // not present, such that it appears as though no headers except for the |
1014 | 0 | // whitelisted ones were set on this channel. |
1015 | 0 | return NS_ERROR_NOT_AVAILABLE; |
1016 | 0 | } |
1017 | 0 | |
1018 | 0 | return mHttpChannel->GetResponseHeader(aHeader, aValue); |
1019 | 0 | } |
1020 | | |
1021 | | NS_IMETHODIMP |
1022 | | nsViewSourceChannel::SetResponseHeader(const nsACString & header, |
1023 | | const nsACString & value, bool merge) |
1024 | 0 | { |
1025 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
1026 | 0 | mHttpChannel->SetResponseHeader(header, value, merge); |
1027 | 0 | } |
1028 | | |
1029 | | NS_IMETHODIMP |
1030 | | nsViewSourceChannel::VisitResponseHeaders(nsIHttpHeaderVisitor *aVisitor) |
1031 | 0 | { |
1032 | 0 | if (!mHttpChannel) |
1033 | 0 | return NS_ERROR_NULL_POINTER; |
1034 | 0 | |
1035 | 0 | NS_NAMED_LITERAL_CSTRING(contentTypeStr, "Content-Type"); |
1036 | 0 | nsAutoCString contentType; |
1037 | 0 | nsresult rv = |
1038 | 0 | mHttpChannel->GetResponseHeader(contentTypeStr, contentType); |
1039 | 0 | if (NS_SUCCEEDED(rv)) { |
1040 | 0 | return aVisitor->VisitHeader(contentTypeStr, contentType); |
1041 | 0 | } |
1042 | 0 | return NS_OK; |
1043 | 0 | } |
1044 | | |
1045 | | NS_IMETHODIMP |
1046 | | nsViewSourceChannel::GetOriginalResponseHeader(const nsACString & aHeader, |
1047 | | nsIHttpHeaderVisitor *aVisitor) |
1048 | 0 | { |
1049 | 0 | nsAutoCString value; |
1050 | 0 | nsresult rv = GetResponseHeader(aHeader, value); |
1051 | 0 | if (NS_FAILED(rv)) { |
1052 | 0 | return rv; |
1053 | 0 | } |
1054 | 0 | return aVisitor->VisitHeader(aHeader, value); |
1055 | 0 | } |
1056 | | |
1057 | | NS_IMETHODIMP |
1058 | | nsViewSourceChannel::VisitOriginalResponseHeaders(nsIHttpHeaderVisitor *aVisitor) |
1059 | 0 | { |
1060 | 0 | return VisitResponseHeaders(aVisitor); |
1061 | 0 | } |
1062 | | |
1063 | | NS_IMETHODIMP |
1064 | | nsViewSourceChannel::IsNoStoreResponse(bool *_retval) |
1065 | 0 | { |
1066 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
1067 | 0 | mHttpChannel->IsNoStoreResponse(_retval); |
1068 | 0 | } |
1069 | | |
1070 | | NS_IMETHODIMP |
1071 | | nsViewSourceChannel::IsNoCacheResponse(bool *_retval) |
1072 | 0 | { |
1073 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
1074 | 0 | mHttpChannel->IsNoCacheResponse(_retval); |
1075 | 0 | } |
1076 | | |
1077 | | NS_IMETHODIMP |
1078 | | nsViewSourceChannel::IsPrivateResponse(bool *_retval) |
1079 | 0 | { |
1080 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
1081 | 0 | mHttpChannel->IsPrivateResponse(_retval); |
1082 | 0 | } |
1083 | | |
1084 | | NS_IMETHODIMP |
1085 | | nsViewSourceChannel::RedirectTo(nsIURI *uri) |
1086 | 0 | { |
1087 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
1088 | 0 | mHttpChannel->RedirectTo(uri); |
1089 | 0 | } |
1090 | | |
1091 | | NS_IMETHODIMP |
1092 | | nsViewSourceChannel::UpgradeToSecure() |
1093 | 0 | { |
1094 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
1095 | 0 | mHttpChannel->UpgradeToSecure(); |
1096 | 0 | } |
1097 | | |
1098 | | NS_IMETHODIMP |
1099 | | nsViewSourceChannel::GetRequestContextID(uint64_t *_retval) |
1100 | 0 | { |
1101 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
1102 | 0 | mHttpChannel->GetRequestContextID(_retval); |
1103 | 0 | } |
1104 | | |
1105 | | NS_IMETHODIMP |
1106 | | nsViewSourceChannel::SetRequestContextID(uint64_t rcid) |
1107 | 0 | { |
1108 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
1109 | 0 | mHttpChannel->SetRequestContextID(rcid); |
1110 | 0 | } |
1111 | | |
1112 | | NS_IMETHODIMP |
1113 | | nsViewSourceChannel::GetIsMainDocumentChannel(bool* aValue) |
1114 | 0 | { |
1115 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
1116 | 0 | mHttpChannel->GetIsMainDocumentChannel(aValue); |
1117 | 0 | } |
1118 | | |
1119 | | NS_IMETHODIMP |
1120 | | nsViewSourceChannel::SetIsMainDocumentChannel(bool aValue) |
1121 | 0 | { |
1122 | 0 | return !mHttpChannel ? NS_ERROR_NULL_POINTER : |
1123 | 0 | mHttpChannel->SetIsMainDocumentChannel(aValue); |
1124 | 0 | } |
1125 | | |
1126 | | // Have to manually forward SetCorsPreflightParameters since it's [notxpcom] |
1127 | | void |
1128 | | nsViewSourceChannel::SetCorsPreflightParameters(const nsTArray<nsCString>& aUnsafeHeaders) |
1129 | 0 | { |
1130 | 0 | mHttpChannelInternal->SetCorsPreflightParameters(aUnsafeHeaders); |
1131 | 0 | } |
1132 | | |
1133 | | void |
1134 | | nsViewSourceChannel::SetAltDataForChild(bool aIsForChild) |
1135 | 0 | { |
1136 | 0 | mHttpChannelInternal->SetAltDataForChild(aIsForChild); |
1137 | 0 | } |
1138 | | |
1139 | | NS_IMETHODIMP |
1140 | | nsViewSourceChannel::LogBlockedCORSRequest(const nsAString& aMessage, |
1141 | | const nsACString& aCategory) |
1142 | 0 | { |
1143 | 0 | if (!mHttpChannel) { |
1144 | 0 | NS_WARNING("nsViewSourceChannel::LogBlockedCORSRequest mHttpChannel is null"); |
1145 | 0 | return NS_ERROR_UNEXPECTED; |
1146 | 0 | } |
1147 | 0 | return mHttpChannel->LogBlockedCORSRequest(aMessage, aCategory); |
1148 | 0 | } |