Bug 689623. Part 2. In nsImageLoadingContent make the discard request an optional part of UntrackImage so that we can use UntrackImage everywhere instead of RemoveImage. r=joe
authorTimothy Nikkel <tnikkel@gmail.com>
Sun, 24 Feb 2013 18:59:21 -0600
changeset 122843 7027a245b90a4513ba311198dbc1a897d7620ae8
parent 122842 37f6664e8f1ed9c17c405f6b2eccbba4f65b7f16
child 122844 ca13b79b1e51cb69a16b817d60e23afb953626dd
push id1387
push userphilringnalda@gmail.com
push dateTue, 26 Feb 2013 22:32:56 +0000
treeherderfx-team@ad4cc4e97774 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjoe
bugs689623
milestone22.0a1
Bug 689623. Part 2. In nsImageLoadingContent make the discard request an optional part of UntrackImage so that we can use UntrackImage everywhere instead of RemoveImage. r=joe
content/base/src/nsImageLoadingContent.cpp
content/base/src/nsImageLoadingContent.h
--- a/content/base/src/nsImageLoadingContent.cpp
+++ b/content/base/src/nsImageLoadingContent.cpp
@@ -418,30 +418,18 @@ nsImageLoadingContent::FrameDestroyed(ns
   }
 
   if (mPendingRequest) {
     nsLayoutUtils::DeregisterImageRequest(GetFramePresContext(),
                                           mPendingRequest,
                                           &mPendingRequestRegistered);
   }
 
-  if (mCurrentRequest && (mCurrentRequestFlags & REQUEST_IS_TRACKED)) {
-    nsIDocument* doc = GetOurCurrentDoc();
-    if (doc) {
-      mCurrentRequestFlags &= ~REQUEST_IS_TRACKED;
-      doc->RemoveImage(mCurrentRequest);
-    }
-  }
-  if (mPendingRequest && (mPendingRequestFlags & REQUEST_IS_TRACKED)) {
-    nsIDocument* doc = GetOurCurrentDoc();
-    if (doc) {
-      mPendingRequestFlags &= ~REQUEST_IS_TRACKED;
-      doc->RemoveImage(mPendingRequest);
-    }
-  }
+  UntrackImage(mCurrentRequest);
+  UntrackImage(mPendingRequest);
 }
 
 int32_t
 nsImageLoadingContent::GetRequestType(imgIRequest* aRequest,
                                       ErrorResult& aError)
 {
   if (aRequest == mCurrentRequest) {
     return CURRENT_REQUEST;
@@ -1096,17 +1084,17 @@ nsImageLoadingContent::ClearCurrentReque
                     "Shouldn't have both mCurrentRequest and mCurrentURI!");
 
   // Deregister this image from the refresh driver so it no longer receives
   // notifications.
   nsLayoutUtils::DeregisterImageRequest(GetFramePresContext(), mCurrentRequest,
                                         &mCurrentRequestRegistered);
 
   // Clean up the request.
-  UntrackImage(mCurrentRequest);
+  UntrackImage(mCurrentRequest, REQUEST_DISCARD);
   mCurrentRequest->CancelAndForgetObserver(aReason);
   mCurrentRequest = nullptr;
   mCurrentRequestFlags = 0;
 }
 
 void
 nsImageLoadingContent::ClearPendingRequest(nsresult aReason)
 {
@@ -1119,17 +1107,17 @@ nsImageLoadingContent::ClearPendingReque
   nsCxPusher pusher;
   pusher.PushNull();
 
   // Deregister this image from the refresh driver so it no longer receives
   // notifications.
   nsLayoutUtils::DeregisterImageRequest(GetFramePresContext(), mPendingRequest,
                                         &mPendingRequestRegistered);
 
-  UntrackImage(mPendingRequest);
+  UntrackImage(mPendingRequest, REQUEST_DISCARD);
   mPendingRequest->CancelAndForgetObserver(aReason);
   mPendingRequest = nullptr;
   mPendingRequestFlags = 0;
 }
 
 bool*
 nsImageLoadingContent::GetRegisteredFlagForRequest(imgIRequest* aRequest)
 {
@@ -1206,24 +1194,18 @@ nsImageLoadingContent::UnbindFromTree(bo
   if (!doc)
     return;
 
   // Push a null JSContext on the stack so that callbacks triggered by the
   // below code won't think they're being called from JS.
   nsCxPusher pusher;
   pusher.PushNull();
 
-  if (mCurrentRequest && (mCurrentRequestFlags & REQUEST_IS_TRACKED)) {
-    mCurrentRequestFlags &= ~REQUEST_IS_TRACKED;
-    doc->RemoveImage(mCurrentRequest);
-  }
-  if (mPendingRequest && (mPendingRequestFlags & REQUEST_IS_TRACKED)) {
-    mPendingRequestFlags &= ~REQUEST_IS_TRACKED;
-    doc->RemoveImage(mPendingRequest);
-  }
+  UntrackImage(mCurrentRequest);
+  UntrackImage(mPendingRequest);
 
   if (mCurrentRequestFlags & REQUEST_BLOCKS_ONLOAD)
     doc->UnblockOnload(false);
 }
 
 nsresult
 nsImageLoadingContent::TrackImage(imgIRequest* aImage)
 {
@@ -1243,36 +1225,38 @@ nsImageLoadingContent::TrackImage(imgIRe
       mPendingRequestFlags |= REQUEST_IS_TRACKED;
       doc->AddImage(mPendingRequest);
     }
   }
   return NS_OK;
 }
 
 nsresult
