Bug 1416879 - Part 3: (Also Bug 1418795) SyntheticDiversionListener should handle !mIPCOpen. r=bkelly

The SyntheticDiversionListener needs to handle the case where the IPC
connection is gone.  This patch avoids calling Send* methods which will
crash the content process if the actor has already been destroyed.
Additionally, OnDataAvailable will return an error in such a case so
that the caller can properly handle the error rather than continuing to
attempt to send data to a listener that doesn't care.  This latter
change is an artifact of a previous hack attempt to fix a related
diversion issue that is probably not required for this stack, but makes
sense as a fix, so I've left it in.

--HG--
extra : rebase_source : 44ee7941be7619a8532c5194eca88fb0ca6323f7
extra : source : 5453b8a58f0c2c28dc7c407c531c266972bff423
This commit is contained in:
Andrew Sutherland 2018-01-04 13:59:13 -05:00
Родитель 6684613c61
Коммит 2da7a3c221
2 изменённых файлов: 11 добавлений и 6 удалений

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

@ -615,8 +615,6 @@ HttpChannelChild::OnStartRequest(const nsresult& channelStatus,
DoOnStartRequest(this, mListenerContext);
}
namespace {
class SyntheticDiversionListener final : public nsIStreamListener
{
RefPtr<HttpChannelChild> mChannel;
@ -643,8 +641,10 @@ public:
OnStopRequest(nsIRequest* aRequest, nsISupports* aContext,
nsresult aStatus) override
{
mChannel->SendDivertOnStopRequest(aStatus);
mChannel->SendDivertComplete();
if (mChannel->mIPCOpen) {
mChannel->SendDivertOnStopRequest(aStatus);
mChannel->SendDivertComplete();
}
return NS_OK;
}
@ -653,6 +653,11 @@ public:
nsIInputStream* aInputStream, uint64_t aOffset,
uint32_t aCount) override
{
if (!mChannel->mIPCOpen) {
aRequest->Cancel(NS_ERROR_ABORT);
return NS_ERROR_ABORT;
}
nsAutoCString data;
nsresult rv = NS_ConsumeStream(aInputStream, aCount, data);
if (NS_WARN_IF(NS_FAILED(rv))) {
@ -669,8 +674,6 @@ public:
NS_IMPL_ISUPPORTS(SyntheticDiversionListener, nsIStreamListener);
} // anonymous namespace
void
HttpChannelChild::DoOnStartRequest(nsIRequest* aRequest, nsISupports* aContext)
{

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

@ -47,6 +47,7 @@ namespace net {
class HttpBackgroundChannelChild;
class InterceptedChannelContent;
class InterceptStreamListener;
class SyntheticDiversionListener;
class HttpChannelChild final : public PHttpChannelChild
, public HttpBaseChannel
@ -474,6 +475,7 @@ private:
friend class HttpAsyncAborter<HttpChannelChild>;
friend class InterceptStreamListener;
friend class InterceptedChannelContent;
friend class SyntheticDiversionListener;
friend class HttpBackgroundChannelChild;
friend class NeckoTargetChannelEvent<HttpChannelChild>;
};