Bug 505385 - Part 7: Initialize imgRequestProxy with a status tracker. r=joe
authorBobby Holley <bobbyholley@gmail.com>
Fri, 12 Oct 2012 12:11:21 -0400
changeset 110231 ea55032b7fd937a45c15ca8eead9160d9d8f34da
parent 110230 a8c623232db48ae088cf371f8883a545e9a3716e
child 110232 8b08ff14b2460e3475c3a374f8d64b295df39bd0
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersjoe
bugs505385
milestone19.0a1
Bug 505385 - Part 7: Initialize imgRequestProxy with a status tracker. r=joe This is sort of symbolic for now, since we keep mOwner and mImage and just pull them off the tracker, but we'll soon change that. ;-)
image/src/imgLoader.cpp
image/src/imgRequestProxy.cpp
image/src/imgRequestProxy.h
--- a/image/src/imgLoader.cpp
+++ b/image/src/imgLoader.cpp
@@ -703,17 +703,17 @@ nsresult imgLoader::CreateNewProxyForReq
      |Init()| adds the request to the loadgroup.
    */
   proxyRequest->SetLoadFlags(aLoadFlags);
 
   nsCOMPtr<nsIURI> uri;
   aRequest->GetURI(getter_AddRefs(uri));
 
   // init adds itself to imgRequest's list of observers
-  nsresult rv = proxyRequest->Init(aRequest, aLoadGroup, aRequest->mImage, uri, aObserver);
+  nsresult rv = proxyRequest->Init(&aRequest->GetStatusTracker(), aLoadGroup, uri, aObserver);
   if (NS_FAILED(rv)) {
     NS_RELEASE(proxyRequest);
     return rv;
   }
 
   // transfer reference to caller
   *_retval = static_cast<imgIRequest*>(proxyRequest);
 
--- a/image/src/imgRequestProxy.cpp
+++ b/image/src/imgRequestProxy.cpp
@@ -83,36 +83,38 @@ imgRequestProxy::~imgRequestProxy()
          the last observer.  This allows the image to continue to download and
          be cached even if no one is using it currently.
        */
       mOwner->RemoveProxy(this, NS_OK);
     }
   }
 }
 
-nsresult imgRequestProxy::Init(imgRequest* request, nsILoadGroup* aLoadGroup, Image* aImage,
+nsresult imgRequestProxy::Init(imgStatusTracker* aStatusTracker,
+                               nsILoadGroup* aLoadGroup,
                                nsIURI* aURI, imgIDecoderObserver* aObserver)
 {
   NS_PRECONDITION(!mOwner && !mListener, "imgRequestProxy is already initialized");
 
-  LOG_SCOPE_WITH_PARAM(gImgLog, "imgRequestProxy::Init", "request", request);
+  LOG_SCOPE_WITH_PARAM(gImgLog, "imgRequestProxy::Init", "request", aStatusTracker->GetRequest());
 
   NS_ABORT_IF_FALSE(mAnimationConsumers == 0, "Cannot have animation before Init");
 
-  mOwner = request;
+  mStatusTracker = aStatusTracker;
+  mOwner = aStatusTracker->GetRequest();
   mListener = aObserver;
   // Make sure to addref mListener before the AddProxy call below, since
   // that call might well want to release it if the imgRequest has
   // already seen OnStopRequest.
   if (mListener) {
     mListenerIsStrongRef = true;
     NS_ADDREF(mListener);
   }
   mLoadGroup = aLoadGroup;
-  mImage = aImage;
+  mImage = aStatusTracker->GetImage();
   mURI = aURI;
 
   // Note: AddProxy won't send all the On* notifications immediately
   if (mOwner)
     mOwner->AddProxy(this);
 
   return NS_OK;
 }
@@ -497,19 +499,17 @@ NS_IMETHODIMP imgRequestProxy::Clone(img
 
   // It is important to call |SetLoadFlags()| before calling |Init()| because
   // |Init()| adds the request to the loadgroup.
   // When a request is added to a loadgroup, its load flags are merged
   // with the load flags of the loadgroup.
   // XXXldb That's not true anymore.  Stuff from imgLoader adds the
   // request to the loadgroup.
   clone->SetLoadFlags(mLoadFlags);
-  nsresult rv = clone->Init(mOwner, mLoadGroup,
-                            mImage ? mImage : mOwner->mImage,
-                            mURI, aObserver);
+  nsresult rv = clone->Init(mStatusTracker, mLoadGroup, mURI, aObserver);
   if (NS_FAILED(rv))
     return rv;
 
   // Assign to *aClone before calling Notify so that if the caller expects to
   // only be notified for requests it's already holding pointers to it won't be
   // surprised.
   NS_ADDREF(*aClone = clone);
 
@@ -846,17 +846,17 @@ imgRequestProxy::GetStaticRequest(imgIRe
     return rv;
 
   nsRefPtr<Image> frame = static_cast<Image*>(currentFrame.get());
 
   // Create a static imgRequestProxy with our new extracted frame.
   nsCOMPtr<nsIPrincipal> currentPrincipal;
   GetImagePrincipal(getter_AddRefs(currentPrincipal));
   nsRefPtr<imgRequestProxy> req = new imgRequestProxyStatic(currentPrincipal);
-  req->Init(nullptr, nullptr, frame, mURI, nullptr);
+  req->Init(&frame->GetStatusTracker(), nullptr, mURI, nullptr);
 
   NS_ADDREF(*aReturn = req);
 
   return NS_OK;
 }
 
 void imgRequestProxy::NotifyListener()
 {
--- a/image/src/imgRequestProxy.h
+++ b/image/src/imgRequestProxy.h
@@ -52,18 +52,18 @@ public:
   NS_DECL_NSISECURITYINFOPROVIDER
   // nsITimedChannel declared below
 
   imgRequestProxy();
   virtual ~imgRequestProxy();
 
   // Callers to Init or ChangeOwner are required to call NotifyListener after
   // (although not immediately after) doing so.
-  nsresult Init(imgRequest *request, nsILoadGroup *aLoadGroup,
-                mozilla::image::Image* aImage,
+  nsresult Init(imgStatusTracker* aStatusTracker,
+                nsILoadGroup *aLoadGroup,
                 nsIURI* aURI, imgIDecoderObserver *aObserver);
 
   nsresult ChangeOwner(imgRequest *aNewOwner); // this will change mOwner.  Do not call this if the previous
                                                // owner has already sent notifications out!
 
   void AddToLoadGroup();
   void RemoveFromLoadGroup(bool releaseLoadGroup);
 
@@ -187,16 +187,19 @@ private:
   // We maintain the following invariant:
   // The proxy is registered at most with a single imgRequest as an observer,
   // and whenever it is, mOwner points to that object. This helps ensure that
   // imgRequestProxy::~imgRequestProxy unregisters the proxy as an observer
   // from whatever request it was registered with (if any). This, in turn,
   // means that imgRequest::mObservers will not have any stale pointers in it.
   nsRefPtr<imgRequest> mOwner;
 
+  // Weak pointer to the status tracker.
+  imgStatusTracker* mStatusTracker;
+
   // The URI of our request.
   nsCOMPtr<nsIURI> mURI;
 
   // The image we represent. Is null until data has been received, and is then
   // set by imgRequest.
   nsRefPtr<mozilla::image::Image> mImage;
 
   // mListener is only promised to be a weak ref (see imgILoader.idl),