From 0bb1333a9eff1190ddd68f34c71d6a779c69dfef Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Thu, 30 Mar 2017 16:12:02 -0400 Subject: Add some calls to MakeUnique This CL replaces some new's with pdfium::MakeUnique. Change-Id: I50faf3ed55e7730b094c14a7989a9dd51cf33cbb Reviewed-on: https://pdfium-review.googlesource.com/3430 Commit-Queue: dsinclair Reviewed-by: Tom Sepez --- fpdfsdk/cfx_systemhandler.cpp | 2 +- fpdfsdk/cpdfsdk_formfillenvironment.cpp | 2 +- fpdfsdk/cpdfsdk_interform.cpp | 7 ++++--- fpdfsdk/cpdfsdk_pageview.cpp | 2 +- fpdfsdk/cpdfsdk_widget.cpp | 6 +++--- fpdfsdk/fpdf_dataavail.cpp | 15 +++++++-------- fpdfsdk/fpdf_flatten.cpp | 2 +- fpdfsdk/fpdfsave.cpp | 8 ++++++-- fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp | 2 +- fpdfsdk/javascript/JS_GlobalData.cpp | 11 ++++++----- fpdfsdk/javascript/cjs_runtime.cpp | 3 +-- fpdfsdk/pdfwindow/PWL_Utils.cpp | 2 +- 12 files changed, 33 insertions(+), 29 deletions(-) (limited to 'fpdfsdk') diff --git a/fpdfsdk/cfx_systemhandler.cpp b/fpdfsdk/cfx_systemhandler.cpp index ea64412d4c..906954354b 100644 --- a/fpdfsdk/cfx_systemhandler.cpp +++ b/fpdfsdk/cfx_systemhandler.cpp @@ -114,7 +114,7 @@ CPDF_Font* CFX_SystemHandler::AddNativeTrueTypeFontToPDF( if (!pDoc) return nullptr; - std::unique_ptr pFXFont(new CFX_Font); + auto pFXFont = pdfium::MakeUnique(); pFXFont->LoadSubst(sFontFaceName, true, 0, 0, 0, CharSet2CP(nCharset), false); return pDoc->AddFont(pFXFont.get(), nCharset, false); } diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.cpp b/fpdfsdk/cpdfsdk_formfillenvironment.cpp index 091ccfc42f..680cd252b7 100644 --- a/fpdfsdk/cpdfsdk_formfillenvironment.cpp +++ b/fpdfsdk/cpdfsdk_formfillenvironment.cpp @@ -35,7 +35,7 @@ CPDFSDK_FormFillEnvironment::CPDFSDK_FormFillEnvironment( FPDF_FORMFILLINFO* pFFinfo) : m_pInfo(pFFinfo), m_pUnderlyingDoc(pDoc), - m_pSysHandler(new CFX_SystemHandler(this)), + m_pSysHandler(pdfium::MakeUnique(this)), m_bChangeMask(false), m_bBeingDestroyed(false) {} diff --git a/fpdfsdk/cpdfsdk_interform.cpp b/fpdfsdk/cpdfsdk_interform.cpp index a16ec93c7a..635a534297 100644 --- a/fpdfsdk/cpdfsdk_interform.cpp +++ b/fpdfsdk/cpdfsdk_interform.cpp @@ -47,7 +47,8 @@ CPDFSDK_InterForm::CPDFSDK_InterForm(CPDFSDK_FormFillEnvironment* pFormFillEnv) : m_pFormFillEnv(pFormFillEnv), - m_pInterForm(new CPDF_InterForm(m_pFormFillEnv->GetPDFDocument())), + m_pInterForm( + pdfium::MakeUnique(m_pFormFillEnv->GetPDFDocument())), #ifdef PDF_ENABLE_XFA m_bXfaCalculate(true), m_bXfaValidationsEnabled(true), @@ -73,8 +74,8 @@ bool CPDFSDK_InterForm::HighlightWidgets() { CPDFSDK_Widget* CPDFSDK_InterForm::GetSibling(CPDFSDK_Widget* pWidget, bool bNext) const { - std::unique_ptr pIterator(new CBA_AnnotIterator( - pWidget->GetPageView(), CPDF_Annot::Subtype::WIDGET)); + auto pIterator = pdfium::MakeUnique( + pWidget->GetPageView(), CPDF_Annot::Subtype::WIDGET); if (bNext) return static_cast(pIterator->GetNextAnnot(pWidget)); diff --git a/fpdfsdk/cpdfsdk_pageview.cpp b/fpdfsdk/cpdfsdk_pageview.cpp index 7a8e2665c3..946dd84163 100644 --- a/fpdfsdk/cpdfsdk_pageview.cpp +++ b/fpdfsdk/cpdfsdk_pageview.cpp @@ -100,7 +100,7 @@ void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, static_cast(pClip.left), static_cast(pClip.top), static_cast(pClip.Width()), static_cast(pClip.Height())); gs.SetClipRect(rectClip); - std::unique_ptr pRenderContext(new CXFA_RenderContext); + auto pRenderContext = pdfium::MakeUnique(); CXFA_RenderOptions renderOptions; renderOptions.m_bHighlight = true; CXFA_FFPageView* xfaView = pPage->GetXFAPageView(); diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp index 2ffd170d8a..e65a94b2b3 100644 --- a/fpdfsdk/cpdfsdk_widget.cpp +++ b/fpdfsdk/cpdfsdk_widget.cpp @@ -1357,7 +1357,7 @@ void CPDFSDK_Widget::ResetAppearance_ComboBox(const CFX_WideString* sValue) { rcButton.left = rcButton.right - 13; rcButton.Normalize(); - std::unique_ptr pEdit(new CFX_Edit); + auto pEdit = pdfium::MakeUnique(); pEdit->EnableRefresh(false); CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler()); @@ -1421,7 +1421,7 @@ void CPDFSDK_Widget::ResetAppearance_ListBox() { CFX_FloatRect rcClient = GetClientRect(); CFX_ByteTextBuf sBody, sLines; - std::unique_ptr pEdit(new CFX_Edit); + auto pEdit = pdfium::MakeUnique(); pEdit->EnableRefresh(false); CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler()); @@ -1503,7 +1503,7 @@ void CPDFSDK_Widget::ResetAppearance_TextField(const CFX_WideString* sValue) { CPDF_FormField* pField = pControl->GetField(); CFX_ByteTextBuf sBody, sLines; - std::unique_ptr pEdit(new CFX_Edit); + auto pEdit = pdfium::MakeUnique(); pEdit->EnableRefresh(false); CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler()); diff --git a/fpdfsdk/fpdf_dataavail.cpp b/fpdfsdk/fpdf_dataavail.cpp index b1bc1e3bc0..f2358d2e5c 100644 --- a/fpdfsdk/fpdf_dataavail.cpp +++ b/fpdfsdk/fpdf_dataavail.cpp @@ -60,9 +60,9 @@ class CFPDF_FileAvailWrap : public CPDF_DataAvail::FileAvail { class CFPDF_FileAccessWrap : public IFX_SeekableReadStream { public: - static CFX_RetainPtr Create() { - return CFX_RetainPtr(new CFPDF_FileAccessWrap()); - } + template + friend CFX_RetainPtr pdfium::MakeRetain(Args&&... args); + ~CFPDF_FileAccessWrap() override {} void Set(FPDF_FILEACCESS* pFile) { m_pFileAccess = pFile; } @@ -101,8 +101,8 @@ class CFPDF_DownloadHintsWrap : public CPDF_DataAvail::DownloadHints { class CFPDF_DataAvail { public: CFPDF_DataAvail() - : m_FileAvail(new CFPDF_FileAvailWrap), - m_FileRead(CFPDF_FileAccessWrap::Create()) {} + : m_FileAvail(pdfium::MakeUnique()), + m_FileRead(pdfium::MakeRetain()) {} ~CFPDF_DataAvail() {} std::unique_ptr m_pDataAvail; @@ -145,11 +145,10 @@ FPDFAvail_GetDocument(FPDF_AVAIL avail, FPDF_BYTESTRING password) { if (!pDataAvail) return nullptr; - std::unique_ptr pParser(new CPDF_Parser); + auto pParser = pdfium::MakeUnique(); pParser->SetPassword(password); - std::unique_ptr pDocument( - new CPDF_Document(std::move(pParser))); + auto pDocument = pdfium::MakeUnique(std::move(pParser)); CPDF_Parser::Error error = pDocument->GetParser()->StartLinearizedParse( pDataAvail->m_pDataAvail->GetFileRead(), pDocument.get()); if (error != CPDF_Parser::SUCCESS) { diff --git a/fpdfsdk/fpdf_flatten.cpp b/fpdfsdk/fpdf_flatten.cpp index c43412cfc7..8e181eb380 100644 --- a/fpdfsdk/fpdf_flatten.cpp +++ b/fpdfsdk/fpdf_flatten.cpp @@ -51,7 +51,7 @@ bool IsValiableRect(CFX_FloatRect rect, CFX_FloatRect rcPage) { void GetContentsRect(CPDF_Document* pDoc, CPDF_Dictionary* pDict, std::vector* pRectArray) { - std::unique_ptr pPDFPage(new CPDF_Page(pDoc, pDict, false)); + auto pPDFPage = pdfium::MakeUnique(pDoc, pDict, false); pPDFPage->ParseContent(); for (const auto& pPageObject : *pPDFPage->GetPageObjectList()) { diff --git a/fpdfsdk/fpdfsave.cpp b/fpdfsdk/fpdfsave.cpp index 1d076ccdad..6894f8c2ed 100644 --- a/fpdfsdk/fpdfsave.cpp +++ b/fpdfsdk/fpdfsave.cpp @@ -41,10 +41,14 @@ class CFX_IFileWrite final : public IFX_WriteStream { public: static CFX_RetainPtr Create(); + bool Init(FPDF_FILEWRITE* pFileWriteStruct); bool WriteBlock(const void* pData, size_t size) override; protected: + template + friend CFX_RetainPtr pdfium::MakeRetain(Args&&... args); + CFX_IFileWrite(); ~CFX_IFileWrite() override {} @@ -52,7 +56,7 @@ class CFX_IFileWrite final : public IFX_WriteStream { }; CFX_RetainPtr CFX_IFileWrite::Create() { - return CFX_RetainPtr(new CFX_IFileWrite()); + return pdfium::MakeRetain(); } CFX_IFileWrite::CFX_IFileWrite() : m_pFileWriteStruct(nullptr) {} @@ -127,7 +131,7 @@ bool SaveXFADocumentData( else if (pPDFObj->GetString() == "template") iTemplate = i + 1; } - std::unique_ptr pChecksum(new CFX_ChecksumContext); + auto pChecksum = pdfium::MakeUnique(); pChecksum->StartChecksum(); // template diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp index 45c5d9255b..7afd12c707 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp @@ -497,7 +497,7 @@ void CPDFXFA_DocEnvironment::ExportData(CXFA_FFDoc* hDoc, fileWrite->WriteBlock(content.c_str(), fileWrite->GetSize(), content.GetLength()); } - std::unique_ptr pAcc(new CPDF_StreamAcc); + auto pAcc = pdfium::MakeUnique(); pAcc->LoadAllData(pStream); fileWrite->WriteBlock(pAcc->GetData(), fileWrite->GetSize(), pAcc->GetSize()); diff --git a/fpdfsdk/javascript/JS_GlobalData.cpp b/fpdfsdk/javascript/JS_GlobalData.cpp index 048fca0591..14202646c5 100644 --- a/fpdfsdk/javascript/JS_GlobalData.cpp +++ b/fpdfsdk/javascript/JS_GlobalData.cpp @@ -9,6 +9,7 @@ #include #include "core/fdrm/crypto/fx_crypt.h" +#include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" #define JS_MAXGLOBALDATA (1024 * 4 - 8) @@ -104,7 +105,7 @@ void CJS_GlobalData::SetGlobalVariableNumber(const CFX_ByteString& propname, pData->data.dData = dData; return; } - std::unique_ptr pNewData(new CJS_GlobalData_Element); + auto pNewData = pdfium::MakeUnique(); pNewData->data.sKey = sPropName; pNewData->data.nType = JS_GlobalDataType::NUMBER; pNewData->data.dData = dData; @@ -122,7 +123,7 @@ void CJS_GlobalData::SetGlobalVariableBoolean(const CFX_ByteString& propname, pData->data.bData = bData; return; } - std::unique_ptr pNewData(new CJS_GlobalData_Element); + auto pNewData = pdfium::MakeUnique(); pNewData->data.sKey = sPropName; pNewData->data.nType = JS_GlobalDataType::BOOLEAN; pNewData->data.bData = bData; @@ -140,7 +141,7 @@ void CJS_GlobalData::SetGlobalVariableString(const CFX_ByteString& propname, pData->data.sData = sData; return; } - std::unique_ptr pNewData(new CJS_GlobalData_Element); + auto pNewData = pdfium::MakeUnique(); pNewData->data.sKey = sPropName; pNewData->data.nType = JS_GlobalDataType::STRING; pNewData->data.sData = sData; @@ -159,7 +160,7 @@ void CJS_GlobalData::SetGlobalVariableObject( pData->data.objData.Copy(array); return; } - std::unique_ptr pNewData(new CJS_GlobalData_Element); + auto pNewData = pdfium::MakeUnique(); pNewData->data.sKey = sPropName; pNewData->data.nType = JS_GlobalDataType::OBJECT; pNewData->data.objData.Copy(array); @@ -175,7 +176,7 @@ void CJS_GlobalData::SetGlobalVariableNull(const CFX_ByteString& propname) { pData->data.nType = JS_GlobalDataType::NULLOBJ; return; } - std::unique_ptr pNewData(new CJS_GlobalData_Element); + auto pNewData = pdfium::MakeUnique(); pNewData->data.sKey = sPropName; pNewData->data.nType = JS_GlobalDataType::NULLOBJ; m_arrayGlobalData.push_back(std::move(pNewData)); diff --git a/fpdfsdk/javascript/cjs_runtime.cpp b/fpdfsdk/javascript/cjs_runtime.cpp index a6da9c494a..cb8f69f9da 100644 --- a/fpdfsdk/javascript/cjs_runtime.cpp +++ b/fpdfsdk/javascript/cjs_runtime.cpp @@ -147,8 +147,7 @@ void CJS_Runtime::DefineJSObjects() { } IJS_EventContext* CJS_Runtime::NewEventContext() { - m_EventContextArray.push_back( - std::unique_ptr(new CJS_EventContext(this))); + m_EventContextArray.push_back(pdfium::MakeUnique(this)); return m_EventContextArray.back().get(); } diff --git a/fpdfsdk/pdfwindow/PWL_Utils.cpp b/fpdfsdk/pdfwindow/PWL_Utils.cpp index 08b5e3013a..dbac6ad8bc 100644 --- a/fpdfsdk/pdfwindow/PWL_Utils.cpp +++ b/fpdfsdk/pdfwindow/PWL_Utils.cpp @@ -331,7 +331,7 @@ CFX_ByteString CPWL_Utils::GetPushButtonAppStream(const CFX_FloatRect& rcBBox, int32_t nLayOut) { const float fAutoFontScale = 1.0f / 3.0f; - std::unique_ptr pEdit(new CFX_Edit); + auto pEdit = pdfium::MakeUnique(); pEdit->SetFontMap(pFontMap); pEdit->SetAlignmentH(1, true); pEdit->SetAlignmentV(1, true); -- cgit v1.2.3