Bug 822846 - Use nsMimeTypes.h instead of working with literal strings in imagelib. r=joe

This commit is contained in:
Seth Fowler 2012-12-19 13:33:56 -08:00
parent 35e2d6a5da
commit d8f9d47626
17 changed files with 68 additions and 55 deletions

View File

@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/ModuleUtils.h"
#include "nsMimeTypes.h"
#include "RasterImage.h"
@ -61,25 +62,25 @@ static const mozilla::Module::ContractIDEntry kImageContracts[] = {
{ "@mozilla.org/image/loader;1", &kNS_IMGLOADER_CID },
{ "@mozilla.org/image/request;1", &kNS_IMGREQUESTPROXY_CID },
{ "@mozilla.org/image/tools;1", &kNS_IMGTOOLS_CID },
{ "@mozilla.org/image/encoder;2?type=image/vnd.microsoft.icon", &kNS_ICOENCODER_CID },
{ "@mozilla.org/image/encoder;2?type=image/jpeg", &kNS_JPEGENCODER_CID },
{ "@mozilla.org/image/encoder;2?type=image/png", &kNS_PNGENCODER_CID },
{ "@mozilla.org/image/encoder;2?type=image/bmp", &kNS_BMPENCODER_CID },
{ "@mozilla.org/image/encoder;2?type=" IMAGE_ICO_MS, &kNS_ICOENCODER_CID },
{ "@mozilla.org/image/encoder;2?type=" IMAGE_JPEG, &kNS_JPEGENCODER_CID },
{ "@mozilla.org/image/encoder;2?type=" IMAGE_PNG, &kNS_PNGENCODER_CID },
{ "@mozilla.org/image/encoder;2?type=" IMAGE_BMP, &kNS_BMPENCODER_CID },
{ NULL }
};
static const mozilla::Module::CategoryEntry kImageCategories[] = {
{ "Gecko-Content-Viewers", "image/gif", "@mozilla.org/content/document-loader-factory;1" },
{ "Gecko-Content-Viewers", "image/jpeg", "@mozilla.org/content/document-loader-factory;1" },
{ "Gecko-Content-Viewers", "image/pjpeg", "@mozilla.org/content/document-loader-factory;1" },
{ "Gecko-Content-Viewers", "image/jpg", "@mozilla.org/content/document-loader-factory;1" },
{ "Gecko-Content-Viewers", "image/x-icon", "@mozilla.org/content/document-loader-factory;1" },
{ "Gecko-Content-Viewers", "image/vnd.microsoft.icon", "@mozilla.org/content/document-loader-factory;1" },
{ "Gecko-Content-Viewers", "image/bmp", "@mozilla.org/content/document-loader-factory;1" },
{ "Gecko-Content-Viewers", "image/x-ms-bmp", "@mozilla.org/content/document-loader-factory;1" },
{ "Gecko-Content-Viewers", "image/icon", "@mozilla.org/content/document-loader-factory;1" },
{ "Gecko-Content-Viewers", "image/png", "@mozilla.org/content/document-loader-factory;1" },
{ "Gecko-Content-Viewers", "image/x-png", "@mozilla.org/content/document-loader-factory;1" },
{ "Gecko-Content-Viewers", IMAGE_GIF, "@mozilla.org/content/document-loader-factory;1" },
{ "Gecko-Content-Viewers", IMAGE_JPEG, "@mozilla.org/content/document-loader-factory;1" },
{ "Gecko-Content-Viewers", IMAGE_PJPEG, "@mozilla.org/content/document-loader-factory;1" },
{ "Gecko-Content-Viewers", IMAGE_JPG, "@mozilla.org/content/document-loader-factory;1" },
{ "Gecko-Content-Viewers", IMAGE_ICO, "@mozilla.org/content/document-loader-factory;1" },
{ "Gecko-Content-Viewers", IMAGE_ICO_MS, "@mozilla.org/content/document-loader-factory;1" },
{ "Gecko-Content-Viewers", IMAGE_BMP, "@mozilla.org/content/document-loader-factory;1" },
{ "Gecko-Content-Viewers", IMAGE_BMP_MS, "@mozilla.org/content/document-loader-factory;1" },
{ "Gecko-Content-Viewers", IMAGE_ICON, "@mozilla.org/content/document-loader-factory;1" },
{ "Gecko-Content-Viewers", IMAGE_PNG, "@mozilla.org/content/document-loader-factory;1" },
{ "Gecko-Content-Viewers", IMAGE_X_PNG, "@mozilla.org/content/document-loader-factory;1" },
{ "content-sniffing-services", "@mozilla.org/image/loader;1", "@mozilla.org/image/loader;1" },
{ NULL }
};

