[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc
kseo at webkit.org
kseo at webkit.org
Wed Dec 22 14:41:54 UTC 2010
The following commit has been merged in the debian/experimental branch:
commit a4fa7e4f37bf7fbb59f5390a20ce799e5e3cd9e7
Author: kseo at webkit.org <kseo at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Sat Oct 16 21:04:30 2010 +0000
[BREWMP] Port TextCodec
https://bugs.webkit.org/show_bug.cgi?id=45797
Reviewed by Kent Tamura.
Implement TextCodec with Brew MP's ICharsetConv.
Only UTF-8 is supported for now.
* platform/text/TextEncoding.cpp:
(WebCore::TextEncoding::encode):
* platform/text/TextEncodingRegistry.cpp:
(WebCore::buildBaseTextCodecMaps):
* platform/text/brew/TextCodecBrew.cpp: Added.
(WebCore::newTextCodecBrew):
(WebCore::TextCodecBrew::registerBaseEncodingNames):
(WebCore::TextCodecBrew::registerBaseCodecs):
(WebCore::TextCodecBrew::registerExtendedEncodingNames):
(WebCore::TextCodecBrew::registerExtendedCodecs):
(WebCore::TextCodecBrew::TextCodecBrew):
(WebCore::TextCodecBrew::~TextCodecBrew):
(WebCore::TextCodecBrew::decode):
(WebCore::TextCodecBrew::encode):
* platform/text/brew/TextCodecBrew.h: Added.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@69917 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 0072a8a..696e160 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,29 @@
+2010-10-16 Kwang Yul Seo <skyul at company100.net>
+
+ Reviewed by Kent Tamura.
+
+ [BREWMP] Port TextCodec
+ https://bugs.webkit.org/show_bug.cgi?id=45797
+
+ Implement TextCodec with Brew MP's ICharsetConv.
+ Only UTF-8 is supported for now.
+
+ * platform/text/TextEncoding.cpp:
+ (WebCore::TextEncoding::encode):
+ * platform/text/TextEncodingRegistry.cpp:
+ (WebCore::buildBaseTextCodecMaps):
+ * platform/text/brew/TextCodecBrew.cpp: Added.
+ (WebCore::newTextCodecBrew):
+ (WebCore::TextCodecBrew::registerBaseEncodingNames):
+ (WebCore::TextCodecBrew::registerBaseCodecs):
+ (WebCore::TextCodecBrew::registerExtendedEncodingNames):
+ (WebCore::TextCodecBrew::registerExtendedCodecs):
+ (WebCore::TextCodecBrew::TextCodecBrew):
+ (WebCore::TextCodecBrew::~TextCodecBrew):
+ (WebCore::TextCodecBrew::decode):
+ (WebCore::TextCodecBrew::encode):
+ * platform/text/brew/TextCodecBrew.h: Added.
+
2010-10-16 Patrick Gansterer <paroga at webkit.org>
Unreviewed.
diff --git a/WebCore/platform/text/TextEncoding.cpp b/WebCore/platform/text/TextEncoding.cpp
index 29ae170..921ceeb 100644
--- a/WebCore/platform/text/TextEncoding.cpp
+++ b/WebCore/platform/text/TextEncoding.cpp
@@ -133,6 +133,10 @@ CString TextEncoding::encode(const UChar* characters, size_t length, Unencodable
// normalization will be done by Windows CE API
OwnPtr<TextCodec> textCodec = newTextCodec(*this);
return textCodec.get() ? textCodec->encode(characters, length, handling) : CString();
+#elif USE(BREWMP_UNICODE)
+ // FIXME: not sure if Brew MP normalizes the input string automatically
+ OwnPtr<TextCodec> textCodec = newTextCodec(*this);
+ return textCodec.get() ? textCodec->encode(characters, length, handling) : CString();
#endif
}
diff --git a/WebCore/platform/text/TextEncodingRegistry.cpp b/WebCore/platform/text/TextEncodingRegistry.cpp
index 40fcdc5..fbe5826 100644
--- a/WebCore/platform/text/TextEncodingRegistry.cpp
+++ b/WebCore/platform/text/TextEncodingRegistry.cpp
@@ -31,6 +31,7 @@
#include "TextCodecLatin1.h"
#include "TextCodecUserDefined.h"
#include "TextCodecUTF16.h"
+#include "TextEncoding.h"
#include <wtf/ASCIICType.h>
#include <wtf/Assertions.h>
#include <wtf/HashFunctions.h>
@@ -51,6 +52,9 @@
#if USE(GLIB_UNICODE)
#include "gtk/TextCodecGtk.h"
#endif
+#if USE(BREWMP_UNICODE)
+#include "brew/TextCodecBrew.h"
+#endif
#if OS(WINCE) && !PLATFORM(QT)
#include "TextCodecWinCE.h"
#endif
@@ -235,6 +239,11 @@ static void buildBaseTextCodecMaps()
TextCodecGtk::registerBaseCodecs(addToTextCodecMap);
#endif
+#if USE(BREWMP_UNICODE)
+ TextCodecBrew::registerBaseEncodingNames(addToTextEncodingNameMap);
+ TextCodecBrew::registerBaseCodecs(addToTextCodecMap);
+#endif
+
#if OS(WINCE) && !PLATFORM(QT)
TextCodecWinCE::registerBaseEncodingNames(addToTextEncodingNameMap);
TextCodecWinCE::registerBaseCodecs(addToTextCodecMap);
diff --git a/WebCore/platform/text/brew/TextCodecBrew.cpp b/WebCore/platform/text/brew/TextCodecBrew.cpp
new file mode 100644
index 0000000..1f32298
--- /dev/null
+++ b/WebCore/platform/text/brew/TextCodecBrew.cpp
@@ -0,0 +1,214 @@
+/*
+ * Copyright (C) 2010 Company 100, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "TextCodecBrew.h"
+
+#include "AEEAppGen.h"
+#include "AEEICharsetConv.h"
+#include "NotImplemented.h"
+#include "PlatformString.h"
+#include <wtf/Assertions.h>
+#include <wtf/text/CString.h>
+
+namespace WebCore {
+
+// FIXME: Not sure if there are Brew MP devices which use big endian.
+const char* WebCore::TextCodecBrew::m_internalEncodingName = "UTF-16LE";
+
+static PassOwnPtr<TextCodec> newTextCodecBrew(const TextEncoding& encoding, const void*)
+{
+ return new TextCodecBrew(encoding);
+}
+
+void TextCodecBrew::registerBaseEncodingNames(EncodingNameRegistrar registrar)
+{
+ registrar("UTF-8", "UTF-8");
+}
+
+void TextCodecBrew::registerBaseCodecs(TextCodecRegistrar registrar)
+{
+ registrar("UTF-8", newTextCodecBrew, 0);
+}
+
+void TextCodecBrew::registerExtendedEncodingNames(EncodingNameRegistrar registrar)
+{
+ // FIXME: Not sure how to enumerate all available encodings.
+ notImplemented();
+}
+
+void TextCodecBrew::registerExtendedCodecs(TextCodecRegistrar registrar)
+{
+ notImplemented();
+}
+
+TextCodecBrew::TextCodecBrew(const TextEncoding& encoding)
+ : m_charsetConverter(0)
+ , m_encoding(encoding)
+ , m_numBufferedBytes(0)
+{
+ String format = String::format("%s>%s", encoding.name(), m_internalEncodingName);
+
+ IShell* shell = reinterpret_cast<AEEApplet*>(GETAPPINSTANCE())->m_pIShell;
+ AEECLSID classID = ISHELL_GetHandler(shell, AEEIID_ICharsetConv, format.latin1().data());
+ ISHELL_CreateInstance(shell, classID, reinterpret_cast<void**>(&m_charsetConverter));
+
+ ASSERT(m_charsetConverter);
+}
+
+TextCodecBrew::~TextCodecBrew()
+{
+ if (m_charsetConverter)
+ ICharsetConv_Release(m_charsetConverter);
+}
+
+String TextCodecBrew::decode(const char* bytes, size_t length, bool flush, bool stopOnError, bool& sawError)
+{
+ int code = ICharsetConv_Initialize(m_charsetConverter, m_encoding.name(), m_internalEncodingName, 0);
+ ASSERT(code == AEE_SUCCESS);
+
+ Vector<UChar> result;
+ Vector<unsigned char> prefixedBytes(length);
+
+ int srcSize;
+ unsigned char* srcBegin;
+
+ if (m_numBufferedBytes) {
+ srcSize = length + m_numBufferedBytes;
+ prefixedBytes.grow(srcSize);
+ memcpy(prefixedBytes.data(), m_bufferedBytes, m_numBufferedBytes);
+ memcpy(prefixedBytes.data() + m_numBufferedBytes, bytes, length);
+
+ srcBegin = prefixedBytes.data();
+
+ // all buffered bytes are consumed now
+ m_numBufferedBytes = 0;
+ } else {
+ srcSize = length;
+ srcBegin = const_cast<unsigned char*>(reinterpret_cast<const unsigned char*>(bytes));
+ }
+
+ unsigned char* src = srcBegin;
+ unsigned char* srcEnd = srcBegin + srcSize;
+
+ Vector<UChar> dstBuffer(srcSize);
+
+ while (src < srcEnd) {
+ int numCharsConverted;
+ unsigned char* dstBegin = reinterpret_cast<unsigned char*>(dstBuffer.data());
+ unsigned char* dst = dstBegin;
+ int dstSize = dstBuffer.size() * sizeof(UChar);
+
+ code = ICharsetConv_CharsetConvert(m_charsetConverter, &src, &srcSize, &dst, &dstSize, &numCharsConverted);
+ ASSERT(code != AEE_ENOSUCH);
+
+ if (code == AEE_EBUFFERTOOSMALL) {
+ // Increase the buffer and try it again.
+ dstBuffer.grow(dstBuffer.size() * 2);
+ continue;
+ }
+
+ if (code == AEE_EBADITEM) {
+ sawError = true;
+ if (stopOnError) {
+ result.append(L'?');
+ break;
+ }
+
+ src++;
+ }
+
+ if (code == AEE_EINCOMPLETEITEM) {
+ if (flush) {
+ LOG_ERROR("Partial bytes at end of input while flush requested.");
+ sawError = true;
+ return String();
+ }
+
+ m_numBufferedBytes = srcEnd - src;
+ memcpy(m_bufferedBytes, src, m_numBufferedBytes);
+ break;
+ }
+
+ int numChars = (dst - dstBegin) / sizeof(UChar);
+ if (numChars > 0)
+ result.append(dstBuffer.data(), numChars);
+ }
+
+ return String::adopt(result);
+}
+
+CString TextCodecBrew::encode(const UChar* characters, size_t length, UnencodableHandling handling)
+{
+ if (!length)
+ return "";
+
+ unsigned int replacementCharacter = '?';
+
+ // FIXME: Impossible to handle EntitiesForUnencodables or URLEncodedEntitiesForUnencodables with ICharsetConv.
+ int code = ICharsetConv_Initialize(m_charsetConverter, m_internalEncodingName, m_encoding.name(), replacementCharacter);
+ ASSERT(code == AEE_SUCCESS);
+
+ Vector<char> result;
+
+ int srcSize = length * sizeof(UChar);
+ unsigned char* srcBegin = const_cast<unsigned char*>(reinterpret_cast<const unsigned char*>(characters));
+ unsigned char* src = srcBegin;
+ unsigned char* srcEnd = srcBegin + srcSize;
+
+ Vector<unsigned char> dstBuffer(length * sizeof(UChar));
+
+ while (src < srcEnd) {
+ int numCharsConverted;
+ unsigned char* dstBegin = dstBuffer.data();
+ unsigned char* dst = dstBegin;
+ int dstSize = dstBuffer.size();
+
+ code = ICharsetConv_CharsetConvert(m_charsetConverter, &src, &srcSize, &dst, &dstSize, &numCharsConverted);
+ ASSERT(code != AEE_EINCOMPLETEITEM);
+
+ if (code == AEE_ENOSUCH) {
+ LOG_ERROR("Conversion error, Code=%d", code);
+ return CString();
+ }
+
+ if (code == AEE_EBUFFERTOOSMALL) {
+ // Increase the buffer and try it again.
+ dstBuffer.grow(dstBuffer.size() * 2);
+ continue;
+ }
+
+ if (code == AEE_EBADITEM)
+ src += sizeof(UChar); // Skip the invalid character
+
+ int numBytes = dst - dstBegin;
+ if (numBytes > 0)
+ result.append(dstBuffer.data(), numBytes);
+ }
+
+ return CString(result.data(), result.size());
+}
+
+} // namespace WebCore
diff --git a/WebCore/platform/text/brew/TextCodecBrew.h b/WebCore/platform/text/brew/TextCodecBrew.h
new file mode 100644
index 0000000..97e2c87
--- /dev/null
+++ b/WebCore/platform/text/brew/TextCodecBrew.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2010 Company 100, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef TextCodecBrew_h
+#define TextCodecBrew_h
+
+#include "TextCodec.h"
+#include "TextEncoding.h"
+
+typedef struct ICharsetConv ICharsetConv;
+
+namespace WebCore {
+
+class TextCodecBrew : public TextCodec {
+public:
+ static void registerBaseEncodingNames(EncodingNameRegistrar);
+ static void registerBaseCodecs(TextCodecRegistrar);
+
+ static void registerExtendedEncodingNames(EncodingNameRegistrar);
+ static void registerExtendedCodecs(TextCodecRegistrar);
+
+ TextCodecBrew(const TextEncoding&);
+ virtual ~TextCodecBrew();
+
+ virtual String decode(const char*, size_t length, bool flush, bool stopOnError, bool& sawError);
+ virtual CString encode(const UChar*, size_t length, UnencodableHandling);
+
+private:
+ TextEncoding m_encoding;
+ size_t m_numBufferedBytes;
+ unsigned char m_bufferedBytes[16]; // bigger than any single multi-byte character
+ ICharsetConv* m_charsetConverter;
+
+ static const char* m_internalEncodingName;
+};
+
+} // namespace WebCore
+
+#endif // TextCodecBrew_h
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list