diff options
author | dsinclair <dsinclair@chromium.org> | 2016-11-01 11:22:37 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-11-01 11:22:37 -0700 |
commit | 8837c91c0db8f9205b7e58db97946e9af7958b39 (patch) | |
tree | aa23430c284fe741685327e4f4704b2846514c54 /fpdfsdk/fpdfxfa/cpdfxfa_app.cpp | |
parent | fcb1728c35f97a67fa0297f12bb13d3cafb01fe1 (diff) | |
download | pdfium-8837c91c0db8f9205b7e58db97946e9af7958b39.tar.xz |
Reland: Make the CPDFXFA_App non-globalchromium/2907
This reverts commit a282c7380f3964de41ea93c9980b12c4513d3473.
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/2421603002
Diffstat (limited to 'fpdfsdk/fpdfxfa/cpdfxfa_app.cpp')
-rw-r--r-- | fpdfsdk/fpdfxfa/cpdfxfa_app.cpp | 157 |
1 files changed, 51 insertions, 106 deletions
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_app.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_app.cpp index dc5c4be0d6..27ca1e0c61 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_app.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_app.cpp @@ -11,110 +11,58 @@ #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h" #include "fpdfsdk/fsdk_define.h" -#include "third_party/base/ptr_util.h" -#include "xfa/fxbarcode/BC_Library.h" +#include "fpdfsdk/javascript/cjs_runtime.h" +#include "fxjs/fxjs_v8.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_pXFAApp = pdfium::MakeUnique<CXFA_FFApp>(this); - m_pXFAApp->SetDefaultFontMgr( - std::unique_ptr<CXFA_DefFontMgr>(new CXFA_DefFontMgr)); - - return TRUE; + m_pXFAApp->SetDefaultFontMgr(pdfium::MakeUnique<CXFA_DefFontMgr>()); } -FX_BOOL CPDFXFA_App::AddFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv) { - if (!pFormFillEnv) - return FALSE; +CPDFXFA_App::~CPDFXFA_App() {} - m_pFormFillEnvList.Add(pFormFillEnv); - return TRUE; -} - -FX_BOOL CPDFXFA_App::RemoveFormFillEnv( - CPDFSDK_FormFillEnvironment* pFormFillEnv) { - if (!pFormFillEnv) - return FALSE; +v8::Isolate* CPDFXFA_App::GetJSERuntime() const { + if (!m_pFormFillEnv) + return nullptr; - int nFind = m_pFormFillEnvList.Find(pFormFillEnv); - if (nFind != -1) { - m_pFormFillEnvList.RemoveAt(nFind); - return TRUE; - } + // XFA requires V8, if we have V8 then we have a CJS_Runtime and not the stub. + CJS_Runtime* runtime = + static_cast<CJS_Runtime*>(m_pFormFillEnv->GetJSRuntime()); + return runtime->GetIsolate(); +} - return FALSE; +void CPDFXFA_App::SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv) { + m_pFormFillEnv = pFormFillEnv; } 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 +95,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 +115,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_SeekableReadStream* 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 +146,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 +262,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; } |