Bug 913247: Don't call imgIContainer::RequestRefresh during hashtable enumeration. r=jwatt

This commit is contained in:
Daniel Holbert 2013-09-06 09:48:26 +01:00
parent 07f5f8bf07
commit d79f00f8b6

View File

@ -1157,7 +1157,18 @@ nsRefreshDriver::Tick(int64_t aNowEpoch, TimeStamp aNowTime)
mStartTable.EnumerateRead(nsRefreshDriver::StartTableRefresh, &parms);
if (mRequests.Count()) {
mRequests.EnumerateEntries(nsRefreshDriver::ImageRequestEnumerator, &parms);
// RequestRefresh may run scripts, so it's not safe to directly call it
// while using a hashtable enumerator to enumerate mRequests in case
// script modifies the hashtable. Instead, we build a (local) array of
// images to refresh, and then we refresh each image in that array.
nsCOMArray<imgIContainer> imagesToRefresh(mRequests.Count());
mRequests.EnumerateEntries(nsRefreshDriver::ImageRequestEnumerator,
&imagesToRefresh);
for (uint32_t i = 0; i < imagesToRefresh.Length(); i++) {
imagesToRefresh[i]->RequestRefresh(aNowTime);
}
imagesToRefresh.Clear();
}
for (uint32_t i = 0; i < mPresShellsToInvalidateIfHidden.Length(); i++) {
@ -1194,14 +1205,13 @@ nsRefreshDriver::Tick(int64_t aNowEpoch, TimeStamp aNowTime)
nsRefreshDriver::ImageRequestEnumerator(nsISupportsHashKey* aEntry,
void* aUserArg)
{
ImageRequestParameters* parms =
static_cast<ImageRequestParameters*> (aUserArg);
mozilla::TimeStamp mostRecentRefresh = parms->mCurrent;
nsCOMArray<imgIContainer>* imagesToRefresh =
static_cast<nsCOMArray<imgIContainer>*> (aUserArg);
imgIRequest* req = static_cast<imgIRequest*>(aEntry->GetKey());
NS_ABORT_IF_FALSE(req, "Unable to retrieve the image request");
nsCOMPtr<imgIContainer> image;
if (NS_SUCCEEDED(req->GetImage(getter_AddRefs(image)))) {
image->RequestRefresh(mostRecentRefresh);
imagesToRefresh->AppendElement(image);
}
return PL_DHASH_NEXT;