Bug 530275. Move more MIME types into nsMimeTypes.h so we don't have to hardcode the strings in various places. r=bzbarsky
--- a/content/xml/document/src/nsXMLContentSink.cpp
+++ b/content/xml/document/src/nsXMLContentSink.cpp
@@ -93,23 +93,22 @@
#include "nsContentPolicyUtils.h"
#include "nsContentErrors.h"
#include "nsIDOMProcessingInstruction.h"
#include "nsNodeUtils.h"
#include "nsIScriptGlobalObject.h"
#include "nsIHTMLDocument.h"
#include "nsEventDispatcher.h"
#include "mozAutoDocUpdate.h"
+#include "nsMimeTypes.h"
#ifdef MOZ_SVG
#include "nsGUIEvent.h"
#endif
-#define kXSLType "text/xsl"
-
// XXX Open Issues:
// 1) what's not allowed - We need to figure out which HTML tags
// (prefixed with a HTML namespace qualifier) are explicitly not
// allowed (if any).
// 2) factoring code with nsHTMLContentSink - There's some amount of
// common code between this and the HTML content sink. This will
// increase as we support more and more HTML elements. How can code
// from the code be factored?
@@ -740,19 +739,19 @@ nsXMLContentSink::ProcessStyleLink(nsICo
nsCAutoString cmd;
if (mParser)
mParser->GetCommand(cmd);
if (cmd.EqualsASCII(kLoadAsData))
return NS_OK; // Do not load stylesheets when loading as data
NS_ConvertUTF16toUTF8 type(aType);
- if (type.EqualsIgnoreCase(kXSLType) ||
- type.EqualsIgnoreCase(kXMLTextContentType) ||
- type.EqualsIgnoreCase(kXMLApplicationContentType)) {
+ if (type.EqualsIgnoreCase(TEXT_XSL) ||
+ type.EqualsIgnoreCase(TEXT_XML) ||
+ type.EqualsIgnoreCase(APPLICATION_XML)) {
if (aAlternate) {
// don't load alternate XSLT
return NS_OK;
}
// LoadXSLStyleSheet needs a mDocShell.
if (!mDocShell)
return NS_OK;
--- a/layout/build/nsContentDLF.cpp
+++ b/layout/build/nsContentDLF.cpp
@@ -57,16 +57,17 @@
#include "nsCRT.h"
#include "nsIViewSourceChannel.h"
#ifdef MOZ_MEDIA
#include "nsHTMLMediaElement.h"
#endif
#include "imgILoader.h"
#include "nsIParser.h"
+#include "nsMimeTypes.h"
// plugins
#include "nsIPluginHost.h"
static NS_DEFINE_CID(kPluginDocumentCID, NS_PLUGINDOCUMENT_CID);
// Factory code for creating variations on html documents
#undef NOISY_REGISTRY
@@ -83,51 +84,51 @@ static NS_DEFINE_IID(kImageDocumentCID,
static NS_DEFINE_IID(kXULDocumentCID, NS_XULDOCUMENT_CID);
nsresult
NS_NewDocumentViewer(nsIDocumentViewer** aResult);
// XXXbz if you change the MIME types here, be sure to update
// nsIParser.h and DetermineParseMode in nsParser.cpp accordingly.
static const char* const gHTMLTypes[] = {
- "text/html",
- "text/plain",
- "text/css",
- "text/javascript",
- "text/ecmascript",
- "application/javascript",
- "application/ecmascript",
- "application/x-javascript",
+ TEXT_HTML,
+ TEXT_PLAIN,
+ TEXT_CSS,
+ TEXT_JAVASCRIPT,
+ TEXT_ECMASCRIPT,
+ APPLICATION_JAVASCRIPT,
+ APPLICATION_ECMASCRIPT,
+ APPLICATION_XJAVASCRIPT,
#ifdef MOZ_VIEW_SOURCE
- "application/x-view-source", //XXX I wish I could just use nsMimeTypes.h here
+ VIEWSOURCE_CONTENT_TYPE,
#endif
- "application/xhtml+xml",
+ APPLICATION_XHTML_XML,
0
};
static const char* const gXMLTypes[] = {
- "text/xml",
- "application/xml",
- "application/rdf+xml",
- "text/rdf",
+ TEXT_XML,
+ APPLICATION_XML,
+ APPLICATION_RDF_XML,
+ TEXT_RDF,
0
};
#ifdef MOZ_SVG
static const char* const gSVGTypes[] = {
- "image/svg+xml",
+ IMAGE_SVG_XML,
0
};
PRBool NS_SVGEnabled();
#endif
static const char* const gXULTypes[] = {
- "application/vnd.mozilla.xul+xml",
- "mozilla.application/cached-xul",
+ TEXT_XUL,
+ APPLICATION_CACHED_XUL,
0
};
nsresult
NS_NewContentDocumentLoaderFactory(nsIDocumentLoaderFactory** aResult)
{
NS_PRECONDITION(aResult, "null OUT ptr");
if (!aResult) {
@@ -178,17 +179,17 @@ nsContentDLF::CreateInstance(const char*
// view-source channel normally returns. Get the actual content
// type of the data. If it's known, use it; otherwise use
// text/plain.
viewSourceChannel->GetOriginalContentType(type);
PRBool knownType = PR_FALSE;
PRInt32 typeIndex;
for (typeIndex = 0; gHTMLTypes[typeIndex] && !knownType; ++typeIndex) {
if (type.Equals(gHTMLTypes[typeIndex]) &&
- !type.EqualsLiteral("application/x-view-source")) {
+ !type.EqualsLiteral(VIEWSOURCE_CONTENT_TYPE)) {
knownType = PR_TRUE;
}
}
for (typeIndex = 0; gXMLTypes[typeIndex] && !knownType; ++typeIndex) {
if (type.Equals(gXMLTypes[typeIndex])) {
knownType = PR_TRUE;
}
@@ -212,21 +213,21 @@ nsContentDLF::CreateInstance(const char*
if (knownType) {
viewSourceChannel->SetContentType(type);
} else if (IsImageContentType(type.get())) {
// If it's an image, we want to display it the same way we normally would.
// Also note the lifetime of "type" allows us to safely use "get()" here.
aContentType = type.get();
} else {
- viewSourceChannel->SetContentType(NS_LITERAL_CSTRING("text/plain"));
+ viewSourceChannel->SetContentType(NS_LITERAL_CSTRING(TEXT_PLAIN));
}
- } else if (0 == PL_strcmp("application/x-view-source", aContentType)) {
- aChannel->SetContentType(NS_LITERAL_CSTRING("text/plain"));
- aContentType = "text/plain";
+ } else if (0 == PL_strcmp(VIEWSOURCE_CONTENT_TYPE, aContentType)) {
+ aChannel->SetContentType(NS_LITERAL_CSTRING(TEXT_PLAIN));
+ aContentType = TEXT_PLAIN;
}
#endif
// Try html
int typeIndex=0;
while(gHTMLTypes[typeIndex]) {
if (0 == PL_strcmp(gHTMLTypes[typeIndex++], aContentType)) {
return CreateDocument(aCommand,
aChannel, aLoadGroup,
--- a/netwerk/mime/public/nsMimeTypes.h
+++ b/netwerk/mime/public/nsMimeTypes.h
@@ -58,17 +58,19 @@
#define APPLICATION_COMPRESS2 "application/compress"
#define APPLICATION_FORTEZZA_CKL "application/x-fortezza-ckl"
#define APPLICATION_FORTEZZA_KRL "application/x-fortezza-krl"
#define APPLICATION_GZIP "application/x-gzip"
#define APPLICATION_GZIP2 "application/gzip"
#define APPLICATION_GZIP3 "application/x-gunzip"
#define APPLICATION_ZIP "application/zip"
#define APPLICATION_HTTP_INDEX_FORMAT "application/http-index-format"
-#define APPLICATION_JAVASCRIPT "application/x-javascript"
+#define APPLICATION_ECMASCRIPT "application/ecmascript"
+#define APPLICATION_JAVASCRIPT "application/javascript"
+#define APPLICATION_XJAVASCRIPT "application/x-javascript"
#define APPLICATION_NETSCAPE_REVOCATION "application/x-netscape-revocation"
#define APPLICATION_NS_PROXY_AUTOCONFIG "application/x-ns-proxy-autoconfig"
#define APPLICATION_NS_JAVASCRIPT_AUTOCONFIG "application/x-javascript-config"
#define APPLICATION_OCTET_STREAM "application/octet-stream"
#define APPLICATION_PGP "application/pgp"
#define APPLICATION_PGP2 "application/x-pgp-message"
#define APPLICATION_POSTSCRIPT "application/postscript"
#define APPLICATION_PDF "application/pdf"
@@ -89,16 +91,19 @@
#define APPLICATION_PKCS7_SIGNATURE "application/pkcs7-signature"
#define APPLICATION_WWW_FORM_URLENCODED "application/x-www-form-urlencoded"
#define APPLICATION_OLEOBJECT "application/oleobject"
#define APPLICATION_OLEOBJECT2 "application/x-oleobject"
#define APPLICATION_JAVAARCHIVE "application/java-archive"
#define APPLICATION_MARIMBA "application/marimba"
#define APPLICATION_XMARIMBA "application/x-marimba"
#define APPLICATION_XPINSTALL "application/x-xpinstall"
+#define APPLICATION_XML "application/xml"
+#define APPLICATION_XHTML_XML "application/xhtml+xml"
+#define APPLICATION_RDF_XML "application/rdf+xml"
#define AUDIO_BASIC "audio/basic"
#define AUDIO_OGG "audio/ogg"
#define AUDIO_WAV "audio/x-wav"
#define IMAGE_GIF "image/gif"
#define IMAGE_JPG "image/jpeg"
#define IMAGE_PJPG "image/pjpeg"
@@ -108,16 +113,17 @@
#define IMAGE_XBM2 "image/x-xbm"
#define IMAGE_XBM3 "image/xbm"
#define IMAGE_ART "image/x-jg"
#define IMAGE_TIFF "image/tiff"
#define IMAGE_BMP "image/bmp"
#define IMAGE_ICO "image/x-icon"
#define IMAGE_MNG "video/x-mng"
#define IMAGE_JNG "image/x-jng"
+#define IMAGE_SVG_XML "image/svg+xml"
#define MESSAGE_EXTERNAL_BODY "message/external-body"
#define MESSAGE_NEWS "message/news"
#define MESSAGE_RFC822 "message/rfc822"
#define MULTIPART_ALTERNATIVE "multipart/alternative"
#define MULTIPART_APPLEDOUBLE "multipart/appledouble"
#define MULTIPART_DIGEST "multipart/digest"
@@ -138,16 +144,19 @@
#define TEXT_PLAIN "text/plain"
#define TEXT_RICHTEXT "text/richtext"
#define TEXT_VCARD "text/x-vcard"
#define TEXT_CSS "text/css"
#define TEXT_JSSS "text/jsss"
#define TEXT_XML "text/xml"
#define TEXT_RDF "text/rdf"
#define TEXT_XUL "application/vnd.mozilla.xul+xml"
+#define TEXT_ECMASCRIPT "text/ecmascript"
+#define TEXT_JAVASCRIPT "text/javascript"
+#define TEXT_XSL "text/xsl"
#define VIDEO_MPEG "video/mpeg"
#define VIDEO_OGG "video/ogg"
#define APPLICATION_OGG "application/ogg"
/* x-uuencode-apple-single. QuickMail made me do this. */
#define UUENCODE_APPLE_SINGLE "x-uuencode-apple-single"
@@ -193,10 +202,11 @@
#define PARAM_X_MAC_TYPE "x-mac-type"
#define PARAM_FORMAT "format"
#define UNKNOWN_CONTENT_TYPE "application/x-unknown-content-type"
#define APPLICATION_GUESS_FROM_EXT "application/x-vnd.mozilla.guess-from-ext"
#define VIEWSOURCE_CONTENT_TYPE "application/x-view-source"
#define APPLICATION_DIRECTORY "application/directory" /* text/x-vcard is synonym */
+#define APPLICATION_CACHED_XUL "mozilla.application/cached-xul"
#endif /* nsMimeTypes_h_ */
--- a/parser/htmlparser/public/nsIParser.h
+++ b/parser/htmlparser/public/nsIParser.h
@@ -393,38 +393,16 @@ const PRUnichar kLeftParen = '('
const PRUnichar kRightParen = ')';
const PRUnichar kLeftBrace = '{';
const PRUnichar kRightBrace = '}';
const PRUnichar kQuestionMark = '?';
const PRUnichar kLeftSquareBracket = '[';
const PRUnichar kRightSquareBracket = ']';
const PRUnichar kNullCh = '\0';
-// XXXbz these type defines should really just go away.... Until they
-// do, changes here should be reflected in nsContentDLF.cpp
-#define kHTMLTextContentType "text/html"
-#define kXMLTextContentType "text/xml"
-#define kXMLApplicationContentType "application/xml"
-#define kXHTMLApplicationContentType "application/xhtml+xml"
-#define kXULTextContentType "application/vnd.mozilla.xul+xml"
-#define kRDFTextContentType "text/rdf"
-#define kRDFApplicationContentType "application/rdf+xml"
-#define kXIFTextContentType "text/xif"
-#define kPlainTextContentType "text/plain"
-#define kViewSourceCommand "view-source"
-#define kViewFragmentCommand "view-fragment"
-#define kTextCSSContentType "text/css"
-#define kApplicationJSContentType "application/javascript"
-#define kApplicationXJSContentType "application/x-javascript"
-#define kTextECMAScriptContentType "text/ecmascript"
-#define kApplicationECMAScriptContentType "application/ecmascript"
-#define kTextJSContentType "text/javascript"
-#define kSGMLTextContentType "text/sgml"
-#define kSVGTextContentType "image/svg+xml"
-
#define NS_IPARSER_FLAG_UNKNOWN_MODE 0x00000000
#define NS_IPARSER_FLAG_QUIRKS_MODE 0x00000002
#define NS_IPARSER_FLAG_STRICT_MODE 0x00000004
#define NS_IPARSER_FLAG_AUTO_DETECT_MODE 0x00000010
#define NS_IPARSER_FLAG_VIEW_NORMAL 0x00000020
#define NS_IPARSER_FLAG_VIEW_SOURCE 0x00000040
#define NS_IPARSER_FLAG_VIEW_ERRORS 0x00000080
#define NS_IPARSER_FLAG_PLAIN_TEXT 0x00000100
--- a/parser/htmlparser/src/CParserContext.cpp
+++ b/parser/htmlparser/src/CParserContext.cpp
@@ -38,16 +38,17 @@
#include "nsIAtom.h"
#include "CParserContext.h"
#include "nsToken.h"
#include "prenv.h"
#include "nsIHTMLContentSink.h"
#include "nsHTMLTokenizer.h"
+#include "nsMimeTypes.h"
CParserContext::CParserContext(CParserContext* aPrevContext,
nsScanner* aScanner,
void *aKey,
eParserCommands aCommand,
nsIRequestObserver* aListener,
eAutoDetectResult aStatus,
PRBool aCopyUnused)
@@ -75,27 +76,27 @@ CParserContext::~CParserContext()
void
CParserContext::SetMimeType(const nsACString& aMimeType)
{
mMimeType.Assign(aMimeType);
mDocType = ePlainText;
- if (mMimeType.EqualsLiteral(kHTMLTextContentType))
+ if (mMimeType.EqualsLiteral(TEXT_HTML))
mDocType = eHTML_Strict;
- else if (mMimeType.EqualsLiteral(kXMLTextContentType) ||
- mMimeType.EqualsLiteral(kXMLApplicationContentType) ||
- mMimeType.EqualsLiteral(kXHTMLApplicationContentType) ||
- mMimeType.EqualsLiteral(kXULTextContentType) ||
+ else if (mMimeType.EqualsLiteral(TEXT_XML) ||
+ mMimeType.EqualsLiteral(APPLICATION_XML) ||
+ mMimeType.EqualsLiteral(APPLICATION_XHTML_XML) ||
+ mMimeType.EqualsLiteral(TEXT_XUL) ||
#ifdef MOZ_SVG
- mMimeType.EqualsLiteral(kSVGTextContentType) ||
+ mMimeType.EqualsLiteral(IMAGE_SVG_XML) ||
#endif
- mMimeType.EqualsLiteral(kRDFApplicationContentType) ||
- mMimeType.EqualsLiteral(kRDFTextContentType))
+ mMimeType.EqualsLiteral(APPLICATION_RDF_XML) ||
+ mMimeType.EqualsLiteral(TEXT_RDF))
mDocType = eXML;
}
nsresult
CParserContext::GetTokenizer(nsIDTD* aDTD,
nsIContentSink* aSink,
nsITokenizer*& aTokenizer)
{
--- a/parser/htmlparser/src/nsParser.cpp
+++ b/parser/htmlparser/src/nsParser.cpp
@@ -69,16 +69,17 @@
#include "nsNetUtil.h"
#include "nsScriptLoader.h"
#include "nsDataHashtable.h"
#include "nsIThreadPool.h"
#include "nsXPCOMCIDInternal.h"
#include "nsICSSStyleSheet.h"
#include "nsICSSLoaderObserver.h"
#include "nsICSSLoader.h"
+#include "nsMimeTypes.h"
#ifdef MOZ_VIEW_SOURCE
#include "nsViewSourceHTML.h"
#endif
#define NS_PARSER_FLAG_PARSER_ENABLED 0x00000002
#define NS_PARSER_FLAG_OBSERVERS_ENABLED 0x00000004
#define NS_PARSER_FLAG_PENDING_CONTINUE_EVENT 0x00000008
@@ -957,19 +958,19 @@ nsParser::GetCommand(nsCString& aCommand
* this allows us to select a DTD which can do, say, view-source.
*
* @param aCommand the command string to set
*/
NS_IMETHODIMP_(void)
nsParser::SetCommand(const char* aCommand)
{
mCommandStr.Assign(aCommand);
- if (mCommandStr.Equals(kViewSourceCommand)) {
+ if (mCommandStr.Equals("view-source")) {
mCommand = eViewSource;
- } else if (mCommandStr.Equals(kViewFragmentCommand)) {
+ } else if (mCommandStr.Equals("view-fragment")) {
mCommand = eViewFragment;
} else {
mCommand = eViewNormal;
}
}
/**
* Call this method once you've created a parser, and want to instruct it
@@ -1428,25 +1429,25 @@ DetermineHTMLParseMode(const nsString& a
aDocType = eHTML_Quirks;
}
}
static void
DetermineParseMode(const nsString& aBuffer, nsDTDMode& aParseMode,
eParserDocType& aDocType, const nsACString& aMimeType)
{
- if (aMimeType.EqualsLiteral(kHTMLTextContentType)) {
+ if (aMimeType.EqualsLiteral(TEXT_HTML)) {
DetermineHTMLParseMode(aBuffer, aParseMode, aDocType);
- } else if (aMimeType.EqualsLiteral(kPlainTextContentType) ||
- aMimeType.EqualsLiteral(kTextCSSContentType) ||
- aMimeType.EqualsLiteral(kApplicationJSContentType) ||
- aMimeType.EqualsLiteral(kApplicationXJSContentType) ||
- aMimeType.EqualsLiteral(kTextECMAScriptContentType) ||
- aMimeType.EqualsLiteral(kApplicationECMAScriptContentType) ||
- aMimeType.EqualsLiteral(kTextJSContentType)) {
+ } else if (aMimeType.EqualsLiteral(TEXT_PLAIN) ||
+ aMimeType.EqualsLiteral(TEXT_CSS) ||
+ aMimeType.EqualsLiteral(APPLICATION_JAVASCRIPT) ||
+ aMimeType.EqualsLiteral(APPLICATION_XJAVASCRIPT) ||
+ aMimeType.EqualsLiteral(TEXT_ECMASCRIPT) ||
+ aMimeType.EqualsLiteral(APPLICATION_ECMASCRIPT) ||
+ aMimeType.EqualsLiteral(TEXT_JAVASCRIPT)) {
aDocType = ePlainText;
aParseMode = eDTDMode_quirks;
} else { // Some form of XML
aDocType = eXML;
aParseMode = eDTDMode_full_standards;
}
}
@@ -2709,17 +2710,17 @@ nsParser::DetectMetaTag(const char* aByt
nsCString& aCharset,
PRInt32& aCharsetSource)
{
aCharsetSource= kCharsetFromMetaTag;
aCharset.SetLength(0);
// XXX Only look inside HTML documents for now. For XML
// documents we should be looking inside the XMLDecl.
- if (!mParserContext->mMimeType.EqualsLiteral(kHTMLTextContentType)) {
+ if (!mParserContext->mMimeType.EqualsLiteral(TEXT_HTML)) {
return PR_FALSE;
}
// Fast and loose parsing to determine if we have a complete
// META tag in this block, looking upto 2k into it.
const nsASingleFragmentCString& str =
Substring(aBytes, aBytes + NS_MIN(aLen, 2048));
// XXXldb Should be const_char_iterator when FindInReadable supports it.
--- a/uriloader/exthandler/nsExternalHelperAppService.cpp
+++ b/uriloader/exthandler/nsExternalHelperAppService.cpp
@@ -512,17 +512,17 @@ static nsExtraMimeTypeEntry extraMimeEnt
{ APPLICATION_OCTET_STREAM, "exe,com", "Binary File" },
#else
{ APPLICATION_OCTET_STREAM, "exe,com,bin", "Binary File" },
#endif
{ APPLICATION_GZIP2, "gz", "gzip" },
{ "application/x-arj", "arj", "ARJ file" },
{ APPLICATION_XPINSTALL, "xpi", "XPInstall Install" },
{ APPLICATION_POSTSCRIPT, "ps,eps,ai", "Postscript File" },
- { APPLICATION_JAVASCRIPT, "js", "Javascript Source File" },
+ { APPLICATION_XJAVASCRIPT, "js", "Javascript Source File" },
{ IMAGE_ART, "art", "ART Image" },
{ 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_PNG, "png", "PNG Image" },
{ IMAGE_TIFF, "tiff,tif", "TIFF Image" },
{ IMAGE_XBM, "xbm", "XBM Image" },