Bug 513681 - part 3 - instantiate decoders without using COM goop.r=joe,a=blocker

This commit is contained in:
Bobby Holley 2010-08-22 22:30:45 -04:00
parent 8d69ad0207
commit 315c1087fb
5 changed files with 101 additions and 11 deletions

View File

@ -47,5 +47,52 @@ Image::Image() :
{
}
// Translates a mimetype into a concrete decoder
Image::eDecoderType
Image::GetDecoderType(const char *aMimeType)
{
// By default we don't know
eDecoderType rv = eDecoderType_unknown;
// PNG
if (!strcmp(aMimeType, "image/png"))
rv = eDecoderType_png;
else if (!strcmp(aMimeType, "image/x-png"))
rv = eDecoderType_png;
// GIF
else if (!strcmp(aMimeType, "image/gif"))
rv = eDecoderType_gif;
// JPEG
else if (!strcmp(aMimeType, "image/jpeg"))
rv = eDecoderType_jpeg;
else if (!strcmp(aMimeType, "image/pjpeg"))
rv = eDecoderType_jpeg;
else if (!strcmp(aMimeType, "image/jpg"))
rv = eDecoderType_jpeg;
// BMP
else if (!strcmp(aMimeType, "image/bmp"))
rv = eDecoderType_bmp;
else if (!strcmp(aMimeType, "image/x-ms-bmp"))
rv = eDecoderType_bmp;
// ICO
else if (!strcmp(aMimeType, "image/x-icon"))
rv = eDecoderType_ico;
else if (!strcmp(aMimeType, "image/vnd.microsoft.icon"))
rv = eDecoderType_ico;
// Icon
else if (!strcmp(aMimeType, "image/icon"))
rv = eDecoderType_icon;
return rv;
}
} // namespace imagelib
} // namespace mozilla

View File

@ -107,6 +107,18 @@ public:
*/
virtual PRUint32 GetDataSize() = 0;
// Mimetype translation
enum eDecoderType {
eDecoderType_png = 0,
eDecoderType_gif = 1,
eDecoderType_jpeg = 2,
eDecoderType_bmp = 3,
eDecoderType_ico = 4,
eDecoderType_icon = 5,
eDecoderType_unknown = 6
};
static eDecoderType GetDecoderType(const char *aMimeType);
protected:
Image();

View File

@ -62,6 +62,11 @@ CPPSRCS = \
imgStatusTracker.cpp \
$(NULL)
LOCAL_INCLUDES += -I$(topsrcdir)/modules/libpr0n/decoders/bmp
LOCAL_INCLUDES += -I$(topsrcdir)/modules/libpr0n/decoders/gif
LOCAL_INCLUDES += -I$(topsrcdir)/modules/libpr0n/decoders/jpeg
LOCAL_INCLUDES += -I$(topsrcdir)/modules/libpr0n/decoders/png
include $(topsrcdir)/config/rules.mk
# Because imgFrame.cpp includes "cairo.h"

View File

@ -58,6 +58,13 @@
#include "nsTime.h"
#include "ImageLogging.h"
#include "nsPNGDecoder.h"
#include "nsGIFDecoder2.h"
#include "nsJPEGDecoder.h"
#include "nsBMPDecoder.h"
#include "nsICODecoder.h"
#include "nsIconDecoder.h"
#include "gfxContext.h"
using namespace mozilla::imagelib;
@ -2107,11 +2114,33 @@ RasterImage::InitDecoder(PRUint32 dFlags)
// Since we're not decoded, we should not have a discard timer active
NS_ABORT_IF_FALSE(!DiscardingActive(), "Discard Timer active in InitDecoder()!");
// Find and instantiate the decoder
nsCAutoString decoderCID(NS_LITERAL_CSTRING("@mozilla.org/image/decoder;3?type=") +
mSourceDataMimeType);
mDecoder = do_CreateInstance(decoderCID.get());
CONTAINER_ENSURE_TRUE(mDecoder, NS_IMAGELIB_ERROR_NO_DECODER);
// Figure out which decoder we want
eDecoderType type = GetDecoderType(mSourceDataMimeType.get());
CONTAINER_ENSURE_TRUE(type != eDecoderType_unknown, NS_IMAGELIB_ERROR_NO_DECODER);
// Instantiate the appropriate decoder
switch (type) {
case eDecoderType_png:
mDecoder = new nsPNGDecoder();
break;
case eDecoderType_gif:
mDecoder = new nsGIFDecoder2();
break;
case eDecoderType_jpeg:
mDecoder = new nsJPEGDecoder();
break;
case eDecoderType_bmp:
mDecoder = new nsBMPDecoder();
break;
case eDecoderType_ico:
mDecoder = new nsICODecoder();
break;
case eDecoderType_icon:
mDecoder = new nsIconDecoder();
break;
default:
NS_ABORT_IF_FALSE(0, "Shouldn't get here!");
}
// Store the flags for this decoder
mDecoderFlags = dFlags;

View File

@ -1853,14 +1853,11 @@ NS_IMETHODIMP imgLoader::LoadImageWithChannel(nsIChannel *channel, imgIDecoderOb
NS_IMETHODIMP imgLoader::SupportImageWithMimeType(const char* aMimeType, PRBool *_retval)
{
*_retval = PR_FALSE;
nsCOMPtr<nsIComponentRegistrar> reg;
nsresult rv = NS_GetComponentRegistrar(getter_AddRefs(reg));
if (NS_FAILED(rv))
return rv;
nsCAutoString mimeType(aMimeType);
ToLowerCase(mimeType);
nsCAutoString decoderId(NS_LITERAL_CSTRING("@mozilla.org/image/decoder;3?type=") + mimeType);
return reg->IsContractIDRegistered(decoderId.get(), _retval);
*_retval = (Image::GetDecoderType(mimeType.get()) == Image::eDecoderType_unknown)
? PR_FALSE : PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP imgLoader::GetMIMETypeFromContent(nsIRequest* aRequest,