From 570137e62385109bafcc6bc550aba66095db43e4 Mon Sep 17 00:00:00 2001
From: Dragana Damjanovic
Date: Thu, 2 Apr 2015 06:12:00 -0400
Subject: [PATCH] Bug 1136969 - Add a check that OnStartRequest is called just
once during the lifetime of a channel. r=mcmanus
---
netwerk/protocol/http/HttpBaseChannel.cpp | 6 ++++++
netwerk/protocol/http/HttpBaseChannel.h | 4 ++++
netwerk/protocol/http/nsHttpChannel.cpp | 6 ++++++
3 files changed, 16 insertions(+)
diff --git a/netwerk/protocol/http/HttpBaseChannel.cpp b/netwerk/protocol/http/HttpBaseChannel.cpp
index 23d7d3d8dab..4e37a34d8fe 100644
--- a/netwerk/protocol/http/HttpBaseChannel.cpp
+++ b/netwerk/protocol/http/HttpBaseChannel.cpp
@@ -82,6 +82,7 @@ HttpBaseChannel::HttpBaseChannel()
, mForcePending(false)
, mCorsIncludeCredentials(false)
, mCorsMode(nsIHttpChannelInternal::CORS_MODE_NO_CORS)
+ , mOnStartRequestCalled(false)
{
LOG(("Creating HttpBaseChannel @%x\n", this));
@@ -2053,8 +2054,13 @@ void
HttpBaseChannel::DoNotifyListener()
{
if (mListener) {
+ MOZ_ASSERT(!mOnStartRequestCalled,
+ "We should not call OnStartRequest twice");
+
nsCOMPtr listener = mListener;
listener->OnStartRequest(this, mListenerContext);
+
+ mOnStartRequestCalled = true;
}
// Make sure mIsPending is set to false. At this moment we are done from
diff --git a/netwerk/protocol/http/HttpBaseChannel.h b/netwerk/protocol/http/HttpBaseChannel.h
index 10d8fdc0ca0..f776c36f0e1 100644
--- a/netwerk/protocol/http/HttpBaseChannel.h
+++ b/netwerk/protocol/http/HttpBaseChannel.h
@@ -424,6 +424,10 @@ protected:
bool mCorsIncludeCredentials;
uint32_t mCorsMode;
+
+ // This parameter is used to ensure that we do not call OnStartRequest more
+ // than once.
+ bool mOnStartRequestCalled;
};
// Share some code while working around C++'s absurd inability to handle casting
diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp
index 27d09c2fb17..2292efa476e 100644
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -934,7 +934,10 @@ nsHttpChannel::CallOnStartRequest()
LOG((" calling mListener->OnStartRequest\n"));
if (mListener) {
+ MOZ_ASSERT(!mOnStartRequestCalled,
+ "We should not call OsStartRequest twice");
rv = mListener->OnStartRequest(this, mListenerContext);
+ mOnStartRequestCalled = true;
if (NS_FAILED(rv))
return rv;
} else {
@@ -5519,7 +5522,10 @@ nsHttpChannel::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult st
// NOTE: since we have a failure status, we can ignore the return
// value from onStartRequest.
if (mListener) {
+ MOZ_ASSERT(!mOnStartRequestCalled,
+ "We should not call OnStartRequest twice.");
mListener->OnStartRequest(this, mListenerContext);
+ mOnStartRequestCalled = true;
} else {
NS_WARNING("OnStartRequest skipped because of null listener");
}