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/app/xfa_ffdoc.cpp | 42 +++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) (limited to 'xfa/fxfa/app/xfa_ffdoc.cpp') diff --git a/xfa/fxfa/app/xfa_ffdoc.cpp b/xfa/fxfa/app/xfa_ffdoc.cpp index e719a41c63..917c853991 100644 --- a/xfa/fxfa/app/xfa_ffdoc.cpp +++ b/xfa/fxfa/app/xfa_ffdoc.cpp @@ -152,12 +152,10 @@ int32_t Base64DecodeW(const FX_WCHAR* pSrc, int32_t iSrcLen, uint8_t* pDst) { CXFA_FFDoc::CXFA_FFDoc(CXFA_FFApp* pApp, IXFA_DocEnvironment* pDocEnvironment) : m_pDocEnvironment(pDocEnvironment), m_pDocumentParser(nullptr), - m_pStream(nullptr), m_pApp(pApp), m_pNotify(nullptr), m_pPDFDoc(nullptr), - m_dwDocType(XFA_DOCTYPE_Static), - m_bOwnStream(true) {} + m_dwDocType(XFA_DOCTYPE_Static) {} CXFA_FFDoc::~CXFA_FFDoc() { CloseDoc(); @@ -292,8 +290,7 @@ CXFA_FFDocView* CXFA_FFDoc::GetDocView() { return it != m_TypeToDocViewMap.end() ? it->second.get() : nullptr; } -bool CXFA_FFDoc::OpenDoc(IFX_SeekableReadStream* pStream, bool bTakeOverFile) { - m_bOwnStream = bTakeOverFile; +bool CXFA_FFDoc::OpenDoc(const CFX_RetainPtr& pStream) { m_pStream = pStream; return true; } @@ -326,14 +323,8 @@ bool CXFA_FFDoc::OpenDoc(CPDF_Document* pPDFDoc) { if (xfaStreams.empty()) return false; - IFX_SeekableReadStream* pFileRead = MakeSeekableReadStream(xfaStreams); m_pPDFDoc = pPDFDoc; - if (m_pStream) { - m_pStream->Release(); - m_pStream = nullptr; - } - m_pStream = pFileRead; - m_bOwnStream = true; + m_pStream = MakeSeekableReadStream(xfaStreams); return true; } @@ -351,11 +342,6 @@ bool CXFA_FFDoc::CloseDoc() { m_pNotify.reset(nullptr); m_pApp->GetXFAFontMgr()->ReleaseDocFonts(this); - if (m_dwDocType != XFA_DOCTYPE_XDP && m_pStream && m_bOwnStream) { - m_pStream->Release(); - m_pStream = nullptr; - } - for (const auto& pair : m_HashToDibDpiMap) delete pair.second.pDibSource; @@ -417,21 +403,21 @@ CFX_DIBitmap* CXFA_FFDoc::GetPDFNamedImage(const CFX_WideStringC& wsName, CPDF_StreamAcc streamAcc; streamAcc.LoadAllData(pStream); - IFX_SeekableReadStream* pImageFileRead = IFX_MemoryStream::Create( - (uint8_t*)streamAcc.GetData(), streamAcc.GetSize()); + CFX_RetainPtr pImageFileRead = + IFX_MemoryStream::Create((uint8_t*)streamAcc.GetData(), + streamAcc.GetSize()); CFX_DIBitmap* pDibSource = XFA_LoadImageFromBuffer( pImageFileRead, FXCODEC_IMAGE_UNKNOWN, iImageXDpi, iImageYDpi); m_HashToDibDpiMap[dwHash] = {pDibSource, iImageXDpi, iImageYDpi}; - pImageFileRead->Release(); return pDibSource; } -bool CXFA_FFDoc::SavePackage(XFA_HashCode code, - IFX_SeekableWriteStream* pFile, - CXFA_ChecksumContext* pCSContext) { +bool CXFA_FFDoc::SavePackage( + XFA_HashCode code, + const CFX_RetainPtr& pFile, + CXFA_ChecksumContext* pCSContext) { CXFA_Document* doc = m_pDocumentParser->GetDocument(); - std::unique_ptr pExport(new CXFA_DataExporter(doc)); CXFA_Node* pNode = code == XFA_HASHCODE_Xfa ? doc->GetRoot() : ToNode(doc->GetXFAObject(code)); @@ -446,8 +432,10 @@ bool CXFA_FFDoc::SavePackage(XFA_HashCode code, pFile, pNode, 0, bsChecksum.GetLength() ? bsChecksum.c_str() : nullptr); } -bool CXFA_FFDoc::ImportData(IFX_SeekableReadStream* pStream, bool bXDP) { - std::unique_ptr importer( - new CXFA_DataImporter(m_pDocumentParser->GetDocument())); +bool CXFA_FFDoc::ImportData( + const CFX_RetainPtr& pStream, + bool bXDP) { + auto importer = + pdfium::MakeUnique(m_pDocumentParser->GetDocument()); return importer->ImportData(pStream); } -- cgit v1.2.3