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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « Source/core/dom/DOMImplementation.h ('k') | Source/core/dom/DOMImplementationTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
6 * Copyright (C) 2006 Samuel Weinig (sam@webkit.org) 6 * Copyright (C) 2006 Samuel Weinig (sam@webkit.org)
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 hasSlash = true; 287 hasSlash = true;
288 continue; 288 continue;
289 default: 289 default:
290 return false; 290 return false;
291 } 291 }
292 } 292 }
293 293
294 return true; 294 return true;
295 } 295 }
296 296
297 bool DOMImplementation::isJSONMIMEType(const String& mimeType)
298 {
299 if (mimeType.startsWith("application/json", false))
300 return true;
301 if (mimeType.startsWith("application/", false)) {
302 size_t subtype = mimeType.find("+json", 12, false);
303 if (subtype != kNotFound) {
304 // Just check that a parameter wasn't matched.
305 size_t parameterMarker = mimeType.find(";");
306 if (parameterMarker == kNotFound) {
307 unsigned endSubtype = static_cast<unsigned>(subtype) + 5;
308 return endSubtype == mimeType.length() || isASCIISpace(mimeType[ endSubtype]);
309 }
310 return parameterMarker > subtype;
311 }
312 }
313 return false;
314 }
315
316 static bool isTextPlainType(const String& mimeType)
317 {
318 return mimeType.startsWith("text/", false)
319 && !(equalIgnoringCase(mimeType, "text/html")
320 || equalIgnoringCase(mimeType, "text/xml")
321 || equalIgnoringCase(mimeType, "text/xsl"));
322 }
323
297 bool DOMImplementation::isTextMIMEType(const String& mimeType) 324 bool DOMImplementation::isTextMIMEType(const String& mimeType)
298 { 325 {
299 if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType) 326 return MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType) || isJSONMI METype(mimeType) || isTextPlainType(mimeType);
300 || mimeType == "application/json" // Render JSON as text/plain.
301 || (mimeType.startsWith("text/") && mimeType != "text/html"
302 && mimeType != "text/xml" && mimeType != "text/xsl"))
303 return true;
304
305 return false;
306 } 327 }
307 328
308 PassRefPtr<HTMLDocument> DOMImplementation::createHTMLDocument(const String& tit le) 329 PassRefPtr<HTMLDocument> DOMImplementation::createHTMLDocument(const String& tit le)
309 { 330 {
310 DocumentInit init = DocumentInit::fromContext(m_document.contextDocument()) 331 DocumentInit init = DocumentInit::fromContext(m_document.contextDocument())
311 .withRegistrationContext(m_document.registrationContext()); 332 .withRegistrationContext(m_document.registrationContext());
312 RefPtr<HTMLDocument> d = HTMLDocument::create(init); 333 RefPtr<HTMLDocument> d = HTMLDocument::create(init);
313 d->open(); 334 d->open();
314 d->write("<!doctype html><html><body></body></html>"); 335 d->write("<!doctype html><html><body></body></html>");
315 if (!title.isNull()) 336 if (!title.isNull())
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 return TextDocument::create(init); 380 return TextDocument::create(init);
360 if (type == "image/svg+xml") 381 if (type == "image/svg+xml")
361 return SVGDocument::create(init); 382 return SVGDocument::create(init);
362 if (isXMLMIMEType(type)) 383 if (isXMLMIMEType(type))
363 return Document::create(init); 384 return Document::create(init);
364 385
365 return HTMLDocument::create(init); 386 return HTMLDocument::create(init);
366 } 387 }
367 388
368 } 389 }
OLDNEW
« 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