diff options
Diffstat (limited to 'fpdfsdk')
-rw-r--r-- | fpdfsdk/formfiller/cffl_iformfiller.cpp | 11 | ||||
-rw-r--r-- | fpdfsdk/formfiller/cffl_iformfiller.h | 6 | ||||
-rw-r--r-- | fpdfsdk/formfiller/cffl_listbox.cpp | 10 | ||||
-rw-r--r-- | fpdfsdk/formfiller/cffl_listbox.h | 3 | ||||
-rw-r--r-- | fpdfsdk/formfiller/cffl_textfield.cpp | 9 | ||||
-rw-r--r-- | fpdfsdk/formfiller/cffl_textfield.h | 6 | ||||
-rw-r--r-- | fpdfsdk/fpdfxfa/fpdfxfa_app.cpp | 6 | ||||
-rw-r--r-- | fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp | 59 | ||||
-rw-r--r-- | fpdfsdk/fpdfxfa/include/fpdfxfa_app.h | 5 | ||||
-rw-r--r-- | fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h | 14 | ||||
-rw-r--r-- | fpdfsdk/include/fsdk_mgr.h | 2 | ||||
-rw-r--r-- | fpdfsdk/javascript/cjs_context.cpp | 10 | ||||
-rw-r--r-- | fpdfsdk/javascript/cjs_context.h | 8 | ||||
-rw-r--r-- | fpdfsdk/pdfwindow/PWL_FontMap.cpp | 11 | ||||
-rw-r--r-- | fpdfsdk/pdfwindow/PWL_FontMap.h | 18 | ||||
-rw-r--r-- | fpdfsdk/pdfwindow/PWL_Wnd.cpp | 8 | ||||
-rw-r--r-- | fpdfsdk/pdfwindow/PWL_Wnd.h | 3 |
17 files changed, 88 insertions, 101 deletions
diff --git a/fpdfsdk/formfiller/cffl_iformfiller.cpp b/fpdfsdk/formfiller/cffl_iformfiller.cpp index 827c44a102..2fd4af1166 100644 --- a/fpdfsdk/formfiller/cffl_iformfiller.cpp +++ b/fpdfsdk/formfiller/cffl_iformfiller.cpp @@ -24,11 +24,7 @@ CFFL_IFormFiller::CFFL_IFormFiller(CPDFDoc_Environment* pApp) : m_pApp(pApp), m_bNotifying(FALSE) {} -CFFL_IFormFiller::~CFFL_IFormFiller() { - for (auto& it : m_Maps) - delete it.second; - m_Maps.clear(); -} +CFFL_IFormFiller::~CFFL_IFormFiller() {} FX_BOOL CFFL_IFormFiller::Annot_HitTest(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, @@ -511,7 +507,7 @@ CFFL_FormFiller* CFFL_IFormFiller::GetFormFiller(CPDFSDK_Annot* pAnnot, FX_BOOL bRegister) { auto it = m_Maps.find(pAnnot); if (it != m_Maps.end()) - return it->second; + return it->second.get(); if (!bRegister) return nullptr; @@ -547,7 +543,7 @@ CFFL_FormFiller* CFFL_IFormFiller::GetFormFiller(CPDFSDK_Annot* pAnnot, if (!pFormFiller) return nullptr; - m_Maps[pAnnot] = pFormFiller; + m_Maps[pAnnot].reset(pFormFiller); return pFormFiller; } @@ -562,7 +558,6 @@ void CFFL_IFormFiller::UnRegisterFormFiller(CPDFSDK_Annot* pAnnot) { if (it == m_Maps.end()) return; - delete it->second; m_Maps.erase(it); } diff --git a/fpdfsdk/formfiller/cffl_iformfiller.h b/fpdfsdk/formfiller/cffl_iformfiller.h index b01159475a..b5b0e4aed6 100644 --- a/fpdfsdk/formfiller/cffl_iformfiller.h +++ b/fpdfsdk/formfiller/cffl_iformfiller.h @@ -8,6 +8,7 @@ #define FPDFSDK_FORMFILLER_CFFL_IFORMFILLER_H_ #include <map> +#include <memory> #include "fpdfsdk/include/fsdk_define.h" #include "fpdfsdk/pdfwindow/PWL_Edit.h" @@ -140,7 +141,8 @@ class CFFL_IFormFiller : public IPWL_Filler_Notify { #endif // PDF_ENABLE_XFA private: - using CFFL_Widget2Filler = std::map<CPDFSDK_Annot*, CFFL_FormFiller*>; + using CFFL_Widget2Filler = + std::map<CPDFSDK_Annot*, std::unique_ptr<CFFL_FormFiller>>; // IPWL_Filler_Notify: void QueryWherePopup(void* pPrivateData, @@ -170,7 +172,7 @@ class CFFL_IFormFiller : public IPWL_Filler_Notify { #endif // PDF_ENABLE_XFA void UnRegisterFormFiller(CPDFSDK_Annot* pAnnot); - CPDFDoc_Environment* m_pApp; + CPDFDoc_Environment* const m_pApp; CFFL_Widget2Filler m_Maps; FX_BOOL m_bNotifying; }; diff --git a/fpdfsdk/formfiller/cffl_listbox.cpp b/fpdfsdk/formfiller/cffl_listbox.cpp index cbac83cb55..a70a1f33ff 100644 --- a/fpdfsdk/formfiller/cffl_listbox.cpp +++ b/fpdfsdk/formfiller/cffl_listbox.cpp @@ -16,11 +16,9 @@ #define FFL_DEFAULTLISTBOXFONTSIZE 12.0f CFFL_ListBox::CFFL_ListBox(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget) - : CFFL_FormFiller(pApp, pWidget), m_pFontMap(nullptr) {} + : CFFL_FormFiller(pApp, pWidget) {} -CFFL_ListBox::~CFFL_ListBox() { - delete m_pFontMap; -} +CFFL_ListBox::~CFFL_ListBox() {} PWL_CREATEPARAM CFFL_ListBox::GetCreateParam() { PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam(); @@ -37,8 +35,8 @@ PWL_CREATEPARAM CFFL_ListBox::GetCreateParam() { cp.fFontSize = FFL_DEFAULTLISTBOXFONTSIZE; if (!m_pFontMap) - m_pFontMap = new CBA_FontMap(m_pWidget, m_pApp->GetSysHandler()); - cp.pFontMap = m_pFontMap; + m_pFontMap.reset(new CBA_FontMap(m_pWidget, m_pApp->GetSysHandler())); + cp.pFontMap = m_pFontMap.get(); return cp; } diff --git a/fpdfsdk/formfiller/cffl_listbox.h b/fpdfsdk/formfiller/cffl_listbox.h index 43fbab6642..4d1f64f113 100644 --- a/fpdfsdk/formfiller/cffl_listbox.h +++ b/fpdfsdk/formfiller/cffl_listbox.h @@ -7,6 +7,7 @@ #ifndef FPDFSDK_FORMFILLER_CFFL_LISTBOX_H_ #define FPDFSDK_FORMFILLER_CFFL_LISTBOX_H_ +#include <memory> #include <set> #include "fpdfsdk/formfiller/cffl_formfiller.h" @@ -37,7 +38,7 @@ class CFFL_ListBox : public CFFL_FormFiller { FX_BOOL bRestoreValue) override; private: - CBA_FontMap* m_pFontMap; + std::unique_ptr<CBA_FontMap> m_pFontMap; std::set<int> m_OriginSelections; CFX_ArrayTemplate<int> m_State; }; diff --git a/fpdfsdk/formfiller/cffl_textfield.cpp b/fpdfsdk/formfiller/cffl_textfield.cpp index d24452fd45..76f4b7414d 100644 --- a/fpdfsdk/formfiller/cffl_textfield.cpp +++ b/fpdfsdk/formfiller/cffl_textfield.cpp @@ -11,14 +11,11 @@ #include "fpdfsdk/include/fsdk_mgr.h" CFFL_TextField::CFFL_TextField(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot) - : CFFL_FormFiller(pApp, pAnnot), m_pFontMap(nullptr) { - m_State.nStart = m_State.nEnd = 0; -} + : CFFL_FormFiller(pApp, pAnnot) {} CFFL_TextField::~CFFL_TextField() { for (const auto& it : m_Maps) it.second->InvalidateFocusHandler(this); - delete m_pFontMap; } PWL_CREATEPARAM CFFL_TextField::GetCreateParam() { @@ -68,8 +65,8 @@ PWL_CREATEPARAM CFFL_TextField::GetCreateParam() { } if (!m_pFontMap) - m_pFontMap = new CBA_FontMap(m_pWidget, m_pApp->GetSysHandler()); - cp.pFontMap = m_pFontMap; + m_pFontMap.reset(new CBA_FontMap(m_pWidget, m_pApp->GetSysHandler())); + cp.pFontMap = m_pFontMap.get(); cp.pFocusHandler = this; return cp; diff --git a/fpdfsdk/formfiller/cffl_textfield.h b/fpdfsdk/formfiller/cffl_textfield.h index 34968e8fc3..5f9fc5d3bc 100644 --- a/fpdfsdk/formfiller/cffl_textfield.h +++ b/fpdfsdk/formfiller/cffl_textfield.h @@ -7,6 +7,8 @@ #ifndef FPDFSDK_FORMFILLER_CFFL_TEXTFIELD_H_ #define FPDFSDK_FORMFILLER_CFFL_TEXTFIELD_H_ +#include <memory> + #include "fpdfsdk/formfiller/cffl_formfiller.h" #define BF_ALIGN_LEFT 0 @@ -16,6 +18,8 @@ class CBA_FontMap; struct FFL_TextFieldState { + FFL_TextFieldState() : nStart(0), nEnd(0) {} + int nStart; int nEnd; CFX_WideString sValue; @@ -56,7 +60,7 @@ class CFFL_TextField : public CFFL_FormFiller, public IPWL_FocusHandler { #endif // PDF_ENABLE_XFA private: - CBA_FontMap* m_pFontMap; + std::unique_ptr<CBA_FontMap> m_pFontMap; FFL_TextFieldState m_State; }; diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_app.cpp b/fpdfsdk/fpdfxfa/fpdfxfa_app.cpp index 22d84f1f9f..b829246908 100644 --- a/fpdfsdk/fpdfxfa/fpdfxfa_app.cpp +++ b/fpdfsdk/fpdfxfa/fpdfxfa_app.cpp @@ -33,16 +33,12 @@ void CPDFXFA_App::ReleaseInstance() { CPDFXFA_App::CPDFXFA_App() : m_bJavaScriptInitialized(FALSE), - m_pXFAApp(nullptr), m_pIsolate(nullptr), m_csAppType(JS_STR_VIEWERTYPE_STANDARD) { m_pEnvList.RemoveAll(); } CPDFXFA_App::~CPDFXFA_App() { - delete m_pXFAApp; - m_pXFAApp = nullptr; - FXJSE_Runtime_Release(m_pIsolate); m_pIsolate = nullptr; @@ -58,7 +54,7 @@ FX_BOOL CPDFXFA_App::Initialize(v8::Isolate* pIsolate) { if (!m_pIsolate) return FALSE; - m_pXFAApp = new CXFA_FFApp(this); + m_pXFAApp.reset(new CXFA_FFApp(this)); m_pXFAApp->SetDefaultFontMgr( std::unique_ptr<CXFA_DefFontMgr>(new CXFA_DefFontMgr)); diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp b/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp index 95f0cbe25a..2b8b7e3044 100644 --- a/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp +++ b/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp @@ -48,8 +48,6 @@ CPDFXFA_Document::CPDFXFA_Document(CPDF_Document* pPDFDoc, CPDFXFA_App* pProvider) : m_iDocType(DOCTYPE_PDF), m_pPDFDoc(pPDFDoc), - m_pSDKDoc(nullptr), - m_pXFADoc(nullptr), m_pXFADocView(nullptr), m_pApp(pProvider), m_pJSContext(nullptr), @@ -67,11 +65,13 @@ CPDFXFA_Document::~CPDFXFA_Document() { CloseXFADoc(pDocHandler); } } - delete m_pXFADoc; + m_pXFADoc.reset(); } if (m_pJSContext && m_pSDKDoc && m_pSDKDoc->GetEnv()) m_pSDKDoc->GetEnv()->GetJSRuntime()->ReleaseContext(m_pJSContext); - delete m_pSDKDoc; + // |m_pSDKDoc| has to be released before |pParser| and |m_pPDFDoc| since it + // needs to access them to kill focused annotations. + m_pSDKDoc.reset(); if (m_pPDFDoc) { CPDF_Parser* pParser = m_pPDFDoc->GetParser(); if (pParser) @@ -95,7 +95,7 @@ FX_BOOL CPDFXFA_Document::LoadXFADoc() { if (!pApp) return FALSE; - m_pXFADoc = pApp->CreateDoc(this, m_pPDFDoc); + m_pXFADoc.reset(pApp->CreateDoc(this, m_pPDFDoc)); if (!m_pXFADoc) { SetLastError(FPDF_ERR_XFALOAD); return FALSE; @@ -222,8 +222,8 @@ void CPDFXFA_Document::RemovePage(CPDFXFA_Page* page) { CPDFSDK_Document* CPDFXFA_Document::GetSDKDocument( CPDFDoc_Environment* pFormFillEnv) { if (!m_pSDKDoc && pFormFillEnv) - m_pSDKDoc = new CPDFSDK_Document(this, pFormFillEnv); - return m_pSDKDoc; + m_pSDKDoc.reset(new CPDFSDK_Document(this, pFormFillEnv)); + return m_pSDKDoc.get(); } void CPDFXFA_Document::FXRect2PDFRect(const CFX_RectF& fxRectF, @@ -235,7 +235,7 @@ void CPDFXFA_Document::FXRect2PDFRect(const CFX_RectF& fxRectF, } void CPDFXFA_Document::SetChangeMark(CXFA_FFDoc* hDoc) { - if (hDoc == m_pXFADoc && m_pSDKDoc) { + if (hDoc == m_pXFADoc.get() && m_pSDKDoc) { m_pSDKDoc->SetChangeMark(); } } @@ -532,13 +532,13 @@ FX_BOOL CPDFXFA_Document::RenderCustomWidget(CXFA_FFWidget* hWidget, } int32_t CPDFXFA_Document::CountPages(CXFA_FFDoc* hDoc) { - if (hDoc == m_pXFADoc && m_pSDKDoc) + if (hDoc == m_pXFADoc.get() && m_pSDKDoc) return GetPageCount(); return 0; } int32_t CPDFXFA_Document::GetCurrentPage(CXFA_FFDoc* hDoc) { - if (hDoc != m_pXFADoc || !m_pSDKDoc) + if (hDoc != m_pXFADoc.get() || !m_pSDKDoc) return -1; if (m_iDocType != DOCTYPE_DYNAMIC_XFA) return -1; @@ -551,8 +551,9 @@ int32_t CPDFXFA_Document::GetCurrentPage(CXFA_FFDoc* hDoc) { } void CPDFXFA_Document::SetCurrentPage(CXFA_FFDoc* hDoc, int32_t iCurPage) { - if (hDoc != m_pXFADoc || !m_pSDKDoc || m_iDocType != DOCTYPE_DYNAMIC_XFA || - iCurPage < 0 || iCurPage >= m_pSDKDoc->GetPageCount()) { + if (hDoc != m_pXFADoc.get() || !m_pSDKDoc || + m_iDocType != DOCTYPE_DYNAMIC_XFA || iCurPage < 0 || + iCurPage >= m_pSDKDoc->GetPageCount()) { return; } CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); @@ -561,7 +562,7 @@ void CPDFXFA_Document::SetCurrentPage(CXFA_FFDoc* hDoc, int32_t iCurPage) { pEnv->FFI_SetCurrentPage(this, iCurPage); } FX_BOOL CPDFXFA_Document::IsCalculationsEnabled(CXFA_FFDoc* hDoc) { - if (hDoc != m_pXFADoc || !m_pSDKDoc) + if (hDoc != m_pXFADoc.get() || !m_pSDKDoc) return FALSE; if (m_pSDKDoc->GetInterForm()) return m_pSDKDoc->GetInterForm()->IsXfaCalculateEnabled(); @@ -570,14 +571,14 @@ FX_BOOL CPDFXFA_Document::IsCalculationsEnabled(CXFA_FFDoc* hDoc) { } void CPDFXFA_Document::SetCalculationsEnabled(CXFA_FFDoc* hDoc, FX_BOOL bEnabled) { - if (hDoc != m_pXFADoc || !m_pSDKDoc) + if (hDoc != m_pXFADoc.get() || !m_pSDKDoc) return; if (m_pSDKDoc->GetInterForm()) m_pSDKDoc->GetInterForm()->XfaEnableCalculate(bEnabled); } void CPDFXFA_Document::GetTitle(CXFA_FFDoc* hDoc, CFX_WideString& wsTitle) { - if (hDoc != m_pXFADoc || !m_pPDFDoc) + if (hDoc != m_pXFADoc.get() || !m_pPDFDoc) return; CPDF_Dictionary* pInfoDict = m_pPDFDoc->GetInfo(); @@ -591,7 +592,7 @@ void CPDFXFA_Document::GetTitle(CXFA_FFDoc* hDoc, CFX_WideString& wsTitle) { void CPDFXFA_Document::SetTitle(CXFA_FFDoc* hDoc, const CFX_WideString& wsTitle) { - if (hDoc != m_pXFADoc || !m_pPDFDoc) + if (hDoc != m_pXFADoc.get() || !m_pPDFDoc) return; if (CPDF_Dictionary* pInfoDict = m_pPDFDoc->GetInfo()) @@ -601,7 +602,7 @@ void CPDFXFA_Document::SetTitle(CXFA_FFDoc* hDoc, void CPDFXFA_Document::ExportData(CXFA_FFDoc* hDoc, const CFX_WideString& wsFilePath, FX_BOOL bXDP) { - if (hDoc != m_pXFADoc) + if (hDoc != m_pXFADoc.get()) return; if (m_iDocType != DOCTYPE_DYNAMIC_XFA && m_iDocType != DOCTYPE_STATIC_XFA) @@ -694,7 +695,7 @@ void CPDFXFA_Document::ImportData(CXFA_FFDoc* hDoc, void CPDFXFA_Document::GotoURL(CXFA_FFDoc* hDoc, const CFX_WideString& bsURL, FX_BOOL bAppend) { - if (hDoc != m_pXFADoc) + if (hDoc != m_pXFADoc.get()) return; if (m_iDocType != DOCTYPE_DYNAMIC_XFA) @@ -710,7 +711,7 @@ void CPDFXFA_Document::GotoURL(CXFA_FFDoc* hDoc, } FX_BOOL CPDFXFA_Document::IsValidationsEnabled(CXFA_FFDoc* hDoc) { - if (hDoc != m_pXFADoc || !m_pSDKDoc) + if (hDoc != m_pXFADoc.get() || !m_pSDKDoc) return FALSE; if (m_pSDKDoc->GetInterForm()) return m_pSDKDoc->GetInterForm()->IsXfaValidationsEnabled(); @@ -719,14 +720,14 @@ FX_BOOL CPDFXFA_Document::IsValidationsEnabled(CXFA_FFDoc* hDoc) { } void CPDFXFA_Document::SetValidationsEnabled(CXFA_FFDoc* hDoc, FX_BOOL bEnabled) { - if (hDoc != m_pXFADoc || !m_pSDKDoc) + if (hDoc != m_pXFADoc.get() || !m_pSDKDoc) return; if (m_pSDKDoc->GetInterForm()) m_pSDKDoc->GetInterForm()->XfaSetValidationsEnabled(bEnabled); } void CPDFXFA_Document::SetFocusWidget(CXFA_FFDoc* hDoc, CXFA_FFWidget* hWidget) { - if (hDoc != m_pXFADoc) + if (hDoc != m_pXFADoc.get()) return; if (!hWidget) { @@ -750,7 +751,7 @@ void CPDFXFA_Document::Print(CXFA_FFDoc* hDoc, int32_t nStartPage, int32_t nEndPage, uint32_t dwOptions) { - if (hDoc != m_pXFADoc) + if (hDoc != m_pXFADoc.get()) return; CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); @@ -812,7 +813,7 @@ FX_BOOL CPDFXFA_Document::Clear(CXFA_FFDoc* hDoc, } void CPDFXFA_Document::GetURL(CXFA_FFDoc* hDoc, CFX_WideString& wsDocURL) { - if (hDoc != m_pXFADoc) + if (hDoc != m_pXFADoc.get()) return; CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); @@ -823,7 +824,7 @@ void CPDFXFA_Document::GetURL(CXFA_FFDoc* hDoc, CFX_WideString& wsDocURL) { } FX_ARGB CPDFXFA_Document::GetHighlightColor(CXFA_FFDoc* hDoc) { - if (hDoc != m_pXFADoc) + if (hDoc != m_pXFADoc.get()) return 0; if (m_pSDKDoc) { if (CPDFSDK_InterForm* pInterForm = m_pSDKDoc->GetInterForm()) { @@ -1236,7 +1237,7 @@ FX_BOOL CPDFXFA_Document::_SubmitData(CXFA_FFDoc* hDoc, CXFA_Submit submit) { FX_BOOL CPDFXFA_Document::SetGlobalProperty(CXFA_FFDoc* hDoc, const CFX_ByteStringC& szPropName, CFXJSE_Value* pValue) { - if (hDoc != m_pXFADoc) + if (hDoc != m_pXFADoc.get()) return FALSE; if (m_pSDKDoc && m_pSDKDoc->GetEnv()->GetJSRuntime()) @@ -1247,14 +1248,14 @@ FX_BOOL CPDFXFA_Document::SetGlobalProperty(CXFA_FFDoc* hDoc, FX_BOOL CPDFXFA_Document::GetPDFScriptObject(CXFA_FFDoc* hDoc, const CFX_ByteStringC& utf8Name, CFXJSE_Value* pValue) { - if (hDoc != m_pXFADoc) + if (hDoc != m_pXFADoc.get()) return FALSE; if (!m_pSDKDoc || !m_pSDKDoc->GetEnv()->GetJSRuntime()) return FALSE; if (!m_pJSContext) { - m_pSDKDoc->GetEnv()->GetJSRuntime()->SetReaderDocument(m_pSDKDoc); + m_pSDKDoc->GetEnv()->GetJSRuntime()->SetReaderDocument(m_pSDKDoc.get()); m_pJSContext = m_pSDKDoc->GetEnv()->GetJSRuntime()->NewContext(); } @@ -1263,13 +1264,13 @@ FX_BOOL CPDFXFA_Document::GetPDFScriptObject(CXFA_FFDoc* hDoc, FX_BOOL CPDFXFA_Document::GetGlobalProperty(CXFA_FFDoc* hDoc, const CFX_ByteStringC& szPropName, CFXJSE_Value* pValue) { - if (hDoc != m_pXFADoc) + if (hDoc != m_pXFADoc.get()) return FALSE; if (!m_pSDKDoc || !m_pSDKDoc->GetEnv()->GetJSRuntime()) return FALSE; if (!m_pJSContext) { - m_pSDKDoc->GetEnv()->GetJSRuntime()->SetReaderDocument(m_pSDKDoc); + m_pSDKDoc->GetEnv()->GetJSRuntime()->SetReaderDocument(m_pSDKDoc.get()); m_pJSContext = m_pSDKDoc->GetEnv()->GetJSRuntime()->NewContext(); } diff --git a/fpdfsdk/fpdfxfa/include/fpdfxfa_app.h b/fpdfsdk/fpdfxfa/include/fpdfxfa_app.h index 5ebb2c2623..18cac4405b 100644 --- a/fpdfsdk/fpdfxfa/include/fpdfxfa_app.h +++ b/fpdfsdk/fpdfxfa/include/fpdfxfa_app.h @@ -21,7 +21,7 @@ class CPDFXFA_App : public IXFA_AppProvider { ~CPDFXFA_App() override; FX_BOOL Initialize(v8::Isolate* pIsolate); - CXFA_FFApp* GetXFAApp() { return m_pXFAApp; } + CXFA_FFApp* GetXFAApp() { return m_pXFAApp.get(); } FX_BOOL AddFormFillEnv(CPDFDoc_Environment* pEnv); FX_BOOL RemoveFormFillEnv(CPDFDoc_Environment* pEnv); @@ -74,9 +74,8 @@ class CPDFXFA_App : public IXFA_AppProvider { protected: FX_BOOL m_bJavaScriptInitialized; - CXFA_FFApp* m_pXFAApp; + std::unique_ptr<CXFA_FFApp> m_pXFAApp; v8::Isolate* m_pIsolate; - IFXJS_Runtime* m_pJSRuntime; CFX_WideString m_csAppType; }; diff --git a/fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h b/fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h index 21a5b13cfa..ed4c8727fc 100644 --- a/fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h +++ b/fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h @@ -9,6 +9,7 @@ #include "xfa/fxfa/include/xfa_ffdoc.h" +#include <memory> #include <vector> #include "public/fpdfview.h" @@ -32,7 +33,7 @@ class CPDFXFA_Document : public IXFA_DocProvider { FX_BOOL LoadXFADoc(); CPDFXFA_App* GetApp() { return m_pApp; } CPDF_Document* GetPDFDoc() { return m_pPDFDoc; } - CXFA_FFDoc* GetXFADoc() { return m_pXFADoc; } + CXFA_FFDoc* GetXFADoc() { return m_pXFADoc.get(); } CXFA_FFDocView* GetXFADocView() { return m_pXFADocView; } int GetPageCount(); @@ -193,18 +194,17 @@ class CPDFXFA_Document : public IXFA_DocProvider { void CloseXFADoc(CXFA_FFDocHandler* pDoc) { if (pDoc) { m_pXFADoc->CloseDoc(); - delete m_pXFADoc; - m_pXFADoc = nullptr; + m_pXFADoc.reset(); m_pXFADocView = nullptr; } } int m_iDocType; CPDF_Document* m_pPDFDoc; - CPDFSDK_Document* m_pSDKDoc; - CXFA_FFDoc* m_pXFADoc; - CXFA_FFDocView* m_pXFADocView; - CPDFXFA_App* m_pApp; + std::unique_ptr<CPDFSDK_Document> m_pSDKDoc; + std::unique_ptr<CXFA_FFDoc> m_pXFADoc; + CXFA_FFDocView* m_pXFADocView; // not owned. + CPDFXFA_App* const m_pApp; IJS_Context* m_pJSContext; CFX_ArrayTemplate<CPDFXFA_Page*> m_XFAPageList; LoadStatus m_nLoadStatus; diff --git a/fpdfsdk/include/fsdk_mgr.h b/fpdfsdk/include/fsdk_mgr.h index b87c982cc1..1c180db57f 100644 --- a/fpdfsdk/include/fsdk_mgr.h +++ b/fpdfsdk/include/fsdk_mgr.h @@ -619,7 +619,7 @@ class CPDFSDK_PageView final : public CPDF_Page::View { UnderlyingPageType* const m_page; std::unique_ptr<CPDF_AnnotList> m_pAnnotList; std::vector<CPDFSDK_Annot*> m_fxAnnotArray; - CPDFSDK_Document* m_pSDKDoc; + CPDFSDK_Document* const m_pSDKDoc; #ifdef PDF_ENABLE_XFA CPDFSDK_Annot* m_CaptureWidget; #else // PDF_ENABLE_XFA diff --git a/fpdfsdk/javascript/cjs_context.cpp b/fpdfsdk/javascript/cjs_context.cpp index 406339d7af..06abf7f48d 100644 --- a/fpdfsdk/javascript/cjs_context.cpp +++ b/fpdfsdk/javascript/cjs_context.cpp @@ -11,13 +11,11 @@ #include "fpdfsdk/javascript/resource.h" CJS_Context::CJS_Context(CJS_Runtime* pRuntime) - : m_pRuntime(pRuntime), m_bBusy(FALSE) { - m_pEventHandler = new CJS_EventHandler(this); -} + : m_pRuntime(pRuntime), + m_pEventHandler(new CJS_EventHandler(this)), + m_bBusy(FALSE) {} -CJS_Context::~CJS_Context() { - delete m_pEventHandler; -} +CJS_Context::~CJS_Context() {} CPDFSDK_Document* CJS_Context::GetReaderDocument() { return m_pRuntime->GetReaderDocument(); diff --git a/fpdfsdk/javascript/cjs_context.h b/fpdfsdk/javascript/cjs_context.h index cccdbc7669..49ba42c6d1 100644 --- a/fpdfsdk/javascript/cjs_context.h +++ b/fpdfsdk/javascript/cjs_context.h @@ -7,6 +7,8 @@ #ifndef FPDFSDK_JAVASCRIPT_CJS_CONTEXT_H_ #define FPDFSDK_JAVASCRIPT_CJS_CONTEXT_H_ +#include <memory> + #include "core/fxcrt/include/fx_string.h" #include "core/fxcrt/include/fx_system.h" #include "fpdfsdk/javascript/ijs_context.h" @@ -121,14 +123,14 @@ class CJS_Context : public IJS_Context { void OnExternal_Exec() override; CJS_Runtime* GetJSRuntime() const { return m_pRuntime; } - CJS_EventHandler* GetEventHandler() const { return m_pEventHandler; } + CJS_EventHandler* GetEventHandler() const { return m_pEventHandler.get(); } CPDFDoc_Environment* GetReaderApp(); CPDFSDK_Document* GetReaderDocument(); private: - CJS_Runtime* m_pRuntime; - CJS_EventHandler* m_pEventHandler; + CJS_Runtime* const m_pRuntime; + std::unique_ptr<CJS_EventHandler> m_pEventHandler; FX_BOOL m_bBusy; }; 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 { |