diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/fpdfapi/parser/cpdf_parser_unittest.cpp | 14 | ||||
-rw-r--r-- | core/fpdfdoc/cpdf_bookmark.cpp | 5 | ||||
-rw-r--r-- | core/fpdfdoc/cpdf_filespec.cpp | 7 | ||||
-rw-r--r-- | core/fpdfdoc/cpdf_filespec.h | 6 | ||||
-rw-r--r-- | core/fpdfdoc/cpdf_interform.cpp | 10 | ||||
-rw-r--r-- | core/fxcodec/codec/fx_codec.cpp | 15 | ||||
-rw-r--r-- | core/fxcrt/fx_bidi.cpp | 6 | ||||
-rw-r--r-- | core/fxcrt/fx_stream.cpp | 4 | ||||
-rw-r--r-- | core/fxcrt/fxcrt_posix.cpp | 7 | ||||
-rw-r--r-- | core/fxcrt/fxcrt_windows.cpp | 7 | ||||
-rw-r--r-- | core/fxcrt/ifxcrt_fileaccess.h | 2 |
11 files changed, 44 insertions, 39 deletions
diff --git a/core/fpdfapi/parser/cpdf_parser_unittest.cpp b/core/fpdfapi/parser/cpdf_parser_unittest.cpp index bbf707a34d..f988f8248b 100644 --- a/core/fpdfapi/parser/cpdf_parser_unittest.cpp +++ b/core/fpdfapi/parser/cpdf_parser_unittest.cpp @@ -16,12 +16,8 @@ // Provide a way to read test data from a buffer instead of a file. class CFX_TestBufferRead : public IFX_SeekableReadStream { public: - static CFX_RetainPtr<CFX_TestBufferRead> Create( - const unsigned char* buffer_in, - size_t buf_size) { - return CFX_RetainPtr<CFX_TestBufferRead>( - new CFX_TestBufferRead(buffer_in, buf_size)); - } + template <typename T, typename... Args> + friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args); // IFX_SeekableReadStream: bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { @@ -62,11 +58,9 @@ class CPDF_TestParser : public CPDF_Parser { // Setup reading from a buffer and initial states. bool InitTestFromBuffer(const unsigned char* buffer, size_t len) { - CFX_RetainPtr<CFX_TestBufferRead> buffer_reader = - CFX_TestBufferRead::Create(buffer, len); - // For the test file, the header is set at the beginning. - m_pSyntax->InitParser(buffer_reader, 0); + m_pSyntax->InitParser(pdfium::MakeRetain<CFX_TestBufferRead>(buffer, len), + 0); return true; } diff --git a/core/fpdfdoc/cpdf_bookmark.cpp b/core/fpdfdoc/cpdf_bookmark.cpp index ba1e18c46d..8ca5d128f5 100644 --- a/core/fpdfdoc/cpdf_bookmark.cpp +++ b/core/fpdfdoc/cpdf_bookmark.cpp @@ -7,6 +7,7 @@ #include "core/fpdfdoc/cpdf_bookmark.h" #include <memory> +#include <vector> #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_string.h" @@ -44,12 +45,12 @@ CFX_WideString CPDF_Bookmark::GetTitle() const { if (!len) return CFX_WideString(); - std::unique_ptr<wchar_t[]> buf(new wchar_t[len]); + std::vector<wchar_t> buf(len); for (int i = 0; i < len; i++) { wchar_t w = title[i]; buf[i] = w > 0x20 ? w : 0x20; } - return CFX_WideString(buf.get(), len); + return CFX_WideString(buf.data(), len); } CPDF_Dest CPDF_Bookmark::GetDest(CPDF_Document* pDocument) const { diff --git a/core/fpdfdoc/cpdf_filespec.cpp b/core/fpdfdoc/cpdf_filespec.cpp index 086515b9a8..7fe8ec8c03 100644 --- a/core/fpdfdoc/cpdf_filespec.cpp +++ b/core/fpdfdoc/cpdf_filespec.cpp @@ -112,10 +112,9 @@ bool CPDF_FileSpec::GetFileName(CFX_WideString* csFileName) const { return true; } -CPDF_FileSpec::CPDF_FileSpec(const CFX_WeakPtr<CFX_ByteStringPool>& pPool) { - m_pObj = new CPDF_Dictionary(pPool); - m_pObj->AsDictionary()->SetNewFor<CPDF_Name>("Type", "Filespec"); -} +CPDF_FileSpec::CPDF_FileSpec(CPDF_Object* pObj) : m_pObj(pObj) {} + +CPDF_FileSpec::~CPDF_FileSpec() {} CFX_WideString CPDF_FileSpec::EncodeFileName(const CFX_WideStringC& filepath) { if (filepath.GetLength() <= 1) diff --git a/core/fpdfdoc/cpdf_filespec.h b/core/fpdfdoc/cpdf_filespec.h index 6266c37a47..ea002f0e22 100644 --- a/core/fpdfdoc/cpdf_filespec.h +++ b/core/fpdfdoc/cpdf_filespec.h @@ -15,8 +15,8 @@ class CPDF_Object; class CPDF_FileSpec { public: - explicit CPDF_FileSpec(const CFX_WeakPtr<CFX_ByteStringPool>& pPool); - explicit CPDF_FileSpec(CPDF_Object* pObj) : m_pObj(pObj) {} + explicit CPDF_FileSpec(CPDF_Object* pObj); + ~CPDF_FileSpec(); // Convert a platform dependent file name into pdf format. static CFX_WideString EncodeFileName(const CFX_WideStringC& filepath); @@ -31,7 +31,7 @@ class CPDF_FileSpec { void SetFileName(const CFX_WideStringC& wsFileName); private: - CPDF_Object* m_pObj; + CPDF_Object* const m_pObj; // not owned. }; #endif // CORE_FPDFDOC_CPDF_FILESPEC_H_ diff --git a/core/fpdfdoc/cpdf_interform.cpp b/core/fpdfdoc/cpdf_interform.cpp index dad25aa037..f498617b27 100644 --- a/core/fpdfdoc/cpdf_interform.cpp +++ b/core/fpdfdoc/cpdf_interform.cpp @@ -23,6 +23,7 @@ #include "core/fxcrt/fx_codepage.h" #include "core/fxge/cfx_substfont.h" #include "core/fxge/fx_font.h" +#include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" namespace { @@ -633,7 +634,7 @@ uint8_t CPDF_InterForm::GetNativeCharSet() { CPDF_InterForm::CPDF_InterForm(CPDF_Document* pDocument) : m_pDocument(pDocument), m_pFormDict(nullptr), - m_pFieldTree(new CFieldTree), + m_pFieldTree(pdfium::MakeUnique<CFieldTree>()), m_pFormNotify(nullptr) { CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); if (!pRoot) @@ -1198,9 +1199,12 @@ std::unique_ptr<CFDF_Document> CPDF_InterForm::ExportToFDF( pMainDict->SetNewFor<CPDF_String>("UF", PDF_EncodeText(wsFilePath), false); } else { - CPDF_FileSpec filespec(pDoc->GetByteStringPool()); + auto pNewDict = + pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()); + pNewDict->SetNewFor<CPDF_Name>("Type", "Filespec"); + CPDF_FileSpec filespec(pNewDict.get()); filespec.SetFileName(pdf_path); - pMainDict->SetFor("F", pdfium::WrapUnique(filespec.GetObj())); + pMainDict->SetFor("F", std::move(pNewDict)); } } diff --git a/core/fxcodec/codec/fx_codec.cpp b/core/fxcodec/codec/fx_codec.cpp index c47231c9af..38f5a7608d 100644 --- a/core/fxcodec/codec/fx_codec.cpp +++ b/core/fxcodec/codec/fx_codec.cpp @@ -18,14 +18,13 @@ #include "third_party/base/ptr_util.h" CCodec_ModuleMgr::CCodec_ModuleMgr() - : m_pBasicModule(new CCodec_BasicModule), - m_pFaxModule(new CCodec_FaxModule), - m_pJpegModule(new CCodec_JpegModule), - m_pJpxModule(new CCodec_JpxModule), - m_pJbig2Module(new CCodec_Jbig2Module), - m_pIccModule(new CCodec_IccModule), - m_pFlateModule(new CCodec_FlateModule) { -} + : m_pBasicModule(pdfium::MakeUnique<CCodec_BasicModule>()), + m_pFaxModule(pdfium::MakeUnique<CCodec_FaxModule>()), + m_pJpegModule(pdfium::MakeUnique<CCodec_JpegModule>()), + m_pJpxModule(pdfium::MakeUnique<CCodec_JpxModule>()), + m_pJbig2Module(pdfium::MakeUnique<CCodec_Jbig2Module>()), + m_pIccModule(pdfium::MakeUnique<CCodec_IccModule>()), + m_pFlateModule(pdfium::MakeUnique<CCodec_FlateModule>()) {} CCodec_ModuleMgr::~CCodec_ModuleMgr() {} diff --git a/core/fxcrt/fx_bidi.cpp b/core/fxcrt/fx_bidi.cpp index 49333f6a76..25544546d3 100644 --- a/core/fxcrt/fx_bidi.cpp +++ b/core/fxcrt/fx_bidi.cpp @@ -5,10 +5,12 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com #include "core/fxcrt/fx_bidi.h" -#include "core/fxcrt/fx_ucd.h" #include <algorithm> +#include "core/fxcrt/fx_ucd.h" +#include "third_party/base/ptr_util.h" + CFX_BidiChar::CFX_BidiChar() : m_CurrentSegment({0, 0, NEUTRAL}), m_LastSegment({0, 0, NEUTRAL}) {} @@ -50,7 +52,7 @@ void CFX_BidiChar::StartNewSegment(CFX_BidiChar::Direction direction) { CFX_BidiString::CFX_BidiString(const CFX_WideString& str) : m_Str(str), - m_pBidiChar(new CFX_BidiChar), + m_pBidiChar(pdfium::MakeUnique<CFX_BidiChar>()), m_eOverallDirection(CFX_BidiChar::LEFT) { for (const auto& c : m_Str) { if (m_pBidiChar->AppendChar(c)) diff --git a/core/fxcrt/fx_stream.cpp b/core/fxcrt/fx_stream.cpp index 2c451c67b8..32b6ca3495 100644 --- a/core/fxcrt/fx_stream.cpp +++ b/core/fxcrt/fx_stream.cpp @@ -52,7 +52,7 @@ class CFX_CRTFileStream final : public IFX_SeekableStream { CFX_RetainPtr<IFX_SeekableStream> IFX_SeekableStream::CreateFromFilename( const char* filename, uint32_t dwModes) { - std::unique_ptr<IFXCRT_FileAccess> pFA(IFXCRT_FileAccess::Create()); + std::unique_ptr<IFXCRT_FileAccess> pFA = IFXCRT_FileAccess::Create(); if (!pFA->Open(filename, dwModes)) return nullptr; return pdfium::MakeRetain<CFX_CRTFileStream>(std::move(pFA)); @@ -62,7 +62,7 @@ CFX_RetainPtr<IFX_SeekableStream> IFX_SeekableStream::CreateFromFilename( CFX_RetainPtr<IFX_SeekableStream> IFX_SeekableStream::CreateFromFilename( const wchar_t* filename, uint32_t dwModes) { - std::unique_ptr<IFXCRT_FileAccess> pFA(IFXCRT_FileAccess::Create()); + std::unique_ptr<IFXCRT_FileAccess> pFA = IFXCRT_FileAccess::Create(); if (!pFA->Open(filename, dwModes)) return nullptr; return pdfium::MakeRetain<CFX_CRTFileStream>(std::move(pFA)); diff --git a/core/fxcrt/fxcrt_posix.cpp b/core/fxcrt/fxcrt_posix.cpp index 562c70c23e..3afe2c32d5 100644 --- a/core/fxcrt/fxcrt_posix.cpp +++ b/core/fxcrt/fxcrt_posix.cpp @@ -6,15 +6,18 @@ #include "core/fxcrt/fxcrt_posix.h" +#include <memory> + #include "core/fxcrt/fx_basic.h" +#include "third_party/base/ptr_util.h" #if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || \ _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || \ _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ // static -IFXCRT_FileAccess* IFXCRT_FileAccess::Create() { - return new CFXCRT_FileAccess_Posix; +std::unique_ptr<IFXCRT_FileAccess> IFXCRT_FileAccess::Create() { + return pdfium::MakeUnique<CFXCRT_FileAccess_Posix>(); } void FXCRT_Posix_GetFileMode(uint32_t dwModes, diff --git a/core/fxcrt/fxcrt_windows.cpp b/core/fxcrt/fxcrt_windows.cpp index 638338706e..6230c74eb7 100644 --- a/core/fxcrt/fxcrt_windows.cpp +++ b/core/fxcrt/fxcrt_windows.cpp @@ -6,13 +6,16 @@ #include "core/fxcrt/fxcrt_windows.h" +#include <memory> + #include "core/fxcrt/fx_string.h" +#include "third_party/base/ptr_util.h" #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ // static -IFXCRT_FileAccess* IFXCRT_FileAccess::Create() { - return new CFXCRT_FileAccess_Win64; +std::unique_ptr<IFXCRT_FileAccess> IFXCRT_FileAccess::Create() { + return pdfium::MakeUnique<CFXCRT_FileAccess_Win64>(); } void FXCRT_Windows_GetFileMode(uint32_t dwMode, diff --git a/core/fxcrt/ifxcrt_fileaccess.h b/core/fxcrt/ifxcrt_fileaccess.h index 9528b3b377..340c2d1eeb 100644 --- a/core/fxcrt/ifxcrt_fileaccess.h +++ b/core/fxcrt/ifxcrt_fileaccess.h @@ -15,7 +15,7 @@ class IFXCRT_FileAccess { public: - static IFXCRT_FileAccess* Create(); + static std::unique_ptr<IFXCRT_FileAccess> Create(); virtual ~IFXCRT_FileAccess() {} virtual bool Open(const CFX_ByteStringC& fileName, uint32_t dwMode) = 0; |