summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfxfa/cpdfxfa_app.cpp
diff options
context:
space:
mode:
authordsinclair <dsinclair@chromium.org>2016-10-13 10:57:01 -0700
committerCommit bot <commit-bot@chromium.org>2016-10-13 10:57:01 -0700
commitb685e6471075bebd26711bc183de3128f54932e3 (patch)
treee3ddfa51c087bb7a6960f117f68a412b14b322d8 /fpdfsdk/fpdfxfa/cpdfxfa_app.cpp
parentabefb79577b32d291d14d7e01a70f6f8cf213bd3 (diff)
downloadpdfium-b685e6471075bebd26711bc183de3128f54932e3.tar.xz
Revert of Make the CPDFXFA_App non-global (patchset #3 id:80001 of https://codereview.chromium.org/2416753002/ )
Reason for revert: https://build.chromium.org/p/client.pdfium/builders/linux_xfa_asan_lsan/builds/112/steps/embeddertests/logs/stdio msan is sad. Original issue's description: > 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 > > Committed: https://pdfium.googlesource.com/pdfium/+/abefb79577b32d291d14d7e01a70f6f8cf213bd3 TBR=tsepez@chromium.org,thestig@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/2412903004
Diffstat (limited to 'fpdfsdk/fpdfxfa/cpdfxfa_app.cpp')
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_app.cpp150
1 files changed, 108 insertions, 42 deletions
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_app.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_app.cpp
index b543d52315..61694d0a28 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_app.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_app.cpp
@@ -11,47 +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) {
- // TODO(dsinclair): How do we 'release' the isolate?
- FXJS_GetIsolate(&m_pIsolate);
+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;
m_pXFAApp = pdfium::MakeUnique<CXFA_FFApp>(this);
- m_pXFAApp->SetDefaultFontMgr(pdfium::MakeUnique<CXFA_DefFontMgr>());
+ 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;
}
-CPDFXFA_App::~CPDFXFA_App() {}
+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;
@@ -84,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;
@@ -104,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,
@@ -135,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) {
@@ -251,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;
}