summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfxfa
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk/fpdfxfa')
-rw-r--r--fpdfsdk/fpdfxfa/DEPS1
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_app.cpp150
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_app.h19
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_document.cpp39
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_document.h17
5 files changed, 79 insertions, 147 deletions
diff --git a/fpdfsdk/fpdfxfa/DEPS b/fpdfsdk/fpdfxfa/DEPS
index d4de6f1e89..1687e308b5 100644
--- a/fpdfsdk/fpdfxfa/DEPS
+++ b/fpdfsdk/fpdfxfa/DEPS
@@ -1,3 +1,4 @@
include_rules = [
+ '+fxjs',
'+xfa/fxbarcode',
]
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_app.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_app.cpp
index 61694d0a28..569e314186 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_app.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_app.cpp
@@ -11,110 +11,49 @@
#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
#include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h"
#include "fpdfsdk/fsdk_define.h"
+#include "fxjs/fxjs_v8.h"
#include "third_party/base/ptr_util.h"
-#include "xfa/fxbarcode/BC_Library.h"
#include "xfa/fxfa/xfa_ffapp.h"
#include "xfa/fxfa/xfa_fontmgr.h"
-namespace {
-
-CPDFXFA_App* g_pApp = nullptr;
-
-} // namespace
-
-CPDFXFA_App* CPDFXFA_App::GetInstance() {
- if (!g_pApp) {
- g_pApp = new CPDFXFA_App();
- }
- return g_pApp;
-}
-
-void CPDFXFA_App::ReleaseInstance() {
- delete g_pApp;
- g_pApp = nullptr;
-}
-
-CPDFXFA_App::CPDFXFA_App()
- : m_bJavaScriptInitialized(FALSE), m_pIsolate(nullptr) {
- m_pFormFillEnvList.RemoveAll();
-}
-
-CPDFXFA_App::~CPDFXFA_App() {
- FXJSE_Runtime_Release(m_pIsolate);
- m_pIsolate = nullptr;
-
- FXJSE_Finalize();
- BC_Library_Destory();
-}
-
-FX_BOOL CPDFXFA_App::Initialize(v8::Isolate* pIsolate) {
- BC_Library_Init();
- FXJSE_Initialize();
-
- m_pIsolate = pIsolate ? pIsolate : FXJSE_Runtime_Create_Own();
- if (!m_pIsolate)
- return FALSE;
+CPDFXFA_App::CPDFXFA_App() : m_pIsolate(nullptr) {
+ m_bOwnsIsolate = FXJS_GetIsolate(&m_pIsolate);
m_pXFAApp = pdfium::MakeUnique<CXFA_FFApp>(this);
- m_pXFAApp->SetDefaultFontMgr(
- std::unique_ptr<CXFA_DefFontMgr>(new CXFA_DefFontMgr));
-
- return TRUE;
-}
-
-FX_BOOL CPDFXFA_App::AddFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv) {
- if (!pFormFillEnv)
- return FALSE;
-
- m_pFormFillEnvList.Add(pFormFillEnv);
- return TRUE;
+ m_pXFAApp->SetDefaultFontMgr(pdfium::MakeUnique<CXFA_DefFontMgr>());
}
-FX_BOOL CPDFXFA_App::RemoveFormFillEnv(
- CPDFSDK_FormFillEnvironment* pFormFillEnv) {
- if (!pFormFillEnv)
- return FALSE;
-
- int nFind = m_pFormFillEnvList.Find(pFormFillEnv);
- if (nFind != -1) {
- m_pFormFillEnvList.RemoveAt(nFind);
- return TRUE;
- }
-
- return FALSE;
+CPDFXFA_App::~CPDFXFA_App() {
+ if (m_bOwnsIsolate)
+ m_pIsolate->Dispose();
}
void CPDFXFA_App::GetAppName(CFX_WideString& wsName) {
- CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0);
- if (pFormFillEnv)
- wsName = pFormFillEnv->FFI_GetAppName();
+ if (m_pFormFillEnv)
+ wsName = m_pFormFillEnv->FFI_GetAppName();
}
void CPDFXFA_App::GetLanguage(CFX_WideString& wsLanguage) {
- CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0);
- if (pFormFillEnv)
- wsLanguage = pFormFillEnv->GetLanguage();
+ if (m_pFormFillEnv)
+ wsLanguage = m_pFormFillEnv->GetLanguage();
}
void CPDFXFA_App::GetPlatform(CFX_WideString& wsPlatform) {
- CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0);
- if (pFormFillEnv) {
- wsPlatform = pFormFillEnv->GetPlatform();
+ if (m_pFormFillEnv) {
+ wsPlatform = m_pFormFillEnv->GetPlatform();
}
}
void CPDFXFA_App::Beep(uint32_t dwType) {
- CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0);
- if (pFormFillEnv)
- pFormFillEnv->JS_appBeep(dwType);
+ if (m_pFormFillEnv)
+ m_pFormFillEnv->JS_appBeep(dwType);
}
int32_t CPDFXFA_App::MsgBox(const CFX_WideString& wsMessage,
const CFX_WideString& wsTitle,
uint32_t dwIconType,
uint32_t dwButtonType) {
- CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0);
- if (!pFormFillEnv)
+ if (!m_pFormFillEnv)
return -1;
uint32_t iconType = 0;
@@ -147,8 +86,8 @@ int32_t CPDFXFA_App::MsgBox(const CFX_WideString& wsMessage,
iButtonType |= 3;
break;
}
- int32_t iRet = pFormFillEnv->JS_appAlert(wsMessage.c_str(), wsTitle.c_str(),
- iButtonType, iconType);
+ int32_t iRet = m_pFormFillEnv->JS_appAlert(wsMessage.c_str(), wsTitle.c_str(),
+ iButtonType, iconType);
switch (iRet) {
case 1:
return XFA_IDOK;
@@ -167,29 +106,29 @@ CFX_WideString CPDFXFA_App::Response(const CFX_WideString& wsQuestion,
const CFX_WideString& wsDefaultAnswer,
FX_BOOL bMark) {
CFX_WideString wsAnswer;
- CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0);
- if (pFormFillEnv) {
- int nLength = 2048;
- char* pBuff = new char[nLength];
- nLength = pFormFillEnv->JS_appResponse(wsQuestion.c_str(), wsTitle.c_str(),
+ if (!m_pFormFillEnv)
+ return wsAnswer;
+
+ int nLength = 2048;
+ char* pBuff = new char[nLength];
+ nLength = m_pFormFillEnv->JS_appResponse(wsQuestion.c_str(), wsTitle.c_str(),
wsDefaultAnswer.c_str(), nullptr,
bMark, pBuff, nLength);
- if (nLength > 0) {
- nLength = nLength > 2046 ? 2046 : nLength;
- pBuff[nLength] = 0;
- pBuff[nLength + 1] = 0;
- wsAnswer = CFX_WideString::FromUTF16LE(
- reinterpret_cast<const unsigned short*>(pBuff),
- nLength / sizeof(unsigned short));
- }
- delete[] pBuff;
+ if (nLength > 0) {
+ nLength = nLength > 2046 ? 2046 : nLength;
+ pBuff[nLength] = 0;
+ pBuff[nLength + 1] = 0;
+ wsAnswer = CFX_WideString::FromUTF16LE(
+ reinterpret_cast<const unsigned short*>(pBuff),
+ nLength / sizeof(unsigned short));
}
+ delete[] pBuff;
return wsAnswer;
}
IFX_FileRead* CPDFXFA_App::DownloadURL(const CFX_WideString& wsURL) {
- CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0);
- return pFormFillEnv ? pFormFillEnv->DownloadFromURL(wsURL.c_str()) : nullptr;
+ return m_pFormFillEnv ? m_pFormFillEnv->DownloadFromURL(wsURL.c_str())
+ : nullptr;
}
FX_BOOL CPDFXFA_App::PostRequestURL(const CFX_WideString& wsURL,
@@ -198,23 +137,21 @@ FX_BOOL CPDFXFA_App::PostRequestURL(const CFX_WideString& wsURL,
const CFX_WideString& wsEncode,
const CFX_WideString& wsHeader,
CFX_WideString& wsResponse) {
- CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0);
- if (!pFormFillEnv)
+ if (!m_pFormFillEnv)
return FALSE;
- wsResponse = pFormFillEnv->PostRequestURL(wsURL.c_str(), wsData.c_str(),
- wsContentType.c_str(),
- wsEncode.c_str(), wsHeader.c_str());
+ wsResponse = m_pFormFillEnv->PostRequestURL(
+ wsURL.c_str(), wsData.c_str(), wsContentType.c_str(), wsEncode.c_str(),
+ wsHeader.c_str());
return TRUE;
}
FX_BOOL CPDFXFA_App::PutRequestURL(const CFX_WideString& wsURL,
const CFX_WideString& wsData,
const CFX_WideString& wsEncode) {
- CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0);
- return pFormFillEnv &&
- pFormFillEnv->PutRequestURL(wsURL.c_str(), wsData.c_str(),
- wsEncode.c_str());
+ return m_pFormFillEnv &&
+ m_pFormFillEnv->PutRequestURL(wsURL.c_str(), wsData.c_str(),
+ wsEncode.c_str());
}
void CPDFXFA_App::LoadString(int32_t iStringID, CFX_WideString& wsString) {
@@ -316,8 +253,7 @@ void CPDFXFA_App::LoadString(int32_t iStringID, CFX_WideString& wsString) {
IFWL_AdapterTimerMgr* CPDFXFA_App::GetTimerMgr() {
CXFA_FWLAdapterTimerMgr* pAdapter = nullptr;
- CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0);
- if (pFormFillEnv)
- pAdapter = new CXFA_FWLAdapterTimerMgr(pFormFillEnv);
+ if (m_pFormFillEnv)
+ pAdapter = new CXFA_FWLAdapterTimerMgr(m_pFormFillEnv);
return pAdapter;
}
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_app.h b/fpdfsdk/fpdfxfa/cpdfxfa_app.h
index 78184d1434..c867df2388 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_app.h
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_app.h
@@ -14,21 +14,13 @@ class IFXJS_Runtime;
class CPDFXFA_App : public IXFA_AppProvider {
public:
- static CPDFXFA_App* GetInstance();
- static void ReleaseInstance();
-
CPDFXFA_App();
~CPDFXFA_App() override;
- FX_BOOL Initialize(v8::Isolate* pIsolate);
CXFA_FFApp* GetXFAApp() { return m_pXFAApp.get(); }
- FX_BOOL AddFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv);
- FX_BOOL RemoveFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv);
-
- FX_BOOL IsJavaScriptInitialized() const { return m_bJavaScriptInitialized; }
- void SetJavaScriptInitialized(FX_BOOL bInitialized) {
- m_bJavaScriptInitialized = bInitialized;
+ void SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv) {
+ m_pFormFillEnv = pFormFillEnv;
}
v8::Isolate* GetJSERuntime() const { return m_pIsolate; }
@@ -62,12 +54,11 @@ class CPDFXFA_App : public IXFA_AppProvider {
void LoadString(int32_t iStringID, CFX_WideString& wsString) override;
IFWL_AdapterTimerMgr* GetTimerMgr() override;
- CFX_ArrayTemplate<CPDFSDK_FormFillEnvironment*> m_pFormFillEnvList;
-
- protected:
- FX_BOOL m_bJavaScriptInitialized;
+ private:
+ CPDFSDK_FormFillEnvironment* m_pFormFillEnv; // Not owned.
std::unique_ptr<CXFA_FFApp> m_pXFAApp;
v8::Isolate* m_pIsolate;
+ bool m_bOwnsIsolate;
};
#endif // FPDFSDK_FPDFXFA_CPDFXFA_APP_H_
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_document.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_document.cpp
index df0da31beb..79d28c0637 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_document.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_document.cpp
@@ -16,6 +16,7 @@
#include "fpdfsdk/fsdk_define.h"
#include "fpdfsdk/javascript/ijs_runtime.h"
#include "public/fpdf_formfill.h"
+#include "third_party/base/ptr_util.h"
#include "xfa/fxfa/cxfa_eventparam.h"
#include "xfa/fxfa/xfa_ffapp.h"
#include "xfa/fxfa/xfa_ffdoc.h"
@@ -28,13 +29,11 @@ extern void SetLastError(int err);
extern int GetLastError();
#endif
-CPDFXFA_Document::CPDFXFA_Document(std::unique_ptr<CPDF_Document> pPDFDoc,
- CPDFXFA_App* pProvider)
+CPDFXFA_Document::CPDFXFA_Document(std::unique_ptr<CPDF_Document> pPDFDoc)
: m_iDocType(DOCTYPE_PDF),
m_pPDFDoc(std::move(pPDFDoc)),
m_pFormFillEnv(nullptr),
m_pXFADocView(nullptr),
- m_pApp(pProvider),
m_nLoadStatus(FXFA_LOADSTATUS_PRELOAD),
m_nPageCount(0),
m_DocEnv(this) {}
@@ -42,6 +41,12 @@ CPDFXFA_Document::CPDFXFA_Document(std::unique_ptr<CPDF_Document> pPDFDoc,
CPDFXFA_Document::~CPDFXFA_Document() {
m_nLoadStatus = FXFA_LOADSTATUS_CLOSING;
+ // Must happen before we remove the form fill environment.
+ if (m_pXFADoc) {
+ if (CXFA_FFApp* pApp = GetApp()->GetXFAApp())
+ CloseXFADoc(pApp->GetDocHandler());
+ }
+
if (m_pFormFillEnv) {
m_pFormFillEnv->ClearAllFocusedAnnots();
// Once we're deleted the FormFillEnvironment will point at a bad underlying
@@ -50,19 +55,23 @@ CPDFXFA_Document::~CPDFXFA_Document() {
m_pFormFillEnv = nullptr;
}
- if (m_pXFADoc) {
- CXFA_FFApp* pApp = m_pApp->GetXFAApp();
- if (pApp) {
- CXFA_FFDocHandler* pDocHandler = pApp->GetDocHandler();
- if (pDocHandler)
- CloseXFADoc(pDocHandler);
- }
- m_pXFADoc.reset();
- }
-
m_nLoadStatus = FXFA_LOADSTATUS_CLOSED;
}
+void CPDFXFA_Document::CloseXFADoc(CXFA_FFDocHandler* pDoc) {
+ if (!pDoc)
+ return;
+ m_pXFADoc->CloseDoc();
+ m_pXFADoc.reset();
+ m_pXFADocView = nullptr;
+}
+
+CPDFXFA_App* CPDFXFA_Document::GetApp() {
+ if (!m_pApp)
+ m_pApp = pdfium::MakeUnique<CPDFXFA_App>();
+ return m_pApp.get();
+}
+
FX_BOOL CPDFXFA_Document::LoadXFADoc() {
m_nLoadStatus = FXFA_LOADSTATUS_LOADING;
@@ -71,7 +80,7 @@ FX_BOOL CPDFXFA_Document::LoadXFADoc() {
m_XFAPageList.RemoveAll();
- CXFA_FFApp* pApp = m_pApp->GetXFAApp();
+ CXFA_FFApp* pApp = GetApp()->GetXFAApp();
if (!pApp)
return FALSE;
@@ -95,7 +104,7 @@ FX_BOOL CPDFXFA_Document::LoadXFADoc() {
return FALSE;
}
m_pXFADoc->StopLoad();
- m_pXFADoc->GetXFADoc()->InitScriptContext(m_pApp->GetJSERuntime());
+ m_pXFADoc->GetXFADoc()->InitScriptContext(GetApp()->GetJSERuntime());
if (m_pXFADoc->GetDocType() == XFA_DOCTYPE_Dynamic)
m_iDocType = DOCTYPE_DYNAMIC_XFA;
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_document.h b/fpdfsdk/fpdfxfa/cpdfxfa_document.h
index de997c16f3..88c0e60f2d 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_document.h
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_document.h
@@ -9,11 +9,11 @@
#include <memory>
+#include "fpdfsdk/fpdfxfa/cpdfxfa_app.h"
#include "fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h"
#include "xfa/fxfa/xfa_ffdoc.h"
class CPDFSDK_FormFillEnvironment;
-class CPDFXFA_App;
class CPDFXFA_Page;
class CXFA_FFDocHandler;
class IJS_Runtime;
@@ -29,8 +29,7 @@ enum LoadStatus {
class CPDFXFA_Document {
public:
- CPDFXFA_Document(std::unique_ptr<CPDF_Document> pPDFDoc,
- CPDFXFA_App* pProvider);
+ CPDFXFA_Document(std::unique_ptr<CPDF_Document> pPDFDoc);
~CPDFXFA_Document();
FX_BOOL LoadXFADoc();
@@ -38,9 +37,11 @@ class CPDFXFA_Document {
CXFA_FFDoc* GetXFADoc() { return m_pXFADoc.get(); }
CXFA_FFDocView* GetXFADocView() { return m_pXFADocView; }
int GetDocType() const { return m_iDocType; }
+ CPDFXFA_App* GetApp(); // Creates if needed.
CPDFSDK_FormFillEnvironment* GetFormFillEnv() const { return m_pFormFillEnv; }
void SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv) {
+ GetApp()->SetFormFillEnv(pFormFillEnv);
m_pFormFillEnv = pFormFillEnv;
}
@@ -68,13 +69,7 @@ class CPDFXFA_Document {
CFX_ArrayTemplate<CPDFXFA_Page*>* GetXFAPageList() { return &m_XFAPageList; }
private:
- void CloseXFADoc(CXFA_FFDocHandler* pDoc) {
- if (pDoc) {
- m_pXFADoc->CloseDoc();
- m_pXFADoc.reset();
- m_pXFADocView = nullptr;
- }
- }
+ void CloseXFADoc(CXFA_FFDocHandler* pDoc);
int m_iDocType;
@@ -82,7 +77,7 @@ class CPDFXFA_Document {
std::unique_ptr<CXFA_FFDoc> m_pXFADoc;
CPDFSDK_FormFillEnvironment* m_pFormFillEnv; // not owned.
CXFA_FFDocView* m_pXFADocView; // not owned.
- CPDFXFA_App* const m_pApp;
+ std::unique_ptr<CPDFXFA_App> m_pApp;
CFX_ArrayTemplate<CPDFXFA_Page*> m_XFAPageList;
LoadStatus m_nLoadStatus;
int m_nPageCount;