Bug 667533 - Display application/json data as text. r=bzbarsky
authorMarkus Stange <mstange@themasta.com>
Mon, 08 Aug 2011 20:32:07 +0200
changeset 74030 10c2c74197fc6dbdd4a761104eec6ca841d42f0b
parent 74029 e45e7a591956184c18ef55fa18e5a3044012a63a
child 74031 f2ff60137bb3025e757f2102fd919612a508949b
push idunknown
push userunknown
push dateunknown
reviewersbzbarsky
bugs667533
milestone8.0a1
Bug 667533 - Display application/json data as text. r=bzbarsky
layout/build/nsContentDLF.cpp
layout/build/nsContentDLF.h
netwerk/mime/nsMimeTypes.h
parser/htmlparser/src/nsParser.cpp
parser/htmlparser/tests/mochitest/test_bug667533.html
--- a/layout/build/nsContentDLF.cpp
+++ b/layout/build/nsContentDLF.cpp
@@ -92,16 +92,17 @@ static const char* const gHTMLTypes[] = 
   TEXT_HTML,
   TEXT_PLAIN,
   TEXT_CSS,
   TEXT_JAVASCRIPT,
   TEXT_ECMASCRIPT,
   APPLICATION_JAVASCRIPT,
   APPLICATION_ECMASCRIPT,
   APPLICATION_XJAVASCRIPT,
+  APPLICATION_JSON,
   VIEWSOURCE_CONTENT_TYPE,
   APPLICATION_XHTML_XML,
   0
 };
   
 static const char* const gXMLTypes[] = {
   TEXT_XML,
   APPLICATION_XML,
--- a/layout/build/nsContentDLF.h
+++ b/layout/build/nsContentDLF.h
@@ -102,16 +102,17 @@ NS_NewContentDocumentLoaderFactory(nsIDo
     { "Gecko-Content-Viewers", TEXT_HTML, "@mozilla.org/content/document-loader-factory;1" }, \
     { "Gecko-Content-Viewers", TEXT_PLAIN, "@mozilla.org/content/document-loader-factory;1" }, \
     { "Gecko-Content-Viewers", TEXT_CSS, "@mozilla.org/content/document-loader-factory;1" }, \
     { "Gecko-Content-Viewers", TEXT_JAVASCRIPT, "@mozilla.org/content/document-loader-factory;1" }, \
     { "Gecko-Content-Viewers", TEXT_ECMASCRIPT, "@mozilla.org/content/document-loader-factory;1" }, \
     { "Gecko-Content-Viewers", APPLICATION_JAVASCRIPT, "@mozilla.org/content/document-loader-factory;1" }, \
     { "Gecko-Content-Viewers", APPLICATION_ECMASCRIPT, "@mozilla.org/content/document-loader-factory;1" }, \
     { "Gecko-Content-Viewers", APPLICATION_XJAVASCRIPT, "@mozilla.org/content/document-loader-factory;1" }, \
+    { "Gecko-Content-Viewers", APPLICATION_JSON, "@mozilla.org/content/document-loader-factory;1" }, \
     { "Gecko-Content-Viewers", APPLICATION_XHTML_XML, "@mozilla.org/content/document-loader-factory;1" }, \
     { "Gecko-Content-Viewers", TEXT_XML, "@mozilla.org/content/document-loader-factory;1" }, \
     { "Gecko-Content-Viewers", APPLICATION_XML, "@mozilla.org/content/document-loader-factory;1" }, \
     { "Gecko-Content-Viewers", APPLICATION_RDF_XML, "@mozilla.org/content/document-loader-factory;1" }, \
     { "Gecko-Content-Viewers", TEXT_RDF, "@mozilla.org/content/document-loader-factory;1" }, \
     { "Gecko-Content-Viewers", TEXT_XUL, "@mozilla.org/content/document-loader-factory;1" }, \
     { "Gecko-Content-Viewers", APPLICATION_CACHED_XUL, "@mozilla.org/content/document-loader-factory;1" }, \
     { "Gecko-Content-Viewers", VIEWSOURCE_CONTENT_TYPE, "@mozilla.org/content/document-loader-factory;1" }, \
--- a/netwerk/mime/nsMimeTypes.h
+++ b/netwerk/mime/nsMimeTypes.h
@@ -61,16 +61,17 @@
 #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_ECMASCRIPT              "application/ecmascript"
 #define APPLICATION_JAVASCRIPT              "application/javascript"
 #define APPLICATION_XJAVASCRIPT             "application/x-javascript"
+#define APPLICATION_JSON                    "application/json"
 #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"
--- a/parser/htmlparser/src/nsParser.cpp
+++ b/parser/htmlparser/src/nsParser.cpp
@@ -1352,16 +1352,17 @@ DetermineParseMode(const nsString& aBuff
                    eParserDocType& aDocType, const nsACString& aMimeType)
 {
   if (aMimeType.EqualsLiteral(TEXT_HTML)) {
     DetermineHTMLParseMode(aBuffer, aParseMode, aDocType);
   } else if (aMimeType.EqualsLiteral(TEXT_PLAIN) ||
              aMimeType.EqualsLiteral(TEXT_CSS) ||
              aMimeType.EqualsLiteral(APPLICATION_JAVASCRIPT) ||
              aMimeType.EqualsLiteral(APPLICATION_XJAVASCRIPT) ||
+             aMimeType.EqualsLiteral(APPLICATION_JSON) ||
              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;
new file mode 100644
--- /dev/null
+++ b/parser/htmlparser/tests/mochitest/test_bug667533.html
@@ -0,0 +1,29 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=667533
+-->
+<head>
+  <title>Test for Bug 667533</title>
+  <script type="application/javascript" src="/MochiKit/packed.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=667533">Mozilla Bug 667533</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+  
+</div>
+<script type="application/javascript">
+SimpleTest.waitForExplicitFinish();
+
+function loaded(iframe) {
+  is(iframe.contentWindow.location.href, iframe.src, "should load correct URL");
+  is(iframe.contentDocument.body.textContent, '{"<p>Hello</p>": null}', "application/json should be treated as text");
+  SimpleTest.finish();
+}
+</script>
+<iframe src="data:application/json,{&quot;<p>Hello</p>&quot;:%20null}" onload="loaded(this);"></iframe>
+</body>
+</html>