summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-03-30 16:12:02 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-03-30 20:26:02 +0000
commit0bb1333a9eff1190ddd68f34c71d6a779c69dfef (patch)
tree5a46946c4852f147309e2b1389e6f42d6553abf7 /fpdfsdk
parent908c848202ef137e98d96f82a4eadfae551403b7 (diff)
downloadpdfium-0bb1333a9eff1190ddd68f34c71d6a779c69dfef.tar.xz
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 <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/cfx_systemhandler.cpp2
-rw-r--r--fpdfsdk/cpdfsdk_formfillenvironment.cpp2
-rw-r--r--fpdfsdk/cpdfsdk_interform.cpp7
-rw-r--r--fpdfsdk/cpdfsdk_pageview.cpp2
-rw-r--r--fpdfsdk/cpdfsdk_widget.cpp6
-rw-r--r--fpdfsdk/fpdf_dataavail.cpp15
-rw-r--r--fpdfsdk/fpdf_flatten.cpp2
-rw-r--r--fpdfsdk/fpdfsave.cpp8
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp2
-rw-r--r--fpdfsdk/javascript/JS_GlobalData.cpp11
-rw-r--r--fpdfsdk/javascript/cjs_runtime.cpp3
-rw-r--r--fpdfsdk/pdfwindow/PWL_Utils.cpp2
12 files changed, 33 insertions, 29 deletions
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<CFX_Font> pFXFont(new CFX_Font);
+ auto pFXFont = pdfium::MakeUnique<CFX_Font>();
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<CFX_SystemHandler>(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<CPDF_InterForm>(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<CBA_AnnotIterator> pIterator(new CBA_AnnotIterator(
- pWidget->GetPageView(), CPDF_Annot::Subtype::WIDGET));
+ auto pIterator = pdfium::MakeUnique<CBA_AnnotIterator>(
+ pWidget->GetPageView(), CPDF_Annot::Subtype::WIDGET);
if (bNext)
return static_cast<CPDFSDK_Widget*>(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<float>(pClip.left), static_cast<float>(pClip.top),
static_cast<float>(pClip.Width()), static_cast<float>(pClip.Height()));
gs.SetClipRect(rectClip);
- std::unique_ptr<CXFA_RenderContext> pRenderContext(new CXFA_RenderContext);
+ auto pRenderContext = pdfium::MakeUnique<CXFA_RenderContext>();
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<CFX_Edit> pEdit(new CFX_Edit);
+ auto pEdit = pdfium::MakeUnique<CFX_Edit>();
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<CFX_Edit> pEdit(new CFX_Edit);
+ auto pEdit = pdfium::MakeUnique<CFX_Edit>();
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<CFX_Edit> pEdit(new CFX_Edit);
+ auto pEdit = pdfium::MakeUnique<CFX_Edit>();
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<CFPDF_FileAccessWrap> Create() {
- return CFX_RetainPtr<CFPDF_FileAccessWrap>(new CFPDF_FileAccessWrap());
- }
+ template <typename T, typename... Args>
+ friend CFX_RetainPtr<T> 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<CFPDF_FileAvailWrap>()),
+ m_FileRead(pdfium::MakeRetain<CFPDF_FileAccessWrap>()) {}
~CFPDF_DataAvail() {}
std::unique_ptr<CPDF_DataAvail> m_pDataAvail;
@@ -145,11 +145,10 @@ FPDFAvail_GetDocument(FPDF_AVAIL avail, FPDF_BYTESTRING password) {
if (!pDataAvail)
return nullptr;
- std::unique_ptr<CPDF_Parser> pParser(new CPDF_Parser);
+ auto pParser = pdfium::MakeUnique<CPDF_Parser>();
pParser->SetPassword(password);
- std::unique_ptr<CPDF_Document> pDocument(
- new CPDF_Document(std::move(pParser)));
+ auto pDocument = pdfium::MakeUnique<CPDF_Document>(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<CFX_FloatRect>* pRectArray) {
- std::unique_ptr<CPDF_Page> pPDFPage(new CPDF_Page(pDoc, pDict, false));
+ auto pPDFPage = pdfium::MakeUnique<CPDF_Page>(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<CFX_IFileWrite> Create();
+
bool Init(FPDF_FILEWRITE* pFileWriteStruct);
bool WriteBlock(const void* pData, size_t size) override;
protected:
+ template <typename T, typename... Args>
+ friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
+
CFX_IFileWrite();
~CFX_IFileWrite() override {}
@@ -52,7 +56,7 @@ class CFX_IFileWrite final : public IFX_WriteStream {
};
CFX_RetainPtr<CFX_IFileWrite> CFX_IFileWrite::Create() {
- return CFX_RetainPtr<CFX_IFileWrite>(new CFX_IFileWrite());
+ return pdfium::MakeRetain<CFX_IFileWrite>();
}
CFX_IFileWrite::CFX_IFileWrite() : m_pFileWriteStruct(nullptr) {}
@@ -127,7 +131,7 @@ bool SaveXFADocumentData(
else if (pPDFObj->GetString() == "template")
iTemplate = i + 1;
}
- std::unique_ptr<CFX_ChecksumContext> pChecksum(new CFX_ChecksumContext);
+ auto pChecksum = pdfium::MakeUnique<CFX_ChecksumContext>();
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<CPDF_StreamAcc> pAcc(new CPDF_StreamAcc);
+ auto pAcc = pdfium::MakeUnique<CPDF_StreamAcc>();
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 <utility>
#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<CJS_GlobalData_Element> pNewData(new CJS_GlobalData_Element);
+ auto pNewData = pdfium::MakeUnique<CJS_GlobalData_Element>();
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<CJS_GlobalData_Element> pNewData(new CJS_GlobalData_Element);
+ auto pNewData = pdfium::MakeUnique<CJS_GlobalData_Element>();
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<CJS_GlobalData_Element> pNewData(new CJS_GlobalData_Element);
+ auto pNewData = pdfium::MakeUnique<CJS_GlobalData_Element>();
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<CJS_GlobalData_Element> pNewData(new CJS_GlobalData_Element);
+ auto pNewData = pdfium::MakeUnique<CJS_GlobalData_Element>();
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<CJS_GlobalData_Element> pNewData(new CJS_GlobalData_Element);
+ auto pNewData = pdfium::MakeUnique<CJS_GlobalData_Element>();
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<CJS_EventContext>(new CJS_EventContext(this)));
+ m_EventContextArray.push_back(pdfium::MakeUnique<CJS_EventContext>(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<CFX_Edit> pEdit(new CFX_Edit);
+ auto pEdit = pdfium::MakeUnique<CFX_Edit>();
pEdit->SetFontMap(pFontMap);
pEdit->SetAlignmentH(1, true);
pEdit->SetAlignmentV(1, true);