michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* vim:set ts=4 sw=4 sts=4 et: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsViewSourceChannel.h" michael@0: #include "nsIIOService.h" michael@0: #include "nsMimeTypes.h" michael@0: #include "nsNetUtil.h" michael@0: #include "nsIHttpHeaderVisitor.h" michael@0: michael@0: NS_IMPL_ADDREF(nsViewSourceChannel) michael@0: NS_IMPL_RELEASE(nsViewSourceChannel) michael@0: /* michael@0: This QI uses NS_INTERFACE_MAP_ENTRY_CONDITIONAL to check for michael@0: non-nullness of mHttpChannel, mCachingChannel, and mUploadChannel. michael@0: */ michael@0: NS_INTERFACE_MAP_BEGIN(nsViewSourceChannel) michael@0: NS_INTERFACE_MAP_ENTRY(nsIViewSourceChannel) michael@0: NS_INTERFACE_MAP_ENTRY(nsIStreamListener) michael@0: NS_INTERFACE_MAP_ENTRY(nsIRequestObserver) michael@0: NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIHttpChannel, mHttpChannel) michael@0: NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIHttpChannelInternal, mHttpChannelInternal) michael@0: NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsICachingChannel, mCachingChannel) michael@0: NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIApplicationCacheChannel, mApplicationCacheChannel) michael@0: NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIUploadChannel, mUploadChannel) michael@0: NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIRequest, nsIViewSourceChannel) michael@0: NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIChannel, nsIViewSourceChannel) michael@0: NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIViewSourceChannel) michael@0: NS_INTERFACE_MAP_END michael@0: michael@0: nsresult michael@0: nsViewSourceChannel::Init(nsIURI* uri) michael@0: { michael@0: mOriginalURI = uri; michael@0: michael@0: nsAutoCString path; michael@0: nsresult rv = uri->GetPath(path); michael@0: if (NS_FAILED(rv)) michael@0: return rv; michael@0: michael@0: nsCOMPtr pService(do_GetIOService(&rv)); michael@0: if (NS_FAILED(rv)) return rv; michael@0: michael@0: nsAutoCString scheme; michael@0: rv = pService->ExtractScheme(path, scheme); michael@0: if (NS_FAILED(rv)) michael@0: return rv; michael@0: michael@0: // prevent viewing source of javascript URIs (see bug 204779) michael@0: if (scheme.LowerCaseEqualsLiteral("javascript")) { michael@0: NS_WARNING("blocking view-source:javascript:"); michael@0: return NS_ERROR_INVALID_ARG; michael@0: } michael@0: michael@0: rv = pService->NewChannel(path, nullptr, nullptr, getter_AddRefs(mChannel)); michael@0: if (NS_FAILED(rv)) michael@0: return rv; michael@0: michael@0: mIsSrcdocChannel = false; michael@0: michael@0: mChannel->SetOriginalURI(mOriginalURI); michael@0: mHttpChannel = do_QueryInterface(mChannel); michael@0: mHttpChannelInternal = do_QueryInterface(mChannel); michael@0: mCachingChannel = do_QueryInterface(mChannel); michael@0: mApplicationCacheChannel = do_QueryInterface(mChannel); michael@0: mUploadChannel = do_QueryInterface(mChannel); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: nsViewSourceChannel::InitSrcdoc(nsIURI* aURI, const nsAString &aSrcdoc, michael@0: nsIURI* aBaseURI) michael@0: { michael@0: michael@0: nsresult rv; michael@0: michael@0: nsCOMPtr inStreamURI; michael@0: // Need to strip view-source: from the URI. Hardcoded to michael@0: // about:srcdoc as this is the only permissible URI for srcdoc michael@0: // loads michael@0: rv = NS_NewURI(getter_AddRefs(inStreamURI), michael@0: NS_LITERAL_STRING("about:srcdoc")); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: rv = NS_NewInputStreamChannel(getter_AddRefs(mChannel), inStreamURI, michael@0: aSrcdoc, NS_LITERAL_CSTRING("text/html"), michael@0: true); michael@0: michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: mOriginalURI = aURI; michael@0: mIsSrcdocChannel = true; michael@0: nsCOMPtr isc = do_QueryInterface(mChannel); michael@0: MOZ_ASSERT(isc); michael@0: isc->SetBaseURI(aBaseURI); michael@0: michael@0: mChannel->SetOriginalURI(mOriginalURI); michael@0: mHttpChannel = do_QueryInterface(mChannel); michael@0: mHttpChannelInternal = do_QueryInterface(mChannel); michael@0: mCachingChannel = do_QueryInterface(mChannel); michael@0: mApplicationCacheChannel = do_QueryInterface(mChannel); michael@0: mUploadChannel = do_QueryInterface(mChannel); michael@0: return NS_OK; michael@0: } michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // nsIRequest methods: michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::GetName(nsACString &result) michael@0: { michael@0: return NS_ERROR_NOT_IMPLEMENTED; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::GetProxyURI(nsIURI** proxyURI) michael@0: { michael@0: return NS_ERROR_NOT_IMPLEMENTED; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::IsPending(bool *result) michael@0: { michael@0: NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); michael@0: michael@0: return mChannel->IsPending(result); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::GetStatus(nsresult *status) michael@0: { michael@0: NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); michael@0: michael@0: return mChannel->GetStatus(status); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::Cancel(nsresult status) michael@0: { michael@0: NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); michael@0: michael@0: return mChannel->Cancel(status); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::Suspend(void) michael@0: { michael@0: NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); michael@0: michael@0: return mChannel->Suspend(); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::Resume(void) michael@0: { michael@0: NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); michael@0: michael@0: return mChannel->Resume(); michael@0: } michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // nsIChannel methods: michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::GetOriginalURI(nsIURI* *aURI) michael@0: { michael@0: NS_ASSERTION(aURI, "Null out param!"); michael@0: *aURI = mOriginalURI; michael@0: NS_ADDREF(*aURI); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::SetOriginalURI(nsIURI* aURI) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aURI); michael@0: mOriginalURI = aURI; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::GetURI(nsIURI* *aURI) michael@0: { michael@0: NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); michael@0: michael@0: nsCOMPtr uri; michael@0: nsresult rv = mChannel->GetURI(getter_AddRefs(uri)); michael@0: if (NS_FAILED(rv)) michael@0: return rv; michael@0: michael@0: // protect ourselves against broken channel implementations michael@0: if (!uri) { michael@0: NS_ERROR("inner channel returned NS_OK and a null URI"); michael@0: return NS_ERROR_UNEXPECTED; michael@0: } michael@0: michael@0: nsAutoCString spec; michael@0: uri->GetSpec(spec); michael@0: michael@0: /* XXX Gross hack -- NS_NewURI goes into an infinite loop on michael@0: non-flat specs. See bug 136980 */ michael@0: return NS_NewURI(aURI, nsAutoCString(NS_LITERAL_CSTRING("view-source:")+spec), nullptr); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::Open(nsIInputStream **_retval) michael@0: { michael@0: NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); michael@0: michael@0: nsresult rv = mChannel->Open(_retval); michael@0: if (NS_SUCCEEDED(rv)) { michael@0: mOpened = true; michael@0: } michael@0: michael@0: return rv; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::AsyncOpen(nsIStreamListener *aListener, nsISupports *ctxt) michael@0: { michael@0: NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); michael@0: michael@0: mListener = aListener; michael@0: michael@0: /* michael@0: * We want to add ourselves to the loadgroup before opening michael@0: * mChannel, since we want to make sure we're in the loadgroup michael@0: * when mChannel finishes and fires OnStopRequest() michael@0: */ michael@0: michael@0: nsCOMPtr loadGroup; michael@0: mChannel->GetLoadGroup(getter_AddRefs(loadGroup)); michael@0: if (loadGroup) michael@0: loadGroup->AddRequest(static_cast michael@0: (this), nullptr); michael@0: michael@0: nsresult rv = mChannel->AsyncOpen(this, ctxt); michael@0: michael@0: if (NS_FAILED(rv) && loadGroup) michael@0: loadGroup->RemoveRequest(static_cast michael@0: (this), michael@0: nullptr, rv); michael@0: michael@0: if (NS_SUCCEEDED(rv)) { michael@0: mOpened = true; michael@0: } michael@0: michael@0: return rv; michael@0: } michael@0: michael@0: /* michael@0: * Both the view source channel and mChannel are added to the michael@0: * loadgroup. There should never be more than one request in the michael@0: * loadgroup that has LOAD_DOCUMENT_URI set. The one that has this michael@0: * flag set is the request whose URI is used to refetch the document, michael@0: * so it better be the viewsource channel. michael@0: * michael@0: * Therefore, we need to make sure that michael@0: * 1) The load flags on mChannel _never_ include LOAD_DOCUMENT_URI michael@0: * 2) The load flags on |this| include LOAD_DOCUMENT_URI when it was michael@0: * set via SetLoadFlags (mIsDocument keeps track of this flag). michael@0: */ michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::GetLoadFlags(uint32_t *aLoadFlags) michael@0: { michael@0: NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); michael@0: michael@0: nsresult rv = mChannel->GetLoadFlags(aLoadFlags); michael@0: if (NS_FAILED(rv)) michael@0: return rv; michael@0: michael@0: // This should actually be just LOAD_DOCUMENT_URI but the win32 compiler michael@0: // fails to deal due to amiguous inheritance. nsIChannel::LOAD_DOCUMENT_URI michael@0: // also fails; the Win32 compiler thinks that's supposed to be a method. michael@0: if (mIsDocument) michael@0: *aLoadFlags |= ::nsIChannel::LOAD_DOCUMENT_URI; michael@0: michael@0: return rv; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::SetLoadFlags(uint32_t aLoadFlags) michael@0: { michael@0: NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); michael@0: michael@0: // "View source" always wants the currently cached content. michael@0: // We also want to have _this_ channel, not mChannel to be the michael@0: // 'document' channel in the loadgroup. michael@0: michael@0: // These should actually be just LOAD_FROM_CACHE and LOAD_DOCUMENT_URI but michael@0: // the win32 compiler fails to deal due to amiguous inheritance. michael@0: // nsIChannel::LOAD_DOCUMENT_URI/nsIRequest::LOAD_FROM_CACHE also fails; the michael@0: // Win32 compiler thinks that's supposed to be a method. michael@0: mIsDocument = (aLoadFlags & ::nsIChannel::LOAD_DOCUMENT_URI) ? true : false; michael@0: michael@0: return mChannel->SetLoadFlags((aLoadFlags | michael@0: ::nsIRequest::LOAD_FROM_CACHE) & michael@0: ~::nsIChannel::LOAD_DOCUMENT_URI); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::GetContentType(nsACString &aContentType) michael@0: { michael@0: NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); michael@0: michael@0: aContentType.Truncate(); michael@0: michael@0: if (mContentType.IsEmpty()) michael@0: { michael@0: // Get the current content type michael@0: nsresult rv; michael@0: nsAutoCString contentType; michael@0: rv = mChannel->GetContentType(contentType); michael@0: if (NS_FAILED(rv)) return rv; michael@0: michael@0: // If we don't know our type, just say so. The unknown michael@0: // content decoder will then kick in automatically, and it michael@0: // will call our SetOriginalContentType method instead of our michael@0: // SetContentType method to set the type it determines. michael@0: if (!contentType.Equals(UNKNOWN_CONTENT_TYPE)) { michael@0: contentType = VIEWSOURCE_CONTENT_TYPE; michael@0: } michael@0: michael@0: mContentType = contentType; michael@0: } michael@0: michael@0: aContentType = mContentType; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::SetContentType(const nsACString &aContentType) michael@0: { michael@0: // Our GetContentType() currently returns VIEWSOURCE_CONTENT_TYPE michael@0: // michael@0: // However, during the parsing phase the parser calls our michael@0: // channel's GetContentType(). Returning the string above trips up michael@0: // the parser. In order to avoid messy changes and not to have the michael@0: // parser depend on nsIViewSourceChannel Vidur proposed the michael@0: // following solution: michael@0: // michael@0: // The ViewSourceChannel initially returns a content type of michael@0: // VIEWSOURCE_CONTENT_TYPE. Based on this type decisions to michael@0: // create a viewer for doing a view source are made. After the michael@0: // viewer is created, nsLayoutDLF::CreateInstance() calls this michael@0: // SetContentType() with the original content type. When it's michael@0: // time for the parser to find out the content type it will call michael@0: // our channel's GetContentType() and it will get the original michael@0: // content type, such as, text/html and everything is kosher from michael@0: // then on. michael@0: michael@0: if (!mOpened) { michael@0: // We do not take hints michael@0: return NS_ERROR_NOT_AVAILABLE; michael@0: } michael@0: michael@0: mContentType = aContentType; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::GetContentCharset(nsACString &aContentCharset) michael@0: { michael@0: NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); michael@0: michael@0: return mChannel->GetContentCharset(aContentCharset); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::SetContentCharset(const nsACString &aContentCharset) michael@0: { michael@0: NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); michael@0: michael@0: return mChannel->SetContentCharset(aContentCharset); michael@0: } michael@0: michael@0: // We don't forward these methods becacuse content-disposition isn't whitelisted michael@0: // (see GetResponseHeader/VisitResponseHeaders). michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::GetContentDisposition(uint32_t *aContentDisposition) michael@0: { michael@0: return NS_ERROR_NOT_AVAILABLE; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::SetContentDisposition(uint32_t aContentDisposition) michael@0: { michael@0: return NS_ERROR_NOT_AVAILABLE; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::GetContentDispositionFilename(nsAString &aContentDispositionFilename) michael@0: { michael@0: return NS_ERROR_NOT_AVAILABLE; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::SetContentDispositionFilename(const nsAString &aContentDispositionFilename) michael@0: { michael@0: return NS_ERROR_NOT_AVAILABLE; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::GetContentDispositionHeader(nsACString &aContentDispositionHeader) michael@0: { michael@0: return NS_ERROR_NOT_AVAILABLE; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::GetContentLength(int64_t *aContentLength) michael@0: { michael@0: NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); michael@0: michael@0: return mChannel->GetContentLength(aContentLength); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::SetContentLength(int64_t aContentLength) michael@0: { michael@0: NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); michael@0: michael@0: return mChannel->SetContentLength(aContentLength); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup) michael@0: { michael@0: NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); michael@0: michael@0: return mChannel->GetLoadGroup(aLoadGroup); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::SetLoadGroup(nsILoadGroup* aLoadGroup) michael@0: { michael@0: NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); michael@0: michael@0: return mChannel->SetLoadGroup(aLoadGroup); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::GetOwner(nsISupports* *aOwner) michael@0: { michael@0: NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); michael@0: michael@0: return mChannel->GetOwner(aOwner); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::SetOwner(nsISupports* aOwner) michael@0: { michael@0: NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); michael@0: michael@0: return mChannel->SetOwner(aOwner); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::GetNotificationCallbacks(nsIInterfaceRequestor* *aNotificationCallbacks) michael@0: { michael@0: NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); michael@0: michael@0: return mChannel->GetNotificationCallbacks(aNotificationCallbacks); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCallbacks) michael@0: { michael@0: NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); michael@0: michael@0: return mChannel->SetNotificationCallbacks(aNotificationCallbacks); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::GetSecurityInfo(nsISupports * *aSecurityInfo) michael@0: { michael@0: NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); michael@0: michael@0: return mChannel->GetSecurityInfo(aSecurityInfo); michael@0: } michael@0: michael@0: // nsIViewSourceChannel methods michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::GetOriginalContentType(nsACString &aContentType) michael@0: { michael@0: NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); michael@0: michael@0: return mChannel->GetContentType(aContentType); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::SetOriginalContentType(const nsACString &aContentType) michael@0: { michael@0: NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE); michael@0: michael@0: // clear our cached content-type value michael@0: mContentType.Truncate(); michael@0: michael@0: return mChannel->SetContentType(aContentType); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::GetIsSrcdocChannel(bool* aIsSrcdocChannel) michael@0: { michael@0: *aIsSrcdocChannel = mIsSrcdocChannel; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::GetBaseURI(nsIURI** aBaseURI) michael@0: { michael@0: if (mIsSrcdocChannel) { michael@0: nsCOMPtr isc = do_QueryInterface(mChannel); michael@0: if (isc) { michael@0: return isc->GetBaseURI(aBaseURI); michael@0: } michael@0: } michael@0: *aBaseURI = mBaseURI; michael@0: NS_IF_ADDREF(*aBaseURI); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::SetBaseURI(nsIURI* aBaseURI) michael@0: { michael@0: mBaseURI = aBaseURI; michael@0: return NS_OK; michael@0: } michael@0: michael@0: // nsIRequestObserver methods michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext) michael@0: { michael@0: NS_ENSURE_TRUE(mListener, NS_ERROR_FAILURE); michael@0: // The channel may have gotten redirected... Time to update our info michael@0: mChannel = do_QueryInterface(aRequest); michael@0: mHttpChannel = do_QueryInterface(aRequest); michael@0: mCachingChannel = do_QueryInterface(aRequest); michael@0: mUploadChannel = do_QueryInterface(aRequest); michael@0: michael@0: return mListener->OnStartRequest(static_cast michael@0: (this), michael@0: aContext); michael@0: } michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::OnStopRequest(nsIRequest *aRequest, nsISupports* aContext, michael@0: nsresult aStatus) michael@0: { michael@0: NS_ENSURE_TRUE(mListener, NS_ERROR_FAILURE); michael@0: if (mChannel) michael@0: { michael@0: nsCOMPtr loadGroup; michael@0: mChannel->GetLoadGroup(getter_AddRefs(loadGroup)); michael@0: if (loadGroup) michael@0: { michael@0: loadGroup->RemoveRequest(static_cast michael@0: (this), michael@0: nullptr, aStatus); michael@0: } michael@0: } michael@0: return mListener->OnStopRequest(static_cast michael@0: (this), michael@0: aContext, aStatus); michael@0: } michael@0: michael@0: michael@0: // nsIStreamListener methods michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::OnDataAvailable(nsIRequest *aRequest, nsISupports* aContext, michael@0: nsIInputStream *aInputStream, michael@0: uint64_t aSourceOffset, michael@0: uint32_t aLength) michael@0: { michael@0: NS_ENSURE_TRUE(mListener, NS_ERROR_FAILURE); michael@0: return mListener->OnDataAvailable(static_cast michael@0: (this), michael@0: aContext, aInputStream, michael@0: aSourceOffset, aLength); michael@0: } michael@0: michael@0: michael@0: // nsIHttpChannel methods michael@0: michael@0: // We want to forward most of nsIHttpChannel over to mHttpChannel, but we want michael@0: // to override GetRequestHeader and VisitHeaders. The reason is that we don't michael@0: // want various headers like Link: and Refresh: applying to view-source. michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::GetRequestMethod(nsACString & aRequestMethod) michael@0: { michael@0: return !mHttpChannel ? NS_ERROR_NULL_POINTER : michael@0: mHttpChannel->GetRequestMethod(aRequestMethod); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::SetRequestMethod(const nsACString & aRequestMethod) michael@0: { michael@0: return !mHttpChannel ? NS_ERROR_NULL_POINTER : michael@0: mHttpChannel->SetRequestMethod(aRequestMethod); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::GetReferrer(nsIURI * *aReferrer) michael@0: { michael@0: return !mHttpChannel ? NS_ERROR_NULL_POINTER : michael@0: mHttpChannel->GetReferrer(aReferrer); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::SetReferrer(nsIURI * aReferrer) michael@0: { michael@0: return !mHttpChannel ? NS_ERROR_NULL_POINTER : michael@0: mHttpChannel->SetReferrer(aReferrer); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::GetRequestHeader(const nsACString & aHeader, michael@0: nsACString & aValue) michael@0: { michael@0: return !mHttpChannel ? NS_ERROR_NULL_POINTER : michael@0: mHttpChannel->GetRequestHeader(aHeader, aValue); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::SetRequestHeader(const nsACString & aHeader, michael@0: const nsACString & aValue, michael@0: bool aMerge) michael@0: { michael@0: return !mHttpChannel ? NS_ERROR_NULL_POINTER : michael@0: mHttpChannel->SetRequestHeader(aHeader, aValue, aMerge); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::VisitRequestHeaders(nsIHttpHeaderVisitor *aVisitor) michael@0: { michael@0: return !mHttpChannel ? NS_ERROR_NULL_POINTER : michael@0: mHttpChannel->VisitRequestHeaders(aVisitor); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::GetAllowPipelining(bool *aAllowPipelining) michael@0: { michael@0: return !mHttpChannel ? NS_ERROR_NULL_POINTER : michael@0: mHttpChannel->GetAllowPipelining(aAllowPipelining); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::SetAllowPipelining(bool aAllowPipelining) michael@0: { michael@0: return !mHttpChannel ? NS_ERROR_NULL_POINTER : michael@0: mHttpChannel->SetAllowPipelining(aAllowPipelining); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::GetRedirectionLimit(uint32_t *aRedirectionLimit) michael@0: { michael@0: return !mHttpChannel ? NS_ERROR_NULL_POINTER : michael@0: mHttpChannel->GetRedirectionLimit(aRedirectionLimit); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::SetRedirectionLimit(uint32_t aRedirectionLimit) michael@0: { michael@0: return !mHttpChannel ? NS_ERROR_NULL_POINTER : michael@0: mHttpChannel->SetRedirectionLimit(aRedirectionLimit); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::GetResponseStatus(uint32_t *aResponseStatus) michael@0: { michael@0: return !mHttpChannel ? NS_ERROR_NULL_POINTER : michael@0: mHttpChannel->GetResponseStatus(aResponseStatus); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::GetResponseStatusText(nsACString & aResponseStatusText) michael@0: { michael@0: return !mHttpChannel ? NS_ERROR_NULL_POINTER : michael@0: mHttpChannel->GetResponseStatusText(aResponseStatusText); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::GetRequestSucceeded(bool *aRequestSucceeded) michael@0: { michael@0: return !mHttpChannel ? NS_ERROR_NULL_POINTER : michael@0: mHttpChannel->GetRequestSucceeded(aRequestSucceeded); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::GetResponseHeader(const nsACString & aHeader, michael@0: nsACString & aValue) michael@0: { michael@0: if (!mHttpChannel) michael@0: return NS_ERROR_NULL_POINTER; michael@0: michael@0: if (!aHeader.Equals(NS_LITERAL_CSTRING("Content-Type"), michael@0: nsCaseInsensitiveCStringComparator()) && michael@0: !aHeader.Equals(NS_LITERAL_CSTRING("X-Content-Security-Policy"), michael@0: nsCaseInsensitiveCStringComparator()) && michael@0: !aHeader.Equals(NS_LITERAL_CSTRING("X-Content-Security-Policy-Report-Only"), michael@0: nsCaseInsensitiveCStringComparator()) && michael@0: !aHeader.Equals(NS_LITERAL_CSTRING("Content-Security-Policy"), michael@0: nsCaseInsensitiveCStringComparator()) && michael@0: !aHeader.Equals(NS_LITERAL_CSTRING("Content-Security-Policy-Report-Only"), michael@0: nsCaseInsensitiveCStringComparator()) && michael@0: !aHeader.Equals(NS_LITERAL_CSTRING("X-Frame-Options"), michael@0: nsCaseInsensitiveCStringComparator())) { michael@0: aValue.Truncate(); michael@0: return NS_OK; michael@0: } michael@0: michael@0: return mHttpChannel->GetResponseHeader(aHeader, aValue); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::SetResponseHeader(const nsACString & header, michael@0: const nsACString & value, bool merge) michael@0: { michael@0: return !mHttpChannel ? NS_ERROR_NULL_POINTER : michael@0: mHttpChannel->SetResponseHeader(header, value, merge); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::VisitResponseHeaders(nsIHttpHeaderVisitor *aVisitor) michael@0: { michael@0: if (!mHttpChannel) michael@0: return NS_ERROR_NULL_POINTER; michael@0: michael@0: NS_NAMED_LITERAL_CSTRING(contentTypeStr, "Content-Type"); michael@0: nsAutoCString contentType; michael@0: nsresult rv = michael@0: mHttpChannel->GetResponseHeader(contentTypeStr, contentType); michael@0: if (NS_SUCCEEDED(rv)) michael@0: aVisitor->VisitHeader(contentTypeStr, contentType); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::IsNoStoreResponse(bool *_retval) michael@0: { michael@0: return !mHttpChannel ? NS_ERROR_NULL_POINTER : michael@0: mHttpChannel->IsNoStoreResponse(_retval); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::IsNoCacheResponse(bool *_retval) michael@0: { michael@0: return !mHttpChannel ? NS_ERROR_NULL_POINTER : michael@0: mHttpChannel->IsNoCacheResponse(_retval); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsViewSourceChannel::RedirectTo(nsIURI *uri) michael@0: { michael@0: return !mHttpChannel ? NS_ERROR_NULL_POINTER : michael@0: mHttpChannel->RedirectTo(uri); michael@0: } michael@0: