Make the IconLoad hold a ref to the image listener. Fixes race to a crash.

Bug 199021, r=pavlov, sr=dbaron
This commit is contained in:
bzbarsky%mit.edu 2003-04-02 01:35:20 +00:00
parent 76564a67f0
commit 7de4451d8e
4 changed files with 12 additions and 8 deletions

View File

@ -320,8 +320,8 @@ nsImageFrame::Init(nsIPresContext* aPresContext,
PRBool loadBlocked = PR_FALSE;
imageLoader->GetImageBlocked(&loadBlocked);
rv = loadBlocked ? NS_ERROR_IMAGE_BLOCKED : NS_ERROR_FAILURE;
HandleLoadError(rv, presShell);
HandleLoadError(loadBlocked ? NS_ERROR_IMAGE_BLOCKED : NS_ERROR_FAILURE,
presShell);
}
return rv;
@ -1902,7 +1902,7 @@ nsresult nsImageFrame::LoadIcons(nsIPresContext *aPresContext)
#ifdef NOISY_ICON_LOADING
printf( "Allocating IconLoad (%p)\n", this);
#endif
mIconLoad = new IconLoad(aPresContext);
mIconLoad = new IconLoad(aPresContext, mListener);
if (!mIconLoad)
return NS_ERROR_OUT_OF_MEMORY;
doLoad = PR_TRUE;

View File

@ -277,8 +277,9 @@ private:
// private class that wraps the data and logic needed for
// broken image and loading image icons
public:
IconLoad(nsIPresContext *aPresContext)
IconLoad(nsIPresContext *aPresContext, imgIDecoderObserver* aObserver)
: mRefCount(0),
mLoadObserver(aObserver),
mIconsLoaded(PR_FALSE)
{
GetPrefs(aPresContext);
@ -306,6 +307,7 @@ private:
#define NS_ICON_BROKEN_IMAGE (1)
public:
struct SingleIconLoad mIconLoads[2];
nsCOMPtr<imgIDecoderObserver> mLoadObserver; // keeps the observer alive
PRPackedBool mIconsLoaded;
PRPackedBool mPrefForceInlineAltText;
PRPackedBool mPrefAllImagesBlocked;

View File

@ -320,8 +320,8 @@ nsImageFrame::Init(nsIPresContext* aPresContext,
PRBool loadBlocked = PR_FALSE;
imageLoader->GetImageBlocked(&loadBlocked);
rv = loadBlocked ? NS_ERROR_IMAGE_BLOCKED : NS_ERROR_FAILURE;
HandleLoadError(rv, presShell);
HandleLoadError(loadBlocked ? NS_ERROR_IMAGE_BLOCKED : NS_ERROR_FAILURE,
presShell);
}
return rv;
@ -1902,7 +1902,7 @@ nsresult nsImageFrame::LoadIcons(nsIPresContext *aPresContext)
#ifdef NOISY_ICON_LOADING
printf( "Allocating IconLoad (%p)\n", this);
#endif
mIconLoad = new IconLoad(aPresContext);
mIconLoad = new IconLoad(aPresContext, mListener);
if (!mIconLoad)
return NS_ERROR_OUT_OF_MEMORY;
doLoad = PR_TRUE;

View File

@ -277,8 +277,9 @@ private:
// private class that wraps the data and logic needed for
// broken image and loading image icons
public:
IconLoad(nsIPresContext *aPresContext)
IconLoad(nsIPresContext *aPresContext, imgIDecoderObserver* aObserver)
: mRefCount(0),
mLoadObserver(aObserver),
mIconsLoaded(PR_FALSE)
{
GetPrefs(aPresContext);
@ -306,6 +307,7 @@ private:
#define NS_ICON_BROKEN_IMAGE (1)
public:
struct SingleIconLoad mIconLoads[2];
nsCOMPtr<imgIDecoderObserver> mLoadObserver; // keeps the observer alive
PRPackedBool mIconsLoaded;
PRPackedBool mPrefForceInlineAltText;
PRPackedBool mPrefAllImagesBlocked;