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

Unified Diff: third_party/WebKit/Source/web/WebPageSerializerImpl.cpp

Issue 1407663004: Tweaking WebPageSerializerImpl to emit a BOM for UTF16/32. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Saving UTF16 with BOM. Leaving UTF32 in a broken state. Created 5 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/web/WebPageSerializerImpl.cpp
diff --git a/third_party/WebKit/Source/web/WebPageSerializerImpl.cpp b/third_party/WebKit/Source/web/WebPageSerializerImpl.cpp
index 694c823537fd26515f275bd1652c7d9b25ae848e..dae6be2b83589f54d21dd41a566007e9bb56d3fb 100644
--- a/third_party/WebKit/Source/web/WebPageSerializerImpl.cpp
+++ b/third_party/WebKit/Source/web/WebPageSerializerImpl.cpp
@@ -93,6 +93,8 @@
#include "core/page/PageSerializer.h"
#include "public/platform/WebVector.h"
#include "web/WebLocalFrameImpl.h"
+#include "wtf/ArrayBufferBuilder.h"
+#include "wtf/text/CString.h"
#include "wtf/text/TextEncoding.h"
namespace blink {
@@ -274,8 +276,26 @@ void WebPageSerializerImpl::encodeAndFlushBuffer(
CString encodedContent = param->textEncoding.encode(content, WTF::EntitiesForUnencodables);
+ CString encodedBOM;
jsbell 2015/12/07 22:53:51 Move this block up above the encodedContent initia
+ if (m_noBytesEncodedYet) {
+ encodedBOM = param->textEncoding.encodeBOMifApplicable();
jsbell 2015/12/07 22:53:51 I was going to suggest some changes to encodeBOMif
+ m_noBytesEncodedYet = false;
+ }
+
+ WebCString result;
+ if (encodedBOM.length() == 0) {
+ result = WebCString(encodedContent);
+ } else {
+ ArrayBufferBuilder resultBuilder;
+ resultBuilder.append(encodedBOM.data(), encodedBOM.length());
+ resultBuilder.append(encodedContent.data(), encodedContent.length());
+ result = WebCString(
jsbell 2015/12/07 22:53:51 Don't need to wrap in blink.
+ static_cast<const char*>(resultBuilder.data()),
+ resultBuilder.byteLength());
+ }
+
// Send result to the client.
- m_client->didSerializeDataForFrame(WebCString(encodedContent), status);
+ m_client->didSerializeDataForFrame(result, status);
}
// TODO(yosin): We should utilize |MarkupFormatter| here to share code,
@@ -423,6 +443,7 @@ WebPageSerializerImpl::WebPageSerializerImpl(WebLocalFrame* frame,
const WebString& localDirectoryName)
: m_client(client)
, m_localDirectoryName(localDirectoryName)
+ , m_noBytesEncodedYet(true)
, m_htmlEntities(false)
, m_xmlEntities(true)
{

Powered by Google App Engine
This is Rietveld 408576698