Bug 1073872 - Fix data encoding if a channel is diverted from a child back to the parent. r=sworkman

This commit is contained in:
Dragana Damjanovic 2014-11-07 07:50:00 +01:00
Родитель cfb6b6200c
Коммит 4ccca6bd65
2 изменённых файлов: 15 добавлений и 38 удалений

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

@ -562,14 +562,7 @@ HttpChannelParent::RecvDivertOnDataAvailable(const nsCString& data,
return true;
}
nsCOMPtr<nsIStreamListener> listener;
if (mConverterListener) {
listener = mConverterListener;
} else {
listener = mParentListener;
MOZ_ASSERT(listener);
}
rv = listener->OnDataAvailable(mChannel, nullptr, stringStream,
rv = mParentListener->OnDataAvailable(mChannel, nullptr, stringStream,
offset, count);
stringStream->Close();
if (NS_FAILED(rv)) {
@ -601,14 +594,7 @@ HttpChannelParent::RecvDivertOnStopRequest(const nsresult& statusCode)
mChannel->ForcePending(false);
}
nsCOMPtr<nsIStreamListener> listener;
if (mConverterListener) {
listener = mConverterListener;
} else {
listener = mParentListener;
MOZ_ASSERT(listener);
}
listener->OnStopRequest(mChannel, nullptr, status);
mParentListener->OnStopRequest(mChannel, nullptr, status);
return true;
}
@ -629,7 +615,6 @@ HttpChannelParent::RecvDivertComplete()
return false;
}
mConverterListener = nullptr;
mParentListener = nullptr;
return true;
}
@ -966,8 +951,7 @@ HttpChannelParent::DivertTo(nsIStreamListener *aListener)
return;
}
DebugOnly<nsresult> rv = mParentListener->DivertTo(aListener);
MOZ_ASSERT(NS_SUCCEEDED(rv));
mDivertListener = aListener;
if (NS_WARN_IF(mIPCClosed || !SendFlushedForDiversion())) {
FailDiversion(NS_ERROR_UNEXPECTED);
@ -996,7 +980,7 @@ HttpChannelParent::StartDiversion()
}
// Call OnStartRequest for the "DivertTo" listener.
nsresult rv = mParentListener->OnStartRequest(mChannel, nullptr);
nsresult rv = mDivertListener->OnStartRequest(mChannel, nullptr);
if (NS_FAILED(rv)) {
if (mChannel) {
mChannel->Cancel(rv);
@ -1007,26 +991,20 @@ HttpChannelParent::StartDiversion()
// After OnStartRequest has been called, setup content decoders if needed.
//
// We want to use the same decoders that the nsHttpChannel might use. There
// are two possible scenarios depending on whether OnStopRequest has been
// called or not.
//
// 1. nsHttpChannel has not called OnStopRequest yet.
// Create content conversion chain based on nsHttpChannel::mListener
// Get ptr to final listener and set that in mContentConverter, as well as
// nsHttpChannel::mListener.
//
// 2. nsHttpChannel has called OnStopRequest.
// Create a content conversion chain based on mParentListener.
// Get ptr to final listener and set that in mContentConverter.
// Create a content conversion chain based on mDivertListener and update
// mDivertListener.
nsCOMPtr<nsIStreamListener> converterListener;
mChannel->DoApplyContentConversions(mParentListener,
mChannel->DoApplyContentConversions(mDivertListener,
getter_AddRefs(converterListener));
if (converterListener) {
mConverterListener = converterListener.forget();
mDivertListener = converterListener.forget();
}
// Now mParentListener can be diverted to mDivertListener.
DebugOnly<nsresult> rvdbg = mParentListener->DivertTo(mDivertListener);
MOZ_ASSERT(NS_SUCCEEDED(rvdbg));
mDivertListener = nullptr;
// The listener chain should now be setup; tell HttpChannelChild to divert
// the OnDataAvailables and OnStopRequest to this HttpChannelParent.
if (NS_WARN_IF(mIPCClosed || !SendDivertMessages())) {
@ -1106,7 +1084,6 @@ HttpChannelParent::NotifyDiversionFailed(nsresult aErrorCode,
mParentListener->OnStopRequest(mChannel, nullptr, aErrorCode);
}
mParentListener = nullptr;
mConverterListener = nullptr;
mChannel = nullptr;
if (!mIPCClosed) {

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

@ -173,8 +173,8 @@ private:
nsRefPtr<nsHttpHandler> mHttpHandler;
nsRefPtr<HttpChannelParentListener> mParentListener;
// The first listener in the decode chain if channel decoding is applied.
nsCOMPtr<nsIStreamListener> mConverterListener;
// This is listener we are diverting to.
nsCOMPtr<nsIStreamListener> mDivertListener;
// Set to the canceled status value if the main channel was canceled.
nsresult mStatus;
// Once set, no OnStart/OnData/OnStop calls should be accepted; conversely, it