summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authordsinclair <dsinclair@chromium.org>2016-10-13 10:48:22 -0700
committerCommit bot <commit-bot@chromium.org>2016-10-13 10:48:22 -0700
commitabefb79577b32d291d14d7e01a70f6f8cf213bd3 (patch)
tree489ab4a6f8ddc0d7de4359e186134292434e2ea0 /fpdfsdk
parentd66f9d0b1fb0af57960f9c7163c475968505ee4a (diff)
downloadpdfium-abefb79577b32d291d14d7e01a70f6f8cf213bd3.tar.xz
Make the CPDFXFA_App non-global
This CL changes CPDFXFA_App from a global object to a child of the CPDFXFA_Document objects. BUG=pdfium:623 Review-Url: https://codereview.chromium.org/2416753002
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/DEPS3
-rw-r--r--fpdfsdk/cpdfsdk_formfillenvironment.cpp5
-rw-r--r--fpdfsdk/fpdfdoc_unittest.cpp3
-rw-r--r--fpdfsdk/fpdfformfill.cpp3
-rw-r--r--fpdfsdk/fpdfsave.cpp3
-rw-r--r--fpdfsdk/fpdfview.cpp21
-rw-r--r--fpdfsdk/fpdfxfa/DEPS1
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_app.cpp150
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_app.h18
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_document.cpp39
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_document.h17
-rw-r--r--fpdfsdk/javascript/cjs_runtime.cpp43
12 files changed, 91 insertions, 215 deletions
diff --git a/fpdfsdk/DEPS b/fpdfsdk/DEPS
index 5b1f3c4f60..ce037d902e 100644
--- a/fpdfsdk/DEPS
+++ b/fpdfsdk/DEPS
@@ -3,6 +3,7 @@ include_rules = [
'+public',
'+v8',
'+xfa/fwl/core',
+ '+xfa/fxbarcode',
'+xfa/fxfa',
'+xfa/fxgraphics',
-]
+ ]
diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.cpp b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
index 71b83b2655..9ad7c9fd71 100644
--- a/fpdfsdk/cpdfsdk_formfillenvironment.cpp
+++ b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
@@ -58,11 +58,6 @@ CPDFSDK_FormFillEnvironment::~CPDFSDK_FormFillEnvironment() {
// Those widgets may call things like KillTimer() as they are shutdown.
m_pFormFiller.reset();
-#ifdef PDF_ENABLE_XFA
- CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance();
- if (pProvider->m_pFormFillEnvList.GetSize() == 0)
- pProvider->SetJavaScriptInitialized(FALSE);
-#endif // PDF_ENABLE_XFA
if (m_pInfo && m_pInfo->Release)
m_pInfo->Release(m_pInfo);
}
diff --git a/fpdfsdk/fpdfdoc_unittest.cpp b/fpdfsdk/fpdfdoc_unittest.cpp
index fc85404dba..45beacfdd0 100644
--- a/fpdfsdk/fpdfdoc_unittest.cpp
+++ b/fpdfsdk/fpdfdoc_unittest.cpp
@@ -35,8 +35,7 @@ class CPDF_TestDocument : public CPDF_Document {
class CPDF_TestXFADocument : public CPDFXFA_Document {
public:
CPDF_TestXFADocument()
- : CPDFXFA_Document(pdfium::MakeUnique<CPDF_TestDocument>(),
- CPDFXFA_App::GetInstance()) {}
+ : CPDFXFA_Document(pdfium::MakeUnique<CPDF_TestDocument>()) {}
void SetRoot(CPDF_Dictionary* root) {
reinterpret_cast<CPDF_TestDocument*>(GetPDFDoc())->SetRoot(root);
diff --git a/fpdfsdk/fpdfformfill.cpp b/fpdfsdk/fpdfformfill.cpp
index 34e206d6bc..0f44b1dfa2 100644
--- a/fpdfsdk/fpdfformfill.cpp
+++ b/fpdfsdk/fpdfformfill.cpp
@@ -258,7 +258,6 @@ FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document,
#ifdef PDF_ENABLE_XFA
pDocument->SetFormFillEnv(pFormFillEnv);
- CPDFXFA_App::GetInstance()->AddFormFillEnv(pFormFillEnv);
#endif // PDF_ENABLE_XFA
return pFormFillEnv;
@@ -273,8 +272,6 @@ FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) {
HandleToCPDFSDKEnvironment(hHandle);
#ifdef PDF_ENABLE_XFA
- CPDFXFA_App::GetInstance()->RemoveFormFillEnv(pFormFillEnv);
-
// Reset the focused annotations and remove the SDK document from the
// XFA document.
pFormFillEnv->ClearAllFocusedAnnots();
diff --git a/fpdfsdk/fpdfsave.cpp b/fpdfsdk/fpdfsave.cpp
index 364f4d2d6f..4dfe120d32 100644
--- a/fpdfsdk/fpdfsave.cpp
+++ b/fpdfsdk/fpdfsave.cpp
@@ -85,9 +85,6 @@ bool SaveXFADocumentData(CPDFXFA_Document* pDocument,
pDocument->GetDocType() != DOCTYPE_STATIC_XFA)
return true;
- if (!CPDFXFA_App::GetInstance()->GetXFAApp())
- return true;
-
CXFA_FFDocView* pXFADocView = pDocument->GetXFADocView();
if (!pXFADocView)
return true;
diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp
index 3ab81fe112..cb0cf5917c 100644
--- a/fpdfsdk/fpdfview.cpp
+++ b/fpdfsdk/fpdfview.cpp
@@ -42,6 +42,7 @@
#include "fpdfsdk/fpdfxfa/cpdfxfa_page.h"
#include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h"
#include "public/fpdf_formfill.h"
+#include "xfa/fxbarcode/BC_Library.h"
#endif // PDF_ENABLE_XFA
#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
@@ -70,8 +71,8 @@ CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) {
FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc) {
#ifdef PDF_ENABLE_XFA
- return doc ? FPDFDocumentFromUnderlying(new CPDFXFA_Document(
- pdfium::WrapUnique(doc), CPDFXFA_App::GetInstance()))
+ return doc ? FPDFDocumentFromUnderlying(
+ new CPDFXFA_Document(pdfium::WrapUnique(doc)))
: nullptr;
#else // PDF_ENABLE_XFA
return FPDFDocumentFromUnderlying(doc);
@@ -285,19 +286,19 @@ FPDF_InitLibraryWithConfig(const FPDF_LIBRARY_CONFIG* cfg) {
pModuleMgr->LoadEmbeddedKorea1CMaps();
#ifdef PDF_ENABLE_XFA
- CPDFXFA_App::GetInstance()->Initialize(
- (cfg && cfg->version >= 2) ? static_cast<v8::Isolate*>(cfg->m_pIsolate)
- : nullptr);
+ FXJSE_Initialize();
+ BC_Library_Init();
#endif // PDF_ENABLE_XFA
-
if (cfg && cfg->version >= 2)
IJS_Runtime::Initialize(cfg->m_v8EmbedderSlot, cfg->m_pIsolate);
}
DLLEXPORT void STDCALL FPDF_DestroyLibrary() {
#ifdef PDF_ENABLE_XFA
- CPDFXFA_App::ReleaseInstance();
+ BC_Library_Destory();
+ FXJSE_Finalize();
#endif // PDF_ENABLE_XFA
+
CPDF_ModuleMgr::Destroy();
CFX_GEModule::Destroy();
@@ -377,11 +378,7 @@ DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadDocument(FPDF_STRING file_path,
ProcessParseError(error);
return nullptr;
}
-#ifdef PDF_ENABLE_XFA
- return new CPDFXFA_Document(std::move(pDocument), CPDFXFA_App::GetInstance());
-#else // PDF_ENABLE_XFA
- return pDocument.release();
-#endif // PDF_ENABLE_XFA
+ return FPDFDocumentFromCPDFDocument(pDocument.release());
}
#ifdef PDF_ENABLE_XFA
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..b543d52315 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_app.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_app.cpp
@@ -11,110 +11,47 @@
#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) {
+ // TODO(dsinclair): How do we 'release' the isolate?
+ 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() {}
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 +84,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 +104,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 +135,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 +251,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..ef5c3761c6 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,10 +54,8 @@ 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;
};
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;
diff --git a/fpdfsdk/javascript/cjs_runtime.cpp b/fpdfsdk/javascript/cjs_runtime.cpp
index d41726b315..637fa0a411 100644
--- a/fpdfsdk/javascript/cjs_runtime.cpp
+++ b/fpdfsdk/javascript/cjs_runtime.cpp
@@ -68,7 +68,7 @@ CJS_Runtime::CJS_Runtime(CPDFSDK_FormFillEnvironment* pFormFillEnv)
m_bBlocking(false),
m_isolateManaged(false) {
v8::Isolate* pIsolate = nullptr;
-#ifndef PDF_ENABLE_XFA
+
IPDF_JSPLATFORM* pPlatform = m_pFormFillEnv->GetFormFillInfo()->m_pJsPlatform;
if (pPlatform->version <= 2) {
unsigned int embedderDataSlot = 0;
@@ -81,44 +81,15 @@ CJS_Runtime::CJS_Runtime(CPDFSDK_FormFillEnvironment* pFormFillEnv)
}
m_isolateManaged = FXJS_GetIsolate(&pIsolate);
SetIsolate(pIsolate);
-#else
- if (CPDFXFA_App::GetInstance()->GetJSERuntime()) {
- // TODO(tsepez): CPDFXFA_App should also use the embedder provided isolate.
- pIsolate = CPDFXFA_App::GetInstance()->GetJSERuntime();
- SetIsolate(pIsolate);
- } else {
- IPDF_JSPLATFORM* pPlatform =
- m_pFormFillEnv->GetFormFillInfo()->m_pJsPlatform;
- if (pPlatform->version <= 2) {
- unsigned int embedderDataSlot = 0;
- v8::Isolate* pExternalIsolate = nullptr;
- if (pPlatform->version == 2) {
- pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate);
- embedderDataSlot = pPlatform->m_v8EmbedderSlot;
- }
- FXJS_Initialize(embedderDataSlot, pExternalIsolate);
- }
- m_isolateManaged = FXJS_GetIsolate(&pIsolate);
- SetIsolate(pIsolate);
- }
+#ifdef PDF_ENABLE_XFA
v8::Isolate::Scope isolate_scope(pIsolate);
v8::HandleScope handle_scope(pIsolate);
- if (CPDFXFA_App::GetInstance()->IsJavaScriptInitialized()) {
- CJS_Context* pContext = (CJS_Context*)NewContext();
- InitializeEngine();
- ReleaseContext(pContext);
- return;
- }
#endif
if (m_isolateManaged || FXJS_GlobalIsolateRefCount() == 0)
DefineJSObjects();
-#ifdef PDF_ENABLE_XFA
- CPDFXFA_App::GetInstance()->SetJavaScriptInitialized(TRUE);
-#endif
-
CJS_Context* pContext = (CJS_Context*)NewContext();
InitializeEngine();
ReleaseContext(pContext);
@@ -261,19 +232,9 @@ FX_BOOL CJS_Runtime::GetValueByName(const CFX_ByteStringC& utf8Name,
v8::Isolate::Scope isolate_scope(GetIsolate());
v8::HandleScope handle_scope(GetIsolate());
- v8::Local<v8::Context> old_context = GetIsolate()->GetCurrentContext();
v8::Local<v8::Context> context = NewLocalContext();
v8::Context::Scope context_scope(context);
- // Caution: We're about to hand to XFA an object that in order to invoke
- // methods will require that the current v8::Context always has a pointer
- // to a CJS_Runtime in its embedder data slot. Unfortunately, XFA creates
- // its own v8::Context which has not initialized the embedder data slot.
- // Do so now.
- // TODO(tsepez): redesign PDF-side objects to not rely on v8::Context's
- // embedder data slots, and/or to always use the right context.
- CFXJS_Engine::SetForV8Context(old_context, this);
-
v8::Local<v8::Value> propvalue =
context->Global()->Get(v8::String::NewFromUtf8(
GetIsolate(), name, v8::String::kNormalString, utf8Name.GetLength()));