summaryrefslogtreecommitdiff
path: root/Source/WebCore/loader/TextResourceDecoder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/loader/TextResourceDecoder.cpp')
-rw-r--r--Source/WebCore/loader/TextResourceDecoder.cpp27
1 files changed, 20 insertions, 7 deletions
diff --git a/Source/WebCore/loader/TextResourceDecoder.cpp b/Source/WebCore/loader/TextResourceDecoder.cpp
index 5105ae0bb..fe94b7f81 100644
--- a/Source/WebCore/loader/TextResourceDecoder.cpp
+++ b/Source/WebCore/loader/TextResourceDecoder.cpp
@@ -23,9 +23,9 @@
#include "config.h"
#include "TextResourceDecoder.h"
-#include "DOMImplementation.h"
#include "HTMLMetaCharsetParser.h"
#include "HTMLNames.h"
+#include "MIMETypeRegistry.h"
#include "TextCodec.h"
#include "TextEncoding.h"
#include "TextEncodingDetector.h"
@@ -302,11 +302,11 @@ breakBreak:
TextResourceDecoder::ContentType TextResourceDecoder::determineContentType(const String& mimeType)
{
- if (equalIgnoringCase(mimeType, "text/css"))
+ if (equalLettersIgnoringASCIICase(mimeType, "text/css"))
return CSS;
- if (equalIgnoringCase(mimeType, "text/html"))
+ if (equalLettersIgnoringASCIICase(mimeType, "text/html"))
return HTML;
- if (DOMImplementation::isXMLMIMEType(mimeType))
+ if (MIMETypeRegistry::isXMLMIMEType(mimeType))
return XML;
return PlainText;
}
@@ -326,7 +326,7 @@ TextResourceDecoder::TextResourceDecoder(const String& mimeType, const TextEncod
: m_contentType(determineContentType(mimeType))
, m_encoding(defaultEncoding(m_contentType, specifiedDefaultEncoding))
, m_source(DefaultEncoding)
- , m_hintEncoding(0)
+ , m_hintEncoding(nullptr)
, m_checkedForBOM(false)
, m_checkedForCSSCharset(false)
, m_checkedForHeadCharset(false)
@@ -355,10 +355,15 @@ void TextResourceDecoder::setEncoding(const TextEncoding& encoding, EncodingSour
else
m_encoding = encoding;
- m_codec.clear();
+ m_codec = nullptr;
m_source = source;
}
+bool TextResourceDecoder::hasEqualEncodingForCharset(const String& charset) const
+{
+ return defaultEncoding(m_contentType, charset) == m_encoding;
+}
+
// Returns the position of the encoding string.
static int findXMLEncoding(const char* str, int len, int& encodingLength)
{
@@ -475,6 +480,8 @@ bool TextResourceDecoder::checkForCSSCharset(const char* data, size_t len, bool&
int encodingNameLength = pos - dataStart;
++pos;
+ if (pos == dataEnd)
+ return false;
if (*pos == ';')
setEncoding(findTextEncoding(dataStart, encodingNameLength), EncodingFromCSSCharset);
@@ -658,9 +665,15 @@ String TextResourceDecoder::flush()
String result = m_codec->decode(m_buffer.data(), m_buffer.size(), true, m_contentType == XML && !m_useLenientXMLDecoding, m_sawError);
m_buffer.clear();
- m_codec.clear();
+ m_codec = nullptr;
m_checkedForBOM = false; // Skip BOM again when re-decoding.
return result;
}
+String TextResourceDecoder::decodeAndFlush(const char* data, size_t length)
+{
+ String decoded = decode(data, length);
+ return decoded + flush();
+}
+
}