Bug 505385 - Part 2: Move notification dispatch into imgStatusTracker. r=joe

This commit is contained in:
Bobby Holley 2012-10-11 21:34:22 -04:00
parent ee2a546a5b
commit 9abde7bec9
4 changed files with 37 additions and 27 deletions

View File

@ -188,8 +188,6 @@ void imgRequest::AddProxy(imgRequestProxy *proxy)
mLoader->SetHasProxies(mURI);
}
proxy->SetPrincipal(mPrincipal);
GetStatusTracker().AddConsumer(proxy);
}
@ -831,12 +829,6 @@ NS_IMETHODIMP imgRequest::OnStartRequest(nsIRequest *aRequest, nsISupports *ctxt
if (NS_FAILED(rv)) {
return rv;
}
// Tell all of our proxies that we have a principal.
nsTObserverArray<imgRequestProxy*>::ForwardIterator iter(GetStatusTracker().GetConsumers());
while (iter.HasMore()) {
iter.GetNext()->SetPrincipal(mPrincipal);
}
}
}

View File

@ -109,6 +109,9 @@ public:
return principal.forget();
}
// Get the current principal of the image. No AddRefing.
inline nsIPrincipal* GetPrincipal() const { return mPrincipal.get(); };
private:
friend class imgCacheEntry;
friend class imgRequestProxy;

View File

@ -41,7 +41,6 @@ imgRequestProxy::imgRequestProxy() :
mOwner(nullptr),
mURI(nullptr),
mImage(nullptr),
mPrincipal(nullptr),
mListener(nullptr),
mLoadFlags(nsIRequest::LOAD_NORMAL),
mLockCount(0),
@ -509,8 +508,6 @@ NS_IMETHODIMP imgRequestProxy::Clone(imgIDecoderObserver* aObserver,
if (NS_FAILED(rv))
return rv;
clone->SetPrincipal(mPrincipal);
// 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.
@ -526,11 +523,10 @@ NS_IMETHODIMP imgRequestProxy::Clone(imgIDecoderObserver* aObserver,
/* readonly attribute nsIPrincipal imagePrincipal; */
NS_IMETHODIMP imgRequestProxy::GetImagePrincipal(nsIPrincipal **aPrincipal)
{
if (!mPrincipal)
if (!mOwner)
return NS_ERROR_FAILURE;
NS_ADDREF(*aPrincipal = mPrincipal);
NS_ADDREF(*aPrincipal = mOwner->GetPrincipal());
return NS_OK;
}
@ -852,20 +848,16 @@ imgRequestProxy::GetStaticRequest(imgIRequest** aReturn)
nsRefPtr<Image> frame = static_cast<Image*>(currentFrame.get());
// Create a static imgRequestProxy with our new extracted frame.
nsRefPtr<imgRequestProxy> req = new imgRequestProxy();
nsCOMPtr<nsIPrincipal> currentPrincipal;
GetImagePrincipal(getter_AddRefs(currentPrincipal));
nsRefPtr<imgRequestProxy> req = new imgRequestProxyStatic(currentPrincipal);
req->Init(nullptr, nullptr, frame, mURI, nullptr);
req->SetPrincipal(mPrincipal);
NS_ADDREF(*aReturn = req);
return NS_OK;
}
void imgRequestProxy::SetPrincipal(nsIPrincipal *aPrincipal)
{
mPrincipal = aPrincipal;
}
void imgRequestProxy::NotifyListener()
{
// It would be nice to notify the observer directly in the status tracker
@ -924,3 +916,15 @@ imgRequestProxy::GetStatusTracker()
// mOwner with a non-null mImage (and a null mStatusTracker pointer).
return mImage ? mImage->GetStatusTracker() : mOwner->GetStatusTracker();
}
////////////////// imgRequestProxyStatic methods
NS_IMETHODIMP imgRequestProxyStatic::GetImagePrincipal(nsIPrincipal **aPrincipal)
{
if (!mPrincipal)
return NS_ERROR_FAILURE;
NS_ADDREF(*aPrincipal = mPrincipal);
return NS_OK;
}

View File

@ -71,8 +71,6 @@ public:
return mListener != nullptr;
}
void SetPrincipal(nsIPrincipal *aPrincipal);
// Asynchronously notify this proxy's listener of the current state of the
// image, and, if we have an imgRequest mOwner, any status changes that
// happen between the time this function is called and the time the
@ -201,10 +199,6 @@ private:
// set by imgRequest.
nsRefPtr<mozilla::image::Image> mImage;
// Our principal. Is null until data has been received from the channel, and
// is then set by imgRequest.
nsCOMPtr<nsIPrincipal> mPrincipal;
// mListener is only promised to be a weak ref (see imgILoader.idl),
// but we actually keep a strong ref to it until we've seen our
// first OnStopRequest.
@ -228,4 +222,21 @@ private:
bool mSentStartContainer;
};
// Used for static image proxies for which no requests are available, so
// certain behaviours must be overridden to compensate.
class imgRequestProxyStatic : public imgRequestProxy
{
public:
imgRequestProxyStatic(nsIPrincipal* aPrincipal) : mPrincipal(aPrincipal) {};
NS_IMETHOD GetImagePrincipal(nsIPrincipal** aPrincipal);
protected:
// Our principal. We have to cache it, rather than accessing the underlying
// request on-demand, because static proxies don't have an underlying request.
nsCOMPtr<nsIPrincipal> mPrincipal;
};
#endif // imgRequestProxy_h__