From 833619b4441915c7c55085d44b3221eaef0d9800 Mon Sep 17 00:00:00 2001 From: tsepez Date: Wed, 7 Dec 2016 09:21:17 -0800 Subject: Refcount all the IFX_ stream classes all the time. We can remove a lot of "bOwnsStream" logic in the process. Always pass these by const reference, in case the called method wants to hang on to the stream (one exception is where we stick a raw pointer into a void* slot in a context from another layer). Review-Url: https://codereview.chromium.org/2451493002 --- xfa/fxfa/parser/cxfa_dataexporter.cpp | 31 ++++++++++++++++++------------- xfa/fxfa/parser/cxfa_dataexporter.h | 5 +++-- xfa/fxfa/parser/cxfa_dataimporter.cpp | 8 +++++--- xfa/fxfa/parser/cxfa_dataimporter.h | 3 ++- xfa/fxfa/parser/cxfa_document_parser.cpp | 5 +++-- xfa/fxfa/parser/cxfa_document_parser.h | 3 ++- xfa/fxfa/parser/cxfa_node.cpp | 9 ++++++--- xfa/fxfa/parser/cxfa_simple_parser.cpp | 5 +++-- xfa/fxfa/parser/cxfa_simple_parser.h | 5 +++-- 9 files changed, 45 insertions(+), 29 deletions(-) (limited to 'xfa/fxfa/parser') diff --git a/xfa/fxfa/parser/cxfa_dataexporter.cpp b/xfa/fxfa/parser/cxfa_dataexporter.cpp index f97e8a34ed..9760261baf 100644 --- a/xfa/fxfa/parser/cxfa_dataexporter.cpp +++ b/xfa/fxfa/parser/cxfa_dataexporter.cpp @@ -197,17 +197,20 @@ void RegenerateFormFile_Changed(CXFA_Node* pNode, if (!pRichTextXML) break; - IFX_MemoryStream* pMemStream = IFX_MemoryStream::Create(true); + CFX_RetainPtr pMemStream = + IFX_MemoryStream::Create(true); + + // Note: ambiguous without cast below. IFGAS_Stream* pTempStream = IFGAS_Stream::CreateStream( - (IFX_SeekableWriteStream*)pMemStream, FX_STREAMACCESS_Text | - FX_STREAMACCESS_Write | - FX_STREAMACCESS_Append); + CFX_RetainPtr(pMemStream), + FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | + FX_STREAMACCESS_Append); + pTempStream->SetCodePage(FX_CODEPAGE_UTF8); pRichTextXML->SaveXMLNode(pTempStream); wsChildren += CFX_WideString::FromUTF8( CFX_ByteStringC(pMemStream->GetBuffer(), pMemStream->GetSize())); pTempStream->Release(); - pMemStream->Release(); } else if (pRawValueNode->GetElementType() == XFA_Element::Sharpxml && wsContentType == FX_WSTRC(L"text/xml")) { CFX_WideString wsRawValue; @@ -444,18 +447,20 @@ CXFA_DataExporter::CXFA_DataExporter(CXFA_Document* pDocument) ASSERT(m_pDocument); } -bool CXFA_DataExporter::Export(IFX_SeekableWriteStream* pWrite) { +bool CXFA_DataExporter::Export( + const CFX_RetainPtr& pWrite) { return Export(pWrite, m_pDocument->GetRoot(), 0, nullptr); } -bool CXFA_DataExporter::Export(IFX_SeekableWriteStream* pWrite, - CXFA_Node* pNode, - uint32_t dwFlag, - const FX_CHAR* pChecksum) { - if (!pWrite) { - ASSERT(false); +bool CXFA_DataExporter::Export( + const CFX_RetainPtr& pWrite, + CXFA_Node* pNode, + uint32_t dwFlag, + const FX_CHAR* pChecksum) { + ASSERT(pWrite); + if (!pWrite) return false; - } + IFGAS_Stream* pStream = IFGAS_Stream::CreateStream( pWrite, FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append); diff --git a/xfa/fxfa/parser/cxfa_dataexporter.h b/xfa/fxfa/parser/cxfa_dataexporter.h index 8496e0d9a6..f3c784a86a 100644 --- a/xfa/fxfa/parser/cxfa_dataexporter.h +++ b/xfa/fxfa/parser/cxfa_dataexporter.h @@ -7,6 +7,7 @@ #ifndef XFA_FXFA_PARSER_CXFA_DATAEXPORTER_H_ #define XFA_FXFA_PARSER_CXFA_DATAEXPORTER_H_ +#include "core/fxcrt/cfx_retain_ptr.h" #include "core/fxcrt/fx_string.h" class CXFA_Document; @@ -18,8 +19,8 @@ class CXFA_DataExporter { public: explicit CXFA_DataExporter(CXFA_Document* pDocument); - bool Export(IFX_SeekableWriteStream* pWrite); - bool Export(IFX_SeekableWriteStream* pWrite, + bool Export(const CFX_RetainPtr& pWrite); + bool Export(const CFX_RetainPtr& pWrite, CXFA_Node* pNode, uint32_t dwFlag, const FX_CHAR* pChecksum); diff --git a/xfa/fxfa/parser/cxfa_dataimporter.cpp b/xfa/fxfa/parser/cxfa_dataimporter.cpp index c0c798dfe6..0199028ecd 100644 --- a/xfa/fxfa/parser/cxfa_dataimporter.cpp +++ b/xfa/fxfa/parser/cxfa_dataimporter.cpp @@ -9,6 +9,7 @@ #include #include "core/fxcrt/fx_stream.h" +#include "third_party/base/ptr_util.h" #include "xfa/fde/xml/fde_xml_imp.h" #include "xfa/fxfa/fxfa.h" #include "xfa/fxfa/fxfa_basic.h" @@ -21,9 +22,10 @@ CXFA_DataImporter::CXFA_DataImporter(CXFA_Document* pDocument) ASSERT(m_pDocument); } -bool CXFA_DataImporter::ImportData(IFX_SeekableReadStream* pDataDocument) { - std::unique_ptr pDataDocumentParser( - new CXFA_SimpleParser(m_pDocument, false)); +bool CXFA_DataImporter::ImportData( + const CFX_RetainPtr& pDataDocument) { + auto pDataDocumentParser = + pdfium::MakeUnique(m_pDocument, false); if (pDataDocumentParser->StartParse(pDataDocument, XFA_XDPPACKET_Datasets) != XFA_PARSESTATUS_Ready) { return false; diff --git a/xfa/fxfa/parser/cxfa_dataimporter.h b/xfa/fxfa/parser/cxfa_dataimporter.h index 86e41a8130..bf04b05846 100644 --- a/xfa/fxfa/parser/cxfa_dataimporter.h +++ b/xfa/fxfa/parser/cxfa_dataimporter.h @@ -7,6 +7,7 @@ #ifndef XFA_FXFA_PARSER_CXFA_DATAIMPORTER_H_ #define XFA_FXFA_PARSER_CXFA_DATAIMPORTER_H_ +#include "core/fxcrt/cfx_retain_ptr.h" #include "core/fxcrt/fx_system.h" class CXFA_Document; @@ -16,7 +17,7 @@ class CXFA_DataImporter { public: explicit CXFA_DataImporter(CXFA_Document* pDocument); - bool ImportData(IFX_SeekableReadStream* pDataDocument); + bool ImportData(const CFX_RetainPtr& pDataDocument); protected: CXFA_Document* const m_pDocument; diff --git a/xfa/fxfa/parser/cxfa_document_parser.cpp b/xfa/fxfa/parser/cxfa_document_parser.cpp index fe3cb933aa..1bf327d667 100644 --- a/xfa/fxfa/parser/cxfa_document_parser.cpp +++ b/xfa/fxfa/parser/cxfa_document_parser.cpp @@ -15,8 +15,9 @@ CXFA_DocumentParser::CXFA_DocumentParser(CXFA_FFNotify* pNotify) CXFA_DocumentParser::~CXFA_DocumentParser() { } -int32_t CXFA_DocumentParser::StartParse(IFX_SeekableReadStream* pStream, - XFA_XDPPACKET ePacketID) { +int32_t CXFA_DocumentParser::StartParse( + const CFX_RetainPtr& pStream, + XFA_XDPPACKET ePacketID) { m_pDocument.reset(); m_nodeParser.CloseParser(); diff --git a/xfa/fxfa/parser/cxfa_document_parser.h b/xfa/fxfa/parser/cxfa_document_parser.h index 29aeca39bc..617bddf55b 100644 --- a/xfa/fxfa/parser/cxfa_document_parser.h +++ b/xfa/fxfa/parser/cxfa_document_parser.h @@ -23,7 +23,8 @@ class CXFA_DocumentParser { explicit CXFA_DocumentParser(CXFA_FFNotify* pNotify); ~CXFA_DocumentParser(); - int32_t StartParse(IFX_SeekableReadStream* pStream, XFA_XDPPACKET ePacketID); + int32_t StartParse(const CFX_RetainPtr& pStream, + XFA_XDPPACKET ePacketID); int32_t DoParse(IFX_Pause* pPause); CFDE_XMLDoc* GetXMLDoc() const; diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 16062f7b6f..5dd6c52717 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -1441,13 +1441,16 @@ void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) { } XFA_DataExporter_DealWithDataGroupNode(this); } - std::unique_ptr> - pMemoryStream(IFX_MemoryStream::Create(true)); + CFX_RetainPtr pMemoryStream = + IFX_MemoryStream::Create(true); + + // Note: ambiguious below without static_cast. std::unique_ptr> pStream( IFGAS_Stream::CreateStream( - static_cast(pMemoryStream.get()), + CFX_RetainPtr(pMemoryStream), FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append)); + if (!pStream) { pArguments->GetReturnValue()->SetString(bsXMLHeader); return; diff --git a/xfa/fxfa/parser/cxfa_simple_parser.cpp b/xfa/fxfa/parser/cxfa_simple_parser.cpp index a9025fa42a..2329e86874 100644 --- a/xfa/fxfa/parser/cxfa_simple_parser.cpp +++ b/xfa/fxfa/parser/cxfa_simple_parser.cpp @@ -277,8 +277,9 @@ void CXFA_SimpleParser::SetFactory(CXFA_Document* pFactory) { m_pFactory = pFactory; } -int32_t CXFA_SimpleParser::StartParse(IFX_SeekableReadStream* pStream, - XFA_XDPPACKET ePacketID) { +int32_t CXFA_SimpleParser::StartParse( + const CFX_RetainPtr& pStream, + XFA_XDPPACKET ePacketID) { CloseParser(); m_pFileRead = pStream; m_pStream.reset(IFGAS_Stream::CreateStream( diff --git a/xfa/fxfa/parser/cxfa_simple_parser.h b/xfa/fxfa/parser/cxfa_simple_parser.h index fa9fdb3014..559df7124b 100644 --- a/xfa/fxfa/parser/cxfa_simple_parser.h +++ b/xfa/fxfa/parser/cxfa_simple_parser.h @@ -24,7 +24,8 @@ class CXFA_SimpleParser { CXFA_SimpleParser(CXFA_Document* pFactory, bool bDocumentParser); ~CXFA_SimpleParser(); - int32_t StartParse(IFX_SeekableReadStream* pStream, XFA_XDPPACKET ePacketID); + int32_t StartParse(const CFX_RetainPtr& pStream, + XFA_XDPPACKET ePacketID); int32_t DoParse(IFX_Pause* pPause); int32_t ParseXMLData(const CFX_WideString& wsXML, CFDE_XMLNode*& pXMLNode, @@ -78,7 +79,7 @@ class CXFA_SimpleParser { CXFA_XMLParser* m_pXMLParser; std::unique_ptr m_pXMLDoc; std::unique_ptr> m_pStream; - IFX_SeekableReadStream* m_pFileRead; + CFX_RetainPtr m_pFileRead; CXFA_Document* m_pFactory; CXFA_Node* m_pRootNode; XFA_XDPPACKET m_ePacketID; -- cgit v1.2.3