diff options
Diffstat (limited to 'xfa/fxfa/parser')
-rw-r--r-- | xfa/fxfa/parser/cxfa_dataexporter.cpp | 22 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_dataexporter.h | 2 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_node.cpp | 12 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_simple_parser.cpp | 20 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_simple_parser.h | 2 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_widetextread.cpp | 19 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_widetextread.h | 9 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_xml_parser.cpp | 3 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_xml_parser.h | 5 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_utils.h | 9 |
10 files changed, 45 insertions, 58 deletions
diff --git a/xfa/fxfa/parser/cxfa_dataexporter.cpp b/xfa/fxfa/parser/cxfa_dataexporter.cpp index 9760261baf..a9965f52a5 100644 --- a/xfa/fxfa/parser/cxfa_dataexporter.cpp +++ b/xfa/fxfa/parser/cxfa_dataexporter.cpp @@ -201,7 +201,7 @@ void RegenerateFormFile_Changed(CXFA_Node* pNode, IFX_MemoryStream::Create(true); // Note: ambiguous without cast below. - IFGAS_Stream* pTempStream = IFGAS_Stream::CreateStream( + CFX_RetainPtr<IFGAS_Stream> pTempStream = IFGAS_Stream::CreateStream( CFX_RetainPtr<IFX_SeekableWriteStream>(pMemStream), FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append); @@ -210,7 +210,6 @@ void RegenerateFormFile_Changed(CXFA_Node* pNode, pRichTextXML->SaveXMLNode(pTempStream); wsChildren += CFX_WideString::FromUTF8( CFX_ByteStringC(pMemStream->GetBuffer(), pMemStream->GetSize())); - pTempStream->Release(); } else if (pRawValueNode->GetElementType() == XFA_Element::Sharpxml && wsContentType == FX_WSTRC(L"text/xml")) { CFX_WideString wsRawValue; @@ -320,7 +319,7 @@ void RegenerateFormFile_Changed(CXFA_Node* pNode, } void RegenerateFormFile_Container(CXFA_Node* pNode, - IFGAS_Stream* pStream, + const CFX_RetainPtr<IFGAS_Stream>& pStream, bool bSaveXML = false) { XFA_Element eType = pNode->GetElementType(); if (eType == XFA_Element::Field || eType == XFA_Element::Draw || @@ -373,10 +372,11 @@ void RegenerateFormFile_Container(CXFA_Node* pNode, } // namespace -void XFA_DataExporter_RegenerateFormFile(CXFA_Node* pNode, - IFGAS_Stream* pStream, - const FX_CHAR* pChecksum, - bool bSaveXML) { +void XFA_DataExporter_RegenerateFormFile( + CXFA_Node* pNode, + const CFX_RetainPtr<IFGAS_Stream>& pStream, + const FX_CHAR* pChecksum, + bool bSaveXML) { if (pNode->IsModelNode()) { static const FX_WCHAR s_pwsTagName[] = L"<form"; static const FX_WCHAR s_pwsClose[] = L"</form\n>"; @@ -461,19 +461,17 @@ bool CXFA_DataExporter::Export( if (!pWrite) return false; - IFGAS_Stream* pStream = IFGAS_Stream::CreateStream( + CFX_RetainPtr<IFGAS_Stream> pStream = IFGAS_Stream::CreateStream( pWrite, FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append); if (!pStream) return false; pStream->SetCodePage(FX_CODEPAGE_UTF8); - bool bRet = Export(pStream, pNode, dwFlag, pChecksum); - pStream->Release(); - return bRet; + return Export(pStream, pNode, dwFlag, pChecksum); } -bool CXFA_DataExporter::Export(IFGAS_Stream* pStream, +bool CXFA_DataExporter::Export(const CFX_RetainPtr<IFGAS_Stream>& pStream, CXFA_Node* pNode, uint32_t dwFlag, const FX_CHAR* pChecksum) { diff --git a/xfa/fxfa/parser/cxfa_dataexporter.h b/xfa/fxfa/parser/cxfa_dataexporter.h index f3c784a86a..0e5de00796 100644 --- a/xfa/fxfa/parser/cxfa_dataexporter.h +++ b/xfa/fxfa/parser/cxfa_dataexporter.h @@ -26,7 +26,7 @@ class CXFA_DataExporter { const FX_CHAR* pChecksum); protected: - bool Export(IFGAS_Stream* pStream, + bool Export(const CFX_RetainPtr<IFGAS_Stream>& pStream, CXFA_Node* pNode, uint32_t dwFlag, const FX_CHAR* pChecksum); diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 5dd6c52717..f3f79cbbec 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -1445,11 +1445,9 @@ void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) { IFX_MemoryStream::Create(true); // Note: ambiguious below without static_cast. - std::unique_ptr<IFGAS_Stream, ReleaseDeleter<IFGAS_Stream>> pStream( - IFGAS_Stream::CreateStream( - CFX_RetainPtr<IFX_SeekableWriteStream>(pMemoryStream), - FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | - FX_STREAMACCESS_Append)); + CFX_RetainPtr<IFGAS_Stream> pStream = IFGAS_Stream::CreateStream( + CFX_RetainPtr<IFX_SeekableWriteStream>(pMemoryStream), + FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append); if (!pStream) { pArguments->GetReturnValue()->SetString(bsXMLHeader); @@ -1458,9 +1456,9 @@ void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) { pStream->SetCodePage(FX_CODEPAGE_UTF8); pStream->WriteData(bsXMLHeader.raw_str(), bsXMLHeader.GetLength()); if (GetPacketID() == XFA_XDPPACKET_Form) - XFA_DataExporter_RegenerateFormFile(this, pStream.get(), nullptr, true); + XFA_DataExporter_RegenerateFormFile(this, pStream, nullptr, true); else - pElement->SaveXMLNode(pStream.get()); + pElement->SaveXMLNode(pStream); // TODO(weili): Check whether we need to save pretty print XML, pdfium:501. // For now, just put it here to avoid unused variable warning. (void)bPrettyMode; diff --git a/xfa/fxfa/parser/cxfa_simple_parser.cpp b/xfa/fxfa/parser/cxfa_simple_parser.cpp index 2329e86874..9eca652db7 100644 --- a/xfa/fxfa/parser/cxfa_simple_parser.cpp +++ b/xfa/fxfa/parser/cxfa_simple_parser.cpp @@ -7,6 +7,7 @@ #include "xfa/fxfa/parser/cxfa_simple_parser.h" #include "core/fxcrt/fx_ext.h" +#include "third_party/base/ptr_util.h" #include "xfa/fgas/crt/fgas_codepage.h" #include "xfa/fxfa/fxfa.h" #include "xfa/fxfa/parser/cxfa_document.h" @@ -282,8 +283,8 @@ int32_t CXFA_SimpleParser::StartParse( XFA_XDPPACKET ePacketID) { CloseParser(); m_pFileRead = pStream; - m_pStream.reset(IFGAS_Stream::CreateStream( - pStream, FX_STREAMACCESS_Read | FX_STREAMACCESS_Text)); + m_pStream = IFGAS_Stream::CreateStream( + pStream, FX_STREAMACCESS_Read | FX_STREAMACCESS_Text); if (!m_pStream) return XFA_PARSESTATUS_StreamErr; @@ -293,7 +294,7 @@ int32_t CXFA_SimpleParser::StartParse( m_pStream->SetCodePage(FX_CODEPAGE_UTF8); } m_pXMLDoc.reset(new CFDE_XMLDoc); - m_pXMLParser = new CXFA_XMLParser(m_pXMLDoc->GetRoot(), m_pStream.get()); + m_pXMLParser = new CXFA_XMLParser(m_pXMLDoc->GetRoot(), m_pStream); if (!m_pXMLDoc->LoadXML(m_pXMLParser)) return XFA_PARSESTATUS_StatusErr; @@ -313,10 +314,10 @@ int32_t CXFA_SimpleParser::DoParse(IFX_Pause* pPause) { m_pRootNode = ParseAsXDPPacket(GetDocumentNode(m_pXMLDoc.get()), m_ePacketID); m_pXMLDoc->CloseXML(); - m_pStream.reset(); - + m_pStream.Reset(); if (!m_pRootNode) return XFA_PARSESTATUS_StatusErr; + return XFA_PARSESTATUS_Done; } @@ -326,10 +327,9 @@ int32_t CXFA_SimpleParser::ParseXMLData(const CFX_WideString& wsXML, CloseParser(); pXMLNode = nullptr; - std::unique_ptr<IFGAS_Stream> pStream(new CXFA_WideTextRead(wsXML)); - m_pXMLDoc.reset(new CFDE_XMLDoc); - CXFA_XMLParser* pParser = - new CXFA_XMLParser(m_pXMLDoc->GetRoot(), pStream.get()); + auto pStream = pdfium::MakeRetain<CXFA_WideTextRead>(wsXML); + m_pXMLDoc = pdfium::MakeUnique<CFDE_XMLDoc>(); + CXFA_XMLParser* pParser = new CXFA_XMLParser(m_pXMLDoc->GetRoot(), pStream); pParser->m_dwCheckStatus = 0x03; if (!m_pXMLDoc->LoadXML(pParser)) return XFA_PARSESTATUS_StatusErr; @@ -1306,5 +1306,5 @@ void CXFA_SimpleParser::ParseInstruction(CXFA_Node* pXFANode, void CXFA_SimpleParser::CloseParser() { m_pXMLDoc.reset(); - m_pStream.reset(); + m_pStream.Reset(); } diff --git a/xfa/fxfa/parser/cxfa_simple_parser.h b/xfa/fxfa/parser/cxfa_simple_parser.h index 559df7124b..5f61ad7d28 100644 --- a/xfa/fxfa/parser/cxfa_simple_parser.h +++ b/xfa/fxfa/parser/cxfa_simple_parser.h @@ -78,7 +78,7 @@ class CXFA_SimpleParser { CXFA_XMLParser* m_pXMLParser; std::unique_ptr<CFDE_XMLDoc> m_pXMLDoc; - std::unique_ptr<IFGAS_Stream, ReleaseDeleter<IFGAS_Stream>> m_pStream; + CFX_RetainPtr<IFGAS_Stream> m_pStream; CFX_RetainPtr<IFX_SeekableReadStream> m_pFileRead; CXFA_Document* m_pFactory; CXFA_Node* m_pRootNode; diff --git a/xfa/fxfa/parser/cxfa_widetextread.cpp b/xfa/fxfa/parser/cxfa_widetextread.cpp index cf03a09e7c..54442df7c0 100644 --- a/xfa/fxfa/parser/cxfa_widetextread.cpp +++ b/xfa/fxfa/parser/cxfa_widetextread.cpp @@ -12,17 +12,7 @@ #include "xfa/fgas/crt/fgas_codepage.h" CXFA_WideTextRead::CXFA_WideTextRead(const CFX_WideString& wsBuffer) - : m_wsBuffer(wsBuffer), m_iPosition(0), m_iRefCount(1) {} - -void CXFA_WideTextRead::Release() { - if (--m_iRefCount < 1) - delete this; -} - -IFGAS_Stream* CXFA_WideTextRead::Retain() { - m_iRefCount++; - return this; -} + : m_wsBuffer(wsBuffer), m_iPosition(0) {} uint32_t CXFA_WideTextRead::GetAccessModes() const { return FX_STREAMACCESS_Read | FX_STREAMACCESS_Text; @@ -98,9 +88,10 @@ uint16_t CXFA_WideTextRead::SetCodePage(uint16_t wCodePage) { return GetCodePage(); } -IFGAS_Stream* CXFA_WideTextRead::CreateSharedStream(uint32_t dwAccess, - int32_t iOffset, - int32_t iLength) { +CFX_RetainPtr<IFGAS_Stream> CXFA_WideTextRead::CreateSharedStream( + uint32_t dwAccess, + int32_t iOffset, + int32_t iLength) { return nullptr; } diff --git a/xfa/fxfa/parser/cxfa_widetextread.h b/xfa/fxfa/parser/cxfa_widetextread.h index bea3ab8fba..d3d3b3792a 100644 --- a/xfa/fxfa/parser/cxfa_widetextread.h +++ b/xfa/fxfa/parser/cxfa_widetextread.h @@ -14,8 +14,6 @@ class CXFA_WideTextRead : public IFGAS_Stream { explicit CXFA_WideTextRead(const CFX_WideString& wsBuffer); // IFGAS_Stream - void Release() override; - IFGAS_Stream* Retain() override; uint32_t GetAccessModes() const override; int32_t GetLength() const override; int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; @@ -30,16 +28,15 @@ class CXFA_WideTextRead : public IFGAS_Stream { int32_t GetBOM(uint8_t bom[4]) const override; uint16_t GetCodePage() const override; uint16_t SetCodePage(uint16_t wCodePage) override; - IFGAS_Stream* CreateSharedStream(uint32_t dwAccess, - int32_t iOffset, - int32_t iLength) override; + CFX_RetainPtr<IFGAS_Stream> CreateSharedStream(uint32_t dwAccess, + int32_t iOffset, + int32_t iLength) override; CFX_WideString GetSrcText() const; protected: CFX_WideString m_wsBuffer; int32_t m_iPosition; - int32_t m_iRefCount; }; #endif // XFA_FXFA_PARSER_CXFA_WIDETEXTREAD_H_ diff --git a/xfa/fxfa/parser/cxfa_xml_parser.cpp b/xfa/fxfa/parser/cxfa_xml_parser.cpp index ac378f0b95..6d2ef350d9 100644 --- a/xfa/fxfa/parser/cxfa_xml_parser.cpp +++ b/xfa/fxfa/parser/cxfa_xml_parser.cpp @@ -6,7 +6,8 @@ #include "xfa/fxfa/parser/cxfa_xml_parser.h" -CXFA_XMLParser::CXFA_XMLParser(CFDE_XMLNode* pRoot, IFGAS_Stream* pStream) +CXFA_XMLParser::CXFA_XMLParser(CFDE_XMLNode* pRoot, + const CFX_RetainPtr<IFGAS_Stream>& pStream) : m_nElementStart(0), m_dwCheckStatus(0), m_dwCurrentCheckStatus(0), diff --git a/xfa/fxfa/parser/cxfa_xml_parser.h b/xfa/fxfa/parser/cxfa_xml_parser.h index cff279453d..4c64ee2f8c 100644 --- a/xfa/fxfa/parser/cxfa_xml_parser.h +++ b/xfa/fxfa/parser/cxfa_xml_parser.h @@ -16,7 +16,8 @@ class IFX_Pause; class CXFA_XMLParser : public CFDE_XMLParser { public: - CXFA_XMLParser(CFDE_XMLNode* pRoot, IFGAS_Stream* pStream); + CXFA_XMLParser(CFDE_XMLNode* pRoot, + const CFX_RetainPtr<IFGAS_Stream>& pStream); ~CXFA_XMLParser() override; // CFDE_XMLParser @@ -31,7 +32,7 @@ class CXFA_XMLParser : public CFDE_XMLParser { protected: CFDE_XMLNode* m_pRoot; - IFGAS_Stream* m_pStream; + CFX_RetainPtr<IFGAS_Stream> m_pStream; std::unique_ptr<CFDE_XMLSyntaxParser, ReleaseDeleter<CFDE_XMLSyntaxParser>> m_pParser; CFDE_XMLNode* m_pParent; diff --git a/xfa/fxfa/parser/xfa_utils.h b/xfa/fxfa/parser/xfa_utils.h index 961c0a4189..d09afda0f9 100644 --- a/xfa/fxfa/parser/xfa_utils.h +++ b/xfa/fxfa/parser/xfa_utils.h @@ -172,10 +172,11 @@ void XFA_GetPlainTextFromRichText(CFDE_XMLNode* pXMLNode, bool XFA_FieldIsMultiListBox(CXFA_Node* pFieldNode); void XFA_DataExporter_DealWithDataGroupNode(CXFA_Node* pDataNode); -void XFA_DataExporter_RegenerateFormFile(CXFA_Node* pNode, - IFGAS_Stream* pStream, - const FX_CHAR* pChecksum = nullptr, - bool bSaveXML = false); +void XFA_DataExporter_RegenerateFormFile( + CXFA_Node* pNode, + const CFX_RetainPtr<IFGAS_Stream>& pStream, + const FX_CHAR* pChecksum = nullptr, + bool bSaveXML = false); const XFA_NOTSUREATTRIBUTE* XFA_GetNotsureAttribute( XFA_Element eElement, |