commit 36053c97fc9dcec827646d2660c5d5b18a35bdbe Author: Boris Zbarsky bzbarsky@mit.edu Date: Tue Jun 24 23:36:39 2014 -0400
Bug 1023121 - Update our progress in docloader before calling state change listeners. r=smaug, a=sledru --- uriloader/base/nsDocLoader.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/uriloader/base/nsDocLoader.cpp b/uriloader/base/nsDocLoader.cpp index de08daf..d08bc97 100644 --- a/uriloader/base/nsDocLoader.cpp +++ b/uriloader/base/nsDocLoader.cpp @@ -1016,16 +1016,20 @@ int64_t nsDocLoader::GetMaxTotalProgress() NS_IMETHODIMP nsDocLoader::OnProgress(nsIRequest *aRequest, nsISupports* ctxt, uint64_t aProgress, uint64_t aProgressMax) { - nsRequestInfo *info; int64_t progressDelta = 0;
// // Update the RequestInfo entry with the new progress data // - info = GetRequestInfo(aRequest); - if (info) { + if (nsRequestInfo* info = GetRequestInfo(aRequest)) { + // Update info->mCurrentProgress before we call FireOnStateChange, + // since that can make the "info" pointer invalid. + int64_t oldCurrentProgress = info->mCurrentProgress; + progressDelta = int64_t(aProgress) - oldCurrentProgress; + info->mCurrentProgress = int64_t(aProgress); + // suppress sending STATE_TRANSFERRING if this is upload progress (see bug 240053) - if (!info->mUploading && (int64_t(0) == info->mCurrentProgress) && (int64_t(0) == info->mMaxProgress)) { + if (!info->mUploading && (int64_t(0) == oldCurrentProgress) && (int64_t(0) == info->mMaxProgress)) { // // If we receive an OnProgress event from a toplevel channel that the URI Loader // has not yet targeted, then we must suppress the event. This is necessary to @@ -1072,11 +1076,8 @@ NS_IMETHODIMP nsDocLoader::OnProgress(nsIRequest *aRequest, nsISupports* ctxt, FireOnStateChange(this, aRequest, flags, NS_OK); }
- // Update the current progress count... - progressDelta = int64_t(aProgress) - info->mCurrentProgress; + // Update our overall current progress count. mCurrentSelfProgress += progressDelta; - - info->mCurrentProgress = int64_t(aProgress); } // // The request is not part of the load group, so ignore its progress