OLD | NEW |
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 Loading... |
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 static bool isJSONType(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 return (parameterMarker == kNotFound || parameterMarker > subtype); |
| 307 } |
| 308 } |
| 309 return false; |
| 310 } |
| 311 |
| 312 static bool isTextPlainType(const String& mimeType) |
| 313 { |
| 314 return (mimeType.startsWith("text/", false) |
| 315 && !(equalIgnoringCase(mimeType, "text/html") |
| 316 || equalIgnoringCase(mimeType, "text/xml") |
| 317 || equalIgnoringCase(mimeType, "text/xsl"))); |
| 318 } |
| 319 |
297 bool DOMImplementation::isTextMIMEType(const String& mimeType) | 320 bool DOMImplementation::isTextMIMEType(const String& mimeType) |
298 { | 321 { |
299 if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType) | 322 if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType) || isJSONType(
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; | 323 return true; |
304 | 324 |
305 return false; | 325 return false; |
306 } | 326 } |
307 | 327 |
| 328 const char* DOMImplementation::getTextDefaultEncodingName(const String& mimeType
) |
| 329 { |
| 330 ASSERT(isTextMIMEType(mimeType)); |
| 331 if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType) || isJSONType(
mimeType)) |
| 332 return "UTF-8"; |
| 333 |
| 334 // The HTTP/1.1 default. |
| 335 return "ISO-8859-1"; |
| 336 } |
| 337 |
308 PassRefPtr<HTMLDocument> DOMImplementation::createHTMLDocument(const String& tit
le) | 338 PassRefPtr<HTMLDocument> DOMImplementation::createHTMLDocument(const String& tit
le) |
309 { | 339 { |
310 DocumentInit init = DocumentInit::fromContext(m_document.contextDocument()) | 340 DocumentInit init = DocumentInit::fromContext(m_document.contextDocument()) |
311 .withRegistrationContext(m_document.registrationContext()); | 341 .withRegistrationContext(m_document.registrationContext()); |
312 RefPtr<HTMLDocument> d = HTMLDocument::create(init); | 342 RefPtr<HTMLDocument> d = HTMLDocument::create(init); |
313 d->open(); | 343 d->open(); |
314 d->write("<!doctype html><html><body></body></html>"); | 344 d->write("<!doctype html><html><body></body></html>"); |
315 if (!title.isNull()) | 345 if (!title.isNull()) |
316 d->setTitle(title); | 346 d->setTitle(title); |
317 d->setSecurityOrigin(m_document.securityOrigin()->isolatedCopy()); | 347 d->setSecurityOrigin(m_document.securityOrigin()->isolatedCopy()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 return TextDocument::create(init); | 389 return TextDocument::create(init); |
360 if (type == "image/svg+xml") | 390 if (type == "image/svg+xml") |
361 return SVGDocument::create(init); | 391 return SVGDocument::create(init); |
362 if (isXMLMIMEType(type)) | 392 if (isXMLMIMEType(type)) |
363 return Document::create(init); | 393 return Document::create(init); |
364 | 394 |
365 return HTMLDocument::create(init); | 395 return HTMLDocument::create(init); |
366 } | 396 } |
367 | 397 |
368 } | 398 } |
OLD | NEW |