| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "fpdfsdk/fpdfxfa/cpdfxfa_app.h" | 7 #include "fpdfsdk/fpdfxfa/cpdfxfa_app.h" |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" | 11 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
| 12 #include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h" | 12 #include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h" |
| 13 #include "fpdfsdk/fsdk_define.h" | 13 #include "fpdfsdk/fsdk_define.h" |
| 14 #include "third_party/base/ptr_util.h" | 14 #include "fpdfsdk/javascript/cjs_runtime.h" |
| 15 #include "xfa/fxbarcode/BC_Library.h" | 15 #include "fxjs/fxjs_v8.h" |
| 16 #include "xfa/fxfa/xfa_ffapp.h" | 16 #include "xfa/fxfa/xfa_ffapp.h" |
| 17 #include "xfa/fxfa/xfa_fontmgr.h" | 17 #include "xfa/fxfa/xfa_fontmgr.h" |
| 18 | 18 |
| 19 namespace { | 19 CPDFXFA_App::CPDFXFA_App() { |
| 20 | 20 m_pXFAApp = pdfium::MakeUnique<CXFA_FFApp>(this); |
| 21 CPDFXFA_App* g_pApp = nullptr; | 21 m_pXFAApp->SetDefaultFontMgr(pdfium::MakeUnique<CXFA_DefFontMgr>()); |
| 22 | |
| 23 } // namespace | |
| 24 | |
| 25 CPDFXFA_App* CPDFXFA_App::GetInstance() { | |
| 26 if (!g_pApp) { | |
| 27 g_pApp = new CPDFXFA_App(); | |
| 28 } | |
| 29 return g_pApp; | |
| 30 } | 22 } |
| 31 | 23 |
| 32 void CPDFXFA_App::ReleaseInstance() { | 24 CPDFXFA_App::~CPDFXFA_App() {} |
| 33 delete g_pApp; | 25 |
| 34 g_pApp = nullptr; | 26 v8::Isolate* CPDFXFA_App::GetJSERuntime() const { |
| 27 if (!m_pFormFillEnv) |
| 28 return nullptr; |
| 29 |
| 30 // XFA requires V8, if we have V8 then we have a CJS_Runtime and not the stub. |
| 31 CJS_Runtime* runtime = |
| 32 static_cast<CJS_Runtime*>(m_pFormFillEnv->GetJSRuntime()); |
| 33 return runtime->GetIsolate(); |
| 35 } | 34 } |
| 36 | 35 |
| 37 CPDFXFA_App::CPDFXFA_App() | 36 void CPDFXFA_App::SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv) { |
| 38 : m_bJavaScriptInitialized(FALSE), m_pIsolate(nullptr) { | 37 m_pFormFillEnv = pFormFillEnv; |
| 39 m_pFormFillEnvList.RemoveAll(); | |
| 40 } | |
| 41 | |
| 42 CPDFXFA_App::~CPDFXFA_App() { | |
| 43 FXJSE_Runtime_Release(m_pIsolate); | |
| 44 m_pIsolate = nullptr; | |
| 45 | |
| 46 FXJSE_Finalize(); | |
| 47 BC_Library_Destory(); | |
| 48 } | |
| 49 | |
| 50 FX_BOOL CPDFXFA_App::Initialize(v8::Isolate* pIsolate) { | |
| 51 BC_Library_Init(); | |
| 52 FXJSE_Initialize(); | |
| 53 | |
| 54 m_pIsolate = pIsolate ? pIsolate : FXJSE_Runtime_Create_Own(); | |
| 55 if (!m_pIsolate) | |
| 56 return FALSE; | |
| 57 | |
| 58 m_pXFAApp = pdfium::MakeUnique<CXFA_FFApp>(this); | |
| 59 m_pXFAApp->SetDefaultFontMgr( | |
| 60 std::unique_ptr<CXFA_DefFontMgr>(new CXFA_DefFontMgr)); | |
| 61 | |
| 62 return TRUE; | |
| 63 } | |
| 64 | |
| 65 FX_BOOL CPDFXFA_App::AddFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv) { | |
| 66 if (!pFormFillEnv) | |
| 67 return FALSE; | |
| 68 | |
| 69 m_pFormFillEnvList.Add(pFormFillEnv); | |
| 70 return TRUE; | |
| 71 } | |
| 72 | |
| 73 FX_BOOL CPDFXFA_App::RemoveFormFillEnv( | |
| 74 CPDFSDK_FormFillEnvironment* pFormFillEnv) { | |
| 75 if (!pFormFillEnv) | |
| 76 return FALSE; | |
| 77 | |
| 78 int nFind = m_pFormFillEnvList.Find(pFormFillEnv); | |
| 79 if (nFind != -1) { | |
| 80 m_pFormFillEnvList.RemoveAt(nFind); | |
| 81 return TRUE; | |
| 82 } | |
| 83 | |
| 84 return FALSE; | |
| 85 } | 38 } |
| 86 | 39 |
| 87 void CPDFXFA_App::GetAppName(CFX_WideString& wsName) { | 40 void CPDFXFA_App::GetAppName(CFX_WideString& wsName) { |
| 88 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0); | 41 if (m_pFormFillEnv) |
| 89 if (pFormFillEnv) | 42 wsName = m_pFormFillEnv->FFI_GetAppName(); |
| 90 wsName = pFormFillEnv->FFI_GetAppName(); | |
| 91 } | 43 } |
| 92 | 44 |
| 93 void CPDFXFA_App::GetLanguage(CFX_WideString& wsLanguage) { | 45 void CPDFXFA_App::GetLanguage(CFX_WideString& wsLanguage) { |
| 94 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0); | 46 if (m_pFormFillEnv) |
| 95 if (pFormFillEnv) | 47 wsLanguage = m_pFormFillEnv->GetLanguage(); |
| 96 wsLanguage = pFormFillEnv->GetLanguage(); | |
| 97 } | 48 } |
| 98 | 49 |
| 99 void CPDFXFA_App::GetPlatform(CFX_WideString& wsPlatform) { | 50 void CPDFXFA_App::GetPlatform(CFX_WideString& wsPlatform) { |
| 100 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0); | 51 if (m_pFormFillEnv) { |
| 101 if (pFormFillEnv) { | 52 wsPlatform = m_pFormFillEnv->GetPlatform(); |
| 102 wsPlatform = pFormFillEnv->GetPlatform(); | |
| 103 } | 53 } |
| 104 } | 54 } |
| 105 | 55 |
| 106 void CPDFXFA_App::Beep(uint32_t dwType) { | 56 void CPDFXFA_App::Beep(uint32_t dwType) { |
| 107 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0); | 57 if (m_pFormFillEnv) |
| 108 if (pFormFillEnv) | 58 m_pFormFillEnv->JS_appBeep(dwType); |
| 109 pFormFillEnv->JS_appBeep(dwType); | |
| 110 } | 59 } |
| 111 | 60 |
| 112 int32_t CPDFXFA_App::MsgBox(const CFX_WideString& wsMessage, | 61 int32_t CPDFXFA_App::MsgBox(const CFX_WideString& wsMessage, |
| 113 const CFX_WideString& wsTitle, | 62 const CFX_WideString& wsTitle, |
| 114 uint32_t dwIconType, | 63 uint32_t dwIconType, |
| 115 uint32_t dwButtonType) { | 64 uint32_t dwButtonType) { |
| 116 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0); | 65 if (!m_pFormFillEnv) |
| 117 if (!pFormFillEnv) | |
| 118 return -1; | 66 return -1; |
| 119 | 67 |
| 120 uint32_t iconType = 0; | 68 uint32_t iconType = 0; |
| 121 int iButtonType = 0; | 69 int iButtonType = 0; |
| 122 switch (dwIconType) { | 70 switch (dwIconType) { |
| 123 case XFA_MBICON_Error: | 71 case XFA_MBICON_Error: |
| 124 iconType |= 0; | 72 iconType |= 0; |
| 125 break; | 73 break; |
| 126 case XFA_MBICON_Warning: | 74 case XFA_MBICON_Warning: |
| 127 iconType |= 1; | 75 iconType |= 1; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 140 case XFA_MB_OKCancel: | 88 case XFA_MB_OKCancel: |
| 141 iButtonType |= 1; | 89 iButtonType |= 1; |
| 142 break; | 90 break; |
| 143 case XFA_MB_YesNo: | 91 case XFA_MB_YesNo: |
| 144 iButtonType |= 2; | 92 iButtonType |= 2; |
| 145 break; | 93 break; |
| 146 case XFA_MB_YesNoCancel: | 94 case XFA_MB_YesNoCancel: |
| 147 iButtonType |= 3; | 95 iButtonType |= 3; |
| 148 break; | 96 break; |
| 149 } | 97 } |
| 150 int32_t iRet = pFormFillEnv->JS_appAlert(wsMessage.c_str(), wsTitle.c_str(), | 98 int32_t iRet = m_pFormFillEnv->JS_appAlert(wsMessage.c_str(), wsTitle.c_str(), |
| 151 iButtonType, iconType); | 99 iButtonType, iconType); |
| 152 switch (iRet) { | 100 switch (iRet) { |
| 153 case 1: | 101 case 1: |
| 154 return XFA_IDOK; | 102 return XFA_IDOK; |
| 155 case 2: | 103 case 2: |
| 156 return XFA_IDCancel; | 104 return XFA_IDCancel; |
| 157 case 3: | 105 case 3: |
| 158 return XFA_IDNo; | 106 return XFA_IDNo; |
| 159 case 4: | 107 case 4: |
| 160 return XFA_IDYes; | 108 return XFA_IDYes; |
| 161 } | 109 } |
| 162 return XFA_IDYes; | 110 return XFA_IDYes; |
| 163 } | 111 } |
| 164 | 112 |
| 165 CFX_WideString CPDFXFA_App::Response(const CFX_WideString& wsQuestion, | 113 CFX_WideString CPDFXFA_App::Response(const CFX_WideString& wsQuestion, |
| 166 const CFX_WideString& wsTitle, | 114 const CFX_WideString& wsTitle, |
| 167 const CFX_WideString& wsDefaultAnswer, | 115 const CFX_WideString& wsDefaultAnswer, |
| 168 FX_BOOL bMark) { | 116 FX_BOOL bMark) { |
| 169 CFX_WideString wsAnswer; | 117 CFX_WideString wsAnswer; |
| 170 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0); | 118 if (!m_pFormFillEnv) |
| 171 if (pFormFillEnv) { | 119 return wsAnswer; |
| 172 int nLength = 2048; | 120 |
| 173 char* pBuff = new char[nLength]; | 121 int nLength = 2048; |
| 174 nLength = pFormFillEnv->JS_appResponse(wsQuestion.c_str(), wsTitle.c_str(), | 122 char* pBuff = new char[nLength]; |
| 123 nLength = m_pFormFillEnv->JS_appResponse(wsQuestion.c_str(), wsTitle.c_str(), |
| 175 wsDefaultAnswer.c_str(), nullptr, | 124 wsDefaultAnswer.c_str(), nullptr, |
| 176 bMark, pBuff, nLength); | 125 bMark, pBuff, nLength); |
| 177 if (nLength > 0) { | 126 if (nLength > 0) { |
| 178 nLength = nLength > 2046 ? 2046 : nLength; | 127 nLength = nLength > 2046 ? 2046 : nLength; |
| 179 pBuff[nLength] = 0; | 128 pBuff[nLength] = 0; |
| 180 pBuff[nLength + 1] = 0; | 129 pBuff[nLength + 1] = 0; |
| 181 wsAnswer = CFX_WideString::FromUTF16LE( | 130 wsAnswer = CFX_WideString::FromUTF16LE( |
| 182 reinterpret_cast<const unsigned short*>(pBuff), | 131 reinterpret_cast<const unsigned short*>(pBuff), |
| 183 nLength / sizeof(unsigned short)); | 132 nLength / sizeof(unsigned short)); |
| 184 } | |
| 185 delete[] pBuff; | |
| 186 } | 133 } |
| 134 delete[] pBuff; |
| 187 return wsAnswer; | 135 return wsAnswer; |
| 188 } | 136 } |
| 189 | 137 |
| 190 IFX_SeekableReadStream* CPDFXFA_App::DownloadURL(const CFX_WideString& wsURL) { | 138 IFX_SeekableReadStream* CPDFXFA_App::DownloadURL(const CFX_WideString& wsURL) { |
| 191 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0); | 139 return m_pFormFillEnv ? m_pFormFillEnv->DownloadFromURL(wsURL.c_str()) |
| 192 return pFormFillEnv ? pFormFillEnv->DownloadFromURL(wsURL.c_str()) : nullptr; | 140 : nullptr; |
| 193 } | 141 } |
| 194 | 142 |
| 195 FX_BOOL CPDFXFA_App::PostRequestURL(const CFX_WideString& wsURL, | 143 FX_BOOL CPDFXFA_App::PostRequestURL(const CFX_WideString& wsURL, |
| 196 const CFX_WideString& wsData, | 144 const CFX_WideString& wsData, |
| 197 const CFX_WideString& wsContentType, | 145 const CFX_WideString& wsContentType, |
| 198 const CFX_WideString& wsEncode, | 146 const CFX_WideString& wsEncode, |
| 199 const CFX_WideString& wsHeader, | 147 const CFX_WideString& wsHeader, |
| 200 CFX_WideString& wsResponse) { | 148 CFX_WideString& wsResponse) { |
| 201 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0); | 149 if (!m_pFormFillEnv) |
| 202 if (!pFormFillEnv) | |
| 203 return FALSE; | 150 return FALSE; |
| 204 | 151 |
| 205 wsResponse = pFormFillEnv->PostRequestURL(wsURL.c_str(), wsData.c_str(), | 152 wsResponse = m_pFormFillEnv->PostRequestURL( |
| 206 wsContentType.c_str(), | 153 wsURL.c_str(), wsData.c_str(), wsContentType.c_str(), wsEncode.c_str(), |
| 207 wsEncode.c_str(), wsHeader.c_str()); | 154 wsHeader.c_str()); |
| 208 return TRUE; | 155 return TRUE; |
| 209 } | 156 } |
| 210 | 157 |
| 211 FX_BOOL CPDFXFA_App::PutRequestURL(const CFX_WideString& wsURL, | 158 FX_BOOL CPDFXFA_App::PutRequestURL(const CFX_WideString& wsURL, |
| 212 const CFX_WideString& wsData, | 159 const CFX_WideString& wsData, |
| 213 const CFX_WideString& wsEncode) { | 160 const CFX_WideString& wsEncode) { |
| 214 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0); | 161 return m_pFormFillEnv && |
| 215 return pFormFillEnv && | 162 m_pFormFillEnv->PutRequestURL(wsURL.c_str(), wsData.c_str(), |
| 216 pFormFillEnv->PutRequestURL(wsURL.c_str(), wsData.c_str(), | 163 wsEncode.c_str()); |
| 217 wsEncode.c_str()); | |
| 218 } | 164 } |
| 219 | 165 |
| 220 void CPDFXFA_App::LoadString(int32_t iStringID, CFX_WideString& wsString) { | 166 void CPDFXFA_App::LoadString(int32_t iStringID, CFX_WideString& wsString) { |
| 221 switch (iStringID) { | 167 switch (iStringID) { |
| 222 case XFA_IDS_ValidateFailed: | 168 case XFA_IDS_ValidateFailed: |
| 223 wsString = L"%s validation failed"; | 169 wsString = L"%s validation failed"; |
| 224 return; | 170 return; |
| 225 case XFA_IDS_CalcOverride: | 171 case XFA_IDS_CalcOverride: |
| 226 wsString = L"Calculate Override"; | 172 wsString = L"Calculate Override"; |
| 227 return; | 173 return; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 L"%s, click Ignore."; | 255 L"%s, click Ignore."; |
| 310 return; | 256 return; |
| 311 case XFA_IDS_ValidateError: | 257 case XFA_IDS_ValidateError: |
| 312 wsString = L"The value you entered for %s is invalid."; | 258 wsString = L"The value you entered for %s is invalid."; |
| 313 return; | 259 return; |
| 314 } | 260 } |
| 315 } | 261 } |
| 316 | 262 |
| 317 IFWL_AdapterTimerMgr* CPDFXFA_App::GetTimerMgr() { | 263 IFWL_AdapterTimerMgr* CPDFXFA_App::GetTimerMgr() { |
| 318 CXFA_FWLAdapterTimerMgr* pAdapter = nullptr; | 264 CXFA_FWLAdapterTimerMgr* pAdapter = nullptr; |
| 319 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0); | 265 if (m_pFormFillEnv) |
| 320 if (pFormFillEnv) | 266 pAdapter = new CXFA_FWLAdapterTimerMgr(m_pFormFillEnv); |
| 321 pAdapter = new CXFA_FWLAdapterTimerMgr(pFormFillEnv); | |
| 322 return pAdapter; | 267 return pAdapter; |
| 323 } | 268 } |
| OLD | NEW |