Bug 924967 - Dispatch nsIRequest::Cancel to main thread in imgRequest::Cancel r=seth

This commit is contained in:
Steve Workman 2013-10-15 16:33:11 -07:00
parent 134858c6de
commit 000699ecd8
2 changed files with 38 additions and 5 deletions

View File

@ -245,6 +245,28 @@ void imgRequest::CancelAndAbort(nsresult aStatus)
}
}
class imgRequestMainThreadCancel : public nsRunnable
{
public:
imgRequestMainThreadCancel(imgRequest *aImgRequest, nsresult aStatus)
: mImgRequest(aImgRequest)
, mStatus(aStatus)
{
MOZ_ASSERT(!NS_IsMainThread(), "Create me off main thread only!");
MOZ_ASSERT(aImgRequest);
}
NS_IMETHOD Run()
{
MOZ_ASSERT(NS_IsMainThread(), "I should be running on the main thread!");
mImgRequest->ContinueCancel(mStatus);
return NS_OK;
}
private:
nsRefPtr<imgRequest> mImgRequest;
nsresult mStatus;
};
void imgRequest::Cancel(nsresult aStatus)
{
/* The Cancel() method here should only be called by this class. */
@ -258,14 +280,22 @@ void imgRequest::Cancel(nsresult aStatus)
statusTracker->RecordCancel();
if (NS_IsMainThread()) {
RemoveFromCache();
ContinueCancel(aStatus);
} else {
NS_DispatchToMainThread(
NS_NewRunnableMethod(this, &imgRequest::RemoveFromCache));
NS_DispatchToMainThread(new imgRequestMainThreadCancel(this, aStatus));
}
}
if (mRequest && statusTracker->IsLoading())
mRequest->Cancel(aStatus);
void imgRequest::ContinueCancel(nsresult aStatus)
{
MOZ_ASSERT(NS_IsMainThread());
RemoveFromCache();
nsRefPtr<imgStatusTracker> statusTracker = GetStatusTracker();
if (mRequest && statusTracker->IsLoading()) {
mRequest->Cancel(aStatus);
}
}
nsresult imgRequest::GetURI(ImageURL **aURI)

View File

@ -72,6 +72,9 @@ public:
// won't be sufficient.
void CancelAndAbort(nsresult aStatus);
// Called or dispatched by cancel for main thread only execution.
void ContinueCancel(nsresult aStatus);
// Methods that get forwarded to the Image, or deferred until it's
// instantiated.
nsresult LockImage();