-nsImageLoadingContent::UntrackImage(imgIRequest* aImage)
+nsImageLoadingContent::UntrackImage(imgIRequest* aImage, uint32_t aFlags /* = 0 */)
 {
   if (!aImage)
     return NS_OK;
 
   MOZ_ASSERT(aImage == mCurrentRequest || aImage == mPendingRequest,
              "Why haven't we heard of this request?");
 
   // If GetOurDocument() returns null here, we've outlived our document.
   // That's fine, because the document empties out the tracker and unlocks
   // all locked images on destruction.
   nsIDocument* doc = GetOurCurrentDoc();
   if (doc) {
     if (aImage == mCurrentRequest && (mCurrentRequestFlags & REQUEST_IS_TRACKED)) {
       mCurrentRequestFlags &= ~REQUEST_IS_TRACKED;
-      doc->RemoveImage(mCurrentRequest, nsIDocument::REQUEST_DISCARD);
+      doc->RemoveImage(mCurrentRequest,
+                       (aFlags & REQUEST_DISCARD) ? nsIDocument::REQUEST_DISCARD : 0);
     }
     if (aImage == mPendingRequest && (mPendingRequestFlags & REQUEST_IS_TRACKED)) {
       mPendingRequestFlags &= ~REQUEST_IS_TRACKED;
-      doc->RemoveImage(mPendingRequest, nsIDocument::REQUEST_DISCARD);
+      doc->RemoveImage(mPendingRequest,
+                       (aFlags & REQUEST_DISCARD) ? nsIDocument::REQUEST_DISCARD : 0);
     }
   }
   return NS_OK;
 }
 
 
 void
 nsImageLoadingContent::CreateStaticImageClone(nsImageLoadingContent* aDest) const
--- a/content/base/src/nsImageLoadingContent.h
+++ b/content/base/src/nsImageLoadingContent.h
@@ -321,19 +321,25 @@ protected:
    * image may be null.
    */
   static bool HaveSize(imgIRequest *aImage);
 
   /**
    * Adds/Removes a given imgIRequest from our document's tracker.
    *
    * No-op if aImage is null.
+   *
+   * REQUEST_DISCARD passed to UntrackImage means we request the discard of the
+   * decoded data of the image.
    */
   nsresult TrackImage(imgIRequest* aImage);
-  nsresult UntrackImage(imgIRequest* aImage);
+  enum {
+    REQUEST_DISCARD = 0x1
+  };
+  nsresult UntrackImage(imgIRequest* aImage, uint32_t aFlags = 0);
 
   /* MEMBERS */
   nsRefPtr<imgRequestProxy> mCurrentRequest;
   nsRefPtr<imgRequestProxy> mPendingRequest;
   uint32_t mCurrentRequestFlags;
   uint32_t mPendingRequestFlags;
 
   enum {