summaryrefslogtreecommitdiff
path: root/fpdfsdk/pdfwindow
diff options
context:
space:
mode:
authorweili <weili@chromium.org>2016-08-03 11:06:49 -0700
committerCommit bot <commit-bot@chromium.org>2016-08-03 11:06:49 -0700
commit2d5b020304e8a9aa8afeb632c61daa7ece87e36d (patch)
tree4d7f04d4800577fa597b4ca1f1b4d31b87194ef0 /fpdfsdk/pdfwindow
parentca27127240fbca2184f1c576b15b5212d5b314e6 (diff)
downloadpdfium-2d5b020304e8a9aa8afeb632c61daa7ece87e36d.tar.xz
Use smart pointers for class owned pointers
For all classes under /fpdfsdk, use smart pointer to replace raw pointer type for class owned member variables so that memory management will be easier. BUG=pdfium:518 Review-Url: https://codereview.chromium.org/2173253002
Diffstat (limited to 'fpdfsdk/pdfwindow')
-rw-r--r--fpdfsdk/pdfwindow/PWL_FontMap.cpp11
-rw-r--r--fpdfsdk/pdfwindow/PWL_FontMap.h18
-rw-r--r--fpdfsdk/pdfwindow/PWL_Wnd.cpp8
-rw-r--r--fpdfsdk/pdfwindow/PWL_Wnd.h3
4 files changed, 17 insertions, 23 deletions
diff --git a/fpdfsdk/pdfwindow/PWL_FontMap.cpp b/fpdfsdk/pdfwindow/PWL_FontMap.cpp
index 9192afd5e8..96acb78ec2 100644
--- a/fpdfsdk/pdfwindow/PWL_FontMap.cpp
+++ b/fpdfsdk/pdfwindow/PWL_FontMap.cpp
@@ -35,14 +35,11 @@ const char* const g_sDEStandardFontName[] = {"Courier",
} // namespace
CPWL_FontMap::CPWL_FontMap(CFX_SystemHandler* pSystemHandler)
- : m_pPDFDoc(nullptr), m_pSystemHandler(pSystemHandler) {
+ : m_pSystemHandler(pSystemHandler) {
ASSERT(m_pSystemHandler);
}
CPWL_FontMap::~CPWL_FontMap() {
- delete m_pPDFDoc;
- m_pPDFDoc = nullptr;
-
Empty();
}
@@ -53,12 +50,12 @@ void CPWL_FontMap::SetSystemHandler(CFX_SystemHandler* pSystemHandler) {
CPDF_Document* CPWL_FontMap::GetDocument() {
if (!m_pPDFDoc) {
if (CPDF_ModuleMgr::Get()) {
- m_pPDFDoc = new CPDF_Document(nullptr);
+ m_pPDFDoc.reset(new CPDF_Document(nullptr));
m_pPDFDoc->CreateNewDoc();
}
}
- return m_pPDFDoc;
+ return m_pPDFDoc.get();
}
CPDF_Font* CPWL_FontMap::GetPDFFont(int32_t nFontIndex) {
@@ -413,7 +410,7 @@ int32_t CPWL_FontMap::GetNativeCharset() {
return nCharset;
}
-const CPWL_FontMap::CharsetFontMap CPWL_FontMap::defaultTTFMap[] = {
+const FPDF_CharsetFontMap CPWL_FontMap::defaultTTFMap[] = {
{ANSI_CHARSET, "Helvetica"}, {GB2312_CHARSET, "SimSun"},
{CHINESEBIG5_CHARSET, "MingLiU"}, {SHIFTJIS_CHARSET, "MS Gothic"},
{HANGUL_CHARSET, "Batang"}, {RUSSIAN_CHARSET, "Arial"},
diff --git a/fpdfsdk/pdfwindow/PWL_FontMap.h b/fpdfsdk/pdfwindow/PWL_FontMap.h
index 2c40c92a97..7f347f5eb5 100644
--- a/fpdfsdk/pdfwindow/PWL_FontMap.h
+++ b/fpdfsdk/pdfwindow/PWL_FontMap.h
@@ -7,6 +7,8 @@
#ifndef FPDFSDK_PDFWINDOW_PWL_FONTMAP_H_
#define FPDFSDK_PDFWINDOW_PWL_FONTMAP_H_
+#include <memory>
+
#include "core/fpdfdoc/include/ipvt_fontmap.h"
#include "fpdfsdk/fxedit/include/fx_edit.h"
#include "public/fpdf_sysfontinfo.h"
@@ -80,6 +82,8 @@ class CPWL_FontMap : public IPVT_FontMap {
CFX_ByteString& sFontName,
uint8_t nCharset);
+ static const FPDF_CharsetFontMap defaultTTFMap[];
+
protected:
virtual void Initialize();
virtual CPDF_Document* GetDocument();
@@ -102,6 +106,9 @@ class CPWL_FontMap : public IPVT_FontMap {
int32_t nCharset);
CFX_ByteString EncodeFontAlias(const CFX_ByteString& sFontName);
+ CFX_ArrayTemplate<CPWL_FontMap_Data*> m_aData;
+ CFX_ArrayTemplate<CPWL_FontMap_Native*> m_aNativeFont;
+
private:
CFX_ByteString GetFontName(int32_t nFontIndex);
int32_t FindFont(const CFX_ByteString& sFontName,
@@ -109,16 +116,7 @@ class CPWL_FontMap : public IPVT_FontMap {
CFX_ByteString GetNativeFont(int32_t nCharset);
- public:
- using CharsetFontMap = FPDF_CharsetFontMap;
- static const CharsetFontMap defaultTTFMap[];
-
- protected:
- CFX_ArrayTemplate<CPWL_FontMap_Data*> m_aData;
- CFX_ArrayTemplate<CPWL_FontMap_Native*> m_aNativeFont;
-
- private:
- CPDF_Document* m_pPDFDoc;
+ std::unique_ptr<CPDF_Document> m_pPDFDoc;
CFX_SystemHandler* m_pSystemHandler;
};
diff --git a/fpdfsdk/pdfwindow/PWL_Wnd.cpp b/fpdfsdk/pdfwindow/PWL_Wnd.cpp
index e680652bb3..4a479de0dc 100644
--- a/fpdfsdk/pdfwindow/PWL_Wnd.cpp
+++ b/fpdfsdk/pdfwindow/PWL_Wnd.cpp
@@ -80,15 +80,13 @@ void CPWL_Timer::TimerProc(int32_t idEvent) {
pTimer->m_pAttached->TimerProc();
}
-CPWL_TimerHandler::CPWL_TimerHandler() : m_pTimer(nullptr) {}
+CPWL_TimerHandler::CPWL_TimerHandler() {}
-CPWL_TimerHandler::~CPWL_TimerHandler() {
- delete m_pTimer;
-}
+CPWL_TimerHandler::~CPWL_TimerHandler() {}
void CPWL_TimerHandler::BeginTimer(int32_t nElapse) {
if (!m_pTimer)
- m_pTimer = new CPWL_Timer(this, GetSystemHandler());
+ m_pTimer.reset(new CPWL_Timer(this, GetSystemHandler()));
if (m_pTimer)
m_pTimer->SetPWLTimer(nElapse);
diff --git a/fpdfsdk/pdfwindow/PWL_Wnd.h b/fpdfsdk/pdfwindow/PWL_Wnd.h
index 3dfaf5afda..de48a8c82d 100644
--- a/fpdfsdk/pdfwindow/PWL_Wnd.h
+++ b/fpdfsdk/pdfwindow/PWL_Wnd.h
@@ -7,6 +7,7 @@
#ifndef FPDFSDK_PDFWINDOW_PWL_WND_H_
#define FPDFSDK_PDFWINDOW_PWL_WND_H_
+#include <memory>
#include <vector>
#include "core/fpdfdoc/include/cpdf_formcontrol.h"
@@ -238,7 +239,7 @@ class CPWL_TimerHandler {
virtual CFX_SystemHandler* GetSystemHandler() const = 0;
private:
- CPWL_Timer* m_pTimer;
+ std::unique_ptr<CPWL_Timer> m_pTimer;
};
class CPWL_Wnd : public CPWL_TimerHandler {