From 61ffdf41307af2a365c3c17b150b8ff96796e493 Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Wed, 25 Oct 2017 17:32:04 -0400 Subject: [PATCH] Bug 1400655 P1 Respect LOAD_CALL_CONTENT_SNIFFERS when a channel is intercepted by a ServiceWorker. r=valentin --- netwerk/protocol/http/HttpBaseChannel.cpp | 15 +++++++++++++++ netwerk/protocol/http/HttpBaseChannel.h | 3 +++ netwerk/protocol/http/HttpChannelChild.cpp | 6 ++++++ netwerk/protocol/http/InterceptedHttpChannel.cpp | 5 +++++ netwerk/protocol/http/nsHttpChannel.cpp | 14 -------------- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/netwerk/protocol/http/HttpBaseChannel.cpp b/netwerk/protocol/http/HttpBaseChannel.cpp index b9aabc53f475..88531cd95005 100644 --- a/netwerk/protocol/http/HttpBaseChannel.cpp +++ b/netwerk/protocol/http/HttpBaseChannel.cpp @@ -4339,5 +4339,20 @@ HttpBaseChannel::SetLastRedirectFlags(uint32_t aValue) return NS_OK; } +// NOTE: This function duplicates code from nsBaseChannel. This will go away +// once HTTP uses nsBaseChannel (part of bug 312760) +/* static */ void +HttpBaseChannel::CallTypeSniffers(void *aClosure, const uint8_t *aData, + uint32_t aCount) +{ + nsIChannel *chan = static_cast(aClosure); + + nsAutoCString newType; + NS_SniffContent(NS_CONTENT_SNIFFER_CATEGORY, chan, aData, aCount, newType); + if (!newType.IsEmpty()) { + chan->SetContentType(newType); + } +} + } // namespace net } // namespace mozilla diff --git a/netwerk/protocol/http/HttpBaseChannel.h b/netwerk/protocol/http/HttpBaseChannel.h index 26a716bb93c3..25d9f0463e7e 100644 --- a/netwerk/protocol/http/HttpBaseChannel.h +++ b/netwerk/protocol/http/HttpBaseChannel.h @@ -464,6 +464,9 @@ protected: // Called before we create the redirect target channel. already_AddRefed CloneLoadInfoForRedirect(nsIURI *newURI, uint32_t redirectFlags); + static void CallTypeSniffers(void *aClosure, const uint8_t *aData, + uint32_t aCount); + friend class PrivateBrowsingChannel; friend class InterceptFailedOnStop; diff --git a/netwerk/protocol/http/HttpChannelChild.cpp b/netwerk/protocol/http/HttpChannelChild.cpp index 75054c911cae..f232ad4ed19a 100644 --- a/netwerk/protocol/http/HttpChannelChild.cpp +++ b/netwerk/protocol/http/HttpChannelChild.cpp @@ -681,6 +681,12 @@ HttpChannelChild::DoOnStartRequest(nsIRequest* aRequest, nsISupports* aContext) Cancel(NS_ERROR_FAILURE); return; } + + if (mSynthesizedResponsePump && mLoadFlags & LOAD_CALL_CONTENT_SNIFFERS) { + mSynthesizedResponsePump->PeekStream(CallTypeSniffers, + static_cast(this)); + } + nsresult rv = mListener->OnStartRequest(aRequest, aContext); if (NS_FAILED(rv)) { Cancel(rv); diff --git a/netwerk/protocol/http/InterceptedHttpChannel.cpp b/netwerk/protocol/http/InterceptedHttpChannel.cpp index f64569f07d45..305ff971e4c0 100644 --- a/netwerk/protocol/http/InterceptedHttpChannel.cpp +++ b/netwerk/protocol/http/InterceptedHttpChannel.cpp @@ -1001,6 +1001,11 @@ InterceptedHttpChannel::OnStartRequest(nsIRequest* aRequest, if (!mProgressSink) { GetCallback(mProgressSink); } + + if (mPump && mLoadFlags & LOAD_CALL_CONTENT_SNIFFERS) { + mPump->PeekStream(CallTypeSniffers, static_cast(this)); + } + if (mListener) { mListener->OnStartRequest(this, mListenerContext); } diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index a067c9fd121c..c6f9668e620a 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -1320,20 +1320,6 @@ nsHttpChannel::SetupTransaction() return rv; } -// NOTE: This function duplicates code from nsBaseChannel. This will go away -// once HTTP uses nsBaseChannel (part of bug 312760) -static void -CallTypeSniffers(void *aClosure, const uint8_t *aData, uint32_t aCount) -{ - nsIChannel *chan = static_cast(aClosure); - - nsAutoCString newType; - NS_SniffContent(NS_CONTENT_SNIFFER_CATEGORY, chan, aData, aCount, newType); - if (!newType.IsEmpty()) { - chan->SetContentType(newType); - } -} - // Helper Function to report messages to the console when loading // a resource was blocked due to a MIME type mismatch. void