diff options
Diffstat (limited to 'xfa/fxfa')
-rw-r--r-- | xfa/fxfa/app/xfa_checksum.cpp | 8 | ||||
-rw-r--r-- | xfa/fxfa/app/xfa_ffapp.cpp | 20 | ||||
-rw-r--r-- | xfa/fxfa/app/xfa_ffapp_unittest.cpp | 20 | ||||
-rw-r--r-- | xfa/fxfa/app/xfa_ffdoc.cpp | 42 | ||||
-rw-r--r-- | xfa/fxfa/app/xfa_ffwidget.cpp | 21 | ||||
-rw-r--r-- | xfa/fxfa/fm2js/xfa_fm2jscontext.cpp | 3 | ||||
-rw-r--r-- | xfa/fxfa/fxfa.h | 6 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_dataexporter.cpp | 31 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_dataexporter.h | 5 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_dataimporter.cpp | 8 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_dataimporter.h | 3 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_document_parser.cpp | 5 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_document_parser.h | 3 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_node.cpp | 9 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_simple_parser.cpp | 5 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_simple_parser.h | 5 | ||||
-rw-r--r-- | xfa/fxfa/xfa_checksum.h | 2 | ||||
-rw-r--r-- | xfa/fxfa/xfa_ffapp.h | 6 | ||||
-rw-r--r-- | xfa/fxfa/xfa_ffdoc.h | 10 | ||||
-rw-r--r-- | xfa/fxfa/xfa_ffwidget.h | 12 |
20 files changed, 115 insertions, 109 deletions
diff --git a/xfa/fxfa/app/xfa_checksum.cpp b/xfa/fxfa/app/xfa_checksum.cpp index 01035f8ea4..61cbe97fb3 100644 --- a/xfa/fxfa/app/xfa_checksum.cpp +++ b/xfa/fxfa/app/xfa_checksum.cpp @@ -225,11 +225,13 @@ void CXFA_ChecksumContext::StartChecksum() { m_pSAXReader = new CFX_SAXReader; } -bool CXFA_ChecksumContext::UpdateChecksum(IFX_SeekableReadStream* pSrcFile, - FX_FILESIZE offset, - size_t size) { +bool CXFA_ChecksumContext::UpdateChecksum( + const CFX_RetainPtr<IFX_SeekableReadStream>& pSrcFile, + FX_FILESIZE offset, + size_t size) { if (!m_pSAXReader || !pSrcFile) return false; + if (size < 1) size = pSrcFile->GetSize(); diff --git a/xfa/fxfa/app/xfa_ffapp.cpp b/xfa/fxfa/app/xfa_ffapp.cpp index 9c0411b731..a0674b6522 100644 --- a/xfa/fxfa/app/xfa_ffapp.cpp +++ b/xfa/fxfa/app/xfa_ffapp.cpp @@ -31,7 +31,6 @@ class CXFA_FileRead : public IFX_SeekableReadStream { // IFX_SeekableReadStream FX_FILESIZE GetSize() override; bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; - void Release() override; private: CFX_ObjectArray<CPDF_StreamAcc> m_Data; @@ -84,15 +83,11 @@ bool CXFA_FileRead::ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) { return false; } -void CXFA_FileRead::Release() { - delete this; -} - } // namespace -IFX_SeekableReadStream* MakeSeekableReadStream( +CFX_RetainPtr<IFX_SeekableReadStream> MakeSeekableReadStream( const std::vector<CPDF_Stream*>& streams) { - return new CXFA_FileRead(streams); + return CFX_RetainPtr<IFX_SeekableReadStream>(new CXFA_FileRead(streams)); } CXFA_FFApp::CXFA_FFApp(IXFA_AppProvider* pProvider) @@ -108,12 +103,11 @@ CXFA_FFDocHandler* CXFA_FFApp::GetDocHandler() { return m_pDocHandler.get(); } -CXFA_FFDoc* CXFA_FFApp::CreateDoc(IXFA_DocEnvironment* pDocEnvironment, - IFX_SeekableReadStream* pStream, - bool bTakeOverFile) { - std::unique_ptr<CXFA_FFDoc> pDoc(new CXFA_FFDoc(this, pDocEnvironment)); - bool bSuccess = pDoc->OpenDoc(pStream, bTakeOverFile); - return bSuccess ? pDoc.release() : nullptr; +CXFA_FFDoc* CXFA_FFApp::CreateDoc( + IXFA_DocEnvironment* pDocEnvironment, + const CFX_RetainPtr<IFX_SeekableReadStream>& pStream) { + auto pDoc = pdfium::MakeUnique<CXFA_FFDoc>(this, pDocEnvironment); + return pDoc->OpenDoc(pStream) ? pDoc.release() : nullptr; } CXFA_FFDoc* CXFA_FFApp::CreateDoc(IXFA_DocEnvironment* pDocEnvironment, diff --git a/xfa/fxfa/app/xfa_ffapp_unittest.cpp b/xfa/fxfa/app/xfa_ffapp_unittest.cpp index 7a65dcc45b..b0879012b4 100644 --- a/xfa/fxfa/app/xfa_ffapp_unittest.cpp +++ b/xfa/fxfa/app/xfa_ffapp_unittest.cpp @@ -13,12 +13,10 @@ #include "testing/gtest/include/gtest/gtest.h" #include "third_party/base/ptr_util.h" -using UniqueFileRead = std::unique_ptr<IFX_SeekableReadStream, - ReleaseDeleter<IFX_SeekableReadStream>>; - TEST(CXFAFileRead, NoStreams) { std::vector<CPDF_Stream*> streams; - UniqueFileRead fileread(MakeSeekableReadStream(streams)); + CFX_RetainPtr<IFX_SeekableReadStream> fileread = + MakeSeekableReadStream(streams); uint8_t output_buffer[16]; memset(output_buffer, 0xbd, sizeof(output_buffer)); @@ -28,9 +26,10 @@ TEST(CXFAFileRead, NoStreams) { TEST(CXFAFileRead, EmptyStreams) { std::vector<CPDF_Stream*> streams; - std::unique_ptr<CPDF_Stream> stream1 = pdfium::MakeUnique<CPDF_Stream>(); + auto stream1 = pdfium::MakeUnique<CPDF_Stream>(); streams.push_back(stream1.get()); - UniqueFileRead fileread(MakeSeekableReadStream(streams)); + CFX_RetainPtr<IFX_SeekableReadStream> fileread = + MakeSeekableReadStream(streams); uint8_t output_buffer[16]; memset(output_buffer, 0xbd, sizeof(output_buffer)); @@ -40,9 +39,9 @@ TEST(CXFAFileRead, EmptyStreams) { TEST(CXFAFileRead, NormalStreams) { std::vector<CPDF_Stream*> streams; - std::unique_ptr<CPDF_Stream> stream1 = pdfium::MakeUnique<CPDF_Stream>(); - std::unique_ptr<CPDF_Stream> stream2 = pdfium::MakeUnique<CPDF_Stream>(); - std::unique_ptr<CPDF_Stream> stream3 = pdfium::MakeUnique<CPDF_Stream>(); + auto stream1 = pdfium::MakeUnique<CPDF_Stream>(); + auto stream2 = pdfium::MakeUnique<CPDF_Stream>(); + auto stream3 = pdfium::MakeUnique<CPDF_Stream>(); // 16 chars total. stream1->InitStream(reinterpret_cast<const uint8_t*>("one t"), 5, @@ -55,7 +54,8 @@ TEST(CXFAFileRead, NormalStreams) { streams.push_back(stream1.get()); streams.push_back(stream2.get()); streams.push_back(stream3.get()); - UniqueFileRead fileread(MakeSeekableReadStream(streams)); + CFX_RetainPtr<IFX_SeekableReadStream> fileread = + MakeSeekableReadStream(streams); uint8_t output_buffer[16]; memset(output_buffer, 0xbd, sizeof(output_buffer)); 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); } diff --git a/xfa/fxfa/app/xfa_ffwidget.cpp b/xfa/fxfa/app/xfa_ffwidget.cpp index dfe418b76b..99333ba1dd 100644 --- a/xfa/fxfa/app/xfa_ffwidget.cpp +++ b/xfa/fxfa/app/xfa_ffwidget.cpp @@ -1054,7 +1054,7 @@ CFX_DIBitmap* XFA_LoadImageData(CXFA_FFDoc* pDoc, FXCODEC_IMAGE_TYPE type = XFA_GetImageType(wsContentType); CFX_ByteString bsContent; uint8_t* pImageBuffer = nullptr; - IFX_SeekableReadStream* pImageFileRead = nullptr; + CFX_RetainPtr<IFX_SeekableReadStream> pImageFileRead; if (wsImage.GetLength() > 0) { XFA_ATTRIBUTEENUM iEncoding = (XFA_ATTRIBUTEENUM)pImage->GetTransferEncoding(); @@ -1092,7 +1092,6 @@ CFX_DIBitmap* XFA_LoadImageData(CXFA_FFDoc* pDoc, CFX_DIBitmap* pBitmap = XFA_LoadImageFromBuffer(pImageFileRead, type, iImageXDpi, iImageYDpi); FX_Free(pImageBuffer); - pImageFileRead->Release(); return pBitmap; } static FXDIB_Format XFA_GetDIBFormat(FXCODEC_IMAGE_TYPE type, @@ -1115,18 +1114,20 @@ static FXDIB_Format XFA_GetDIBFormat(FXCODEC_IMAGE_TYPE type, } return dibFormat; } -CFX_DIBitmap* XFA_LoadImageFromBuffer(IFX_SeekableReadStream* pImageFileRead, - FXCODEC_IMAGE_TYPE type, - int32_t& iImageXDpi, - int32_t& iImageYDpi) { + +CFX_DIBitmap* XFA_LoadImageFromBuffer( + const CFX_RetainPtr<IFX_SeekableReadStream>& pImageFileRead, + FXCODEC_IMAGE_TYPE type, + int32_t& iImageXDpi, + int32_t& iImageYDpi) { CFX_GEModule* pGeModule = CFX_GEModule::Get(); - if (!pGeModule) { + if (!pGeModule) return nullptr; - } + CCodec_ModuleMgr* pCodecMgr = pGeModule->GetCodecModule(); - if (!pCodecMgr) { + if (!pCodecMgr) return nullptr; - } + CFX_DIBAttribute dibAttr; CFX_DIBitmap* pBitmap = nullptr; CCodec_ProgressiveDecoder* pProgressiveDecoder = diff --git a/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp b/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp index 8bcdcdda31..01328f2374 100644 --- a/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp +++ b/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp @@ -4924,7 +4924,7 @@ void CXFA_FM2JSContext::Get(CFXJSE_Value* pThis, std::unique_ptr<CFXJSE_Value> argOne = GetSimpleValue(pThis, args, 0); CFX_ByteString urlString; ValueToUTF8String(argOne.get(), urlString); - IFX_SeekableReadStream* pFile = pAppProvider->DownloadURL( + CFX_RetainPtr<IFX_SeekableReadStream> pFile = pAppProvider->DownloadURL( CFX_WideString::FromUTF8(urlString.AsStringC())); if (!pFile) return; @@ -4933,7 +4933,6 @@ void CXFA_FM2JSContext::Get(CFXJSE_Value* pThis, std::unique_ptr<uint8_t> pData(FX_Alloc(uint8_t, size)); pFile->ReadBlock(pData.get(), size); args.GetReturnValue()->SetString(CFX_ByteStringC(pData.get(), size)); - pFile->Release(); } // static diff --git a/xfa/fxfa/fxfa.h b/xfa/fxfa/fxfa.h index d3ae838315..ec5282cf8a 100644 --- a/xfa/fxfa/fxfa.h +++ b/xfa/fxfa/fxfa.h @@ -9,6 +9,7 @@ #include <vector> +#include "core/fxcrt/cfx_retain_ptr.h" #include "xfa/fxfa/fxfa_basic.h" #include "xfa/fxfa/fxfa_widget.h" @@ -230,7 +231,8 @@ class IXFA_AppProvider { * @param[in] wsURL - http, ftp, such as * "http://www.w3.org/TR/REC-xml-names/". */ - virtual IFX_SeekableReadStream* DownloadURL(const CFX_WideString& wsURL) = 0; + virtual CFX_RetainPtr<IFX_SeekableReadStream> DownloadURL( + const CFX_WideString& wsURL) = 0; /** * POST data to the given url. @@ -320,7 +322,7 @@ class IXFA_DocEnvironment { virtual bool SetGlobalProperty(CXFA_FFDoc* hDoc, const CFX_ByteStringC& szPropName, CFXJSE_Value* pValue) = 0; - virtual IFX_SeekableReadStream* OpenLinkedFile( + virtual CFX_RetainPtr<IFX_SeekableReadStream> OpenLinkedFile( CXFA_FFDoc* hDoc, const CFX_WideString& wsLink) = 0; }; 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<IFX_MemoryStream> 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<IFX_SeekableWriteStream>(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<IFX_SeekableWriteStream>& 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<IFX_SeekableWriteStream>& 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<IFX_SeekableWriteStream>& pWrite); + bool Export(const CFX_RetainPtr<IFX_SeekableWriteStream>& 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 <memory> #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<CXFA_SimpleParser> pDataDocumentParser( - new CXFA_SimpleParser(m_pDocument, false)); +bool CXFA_DataImporter::ImportData( + const CFX_RetainPtr<IFX_SeekableReadStream>& pDataDocument) { + auto pDataDocumentParser = + pdfium::MakeUnique<CXFA_SimpleParser>(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<IFX_SeekableReadStream>& 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<IFX_SeekableReadStream>& 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<IFX_SeekableReadStream>& 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<IFX_MemoryStream, ReleaseDeleter<IFX_MemoryStream>> - pMemoryStream(IFX_MemoryStream::Create(true)); + CFX_RetainPtr<IFX_MemoryStream> pMemoryStream = + IFX_MemoryStream::Create(true); + + // Note: ambiguious below without static_cast. std::unique_ptr<IFGAS_Stream, ReleaseDeleter<IFGAS_Stream>> pStream( IFGAS_Stream::CreateStream( - static_cast<IFX_SeekableWriteStream*>(pMemoryStream.get()), + CFX_RetainPtr<IFX_SeekableWriteStream>(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<IFX_SeekableReadStream>& 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<IFX_SeekableReadStream>& 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<CFDE_XMLDoc> m_pXMLDoc; std::unique_ptr<IFGAS_Stream, ReleaseDeleter<IFGAS_Stream>> m_pStream; - IFX_SeekableReadStream* m_pFileRead; + CFX_RetainPtr<IFX_SeekableReadStream> m_pFileRead; CXFA_Document* m_pFactory; CXFA_Node* m_pRootNode; XFA_XDPPACKET m_ePacketID; diff --git a/xfa/fxfa/xfa_checksum.h b/xfa/fxfa/xfa_checksum.h index aaa587fed0..32862c94c3 100644 --- a/xfa/fxfa/xfa_checksum.h +++ b/xfa/fxfa/xfa_checksum.h @@ -62,7 +62,7 @@ class CXFA_ChecksumContext { void StartChecksum(); void Update(const CFX_ByteStringC& bsText); - bool UpdateChecksum(IFX_SeekableReadStream* pSrcFile, + bool UpdateChecksum(const CFX_RetainPtr<IFX_SeekableReadStream>& pSrcFile, FX_FILESIZE offset = 0, size_t size = 0); void FinishChecksum(); diff --git a/xfa/fxfa/xfa_ffapp.h b/xfa/fxfa/xfa_ffapp.h index 95013ef82f..5883be2279 100644 --- a/xfa/fxfa/xfa_ffapp.h +++ b/xfa/fxfa/xfa_ffapp.h @@ -12,6 +12,7 @@ #include "core/fpdfapi/parser/cpdf_stream.h" #include "core/fpdfapi/parser/cpdf_stream_acc.h" +#include "core/fxcrt/cfx_retain_ptr.h" #include "xfa/fgas/font/cfgas_fontmgr.h" #include "xfa/fwl/core/cfwl_app.h" #include "xfa/fxfa/fxfa.h" @@ -26,7 +27,7 @@ class CFWL_WidgetMgrDelegate; // Layering prevents fxcrt from knowing about CPDF_Streams; this could go // in fpdfsdk, but it is XFA-Only. -IFX_SeekableReadStream* MakeSeekableReadStream( +CFX_RetainPtr<IFX_SeekableReadStream> MakeSeekableReadStream( const std::vector<CPDF_Stream*>& streams); class CXFA_FFApp { @@ -35,8 +36,7 @@ class CXFA_FFApp { ~CXFA_FFApp(); CXFA_FFDoc* CreateDoc(IXFA_DocEnvironment* pDocEnvironment, - IFX_SeekableReadStream* pStream, - bool bTakeOverFile); + const CFX_RetainPtr<IFX_SeekableReadStream>& pStream); CXFA_FFDoc* CreateDoc(IXFA_DocEnvironment* pDocEnvironment, CPDF_Document* pPDFDoc); void SetDefaultFontMgr(std::unique_ptr<CXFA_DefFontMgr> pFontMgr); diff --git a/xfa/fxfa/xfa_ffdoc.h b/xfa/fxfa/xfa_ffdoc.h index a31f6d7e50..44079704e7 100644 --- a/xfa/fxfa/xfa_ffdoc.h +++ b/xfa/fxfa/xfa_ffdoc.h @@ -40,7 +40,7 @@ class CXFA_FFDoc { CXFA_FFDocView* CreateDocView(uint32_t dwView = 0); - bool OpenDoc(IFX_SeekableReadStream* pStream, bool bTakeOverFile); + bool OpenDoc(const CFX_RetainPtr<IFX_SeekableReadStream>& pStream); bool OpenDoc(CPDF_Document* pPDFDoc); bool CloseDoc(); @@ -54,21 +54,21 @@ class CXFA_FFDoc { int32_t& iImageYDpi); bool SavePackage(XFA_HashCode code, - IFX_SeekableWriteStream* pFile, + const CFX_RetainPtr<IFX_SeekableWriteStream>& pFile, CXFA_ChecksumContext* pCSContext); - bool ImportData(IFX_SeekableReadStream* pStream, bool bXDP = true); + bool ImportData(const CFX_RetainPtr<IFX_SeekableReadStream>& pStream, + bool bXDP = true); protected: IXFA_DocEnvironment* const m_pDocEnvironment; std::unique_ptr<CXFA_DocumentParser> m_pDocumentParser; - IFX_SeekableReadStream* m_pStream; + CFX_RetainPtr<IFX_SeekableReadStream> m_pStream; CXFA_FFApp* m_pApp; std::unique_ptr<CXFA_FFNotify> m_pNotify; CPDF_Document* m_pPDFDoc; std::map<uint32_t, FX_IMAGEDIB_AND_DPI> m_HashToDibDpiMap; std::map<uint32_t, std::unique_ptr<CXFA_FFDocView>> m_TypeToDocViewMap; uint32_t m_dwDocType; - bool m_bOwnStream; }; #endif // XFA_FXFA_XFA_FFDOC_H_ diff --git a/xfa/fxfa/xfa_ffwidget.h b/xfa/fxfa/xfa_ffwidget.h index 9e02680a23..031c35ba2b 100644 --- a/xfa/fxfa/xfa_ffwidget.h +++ b/xfa/fxfa/xfa_ffwidget.h @@ -161,15 +161,19 @@ void XFA_DrawImage(CFX_Graphics* pGS, int32_t iImageYDpi, int32_t iHorzAlign = XFA_ATTRIBUTEENUM_Left, int32_t iVertAlign = XFA_ATTRIBUTEENUM_Top); + CFX_DIBitmap* XFA_LoadImageData(CXFA_FFDoc* pDoc, CXFA_Image* pImage, bool& bNameImage, int32_t& iImageXDpi, int32_t& iImageYDpi); -CFX_DIBitmap* XFA_LoadImageFromBuffer(IFX_SeekableReadStream* pImageFileRead, - FXCODEC_IMAGE_TYPE type, - int32_t& iImageXDpi, - int32_t& iImageYDpi); + +CFX_DIBitmap* XFA_LoadImageFromBuffer( + const CFX_RetainPtr<IFX_SeekableReadStream>& pImageFileRead, + FXCODEC_IMAGE_TYPE type, + int32_t& iImageXDpi, + int32_t& iImageYDpi); + FXCODEC_IMAGE_TYPE XFA_GetImageType(const CFX_WideString& wsType); FX_CHAR* XFA_Base64Encode(const uint8_t* buf, int32_t buf_len); void XFA_RectWidthoutMargin(CFX_RectF& rt, |