summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--BUILD.gn1
-rw-r--r--core/fpdfapi/font/cpdf_type3font.cpp4
-rw-r--r--core/fpdfapi/page/cpdf_streamcontentparser.cpp14
-rw-r--r--core/fpdfapi/parser/cpdf_array_unittest.cpp13
-rw-r--r--core/fpdfapi/parser/cpdf_object_unittest.cpp19
-rw-r--r--core/fpdfapi/render/cpdf_dibsource.cpp14
-rw-r--r--core/fpdfdoc/cpdf_filespec_unittest.cpp12
-rw-r--r--core/fpdfdoc/cpdf_formfield.cpp2
-rw-r--r--core/fxcodec/codec/ccodec_jpxmodule.h8
-rw-r--r--core/fxcodec/codec/cjpx_decoder.h36
-rw-r--r--core/fxcodec/codec/fx_codec_flate.cpp4
-rw-r--r--core/fxcodec/codec/fx_codec_jpx_opj.cpp37
-rw-r--r--core/fxcodec/jbig2/JBig2_Context.cpp38
-rw-r--r--core/fxcodec/jbig2/JBig2_GrdProc.cpp17
-rw-r--r--core/fxcodec/jbig2/JBig2_GrrdProc.cpp9
-rw-r--r--core/fxcodec/jbig2/JBig2_GsidProc.cpp5
-rw-r--r--core/fxcodec/jbig2/JBig2_HtrdProc.cpp8
-rw-r--r--core/fxcodec/jbig2/JBig2_PddProc.cpp9
-rw-r--r--core/fxcodec/jbig2/JBig2_TrdProc.cpp14
-rw-r--r--core/fxcrt/fx_basic_util.cpp9
-rw-r--r--core/fxge/android/fx_android_imp.cpp3
-rw-r--r--core/fxge/ge/cfx_fontcache.cpp3
-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
-rw-r--r--fxbarcode/datamatrix/BC_HighLevelEncoder.cpp13
-rw-r--r--fxbarcode/qrcode/BC_QRCoderEncoder.cpp15
-rw-r--r--fxjs/cfxjse_class.cpp44
-rw-r--r--fxjs/cfxjse_context.cpp3
-rw-r--r--testing/libfuzzer/pdf_codec_jbig2_fuzzer.cc3
-rw-r--r--testing/libfuzzer/pdf_jpx_fuzzer.cc9
-rw-r--r--xfa/fde/cfde_txtedtpage.cpp6
-rw-r--r--xfa/fde/cfde_txtedtparag.cpp4
-rw-r--r--xfa/fgas/crt/ifgas_stream.cpp6
-rw-r--r--xfa/fwl/cfwl_barcode.cpp2
-rw-r--r--xfa/fwl/cfwl_edit.cpp5
-rw-r--r--xfa/fxfa/app/cxfa_textlayout.cpp5
-rw-r--r--xfa/fxfa/app/xfa_fwltheme.cpp24
-rw-r--r--xfa/fxfa/cxfa_ffdoc.cpp2
-rw-r--r--xfa/fxfa/parser/cxfa_scriptcontext.cpp14
-rw-r--r--xfa/fxfa/parser/cxfa_simple_parser.cpp3
-rw-r--r--xfa/fxfa/parser/cxfa_xml_parser.cpp4
51 files changed, 261 insertions, 242 deletions
diff --git a/BUILD.gn b/BUILD.gn
index 53facc858c..c4da7d6da6 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -645,6 +645,7 @@ static_library("fxcodec") {
"core/fxcodec/codec/ccodec_jpegmodule.h",
"core/fxcodec/codec/ccodec_jpxmodule.h",
"core/fxcodec/codec/ccodec_scanlinedecoder.h",
+ "core/fxcodec/codec/cjpx_decoder.h",
"core/fxcodec/codec/codec_int.h",
"core/fxcodec/codec/fx_codec.cpp",
"core/fxcodec/codec/fx_codec_fax.cpp",
diff --git a/core/fpdfapi/font/cpdf_type3font.cpp b/core/fpdfapi/font/cpdf_type3font.cpp
index b9a05a0588..59702aed6a 100644
--- a/core/fpdfapi/font/cpdf_type3font.cpp
+++ b/core/fpdfapi/font/cpdf_type3font.cpp
@@ -105,9 +105,9 @@ CPDF_Type3Char* CPDF_Type3Font::LoadChar(uint32_t charcode) {
if (!pStream)
return nullptr;
- std::unique_ptr<CPDF_Type3Char> pNewChar(new CPDF_Type3Char(new CPDF_Form(
+ auto pNewChar = pdfium::MakeUnique<CPDF_Type3Char>(new CPDF_Form(
m_pDocument, m_pFontResources ? m_pFontResources : m_pPageResources,
- pStream, nullptr)));
+ pStream, nullptr));
// This can trigger recursion into this method. The content of |m_CacheMap|
// can change as a result. Thus after it returns, check the cache again for
diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
index 312996ba11..4c64e13b06 100644
--- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
@@ -262,7 +262,7 @@ CPDF_StreamContentParser::CPDF_StreamContentParser(
m_Level(level),
m_ParamStartPos(0),
m_ParamCount(0),
- m_pCurStates(new CPDF_AllStates),
+ m_pCurStates(pdfium::MakeUnique<CPDF_AllStates>()),
m_pLastTextObject(nullptr),
m_DefFontSize(0),
m_PathStartX(0.0f),
@@ -765,9 +765,9 @@ void CPDF_StreamContentParser::Handle_ExecuteXObject() {
}
void CPDF_StreamContentParser::AddForm(CPDF_Stream* pStream) {
- std::unique_ptr<CPDF_FormObject> pFormObj(new CPDF_FormObject);
- pFormObj->m_pForm.reset(
- new CPDF_Form(m_pDocument, m_pPageResources, pStream, m_pResources));
+ auto pFormObj = pdfium::MakeUnique<CPDF_FormObject>();
+ pFormObj->m_pForm = pdfium::MakeUnique<CPDF_Form>(
+ m_pDocument, m_pPageResources, pStream, m_pResources);
pFormObj->m_FormMatrix = m_pCurStates->m_CTM;
pFormObj->m_FormMatrix.Concat(m_mtContentToUser);
CPDF_AllStates status;
@@ -957,7 +957,7 @@ void CPDF_StreamContentParser::Handle_EndPath() {
}
void CPDF_StreamContentParser::Handle_SaveGraphState() {
- std::unique_ptr<CPDF_AllStates> pStates(new CPDF_AllStates);
+ auto pStates = pdfium::MakeUnique<CPDF_AllStates>();
pStates->Copy(*m_pCurStates);
m_StateStack.push_back(std::move(pStates));
}
@@ -1110,7 +1110,7 @@ void CPDF_StreamContentParser::Handle_ShadeFill() {
if (!pShading->IsShadingObject() || !pShading->Load())
return;
- std::unique_ptr<CPDF_ShadingObject> pObj(new CPDF_ShadingObject);
+ auto pObj = pdfium::MakeUnique<CPDF_ShadingObject>();
pObj->m_pShading = pShading;
SetGraphicStates(pObj.get(), false, false, false);
pObj->m_Matrix = m_pCurStates->m_CTM;
@@ -1248,7 +1248,7 @@ void CPDF_StreamContentParser::AddTextObject(CFX_ByteString* pStrs,
pFont->IsType3Font() ? TextRenderingMode::MODE_FILL
: m_pCurStates->m_TextState.GetTextMode();
{
- std::unique_ptr<CPDF_TextObject> pText(new CPDF_TextObject);
+ auto pText = pdfium::MakeUnique<CPDF_TextObject>();
m_pLastTextObject = pText.get();
SetGraphicStates(m_pLastTextObject, true, true, true);
if (TextRenderingModeIsStrokeMode(text_mode)) {
diff --git a/core/fpdfapi/parser/cpdf_array_unittest.cpp b/core/fpdfapi/parser/cpdf_array_unittest.cpp
index 6d458d83cd..1e92b32716 100644
--- a/core/fpdfapi/parser/cpdf_array_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_array_unittest.cpp
@@ -15,7 +15,7 @@
TEST(cpdf_array, RemoveAt) {
{
int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
- std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
+ auto arr = pdfium::MakeUnique<CPDF_Array>();
for (size_t i = 0; i < FX_ArraySize(elems); ++i)
arr->AddNew<CPDF_Number>(elems[i]);
arr->RemoveAt(3, 3);
@@ -32,7 +32,7 @@ TEST(cpdf_array, RemoveAt) {
{
// When the range is out of bound, RemoveAt has no effect.
int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
- std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
+ auto arr = pdfium::MakeUnique<CPDF_Array>();
for (size_t i = 0; i < FX_ArraySize(elems); ++i)
arr->AddNew<CPDF_Number>(elems[i]);
arr->RemoveAt(8, 5);
@@ -102,14 +102,13 @@ TEST(cpdf_array, Clone) {
static const size_t kNumOfRowElems = 5;
int elems[kNumOfRows][kNumOfRowElems] = {
{1, 2, 3, 4, 5}, {10, 9, 8, 7, 6}, {11, 12, 13, 14, 15}};
- std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
+ auto arr = pdfium::MakeUnique<CPDF_Array>();
// Indirect references to indirect objects.
- std::unique_ptr<CPDF_IndirectObjectHolder> obj_holder(
- new CPDF_IndirectObjectHolder());
+ auto obj_holder = pdfium::MakeUnique<CPDF_IndirectObjectHolder>();
for (size_t i = 0; i < kNumOfRows; ++i) {
auto arr_elem = pdfium::MakeUnique<CPDF_Array>();
for (size_t j = 0; j < kNumOfRowElems; ++j) {
- std::unique_ptr<CPDF_Number> obj(new CPDF_Number(elems[i][j]));
+ auto obj = pdfium::MakeUnique<CPDF_Number>(elems[i][j]);
// Starts object number from 1.
int obj_num = i * kNumOfRowElems + j + 1;
obj_holder->ReplaceIndirectObjectIfHigherGeneration(obj_num,
@@ -168,7 +167,7 @@ TEST(cpdf_array, Clone) {
TEST(cpdf_array, Iterator) {
const int elems[] = {-23, -11, 3, 455, 2345877,
0, 7895330, -12564334, 10000, -100000};
- std::unique_ptr<CPDF_Array> arr(new CPDF_Array);
+ auto arr = pdfium::MakeUnique<CPDF_Array>();
for (size_t i = 0; i < FX_ArraySize(elems); ++i)
arr->InsertNewAt<CPDF_Number>(i, elems[i]);
size_t index = 0;
diff --git a/core/fpdfapi/parser/cpdf_object_unittest.cpp b/core/fpdfapi/parser/cpdf_object_unittest.cpp
index b25d40a029..3b5374b637 100644
--- a/core/fpdfapi/parser/cpdf_object_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_object_unittest.cpp
@@ -484,8 +484,8 @@ TEST(PDFArrayTest, GetTypeAt) {
// String and name array
const char* const vals[] = {"this", "adsde$%^", "\r\t", "\"012",
".", "EYREW", "It is a joke :)"};
- std::unique_ptr<CPDF_Array> string_array(new CPDF_Array);
- std::unique_ptr<CPDF_Array> name_array(new CPDF_Array);
+ auto string_array = pdfium::MakeUnique<CPDF_Array>();
+ auto name_array = pdfium::MakeUnique<CPDF_Array>();
for (size_t i = 0; i < FX_ArraySize(vals); ++i) {
string_array->InsertNewAt<CPDF_String>(i, vals[i], false);
name_array->InsertNewAt<CPDF_Name>(i, vals[i]);
@@ -695,8 +695,8 @@ TEST(PDFArrayTest, AddInteger) {
TEST(PDFArrayTest, AddStringAndName) {
const char* vals[] = {"", "a", "ehjhRIOYTTFdfcdnv", "122323",
"$#%^&**", " ", "This is a test.\r\n"};
- std::unique_ptr<CPDF_Array> string_array(new CPDF_Array);
- std::unique_ptr<CPDF_Array> name_array(new CPDF_Array);
+ auto string_array = pdfium::MakeUnique<CPDF_Array>();
+ auto name_array = pdfium::MakeUnique<CPDF_Array>();
for (size_t i = 0; i < FX_ArraySize(vals); ++i) {
string_array->AddNew<CPDF_String>(vals[i], false);
name_array->AddNew<CPDF_Name>(vals[i]);
@@ -710,8 +710,7 @@ TEST(PDFArrayTest, AddStringAndName) {
}
TEST(PDFArrayTest, AddReferenceAndGetObjectAt) {
- std::unique_ptr<CPDF_IndirectObjectHolder> holder(
- new CPDF_IndirectObjectHolder());
+ auto holder = pdfium::MakeUnique<CPDF_IndirectObjectHolder>();
CPDF_Boolean* boolean_obj = new CPDF_Boolean(true);
CPDF_Number* int_obj = new CPDF_Number(-1234);
CPDF_Number* float_obj = new CPDF_Number(2345.089f);
@@ -723,7 +722,7 @@ TEST(PDFArrayTest, AddReferenceAndGetObjectAt) {
str_obj, name_obj, null_obj};
unsigned int obj_nums[] = {2, 4, 7, 2345, 799887, 1};
auto arr = pdfium::MakeUnique<CPDF_Array>();
- std::unique_ptr<CPDF_Array> arr1(new CPDF_Array);
+ auto arr1 = pdfium::MakeUnique<CPDF_Array>();
// Create two arrays of references by different AddReference() APIs.
for (size_t i = 0; i < FX_ArraySize(indirect_objs); ++i) {
holder->ReplaceIndirectObjectIfHigherGeneration(
@@ -748,7 +747,7 @@ TEST(PDFArrayTest, AddReferenceAndGetObjectAt) {
TEST(PDFArrayTest, CloneDirectObject) {
CPDF_IndirectObjectHolder objects_holder;
- std::unique_ptr<CPDF_Array> array(new CPDF_Array);
+ auto array = pdfium::MakeUnique<CPDF_Array>();
array->AddNew<CPDF_Reference>(&objects_holder, 1234);
ASSERT_EQ(1U, array->GetCount());
CPDF_Object* obj = array->GetObjectAt(0);
@@ -782,7 +781,7 @@ TEST(PDFArrayTest, ConvertIndirect) {
TEST(PDFDictionaryTest, CloneDirectObject) {
CPDF_IndirectObjectHolder objects_holder;
- std::unique_ptr<CPDF_Dictionary> dict(new CPDF_Dictionary());
+ auto dict = pdfium::MakeUnique<CPDF_Dictionary>();
dict->SetNewFor<CPDF_Reference>("foo", &objects_holder, 1234);
ASSERT_EQ(1U, dict->GetCount());
CPDF_Object* obj = dict->GetObjectFor("foo");
@@ -867,7 +866,7 @@ TEST(PDFObjectTest, CloneCheckLoop) {
TEST(PDFDictionaryTest, ConvertIndirect) {
CPDF_IndirectObjectHolder objects_holder;
- std::unique_ptr<CPDF_Dictionary> dict(new CPDF_Dictionary);
+ auto dict = pdfium::MakeUnique<CPDF_Dictionary>();
CPDF_Object* pObj = dict->SetNewFor<CPDF_Number>("clams", 42);
dict->ConvertToIndirectObjectFor("clams", &objects_holder);
CPDF_Object* pRef = dict->GetObjectFor("clams");
diff --git a/core/fpdfapi/render/cpdf_dibsource.cpp b/core/fpdfapi/render/cpdf_dibsource.cpp
index f3703dd23a..cb8e9c9eee 100644
--- a/core/fpdfapi/render/cpdf_dibsource.cpp
+++ b/core/fpdfapi/render/cpdf_dibsource.cpp
@@ -21,6 +21,7 @@
#include "core/fpdfapi/parser/fpdf_parser_decode.h"
#include "core/fpdfapi/render/cpdf_pagerendercache.h"
#include "core/fpdfapi/render/cpdf_renderstatus.h"
+#include "core/fxcodec/codec/cjpx_decoder.h"
#include "core/fxcodec/fx_codec.h"
#include "core/fxcrt/fx_safe_types.h"
#include "third_party/base/ptr_util.h"
@@ -79,16 +80,17 @@ class JpxBitMapContext {
explicit JpxBitMapContext(CCodec_JpxModule* jpx_module)
: jpx_module_(jpx_module), decoder_(nullptr) {}
- ~JpxBitMapContext() { jpx_module_->DestroyDecoder(decoder_); }
+ ~JpxBitMapContext() {}
- // Takes ownership of |decoder|.
- void set_decoder(CJPX_Decoder* decoder) { decoder_ = decoder; }
+ void set_decoder(std::unique_ptr<CJPX_Decoder> decoder) {
+ decoder_ = std::move(decoder);
+ }
- CJPX_Decoder* decoder() { return decoder_; }
+ CJPX_Decoder* decoder() { return decoder_.get(); }
private:
CCodec_JpxModule* const jpx_module_; // Weak pointer.
- CJPX_Decoder* decoder_; // Decoder, owned.
+ std::unique_ptr<CJPX_Decoder> decoder_;
// Disallow evil constructors
JpxBitMapContext(const JpxBitMapContext&);
@@ -613,7 +615,7 @@ void CPDF_DIBSource::LoadJpxBitmap() {
if (!pJpxModule)
return;
- std::unique_ptr<JpxBitMapContext> context(new JpxBitMapContext(pJpxModule));
+ auto context = pdfium::MakeUnique<JpxBitMapContext>(pJpxModule);
context->set_decoder(pJpxModule->CreateDecoder(
m_pStreamAcc->GetData(), m_pStreamAcc->GetSize(), m_pColorSpace));
if (!context->decoder())
diff --git a/core/fpdfdoc/cpdf_filespec_unittest.cpp b/core/fpdfdoc/cpdf_filespec_unittest.cpp
index d164165f00..e237aa5b6b 100644
--- a/core/fpdfdoc/cpdf_filespec_unittest.cpp
+++ b/core/fpdfdoc/cpdf_filespec_unittest.cpp
@@ -11,6 +11,7 @@
#include "core/fpdfdoc/cpdf_filespec.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/test_support.h"
+#include "third_party/base/ptr_util.h"
TEST(cpdf_filespec, EncodeDecodeFileName) {
std::vector<pdfium::NullTermWstrFuncTestData> test_data = {
@@ -67,8 +68,7 @@ TEST(cpdf_filespec, GetFileName) {
L"/docs/test.pdf"
#endif
};
- std::unique_ptr<CPDF_Object> str_obj(
- new CPDF_String(nullptr, test_data.input));
+ auto str_obj = pdfium::MakeUnique<CPDF_String>(nullptr, test_data.input);
CPDF_FileSpec file_spec(str_obj.get());
CFX_WideString file_name;
EXPECT_TRUE(file_spec.GetFileName(&file_name));
@@ -99,7 +99,7 @@ TEST(cpdf_filespec, GetFileName) {
};
// Keyword fields in reverse order of precedence to retrieve the file name.
const char* const keywords[5] = {"Unix", "Mac", "DOS", "F", "UF"};
- std::unique_ptr<CPDF_Dictionary> dict_obj(new CPDF_Dictionary());
+ auto dict_obj = pdfium::MakeUnique<CPDF_Dictionary>();
CPDF_FileSpec file_spec(dict_obj.get());
CFX_WideString file_name;
for (int i = 0; i < 5; ++i) {
@@ -116,7 +116,7 @@ TEST(cpdf_filespec, GetFileName) {
}
{
// Invalid object.
- std::unique_ptr<CPDF_Object> name_obj(new CPDF_Name(nullptr, "test.pdf"));
+ auto name_obj = pdfium::MakeUnique<CPDF_Name>(nullptr, "test.pdf");
CPDF_FileSpec file_spec(name_obj.get());
CFX_WideString file_name;
EXPECT_FALSE(file_spec.GetFileName(&file_name));
@@ -137,7 +137,7 @@ TEST(cpdf_filespec, SetFileName) {
#endif
};
// String object.
- std::unique_ptr<CPDF_Object> str_obj(new CPDF_String(nullptr, L"babababa"));
+ auto str_obj = pdfium::MakeUnique<CPDF_String>(nullptr, L"babababa");
CPDF_FileSpec file_spec1(str_obj.get());
file_spec1.SetFileName(test_data.input);
// Check internal object value.
@@ -149,7 +149,7 @@ TEST(cpdf_filespec, SetFileName) {
EXPECT_TRUE(file_name == test_data.input);
// Dictionary object.
- std::unique_ptr<CPDF_Dictionary> dict_obj(new CPDF_Dictionary());
+ auto dict_obj = pdfium::MakeUnique<CPDF_Dictionary>();
CPDF_FileSpec file_spec2(dict_obj.get());
file_spec2.SetFileName(test_data.input);
// Check internal object value.
diff --git a/core/fpdfdoc/cpdf_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp
index c697cbbf16..e7ca7c6a8d 100644
--- a/core/fpdfdoc/cpdf_formfield.cpp
+++ b/core/fpdfdoc/cpdf_formfield.cpp
@@ -566,7 +566,7 @@ bool CPDF_FormField::SetItemSelection(int index, bool bSelected, bool bNotify) {
if (pValue->GetUnicodeText() == opt_value)
m_pDict->RemoveFor("V");
} else if (pValue->IsArray()) {
- std::unique_ptr<CPDF_Array> pArray(new CPDF_Array);
+ auto pArray = pdfium::MakeUnique<CPDF_Array>();
for (int i = 0; i < CountOptions(); i++) {
if (i != index && IsItemSelected(i)) {
opt_value = GetOptionValue(i);
diff --git a/core/fxcodec/codec/ccodec_jpxmodule.h b/core/fxcodec/codec/ccodec_jpxmodule.h
index fd919d91b0..c57002722e 100644
--- a/core/fxcodec/codec/ccodec_jpxmodule.h
+++ b/core/fxcodec/codec/ccodec_jpxmodule.h
@@ -7,6 +7,7 @@
#ifndef CORE_FXCODEC_CODEC_CCODEC_JPXMODULE_H_
#define CORE_FXCODEC_CODEC_CCODEC_JPXMODULE_H_
+#include <memory>
#include <vector>
#include "core/fxcrt/fx_system.h"
@@ -19,9 +20,9 @@ class CCodec_JpxModule {
CCodec_JpxModule();
~CCodec_JpxModule();
- CJPX_Decoder* CreateDecoder(const uint8_t* src_buf,
- uint32_t src_size,
- CPDF_ColorSpace* cs);
+ std::unique_ptr<CJPX_Decoder> CreateDecoder(const uint8_t* src_buf,
+ uint32_t src_size,
+ CPDF_ColorSpace* cs);
void GetImageInfo(CJPX_Decoder* pDecoder,
uint32_t* width,
uint32_t* height,
@@ -30,7 +31,6 @@ class CCodec_JpxModule {
uint8_t* dest_data,
int pitch,
const std::vector<uint8_t>& offsets);
- void DestroyDecoder(CJPX_Decoder* pDecoder);
};
#endif // CORE_FXCODEC_CODEC_CCODEC_JPXMODULE_H_
diff --git a/core/fxcodec/codec/cjpx_decoder.h b/core/fxcodec/codec/cjpx_decoder.h
new file mode 100644
index 0000000000..2e63caac73
--- /dev/null
+++ b/core/fxcodec/codec/cjpx_decoder.h
@@ -0,0 +1,36 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FXCODEC_CODEC_CJPX_DECODER_H_
+#define CORE_FXCODEC_CODEC_CJPX_DECODER_H_
+
+#include <vector>
+
+#include "third_party/libopenjpeg20/openjpeg.h"
+
+class CPDF_ColorSpace;
+
+class CJPX_Decoder {
+ public:
+ explicit CJPX_Decoder(CPDF_ColorSpace* cs);
+ ~CJPX_Decoder();
+
+ bool Init(const unsigned char* src_data, uint32_t src_size);
+ void GetInfo(uint32_t* width, uint32_t* height, uint32_t* components);
+ bool Decode(uint8_t* dest_buf,
+ int pitch,
+ const std::vector<uint8_t>& offsets);
+
+ private:
+ const uint8_t* m_SrcData;
+ uint32_t m_SrcSize;
+ opj_image_t* image;
+ opj_codec_t* l_codec;
+ opj_stream_t* l_stream;
+ const CPDF_ColorSpace* const m_ColorSpace;
+};
+
+#endif // CORE_FXCODEC_CODEC_CJPX_DECODER_H_
diff --git a/core/fxcodec/codec/fx_codec_flate.cpp b/core/fxcodec/codec/fx_codec_flate.cpp
index 7c19d335bb..269bf58813 100644
--- a/core/fxcodec/codec/fx_codec_flate.cpp
+++ b/core/fxcodec/codec/fx_codec_flate.cpp
@@ -822,7 +822,7 @@ uint32_t CCodec_FlateModule::FlateOrLZWDecode(bool bLZW,
}
if (bLZW) {
{
- std::unique_ptr<CLZWDecoder> decoder(new CLZWDecoder);
+ auto decoder = pdfium::MakeUnique<CLZWDecoder>();
dest_size = 0xFFFFFFFF;
offset = src_size;
int err =
@@ -832,7 +832,7 @@ uint32_t CCodec_FlateModule::FlateOrLZWDecode(bool bLZW,
}
}
{
- std::unique_ptr<CLZWDecoder> decoder(new CLZWDecoder);
+ auto decoder = pdfium::MakeUnique<CLZWDecoder>();
dest_buf = FX_Alloc(uint8_t, dest_size + 1);
dest_buf[dest_size] = '\0';
decoder->Decode(dest_buf, dest_size, src_buf, offset, bEarlyChange);
diff --git a/core/fxcodec/codec/fx_codec_jpx_opj.cpp b/core/fxcodec/codec/fx_codec_jpx_opj.cpp
index eccf876218..4fc3d689f1 100644
--- a/core/fxcodec/codec/fx_codec_jpx_opj.cpp
+++ b/core/fxcodec/codec/fx_codec_jpx_opj.cpp
@@ -7,12 +7,15 @@
#include <algorithm>
#include <limits>
#include <memory>
+#include <utility>
#include <vector>
#include "core/fpdfapi/page/cpdf_colorspace.h"
+#include "core/fxcodec/codec/cjpx_decoder.h"
#include "core/fxcodec/codec/codec_int.h"
#include "core/fxcodec/fx_codec.h"
#include "core/fxcrt/fx_safe_types.h"
+#include "third_party/base/ptr_util.h"
#include "third_party/lcms2-2.6/include/lcms2.h"
#include "third_party/libopenjpeg20/openjpeg.h"
@@ -669,24 +672,6 @@ void color_apply_conversion(opj_image_t* image) {
return;
}
}
-class CJPX_Decoder {
- public:
- explicit CJPX_Decoder(CPDF_ColorSpace* cs);
- ~CJPX_Decoder();
- bool Init(const unsigned char* src_data, uint32_t src_size);
- void GetInfo(uint32_t* width, uint32_t* height, uint32_t* components);
- bool Decode(uint8_t* dest_buf,
- int pitch,
- const std::vector<uint8_t>& offsets);
-
- private:
- const uint8_t* m_SrcData;
- uint32_t m_SrcSize;
- opj_image_t* image;
- opj_codec_t* l_codec;
- opj_stream_t* l_stream;
- const CPDF_ColorSpace* const m_ColorSpace;
-};
CJPX_Decoder::CJPX_Decoder(CPDF_ColorSpace* cs)
: image(nullptr), l_codec(nullptr), l_stream(nullptr), m_ColorSpace(cs) {}
@@ -872,13 +857,15 @@ bool CJPX_Decoder::Decode(uint8_t* dest_buf,
}
CCodec_JpxModule::CCodec_JpxModule() {}
+
CCodec_JpxModule::~CCodec_JpxModule() {}
-CJPX_Decoder* CCodec_JpxModule::CreateDecoder(const uint8_t* src_buf,
- uint32_t src_size,
- CPDF_ColorSpace* cs) {
- std::unique_ptr<CJPX_Decoder> decoder(new CJPX_Decoder(cs));
- return decoder->Init(src_buf, src_size) ? decoder.release() : nullptr;
+std::unique_ptr<CJPX_Decoder> CCodec_JpxModule::CreateDecoder(
+ const uint8_t* src_buf,
+ uint32_t src_size,
+ CPDF_ColorSpace* cs) {
+ auto decoder = pdfium::MakeUnique<CJPX_Decoder>(cs);
+ return decoder->Init(src_buf, src_size) ? std::move(decoder) : nullptr;
}
void CCodec_JpxModule::GetImageInfo(CJPX_Decoder* pDecoder,
@@ -894,7 +881,3 @@ bool CCodec_JpxModule::Decode(CJPX_Decoder* pDecoder,
const std::vector<uint8_t>& offsets) {
return pDecoder->Decode(dest_data, pitch, offsets);
}
-
-void CCodec_JpxModule::DestroyDecoder(CJPX_Decoder* pDecoder) {
- delete pDecoder;
-}
diff --git a/core/fxcodec/jbig2/JBig2_Context.cpp b/core/fxcodec/jbig2/JBig2_Context.cpp
index 109013204e..9261d16bfc 100644
--- a/core/fxcodec/jbig2/JBig2_Context.cpp
+++ b/core/fxcodec/jbig2/JBig2_Context.cpp
@@ -122,7 +122,7 @@ int32_t CJBig2_Context::decode_EmbedOrgnazation(IFX_Pause* pPause) {
int32_t CJBig2_Context::decode_RandomOrgnazation_FirstPage(IFX_Pause* pPause) {
int32_t nRet;
while (m_pStream->getByteLeft() > JBIG2_MIN_SEGMENT_SIZE) {
- std::unique_ptr<CJBig2_Segment> pSegment(new CJBig2_Segment);
+ auto pSegment = pdfium::MakeUnique<CJBig2_Segment>();
nRet = parseSegmentHeader(pSegment.get());
if (nRet != JBIG2_SUCCESS) {
return nRet;
@@ -364,7 +364,7 @@ int32_t CJBig2_Context::ProcessingParseSegmentData(CJBig2_Segment* pSegment,
return parseGenericRefinementRegion(pSegment);
case 48: {
uint16_t wTemp;
- std::unique_ptr<JBig2PageInfo> pPageInfo(new JBig2PageInfo);
+ auto pPageInfo = pdfium::MakeUnique<JBig2PageInfo>();
if (m_pStream->readInteger(&pPageInfo->m_dwWidth) != 0 ||
m_pStream->readInteger(&pPageInfo->m_dwHeight) != 0 ||
m_pStream->readInteger(&pPageInfo->m_dwResolutionX) != 0 ||
@@ -424,7 +424,7 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment,
if (m_pStream->readShortInteger(&wFlags) != 0)
return JBIG2_ERROR_TOO_SHORT;
- std::unique_ptr<CJBig2_SDDProc> pSymbolDictDecoder(new CJBig2_SDDProc);
+ auto pSymbolDictDecoder = pdfium::MakeUnique<CJBig2_SDDProc>();
pSymbolDictDecoder->SDHUFF = wFlags & 0x0001;
pSymbolDictDecoder->SDREFAGG = (wFlags >> 1) & 0x0001;
pSymbolDictDecoder->SDTEMPLATE = (wFlags >> 10) & 0x0003;
@@ -600,8 +600,8 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment,
}
if (!cache_hit) {
if (bUseGbContext) {
- std::unique_ptr<CJBig2_ArithDecoder> pArithDecoder(
- new CJBig2_ArithDecoder(m_pStream.get()));
+ auto pArithDecoder =
+ pdfium::MakeUnique<CJBig2_ArithDecoder>(m_pStream.get());
pSegment->m_Result.sd = pSymbolDictDecoder->decode_Arith(
pArithDecoder.get(), &gbContext, &grContext);
if (!pSegment->m_Result.sd)
@@ -644,7 +644,7 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) {
return JBIG2_ERROR_TOO_SHORT;
}
- std::unique_ptr<CJBig2_TRDProc> pTRD(new CJBig2_TRDProc);
+ auto pTRD = pdfium::MakeUnique<CJBig2_TRDProc>();
pTRD->SBW = ri.width;
pTRD->SBH = ri.height;
pTRD->SBHUFF = wFlags & 0x0001;
@@ -902,8 +902,8 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) {
JBIG2_memset(grContext.get(), 0, sizeof(JBig2ArithCtx) * size);
}
if (pTRD->SBHUFF == 0) {
- std::unique_ptr<CJBig2_ArithDecoder> pArithDecoder(
- new CJBig2_ArithDecoder(m_pStream.get()));
+ auto pArithDecoder =
+ pdfium::MakeUnique<CJBig2_ArithDecoder>(m_pStream.get());
pSegment->m_nResultType = JBIG2_IMAGE_POINTER;
pSegment->m_Result.im =
pTRD->decode_Arith(pArithDecoder.get(), grContext.get(), nullptr);
@@ -938,7 +938,7 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) {
int32_t CJBig2_Context::parsePatternDict(CJBig2_Segment* pSegment,
IFX_Pause* pPause) {
uint8_t cFlags;
- std::unique_ptr<CJBig2_PDDProc> pPDD(new CJBig2_PDDProc);
+ auto pPDD = pdfium::MakeUnique<CJBig2_PDDProc>();
if (m_pStream->read1Byte(&cFlags) != 0 ||
m_pStream->read1Byte(&pPDD->HDPW) != 0 ||
m_pStream->read1Byte(&pPDD->HDPH) != 0 ||
@@ -956,8 +956,8 @@ int32_t CJBig2_Context::parsePatternDict(CJBig2_Segment* pSegment,
std::unique_ptr<JBig2ArithCtx, FxFreeDeleter> gbContext(
FX_Alloc(JBig2ArithCtx, size));
JBIG2_memset(gbContext.get(), 0, sizeof(JBig2ArithCtx) * size);
- std::unique_ptr<CJBig2_ArithDecoder> pArithDecoder(
- new CJBig2_ArithDecoder(m_pStream.get()));
+ auto pArithDecoder =
+ pdfium::MakeUnique<CJBig2_ArithDecoder>(m_pStream.get());
pSegment->m_Result.pd =
pPDD->decode_Arith(pArithDecoder.get(), gbContext.get(), pPause);
if (!pSegment->m_Result.pd)
@@ -978,7 +978,7 @@ int32_t CJBig2_Context::parseHalftoneRegion(CJBig2_Segment* pSegment,
IFX_Pause* pPause) {
uint8_t cFlags;
JBig2RegionInfo ri;
- std::unique_ptr<CJBig2_HTRDProc> pHRD(new CJBig2_HTRDProc);
+ auto pHRD = pdfium::MakeUnique<CJBig2_HTRDProc>();
if (parseRegionInfo(&ri) != JBIG2_SUCCESS ||
m_pStream->read1Byte(&cFlags) != 0 ||
m_pStream->readInteger(&pHRD->HGW) != 0 ||
@@ -1022,8 +1022,8 @@ int32_t CJBig2_Context::parseHalftoneRegion(CJBig2_Segment* pSegment,
std::unique_ptr<JBig2ArithCtx, FxFreeDeleter> gbContext(
FX_Alloc(JBig2ArithCtx, size));
JBIG2_memset(gbContext.get(), 0, sizeof(JBig2ArithCtx) * size);
- std::unique_ptr<CJBig2_ArithDecoder> pArithDecoder(
- new CJBig2_ArithDecoder(m_pStream.get()));
+ auto pArithDecoder =
+ pdfium::MakeUnique<CJBig2_ArithDecoder>(m_pStream.get());
pSegment->m_Result.im =
pHRD->decode_Arith(pArithDecoder.get(), gbContext.get(), pPause);
if (!pSegment->m_Result.im)
@@ -1056,7 +1056,7 @@ int32_t CJBig2_Context::parseHalftoneRegion(CJBig2_Segment* pSegment,
int32_t CJBig2_Context::parseGenericRegion(CJBig2_Segment* pSegment,
IFX_Pause* pPause) {
if (!m_pGRD) {
- std::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc);
+ auto pGRD = pdfium::MakeUnique<CJBig2_GRDProc>();
uint8_t cFlags;
if (parseRegionInfo(&m_ri) != JBIG2_SUCCESS ||
m_pStream->read1Byte(&cFlags) != 0) {
@@ -1165,7 +1165,7 @@ int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) {
m_pStream->read1Byte(&cFlags) != 0) {
return JBIG2_ERROR_TOO_SHORT;
}
- std::unique_ptr<CJBig2_GRRDProc> pGRRD(new CJBig2_GRRDProc);
+ auto pGRRD = pdfium::MakeUnique<CJBig2_GRRDProc>();
pGRRD->GRW = ri.width;
pGRRD->GRH = ri.height;
pGRRD->GRTEMPLATE = !!(cFlags & 0x01);
@@ -1202,8 +1202,7 @@ int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) {
std::unique_ptr<JBig2ArithCtx, FxFreeDeleter> grContext(
FX_Alloc(JBig2ArithCtx, size));
JBIG2_memset(grContext.get(), 0, sizeof(JBig2ArithCtx) * size);
- std::unique_ptr<CJBig2_ArithDecoder> pArithDecoder(
- new CJBig2_ArithDecoder(m_pStream.get()));
+ auto pArithDecoder = pdfium::MakeUnique<CJBig2_ArithDecoder>(m_pStream.get());
pSegment->m_nResultType = JBIG2_IMAGE_POINTER;
pSegment->m_Result.im = pGRRD->decode(pArithDecoder.get(), grContext.get());
if (!pSegment->m_Result.im)
@@ -1230,8 +1229,7 @@ int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) {
int32_t CJBig2_Context::parseTable(CJBig2_Segment* pSegment) {
pSegment->m_nResultType = JBIG2_HUFFMAN_TABLE_POINTER;
pSegment->m_Result.ht = nullptr;
- std::unique_ptr<CJBig2_HuffmanTable> pHuff(
- new CJBig2_HuffmanTable(m_pStream.get()));
+ auto pHuff = pdfium::MakeUnique<CJBig2_HuffmanTable>(m_pStream.get());
if (!pHuff->IsOK())
return JBIG2_ERROR_FATAL;
diff --git a/core/fxcodec/jbig2/JBig2_GrdProc.cpp b/core/fxcodec/jbig2/JBig2_GrdProc.cpp
index d5d4c6d0dc..675de9bcdd 100644
--- a/core/fxcodec/jbig2/JBig2_GrdProc.cpp
+++ b/core/fxcodec/jbig2/JBig2_GrdProc.cpp
@@ -12,6 +12,7 @@
#include "core/fxcodec/jbig2/JBig2_ArithDecoder.h"
#include "core/fxcodec/jbig2/JBig2_BitStream.h"
#include "core/fxcodec/jbig2/JBig2_Image.h"
+#include "third_party/base/ptr_util.h"
CJBig2_GRDProc::CJBig2_GRDProc()
: m_loopIndex(0),
@@ -65,7 +66,7 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_opt3(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext) {
- std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH));
+ auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH);
if (!GBREG->m_pData)
return nullptr;
@@ -164,7 +165,7 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_unopt(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext) {
int LTP = 0;
- std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH));
+ auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH);
GBREG->fill(0);
for (uint32_t h = 0; h < GBH; h++) {
if (TPGDON) {
@@ -214,7 +215,7 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_unopt(
CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_opt3(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext) {
- std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH));
+ auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH);
if (!GBREG->m_pData)
return nullptr;
@@ -312,7 +313,7 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_unopt(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext) {
int LTP = 0;
- std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH));
+ auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH);
GBREG->fill(0);
for (uint32_t h = 0; h < GBH; h++) {
if (TPGDON) {
@@ -360,7 +361,7 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_unopt(
CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_opt3(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext) {
- std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH));
+ auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH);
if (!GBREG->m_pData)
return nullptr;
@@ -458,7 +459,7 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_unopt(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext) {
int LTP = 0;
- std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH));
+ auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH);
GBREG->fill(0);
for (uint32_t h = 0; h < GBH; h++) {
if (TPGDON) {
@@ -504,7 +505,7 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_unopt(
CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_opt3(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext) {
- std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH));
+ auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH);
if (!GBREG->m_pData)
return nullptr;
@@ -590,7 +591,7 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_unopt(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext) {
int LTP = 0;
- std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH));
+ auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH);
GBREG->fill(0);
for (uint32_t h = 0; h < GBH; h++) {
if (TPGDON) {
diff --git a/core/fxcodec/jbig2/JBig2_GrrdProc.cpp b/core/fxcodec/jbig2/JBig2_GrrdProc.cpp
index 669fed68e9..936b851d37 100644
--- a/core/fxcodec/jbig2/JBig2_GrrdProc.cpp
+++ b/core/fxcodec/jbig2/JBig2_GrrdProc.cpp
@@ -11,6 +11,7 @@
#include "core/fxcodec/jbig2/JBig2_ArithDecoder.h"
#include "core/fxcodec/jbig2/JBig2_BitStream.h"
#include "core/fxcodec/jbig2/JBig2_Image.h"
+#include "third_party/base/ptr_util.h"
CJBig2_Image* CJBig2_GRRDProc::decode(CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* grContext) {
@@ -35,7 +36,7 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template0_unopt(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* grContext) {
int LTP = 0;
- std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(GRW, GRH));
+ auto GRREG = pdfium::MakeUnique<CJBig2_Image>(GRW, GRH);
GRREG->fill(0);
for (uint32_t h = 0; h < GRH; h++) {
if (TPGRON)
@@ -155,7 +156,7 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template0_opt(
int32_t iGRW = static_cast<int32_t>(GRW);
int32_t iGRH = static_cast<int32_t>(GRH);
- std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(iGRW, iGRH));
+ auto GRREG = pdfium::MakeUnique<CJBig2_Image>(iGRW, iGRH);
if (!GRREG->m_pData)
return nullptr;
@@ -283,7 +284,7 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template1_unopt(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* grContext) {
int LTP = 0;
- std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(GRW, GRH));
+ auto GRREG = pdfium::MakeUnique<CJBig2_Image>(GRW, GRH);
GRREG->fill(0);
for (uint32_t h = 0; h < GRH; h++) {
if (TPGRON)
@@ -389,7 +390,7 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template1_opt(
int32_t iGRW = static_cast<int32_t>(GRW);
int32_t iGRH = static_cast<int32_t>(GRH);
- std::unique_ptr<CJBig2_Image> GRREG(new CJBig2_Image(iGRW, iGRH));
+ auto GRREG = pdfium::MakeUnique<CJBig2_Image>(iGRW, iGRH);
if (!GRREG->m_pData)
return nullptr;
diff --git a/core/fxcodec/jbig2/JBig2_GsidProc.cpp b/core/fxcodec/jbig2/JBig2_GsidProc.cpp
index 387f8ee511..e65b47de62 100644
--- a/core/fxcodec/jbig2/JBig2_GsidProc.cpp
+++ b/core/fxcodec/jbig2/JBig2_GsidProc.cpp
@@ -13,11 +13,12 @@
#include "core/fxcodec/jbig2/JBig2_GrdProc.h"
#include "core/fxcodec/jbig2/JBig2_Image.h"
#include "core/fxcrt/fx_basic.h"
+#include "third_party/base/ptr_util.h"
uint32_t* CJBig2_GSIDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext,
IFX_Pause* pPause) {
- std::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc());
+ auto pGRD = pdfium::MakeUnique<CJBig2_GRDProc>();
pGRD->MMR = GSMMR;
pGRD->GBW = GSW;
pGRD->GBH = GSH;
@@ -69,7 +70,7 @@ uint32_t* CJBig2_GSIDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
uint32_t* CJBig2_GSIDProc::decode_MMR(CJBig2_BitStream* pStream,
IFX_Pause* pPause) {
- std::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc());
+ auto pGRD = pdfium::MakeUnique<CJBig2_GRDProc>();
pGRD->MMR = GSMMR;
pGRD->GBW = GSW;
pGRD->GBH = GSH;
diff --git a/core/fxcodec/jbig2/JBig2_HtrdProc.cpp b/core/fxcodec/jbig2/JBig2_HtrdProc.cpp
index 121bf1d6df..8899fb1350 100644
--- a/core/fxcodec/jbig2/JBig2_HtrdProc.cpp
+++ b/core/fxcodec/jbig2/JBig2_HtrdProc.cpp
@@ -20,7 +20,7 @@ CJBig2_Image* CJBig2_HTRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
uint32_t HBPP;
uint32_t* GI;
std::unique_ptr<CJBig2_Image> HSKIP;
- std::unique_ptr<CJBig2_Image> HTREG(new CJBig2_Image(HBW, HBH));
+ auto HTREG = pdfium::MakeUnique<CJBig2_Image>(HBW, HBH);
HTREG->fill(HDEFPIXEL);
if (HENABLESKIP == 1) {
HSKIP = pdfium::MakeUnique<CJBig2_Image>(HGW, HGH);
@@ -41,7 +41,7 @@ CJBig2_Image* CJBig2_HTRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
while ((uint32_t)(1 << HBPP) < HNUMPATS) {
HBPP++;
}
- std::unique_ptr<CJBig2_GSIDProc> pGID(new CJBig2_GSIDProc());
+ auto pGID = pdfium::MakeUnique<CJBig2_GSIDProc>();
pGID->GSMMR = HMMR;
pGID->GSW = HGW;
pGID->GSH = HGH;
@@ -73,13 +73,13 @@ CJBig2_Image* CJBig2_HTRDProc::decode_MMR(CJBig2_BitStream* pStream,
uint32_t ng, mg;
int32_t x, y;
uint32_t* GI;
- std::unique_ptr<CJBig2_Image> HTREG(new CJBig2_Image(HBW, HBH));
+ auto HTREG = pdfium::MakeUnique<CJBig2_Image>(HBW, HBH);
HTREG->fill(HDEFPIXEL);
uint32_t HBPP = 1;
while ((uint32_t)(1 << HBPP) < HNUMPATS) {
HBPP++;
}
- std::unique_ptr<CJBig2_GSIDProc> pGID(new CJBig2_GSIDProc());
+ auto pGID = pdfium::MakeUnique<CJBig2_GSIDProc>();
pGID->GSMMR = HMMR;
pGID->GSW = HGW;
pGID->GSH = HGH;
diff --git a/core/fxcodec/jbig2/JBig2_PddProc.cpp b/core/fxcodec/jbig2/JBig2_PddProc.cpp
index 679a87a036..3eef302baf 100644
--- a/core/fxcodec/jbig2/JBig2_PddProc.cpp
+++ b/core/fxcodec/jbig2/JBig2_PddProc.cpp
@@ -11,6 +11,7 @@
#include "core/fxcodec/jbig2/JBig2_GrdProc.h"
#include "core/fxcodec/jbig2/JBig2_Image.h"
#include "core/fxcodec/jbig2/JBig2_PatternDict.h"
+#include "third_party/base/ptr_util.h"
CJBig2_PatternDict* CJBig2_PDDProc::decode_Arith(
CJBig2_ArithDecoder* pArithDecoder,
@@ -18,12 +19,12 @@ CJBig2_PatternDict* CJBig2_PDDProc::decode_Arith(
IFX_Pause* pPause) {
uint32_t GRAY;
CJBig2_Image* BHDC = nullptr;
- std::unique_ptr<CJBig2_PatternDict> pDict(new CJBig2_PatternDict());
+ auto pDict = pdfium::MakeUnique<CJBig2_PatternDict>();
pDict->NUMPATS = GRAYMAX + 1;
pDict->HDPATS = FX_Alloc(CJBig2_Image*, pDict->NUMPATS);
JBIG2_memset(pDict->HDPATS, 0, sizeof(CJBig2_Image*) * pDict->NUMPATS);
- std::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc());
+ auto pGRD = pdfium::MakeUnique<CJBig2_GRDProc>();
pGRD->MMR = HDMMR;
pGRD->GBW = (GRAYMAX + 1) * HDPW;
pGRD->GBH = HDPH;
@@ -60,12 +61,12 @@ CJBig2_PatternDict* CJBig2_PDDProc::decode_MMR(CJBig2_BitStream* pStream,
IFX_Pause* pPause) {
uint32_t GRAY;
CJBig2_Image* BHDC = nullptr;
- std::unique_ptr<CJBig2_PatternDict> pDict(new CJBig2_PatternDict());
+ auto pDict = pdfium::MakeUnique<CJBig2_PatternDict>();
pDict->NUMPATS = GRAYMAX + 1;
pDict->HDPATS = FX_Alloc(CJBig2_Image*, pDict->NUMPATS);
JBIG2_memset(pDict->HDPATS, 0, sizeof(CJBig2_Image*) * pDict->NUMPATS);
- std::unique_ptr<CJBig2_GRDProc> pGRD(new CJBig2_GRDProc());
+ auto pGRD = pdfium::MakeUnique<CJBig2_GRDProc>();
pGRD->MMR = HDMMR;
pGRD->GBW = (GRAYMAX + 1) * HDPW;
pGRD->GBH = HDPH;
diff --git a/core/fxcodec/jbig2/JBig2_TrdProc.cpp b/core/fxcodec/jbig2/JBig2_TrdProc.cpp
index 84042dbd8c..cf58d9c3c6 100644
--- a/core/fxcodec/jbig2/JBig2_TrdProc.cpp
+++ b/core/fxcodec/jbig2/JBig2_TrdProc.cpp
@@ -16,9 +16,8 @@
CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream,
JBig2ArithCtx* grContext) {
- std::unique_ptr<CJBig2_HuffmanDecoder> pHuffmanDecoder(
- new CJBig2_HuffmanDecoder(pStream));
- std::unique_ptr<CJBig2_Image> SBREG(new CJBig2_Image(SBW, SBH));
+ auto pHuffmanDecoder = pdfium::MakeUnique<CJBig2_HuffmanDecoder>(pStream);
+ auto SBREG = pdfium::MakeUnique<CJBig2_Image>(SBW, SBH);
SBREG->fill(SBDEFPIXEL);
int32_t STRIPT;
if (pHuffmanDecoder->decodeAValue(SBHUFFDT, &STRIPT) != 0)
@@ -120,7 +119,7 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream,
if ((int)(WOI + RDWI) < 0 || (int)(HOI + RDHI) < 0)
return nullptr;
- std::unique_ptr<CJBig2_GRRDProc> pGRRD(new CJBig2_GRRDProc());
+ auto pGRRD = pdfium::MakeUnique<CJBig2_GRRDProc>();
pGRRD->GRW = WOI + RDWI;
pGRRD->GRH = HOI + RDHI;
pGRRD->GRTEMPLATE = SBRTEMPLATE;
@@ -134,8 +133,7 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream,
pGRRD->GRAT[3] = SBRAT[3];
{
- std::unique_ptr<CJBig2_ArithDecoder> pArithDecoder(
- new CJBig2_ArithDecoder(pStream));
+ auto pArithDecoder = pdfium::MakeUnique<CJBig2_ArithDecoder>(pStream);
IBI = pGRRD->decode(pArithDecoder.get(), grContext);
if (!IBI)
return nullptr;
@@ -264,7 +262,7 @@ CJBig2_Image* CJBig2_TRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
pIARDY = IARDY.get();
pIAID = IAID.get();
}
- std::unique_ptr<CJBig2_Image> SBREG(new CJBig2_Image(SBW, SBH));
+ auto SBREG = pdfium::MakeUnique<CJBig2_Image>(SBW, SBH);
SBREG->fill(SBDEFPIXEL);
int32_t STRIPT;
if (!pIADT->decode(pArithDecoder, &STRIPT))
@@ -335,7 +333,7 @@ CJBig2_Image* CJBig2_TRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
if ((int)(WOI + RDWI) < 0 || (int)(HOI + RDHI) < 0)
return nullptr;
- std::unique_ptr<CJBig2_GRRDProc> pGRRD(new CJBig2_GRRDProc());
+ auto pGRRD = pdfium::MakeUnique<CJBig2_GRRDProc>();
pGRRD->GRW = WOI + RDWI;
pGRRD->GRH = HOI + RDHI;
pGRRD->GRTEMPLATE = SBRTEMPLATE;
diff --git a/core/fxcrt/fx_basic_util.cpp b/core/fxcrt/fx_basic_util.cpp
index 19e5696c86..9f699e4da7 100644
--- a/core/fxcrt/fx_basic_util.cpp
+++ b/core/fxcrt/fx_basic_util.cpp
@@ -4,14 +4,15 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#include "core/fxcrt/fx_basic.h"
-#include "core/fxcrt/fx_ext.h"
-
#include <algorithm>
#include <cctype>
#include <limits>
#include <memory>
+#include "core/fxcrt/fx_basic.h"
+#include "core/fxcrt/fx_ext.h"
+#include "third_party/base/ptr_util.h"
+
bool FX_atonum(const CFX_ByteStringC& strc, void* pData) {
if (strc.Find('.') != -1) {
float* pFloat = static_cast<float*>(pData);
@@ -142,7 +143,7 @@ void FXSYS_vsnprintf(char* str, size_t size, const char* fmt, va_list ap) {
FX_FileHandle* FX_OpenFolder(const char* path) {
#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
- std::unique_ptr<CFindFileDataA> pData(new CFindFileDataA);
+ auto pData = pdfium::MakeUnique<CFindFileDataA>();
pData->m_Handle = FindFirstFileExA((CFX_ByteString(path) + "/*.*").c_str(),
FindExInfoStandard, &pData->m_FindData,
FindExSearchNameMatch, nullptr, 0);
diff --git a/core/fxge/android/fx_android_imp.cpp b/core/fxge/android/fx_android_imp.cpp
index b8e7c5b218..e4fdd1e131 100644
--- a/core/fxge/android/fx_android_imp.cpp
+++ b/core/fxge/android/fx_android_imp.cpp
@@ -11,6 +11,7 @@
#include "core/fxge/android/cfpf_skiadevicemodule.h"
#include "core/fxge/android/cfx_androidfontinfo.h"
+#include "third_party/base/ptr_util.h"
void CFX_GEModule::InitPlatform() {
CFPF_SkiaDeviceModule* pDeviceModule = CFPF_GetSkiaDeviceModule();
@@ -19,7 +20,7 @@ void CFX_GEModule::InitPlatform() {
CFPF_SkiaFontMgr* pFontMgr = pDeviceModule->GetFontMgr();
if (pFontMgr) {
- std::unique_ptr<CFX_AndroidFontInfo> pFontInfo(new CFX_AndroidFontInfo);
+ auto pFontInfo = pdfium::MakeUnique<CFX_AndroidFontInfo>();
pFontInfo->Init(pFontMgr);
m_pFontMgr->SetSystemFontInfo(std::move(pFontInfo));
}
diff --git a/core/fxge/ge/cfx_fontcache.cpp b/core/fxge/ge/cfx_fontcache.cpp
index 58cee06d42..1599c30b93 100644
--- a/core/fxge/ge/cfx_fontcache.cpp
+++ b/core/fxge/ge/cfx_fontcache.cpp
@@ -12,6 +12,7 @@
#include "core/fxge/cfx_facecache.h"
#include "core/fxge/fx_font.h"
#include "core/fxge/fx_freetype.h"
+#include "third_party/base/ptr_util.h"
CFX_FontCache::CountedFaceCache::CountedFaceCache() {}
@@ -35,7 +36,7 @@ CFX_FaceCache* CFX_FontCache::GetCachedFace(const CFX_Font* pFont) {
return counted_face_cache->m_Obj.get();
}
- std::unique_ptr<CountedFaceCache> counted_face_cache(new CountedFaceCache);
+ auto counted_face_cache = pdfium::MakeUnique<CountedFaceCache>();
counted_face_cache->m_nCount = 2;
CFX_FaceCache* face_cache = new CFX_FaceCache(bExternal ? nullptr : face);
counted_face_cache->m_Obj.reset(face_cache);
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);
diff --git a/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp b/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp
index e2d483cbdf..041272ef8c 100644
--- a/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp
+++ b/fxbarcode/datamatrix/BC_HighLevelEncoder.cpp
@@ -39,6 +39,7 @@
#include "fxbarcode/datamatrix/BC_TextEncoder.h"
#include "fxbarcode/datamatrix/BC_X12Encoder.h"
#include "fxbarcode/utils.h"
+#include "third_party/base/ptr_util.h"
wchar_t CBC_HighLevelEncoder::LATCH_TO_C40 = 230;
wchar_t CBC_HighLevelEncoder::LATCH_TO_BASE256 = 231;
@@ -95,12 +96,12 @@ CFX_WideString CBC_HighLevelEncoder::encodeHighLevel(CFX_WideString msg,
}
std::vector<std::unique_ptr<CBC_Encoder>> encoders;
- encoders.push_back(std::unique_ptr<CBC_Encoder>(new CBC_ASCIIEncoder()));
- encoders.push_back(std::unique_ptr<CBC_Encoder>(new CBC_C40Encoder()));
- encoders.push_back(std::unique_ptr<CBC_Encoder>(new CBC_TextEncoder()));
- encoders.push_back(std::unique_ptr<CBC_Encoder>(new CBC_X12Encoder()));
- encoders.push_back(std::unique_ptr<CBC_Encoder>(new CBC_EdifactEncoder()));
- encoders.push_back(std::unique_ptr<CBC_Encoder>(new CBC_Base256Encoder()));
+ encoders.push_back(pdfium::MakeUnique<CBC_ASCIIEncoder>());
+ encoders.push_back(pdfium::MakeUnique<CBC_C40Encoder>());
+ encoders.push_back(pdfium::MakeUnique<CBC_TextEncoder>());
+ encoders.push_back(pdfium::MakeUnique<CBC_X12Encoder>());
+ encoders.push_back(pdfium::MakeUnique<CBC_EdifactEncoder>());
+ encoders.push_back(pdfium::MakeUnique<CBC_Base256Encoder>());
int32_t encodingMode = ASCII_ENCODATION;
while (context.hasMoreCharacters()) {
encoders[encodingMode]->Encode(context, e);
diff --git a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
index b07b700c51..29dc69996b 100644
--- a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
+++ b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
@@ -39,6 +39,7 @@
#include "fxbarcode/qrcode/BC_QRCoderMatrixUtil.h"
#include "fxbarcode/qrcode/BC_QRCoderMode.h"
#include "fxbarcode/qrcode/BC_QRCoderVersion.h"
+#include "third_party/base/ptr_util.h"
namespace {
@@ -388,8 +389,8 @@ void CBC_QRCoderEncoder::EncodeWithSpecifyVersion(
if (e != BCExceptionNO)
return;
- std::unique_ptr<CBC_CommonByteMatrix> matrix(new CBC_CommonByteMatrix(
- qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth()));
+ auto matrix = pdfium::MakeUnique<CBC_CommonByteMatrix>(
+ qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth());
matrix->Init();
int32_t maskPattern = ChooseMaskPattern(
&finalBits, qrCode->GetECLevel(), qrCode->GetVersion(), matrix.get(), e);
@@ -473,8 +474,8 @@ catchException:
if (e != BCExceptionNO)
return;
- std::unique_ptr<CBC_CommonByteMatrix> matrix(new CBC_CommonByteMatrix(
- qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth()));
+ auto matrix = pdfium::MakeUnique<CBC_CommonByteMatrix>(
+ qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth());
matrix->Init();
int32_t maskPattern = ChooseMaskPattern(
&finalBits, qrCode->GetECLevel(), qrCode->GetVersion(), matrix.get(), e);
@@ -533,8 +534,8 @@ void CBC_QRCoderEncoder::Encode(const CFX_WideString& content,
if (e != BCExceptionNO)
return;
- std::unique_ptr<CBC_CommonByteMatrix> matrix(new CBC_CommonByteMatrix(
- qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth()));
+ auto matrix = pdfium::MakeUnique<CBC_CommonByteMatrix>(
+ qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth());
matrix->Init();
int32_t maskPattern = ChooseMaskPattern(
&finalBits, qrCode->GetECLevel(), qrCode->GetVersion(), matrix.get(), e);
@@ -878,7 +879,7 @@ void CBC_QRCoderEncoder::InterleaveWithECBytes(CBC_QRCoderBitVector* bits,
GetNumDataBytesAndNumECBytesForBlockID(numTotalBytes, numDataBytes,
numRSBlocks, i, numDataBytesInBlock,
numEcBytesInBlosk);
- std::unique_ptr<CBC_CommonByteArray> dataBytes(new CBC_CommonByteArray);
+ auto dataBytes = pdfium::MakeUnique<CBC_CommonByteArray>();
dataBytes->Set(bits->GetArray(), dataBytesOffset, numDataBytesInBlock);
std::unique_ptr<CBC_CommonByteArray> ecBytes(
GenerateECBytes(dataBytes.get(), numEcBytesInBlosk, e));
diff --git a/fxjs/cfxjse_class.cpp b/fxjs/cfxjse_class.cpp
index 3801fb520a..8924a48a47 100644
--- a/fxjs/cfxjse_class.cpp
+++ b/fxjs/cfxjse_class.cpp
@@ -10,6 +10,7 @@
#include "fxjs/cfxjse_context.h"
#include "fxjs/cfxjse_value.h"
+#include "third_party/base/ptr_util.h"
namespace {
@@ -22,10 +23,9 @@ void V8FunctionCallback_Wrapper(
return;
CFX_ByteStringC szFunctionName(lpFunctionInfo->name);
- std::unique_ptr<CFXJSE_Value> lpThisValue(
- new CFXJSE_Value(info.GetIsolate()));
+ auto lpThisValue = pdfium::MakeUnique<CFXJSE_Value>(info.GetIsolate());
lpThisValue->ForceSetValue(info.Holder());
- std::unique_ptr<CFXJSE_Value> lpRetValue(new CFXJSE_Value(info.GetIsolate()));
+ auto lpRetValue = pdfium::MakeUnique<CFXJSE_Value>(info.GetIsolate());
CFXJSE_Arguments impl(&info, lpRetValue.get());
lpFunctionInfo->callbackProc(lpThisValue.get(), szFunctionName, impl);
if (!lpRetValue->DirectGetValue().IsEmpty())
@@ -41,10 +41,9 @@ void V8ClassGlobalConstructorCallback_Wrapper(
return;
CFX_ByteStringC szFunctionName(lpClassDefinition->name);
- std::unique_ptr<CFXJSE_Value> lpThisValue(
- new CFXJSE_Value(info.GetIsolate()));
+ auto lpThisValue = pdfium::MakeUnique<CFXJSE_Value>(info.GetIsolate());
lpThisValue->ForceSetValue(info.Holder());
- std::unique_ptr<CFXJSE_Value> lpRetValue(new CFXJSE_Value(info.GetIsolate()));
+ auto lpRetValue = pdfium::MakeUnique<CFXJSE_Value>(info.GetIsolate());
CFXJSE_Arguments impl(&info, lpRetValue.get());
lpClassDefinition->constructor(lpThisValue.get(), szFunctionName, impl);
if (!lpRetValue->DirectGetValue().IsEmpty())
@@ -60,10 +59,8 @@ void V8GetterCallback_Wrapper(v8::Local<v8::String> property,
return;
CFX_ByteStringC szPropertyName(lpPropertyInfo->name);
- std::unique_ptr<CFXJSE_Value> lpThisValue(
- new CFXJSE_Value(info.GetIsolate()));
- std::unique_ptr<CFXJSE_Value> lpPropValue(
- new CFXJSE_Value(info.GetIsolate()));
+ auto lpThisValue = pdfium::MakeUnique<CFXJSE_Value>(info.GetIsolate());
+ auto lpPropValue = pdfium::MakeUnique<CFXJSE_Value>(info.GetIsolate());
lpThisValue->ForceSetValue(info.Holder());
lpPropertyInfo->getProc(lpThisValue.get(), szPropertyName, lpPropValue.get());
info.GetReturnValue().Set(lpPropValue->DirectGetValue());
@@ -79,10 +76,8 @@ void V8SetterCallback_Wrapper(v8::Local<v8::String> property,
return;
CFX_ByteStringC szPropertyName(lpPropertyInfo->name);
- std::unique_ptr<CFXJSE_Value> lpThisValue(
- new CFXJSE_Value(info.GetIsolate()));
- std::unique_ptr<CFXJSE_Value> lpPropValue(
- new CFXJSE_Value(info.GetIsolate()));
+ auto lpThisValue = pdfium::MakeUnique<CFXJSE_Value>(info.GetIsolate());
+ auto lpPropValue = pdfium::MakeUnique<CFXJSE_Value>(info.GetIsolate());
lpThisValue->ForceSetValue(info.Holder());
lpPropValue->ForceSetValue(value);
lpPropertyInfo->setProc(lpThisValue.get(), szPropertyName, lpPropValue.get());
@@ -135,10 +130,9 @@ void DynPropGetterAdapter_MethodCallback(
ASSERT(lpClass && !hPropName.IsEmpty());
v8::String::Utf8Value szPropName(hPropName);
CFX_ByteStringC szFxPropName = *szPropName;
- std::unique_ptr<CFXJSE_Value> lpThisValue(
- new CFXJSE_Value(info.GetIsolate()));
+ auto lpThisValue = pdfium::MakeUnique<CFXJSE_Value>(info.GetIsolate());
lpThisValue->ForceSetValue(info.Holder());
- std::unique_ptr<CFXJSE_Value> lpRetValue(new CFXJSE_Value(info.GetIsolate()));
+ auto lpRetValue = pdfium::MakeUnique<CFXJSE_Value>(info.GetIsolate());
CFXJSE_Arguments impl(&info, lpRetValue.get());
lpClass->dynMethodCall(lpThisValue.get(), szFxPropName, impl);
if (!lpRetValue->DirectGetValue().IsEmpty())
@@ -233,8 +227,7 @@ void NamedPropertyQueryCallback(
v8::HandleScope scope(pIsolate);
v8::String::Utf8Value szPropName(property);
CFX_ByteStringC szFxPropName(*szPropName, szPropName.length());
- std::unique_ptr<CFXJSE_Value> lpThisValue(
- new CFXJSE_Value(info.GetIsolate()));
+ auto lpThisValue = pdfium::MakeUnique<CFXJSE_Value>(info.GetIsolate());
lpThisValue->ForceSetValue(thisObject);
if (DynPropQueryAdapter(lpClass, lpThisValue.get(), szFxPropName)) {
info.GetReturnValue().Set(v8::DontDelete);
@@ -254,8 +247,7 @@ void NamedPropertyDeleterCallback(
v8::HandleScope scope(pIsolate);
v8::String::Utf8Value szPropName(property);
CFX_ByteStringC szFxPropName(*szPropName, szPropName.length());
- std::unique_ptr<CFXJSE_Value> lpThisValue(
- new CFXJSE_Value(info.GetIsolate()));
+ auto lpThisValue = pdfium::MakeUnique<CFXJSE_Value>(info.GetIsolate());
lpThisValue->ForceSetValue(thisObject);
info.GetReturnValue().Set(
!!DynPropDeleterAdapter(lpClass, lpThisValue.get(), szFxPropName));
@@ -269,10 +261,9 @@ void NamedPropertyGetterCallback(
info.Data().As<v8::External>()->Value());
v8::String::Utf8Value szPropName(property);
CFX_ByteStringC szFxPropName(*szPropName, szPropName.length());
- std::unique_ptr<CFXJSE_Value> lpThisValue(
- new CFXJSE_Value(info.GetIsolate()));
+ auto lpThisValue = pdfium::MakeUnique<CFXJSE_Value>(info.GetIsolate());
lpThisValue->ForceSetValue(thisObject);
- std::unique_ptr<CFXJSE_Value> lpNewValue(new CFXJSE_Value(info.GetIsolate()));
+ auto lpNewValue = pdfium::MakeUnique<CFXJSE_Value>(info.GetIsolate());
DynPropGetterAdapter(lpClass, lpThisValue.get(), szFxPropName,
lpNewValue.get());
info.GetReturnValue().Set(lpNewValue->DirectGetValue());
@@ -287,11 +278,10 @@ void NamedPropertySetterCallback(
info.Data().As<v8::External>()->Value());
v8::String::Utf8Value szPropName(property);
CFX_ByteStringC szFxPropName(*szPropName, szPropName.length());
- std::unique_ptr<CFXJSE_Value> lpThisValue(
- new CFXJSE_Value(info.GetIsolate()));
+ auto lpThisValue = pdfium::MakeUnique<CFXJSE_Value>(info.GetIsolate());
lpThisValue->ForceSetValue(thisObject);
- std::unique_ptr<CFXJSE_Value> lpNewValue(new CFXJSE_Value(info.GetIsolate()));
+ auto lpNewValue = pdfium::MakeUnique<CFXJSE_Value>(info.GetIsolate());
lpNewValue->ForceSetValue(value);
DynPropSetterAdapter(lpClass, lpThisValue.get(), szFxPropName,
lpNewValue.get());
diff --git a/fxjs/cfxjse_context.cpp b/fxjs/cfxjse_context.cpp
index 076e6cf2b1..d3b55ff43e 100644
--- a/fxjs/cfxjse_context.cpp
+++ b/fxjs/cfxjse_context.cpp
@@ -8,6 +8,7 @@
#include "fxjs/cfxjse_class.h"
#include "fxjs/cfxjse_value.h"
+#include "third_party/base/ptr_util.h"
namespace {
@@ -187,7 +188,7 @@ CFXJSE_Context::CFXJSE_Context(v8::Isolate* pIsolate) : m_pIsolate(pIsolate) {}
CFXJSE_Context::~CFXJSE_Context() {}
std::unique_ptr<CFXJSE_Value> CFXJSE_Context::GetGlobalObject() {
- std::unique_ptr<CFXJSE_Value> pValue(new CFXJSE_Value(m_pIsolate));
+ auto pValue = pdfium::MakeUnique<CFXJSE_Value>(m_pIsolate);
CFXJSE_ScopeUtil_IsolateHandleContext scope(this);
v8::Local<v8::Context> hContext =
diff --git a/testing/libfuzzer/pdf_codec_jbig2_fuzzer.cc b/testing/libfuzzer/pdf_codec_jbig2_fuzzer.cc
index 162a0bf772..e86ebeb242 100644
--- a/testing/libfuzzer/pdf_codec_jbig2_fuzzer.cc
+++ b/testing/libfuzzer/pdf_codec_jbig2_fuzzer.cc
@@ -10,6 +10,7 @@
#include "core/fxcodec/codec/ccodec_jbig2module.h"
#include "core/fxcodec/jbig2/JBig2_Context.h"
#include "core/fxge/fx_dib.h"
+#include "third_party/base/ptr_util.h"
static uint32_t GetInteger(const uint8_t* data) {
return data[0] | data[1] << 8 | data[2] << 16 | data[3] << 24;
@@ -29,7 +30,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
if (!bitmap->Create(width, height, FXDIB_1bppRgb))
return 0;
- std::unique_ptr<CPDF_Object> stream(new CPDF_Stream);
+ auto stream = pdfium::MakeUnique<CPDF_Stream>();
stream->AsStream()->SetData(data, size);
CPDF_StreamAcc src_stream;
src_stream.LoadAllData(stream->AsStream(), true);
diff --git a/testing/libfuzzer/pdf_jpx_fuzzer.cc b/testing/libfuzzer/pdf_jpx_fuzzer.cc
index 92ba210be3..5ac31486f1 100644
--- a/testing/libfuzzer/pdf_jpx_fuzzer.cc
+++ b/testing/libfuzzer/pdf_jpx_fuzzer.cc
@@ -6,18 +6,15 @@
#include <memory>
#include <vector>
+#include "core/fxcodec/codec/cjpx_decoder.h"
#include "core/fxcodec/codec/codec_int.h"
#include "core/fxge/fx_dib.h"
CCodec_JpxModule g_module;
-struct DecoderDeleter {
- void operator()(CJPX_Decoder* decoder) { g_module.DestroyDecoder(decoder); }
-};
-
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- std::unique_ptr<CJPX_Decoder, DecoderDeleter> decoder(
- g_module.CreateDecoder(data, size, nullptr));
+ std::unique_ptr<CJPX_Decoder> decoder =
+ g_module.CreateDecoder(data, size, nullptr);
if (!decoder)
return 0;
diff --git a/xfa/fde/cfde_txtedtpage.cpp b/xfa/fde/cfde_txtedtpage.cpp
index ef16939116..122eb40f7d 100644
--- a/xfa/fde/cfde_txtedtpage.cpp
+++ b/xfa/fde/cfde_txtedtpage.cpp
@@ -215,7 +215,7 @@ int32_t CFDE_TxtEdtPage::SelectWord(const CFX_PointF& fPoint, int32_t& nCount) {
if (nIndex < 0) {
return -1;
}
- std::unique_ptr<CFX_WordBreak> pIter(new CFX_WordBreak);
+ auto pIter = pdfium::MakeUnique<CFX_WordBreak>();
pIter->Attach(new CFDE_TxtEdtBuf::Iterator(pBuf));
pIter->SetAt(nIndex);
nCount = pIter->GetWordLength();
@@ -238,8 +238,8 @@ int32_t CFDE_TxtEdtPage::LoadPage(const CFX_RectF* pClipBox,
if (pParams->dwMode & FDE_TEXTEDITMODE_Password) {
wcAlias = m_pEditEngine->GetAliasChar();
}
- m_pIter.reset(new CFDE_TxtEdtBuf::Iterator(static_cast<CFDE_TxtEdtBuf*>(pBuf),
- wcAlias));
+ m_pIter = pdfium::MakeUnique<CFDE_TxtEdtBuf::Iterator>(
+ static_cast<CFDE_TxtEdtBuf*>(pBuf), wcAlias);
CFX_TxtBreak* pBreak = m_pEditEngine->GetTextBreak();
pBreak->EndBreak(CFX_BreakType::Paragraph);
pBreak->ClearBreakPieces();
diff --git a/xfa/fde/cfde_txtedtparag.cpp b/xfa/fde/cfde_txtedtparag.cpp
index ceff448f2c..bcacc66695 100644
--- a/xfa/fde/cfde_txtedtparag.cpp
+++ b/xfa/fde/cfde_txtedtparag.cpp
@@ -43,8 +43,8 @@ void CFDE_TxtEdtParag::LoadParag() {
if (pParam->dwMode & FDE_TEXTEDITMODE_Password)
wcAlias = m_pEngine->GetAliasChar();
- std::unique_ptr<IFX_CharIter> pIter(new CFDE_TxtEdtBuf::Iterator(
- static_cast<CFDE_TxtEdtBuf*>(pTxtBuf), wcAlias));
+ auto pIter = pdfium::MakeUnique<CFDE_TxtEdtBuf::Iterator>(
+ static_cast<CFDE_TxtEdtBuf*>(pTxtBuf), wcAlias);
pIter->SetAt(m_nCharStart);
int32_t nEndIndex = m_nCharStart + m_nCharCount;
std::vector<int32_t> LineBaseArr;
diff --git a/xfa/fgas/crt/ifgas_stream.cpp b/xfa/fgas/crt/ifgas_stream.cpp
index eef19a59ff..4981145f74 100644
--- a/xfa/fgas/crt/ifgas_stream.cpp
+++ b/xfa/fgas/crt/ifgas_stream.cpp
@@ -1082,7 +1082,7 @@ bool CFGAS_Stream::LoadFile(const wchar_t* pszSrcFileName, uint32_t dwAccess) {
if (!pszSrcFileName || FXSYS_wcslen(pszSrcFileName) < 1)
return false;
- std::unique_ptr<CFGAS_FileStreamImp> pImp(new CFGAS_FileStreamImp());
+ auto pImp = pdfium::MakeUnique<CFGAS_FileStreamImp>();
if (!pImp->LoadFile(pszSrcFileName, dwAccess))
return false;
@@ -1102,7 +1102,7 @@ bool CFGAS_Stream::LoadFileRead(
if (!pFileRead)
return false;
- std::unique_ptr<CFGAS_FileReadStreamImp> pImp(new CFGAS_FileReadStreamImp());
+ auto pImp = pdfium::MakeUnique<CFGAS_FileReadStreamImp>();
if (!pImp->LoadFileRead(pFileRead, dwAccess))
return false;
@@ -1142,7 +1142,7 @@ bool CFGAS_Stream::LoadBuffer(uint8_t* pData,
if (!pData || iTotalSize < 1)
return false;
- std::unique_ptr<CFGAS_BufferStreamImp> pImp(new CFGAS_BufferStreamImp());
+ auto pImp = pdfium::MakeUnique<CFGAS_BufferStreamImp>();
if (!pImp->LoadBuffer(pData, iTotalSize, dwAccess))
return false;
diff --git a/xfa/fwl/cfwl_barcode.cpp b/xfa/fwl/cfwl_barcode.cpp
index e894d25d64..bed8921e0e 100644
--- a/xfa/fwl/cfwl_barcode.cpp
+++ b/xfa/fwl/cfwl_barcode.cpp
@@ -218,7 +218,7 @@ void CFWL_Barcode::CreateBarcodeEngine() {
if (m_pBarcodeEngine || m_type == BC_UNKNOWN)
return;
- std::unique_ptr<CFX_Barcode> pBarcode(new CFX_Barcode);
+ auto pBarcode = pdfium::MakeUnique<CFX_Barcode>();
if (pBarcode->Create(m_type))
m_pBarcodeEngine = std::move(pBarcode);
}
diff --git a/xfa/fwl/cfwl_edit.cpp b/xfa/fwl/cfwl_edit.cpp
index e05f251310..c2b0ddf669 100644
--- a/xfa/fwl/cfwl_edit.cpp
+++ b/xfa/fwl/cfwl_edit.cpp
@@ -566,9 +566,8 @@ void CFWL_Edit::DrawContent(CFX_Graphics* pGraphics,
if (!pRenderDev)
return;
- std::unique_ptr<CFDE_RenderDevice> pRenderDevice(
- new CFDE_RenderDevice(pRenderDev, false));
- std::unique_ptr<CFDE_RenderContext> pRenderContext(new CFDE_RenderContext);
+ auto pRenderDevice = pdfium::MakeUnique<CFDE_RenderDevice>(pRenderDev, false);
+ auto pRenderContext = pdfium::MakeUnique<CFDE_RenderContext>();
pRenderDevice->SetClipRect(rtClip);
pRenderContext->StartRender(pRenderDevice.get(), pPage, mt);
pRenderContext->DoRender(nullptr);
diff --git a/xfa/fxfa/app/cxfa_textlayout.cpp b/xfa/fxfa/app/cxfa_textlayout.cpp
index c8ed4f7f46..f16fd8c1a9 100644
--- a/xfa/fxfa/app/cxfa_textlayout.cpp
+++ b/xfa/fxfa/app/cxfa_textlayout.cpp
@@ -559,8 +559,7 @@ bool CXFA_TextLayout::DrawString(CFX_RenderDevice* pFxDevice,
if (!pFxDevice)
return false;
- std::unique_ptr<CFDE_RenderDevice> pDevice(
- new CFDE_RenderDevice(pFxDevice, false));
+ auto pDevice = pdfium::MakeUnique<CFDE_RenderDevice>(pFxDevice, false);
pDevice->SaveState();
pDevice->SetClipRect(rtClip);
@@ -1176,7 +1175,7 @@ void CXFA_TextLayout::RenderPath(CFDE_RenderDevice* pDevice,
return;
pPen->SetColor(pPiece->dwColor);
- std::unique_ptr<CFDE_Path> pPath(new CFDE_Path);
+ auto pPath = pdfium::MakeUnique<CFDE_Path>();
int32_t iChars = GetDisplayPos(pPiece, pCharPos);
if (iChars > 0) {
CFX_PointF pt1, pt2;
diff --git a/xfa/fxfa/app/xfa_fwltheme.cpp b/xfa/fxfa/app/xfa_fwltheme.cpp
index 4d5b20e438..629cd509e8 100644
--- a/xfa/fxfa/app/xfa_fwltheme.cpp
+++ b/xfa/fxfa/app/xfa_fwltheme.cpp
@@ -44,18 +44,18 @@ CXFA_FFWidget* XFA_ThemeGetOuterWidget(CFWL_Widget* pWidget) {
}
CXFA_FWLTheme::CXFA_FWLTheme(CXFA_FFApp* pApp)
- : m_pCheckBoxTP(new CFWL_CheckBoxTP),
- m_pListBoxTP(new CFWL_ListBoxTP),
- m_pPictureBoxTP(new CFWL_PictureBoxTP),
- m_pSrollBarTP(new CFWL_ScrollBarTP),
- m_pEditTP(new CFWL_EditTP),
- m_pComboBoxTP(new CFWL_ComboBoxTP),
- m_pMonthCalendarTP(new CFWL_MonthCalendarTP),
- m_pDateTimePickerTP(new CFWL_DateTimePickerTP),
- m_pPushButtonTP(new CFWL_PushButtonTP),
- m_pCaretTP(new CFWL_CaretTP),
- m_pBarcodeTP(new CFWL_BarcodeTP),
- m_pTextOut(new CFDE_TextOut),
+ : m_pCheckBoxTP(pdfium::MakeUnique<CFWL_CheckBoxTP>()),
+ m_pListBoxTP(pdfium::MakeUnique<CFWL_ListBoxTP>()),
+ m_pPictureBoxTP(pdfium::MakeUnique<CFWL_PictureBoxTP>()),
+ m_pSrollBarTP(pdfium::MakeUnique<CFWL_ScrollBarTP>()),
+ m_pEditTP(pdfium::MakeUnique<CFWL_EditTP>()),
+ m_pComboBoxTP(pdfium::MakeUnique<CFWL_ComboBoxTP>()),
+ m_pMonthCalendarTP(pdfium::MakeUnique<CFWL_MonthCalendarTP>()),
+ m_pDateTimePickerTP(pdfium::MakeUnique<CFWL_DateTimePickerTP>()),
+ m_pPushButtonTP(pdfium::MakeUnique<CFWL_PushButtonTP>()),
+ m_pCaretTP(pdfium::MakeUnique<CFWL_CaretTP>()),
+ m_pBarcodeTP(pdfium::MakeUnique<CFWL_BarcodeTP>()),
+ m_pTextOut(pdfium::MakeUnique<CFDE_TextOut>()),
m_pCalendarFont(nullptr),
m_pApp(pApp) {
m_Rect.Reset();
diff --git a/xfa/fxfa/cxfa_ffdoc.cpp b/xfa/fxfa/cxfa_ffdoc.cpp
index b5036926aa..0deb864811 100644
--- a/xfa/fxfa/cxfa_ffdoc.cpp
+++ b/xfa/fxfa/cxfa_ffdoc.cpp
@@ -405,7 +405,7 @@ bool CXFA_FFDoc::SavePackage(
const CFX_RetainPtr<IFX_SeekableWriteStream>& pFile,
CFX_ChecksumContext* pCSContext) {
CXFA_Document* doc = m_pDocumentParser->GetDocument();
- std::unique_ptr<CXFA_DataExporter> pExport(new CXFA_DataExporter(doc));
+ auto pExport = pdfium::MakeUnique<CXFA_DataExporter>(doc);
CXFA_Node* pNode = code == XFA_HASHCODE_Xfa ? doc->GetRoot()
: ToNode(doc->GetXFAObject(code));
if (!pNode)
diff --git a/xfa/fxfa/parser/cxfa_scriptcontext.cpp b/xfa/fxfa/parser/cxfa_scriptcontext.cpp
index 37f59bd71b..f539c39f76 100644
--- a/xfa/fxfa/parser/cxfa_scriptcontext.cpp
+++ b/xfa/fxfa/parser/cxfa_scriptcontext.cpp
@@ -153,8 +153,8 @@ bool CXFA_ScriptContext::RunScript(XFA_SCRIPTLANGTYPE eScriptType,
m_eScriptType = eScriptType;
if (eScriptType == XFA_SCRIPTLANGTYPE_Formcalc) {
if (!m_FM2JSContext) {
- m_FM2JSContext.reset(
- new CXFA_FM2JSContext(m_pIsolate, m_JsContext.get(), m_pDocument));
+ m_FM2JSContext = pdfium::MakeUnique<CXFA_FM2JSContext>(
+ m_pIsolate, m_JsContext.get(), m_pDocument);
}
CFX_WideTextBuf wsJavaScript;
CFX_WideString wsErrorInfo;
@@ -492,7 +492,7 @@ bool CXFA_ScriptContext::RunVariablesScript(CXFA_Node* pScriptNode) {
return false;
CFX_ByteString btScript = FX_UTF8Encode(wsScript);
- std::unique_ptr<CFXJSE_Value> hRetValue(new CFXJSE_Value(m_pIsolate));
+ auto hRetValue = pdfium::MakeUnique<CFXJSE_Value>(m_pIsolate);
CXFA_Node* pThisObject = pParent->GetNodeItem(XFA_NODEITEM_Parent);
CFXJSE_Context* pVariablesContext =
CreateVariablesContext(pScriptNode, pThisObject);
@@ -521,7 +521,7 @@ bool CXFA_ScriptContext::QueryVariableValue(CXFA_Node* pScriptNode,
bool bRes = false;
CFXJSE_Context* pVariableContext = static_cast<CFXJSE_Context*>(lpVariables);
std::unique_ptr<CFXJSE_Value> pObject = pVariableContext->GetGlobalObject();
- std::unique_ptr<CFXJSE_Value> hVariableValue(new CFXJSE_Value(m_pIsolate));
+ auto hVariableValue = pdfium::MakeUnique<CFXJSE_Value>(m_pIsolate);
if (!bGetter) {
pObject->SetObjectOwnProperty(szPropName, pValue);
bRes = true;
@@ -545,7 +545,7 @@ void CXFA_ScriptContext::DefineJsClass() {
void CXFA_ScriptContext::RemoveBuiltInObjs(CFXJSE_Context* pContext) const {
static const CFX_ByteStringC OBJ_NAME[2] = {"Number", "Date"};
std::unique_ptr<CFXJSE_Value> pObject = pContext->GetGlobalObject();
- std::unique_ptr<CFXJSE_Value> hProp(new CFXJSE_Value(m_pIsolate));
+ auto hProp = pdfium::MakeUnique<CFXJSE_Value>(m_pIsolate);
for (int i = 0; i < 2; ++i) {
if (pObject->GetObjectProperty(OBJ_NAME[i], hProp.get()))
pObject->DeleteObjectProperty(OBJ_NAME[i]);
@@ -650,7 +650,7 @@ int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refObject,
}
if (rndFind.m_dwFlag == XFA_RESOVENODE_RSTYPE_Attribute &&
rndFind.m_pScriptAttribute && nStart < wsExpression.GetLength()) {
- std::unique_ptr<CFXJSE_Value> pValue(new CFXJSE_Value(m_pIsolate));
+ auto pValue = pdfium::MakeUnique<CFXJSE_Value>(m_pIsolate);
(rndFind.m_Objects.front()
->*(rndFind.m_pScriptAttribute->lpfnCallback))(
pValue.get(), false,
@@ -733,7 +733,7 @@ CFXJSE_Value* CXFA_ScriptContext::GetJSValueFromMap(CXFA_Object* pObject) {
if (iter != m_mapObjectToValue.end())
return iter->second.get();
- std::unique_ptr<CFXJSE_Value> jsValue(new CFXJSE_Value(m_pIsolate));
+ auto jsValue = pdfium::MakeUnique<CFXJSE_Value>(m_pIsolate);
jsValue->SetObject(pObject, m_pJsClass);
CFXJSE_Value* pValue = jsValue.get();
m_mapObjectToValue.insert(std::make_pair(pObject, std::move(jsValue)));
diff --git a/xfa/fxfa/parser/cxfa_simple_parser.cpp b/xfa/fxfa/parser/cxfa_simple_parser.cpp
index 949f7864ea..574ef3a458 100644
--- a/xfa/fxfa/parser/cxfa_simple_parser.cpp
+++ b/xfa/fxfa/parser/cxfa_simple_parser.cpp
@@ -661,7 +661,8 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_TemplateForm(
m_pXMLParser->m_dwCheckStatus != 0x03) {
return nullptr;
}
- std::unique_ptr<CFX_ChecksumContext> pChecksum(new CFX_ChecksumContext);
+
+ auto pChecksum = pdfium::MakeUnique<CFX_ChecksumContext>();
pChecksum->StartChecksum();
pChecksum->UpdateChecksum(m_pFileRead, m_pXMLParser->m_nStart[0],
m_pXMLParser->m_nSize[0]);
diff --git a/xfa/fxfa/parser/cxfa_xml_parser.cpp b/xfa/fxfa/parser/cxfa_xml_parser.cpp
index ebde399931..72564d9fe5 100644
--- a/xfa/fxfa/parser/cxfa_xml_parser.cpp
+++ b/xfa/fxfa/parser/cxfa_xml_parser.cpp
@@ -6,13 +6,15 @@
#include "xfa/fxfa/parser/cxfa_xml_parser.h"
+#include "third_party/base/ptr_util.h"
+
CXFA_XMLParser::CXFA_XMLParser(CFDE_XMLNode* pParent,
const CFX_RetainPtr<IFGAS_Stream>& pStream)
: m_nElementStart(0),
m_dwCheckStatus(0),
m_dwCurrentCheckStatus(0),
m_pStream(pStream),
- m_pParser(new CFDE_XMLSyntaxParser),
+ m_pParser(pdfium::MakeUnique<CFDE_XMLSyntaxParser>()),
m_pParent(pParent),
m_pChild(nullptr),
m_syntaxParserResult(FDE_XmlSyntaxResult::None) {