Bug 1184996 (Part 4) - Forbid instantiation of decoders except via DecoderFactory. r=tn

This commit is contained in:
Seth Fowler 2015-07-22 22:39:56 -07:00
parent ff2b61cc0f
commit a0d4f607c9
10 changed files with 49 additions and 17 deletions

View File

@ -424,7 +424,6 @@ Decoder::SetSizeOnImage()
*/
void Decoder::InitInternal() { }
void Decoder::WriteInternal(const char* aBuffer, uint32_t aCount) { }
void Decoder::FinishInternal() { }
void Decoder::FinishWithErrorInternal() { }

View File

@ -285,7 +285,7 @@ protected:
* only these methods.
*/
virtual void InitInternal();
virtual void WriteInternal(const char* aBuffer, uint32_t aCount);
virtual void WriteInternal(const char* aBuffer, uint32_t aCount) = 0;
virtual void FinishInternal();
virtual void FinishWithErrorInternal();

View File

@ -67,10 +67,10 @@ DecoderFactory::GetDecoderType(const char* aMimeType)
return type;
}
static already_AddRefed<Decoder>
GetDecoder(DecoderType aType,
RasterImage* aImage,
bool aIsRedecode)
/* static */ already_AddRefed<Decoder>
DecoderFactory::GetDecoder(DecoderType aType,
RasterImage* aImage,
bool aIsRedecode)
{
nsRefPtr<Decoder> decoder;

View File

@ -91,6 +91,13 @@ public:
private:
virtual ~DecoderFactory() = 0;
/**
* An internal method which allocates a new decoder of the requested @aType.
*/
static already_AddRefed<Decoder> GetDecoder(DecoderType aType,
RasterImage* aImage,
bool aIsRedecode);
};
} // namespace image

View File

@ -22,8 +22,6 @@ class RasterImage;
class nsBMPDecoder : public Decoder
{
public:
explicit nsBMPDecoder(RasterImage* aImage);
~nsBMPDecoder();
// Specifies whether or not the BMP file will contain alpha data
@ -55,6 +53,12 @@ public:
virtual void FinishInternal() override;
private:
friend class DecoderFactory;
friend class nsICODecoder;
// Decoders should only be instantiated via DecoderFactory.
// XXX(seth): nsICODecoder is temporarily an exception to this rule.
explicit nsBMPDecoder(RasterImage* aImage);
/// Calculates the red-, green- and blueshift in mBitFields using
/// the bitmasks from mBitFields

View File

@ -22,8 +22,6 @@ class RasterImage;
class nsGIFDecoder2 : public Decoder
{
public:
explicit nsGIFDecoder2(RasterImage* aImage);
~nsGIFDecoder2();
virtual void WriteInternal(const char* aBuffer, uint32_t aCount) override;
@ -31,9 +29,13 @@ public:
virtual Telemetry::ID SpeedHistogram() override;
private:
friend class DecoderFactory;
// Decoders should only be instantiated via DecoderFactory.
explicit nsGIFDecoder2(RasterImage* aImage);
// These functions will be called when the decoder has a decoded row,
// frame size information, etc.
void BeginGIF();
nsresult BeginImageFrame(uint16_t aDepth);
void EndImageFrame();

View File

@ -22,8 +22,6 @@ class RasterImage;
class nsICODecoder : public Decoder
{
public:
explicit nsICODecoder(RasterImage* aImage);
virtual ~nsICODecoder();
// Obtains the width of the icon directory entry
@ -43,6 +41,11 @@ public:
virtual void FinishWithErrorInternal() override;
private:
friend class DecoderFactory;
// Decoders should only be instantiated via DecoderFactory.
explicit nsICODecoder(RasterImage* aImage);
// Writes to the contained decoder and sets the appropriate errors
// Returns true if there are no errors.
bool WriteToContainedDecoder(const char* aBuffer, uint32_t aCount);

View File

@ -37,12 +37,17 @@ class RasterImage;
class nsIconDecoder : public Decoder
{
public:
explicit nsIconDecoder(RasterImage* aImage);
virtual ~nsIconDecoder();
virtual void WriteInternal(const char* aBuffer, uint32_t aCount) override;
private:
friend class DecoderFactory;
// Decoders should only be instantiated via DecoderFactory.
explicit nsIconDecoder(RasterImage* aImage);
public:
uint8_t mWidth;
uint8_t mHeight;
uint32_t mPixBytesRead;

View File

@ -53,7 +53,6 @@ struct Orientation;
class nsJPEGDecoder : public Decoder
{
public:
nsJPEGDecoder(RasterImage* aImage, Decoder::DecodeStyle aDecodeStyle);
virtual ~nsJPEGDecoder();
virtual nsresult SetTargetSize(const nsIntSize& aSize) override;
@ -71,6 +70,12 @@ protected:
Maybe<Downscaler> mDownscaler;
private:
friend class DecoderFactory;
// Decoders should only be instantiated via DecoderFactory.
nsJPEGDecoder(RasterImage* aImage, Decoder::DecodeStyle aDecodeStyle);
public:
struct jpeg_decompress_struct mInfo;
struct jpeg_source_mgr mSourceMgr;

View File

@ -24,7 +24,6 @@ class RasterImage;
class nsPNGDecoder : public Decoder
{
public:
explicit nsPNGDecoder(RasterImage* aImage);
virtual ~nsPNGDecoder();
virtual void InitInternal() override;
@ -67,6 +66,14 @@ public:
}
}
private:
friend class DecoderFactory;
friend class nsICODecoder;
// Decoders should only be instantiated via DecoderFactory.
// XXX(seth): nsICODecoder is temporarily an exception to this rule.
explicit nsPNGDecoder(RasterImage* aImage);
public:
png_structp mPNG;
png_infop mInfo;