Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(751)

Unified Diff: Source/core/dom/DOMImplementation.cpp

Issue 94893003: Support for json media types as (non-image) mime types. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Test via synthetic NetworkRequest Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/dom/DOMImplementation.h ('k') | Source/core/dom/DOMImplementationTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/DOMImplementation.cpp
diff --git a/Source/core/dom/DOMImplementation.cpp b/Source/core/dom/DOMImplementation.cpp
index ff898a52dea55fc0f6fe0adb3536cf06815d005b..ac17ccb749655871ed4312d8d64dc5efab282290 100644
--- a/Source/core/dom/DOMImplementation.cpp
+++ b/Source/core/dom/DOMImplementation.cpp
@@ -294,17 +294,38 @@ bool DOMImplementation::isXMLMIMEType(const String& mimeType)
return true;
}
-bool DOMImplementation::isTextMIMEType(const String& mimeType)
+bool DOMImplementation::isJSONMIMEType(const String& mimeType)
{
- if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType)
- || mimeType == "application/json" // Render JSON as text/plain.
- || (mimeType.startsWith("text/") && mimeType != "text/html"
- && mimeType != "text/xml" && mimeType != "text/xsl"))
+ if (mimeType.startsWith("application/json", false))
return true;
-
+ if (mimeType.startsWith("application/", false)) {
+ size_t subtype = mimeType.find("+json", 12, false);
+ if (subtype != kNotFound) {
+ // Just check that a parameter wasn't matched.
+ size_t parameterMarker = mimeType.find(";");
+ if (parameterMarker == kNotFound) {
+ unsigned endSubtype = static_cast<unsigned>(subtype) + 5;
+ return endSubtype == mimeType.length() || isASCIISpace(mimeType[endSubtype]);
+ }
+ return parameterMarker > subtype;
+ }
+ }
return false;
}
+static bool isTextPlainType(const String& mimeType)
+{
+ return mimeType.startsWith("text/", false)
+ && !(equalIgnoringCase(mimeType, "text/html")
+ || equalIgnoringCase(mimeType, "text/xml")
+ || equalIgnoringCase(mimeType, "text/xsl"));
+}
+
+bool DOMImplementation::isTextMIMEType(const String& mimeType)
+{
+ return MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType) || isJSONMIMEType(mimeType) || isTextPlainType(mimeType);
+}
+
PassRefPtr<HTMLDocument> DOMImplementation::createHTMLDocument(const String& title)
{
DocumentInit init = DocumentInit::fromContext(m_document.contextDocument())
« no previous file with comments | « Source/core/dom/DOMImplementation.h ('k') | Source/core/dom/DOMImplementationTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698