summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfxfa
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk/fpdfxfa')
-rw-r--r--fpdfsdk/fpdfxfa/fpdfxfa_app.cpp6
-rw-r--r--fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp59
-rw-r--r--fpdfsdk/fpdfxfa/include/fpdfxfa_app.h5
-rw-r--r--fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h14
4 files changed, 40 insertions, 44 deletions
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;