Bug 587902, part 1: Allow an imgStatusTracker to be instantiated before its Image. r=joe a=blocking

This commit is contained in:
Daniel Holbert 2010-08-23 15:44:07 -07:00
parent 51f184779e
commit 9bcea9cf08
8 changed files with 36 additions and 12 deletions

View File

@ -41,10 +41,15 @@ namespace mozilla {
namespace imagelib {
// Constructor
Image::Image() :
mStatusTracker(this),
Image::Image(imgStatusTracker* aStatusTracker) :
mInitialized(PR_FALSE)
{
if (aStatusTracker) {
mStatusTracker = aStatusTracker;
mStatusTracker->SetImage(this);
} else {
mStatusTracker = new imgStatusTracker(this);
}
}
// Translates a mimetype into a concrete decoder

View File

@ -48,7 +48,7 @@ namespace imagelib {
class Image : public imgIContainer
{
public:
imgStatusTracker& GetStatusTracker() { return mStatusTracker; }
imgStatusTracker& GetStatusTracker() { return *mStatusTracker; }
PRBool IsInitialized() const { return mInitialized; }
/**
@ -108,11 +108,11 @@ public:
static eDecoderType GetDecoderType(const char *aMimeType);
protected:
Image();
Image(imgStatusTracker* aStatusTracker);
// Member data shared by all implementations of this abstract class
imgStatusTracker mStatusTracker;
PRPackedBool mInitialized; // Have we been initalized?
nsAutoPtr<imgStatusTracker> mStatusTracker;
PRPackedBool mInitialized; // Have we been initalized?
};
} // namespace imagelib

View File

@ -149,7 +149,8 @@ NS_IMPL_ISUPPORTS4(RasterImage, imgIContainer, nsITimerCallback, nsIProperties,
nsISupportsWeakReference)
//******************************************************************************
RasterImage::RasterImage() :
RasterImage::RasterImage(imgStatusTracker* aStatusTracker) :
Image(aStatusTracker), // invoke superclass's constructor
mSize(0,0),
mAnim(nsnull),
mAnimationMode(kNormalAnimMode),
@ -342,8 +343,8 @@ RasterImage::ExtractFrame(PRUint32 aWhichFrame,
img->mFrames.AppendElement(subframe.forget());
img->mStatusTracker.RecordLoaded();
img->mStatusTracker.RecordDecoded();
img->mStatusTracker->RecordLoaded();
img->mStatusTracker->RecordDecoded();
*_retval = img.forget().get();

View File

@ -156,7 +156,7 @@ public:
NS_DECL_NSITIMERCALLBACK
NS_DECL_NSIPROPERTIES
RasterImage();
RasterImage(imgStatusTracker* aStatusTracker = nsnull);
virtual ~RasterImage();
// C++-only version of imgIContainer::GetType, for convenience

View File

@ -204,10 +204,11 @@ nsresult imgRequest::Init(nsIURI *aURI,
mProperties = do_CreateInstance("@mozilla.org/properties;1");
mStatusTracker = new imgStatusTracker(nsnull);
// XXXdholbert For SVG support, this mImage-construction will need to happen
// later -- *after* we know image mimetype.
nsCOMPtr<imgIContainer> comImg = do_CreateInstance("@mozilla.org/image/rasterimage;1");
mImage = static_cast<Image*>(comImg.get());
mImage = new RasterImage(mStatusTracker.forget());
mURI = aURI;
mKeyURI = aKeyURI;

View File

@ -59,6 +59,7 @@
#include "nsWeakReference.h"
#include "ImageErrors.h"
#include "imgIRequest.h"
#include "imgStatusTracker.h"
#include "nsIAsyncVerifyRedirectCallback.h"
class imgCacheValidator;
@ -195,6 +196,8 @@ private:
// The URI we are keyed on in the cache.
nsCOMPtr<nsIURI> mKeyURI;
nsCOMPtr<nsIPrincipal> mPrincipal;
// Status-tracker -- transferred to mImage, when it gets instantiated
nsAutoPtr<imgStatusTracker> mStatusTracker;
nsRefPtr<mozilla::imagelib::Image> mImage;
nsCOMPtr<nsIProperties> mProperties;
nsCOMPtr<nsISupports> mSecurityInfo;

View File

@ -75,6 +75,14 @@ imgStatusTracker::imgStatusTracker(const imgStatusTracker& aOther)
// called.
{}
void
imgStatusTracker::SetImage(Image* aImage)
{
NS_ABORT_IF_FALSE(aImage, "Setting null image");
NS_ABORT_IF_FALSE(!mImage, "Setting image when we already have one");
mImage = aImage;
}
PRBool
imgStatusTracker::IsLoading() const
{

View File

@ -87,6 +87,12 @@ public:
imgStatusTracker(mozilla::imagelib::Image* aImage);
imgStatusTracker(const imgStatusTracker& aOther);
// Image-setter, for imgStatusTrackers created by imgRequest::Init, which
// are created before their Image is created. This method should only
// be called once, and only on an imgStatusTracker that was initialized
// without an image.
void SetImage(mozilla::imagelib::Image* aImage);
// Schedule an asynchronous "replaying" of all the notifications that would
// have to happen to put us in the current state.
// We will also take note of any notifications that happen between the time