diff options
author | tsepez <tsepez@chromium.org> | 2016-10-03 15:24:27 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-10-03 15:24:27 -0700 |
commit | 36eb4bdcae719cf33c536ff72ac000482aed8382 (patch) | |
tree | b3c3467fa10eafc3863a619ef511d1bf20af6367 | |
parent | 76383db4906c9357292846ace77566b34eb47de9 (diff) | |
download | pdfium-36eb4bdcae719cf33c536ff72ac000482aed8382.tar.xz |
Add ptr_util.h from base until std::make_unique<> available
Review-Url: https://codereview.chromium.org/2386273004
39 files changed, 200 insertions, 94 deletions
diff --git a/core/fpdfapi/fpdf_font/cpdf_font.cpp b/core/fpdfapi/fpdf_font/cpdf_font.cpp index 9b6fc5e824..96ebda740a 100644 --- a/core/fpdfapi/fpdf_font/cpdf_font.cpp +++ b/core/fpdfapi/fpdf_font/cpdf_font.cpp @@ -24,6 +24,7 @@ #include "core/fpdfapi/fpdf_parser/cpdf_stream_acc.h" #include "core/fxcrt/fx_memory.h" #include "core/fxge/fx_freetype.h" +#include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" namespace { @@ -454,7 +455,7 @@ const FX_CHAR* CPDF_Font::GetAdobeCharName( uint32_t CPDF_Font::FallbackFontFromCharcode(uint32_t charcode) { if (m_FontFallbacks.empty()) { - m_FontFallbacks.push_back(WrapUnique(new CFX_Font())); + m_FontFallbacks.push_back(pdfium::MakeUnique<CFX_Font>()); m_FontFallbacks[0]->LoadSubst("Arial", IsTrueTypeFont(), m_Flags, m_StemV * 5, m_ItalicAngle, 0, IsVertWriting()); diff --git a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp index 4fc4bdc934..5356e1f5b5 100644 --- a/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp +++ b/core/fpdfapi/fpdf_page/fpdf_page_parser.cpp @@ -36,6 +36,7 @@ #include "core/fxcrt/fx_safe_types.h" #include "core/fxge/cfx_graphstatedata.h" #include "core/fxge/cfx_pathdata.h" +#include "third_party/base/ptr_util.h" namespace { @@ -790,7 +791,7 @@ CPDF_ImageObject* CPDF_StreamContentParser::AddImage(CPDF_Stream* pStream, pImageObj->SetUnownedImage(m_pDocument->LoadImageF(pStream)); } else { pImageObj->SetOwnedImage( - WrapUnique(new CPDF_Image(m_pDocument, pStream, bInline))); + pdfium::MakeUnique<CPDF_Image>(m_pDocument, pStream, bInline)); } SetGraphicStates(pImageObj.get(), pImageObj->GetImage()->IsMask(), FALSE, FALSE); diff --git a/core/fpdfapi/fpdf_parser/cfdf_document.cpp b/core/fpdfapi/fpdf_parser/cfdf_document.cpp index 3721bf885b..c8ed9edada 100644 --- a/core/fpdfapi/fpdf_parser/cfdf_document.cpp +++ b/core/fpdfapi/fpdf_parser/cfdf_document.cpp @@ -9,13 +9,14 @@ #include "core/fpdfapi/fpdf_edit/cpdf_creator.h" #include "core/fpdfapi/fpdf_parser/cpdf_dictionary.h" #include "core/fpdfapi/fpdf_parser/cpdf_syntax_parser.h" +#include "third_party/base/ptr_util.h" CFDF_Document::CFDF_Document() : CPDF_IndirectObjectHolder(), m_pRootDict(nullptr), m_pFile(nullptr), m_bOwnFile(FALSE), - m_pByteStringPool(WrapUnique(new CFX_ByteStringPool)) {} + m_pByteStringPool(pdfium::MakeUnique<CFX_ByteStringPool>()) {} CFDF_Document::~CFDF_Document() { if (m_bOwnFile && m_pFile) diff --git a/core/fpdfapi/fpdf_parser/cpdf_document.cpp b/core/fpdfapi/fpdf_parser/cpdf_document.cpp index f8b4f9b87b..75e6a84598 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_document.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_document.cpp @@ -23,6 +23,7 @@ #include "core/fxcodec/JBig2_DocumentContext.h" #include "core/fxge/cfx_unicodeencoding.h" #include "core/fxge/fx_font.h" +#include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" namespace { @@ -415,7 +416,7 @@ CPDF_Document::CPDF_Document(std::unique_ptr<CPDF_Parser> pParser) m_dwFirstPageObjNum(0), m_pDocPage(new CPDF_DocPageData(this)), m_pDocRender(new CPDF_DocRenderData(this)), - m_pByteStringPool(WrapUnique(new CFX_ByteStringPool)) { + m_pByteStringPool(pdfium::MakeUnique<CFX_ByteStringPool>()) { if (pParser) SetLastObjNum(m_pParser->GetLastObjNum()); } diff --git a/core/fpdfdoc/cpdf_annot.cpp b/core/fpdfdoc/cpdf_annot.cpp index 3df5ca5144..c2297ac3df 100644 --- a/core/fpdfdoc/cpdf_annot.cpp +++ b/core/fpdfdoc/cpdf_annot.cpp @@ -17,6 +17,7 @@ #include "core/fxge/cfx_graphstatedata.h" #include "core/fxge/cfx_pathdata.h" #include "core/fxge/cfx_renderdevice.h" +#include "third_party/base/ptr_util.h" namespace { @@ -183,7 +184,7 @@ CPDF_Form* CPDF_Annot::GetAPForm(const CPDF_Page* pPage, AppearanceMode mode) { CPDF_Form* pNewForm = new CPDF_Form(m_pDocument, pPage->m_pResources, pStream); pNewForm->ParseContent(nullptr, nullptr, nullptr); - m_APMap[pStream] = WrapUnique(pNewForm); + m_APMap[pStream] = pdfium::WrapUnique(pNewForm); return pNewForm; } diff --git a/core/fxcrt/fx_memory.h b/core/fxcrt/fx_memory.h index beb194fbda..0ad28ce896 100644 --- a/core/fxcrt/fx_memory.h +++ b/core/fxcrt/fx_memory.h @@ -101,12 +101,6 @@ struct ReleaseDeleter { inline void operator()(T* ptr) const { ptr->Release(); } }; -// Used to help transfer ownership of a raw pointer to std::unique_ptr. -template <typename T> -std::unique_ptr<T> WrapUnique(T* ptr) { - return std::unique_ptr<T>(ptr); -} - #endif // __cplusplus #endif // CORE_FXCRT_FX_MEMORY_H_ diff --git a/core/fxcrt/fx_xml_parser.cpp b/core/fxcrt/fx_xml_parser.cpp index a7026e9bb1..563e1c961b 100644 --- a/core/fxcrt/fx_xml_parser.cpp +++ b/core/fxcrt/fx_xml_parser.cpp @@ -10,6 +10,7 @@ #include "core/fxcrt/fx_ext.h" #include "core/fxcrt/fx_xml.h" +#include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" CXML_DataBufAcc::CXML_DataBufAcc(const uint8_t* pBuffer, size_t size) @@ -894,7 +895,7 @@ void CXML_AttrMap::SetAt(const CFX_ByteString& space, const CFX_ByteString& name, const CFX_WideString& value) { if (!m_pMap) - m_pMap = WrapUnique(new std::vector<CXML_AttrItem>); + m_pMap = pdfium::MakeUnique<std::vector<CXML_AttrItem>>(); for (CXML_AttrItem& item : *m_pMap) { if (item.Matches(space, name)) { diff --git a/core/fxge/agg/fx_agg_driver.cpp b/core/fxge/agg/fx_agg_driver.cpp index 4f9c85c8a9..d3be763def 100644 --- a/core/fxge/agg/fx_agg_driver.cpp +++ b/core/fxge/agg/fx_agg_driver.cpp @@ -27,6 +27,7 @@ #include "third_party/agg23/agg_rasterizer_scanline_aa.h" #include "third_party/agg23/agg_renderer_scanline.h" #include "third_party/agg23/agg_scanline_u.h" +#include "third_party/base/ptr_util.h" namespace { @@ -498,7 +499,7 @@ int CFX_AggDeviceDriver::GetDeviceCaps(int caps_id) const { void CFX_AggDeviceDriver::SaveState() { std::unique_ptr<CFX_ClipRgn> pClip; if (m_pClipRgn) - pClip = WrapUnique(new CFX_ClipRgn(*m_pClipRgn)); + pClip = pdfium::MakeUnique<CFX_ClipRgn>(*m_pClipRgn); m_StateStack.push_back(std::move(pClip)); } @@ -510,7 +511,7 @@ void CFX_AggDeviceDriver::RestoreState(bool bKeepSaved) { if (bKeepSaved) { if (m_StateStack.back()) - m_pClipRgn = WrapUnique(new CFX_ClipRgn(*m_StateStack.back())); + m_pClipRgn = pdfium::MakeUnique<CFX_ClipRgn>(*m_StateStack.back()); } else { m_pClipRgn = std::move(m_StateStack.back()); m_StateStack.pop_back(); @@ -544,8 +545,8 @@ FX_BOOL CFX_AggDeviceDriver::SetClip_PathFill(const CFX_PathData* pPathData, int fill_mode) { m_FillFlags = fill_mode; if (!m_pClipRgn) { - m_pClipRgn = WrapUnique(new CFX_ClipRgn(GetDeviceCaps(FXDC_PIXEL_WIDTH), - GetDeviceCaps(FXDC_PIXEL_HEIGHT))); + m_pClipRgn = pdfium::MakeUnique<CFX_ClipRgn>( + GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT)); } if (pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) { CFX_FloatRect rectf; @@ -577,8 +578,8 @@ FX_BOOL CFX_AggDeviceDriver::SetClip_PathStroke( const CFX_Matrix* pObject2Device, const CFX_GraphStateData* pGraphState) { if (!m_pClipRgn) { - m_pClipRgn = WrapUnique(new CFX_ClipRgn(GetDeviceCaps(FXDC_PIXEL_WIDTH), - GetDeviceCaps(FXDC_PIXEL_HEIGHT))); + m_pClipRgn = pdfium::MakeUnique<CFX_ClipRgn>( + GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT)); } CAgg_PathData path_data; path_data.BuildPath(pPathData, nullptr); @@ -1735,8 +1736,8 @@ bool CFX_FxgeDevice::Attach(CFX_DIBitmap* pBitmap, return false; SetBitmap(pBitmap); - SetDeviceDriver(WrapUnique(new CFX_AggDeviceDriver( - pBitmap, bRgbByteOrder, pOriDevice, bGroupKnockout))); + SetDeviceDriver(pdfium::MakeUnique<CFX_AggDeviceDriver>( + pBitmap, bRgbByteOrder, pOriDevice, bGroupKnockout)); return true; } @@ -1751,8 +1752,8 @@ bool CFX_FxgeDevice::Create(int width, return false; } SetBitmap(pBitmap); - SetDeviceDriver( - WrapUnique(new CFX_AggDeviceDriver(pBitmap, FALSE, pOriDevice, FALSE))); + SetDeviceDriver(pdfium::MakeUnique<CFX_AggDeviceDriver>(pBitmap, FALSE, + pOriDevice, FALSE)); return true; } diff --git a/core/fxge/apple/fx_quartz_device.cpp b/core/fxge/apple/fx_quartz_device.cpp index d3520d7257..74a03649dd 100644 --- a/core/fxge/apple/fx_quartz_device.cpp +++ b/core/fxge/apple/fx_quartz_device.cpp @@ -18,6 +18,7 @@ #include "core/fxge/dib/dib_int.h" #include "core/fxge/fx_freetype.h" #include "core/fxge/ge/fx_text_int.h" +#include "third_party/base/ptr_util.h" #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ #include "core/fxge/apple/apple_int.h" @@ -1021,7 +1022,7 @@ FX_BOOL CFX_QuartzDevice::Attach(CGContextRef context, int32_t nDeviceClass) { m_pContext = context; CGContextRetain(m_pContext); SetDeviceDriver( - WrapUnique(new CFX_QuartzDeviceDriver(m_pContext, nDeviceClass))); + pdfium::MakeUnique<CFX_QuartzDeviceDriver>(m_pContext, nDeviceClass)); return TRUE; } @@ -1032,7 +1033,7 @@ FX_BOOL CFX_QuartzDevice::Attach(CFX_DIBitmap* pBitmap) { return FALSE; SetDeviceDriver( - WrapUnique(new CFX_QuartzDeviceDriver(m_pContext, FXDC_DISPLAY))); + pdfium::MakeUnique<CFX_QuartzDeviceDriver>(m_pContext, FXDC_DISPLAY)); return TRUE; } diff --git a/core/fxge/dib/fx_dib_engine.cpp b/core/fxge/dib/fx_dib_engine.cpp index c8e9558888..389cf23909 100644 --- a/core/fxge/dib/fx_dib_engine.cpp +++ b/core/fxge/dib/fx_dib_engine.cpp @@ -10,6 +10,7 @@ #include "core/fxge/dib/dib_int.h" #include "core/fxge/fx_dib.h" +#include "third_party/base/ptr_util.h" namespace { @@ -930,9 +931,9 @@ FX_BOOL CFX_ImageStretcher::Continue(IFX_Pause* pPause) { } FX_BOOL CFX_ImageStretcher::StartStretch() { - m_pStretchEngine = WrapUnique( - new CStretchEngine(m_pDest, m_DestFormat, m_DestWidth, m_DestHeight, - m_ClipRect, m_pSource, m_Flags)); + m_pStretchEngine = pdfium::MakeUnique<CStretchEngine>( + m_pDest, m_DestFormat, m_DestWidth, m_DestHeight, m_ClipRect, m_pSource, + m_Flags); m_pStretchEngine->StartStretchHorz(); if (SourceSizeWithinLimit(m_pSource->GetWidth(), m_pSource->GetHeight())) { m_pStretchEngine->Continue(nullptr); diff --git a/core/fxge/dib/fx_dib_main.cpp b/core/fxge/dib/fx_dib_main.cpp index 14cd0f4da6..df448a66bd 100644 --- a/core/fxge/dib/fx_dib_main.cpp +++ b/core/fxge/dib/fx_dib_main.cpp @@ -13,6 +13,7 @@ #include "core/fxge/cfx_gemodule.h" #include "core/fxge/dib/dib_int.h" #include "core/fxge/ge/cfx_cliprgn.h" +#include "third_party/base/ptr_util.h" void CmykDecode(uint32_t cmyk, int& c, int& m, int& y, int& k) { c = FXSYS_GetCValue(cmyk); @@ -1461,7 +1462,7 @@ CFX_DIBitmap* CFX_DIBSource::FlipImage(FX_BOOL bXFlip, FX_BOOL bYFlip) const { CFX_DIBExtractor::CFX_DIBExtractor(const CFX_DIBSource* pSrc) { if (pSrc->GetBuffer()) { - m_pBitmap = WrapUnique(new CFX_DIBitmap); + m_pBitmap = pdfium::MakeUnique<CFX_DIBitmap>(); if (!m_pBitmap->Create(pSrc->GetWidth(), pSrc->GetHeight(), pSrc->GetFormat(), pSrc->GetBuffer())) { m_pBitmap.reset(); @@ -1567,9 +1568,9 @@ FX_BOOL CFX_ImageRenderer::Start(CFX_DIBitmap* pDevice, m_Composer.Compose(pDevice, pClipRgn, bitmap_alpha, mask_color, m_ClipBox, TRUE, m_Matrix.c > 0, m_Matrix.b < 0, m_bRgbByteOrder, alpha_flag, pIccTransform, m_BlendType); - m_Stretcher = WrapUnique(new CFX_ImageStretcher(&m_Composer, pSource, - dest_height, dest_width, - bitmap_clip, dib_flags)); + m_Stretcher = pdfium::MakeUnique<CFX_ImageStretcher>( + &m_Composer, pSource, dest_height, dest_width, bitmap_clip, + dib_flags); if (!m_Stretcher->Start()) return FALSE; @@ -1600,8 +1601,8 @@ FX_BOOL CFX_ImageRenderer::Start(CFX_DIBitmap* pDevice, FALSE, FALSE, FALSE, m_bRgbByteOrder, alpha_flag, pIccTransform, m_BlendType); m_Status = 1; - m_Stretcher = WrapUnique(new CFX_ImageStretcher( - &m_Composer, pSource, dest_width, dest_height, bitmap_clip, dib_flags)); + m_Stretcher = pdfium::MakeUnique<CFX_ImageStretcher>( + &m_Composer, pSource, dest_width, dest_height, bitmap_clip, dib_flags); return m_Stretcher->Start(); } @@ -1680,7 +1681,7 @@ FX_BOOL CFX_BitmapStorer::SetInfo(int width, int height, FXDIB_Format src_format, uint32_t* pSrcPalette) { - m_pBitmap = WrapUnique(new CFX_DIBitmap); + m_pBitmap = pdfium::MakeUnique<CFX_DIBitmap>(); if (!m_pBitmap->Create(width, height, src_format)) { m_pBitmap.reset(); return FALSE; diff --git a/core/fxge/dib/fx_dib_transform.cpp b/core/fxge/dib/fx_dib_transform.cpp index a559fee55d..559c6e2a38 100644 --- a/core/fxge/dib/fx_dib_transform.cpp +++ b/core/fxge/dib/fx_dib_transform.cpp @@ -7,6 +7,7 @@ #include "core/fxge/dib/dib_int.h" #include "core/fxge/fx_dib.h" +#include "third_party/base/ptr_util.h" namespace { @@ -363,8 +364,8 @@ FX_BOOL CFX_ImageTransformer::Start() { result_clip.Offset(-result_rect.left, -result_rect.top); result_clip = FXDIB_SwapClipBox(result_clip, dest_width, dest_height, m_pMatrix->c > 0, m_pMatrix->b < 0); - m_Stretcher = WrapUnique(new CFX_ImageStretcher( - &m_Storer, m_pSrc, dest_height, dest_width, result_clip, m_Flags)); + m_Stretcher = pdfium::MakeUnique<CFX_ImageStretcher>( + &m_Storer, m_pSrc, dest_height, dest_width, result_clip, m_Flags); m_Stretcher->Start(); m_Status = 1; return TRUE; @@ -376,8 +377,8 @@ FX_BOOL CFX_ImageTransformer::Start() { int dest_height = m_pMatrix->d > 0 ? (int)-FXSYS_ceil(m_pMatrix->d) : (int)-FXSYS_floor(m_pMatrix->d); result_clip.Offset(-result_rect.left, -result_rect.top); - m_Stretcher = WrapUnique(new CFX_ImageStretcher( - &m_Storer, m_pSrc, dest_width, dest_height, result_clip, m_Flags)); + m_Stretcher = pdfium::MakeUnique<CFX_ImageStretcher>( + &m_Storer, m_pSrc, dest_width, dest_height, result_clip, m_Flags); m_Stretcher->Start(); m_Status = 2; return TRUE; @@ -395,9 +396,8 @@ FX_BOOL CFX_ImageTransformer::Start() { clip_rect_f.Transform(&m_dest2stretch); m_StretchClip = clip_rect_f.GetOuterRect(); m_StretchClip.Intersect(0, 0, stretch_width, stretch_height); - m_Stretcher = WrapUnique(new CFX_ImageStretcher(&m_Storer, m_pSrc, - stretch_width, stretch_height, - m_StretchClip, m_Flags)); + m_Stretcher = pdfium::MakeUnique<CFX_ImageStretcher>( + &m_Storer, m_pSrc, stretch_width, stretch_height, m_StretchClip, m_Flags); m_Stretcher->Start(); m_Status = 3; return TRUE; diff --git a/core/fxge/ge/cfx_font.cpp b/core/fxge/ge/cfx_font.cpp index 737d7c450b..e957b219f4 100644 --- a/core/fxge/ge/cfx_font.cpp +++ b/core/fxge/ge/cfx_font.cpp @@ -15,6 +15,7 @@ #include "core/fxge/cfx_substfont.h" #include "core/fxge/fx_freetype.h" #include "core/fxge/ge/fx_text_int.h" +#include "third_party/base/ptr_util.h" #define EM_ADJUST(em, a) (em == 0 ? (a) : (a)*1000 / em) @@ -244,7 +245,7 @@ FX_BOOL CFX_Font::LoadClone(const CFX_Font* pFont) { m_bShallowCopy = true; if (pFont->m_pSubstFont) { - m_pSubstFont = WrapUnique(new CFX_SubstFont); + m_pSubstFont = pdfium::MakeUnique<CFX_SubstFont>(); m_pSubstFont->m_Charset = pFont->m_pSubstFont->m_Charset; m_pSubstFont->m_SubstFlags = pFont->m_pSubstFont->m_SubstFlags; m_pSubstFont->m_Weight = pFont->m_pSubstFont->m_Weight; @@ -319,7 +320,7 @@ void CFX_Font::LoadSubst(const CFX_ByteString& face_name, bool bVertical) { m_bEmbedded = false; m_bVertical = bVertical; - m_pSubstFont = WrapUnique(new CFX_SubstFont); + m_pSubstFont = pdfium::MakeUnique<CFX_SubstFont>(); m_Face = CFX_GEModule::Get()->GetFontMgr()->FindSubstFont( face_name, bTrueType, flags, weight, italic_angle, CharsetCP, m_pSubstFont.get()); diff --git a/core/fxge/ge/cfx_fontmgr.cpp b/core/fxge/ge/cfx_fontmgr.cpp index 54000e6b5d..95a2b662ed 100644 --- a/core/fxge/ge/cfx_fontmgr.cpp +++ b/core/fxge/ge/cfx_fontmgr.cpp @@ -12,6 +12,7 @@ #include "core/fxge/fx_font.h" #include "core/fxge/ge/cttfontdesc.h" #include "core/fxge/ifx_systemfontinfo.h" +#include "third_party/base/ptr_util.h" namespace { @@ -81,7 +82,7 @@ int GetTTCIndex(const uint8_t* pFontData, CFX_FontMgr::CFX_FontMgr() : m_FTLibrary(nullptr), m_FTLibrarySupportsHinting(false) { - m_pBuiltinMapper = WrapUnique(new CFX_FontMapper(this)); + m_pBuiltinMapper = pdfium::MakeUnique<CFX_FontMapper>(this); } CFX_FontMgr::~CFX_FontMgr() { diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp index 6a492dd074..928b56fa61 100644 --- a/core/fxge/skia/fx_skia_device.cpp +++ b/core/fxge/skia/fx_skia_device.cpp @@ -20,7 +20,7 @@ #include "core/fxge/cfx_pathdata.h" #include "core/fxge/cfx_renderdevice.h" #include "core/fxge/skia/fx_skia_device.h" - +#include "third_party/base/ptr_util.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkColorFilter.h" #include "third_party/skia/include/core/SkColorPriv.h" @@ -1586,7 +1586,7 @@ void CFX_FxgeDevice::Clear(uint32_t color) { SkPictureRecorder* CFX_FxgeDevice::CreateRecorder(int size_x, int size_y) { CFX_SkiaDeviceDriver* skDriver = new CFX_SkiaDeviceDriver(size_x, size_y); - SetDeviceDriver(WrapUnique(skDriver)); + SetDeviceDriver(pdfium::WrapUnique(skDriver)); return skDriver->GetRecorder(); } @@ -1597,15 +1597,15 @@ bool CFX_FxgeDevice::Attach(CFX_DIBitmap* pBitmap, if (!pBitmap) return false; SetBitmap(pBitmap); - SetDeviceDriver(WrapUnique(new CFX_SkiaDeviceDriver( - pBitmap, bRgbByteOrder, pOriDevice, bGroupKnockout))); + SetDeviceDriver(pdfium::MakeUnique<CFX_SkiaDeviceDriver>( + pBitmap, bRgbByteOrder, pOriDevice, bGroupKnockout)); return true; } bool CFX_FxgeDevice::AttachRecorder(SkPictureRecorder* recorder) { if (!recorder) return false; - SetDeviceDriver(WrapUnique(new CFX_SkiaDeviceDriver(recorder))); + SetDeviceDriver(pdfium::MakeUnique<CFX_SkiaDeviceDriver>(recorder)); return true; } @@ -1620,8 +1620,8 @@ bool CFX_FxgeDevice::Create(int width, return false; } SetBitmap(pBitmap); - SetDeviceDriver( - WrapUnique(new CFX_SkiaDeviceDriver(pBitmap, FALSE, pOriDevice, FALSE))); + SetDeviceDriver(pdfium::MakeUnique<CFX_SkiaDeviceDriver>(pBitmap, FALSE, + pOriDevice, FALSE)); return true; } diff --git a/core/fxge/win32/fx_win32_device.cpp b/core/fxge/win32/fx_win32_device.cpp index f0eb2dbce2..bc6817da63 100644 --- a/core/fxge/win32/fx_win32_device.cpp +++ b/core/fxge/win32/fx_win32_device.cpp @@ -27,6 +27,7 @@ #include "core/fxge/win32/cfx_windowsdib.h" #include "core/fxge/win32/dwrite_int.h" #include "core/fxge/win32/win32_int.h" +#include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" #ifndef _SKIA_SUPPORT_ @@ -1369,7 +1370,7 @@ FX_BOOL CGdiDisplayDriver::StartDIBits(const CFX_DIBSource* pBitmap, } CFX_WindowsDevice::CFX_WindowsDevice(HDC hDC) { - SetDeviceDriver(WrapUnique(CreateDriver(hDC))); + SetDeviceDriver(pdfium::WrapUnique(CreateDriver(hDC))); } CFX_WindowsDevice::~CFX_WindowsDevice() {} diff --git a/fpdfsdk/cpdfsdk_document.cpp b/fpdfsdk/cpdfsdk_document.cpp index 66851c0ebb..6179ef88d4 100644 --- a/fpdfsdk/cpdfsdk_document.cpp +++ b/fpdfsdk/cpdfsdk_document.cpp @@ -20,6 +20,7 @@ #include "fpdfsdk/cpdfsdk_pageview.h" #include "fpdfsdk/cpdfsdk_widget.h" #include "fpdfsdk/fsdk_actionhandler.h" +#include "third_party/base/ptr_util.h" // static CPDFSDK_Document* CPDFSDK_Document::FromFPDFFormHandle( @@ -162,7 +163,7 @@ UnderlyingPageType* CPDFSDK_Document::GetPage(int nIndex) { CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm() { if (!m_pInterForm) - m_pInterForm = WrapUnique(new CPDFSDK_InterForm(this)); + m_pInterForm = pdfium::MakeUnique<CPDFSDK_InterForm>(this); return m_pInterForm.get(); } diff --git a/fpdfsdk/cpdfsdk_environment.cpp b/fpdfsdk/cpdfsdk_environment.cpp index 6ea95ad3f5..df0ba06167 100644 --- a/fpdfsdk/cpdfsdk_environment.cpp +++ b/fpdfsdk/cpdfsdk_environment.cpp @@ -13,6 +13,7 @@ #include "fpdfsdk/formfiller/cffl_interactiveformfiller.h" #include "fpdfsdk/fsdk_actionhandler.h" #include "fpdfsdk/javascript/ijs_runtime.h" +#include "third_party/base/ptr_util.h" #ifdef PDF_ENABLE_XFA #include "fpdfsdk/fpdfxfa/fpdfxfa_app.h" @@ -201,19 +202,19 @@ IJS_Runtime* CPDFSDK_Environment::GetJSRuntime() { CPDFSDK_AnnotHandlerMgr* CPDFSDK_Environment::GetAnnotHandlerMgr() { if (!m_pAnnotHandlerMgr) - m_pAnnotHandlerMgr = WrapUnique(new CPDFSDK_AnnotHandlerMgr(this)); + m_pAnnotHandlerMgr = pdfium::MakeUnique<CPDFSDK_AnnotHandlerMgr>(this); return m_pAnnotHandlerMgr.get(); } CPDFSDK_ActionHandler* CPDFSDK_Environment::GetActionHander() { if (!m_pActionHandler) - m_pActionHandler = WrapUnique(new CPDFSDK_ActionHandler()); + m_pActionHandler = pdfium::MakeUnique<CPDFSDK_ActionHandler>(); return m_pActionHandler.get(); } CFFL_InteractiveFormFiller* CPDFSDK_Environment::GetInteractiveFormFiller() { if (!m_pFormFiller) - m_pFormFiller = WrapUnique(new CFFL_InteractiveFormFiller(this)); + m_pFormFiller = pdfium::MakeUnique<CFFL_InteractiveFormFiller>(this); return m_pFormFiller.get(); } diff --git a/fpdfsdk/cpdfsdk_pageview.cpp b/fpdfsdk/cpdfsdk_pageview.cpp index 2e7e6c0ad6..f877d25da5 100644 --- a/fpdfsdk/cpdfsdk_pageview.cpp +++ b/fpdfsdk/cpdfsdk_pageview.cpp @@ -18,6 +18,7 @@ #include "fpdfsdk/cpdfsdk_annotiterator.h" #include "fpdfsdk/cpdfsdk_environment.h" #include "fpdfsdk/cpdfsdk_interform.h" +#include "third_party/base/ptr_util.h" #ifdef PDF_ENABLE_XFA #include "fpdfsdk/fpdfxfa/fpdfxfa_page.h" @@ -495,7 +496,7 @@ void CPDFSDK_PageView::LoadFXAnnots() { bool bUpdateAP = CPDF_InterForm::IsUpdateAPEnabled(); // Disable the default AP construction. CPDF_InterForm::SetUpdateAP(false); - m_pAnnotList = WrapUnique(new CPDF_AnnotList(pPage)); + m_pAnnotList = pdfium::MakeUnique<CPDF_AnnotList>(pPage); CPDF_InterForm::SetUpdateAP(bUpdateAP); const size_t nCount = m_pAnnotList->Count(); diff --git a/fpdfsdk/formfiller/cffl_listbox.cpp b/fpdfsdk/formfiller/cffl_listbox.cpp index 664c02dc36..ab437d401e 100644 --- a/fpdfsdk/formfiller/cffl_listbox.cpp +++ b/fpdfsdk/formfiller/cffl_listbox.cpp @@ -13,6 +13,7 @@ #include "fpdfsdk/formfiller/cffl_interactiveformfiller.h" #include "fpdfsdk/fsdk_common.h" #include "fpdfsdk/pdfwindow/PWL_ListBox.h" +#include "third_party/base/ptr_util.h" #define FFL_DEFAULTLISTBOXFONTSIZE 12.0f @@ -37,7 +38,7 @@ PWL_CREATEPARAM CFFL_ListBox::GetCreateParam() { if (!m_pFontMap) { m_pFontMap = - WrapUnique(new CBA_FontMap(m_pWidget, m_pEnv->GetSysHandler())); + pdfium::MakeUnique<CBA_FontMap>(m_pWidget, m_pEnv->GetSysHandler()); } cp.pFontMap = m_pFontMap.get(); diff --git a/fpdfsdk/formfiller/cffl_textfield.cpp b/fpdfsdk/formfiller/cffl_textfield.cpp index 7e2cce1d99..ffb3785c36 100644 --- a/fpdfsdk/formfiller/cffl_textfield.cpp +++ b/fpdfsdk/formfiller/cffl_textfield.cpp @@ -10,6 +10,7 @@ #include "fpdfsdk/cpdfsdk_widget.h" #include "fpdfsdk/formfiller/cba_fontmap.h" #include "fpdfsdk/fsdk_common.h" +#include "third_party/base/ptr_util.h" CFFL_TextField::CFFL_TextField(CPDFSDK_Environment* pApp, CPDFSDK_Annot* pAnnot) : CFFL_FormFiller(pApp, pAnnot) {} @@ -72,7 +73,7 @@ PWL_CREATEPARAM CFFL_TextField::GetCreateParam() { if (!m_pFontMap) { m_pFontMap = - WrapUnique(new CBA_FontMap(m_pWidget, m_pEnv->GetSysHandler())); + pdfium::MakeUnique<CBA_FontMap>(m_pWidget, m_pEnv->GetSysHandler()); } cp.pFontMap = m_pFontMap.get(); cp.pFocusHandler = this; diff --git a/fpdfsdk/fpdf_dataavail.cpp b/fpdfsdk/fpdf_dataavail.cpp index cc8376ed2c..f38f38eaa9 100644 --- a/fpdfsdk/fpdf_dataavail.cpp +++ b/fpdfsdk/fpdf_dataavail.cpp @@ -13,6 +13,7 @@ #include "core/fpdfapi/fpdf_parser/cpdf_document.h" #include "fpdfsdk/fsdk_define.h" #include "public/fpdf_formfill.h" +#include "third_party/base/ptr_util.h" // These checks are here because core/ and public/ cannot depend on each other. static_assert(CPDF_DataAvail::DataError == PDF_DATA_ERROR, @@ -115,8 +116,8 @@ DLLEXPORT FPDF_AVAIL STDCALL FPDFAvail_Create(FX_FILEAVAIL* file_avail, CFPDF_DataAvail* pAvail = new CFPDF_DataAvail; pAvail->m_FileAvail.Set(file_avail); pAvail->m_FileRead.Set(file); - pAvail->m_pDataAvail = WrapUnique( - new CPDF_DataAvail(&pAvail->m_FileAvail, &pAvail->m_FileRead, TRUE)); + pAvail->m_pDataAvail = pdfium::MakeUnique<CPDF_DataAvail>( + &pAvail->m_FileAvail, &pAvail->m_FileRead, TRUE); return pAvail; } diff --git a/fpdfsdk/fpdf_ext.cpp b/fpdfsdk/fpdf_ext.cpp index d9889ef150..66247545d9 100644 --- a/fpdfsdk/fpdf_ext.cpp +++ b/fpdfsdk/fpdf_ext.cpp @@ -18,6 +18,7 @@ #include "core/fxcrt/fx_memory.h" #include "core/fxcrt/fx_xml.h" #include "fpdfsdk/fsdk_define.h" +#include "third_party/base/ptr_util.h" #ifdef PDF_ENABLE_XFA #include "fpdfsdk/fpdfxfa/fpdfxfa_doc.h" @@ -41,7 +42,7 @@ FSDK_SetUnSpObjProcessHandler(UNSUPPORT_INFO* unsp_info) { return FALSE; CPDF_ModuleMgr::Get()->SetUnsupportInfoAdapter( - WrapUnique(new CFSDK_UnsupportInfo_Adapter(unsp_info))); + pdfium::MakeUnique<CFSDK_UnsupportInfo_Adapter>(unsp_info)); return TRUE; } diff --git a/fpdfsdk/fpdf_progressive.cpp b/fpdfsdk/fpdf_progressive.cpp index 5a51a322bb..8c08b8f310 100644 --- a/fpdfsdk/fpdf_progressive.cpp +++ b/fpdfsdk/fpdf_progressive.cpp @@ -15,6 +15,7 @@ #include "fpdfsdk/fsdk_define.h" #include "fpdfsdk/fsdk_pauseadapter.h" #include "public/fpdfview.h" +#include "third_party/base/ptr_util.h" // These checks are here because core/ and public/ cannot depend on each other. static_assert(CPDF_ProgressiveRenderer::Ready == FPDF_RENDER_READER, @@ -44,7 +45,7 @@ DLLEXPORT int STDCALL FPDF_RenderPageBitmap_Start(FPDF_BITMAP bitmap, return FPDF_RENDER_FAILED; CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext; - pPage->SetRenderContext(WrapUnique(pContext)); + pPage->SetRenderContext(pdfium::WrapUnique(pContext)); CFX_FxgeDevice* pDevice = new CFX_FxgeDevice; pContext->m_pDevice.reset(pDevice); CFX_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap); diff --git a/fpdfsdk/fpdfdoc_unittest.cpp b/fpdfsdk/fpdfdoc_unittest.cpp index 70d136b890..e559f60125 100644 --- a/fpdfsdk/fpdfdoc_unittest.cpp +++ b/fpdfsdk/fpdfdoc_unittest.cpp @@ -16,6 +16,7 @@ #include "core/fpdfapi/fpdf_parser/cpdf_string.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/test_support.h" +#include "third_party/base/ptr_util.h" #ifdef PDF_ENABLE_XFA #include "fpdfsdk/fpdfxfa/fpdfxfa_app.h" @@ -34,7 +35,7 @@ class CPDF_TestDocument : public CPDF_Document { class CPDF_TestXFADocument : public CPDFXFA_Document { public: CPDF_TestXFADocument() - : CPDFXFA_Document(WrapUnique(new CPDF_TestDocument()), + : CPDFXFA_Document(pdfium::MakeUnique<CPDF_TestDocument>(), CPDFXFA_App::GetInstance()) {} void SetRoot(CPDF_Dictionary* root) { @@ -61,7 +62,7 @@ class PDFDocTest : public testing::Test { CPDF_ModuleMgr* module_mgr = CPDF_ModuleMgr::Get(); module_mgr->InitPageModule(); - m_pDoc = WrapUnique(new CPDF_TestPdfDocument()); + m_pDoc = pdfium::MakeUnique<CPDF_TestPdfDocument>(); m_pIndirectObjs = m_pDoc->GetHolder(); // Setup the root directory. m_pRootObj.reset(new CPDF_Dictionary()); diff --git a/fpdfsdk/fpdfeditimg.cpp b/fpdfsdk/fpdfeditimg.cpp index 64908408a9..cd4d5525f4 100644 --- a/fpdfsdk/fpdfeditimg.cpp +++ b/fpdfsdk/fpdfeditimg.cpp @@ -11,6 +11,7 @@ #include "core/fpdfapi/fpdf_page/cpdf_imageobject.h" #include "core/fpdfapi/fpdf_page/cpdf_pageobject.h" #include "fpdfsdk/fsdk_define.h" +#include "third_party/base/ptr_util.h" DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document) { @@ -19,7 +20,7 @@ FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document) { return nullptr; CPDF_ImageObject* pImageObj = new CPDF_ImageObject; - pImageObj->SetOwnedImage(WrapUnique(new CPDF_Image(pDoc))); + pImageObj->SetOwnedImage(pdfium::MakeUnique<CPDF_Image>(pDoc)); return pImageObj; } diff --git a/fpdfsdk/fpdfformfill.cpp b/fpdfsdk/fpdfformfill.cpp index 8839a61afd..a9a83b3541 100644 --- a/fpdfsdk/fpdfformfill.cpp +++ b/fpdfsdk/fpdfformfill.cpp @@ -24,6 +24,7 @@ #include "fpdfsdk/fsdk_actionhandler.h" #include "fpdfsdk/fsdk_define.h" #include "public/fpdfview.h" +#include "third_party/base/ptr_util.h" #include "third_party/base/stl_util.h" #ifdef PDF_ENABLE_XFA @@ -254,7 +255,7 @@ FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document, #ifdef PDF_ENABLE_XFA // Ownership of the SDKDocument is passed to the CPDFXFA_Document. - pDocument->SetSDKDoc(WrapUnique(pEnv->GetSDKDocument())); + pDocument->SetSDKDoc(pdfium::WrapUnique(pEnv->GetSDKDocument())); CPDFXFA_App::GetInstance()->AddFormFillEnv(pEnv); #endif // PDF_ENABLE_XFA diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp index e48c2e9eb1..552ec2a8c7 100644 --- a/fpdfsdk/fpdfview.cpp +++ b/fpdfsdk/fpdfview.cpp @@ -33,6 +33,7 @@ #include "public/fpdf_ext.h" #include "public/fpdf_progressive.h" #include "third_party/base/numerics/safe_conversions_impl.h" +#include "third_party/base/ptr_util.h" #ifdef PDF_ENABLE_XFA #include "fpdfsdk/fpdfxfa/fpdfxfa_app.h" @@ -69,7 +70,7 @@ CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) { FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc) { #ifdef PDF_ENABLE_XFA return doc ? FPDFDocumentFromUnderlying(new CPDFXFA_Document( - WrapUnique(doc), CPDFXFA_App::GetInstance())) + pdfium::WrapUnique(doc), CPDFXFA_App::GetInstance())) : nullptr; #else // PDF_ENABLE_XFA return FPDFDocumentFromUnderlying(doc); @@ -574,20 +575,20 @@ DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, return; CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext; - pPage->SetRenderContext(WrapUnique(pContext)); + pPage->SetRenderContext(pdfium::WrapUnique(pContext)); std::unique_ptr<CFX_DIBitmap> pBitmap; const bool bNewBitmap = pPage->BackgroundAlphaNeeded() || pPage->HasImageMask(); if (bNewBitmap) { - pBitmap = WrapUnique(new CFX_DIBitmap); + pBitmap = pdfium::MakeUnique<CFX_DIBitmap>(); pBitmap->Create(size_x, size_y, FXDIB_Argb); pBitmap->Clear(0x00ffffff); CFX_FxgeDevice* pDevice = new CFX_FxgeDevice; - pContext->m_pDevice = WrapUnique(pDevice); + pContext->m_pDevice = pdfium::WrapUnique(pDevice); pDevice->Attach(pBitmap.get(), false, nullptr, false); } else { - pContext->m_pDevice = WrapUnique(new CFX_WindowsDevice(dc)); + pContext->m_pDevice = pdfium::MakeUnique<CFX_WindowsDevice>(dc); } FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, @@ -596,7 +597,7 @@ DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, if (bNewBitmap) { CFX_WindowsDevice WinDC(dc); if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) { - std::unique_ptr<CFX_DIBitmap> pDst = WrapUnique(new CFX_DIBitmap); + std::unique_ptr<CFX_DIBitmap> pDst = pdfium::MakeUnique<CFX_DIBitmap>(); int pitch = pBitmap->GetPitch(); pDst->Create(size_x, size_y, FXDIB_Rgb32); FXSYS_memset(pDst->GetBuffer(), -1, pitch * size_y); @@ -628,7 +629,7 @@ DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap, return; CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext; - pPage->SetRenderContext(WrapUnique(pContext)); + pPage->SetRenderContext(pdfium::WrapUnique(pContext)); CFX_FxgeDevice* pDevice = new CFX_FxgeDevice; pContext->m_pDevice.reset(pDevice); CFX_DIBitmap* pBitmap = CFXBitmapFromFPDFBitmap(bitmap); @@ -649,7 +650,7 @@ DLLEXPORT FPDF_RECORDER STDCALL FPDF_RenderPageSkp(FPDF_PAGE page, return nullptr; CPDF_PageRenderContext* pContext = new CPDF_PageRenderContext; - pPage->SetRenderContext(WrapUnique(pContext)); + pPage->SetRenderContext(pdfium::WrapUnique(pContext)); CFX_FxgeDevice* skDevice = new CFX_FxgeDevice; FPDF_RECORDER recorder = skDevice->CreateRecorder(size_x, size_y); pContext->m_pDevice.reset(skDevice); @@ -850,7 +851,7 @@ void FPDF_RenderPage_Retail(CPDF_PageRenderContext* pContext, return; if (!pContext->m_pOptions) - pContext->m_pOptions = WrapUnique(new CPDF_RenderOptions); + pContext->m_pOptions = pdfium::MakeUnique<CPDF_RenderOptions>(); if (flags & FPDF_LCD_TEXT) pContext->m_pOptions->m_Flags |= RENDER_CLEARTYPE; @@ -889,19 +890,19 @@ void FPDF_RenderPage_Retail(CPDF_PageRenderContext* pContext, pContext->m_pDevice->SetClip_Rect( FX_RECT(start_x, start_y, start_x + size_x, start_y + size_y)); - pContext->m_pContext = WrapUnique(new CPDF_RenderContext(pPage)); + pContext->m_pContext = pdfium::MakeUnique<CPDF_RenderContext>(pPage); pContext->m_pContext->AppendLayer(pPage, &matrix); if (flags & FPDF_ANNOT) { - pContext->m_pAnnots = WrapUnique(new CPDF_AnnotList(pPage)); + pContext->m_pAnnots = pdfium::MakeUnique<CPDF_AnnotList>(pPage); FX_BOOL bPrinting = pContext->m_pDevice->GetDeviceClass() != FXDC_DISPLAY; pContext->m_pAnnots->DisplayAnnots(pPage, pContext->m_pContext.get(), bPrinting, &matrix, FALSE, nullptr); } - pContext->m_pRenderer = WrapUnique(new CPDF_ProgressiveRenderer( + pContext->m_pRenderer = pdfium::MakeUnique<CPDF_ProgressiveRenderer>( pContext->m_pContext.get(), pContext->m_pDevice.get(), - pContext->m_pOptions.get())); + pContext->m_pOptions.get()); pContext->m_pRenderer->Start(pause); if (bNeedToRestore) pContext->m_pDevice->RestoreState(false); diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_app.cpp b/fpdfsdk/fpdfxfa/fpdfxfa_app.cpp index 88c31ef006..4edfcf0676 100644 --- a/fpdfsdk/fpdfxfa/fpdfxfa_app.cpp +++ b/fpdfsdk/fpdfxfa/fpdfxfa_app.cpp @@ -11,6 +11,7 @@ #include "fpdfsdk/cpdfsdk_environment.h" #include "fpdfsdk/fpdfxfa/fpdfxfa_util.h" #include "fpdfsdk/fsdk_define.h" +#include "third_party/base/ptr_util.h" #include "xfa/fxbarcode/BC_Library.h" #include "xfa/fxfa/xfa_ffapp.h" #include "xfa/fxfa/xfa_fontmgr.h" @@ -56,7 +57,7 @@ FX_BOOL CPDFXFA_App::Initialize(v8::Isolate* pIsolate) { if (!m_pIsolate) return FALSE; - m_pXFAApp = WrapUnique(new CXFA_FFApp(this)); + m_pXFAApp = pdfium::MakeUnique<CXFA_FFApp>(this); m_pXFAApp->SetDefaultFontMgr( std::unique_ptr<CXFA_DefFontMgr>(new CXFA_DefFontMgr)); diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_page.cpp b/fpdfsdk/fpdfxfa/fpdfxfa_page.cpp index fdbd2d08e4..b3bc20bad8 100644 --- a/fpdfsdk/fpdfxfa/fpdfxfa_page.cpp +++ b/fpdfsdk/fpdfxfa/fpdfxfa_page.cpp @@ -12,6 +12,7 @@ #include "fpdfsdk/fpdfxfa/fpdfxfa_util.h" #include "fpdfsdk/fsdk_define.h" #include "public/fpdf_formfill.h" +#include "third_party/base/ptr_util.h" #include "xfa/fxfa/xfa_ffdocview.h" #include "xfa/fxfa/xfa_ffpageview.h" @@ -39,7 +40,7 @@ FX_BOOL CPDFXFA_Page::LoadPDFPage() { return FALSE; if (!m_pPDFPage || m_pPDFPage->m_pFormDict != pDict) { - m_pPDFPage = WrapUnique(new CPDF_Page(pPDFDoc, pDict, true)); + m_pPDFPage = pdfium::MakeUnique<CPDF_Page>(pPDFDoc, pDict, true); m_pPDFPage->ParseContent(); } return TRUE; @@ -88,7 +89,7 @@ FX_BOOL CPDFXFA_Page::LoadPDFPage(CPDF_Dictionary* pageDict) { return FALSE; m_pPDFPage = - WrapUnique(new CPDF_Page(m_pDocument->GetPDFDoc(), pageDict, true)); + pdfium::MakeUnique<CPDF_Page>(m_pDocument->GetPDFDoc(), pageDict, true); m_pPDFPage->ParseContent(); return TRUE; } diff --git a/fpdfsdk/fxedit/fxet_edit.cpp b/fpdfsdk/fxedit/fxet_edit.cpp index ef3f7415bd..9f733acd70 100644 --- a/fpdfsdk/fxedit/fxet_edit.cpp +++ b/fpdfsdk/fxedit/fxet_edit.cpp @@ -28,6 +28,7 @@ #include "fpdfsdk/fxedit/fx_edit.h" #include "fpdfsdk/pdfwindow/PWL_Edit.h" #include "fpdfsdk/pdfwindow/PWL_EditCtrl.h" +#include "third_party/base/ptr_util.h" namespace { @@ -1026,7 +1027,7 @@ void CFX_Edit::Initialize() { } void CFX_Edit::SetFontMap(IPVT_FontMap* pFontMap) { - m_pVTProvider = WrapUnique(new CFX_Edit_Provider(pFontMap)); + m_pVTProvider = pdfium::MakeUnique<CFX_Edit_Provider>(pFontMap); m_pVT->SetProvider(m_pVTProvider.get()); } @@ -1039,8 +1040,10 @@ void CFX_Edit::SetOprNotify(CPWL_Edit* pOprNotify) { } CFX_Edit_Iterator* CFX_Edit::GetIterator() { - if (!m_pIterator) - m_pIterator = WrapUnique(new CFX_Edit_Iterator(this, m_pVT->GetIterator())); + if (!m_pIterator) { + m_pIterator = + pdfium::MakeUnique<CFX_Edit_Iterator>(this, m_pVT->GetIterator()); + } return m_pIterator.get(); } diff --git a/fpdfsdk/javascript/JS_Runtime_Stub.cpp b/fpdfsdk/javascript/JS_Runtime_Stub.cpp index 3b316aaf69..8d8ac33474 100644 --- a/fpdfsdk/javascript/JS_Runtime_Stub.cpp +++ b/fpdfsdk/javascript/JS_Runtime_Stub.cpp @@ -8,6 +8,7 @@ #include "fpdfsdk/javascript/ijs_context.h" #include "fpdfsdk/javascript/ijs_runtime.h" +#include "third_party/base/ptr_util.h" class CJS_ContextStub final : public IJS_Context { public: @@ -124,7 +125,7 @@ class CJS_RuntimeStub final : public IJS_Runtime { IJS_Context* NewContext() override { if (!m_pContext) - m_pContext = WrapUnique(new CJS_ContextStub()); + m_pContext = pdfium::MakeUnique<CJS_ContextStub>(); return GetCurrentContext(); } diff --git a/fpdfsdk/pdfwindow/PWL_FontMap.cpp b/fpdfsdk/pdfwindow/PWL_FontMap.cpp index 57feb27dcd..440efe5a06 100644 --- a/fpdfsdk/pdfwindow/PWL_FontMap.cpp +++ b/fpdfsdk/pdfwindow/PWL_FontMap.cpp @@ -13,6 +13,7 @@ #include "core/fpdfapi/fpdf_parser/cpdf_parser.h" #include "core/fpdfdoc/ipvt_fontmap.h" #include "fpdfsdk/pdfwindow/PWL_Wnd.h" +#include "third_party/base/ptr_util.h" namespace { @@ -47,7 +48,8 @@ CPWL_FontMap::~CPWL_FontMap() { CPDF_Document* CPWL_FontMap::GetDocument() { if (!m_pPDFDoc) { if (CPDF_ModuleMgr::Get()) { - m_pPDFDoc = WrapUnique(new CPDF_Document(std::unique_ptr<CPDF_Parser>())); + m_pPDFDoc = + pdfium::MakeUnique<CPDF_Document>(std::unique_ptr<CPDF_Parser>()); m_pPDFDoc->CreateNewDoc(); } } diff --git a/fpdfsdk/pdfwindow/PWL_ListBox.cpp b/fpdfsdk/pdfwindow/PWL_ListBox.cpp index 1af2682570..8739c3b515 100644 --- a/fpdfsdk/pdfwindow/PWL_ListBox.cpp +++ b/fpdfsdk/pdfwindow/PWL_ListBox.cpp @@ -14,6 +14,7 @@ #include "fpdfsdk/pdfwindow/PWL_Utils.h" #include "fpdfsdk/pdfwindow/PWL_Wnd.h" #include "public/fpdf_fwlevent.h" +#include "third_party/base/ptr_util.h" CPWL_List_Notify::CPWL_List_Notify(CPWL_ListBox* pList) : m_pList(pList) { ASSERT(m_pList); @@ -76,7 +77,7 @@ CFX_ByteString CPWL_ListBox::GetClassName() const { void CPWL_ListBox::OnCreated() { m_pList->SetFontMap(GetFontMap()); - m_pListNotify = WrapUnique(new CPWL_List_Notify(this)); + m_pListNotify = pdfium::MakeUnique<CPWL_List_Notify>(this); m_pList->SetNotify(m_pListNotify.get()); SetHoverSel(HasFlag(PLBS_HOVERSEL)); diff --git a/fpdfsdk/pdfwindow/PWL_Wnd.cpp b/fpdfsdk/pdfwindow/PWL_Wnd.cpp index 207157db7e..729b27ca5d 100644 --- a/fpdfsdk/pdfwindow/PWL_Wnd.cpp +++ b/fpdfsdk/pdfwindow/PWL_Wnd.cpp @@ -9,6 +9,7 @@ #include "fpdfsdk/pdfwindow/PWL_ScrollBar.h" #include "fpdfsdk/pdfwindow/PWL_Utils.h" #include "fpdfsdk/pdfwindow/PWL_Wnd.h" +#include "third_party/base/ptr_util.h" static std::map<int32_t, CPWL_Timer*>& GetPWLTimeMap() { // Leak the object at shutdown. @@ -86,10 +87,9 @@ CPWL_TimerHandler::~CPWL_TimerHandler() {} void CPWL_TimerHandler::BeginTimer(int32_t nElapse) { if (!m_pTimer) - m_pTimer = WrapUnique(new CPWL_Timer(this, GetSystemHandler())); + m_pTimer = pdfium::MakeUnique<CPWL_Timer>(this, GetSystemHandler()); - if (m_pTimer) - m_pTimer->SetPWLTimer(nElapse); + m_pTimer->SetPWLTimer(nElapse); } void CPWL_TimerHandler::EndTimer() { diff --git a/testing/js_embedder_test.cpp b/testing/js_embedder_test.cpp index a8b0d5bfcf..064a961049 100644 --- a/testing/js_embedder_test.cpp +++ b/testing/js_embedder_test.cpp @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "testing/js_embedder_test.h" +#include "third_party/base/ptr_util.h" JSEmbedderTest::JSEmbedderTest() : m_pArrayBufferAllocator(new FXJS_ArrayBufferAllocator), @@ -21,7 +22,7 @@ void JSEmbedderTest::SetUp() { v8::Isolate::Scope isolate_scope(m_pIsolate); v8::HandleScope handle_scope(m_pIsolate); FXJS_PerIsolateData::SetUp(m_pIsolate); - m_Engine = WrapUnique(new CFXJS_Engine(m_pIsolate)); + m_Engine = pdfium::MakeUnique<CFXJS_Engine>(m_pIsolate); m_Engine->InitializeEngine(); } diff --git a/third_party/BUILD.gn b/third_party/BUILD.gn index 958b9cc85e..1fef9bb345 100644 --- a/third_party/BUILD.gn +++ b/third_party/BUILD.gn @@ -480,6 +480,7 @@ source_set("pdfium_base") { "base/numerics/safe_conversions_impl.h", "base/numerics/safe_math.h", "base/numerics/safe_math_impl.h", + "base/ptr_util.h", "base/stl_util.h", ] } diff --git a/third_party/base/ptr_util.h b/third_party/base/ptr_util.h new file mode 100644 index 0000000000..b64261f82d --- /dev/null +++ b/third_party/base/ptr_util.h @@ -0,0 +1,74 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PDFIUM_THIRD_PARTY_BASE_PTR_UTIL_H_ +#define PDFIUM_THIRD_PARTY_BASE_PTR_UTIL_H_ + +#include <memory> +#include <utility> + +namespace pdfium { + +// Helper to transfer ownership of a raw pointer to a std::unique_ptr<T>. +// Note that std::unique_ptr<T> has very different semantics from +// std::unique_ptr<T[]>: do not use this helper for array allocations. +template <typename T> +std::unique_ptr<T> WrapUnique(T* ptr) { + return std::unique_ptr<T>(ptr); +} + +namespace internal { + +template <typename T> +struct MakeUniqueResult { + using Scalar = std::unique_ptr<T>; +}; + +template <typename T> +struct MakeUniqueResult<T[]> { + using Array = std::unique_ptr<T[]>; +}; + +template <typename T, size_t N> +struct MakeUniqueResult<T[N]> { + using Invalid = void; +}; + +} // namespace internal + +// Helper to construct an object wrapped in a std::unique_ptr. This is an +// implementation of C++14's std::MakeUnique that can be used in Chrome. +// +// MakeUnique<T>(args) should be preferred over WrapUnique(new T(args)): bare +// calls to `new` should be treated with scrutiny. +// +// Usage: +// // ptr is a std::unique_ptr<std::string> +// auto ptr = MakeUnique<std::string>("hello world!"); +// +// // arr is a std::unique_ptr<int[]> +// auto arr = MakeUnique<int[]>(5); + +// Overload for non-array types. Arguments are forwarded to T's constructor. +template <typename T, typename... Args> +typename internal::MakeUniqueResult<T>::Scalar MakeUnique(Args&&... args) { + return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); +} + +// Overload for array types of unknown bound, e.g. T[]. The array is allocated +// with `new T[n]()` and value-initialized: note that this is distinct from +// `new T[n]`, which default-initializes. +template <typename T> +typename internal::MakeUniqueResult<T>::Array MakeUnique(size_t size) { + return std::unique_ptr<T>(new typename std::remove_extent<T>::type[size]()); +} + +// Overload to reject array types of known bound, e.g. T[n]. +template <typename T, typename... Args> +typename internal::MakeUniqueResult<T>::Invalid MakeUnique(Args&&... args) = + delete; + +} // namespace pdfium + +#endif // PDFIUM_THIRD_PARTY_BASE_PTR_UTIL_H_ diff --git a/xfa/fde/xml/cfx_saxreader.cpp b/xfa/fde/xml/cfx_saxreader.cpp index bd76e79442..187d14e98b 100644 --- a/xfa/fde/xml/cfx_saxreader.cpp +++ b/xfa/fde/xml/cfx_saxreader.cpp @@ -9,6 +9,7 @@ #include <algorithm> #include <utility> +#include "third_party/base/ptr_util.h" #include "xfa/fxfa/xfa_checksum.h" enum class CFX_SaxMode { @@ -159,7 +160,8 @@ void CFX_SAXReader::Reset() { } void CFX_SAXReader::Push() { - std::unique_ptr<CFX_SAXItem> pNew(WrapUnique(new CFX_SAXItem(++m_dwItemID))); + std::unique_ptr<CFX_SAXItem> pNew = + pdfium::MakeUnique<CFX_SAXItem>(++m_dwItemID); if (!m_Stack.empty()) pNew->m_bSkip = m_Stack.top()->m_bSkip; m_Stack.push(std::move(pNew)); |