View File

@ -5,6 +5,7 @@
#include <stdlib.h>
#include "mozilla/dom/ContentChild.h"
#include "nsMimeTypes.h"
#include "nsIURL.h"
#include "nsXULAppAPI.h"
#include "AndroidBridge.h"
@ -102,7 +103,7 @@ moz_icon_to_channel(nsIURI *aURI, const nsACString& aFileExt, uint32_t aIconSize
NS_ENSURE_SUCCESS(rv, rv);
return NS_NewInputStreamChannel(aChannel, aURI, stream,
NS_LITERAL_CSTRING("image/icon"));
NS_LITERAL_CSTRING(IMAGE_ICON));
}
nsresult

View File

@ -25,6 +25,7 @@ extern "C" {
#include <gtk/gtk.h>
#include "nsMimeTypes.h"
#include "nsIMIMEService.h"
#include "nsIStringBundle.h"
@ -125,7 +126,7 @@ moz_gdk_pixbuf_to_channel(GdkPixbuf* aPixbuf, nsIURI *aURI,
NS_ENSURE_SUCCESS(rv, rv);
rv = NS_NewInputStreamChannel(aChannel, aURI, stream,
NS_LITERAL_CSTRING("image/icon"));
NS_LITERAL_CSTRING(IMAGE_ICON));
return rv;
}

View File

@ -345,7 +345,7 @@ NS_IMETHODIMP nsIconChannel::SetLoadFlags(uint32_t aLoadAttributes)
NS_IMETHODIMP nsIconChannel::GetContentType(nsACString &aContentType)
{
aContentType.AssignLiteral("image/icon");
aContentType.AssignLiteral(IMAGE_ICON);
return NS_OK;
}
@ -359,7 +359,7 @@ nsIconChannel::SetContentType(const nsACString &aContentType)
NS_IMETHODIMP nsIconChannel::GetContentCharset(nsACString &aContentCharset)
{
aContentCharset.AssignLiteral("image/icon");
aContentCharset.AssignLiteral(IMAGE_ICON);
return NS_OK;
}

View File

@ -11,6 +11,7 @@
#include "nsReadableUtils.h"
#include "nsMemory.h"
#include "nsNetUtil.h"
#include "nsMimeTypes.h"
#include "nsIFile.h"
#include "nsIFileURL.h"
#include "nsDirectoryServiceDefs.h"
@ -573,7 +574,7 @@ void ConvertMaskBitMap(uint8_t *inBuf, PBITMAPINFO2 pBMInfo,
NS_IMETHODIMP nsIconChannel::GetContentType(nsACString &aContentType)
{
aContentType.AssignLiteral("image/icon");
aContentType.AssignLiteral(IMAGE_ICON);
return NS_OK;
}

View File

@ -10,6 +10,7 @@
#include <stdlib.h>
#include <unistd.h>
#include "nsMimeTypes.h"
#include "nsIMIMEService.h"
#include "nsIStringBundle.h"
@ -84,7 +85,7 @@ moz_qicon_to_channel(QImage *image, nsIURI *aURI,
NS_ENSURE_SUCCESS(rv, rv);
return NS_NewInputStreamChannel(aChannel, aURI, stream,
NS_LITERAL_CSTRING("image/icon"));
NS_LITERAL_CSTRING(IMAGE_ICON));
}
nsresult

View File

