Diff
Modified: trunk/Source/WebCore/ChangeLog (263021 => 263022)
--- trunk/Source/WebCore/ChangeLog 2020-06-15 08:17:23 UTC (rev 263021)
+++ trunk/Source/WebCore/ChangeLog 2020-06-15 08:35:15 UTC (rev 263022)
@@ -1,3 +1,21 @@
+2020-06-15 Tetsuharu Ohzeki <[email protected]>
+
+ Move textFromUTF8() to TextResourceDecoder from FetchBodyConsumer
+ https://bugs.webkit.org/show_bug.cgi?id=213170
+
+ Reviewed by Youenn Fablet.
+
+ This function abstracts https://encoding.spec.whatwg.org/#utf-8-decode
+ so I think it's better to place to `TextResourceDecoder`.
+
+ * Modules/fetch/FetchBodyConsumer.cpp:
+ (WebCore::resolveWithTypeAndData):
+ (WebCore::FetchBodyConsumer::takeAsText):
+ * loader/TextResourceDecoder.cpp:
+ (WebCore::shouldPrependBOM):
+ (WebCore::TextResourceDecoder::textFromUTF8):
+ * loader/TextResourceDecoder.h:
+
2020-06-15 Youenn Fablet <[email protected]>
MediaRecorder should not be collectable when fetching data from its backend
Modified: trunk/Source/WebCore/Modules/fetch/FetchBodyConsumer.cpp (263021 => 263022)
--- trunk/Source/WebCore/Modules/fetch/FetchBodyConsumer.cpp 2020-06-15 08:17:23 UTC (rev 263021)
+++ trunk/Source/WebCore/Modules/fetch/FetchBodyConsumer.cpp 2020-06-15 08:35:15 UTC (rev 263022)
@@ -42,21 +42,6 @@
return Blob::create(WTFMove(value), contentType);
}
-static inline bool shouldPrependBOM(const unsigned char* data, unsigned length)
-{
- if (length < 3)
- return true;
- return data[0] != 0xef || data[1] != 0xbb || data[2] != 0xbf;
-}
-
-static String textFromUTF8(const unsigned char* data, unsigned length)
-{
- auto decoder = TextResourceDecoder::create("text/plain", "UTF-8");
- if (shouldPrependBOM(data, length))
- decoder->decode("\xef\xbb\xbf", 3);
- return decoder->decodeAndFlush(reinterpret_cast<const char*>(data), length);
-}
-
static void resolveWithTypeAndData(Ref<DeferredPromise>&& promise, FetchBodyConsumer::Type type, const String& contentType, const unsigned char* data, unsigned length)
{
switch (type) {
@@ -69,10 +54,10 @@
});
return;
case FetchBodyConsumer::Type::JSON:
- fulfillPromiseWithJSON(WTFMove(promise), textFromUTF8(data, length));
+ fulfillPromiseWithJSON(WTFMove(promise), TextResourceDecoder::textFromUTF8(data, length));
return;
case FetchBodyConsumer::Type::Text:
- promise->resolve<IDLDOMString>(textFromUTF8(data, length));
+ promise->resolve<IDLDOMString>(TextResourceDecoder::textFromUTF8(data, length));
return;
case FetchBodyConsumer::Type::None:
ASSERT_NOT_REACHED();
@@ -196,7 +181,7 @@
if (!m_buffer)
return String();
- auto text = textFromUTF8(reinterpret_cast<const unsigned char*>(m_buffer->data()), m_buffer->size());
+ auto text = TextResourceDecoder::textFromUTF8(reinterpret_cast<const unsigned char*>(m_buffer->data()), m_buffer->size());
m_buffer = nullptr;
return text;
}
Modified: trunk/Source/WebCore/loader/TextResourceDecoder.cpp (263021 => 263022)
--- trunk/Source/WebCore/loader/TextResourceDecoder.cpp 2020-06-15 08:17:23 UTC (rev 263021)
+++ trunk/Source/WebCore/loader/TextResourceDecoder.cpp 2020-06-15 08:35:15 UTC (rev 263022)
@@ -320,6 +320,22 @@
TextResourceDecoder::~TextResourceDecoder() = default;
+static inline bool shouldPrependBOM(const unsigned char* data, unsigned length)
+{
+ if (length < 3)
+ return true;
+ return data[0] != 0xef || data[1] != 0xbb || data[2] != 0xbf;
+}
+
+// https://encoding.spec.whatwg.org/#utf-8-decode
+String TextResourceDecoder::textFromUTF8(const unsigned char* data, unsigned length)
+{
+ auto decoder = TextResourceDecoder::create("text/plain", "UTF-8");
+ if (shouldPrependBOM(data, length))
+ decoder->decode("\xef\xbb\xbf", 3);
+ return decoder->decodeAndFlush(reinterpret_cast<const char*>(data), length);
+}
+
void TextResourceDecoder::setEncoding(const TextEncoding& encoding, EncodingSource source)
{
// In case the encoding didn't exist, we keep the old one (helps some sites specifying invalid encodings).
Modified: trunk/Source/WebCore/loader/TextResourceDecoder.h (263021 => 263022)
--- trunk/Source/WebCore/loader/TextResourceDecoder.h 2020-06-15 08:17:23 UTC (rev 263021)
+++ trunk/Source/WebCore/loader/TextResourceDecoder.h 2020-06-15 08:35:15 UTC (rev 263022)
@@ -46,6 +46,8 @@
WEBCORE_EXPORT static Ref<TextResourceDecoder> create(const String& mimeType, const TextEncoding& defaultEncoding = { }, bool usesEncodingDetector = false);
WEBCORE_EXPORT ~TextResourceDecoder();
+ static String textFromUTF8(const unsigned char* data, unsigned length);
+
void setEncoding(const TextEncoding&, EncodingSource);
const TextEncoding& encoding() const { return m_encoding; }
const TextEncoding* encodingForURLParsing();