diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2018-02-13 21:27:44 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-02-13 21:27:44 +0000 |
commit | 9c112f92d4c2046d5a4f8538f4d18b74a87649d4 (patch) | |
tree | ffd0ba656902d28257e6560c8713df895802d313 | |
parent | 20eb52e66c565d36a78dc1399f04f7485ccf8fe6 (diff) | |
download | pdfium-9c112f92d4c2046d5a4f8538f4d18b74a87649d4.tar.xz |
Cleanup CFX_XMLDoc::SaveXMLNode
The CFX_XMLDoc::SaveXMLNode method is almost an exact copy of the
CFX_XMLNode::SaveXMLNode. This CL removes the XMLDoc variant and calls
the XMLNode method directly.
This Removes the need to pass the CXFA_DocumentParser into CXFA_Document
and we can instead pass in the CXFA_FFNotify object directly.
Change-Id: Ic3c8c66375483fe73b44dd84064a1b71b039d61c
Reviewed-on: https://pdfium-review.googlesource.com/26530
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
-rw-r--r-- | core/fxcrt/xml/cfx_xmldoc.cpp | 111 | ||||
-rw-r--r-- | core/fxcrt/xml/cfx_xmldoc.h | 2 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_dataexporter.cpp | 7 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_document.cpp | 16 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_document.h | 10 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_document_parser.cpp | 6 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_document_parser.h | 1 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_node_unittest.cpp | 17 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_simple_parser.cpp | 4 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_simple_parser.h | 1 |
10 files changed, 12 insertions, 163 deletions
diff --git a/core/fxcrt/xml/cfx_xmldoc.cpp b/core/fxcrt/xml/cfx_xmldoc.cpp index 1c3785d313..236ab05c37 100644 --- a/core/fxcrt/xml/cfx_xmldoc.cpp +++ b/core/fxcrt/xml/cfx_xmldoc.cpp @@ -47,114 +47,3 @@ void CFX_XMLDoc::CloseXML() { m_pXMLParser.reset(); } -void CFX_XMLDoc::SaveXMLNode( - const RetainPtr<CFX_SeekableStreamProxy>& pXMLStream, - CFX_XMLNode* pINode) { - CFX_XMLNode* pNode = (CFX_XMLNode*)pINode; - switch (pNode->GetType()) { - case FX_XMLNODE_Instruction: { - CFX_XMLInstruction* pInstruction = (CFX_XMLInstruction*)pNode; - if (pInstruction->GetName().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()); - } else { - WideString ws = - WideString::Format(L"<?%ls", pInstruction->GetName().c_str()); - pXMLStream->WriteString(ws.AsStringView()); - - for (auto it : pInstruction->GetAttributes()) { - WideString wsValue = it.second; - wsValue.Replace(L"&", L"&"); - wsValue.Replace(L"<", L"<"); - wsValue.Replace(L">", L">"); - wsValue.Replace(L"\'", L"'"); - wsValue.Replace(L"\"", L"""); - - ws = L" "; - ws += it.first; - ws += L"=\""; - ws += wsValue; - ws += L"\""; - pXMLStream->WriteString(ws.AsStringView()); - } - - for (auto target : pInstruction->GetTargetData()) { - ws = L" \""; - ws += target; - ws += L"\""; - pXMLStream->WriteString(ws.AsStringView()); - } - ws = L"?>"; - pXMLStream->WriteString(ws.AsStringView()); - } - break; - } - case FX_XMLNODE_Element: { - WideString ws; - ws = L"<"; - ws += static_cast<CFX_XMLElement*>(pNode)->GetName(); - pXMLStream->WriteString(ws.AsStringView()); - - for (auto it : static_cast<CFX_XMLElement*>(pNode)->GetAttributes()) { - WideString wsValue = it.second; - wsValue.Replace(L"&", L"&"); - wsValue.Replace(L"<", L"<"); - wsValue.Replace(L">", L">"); - wsValue.Replace(L"\'", L"'"); - wsValue.Replace(L"\"", L"""); - - ws = L" "; - ws += it.first; - ws += L"=\""; - ws += wsValue; - ws += L"\""; - pXMLStream->WriteString(ws.AsStringView()); - } - if (pNode->m_pChild) { - ws = L"\n>"; - pXMLStream->WriteString(ws.AsStringView()); - CFX_XMLNode* pChild = pNode->m_pChild; - while (pChild) { - SaveXMLNode(pXMLStream, static_cast<CFX_XMLNode*>(pChild)); - pChild = pChild->m_pNext; - } - ws = L"</"; - ws += static_cast<CFX_XMLElement*>(pNode)->GetName(); - ws += L"\n>"; - } else { - ws = L"\n/>"; - } - pXMLStream->WriteString(ws.AsStringView()); - break; - } - case FX_XMLNODE_Text: { - WideString ws = static_cast<CFX_XMLText*>(pNode)->GetText(); - ws.Replace(L"&", L"&"); - ws.Replace(L"<", L"<"); - ws.Replace(L">", L">"); - ws.Replace(L"\'", L"'"); - ws.Replace(L"\"", L"""); - pXMLStream->WriteString(ws.AsStringView()); - break; - } - case FX_XMLNODE_CharData: { - WideString ws = L"<![CDATA["; - ws += static_cast<CFX_XMLCharData*>(pNode)->GetText(); - ws += L"]]>"; - pXMLStream->WriteString(ws.AsStringView()); - break; - } - case FX_XMLNODE_Unknown: - default: - break; - } -} diff --git a/core/fxcrt/xml/cfx_xmldoc.h b/core/fxcrt/xml/cfx_xmldoc.h index 28de7fdba1..8ab6b8fea4 100644 --- a/core/fxcrt/xml/cfx_xmldoc.h +++ b/core/fxcrt/xml/cfx_xmldoc.h @@ -24,8 +24,6 @@ class CFX_XMLDoc { void CloseXML(); CFX_XMLNode* GetRoot() const { return m_pRoot.get(); } - void SaveXMLNode(const RetainPtr<CFX_SeekableStreamProxy>& pXMLStream, - CFX_XMLNode* pNode); private: int32_t m_iStatus; diff --git a/xfa/fxfa/parser/cxfa_dataexporter.cpp b/xfa/fxfa/parser/cxfa_dataexporter.cpp index 23fc17883a..b254ce6cad 100644 --- a/xfa/fxfa/parser/cxfa_dataexporter.cpp +++ b/xfa/fxfa/parser/cxfa_dataexporter.cpp @@ -44,7 +44,6 @@ bool CXFA_DataExporter::Export( CXFA_Node* pNode, uint32_t dwFlag, const char* pChecksum) { - CFX_XMLDoc* pXMLDoc = m_pDocument->GetXMLDoc(); if (pNode->IsModelNode()) { switch (pNode->GetPacketType()) { case XFA_PacketType::Xdp: { @@ -66,7 +65,7 @@ bool CXFA_DataExporter::Export( CXFA_Node* pDataNode = pNode->GetFirstChild(); ASSERT(pDataNode); XFA_DataExporter_DealWithDataGroupNode(pDataNode); - pXMLDoc->SaveXMLNode(pStream, pElement); + pElement->SaveXMLNode(pStream); break; } case XFA_PacketType::Form: { @@ -80,7 +79,7 @@ bool CXFA_DataExporter::Export( if (!pElement || pElement->GetType() != FX_XMLNODE_Element) return false; - pXMLDoc->SaveXMLNode(pStream, pElement); + pElement->SaveXMLNode(pStream); break; } } @@ -103,7 +102,7 @@ bool CXFA_DataExporter::Export( XFA_DataExporter_DealWithDataGroupNode(pExportNode); pElement->SetString(L"xmlns:xfa", L"http://www.xfa.org/schema/xfa-data/1.0/"); - pXMLDoc->SaveXMLNode(pStream, pElement); + pElement->SaveXMLNode(pStream); pElement->RemoveAttribute(L"xmlns:xfa"); return true; diff --git a/xfa/fxfa/parser/cxfa_document.cpp b/xfa/fxfa/parser/cxfa_document.cpp index a21d3f974c..2a9d80e0cd 100644 --- a/xfa/fxfa/parser/cxfa_document.cpp +++ b/xfa/fxfa/parser/cxfa_document.cpp @@ -88,14 +88,12 @@ void MergeNode(CXFA_Document* pDocument, } // namespace -CXFA_Document::CXFA_Document(CXFA_DocumentParser* pParser) +CXFA_Document::CXFA_Document(CXFA_FFNotify* notify) : CXFA_NodeOwner(), - m_pParser(pParser), + notify_(notify), m_pRootNode(nullptr), m_eCurVersionMode(XFA_VERSION_DEFAULT), - m_dwDocFlags(0) { - ASSERT(m_pParser); -} + m_dwDocFlags(0) {} CXFA_Document::~CXFA_Document() { // Remove all the bindings before freeing the node as the ownership is wonky. @@ -125,14 +123,6 @@ void CXFA_Document::ClearLayoutData() { m_pScriptSignature.reset(); } -CFX_XMLDoc* CXFA_Document::GetXMLDoc() const { - return m_pParser->GetXMLDoc(); -} - -CXFA_FFNotify* CXFA_Document::GetNotify() const { - return m_pParser->GetNotify(); -} - CXFA_Object* CXFA_Document::GetXFAObject(XFA_HashCode dwNodeNameHash) { switch (dwNodeNameHash) { case XFA_HASHCODE_Data: { diff --git a/xfa/fxfa/parser/cxfa_document.h b/xfa/fxfa/parser/cxfa_document.h index 4d1c417c5b..9dc8e52ab6 100644 --- a/xfa/fxfa/parser/cxfa_document.h +++ b/xfa/fxfa/parser/cxfa_document.h @@ -50,7 +50,6 @@ class CScript_LayoutPseudoModel; class CScript_LogPseudoModel; class CScript_SignaturePseudoModel; class CXFA_ContainerLayoutItem; -class CXFA_DocumentParser; class CXFA_FFNotify; class CXFA_LayoutItem; class CXFA_LayoutProcessor; @@ -59,16 +58,13 @@ class CXFA_Object; class CXFA_Document : public CXFA_NodeOwner { public: - explicit CXFA_Document(CXFA_DocumentParser* pParser); + explicit CXFA_Document(CXFA_FFNotify* notify); ~CXFA_Document() override; - virtual CXFA_FFNotify* GetNotify() const; - CFXJSE_Engine* InitScriptContext(CFXJS_Engine* fxjs_engine); CXFA_Node* GetRoot() const { return m_pRootNode; } - CFX_XMLDoc* GetXMLDoc() const; - + CXFA_FFNotify* GetNotify() const { return notify_.Get(); } CXFA_LocaleMgr* GetLocalMgr(); CXFA_Object* GetXFAObject(XFA_HashCode wsNodeNameHash); CXFA_Node* GetNodeByID(CXFA_Node* pRoot, const WideStringView& wsID); @@ -105,7 +101,7 @@ class CXFA_Document : public CXFA_NodeOwner { std::vector<CXFA_Node*> m_pPendingPageSet; private: - CXFA_DocumentParser* m_pParser; + UnownedPtr<CXFA_FFNotify> notify_; CXFA_Node* m_pRootNode; std::unique_ptr<CFXJSE_Engine> m_pScriptContext; std::unique_ptr<CXFA_LayoutProcessor> m_pLayoutProcessor; diff --git a/xfa/fxfa/parser/cxfa_document_parser.cpp b/xfa/fxfa/parser/cxfa_document_parser.cpp index 6446ea31ce..652694e214 100644 --- a/xfa/fxfa/parser/cxfa_document_parser.cpp +++ b/xfa/fxfa/parser/cxfa_document_parser.cpp @@ -25,7 +25,7 @@ int32_t CXFA_DocumentParser::StartParse( int32_t nRetStatus = m_nodeParser.StartParse(pStream, ePacketID); if (nRetStatus == XFA_PARSESTATUS_Ready) { - m_pDocument = pdfium::MakeUnique<CXFA_Document>(this); + m_pDocument = pdfium::MakeUnique<CXFA_Document>(GetNotify()); m_nodeParser.SetFactory(m_pDocument.get()); } return nRetStatus; @@ -40,10 +40,6 @@ int32_t CXFA_DocumentParser::DoParse() { return nRetStatus; } -CFX_XMLDoc* CXFA_DocumentParser::GetXMLDoc() const { - return m_nodeParser.GetXMLDoc(); -} - CXFA_FFNotify* CXFA_DocumentParser::GetNotify() const { return m_pNotify.Get(); } diff --git a/xfa/fxfa/parser/cxfa_document_parser.h b/xfa/fxfa/parser/cxfa_document_parser.h index 35d71603cb..c245843c0f 100644 --- a/xfa/fxfa/parser/cxfa_document_parser.h +++ b/xfa/fxfa/parser/cxfa_document_parser.h @@ -26,7 +26,6 @@ class CXFA_DocumentParser { XFA_PacketType ePacketID); int32_t DoParse(); - CFX_XMLDoc* GetXMLDoc() const; CXFA_FFNotify* GetNotify() const; CXFA_Document* GetDocument() const; diff --git a/xfa/fxfa/parser/cxfa_node_unittest.cpp b/xfa/fxfa/parser/cxfa_node_unittest.cpp index 7c35e5d989..81e21890df 100644 --- a/xfa/fxfa/parser/cxfa_node_unittest.cpp +++ b/xfa/fxfa/parser/cxfa_node_unittest.cpp @@ -7,19 +7,9 @@ #include "testing/test_support.h" #include "third_party/base/ptr_util.h" #include "xfa/fxfa/parser/cxfa_document.h" -#include "xfa/fxfa/parser/cxfa_document_parser.h" namespace { -class CXFA_DocumentMock : public CXFA_Document { - public: - explicit CXFA_DocumentMock(CXFA_DocumentParser* parser) - : CXFA_Document(parser) {} - ~CXFA_DocumentMock() override = default; - - CXFA_FFNotify* GetNotify() const override { return nullptr; } -}; - class TestNode : public CXFA_Node { public: explicit TestNode(CXFA_Document* doc) @@ -40,23 +30,20 @@ class TestNode : public CXFA_Node { class CXFANodeTest : public testing::Test { public: void SetUp() override { - doc_parser_ = pdfium::MakeUnique<CXFA_DocumentParser>(nullptr); - doc_ = pdfium::MakeUnique<CXFA_DocumentMock>(doc_parser_.get()); + doc_ = pdfium::MakeUnique<CXFA_Document>(nullptr); node_ = pdfium::MakeUnique<TestNode>(doc_.get()); } void TearDown() override { node_ = nullptr; doc_ = nullptr; - doc_parser_ = nullptr; } CXFA_Document* GetDoc() const { return doc_.get(); } CXFA_Node* GetNode() const { return node_.get(); } private: - std::unique_ptr<CXFA_DocumentParser> doc_parser_; - std::unique_ptr<CXFA_DocumentMock> doc_; + std::unique_ptr<CXFA_Document> doc_; std::unique_ptr<TestNode> node_; }; diff --git a/xfa/fxfa/parser/cxfa_simple_parser.cpp b/xfa/fxfa/parser/cxfa_simple_parser.cpp index 0bce147223..f21506d557 100644 --- a/xfa/fxfa/parser/cxfa_simple_parser.cpp +++ b/xfa/fxfa/parser/cxfa_simple_parser.cpp @@ -468,10 +468,6 @@ CXFA_Node* CXFA_SimpleParser::GetRootNode() const { return m_pRootNode; } -CFX_XMLDoc* CXFA_SimpleParser::GetXMLDoc() const { - return m_pXMLDoc.get(); -} - CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket(CFX_XMLNode* pXMLDocumentNode, XFA_PacketType ePacketID) { switch (ePacketID) { diff --git a/xfa/fxfa/parser/cxfa_simple_parser.h b/xfa/fxfa/parser/cxfa_simple_parser.h index 7a20de384a..c1015469c9 100644 --- a/xfa/fxfa/parser/cxfa_simple_parser.h +++ b/xfa/fxfa/parser/cxfa_simple_parser.h @@ -32,7 +32,6 @@ class CXFA_SimpleParser { CFX_XMLNode* ParseXMLData(const ByteString& wsXML); void ConstructXFANode(CXFA_Node* pXFANode, CFX_XMLNode* pXMLNode); CXFA_Node* GetRootNode() const; - CFX_XMLDoc* GetXMLDoc() const; void CloseParser(); // Called later for the ctor with no parameters. |