diff options
author | Tom Sepez <tsepez@chromium.org> | 2015-09-14 15:06:53 -0700 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2015-09-14 15:06:53 -0700 |
commit | f458362c167f29f37301f48b08eb8d916e69d40b (patch) | |
tree | d1d53eb4e1fddee030d7ccbc05e19c80765260c3 /fpdfsdk/src/javascript/JS_GlobalData.cpp | |
parent | 142165e2f62b8ba727e8aab40591ca3a7b6fa214 (diff) | |
download | pdfium-f458362c167f29f37301f48b08eb8d916e69d40b.tar.xz |
Merge to XFA: Get CJS_RuntimeFactory out of CJS_GlobalData management.
(cherry picked from commit 9a817f092e6800e9338b41acf4ea0416b6ad4467)
Original Review URL: https://codereview.chromium.org/1338993005 .
Small manual merge in
fpdfsdk/src/javascript/JS_GlobalData.cpp
fpdfsdk/src/javascript/global.cpp
TBR=thestig@chromium.org
Review URL: https://codereview.chromium.org/1341913002 .
Diffstat (limited to 'fpdfsdk/src/javascript/JS_GlobalData.cpp')
-rw-r--r-- | fpdfsdk/src/javascript/JS_GlobalData.cpp | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/fpdfsdk/src/javascript/JS_GlobalData.cpp b/fpdfsdk/src/javascript/JS_GlobalData.cpp index 567e4f2c0a..a4afb9d62c 100644 --- a/fpdfsdk/src/javascript/JS_GlobalData.cpp +++ b/fpdfsdk/src/javascript/JS_GlobalData.cpp @@ -99,19 +99,32 @@ static const uint8_t JS_RC4KEY[] = { 0x0e, 0xd0, 0x6b, 0xbb, 0xd5, 0x75, 0x55, 0x8b, 0x6e, 0x6b, 0x19, 0xa0, 0xf8, 0x77, 0xd5, 0xa3}; -CJS_GlobalData::CJS_GlobalData(CPDFDoc_Environment* pApp) : m_pApp(pApp) { - // IBaseAnnot* pBaseAnnot = IBaseAnnot::GetBaseAnnot(m_pApp); - // ASSERT(pBaseAnnot != NULL); - // - // m_sFilePath = pBaseAnnot->GetUserPath(); - m_sFilePath += SDK_JS_GLOBALDATA_FILENAME; +CJS_GlobalData* CJS_GlobalData::g_Instance = nullptr; + +// static +CJS_GlobalData* CJS_GlobalData::GetRetainedInstance(CPDFDoc_Environment* pApp) { + if (!g_Instance) { + g_Instance = new CJS_GlobalData(pApp); + } + ++g_Instance->m_RefCount; + return g_Instance; +} +void CJS_GlobalData::Release() { + if (!--m_RefCount) { + delete g_Instance; + g_Instance = nullptr; + } +} + +CJS_GlobalData::CJS_GlobalData(CPDFDoc_Environment* pApp) + : m_pApp(pApp), m_RefCount(0) { + m_sFilePath += SDK_JS_GLOBALDATA_FILENAME; LoadGlobalPersistentVariables(); } CJS_GlobalData::~CJS_GlobalData() { SaveGlobalPersisitentVariables(); - for (int i = 0, sz = m_arrayGlobalData.GetSize(); i < sz; i++) delete m_arrayGlobalData.GetAt(i); @@ -119,19 +132,12 @@ CJS_GlobalData::~CJS_GlobalData() { } int CJS_GlobalData::FindGlobalVariable(const FX_CHAR* propname) { - ASSERT(propname != NULL); - - int nRet = -1; - for (int i = 0, sz = m_arrayGlobalData.GetSize(); i < sz; i++) { CJS_GlobalData_Element* pTemp = m_arrayGlobalData.GetAt(i); - if (pTemp->data.sKey[0] == *propname && pTemp->data.sKey == propname) { - nRet = i; - break; - } + if (pTemp->data.sKey[0] == *propname && pTemp->data.sKey == propname) + return i; } - - return nRet; + return -1; } CJS_GlobalData_Element* CJS_GlobalData::GetGlobalVariable( |