Bug 1400655 P1 Respect LOAD_CALL_CONTENT_SNIFFERS when a channel is intercepted by a ServiceWorker. r=valentin

This commit is contained in:
Ben Kelly 2017-10-25 17:32:04 -04:00
Родитель 24e65c29e3
Коммит 61ffdf4130
5 изменённых файлов: 29 добавлений и 14 удалений

Просмотреть файл

@ -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<nsIChannel*>(aClosure);
nsAutoCString newType;
NS_SniffContent(NS_CONTENT_SNIFFER_CATEGORY, chan, aData, aCount, newType);
if (!newType.IsEmpty()) {
chan->SetContentType(newType);
}
}
} // namespace net
} // namespace mozilla

Просмотреть файл

@ -464,6 +464,9 @@ protected:
// Called before we create the redirect target channel.
already_AddRefed<nsILoadInfo> CloneLoadInfoForRedirect(nsIURI *newURI, uint32_t redirectFlags);
static void CallTypeSniffers(void *aClosure, const uint8_t *aData,
uint32_t aCount);
friend class PrivateBrowsingChannel<HttpBaseChannel>;
friend class InterceptFailedOnStop;

Просмотреть файл

@ -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<nsIChannel*>(this));
}
nsresult rv = mListener->OnStartRequest(aRequest, aContext);
if (NS_FAILED(rv)) {
Cancel(rv);

Просмотреть файл

@ -1001,6 +1001,11 @@ InterceptedHttpChannel::OnStartRequest(nsIRequest* aRequest,
if (!mProgressSink) {
GetCallback(mProgressSink);
}
if (mPump && mLoadFlags & LOAD_CALL_CONTENT_SNIFFERS) {
mPump->PeekStream(CallTypeSniffers, static_cast<nsIChannel*>(this));
}
if (mListener) {
mListener->OnStartRequest(this, mListenerContext);
}

Просмотреть файл

@ -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<nsIChannel*>(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