summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfxfa
diff options
context:
space:
mode:
authordsinclair <dsinclair@chromium.org>2016-10-13 12:14:34 -0700
committerCommit bot <commit-bot@chromium.org>2016-10-13 12:14:35 -0700
commita282c7380f3964de41ea93c9980b12c4513d3473 (patch)
tree5202284e527cd2bdcd7bcd22495018c9fbff1fd5 /fpdfsdk/fpdfxfa
parentf3736bca5f874b0889c5906ffbd74a405089f671 (diff)
downloadpdfium-a282c7380f3964de41ea93c9980b12c4513d3473.tar.xz
Revert of Reland: Make the CPDFXFA_App non-global (patchset #2 id:20001 of https://codereview.chromium.org/2418653003/ )
Reason for revert: https://build.chromium.org/p/client.pdfium/builders/linux_xfa_asan_lsan/builds/117/steps/corpus%20tests/logs/stdio Original issue's description: > Reland: Make the CPDFXFA_App non-global > > This reverts commit b685e6471075bebd26711bc183de3128f54932e3. > > This CL changes CPDFXFA_App from a global object to a child of the CPDFXFA_Document objects. > > BUG=pdfium:623 > > Committed: https://pdfium.googlesource.com/pdfium/+/f3736bca5f874b0889c5906ffbd74a405089f671 TBR=tsepez@chromium.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=pdfium:623 Review-Url: https://codereview.chromium.org/2414883006
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, 147 insertions, 79 deletions
diff --git a/fpdfsdk/fpdfxfa/DEPS b/fpdfsdk/fpdfxfa/DEPS
index 1687e308b5..d4de6f1e89 100644
--- a/fpdfsdk/fpdfxfa/DEPS
+++ b/fpdfsdk/fpdfxfa/DEPS
@@ -1,4 +1,3 @@
include_rules = [
- '+fxjs',
'+xfa/fxbarcode',
]
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_app.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_app.cpp
index 569e314186..61694d0a28 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_app.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_app.cpp
@@ -11,49 +11,110 @@
#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"
-CPDFXFA_App::CPDFXFA_App() : m_pIsolate(nullptr) {
- m_bOwnsIsolate = FXJS_GetIsolate(&m_pIsolate);
+namespace {
- m_pXFAApp = pdfium::MakeUnique<CXFA_FFApp>(this);
- m_pXFAApp->SetDefaultFontMgr(pdfium::MakeUnique<CXFA_DefFontMgr>());
+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() {
- if (m_bOwnsIsolate)
- m_pIsolate->Dispose();
+ 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;
+
+ 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;
+}
+
+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;
}
void CPDFXFA_App::GetAppName(CFX_WideString& wsName) {
- if (m_pFormFillEnv)
- wsName = m_pFormFillEnv->FFI_GetAppName();
+ CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0);
+ if (pFormFillEnv)
+ wsName = pFormFillEnv->FFI_GetAppName();
}
void CPDFXFA_App::GetLanguage(CFX_WideString& wsLanguage) {
- if (m_pFormFillEnv)
- wsLanguage = m_pFormFillEnv->GetLanguage();
+ CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0);
+ if (pFormFillEnv)
+ wsLanguage = pFormFillEnv->GetLanguage();
}
void CPDFXFA_App::GetPlatform(CFX_WideString& wsPlatform) {
- if (m_pFormFillEnv) {
- wsPlatform = m_pFormFillEnv->GetPlatform();
+ CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0);
+ if (pFormFillEnv) {
+ wsPlatform = pFormFillEnv->GetPlatform();
}
}
void CPDFXFA_App::Beep(uint32_t dwType) {
- if (m_pFormFillEnv)
- m_pFormFillEnv->JS_appBeep(dwType);
+ CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0);
+ if (pFormFillEnv)
+ pFormFillEnv->JS_appBeep(dwType);
}
int32_t CPDFXFA_App::MsgBox(const CFX_WideString& wsMessage,
const CFX_WideString& wsTitle,
uint32_t dwIconType,
uint32_t dwButtonType) {
- if (!m_pFormFillEnv)
+ CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0);
+ if (!pFormFillEnv)
return -1;
uint32_t iconType = 0;
@@ -86,8 +147,8 @@ int32_t CPDFXFA_App::MsgBox(const CFX_WideString& wsMessage,
iButtonType |= 3;
break;
}
- int32_t iRet = m_pFormFillEnv->JS_appAlert(wsMessage.c_str(), wsTitle.c_str(),
- iButtonType, iconType);
+ int32_t iRet = pFormFillEnv->JS_appAlert(wsMessage.c_str(), wsTitle.c_str(),
+ iButtonType, iconType);
switch (iRet) {
case 1:
return XFA_IDOK;
@@ -106,29 +167,29 @@ CFX_WideString CPDFXFA_App::Response(const CFX_WideString& wsQuestion,
const CFX_WideString& wsDefaultAnswer,
FX_BOOL bMark) {
CFX_WideString wsAnswer;
- if (!m_pFormFillEnv)
- return wsAnswer;
-
- int nLength = 2048;
- char* pBuff = new char[nLength];
- nLength = m_pFormFillEnv->JS_appResponse(wsQuestion.c_str(), wsTitle.c_str(),
+ 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(),
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));
+ 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;
}
- delete[] pBuff;
return wsAnswer;
}
IFX_FileRead* CPDFXFA_App::DownloadURL(const CFX_WideString& wsURL) {
- return m_pFormFillEnv ? m_pFormFillEnv->DownloadFromURL(wsURL.c_str())
- : nullptr;
+ CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0);
+ return pFormFillEnv ? pFormFillEnv->DownloadFromURL(wsURL.c_str()) : nullptr;
}
FX_BOOL CPDFXFA_App::PostRequestURL(const CFX_WideString& wsURL,
@@ -137,21 +198,23 @@ FX_BOOL CPDFXFA_App::PostRequestURL(const CFX_WideString& wsURL,
const CFX_WideString& wsEncode,
const CFX_WideString& wsHeader,
CFX_WideString& wsResponse) {
- if (!m_pFormFillEnv)
+ CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0);
+ if (!pFormFillEnv)
return FALSE;
- wsResponse = m_pFormFillEnv->PostRequestURL(
- wsURL.c_str(), wsData.c_str(), wsContentType.c_str(), wsEncode.c_str(),
- wsHeader.c_str());
+ wsResponse = 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) {
- return m_pFormFillEnv &&
- m_pFormFillEnv->PutRequestURL(wsURL.c_str(), wsData.c_str(),
- wsEncode.c_str());
+ CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0);
+ return pFormFillEnv &&
+ pFormFillEnv->PutRequestURL(wsURL.c_str(), wsData.c_str(),
+ wsEncode.c_str());
}
void CPDFXFA_App::LoadString(int32_t iStringID, CFX_WideString& wsString) {
@@ -253,7 +316,8 @@ void CPDFXFA_App::LoadString(int32_t iStringID, CFX_WideString& wsString) {
IFWL_AdapterTimerMgr* CPDFXFA_App::GetTimerMgr() {
CXFA_FWLAdapterTimerMgr* pAdapter = nullptr;
- if (m_pFormFillEnv)
- pAdapter = new CXFA_FWLAdapterTimerMgr(m_pFormFillEnv);
+ CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0);
+ if (pFormFillEnv)
+ pAdapter = new CXFA_FWLAdapterTimerMgr(pFormFillEnv);
return pAdapter;
}
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_app.h b/fpdfsdk/fpdfxfa/cpdfxfa_app.h
index c867df2388..78184d1434 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_app.h
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_app.h
@@ -14,13 +14,21 @@ 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(); }
- void SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv) {
- m_pFormFillEnv = pFormFillEnv;
+ 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;
}
v8::Isolate* GetJSERuntime() const { return m_pIsolate; }
@@ -54,11 +62,12 @@ class CPDFXFA_App : public IXFA_AppProvider {
void LoadString(int32_t iStringID, CFX_WideString& wsString) override;
IFWL_AdapterTimerMgr* GetTimerMgr() override;
- private:
- CPDFSDK_FormFillEnvironment* m_pFormFillEnv; // Not owned.
+ CFX_ArrayTemplate<CPDFSDK_FormFillEnvironment*> m_pFormFillEnvList;
+
+ protected:
+ FX_BOOL m_bJavaScriptInitialized;
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 79d28c0637..df0da31beb 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_document.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_document.cpp
@@ -16,7 +16,6 @@
#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"
@@ -29,11 +28,13 @@ extern void SetLastError(int err);
extern int GetLastError();
#endif
-CPDFXFA_Document::CPDFXFA_Document(std::unique_ptr<CPDF_Document> pPDFDoc)
+CPDFXFA_Document::CPDFXFA_Document(std::unique_ptr<CPDF_Document> pPDFDoc,
+ CPDFXFA_App* pProvider)
: 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) {}
@@ -41,12 +42,6 @@ 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
@@ -55,21 +50,17 @@ CPDFXFA_Document::~CPDFXFA_Document() {
m_pFormFillEnv = nullptr;
}
- m_nLoadStatus = FXFA_LOADSTATUS_CLOSED;
-}
-
-void CPDFXFA_Document::CloseXFADoc(CXFA_FFDocHandler* pDoc) {
- if (!pDoc)
- return;
- m_pXFADoc->CloseDoc();
- m_pXFADoc.reset();
- m_pXFADocView = nullptr;
-}
+ if (m_pXFADoc) {
+ CXFA_FFApp* pApp = m_pApp->GetXFAApp();
+ if (pApp) {
+ CXFA_FFDocHandler* pDocHandler = pApp->GetDocHandler();
+ if (pDocHandler)
+ CloseXFADoc(pDocHandler);
+ }
+ m_pXFADoc.reset();
+ }
-CPDFXFA_App* CPDFXFA_Document::GetApp() {
- if (!m_pApp)
- m_pApp = pdfium::MakeUnique<CPDFXFA_App>();
- return m_pApp.get();
+ m_nLoadStatus = FXFA_LOADSTATUS_CLOSED;
}
FX_BOOL CPDFXFA_Document::LoadXFADoc() {
@@ -80,7 +71,7 @@ FX_BOOL CPDFXFA_Document::LoadXFADoc() {
m_XFAPageList.RemoveAll();
- CXFA_FFApp* pApp = GetApp()->GetXFAApp();
+ CXFA_FFApp* pApp = m_pApp->GetXFAApp();
if (!pApp)
return FALSE;
@@ -104,7 +95,7 @@ FX_BOOL CPDFXFA_Document::LoadXFADoc() {
return FALSE;
}
m_pXFADoc->StopLoad();
- m_pXFADoc->GetXFADoc()->InitScriptContext(GetApp()->GetJSERuntime());
+ m_pXFADoc->GetXFADoc()->InitScriptContext(m_pApp->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 88c0e60f2d..de997c16f3 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,7 +29,8 @@ enum LoadStatus {
class CPDFXFA_Document {
public:
- CPDFXFA_Document(std::unique_ptr<CPDF_Document> pPDFDoc);
+ CPDFXFA_Document(std::unique_ptr<CPDF_Document> pPDFDoc,
+ CPDFXFA_App* pProvider);
~CPDFXFA_Document();
FX_BOOL LoadXFADoc();
@@ -37,11 +38,9 @@ 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;
}
@@ -69,7 +68,13 @@ class CPDFXFA_Document {
CFX_ArrayTemplate<CPDFXFA_Page*>* GetXFAPageList() { return &m_XFAPageList; }
private:
- void CloseXFADoc(CXFA_FFDocHandler* pDoc);
+ void CloseXFADoc(CXFA_FFDocHandler* pDoc) {
+ if (pDoc) {
+ m_pXFADoc->CloseDoc();
+ m_pXFADoc.reset();
+ m_pXFADocView = nullptr;
+ }
+ }
int m_iDocType;
@@ -77,7 +82,7 @@ class CPDFXFA_Document {
std::unique_ptr<CXFA_FFDoc> m_pXFADoc;
CPDFSDK_FormFillEnvironment* m_pFormFillEnv; // not owned.
CXFA_FFDocView* m_pXFADocView; // not owned.
- std::unique_ptr<CPDFXFA_App> m_pApp;
+ CPDFXFA_App* const m_pApp;
CFX_ArrayTemplate<CPDFXFA_Page*> m_XFAPageList;
LoadStatus m_nLoadStatus;
int m_nPageCount;