Bug 801701 - Fix references to non-existent requests in status trackers for extracted frames. r=joe
authorJosh Matthews <josh@joshmatthews.net>
Mon, 15 Oct 2012 16:05:01 -0400
changeset 110454 5ced91531316b79e42ec1645d0f77ada840d993b
parent 110453 4e9d97c921276a69bfdec4a4d6f86890f2c19fc3
child 110455 c4b7708e04f4f04c849faad9d1c90d1a7f360bd2
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersjoe
bugs801701
milestone19.0a1
Bug 801701 - Fix references to non-existent requests in status trackers for extracted frames. r=joe
image/src/imgStatusTracker.cpp
--- a/image/src/imgStatusTracker.cpp
+++ b/image/src/imgStatusTracker.cpp
@@ -47,34 +47,36 @@ NS_IMETHODIMP imgStatusTrackerObserver::
 /** imgIDecoderObserver methods **/
 
 NS_IMETHODIMP imgStatusTrackerObserver::OnStartDecode()
 {
   LOG_SCOPE(gImgLog, "imgStatusTrackerObserver::OnStartDecode");
   NS_ABORT_IF_FALSE(mTracker->GetImage(),
                     "OnStartDecode callback before we've created our image");
 
-  if (!mTracker->GetRequest()->GetMultipart()) {
+  if (mTracker->GetRequest() && !mTracker->GetRequest()->GetMultipart()) {
     MOZ_ASSERT(!mTracker->mBlockingOnload);
     mTracker->mBlockingOnload = true;
 
     mTracker->RecordBlockOnload();
 
     nsTObserverArray<imgRequestProxy*>::ForwardIterator iter(mTracker->mConsumers);
     while (iter.HasMore()) {
       mTracker->SendBlockOnload(iter.GetNext());
     }
   }
 
   /* In the case of streaming jpegs, it is possible to get multiple OnStartDecodes which
      indicates the beginning of a new decode.
      The cache entry's size therefore needs to be reset to 0 here.  If we do not do this,
      the code in imgStatusTrackerObserver::OnStopFrame will continue to increase the data size cumulatively.
   */
-  mTracker->GetRequest()->ResetCacheEntry();
+  if (mTracker->GetRequest()) {
+    mTracker->GetRequest()->ResetCacheEntry();
+  }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP imgStatusTrackerObserver::OnStartRequest()
 {
   NS_NOTREACHED("imgRequest(imgIDecoderObserver)::OnStartRequest");
   return NS_OK;
@@ -151,32 +153,34 @@ FireFailureNotification(imgRequest* aReq
 NS_IMETHODIMP imgStatusTrackerObserver::OnStopDecode(nsresult aStatus)
 {
   LOG_SCOPE(gImgLog, "imgStatusTrackerObserver::OnStopDecode");
   NS_ABORT_IF_FALSE(mTracker->GetImage(),
                     "OnStopDecode callback before we've created our image");
 
   // We finished the decode, and thus have the decoded frames. Update the cache
   // entry size to take this into account.
-  mTracker->GetRequest()->UpdateCacheEntrySize();
+  if (mTracker->GetRequest()) {
+    mTracker->GetRequest()->UpdateCacheEntrySize();
+  }
 
   bool preexistingError = mTracker->GetImageStatus() == imgIRequest::STATUS_ERROR;
 
   mTracker->RecordStopDecode(aStatus);
 
   nsTObserverArray<imgRequestProxy*>::ForwardIterator iter(mTracker->mConsumers);
   while (iter.HasMore()) {
     mTracker->SendStopDecode(iter.GetNext(), aStatus);
   }
 
   // This is really hacky. We need to handle the case where we start decoding,
   // block onload, but then hit an error before we get to our first frame.
   mTracker->MaybeUnblockOnload();
 
-  if (NS_FAILED(aStatus) && !preexistingError) {
+  if (NS_FAILED(aStatus) && !preexistingError && mTracker->GetRequest()) {
     FireFailureNotification(mTracker->GetRequest());
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP imgStatusTrackerObserver::OnStopRequest(bool aLastPart)
 {
@@ -188,17 +192,19 @@ NS_IMETHODIMP imgStatusTrackerObserver::
 NS_IMETHODIMP imgStatusTrackerObserver::OnDiscard()
 {
   NS_ABORT_IF_FALSE(mTracker->GetImage(),
                     "OnDiscard callback before we've created our image");
 
   mTracker->RecordDiscard();
 
   // Update the cache entry size, since we just got rid of frame data
-  mTracker->GetRequest()->UpdateCacheEntrySize();
+  if (mTracker->GetRequest()) {
+    mTracker->GetRequest()->UpdateCacheEntrySize();
+  }
 
   nsTObserverArray<imgRequestProxy*>::ForwardIterator iter(mTracker->mConsumers);
   while (iter.HasMore()) {
     mTracker->SendDiscard(iter.GetNext());
   }
 
   return NS_OK;
 }
@@ -697,17 +703,17 @@ imgStatusTracker::OnStopRequest(bool aLa
 
   RecordStopRequest(aLastPart, aStatus);
   /* notify the kids */
   nsTObserverArray<imgRequestProxy*>::ForwardIterator srIter(mConsumers);
   while (srIter.HasMore()) {
     SendStopRequest(srIter.GetNext(), aLastPart, aStatus);
   }
 
-  if (NS_FAILED(aStatus) && !preexistingError) {
+  if (NS_FAILED(aStatus) && !preexistingError && GetRequest()) {
     FireFailureNotification(GetRequest());
   }
 }
 
 void
 imgStatusTracker::OnDataAvailable()
 {
   // Notify any imgRequestProxys that are observing us that we have an Image.