summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordan sinclair <dsinclair@chromium.org>2018-04-17 18:12:38 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-17 18:12:38 +0000
commitbc069b7a855998ab28f487d2f09152851dddb16a (patch)
treeb50e3713a80177034a3fc7a2c12920c15aeb7056
parent8b4a3c7ef32b2ffb4874e4cc65b38ee555d8806e (diff)
downloadpdfium-bc069b7a855998ab28f487d2f09152851dddb16a.tar.xz
Use an IFX_SeekableStream for XML saving
This CL converts the CFX_XML Save methods to take an IFX_SeekableStream instead of a CFX_SeekableStreamProxy. Change-Id: I6b3f6acc9f51e73b3c863b965b4dcdcbd25ba949 Reviewed-on: https://pdfium-review.googlesource.com/30850 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
-rw-r--r--core/fxcrt/cfx_blockbuffer.h1
-rw-r--r--core/fxcrt/xml/cfx_xmlchardata.cpp10
-rw-r--r--core/fxcrt/xml/cfx_xmlchardata.h2
-rw-r--r--core/fxcrt/xml/cfx_xmlelement.cpp21
-rw-r--r--core/fxcrt/xml/cfx_xmlelement.h2
-rw-r--r--core/fxcrt/xml/cfx_xmlinstruction.cpp27
-rw-r--r--core/fxcrt/xml/cfx_xmlinstruction.h2
-rw-r--r--core/fxcrt/xml/cfx_xmlnode.cpp2
-rw-r--r--core/fxcrt/xml/cfx_xmlnode.h4
-rw-r--r--core/fxcrt/xml/cfx_xmltext.cpp5
-rw-r--r--core/fxcrt/xml/cfx_xmltext.h2
-rw-r--r--fxjs/xfa/cjx_node.cpp24
-rw-r--r--xfa/fxfa/parser/cxfa_dataexporter.cpp24
-rw-r--r--xfa/fxfa/parser/xfa_utils.cpp6
14 files changed, 56 insertions, 76 deletions
diff --git a/core/fxcrt/cfx_blockbuffer.h b/core/fxcrt/cfx_blockbuffer.h
index 423aa6820b..1673136643 100644
--- a/core/fxcrt/cfx_blockbuffer.h
+++ b/core/fxcrt/cfx_blockbuffer.h
@@ -21,7 +21,6 @@ class CFX_BlockBuffer {
~CFX_BlockBuffer();
bool InitBuffer();
- bool IsInitialized() { return m_BufferSize / GetAllocStep() >= 1; }
std::pair<wchar_t*, size_t> GetAvailableBlock();
size_t GetAllocStep() const;
diff --git a/core/fxcrt/xml/cfx_xmlchardata.cpp b/core/fxcrt/xml/cfx_xmlchardata.cpp
index 7712b30dfe..b613b15d00 100644
--- a/core/fxcrt/xml/cfx_xmlchardata.cpp
+++ b/core/fxcrt/xml/cfx_xmlchardata.cpp
@@ -21,10 +21,8 @@ std::unique_ptr<CFX_XMLNode> CFX_XMLCharData::Clone() {
return pdfium::MakeUnique<CFX_XMLCharData>(GetText());
}
-void CFX_XMLCharData::Save(
- const RetainPtr<CFX_SeekableStreamProxy>& pXMLStream) {
- WideString ws = L"<![CDATA[";
- ws += GetText();
- ws += L"]]>";
- pXMLStream->WriteString(ws.AsStringView());
+void CFX_XMLCharData::Save(const RetainPtr<IFX_SeekableStream>& pXMLStream) {
+ pXMLStream->WriteString("<![CDATA[");
+ pXMLStream->WriteString(GetText().UTF8Encode().AsStringView());
+ pXMLStream->WriteString("]]>");
}
diff --git a/core/fxcrt/xml/cfx_xmlchardata.h b/core/fxcrt/xml/cfx_xmlchardata.h
index c702d9636f..5b00597955 100644
--- a/core/fxcrt/xml/cfx_xmlchardata.h
+++ b/core/fxcrt/xml/cfx_xmlchardata.h
@@ -20,7 +20,7 @@ class CFX_XMLCharData : public CFX_XMLText {
// CFX_XMLNode
FX_XMLNODETYPE GetType() const override;
std::unique_ptr<CFX_XMLNode> Clone() override;
- void Save(const RetainPtr<CFX_SeekableStreamProxy>& pXMLStream) override;
+ void Save(const RetainPtr<IFX_SeekableStream>& pXMLStream) override;
};
#endif // CORE_FXCRT_XML_CFX_XMLCHARDATA_H_
diff --git a/core/fxcrt/xml/cfx_xmlelement.cpp b/core/fxcrt/xml/cfx_xmlelement.cpp
index 42588c6393..c54d8488a3 100644
--- a/core/fxcrt/xml/cfx_xmlelement.cpp
+++ b/core/fxcrt/xml/cfx_xmlelement.cpp
@@ -93,30 +93,31 @@ void CFX_XMLElement::SetTextData(const WideString& wsText) {
AppendChild(new CFX_XMLText(wsText));
}
-void CFX_XMLElement::Save(
- const RetainPtr<CFX_SeekableStreamProxy>& pXMLStream) {
- pXMLStream->WriteString(L"<");
- pXMLStream->WriteString(name_.AsStringView());
+void CFX_XMLElement::Save(const RetainPtr<IFX_SeekableStream>& pXMLStream) {
+ ByteStringView name_encoded = name_.UTF8Encode().AsStringView();
+
+ pXMLStream->WriteString("<");
+ pXMLStream->WriteString(name_encoded);
for (auto it : attrs_) {
pXMLStream->WriteString(
- AttributeToString(it.first, it.second).AsStringView());
+ AttributeToString(it.first, it.second).UTF8Encode().AsStringView());
}
if (!GetFirstChild()) {
- pXMLStream->WriteString(L" />");
+ pXMLStream->WriteString(" />\n");
return;
}
- pXMLStream->WriteString(L">");
+ pXMLStream->WriteString(">\n");
for (CFX_XMLNode* pChild = GetFirstChild(); pChild;
pChild = pChild->GetNextSibling()) {
pChild->Save(pXMLStream);
}
- pXMLStream->WriteString(L"</");
- pXMLStream->WriteString(name_.AsStringView());
- pXMLStream->WriteString(L"\n>");
+ pXMLStream->WriteString("</");
+ pXMLStream->WriteString(name_encoded);
+ pXMLStream->WriteString(">\n");
}
CFX_XMLElement* CFX_XMLElement::GetFirstChildNamed(
diff --git a/core/fxcrt/xml/cfx_xmlelement.h b/core/fxcrt/xml/cfx_xmlelement.h
index f8533a1445..c1d9fea3f0 100644
--- a/core/fxcrt/xml/cfx_xmlelement.h
+++ b/core/fxcrt/xml/cfx_xmlelement.h
@@ -22,7 +22,7 @@ class CFX_XMLElement : public CFX_XMLNode {
// CFX_XMLNode
FX_XMLNODETYPE GetType() const override;
std::unique_ptr<CFX_XMLNode> Clone() override;
- void Save(const RetainPtr<CFX_SeekableStreamProxy>& pXMLStream) override;
+ void Save(const RetainPtr<IFX_SeekableStream>& pXMLStream) override;
WideString GetName() const { return name_; }
diff --git a/core/fxcrt/xml/cfx_xmlinstruction.cpp b/core/fxcrt/xml/cfx_xmlinstruction.cpp
index f3185fbf5b..7b844e6808 100644
--- a/core/fxcrt/xml/cfx_xmlinstruction.cpp
+++ b/core/fxcrt/xml/cfx_xmlinstruction.cpp
@@ -40,31 +40,20 @@ bool CFX_XMLInstruction::IsAcrobat() const {
return name_ == L"acrobat";
}
-void CFX_XMLInstruction::Save(
- const RetainPtr<CFX_SeekableStreamProxy>& pXMLStream) {
+void CFX_XMLInstruction::Save(const RetainPtr<IFX_SeekableStream>& pXMLStream) {
if (name_.CompareNoCase(L"xml") == 0) {
- WideString ws = L"<?xml version=\"1.0\" encoding=\"";
- uint16_t wCodePage = pXMLStream->GetCodePage();
- if (wCodePage == FX_CODEPAGE_UTF16LE)
- ws += L"UTF-16";
- else if (wCodePage == FX_CODEPAGE_UTF16BE)
- ws += L"UTF-16be";
- else
- ws += L"UTF-8";
-
- ws += L"\"?>";
- pXMLStream->WriteString(ws.AsStringView());
+ pXMLStream->WriteString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
return;
}
- pXMLStream->WriteString(
- WideString::Format(L"<?%ls", name_.c_str()).AsStringView());
+ pXMLStream->WriteString("<?");
+ pXMLStream->WriteString(name_.UTF8Encode().AsStringView());
for (const WideString& target : m_TargetData) {
- pXMLStream->WriteString(L"\"");
- pXMLStream->WriteString(target.AsStringView());
- pXMLStream->WriteString(L"\"");
+ pXMLStream->WriteString("\"");
+ pXMLStream->WriteString(target.UTF8Encode().AsStringView());
+ pXMLStream->WriteString("\"");
}
- pXMLStream->WriteString(WideStringView(L"?>"));
+ pXMLStream->WriteString("?>");
}
diff --git a/core/fxcrt/xml/cfx_xmlinstruction.h b/core/fxcrt/xml/cfx_xmlinstruction.h
index 7cee1d4fc0..045610bd8a 100644
--- a/core/fxcrt/xml/cfx_xmlinstruction.h
+++ b/core/fxcrt/xml/cfx_xmlinstruction.h
@@ -21,7 +21,7 @@ class CFX_XMLInstruction : public CFX_XMLNode {
// CFX_XMLNode
FX_XMLNODETYPE GetType() const override;
std::unique_ptr<CFX_XMLNode> Clone() override;
- void Save(const RetainPtr<CFX_SeekableStreamProxy>& pXMLStream) override;
+ void Save(const RetainPtr<IFX_SeekableStream>& pXMLStream) override;
bool IsOriginalXFAVersion() const;
bool IsAcrobat() const;
diff --git a/core/fxcrt/xml/cfx_xmlnode.cpp b/core/fxcrt/xml/cfx_xmlnode.cpp
index 540b20e721..6303615d01 100644
--- a/core/fxcrt/xml/cfx_xmlnode.cpp
+++ b/core/fxcrt/xml/cfx_xmlnode.cpp
@@ -108,7 +108,7 @@ std::unique_ptr<CFX_XMLNode> CFX_XMLNode::Clone() {
return nullptr;
}
-void CFX_XMLNode::Save(const RetainPtr<CFX_SeekableStreamProxy>& pXMLStream) {}
+void CFX_XMLNode::Save(const RetainPtr<IFX_SeekableStream>& pXMLStream) {}
WideString CFX_XMLNode::EncodeEntities(const WideString& value) {
WideString ret = value;
diff --git a/core/fxcrt/xml/cfx_xmlnode.h b/core/fxcrt/xml/cfx_xmlnode.h
index 7278d2b4ca..86b5e998e6 100644
--- a/core/fxcrt/xml/cfx_xmlnode.h
+++ b/core/fxcrt/xml/cfx_xmlnode.h
@@ -9,7 +9,7 @@
#include <memory>
-#include "core/fxcrt/cfx_seekablestreamproxy.h"
+#include "core/fxcrt/fx_stream.h"
#include "core/fxcrt/retain_ptr.h"
enum FX_XMLNODETYPE {
@@ -32,7 +32,7 @@ class CFX_XMLNode {
virtual FX_XMLNODETYPE GetType() const;
virtual std::unique_ptr<CFX_XMLNode> Clone();
- virtual void Save(const RetainPtr<CFX_SeekableStreamProxy>& pXMLStream);
+ virtual void Save(const RetainPtr<IFX_SeekableStream>& pXMLStream);
CFX_XMLNode* GetRoot();
CFX_XMLNode* GetParent() const { return parent_; }
diff --git a/core/fxcrt/xml/cfx_xmltext.cpp b/core/fxcrt/xml/cfx_xmltext.cpp
index 05e2935440..74d0a501eb 100644
--- a/core/fxcrt/xml/cfx_xmltext.cpp
+++ b/core/fxcrt/xml/cfx_xmltext.cpp
@@ -21,6 +21,7 @@ std::unique_ptr<CFX_XMLNode> CFX_XMLText::Clone() {
return pdfium::MakeUnique<CFX_XMLText>(m_wsText);
}
-void CFX_XMLText::Save(const RetainPtr<CFX_SeekableStreamProxy>& pXMLStream) {
- pXMLStream->WriteString(EncodeEntities(GetText()).AsStringView());
+void CFX_XMLText::Save(const RetainPtr<IFX_SeekableStream>& pXMLStream) {
+ pXMLStream->WriteString(
+ EncodeEntities(GetText()).UTF8Encode().AsStringView());
}
diff --git a/core/fxcrt/xml/cfx_xmltext.h b/core/fxcrt/xml/cfx_xmltext.h
index b26eef14ac..bbf14be257 100644
--- a/core/fxcrt/xml/cfx_xmltext.h
+++ b/core/fxcrt/xml/cfx_xmltext.h
@@ -20,7 +20,7 @@ class CFX_XMLText : public CFX_XMLNode {
// CFX_XMLNode
FX_XMLNODETYPE GetType() const override;
std::unique_ptr<CFX_XMLNode> Clone() override;
- void Save(const RetainPtr<CFX_SeekableStreamProxy>& pXMLStream) override;
+ void Save(const RetainPtr<IFX_SeekableStream>& pXMLStream) override;
WideString GetText() const { return m_wsText; }
void SetText(const WideString& wsText) { m_wsText = wsText; }
diff --git a/fxjs/xfa/cjx_node.cpp b/fxjs/xfa/cjx_node.cpp
index 125c52ca93..dc4cd30132 100644
--- a/fxjs/xfa/cjx_node.cpp
+++ b/fxjs/xfa/cjx_node.cpp
@@ -332,7 +332,7 @@ CJS_Return CJX_Node::saveXML(CFX_V8* runtime,
// TODO(weili): Check whether we need to save pretty print XML, pdfium:501.
- WideString bsXMLHeader = L"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
+ ByteString bsXMLHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
if (GetXFANode()->GetPacketType() != XFA_PacketType::Form &&
GetXFANode()->GetPacketType() != XFA_PacketType::Datasets) {
return CJS_Return(runtime->NewString(""));
@@ -342,23 +342,23 @@ CJS_Return CJX_Node::saveXML(CFX_V8* runtime,
if (GetXFANode()->GetPacketType() == XFA_PacketType::Datasets) {
pElement = GetXFANode()->GetXMLMappingNode();
if (!pElement || pElement->GetType() != FX_XMLNODE_Element) {
- return CJS_Return(
- runtime->NewString(bsXMLHeader.UTF8Encode().AsStringView()));
+ return CJS_Return(runtime->NewString(bsXMLHeader.AsStringView()));
}
XFA_DataExporter_DealWithDataGroupNode(GetXFANode());
}
auto pMemoryStream = pdfium::MakeRetain<CFX_MemoryStream>(true);
- auto pStream =
- pdfium::MakeRetain<CFX_SeekableStreamProxy>(pMemoryStream, true);
- pStream->SetCodePage(FX_CODEPAGE_UTF8);
- pStream->WriteString(bsXMLHeader.AsStringView());
-
- if (GetXFANode()->GetPacketType() == XFA_PacketType::Form)
- XFA_DataExporter_RegenerateFormFile(GetXFANode(), pStream, true);
- else
- pElement->Save(pStream);
+ pMemoryStream->WriteString(bsXMLHeader.AsStringView());
+
+ if (GetXFANode()->GetPacketType() == XFA_PacketType::Form) {
+ auto proxy =
+ pdfium::MakeRetain<CFX_SeekableStreamProxy>(pMemoryStream, true);
+ proxy->SetCodePage(FX_CODEPAGE_UTF8);
+ XFA_DataExporter_RegenerateFormFile(GetXFANode(), proxy, true);
+ } else {
+ pElement->Save(pMemoryStream);
+ }
return CJS_Return(runtime->NewString(
ByteStringView(pMemoryStream->GetBuffer(), pMemoryStream->GetSize())));
diff --git a/xfa/fxfa/parser/cxfa_dataexporter.cpp b/xfa/fxfa/parser/cxfa_dataexporter.cpp
index 389b9dbacb..1bd81e820a 100644
--- a/xfa/fxfa/parser/cxfa_dataexporter.cpp
+++ b/xfa/fxfa/parser/cxfa_dataexporter.cpp
@@ -18,30 +18,23 @@ CXFA_DataExporter::CXFA_DataExporter() = default;
CXFA_DataExporter::~CXFA_DataExporter() = default;
-bool CXFA_DataExporter::Export(const RetainPtr<IFX_SeekableStream>& pWrite,
+bool CXFA_DataExporter::Export(const RetainPtr<IFX_SeekableStream>& pStream,
CXFA_Node* pNode) {
- ASSERT(pWrite);
- if (!pWrite)
- return false;
+ ASSERT(pStream);
- auto pStream = pdfium::MakeRetain<CFX_SeekableStreamProxy>(pWrite, true);
- pStream->SetCodePage(FX_CODEPAGE_UTF8);
- return Export(pStream, pNode);
-}
+ if (!pStream)
+ return false;
-bool CXFA_DataExporter::Export(
- const RetainPtr<CFX_SeekableStreamProxy>& pStream,
- CXFA_Node* pNode) {
if (pNode->IsModelNode()) {
switch (pNode->GetPacketType()) {
case XFA_PacketType::Xdp: {
pStream->WriteString(
- L"<xdp:xdp xmlns:xdp=\"http://ns.adobe.com/xdp/\">");
+ "<xdp:xdp xmlns:xdp=\"http://ns.adobe.com/xdp/\">");
for (CXFA_Node* pChild = pNode->GetFirstChild(); pChild;
pChild = pChild->GetNextSibling()) {
Export(pStream, pChild);
}
- pStream->WriteString(L"</xdp:xdp\n>");
+ pStream->WriteString("</xdp:xdp\n>");
break;
}
case XFA_PacketType::Datasets: {
@@ -57,7 +50,10 @@ bool CXFA_DataExporter::Export(
break;
}
case XFA_PacketType::Form: {
- XFA_DataExporter_RegenerateFormFile(pNode, pStream, false);
+ auto proxy =
+ pdfium::MakeRetain<CFX_SeekableStreamProxy>(pStream, false);
+ proxy->SetCodePage(FX_CODEPAGE_UTF8);
+ XFA_DataExporter_RegenerateFormFile(pNode, proxy, false);
break;
}
case XFA_PacketType::Template:
diff --git a/xfa/fxfa/parser/xfa_utils.cpp b/xfa/fxfa/parser/xfa_utils.cpp
index ebe087aa64..55baf10229 100644
--- a/xfa/fxfa/parser/xfa_utils.cpp
+++ b/xfa/fxfa/parser/xfa_utils.cpp
@@ -216,11 +216,7 @@ void RegenerateFormFile_Changed(CXFA_Node* pNode,
break;
auto pMemStream = pdfium::MakeRetain<CFX_MemoryStream>(true);
- auto pTempStream =
- pdfium::MakeRetain<CFX_SeekableStreamProxy>(pMemStream, true);
-
- pTempStream->SetCodePage(FX_CODEPAGE_UTF8);
- pRichTextXML->Save(pTempStream);
+ pRichTextXML->Save(pMemStream);
wsChildren += WideString::FromUTF8(
ByteStringView(pMemStream->GetBuffer(), pMemStream->GetSize()));
} else if (pRawValueNode->GetElementType() == XFA_Element::Sharpxml &&