@ -587,7 +587,7 @@ nsresult nsIconChannel::MakeInputStream(nsIInputStream** _retval, bool nonBlocki
NS_IMETHODIMP nsIconChannel::GetContentType(nsACString &aContentType)
{
aContentType.AssignLiteral("image/x-icon");
aContentType.AssignLiteral(IMAGE_ICO);
return NS_OK;
}

View File

@ -3,6 +3,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsMimeTypes.h"
#include "Image.h"
namespace mozilla {
@ -49,39 +51,39 @@ Image::GetDecoderType(const char *aMimeType)
eDecoderType rv = eDecoderType_unknown;
// PNG
if (!strcmp(aMimeType, "image/png"))
if (!strcmp(aMimeType, IMAGE_PNG))
rv = eDecoderType_png;
else if (!strcmp(aMimeType, "image/x-png"))
else if (!strcmp(aMimeType, IMAGE_X_PNG))
rv = eDecoderType_png;
// GIF
else if (!strcmp(aMimeType, "image/gif"))
else if (!strcmp(aMimeType, IMAGE_GIF))
rv = eDecoderType_gif;
// JPEG
else if (!strcmp(aMimeType, "image/jpeg"))
else if (!strcmp(aMimeType, IMAGE_JPEG))
rv = eDecoderType_jpeg;
else if (!strcmp(aMimeType, "image/pjpeg"))
else if (!strcmp(aMimeType, IMAGE_PJPEG))
rv = eDecoderType_jpeg;
else if (!strcmp(aMimeType, "image/jpg"))
else if (!strcmp(aMimeType, IMAGE_JPG))
rv = eDecoderType_jpeg;
// BMP
else if (!strcmp(aMimeType, "image/bmp"))
else if (!strcmp(aMimeType, IMAGE_BMP))
rv = eDecoderType_bmp;
else if (!strcmp(aMimeType, "image/x-ms-bmp"))
else if (!strcmp(aMimeType, IMAGE_BMP_MS))
rv = eDecoderType_bmp;
// ICO
else if (!strcmp(aMimeType, "image/x-icon"))
else if (!strcmp(aMimeType, IMAGE_ICO))
rv = eDecoderType_ico;
else if (!strcmp(aMimeType, "image/vnd.microsoft.icon"))
else if (!strcmp(aMimeType, IMAGE_ICO_MS))
rv = eDecoderType_ico;
// Icon
else if (!strcmp(aMimeType, "image/icon"))
else if (!strcmp(aMimeType, IMAGE_ICON))
rv = eDecoderType_icon;
return rv;

View File

@ -9,6 +9,7 @@
#include "nsIHttpChannel.h"
#include "nsSimpleURI.h"
#include "nsMimeTypes.h"
#include "RasterImage.h"
#include "VectorImage.h"
@ -18,8 +19,6 @@
namespace mozilla {
namespace image {
const char* SVG_MIMETYPE = "image/svg+xml";
// Global preferences related to image containers.
static bool gInitializedPrefCaches = false;
static bool gDecodeOnDraw = false;
@ -89,7 +88,7 @@ ImageFactory::CreateImage(nsIRequest* aRequest,
uint32_t imageFlags = ComputeImageFlags(aURI, aIsMultiPart);
// Select the type of image to create based on MIME type.
if (aMimeType.Equals(SVG_MIMETYPE)) {
if (aMimeType.EqualsLiteral(IMAGE_SVG_XML)) {
return CreateVectorImage(aRequest, aStatusTracker, aMimeType,
aURI, imageFlags, aInnerWindowId);
} else {

View File

@ -15,8 +15,6 @@
namespace mozilla {
namespace image {
extern const char* SVG_MIMETYPE;
struct ImageFactory
{
/**

View File

@ -342,7 +342,7 @@ SVGDocumentWrapper::SetupViewer(nsIRequest* aRequest,
do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
NS_ENSURE_TRUE(catMan, NS_ERROR_NOT_AVAILABLE);
nsXPIDLCString contractId;
nsresult rv = catMan->GetCategoryEntry("Gecko-Content-Viewers", SVG_MIMETYPE,
nsresult rv = catMan->GetCategoryEntry("Gecko-Content-Viewers", IMAGE_SVG_XML,
getter_Copies(contractId));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDocumentLoaderFactory> docLoaderFactory =
@ -353,7 +353,7 @@ SVGDocumentWrapper::SetupViewer(nsIRequest* aRequest,
nsCOMPtr<nsIStreamListener> listener;
rv = docLoaderFactory->CreateInstance("external-resource", chan,
newLoadGroup,
SVG_MIMETYPE, nullptr, nullptr,
IMAGE_SVG_XML, nullptr, nullptr,
getter_AddRefs(listener),
getter_AddRefs(viewer));
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -15,6 +15,7 @@
#include "nsIObserver.h"
#include "nsIContentViewer.h"
#include "nsWeakReference.h"
#include "nsMimeTypes.h"
class nsIAtom;
class nsIPresShell;
@ -24,7 +25,6 @@ class nsIFrame;
struct nsIntSize;
class nsSVGSVGElement;
#define SVG_MIMETYPE "image/svg+xml"
#define OBSERVER_SVC_CID "@mozilla.org/observer-service;1"

View File

@ -14,6 +14,7 @@
#include "nsIObserverService.h"
#include "nsIPresShell.h"
#include "nsIStreamListener.h"
#include "nsMimeTypes.h"
#include "nsComponentManagerUtils.h"
#include "nsServiceManagerUtils.h"
#include "nsSVGUtils.h" // for nsSVGUtils::ConvertToSurfaceSize
@ -204,7 +205,7 @@ VectorImage::Init(imgDecoderObserver* aObserver,
if (aObserver) {
mObserver = aObserver->asWeakPtr();
}
NS_ABORT_IF_FALSE(!strcmp(aMimeType, SVG_MIMETYPE), "Unexpected mimetype");
NS_ABORT_IF_FALSE(!strcmp(aMimeType, IMAGE_SVG_XML), "Unexpected mimetype");
mIsInitialized = true;

View File

@ -25,6 +25,7 @@
#include "nsContentUtils.h"
#include "nsCrossSiteListenerProxy.h"
#include "nsNetUtil.h"
#include "nsMimeTypes.h"
#include "nsStreamUtils.h"
#include "nsIHttpChannel.h"
#include "nsICachingChannel.h"
@ -957,7 +958,7 @@ void imgLoader::ReadAcceptHeaderPref()
if (accept)
mAcceptHeader = accept;
else
mAcceptHeader = "image/png,image/*;q=0.8,*/*;q=0.5";
mAcceptHeader = IMAGE_PNG "," IMAGE_WILDCARD ";q=0.8," ANY_WILDCARD ";q=0.5";
}
/* void clearCache (in boolean chrome); */
@ -1991,7 +1992,7 @@ nsresult imgLoader::GetMimeTypeFromContent(const char* aContents, uint32_t aLeng
if (aLength >= 6 && (!nsCRT::strncmp(aContents, "GIF87a", 6) ||
!nsCRT::strncmp(aContents, "GIF89a", 6)))
{
aContentType.AssignLiteral("image/gif");
aContentType.AssignLiteral(IMAGE_GIF);
}
/* or a PNG? */
@ -2004,7 +2005,7 @@ nsresult imgLoader::GetMimeTypeFromContent(const char* aContents, uint32_t aLeng
(unsigned char)aContents[6]==0x1A &&
(unsigned char)aContents[7]==0x0A))
{
aContentType.AssignLiteral("image/png");
aContentType.AssignLiteral(IMAGE_PNG);
}
/* maybe a JPEG (JFIF)? */
@ -2019,7 +2020,7 @@ nsresult imgLoader::GetMimeTypeFromContent(const char* aContents, uint32_t aLeng
((unsigned char)aContents[1])==0xD8 &&
((unsigned char)aContents[2])==0xFF)
{
aContentType.AssignLiteral("image/jpeg");
aContentType.AssignLiteral(IMAGE_JPEG);
}
/* or how about ART? */
@ -2031,18 +2032,18 @@ nsresult imgLoader::GetMimeTypeFromContent(const char* aContents, uint32_t aLeng
((unsigned char) aContents[1])==0x47 &&
((unsigned char) aContents[4])==0x00 )
{
aContentType.AssignLiteral("image/x-jg");
aContentType.AssignLiteral(IMAGE_ART);
}
else if (aLength >= 2 && !nsCRT::strncmp(aContents, "BM", 2)) {
aContentType.AssignLiteral("image/bmp");
aContentType.AssignLiteral(IMAGE_BMP);
}
// ICOs always begin with a 2-byte 0 followed by a 2-byte 1.
// CURs begin with 2-byte 0 followed by 2-byte 2.
else if (aLength >= 4 && (!memcmp(aContents, "\000\000\001\000", 4) ||
!memcmp(aContents, "\000\000\002\000", 4))) {
aContentType.AssignLiteral("image/x-icon");
aContentType.AssignLiteral(IMAGE_ICO);
}
else {

View File

@ -31,6 +31,7 @@
#include "nsIHttpChannel.h"
#include "nsIApplicationCache.h"
#include "nsIApplicationCacheChannel.h"
#include "nsMimeTypes.h"
#include "nsIComponentManager.h"
#include "nsIInterfaceRequestorUtils.h"
@ -726,7 +727,7 @@ imgRequest::OnDataAvailable(nsIRequest *aRequest, nsISupports *ctxt,
// type and decoder.
// We always reinitialize for SVGs, because they have no way of
// reinitializing themselves.
if (mContentType != newType || newType.Equals(SVG_MIMETYPE)) {
if (mContentType != newType || newType.EqualsLiteral(IMAGE_SVG_XML)) {
mContentType = newType;
// If we've resniffed our MIME type and it changed, we need to create a

View File

@ -16,6 +16,7 @@
instead, to help catch typos, and make central management of them easier.
*/
#define ANY_WILDCARD "*/*"
#define AUDIO_WILDCARD "audio/*"
#define IMAGE_WILDCARD "image/*"
@ -81,9 +82,11 @@
#define BINARY_OCTET_STREAM "binary/octet-stream"
#define IMAGE_GIF "image/gif"
#define IMAGE_JPG "image/jpeg"
#define IMAGE_PJPG "image/pjpeg"
#define IMAGE_JPEG "image/jpeg"
#define IMAGE_JPG "image/jpg"
#define IMAGE_PJPEG "image/pjpeg"
#define IMAGE_PNG "image/png"
#define IMAGE_X_PNG "image/x-png"
#define IMAGE_PPM "image/x-portable-pixmap"
#define IMAGE_XBM "image/x-xbitmap"
#define IMAGE_XBM2 "image/x-xbm"
@ -91,7 +94,10 @@
#define IMAGE_ART "image/x-jg"
#define IMAGE_TIFF "image/tiff"
#define IMAGE_BMP "image/bmp"
#define IMAGE_BMP_MS "image/x-ms-bmp"
#define IMAGE_ICO "image/x-icon"
#define IMAGE_ICO_MS "image/vnd.microsoft.icon"
#define IMAGE_ICON "image/icon"
#define IMAGE_MNG "video/x-mng"
#define IMAGE_JNG "image/x-jng"
#define IMAGE_SVG_XML "image/svg+xml"

View File

@ -381,8 +381,8 @@ static nsDefaultMimeTypeEntry defaultMimeEntries [] =
{ IMAGE_PNG, "png" },
// -- end extensions used during startup
{ TEXT_CSS, "css" },
{ IMAGE_JPG, "jpeg" },
{ IMAGE_JPG, "jpg" },
{ IMAGE_JPEG, "jpeg" },
{ IMAGE_JPEG, "jpg" },
{ TEXT_HTML, "html" },
{ TEXT_HTML, "htm" },
{ APPLICATION_XPINSTALL, "xpi" },
@ -460,7 +460,7 @@ static nsExtraMimeTypeEntry extraMimeEntries [] =
{ IMAGE_BMP, "bmp", "BMP Image" },
{ IMAGE_GIF, "gif", "GIF Image" },
{ IMAGE_ICO, "ico,cur", "ICO Image" },
{ IMAGE_JPG, "jpeg,jpg,jfif,pjpeg,pjp", "JPEG Image" },
{ IMAGE_JPEG, "jpeg,jpg,jfif,pjpeg,pjp", "JPEG Image" },
{ IMAGE_PNG, "png", "PNG Image" },
{ IMAGE_TIFF, "tiff,tif", "TIFF Image" },
{ IMAGE_XBM, "xbm", "XBM Image" },