diff options
author | tsepez <tsepez@chromium.org> | 2016-12-07 09:21:17 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-12-07 09:21:18 -0800 |
commit | 833619b4441915c7c55085d44b3221eaef0d9800 (patch) | |
tree | 68bf76e83078223ba03f490c2c13f484e40154d4 /xfa/fxfa/app/xfa_ffdoc.cpp | |
parent | 8f875507a986d10335e40a5f7c1679aff9770d0a (diff) | |
download | pdfium-833619b4441915c7c55085d44b3221eaef0d9800.tar.xz |
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
Diffstat (limited to 'xfa/fxfa/app/xfa_ffdoc.cpp')
-rw-r--r-- | xfa/fxfa/app/xfa_ffdoc.cpp | 42 |
1 files changed, 15 insertions, 27 deletions
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<IFX_SeekableReadStream>& 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<IFX_SeekableReadStream> 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<IFX_SeekableWriteStream>& pFile, + CXFA_ChecksumContext* pCSContext) { CXFA_Document* doc = m_pDocumentParser->GetDocument(); - std::unique_ptr<CXFA_DataExporter> 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<CXFA_DataImporter> importer( - new CXFA_DataImporter(m_pDocumentParser->GetDocument())); +bool CXFA_FFDoc::ImportData( + const CFX_RetainPtr<IFX_SeekableReadStream>& pStream, + bool bXDP) { + auto importer = + pdfium::MakeUnique<CXFA_DataImporter>(m_pDocumentParser->GetDocument()); return importer->ImportData(pStream); } |