Bug 1136969 - Add a check that OnStartRequest is called just once during the lifetime of a channel. r=mcmanus

This commit is contained in:
Dragana Damjanovic 2015-04-02 06:12:00 -04:00
parent c4456e9497
commit 570137e623
3 changed files with 16 additions and 0 deletions

View File

@ -82,6 +82,7 @@ HttpBaseChannel::HttpBaseChannel()
, mForcePending(false) , mForcePending(false)
, mCorsIncludeCredentials(false) , mCorsIncludeCredentials(false)
, mCorsMode(nsIHttpChannelInternal::CORS_MODE_NO_CORS) , mCorsMode(nsIHttpChannelInternal::CORS_MODE_NO_CORS)
, mOnStartRequestCalled(false)
{ {
LOG(("Creating HttpBaseChannel @%x\n", this)); LOG(("Creating HttpBaseChannel @%x\n", this));
@ -2053,8 +2054,13 @@ void
HttpBaseChannel::DoNotifyListener() HttpBaseChannel::DoNotifyListener()
{ {
if (mListener) { if (mListener) {
MOZ_ASSERT(!mOnStartRequestCalled,
"We should not call OnStartRequest twice");
nsCOMPtr<nsIStreamListener> listener = mListener; nsCOMPtr<nsIStreamListener> listener = mListener;
listener->OnStartRequest(this, mListenerContext); listener->OnStartRequest(this, mListenerContext);
mOnStartRequestCalled = true;
} }
// Make sure mIsPending is set to false. At this moment we are done from // Make sure mIsPending is set to false. At this moment we are done from

View File

@ -424,6 +424,10 @@ protected:
bool mCorsIncludeCredentials; bool mCorsIncludeCredentials;
uint32_t mCorsMode; 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 // Share some code while working around C++'s absurd inability to handle casting

View File

@ -934,7 +934,10 @@ nsHttpChannel::CallOnStartRequest()
LOG((" calling mListener->OnStartRequest\n")); LOG((" calling mListener->OnStartRequest\n"));
if (mListener) { if (mListener) {
MOZ_ASSERT(!mOnStartRequestCalled,
"We should not call OsStartRequest twice");
rv = mListener->OnStartRequest(this, mListenerContext); rv = mListener->OnStartRequest(this, mListenerContext);
mOnStartRequestCalled = true;
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; return rv;
} else { } 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 // NOTE: since we have a failure status, we can ignore the return
// value from onStartRequest. // value from onStartRequest.
if (mListener) { if (mListener) {
MOZ_ASSERT(!mOnStartRequestCalled,
"We should not call OnStartRequest twice.");
mListener->OnStartRequest(this, mListenerContext); mListener->OnStartRequest(this, mListenerContext);
mOnStartRequestCalled = true;
} else { } else {
NS_WARNING("OnStartRequest skipped because of null listener"); NS_WARNING("OnStartRequest skipped because of null listener");
} }