| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
| 6 | |
| 7 #include "fpdfsdk/fpdfxfa/fpdfxfa_app.h" | |
| 8 | |
| 9 #include <memory> | |
| 10 | |
| 11 #include "fpdfsdk/cpdfsdk_environment.h" | |
| 12 #include "fpdfsdk/fpdfxfa/fpdfxfa_util.h" | |
| 13 #include "fpdfsdk/fsdk_define.h" | |
| 14 #include "third_party/base/ptr_util.h" | |
| 15 #include "xfa/fxbarcode/BC_Library.h" | |
| 16 #include "xfa/fxfa/xfa_ffapp.h" | |
| 17 #include "xfa/fxfa/xfa_fontmgr.h" | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 CPDFXFA_App* g_pApp = nullptr; | |
| 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 } | |
| 31 | |
| 32 void CPDFXFA_App::ReleaseInstance() { | |
| 33 delete g_pApp; | |
| 34 g_pApp = nullptr; | |
| 35 } | |
| 36 | |
| 37 CPDFXFA_App::CPDFXFA_App() | |
| 38 : m_bJavaScriptInitialized(FALSE), | |
| 39 m_pIsolate(nullptr), | |
| 40 m_csAppType(JS_STR_VIEWERTYPE_STANDARD) { | |
| 41 m_pEnvList.RemoveAll(); | |
| 42 } | |
| 43 | |
| 44 CPDFXFA_App::~CPDFXFA_App() { | |
| 45 FXJSE_Runtime_Release(m_pIsolate); | |
| 46 m_pIsolate = nullptr; | |
| 47 | |
| 48 FXJSE_Finalize(); | |
| 49 BC_Library_Destory(); | |
| 50 } | |
| 51 | |
| 52 FX_BOOL CPDFXFA_App::Initialize(v8::Isolate* pIsolate) { | |
| 53 BC_Library_Init(); | |
| 54 FXJSE_Initialize(); | |
| 55 | |
| 56 m_pIsolate = pIsolate ? pIsolate : FXJSE_Runtime_Create_Own(); | |
| 57 if (!m_pIsolate) | |
| 58 return FALSE; | |
| 59 | |
| 60 m_pXFAApp = pdfium::MakeUnique<CXFA_FFApp>(this); | |
| 61 m_pXFAApp->SetDefaultFontMgr( | |
| 62 std::unique_ptr<CXFA_DefFontMgr>(new CXFA_DefFontMgr)); | |
| 63 | |
| 64 return TRUE; | |
| 65 } | |
| 66 | |
| 67 FX_BOOL CPDFXFA_App::AddFormFillEnv(CPDFSDK_Environment* pEnv) { | |
| 68 if (!pEnv) | |
| 69 return FALSE; | |
| 70 | |
| 71 m_pEnvList.Add(pEnv); | |
| 72 return TRUE; | |
| 73 } | |
| 74 | |
| 75 FX_BOOL CPDFXFA_App::RemoveFormFillEnv(CPDFSDK_Environment* pEnv) { | |
| 76 if (!pEnv) | |
| 77 return FALSE; | |
| 78 | |
| 79 int nFind = m_pEnvList.Find(pEnv); | |
| 80 if (nFind != -1) { | |
| 81 m_pEnvList.RemoveAt(nFind); | |
| 82 return TRUE; | |
| 83 } | |
| 84 | |
| 85 return FALSE; | |
| 86 } | |
| 87 | |
| 88 void CPDFXFA_App::GetAppType(CFX_WideString& wsAppType) { | |
| 89 wsAppType = m_csAppType; | |
| 90 } | |
| 91 | |
| 92 void CPDFXFA_App::GetAppName(CFX_WideString& wsName) { | |
| 93 CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); | |
| 94 if (pEnv) { | |
| 95 wsName = pEnv->FFI_GetAppName(); | |
| 96 } | |
| 97 } | |
| 98 | |
| 99 void CPDFXFA_App::SetAppType(const CFX_WideStringC& wsAppType) { | |
| 100 m_csAppType = wsAppType; | |
| 101 } | |
| 102 | |
| 103 void CPDFXFA_App::GetLanguage(CFX_WideString& wsLanguage) { | |
| 104 CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); | |
| 105 if (pEnv) | |
| 106 wsLanguage = pEnv->GetLanguage(); | |
| 107 } | |
| 108 | |
| 109 void CPDFXFA_App::GetPlatform(CFX_WideString& wsPlatform) { | |
| 110 CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); | |
| 111 if (pEnv) { | |
| 112 wsPlatform = pEnv->GetPlatform(); | |
| 113 } | |
| 114 } | |
| 115 | |
| 116 void CPDFXFA_App::GetVariation(CFX_WideString& wsVariation) { | |
| 117 wsVariation = JS_STR_VIEWERVARIATION; | |
| 118 } | |
| 119 | |
| 120 void CPDFXFA_App::GetVersion(CFX_WideString& wsVersion) { | |
| 121 wsVersion = JS_STR_VIEWERVERSION_XFA; | |
| 122 } | |
| 123 | |
| 124 void CPDFXFA_App::Beep(uint32_t dwType) { | |
| 125 CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); | |
| 126 if (pEnv) { | |
| 127 pEnv->JS_appBeep(dwType); | |
| 128 } | |
| 129 } | |
| 130 | |
| 131 int32_t CPDFXFA_App::MsgBox(const CFX_WideString& wsMessage, | |
| 132 const CFX_WideString& wsTitle, | |
| 133 uint32_t dwIconType, | |
| 134 uint32_t dwButtonType) { | |
| 135 CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); | |
| 136 if (!pEnv) | |
| 137 return -1; | |
| 138 | |
| 139 uint32_t iconType = 0; | |
| 140 int iButtonType = 0; | |
| 141 switch (dwIconType) { | |
| 142 case XFA_MBICON_Error: | |
| 143 iconType |= 0; | |
| 144 break; | |
| 145 case XFA_MBICON_Warning: | |
| 146 iconType |= 1; | |
| 147 break; | |
| 148 case XFA_MBICON_Question: | |
| 149 iconType |= 2; | |
| 150 break; | |
| 151 case XFA_MBICON_Status: | |
| 152 iconType |= 3; | |
| 153 break; | |
| 154 } | |
| 155 switch (dwButtonType) { | |
| 156 case XFA_MB_OK: | |
| 157 iButtonType |= 0; | |
| 158 break; | |
| 159 case XFA_MB_OKCancel: | |
| 160 iButtonType |= 1; | |
| 161 break; | |
| 162 case XFA_MB_YesNo: | |
| 163 iButtonType |= 2; | |
| 164 break; | |
| 165 case XFA_MB_YesNoCancel: | |
| 166 iButtonType |= 3; | |
| 167 break; | |
| 168 } | |
| 169 int32_t iRet = pEnv->JS_appAlert(wsMessage.c_str(), wsTitle.c_str(), | |
| 170 iButtonType, iconType); | |
| 171 switch (iRet) { | |
| 172 case 1: | |
| 173 return XFA_IDOK; | |
| 174 case 2: | |
| 175 return XFA_IDCancel; | |
| 176 case 3: | |
| 177 return XFA_IDNo; | |
| 178 case 4: | |
| 179 return XFA_IDYes; | |
| 180 } | |
| 181 return XFA_IDYes; | |
| 182 } | |
| 183 | |
| 184 CFX_WideString CPDFXFA_App::Response(const CFX_WideString& wsQuestion, | |
| 185 const CFX_WideString& wsTitle, | |
| 186 const CFX_WideString& wsDefaultAnswer, | |
| 187 FX_BOOL bMark) { | |
| 188 CFX_WideString wsAnswer; | |
| 189 CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); | |
| 190 if (pEnv) { | |
| 191 int nLength = 2048; | |
| 192 char* pBuff = new char[nLength]; | |
| 193 nLength = pEnv->JS_appResponse(wsQuestion.c_str(), wsTitle.c_str(), | |
| 194 wsDefaultAnswer.c_str(), nullptr, bMark, | |
| 195 pBuff, nLength); | |
| 196 if (nLength > 0) { | |
| 197 nLength = nLength > 2046 ? 2046 : nLength; | |
| 198 pBuff[nLength] = 0; | |
| 199 pBuff[nLength + 1] = 0; | |
| 200 wsAnswer = CFX_WideString::FromUTF16LE( | |
| 201 reinterpret_cast<const unsigned short*>(pBuff), | |
| 202 nLength / sizeof(unsigned short)); | |
| 203 } | |
| 204 delete[] pBuff; | |
| 205 } | |
| 206 return wsAnswer; | |
| 207 } | |
| 208 | |
| 209 IFX_FileRead* CPDFXFA_App::DownloadURL(const CFX_WideString& wsURL) { | |
| 210 CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); | |
| 211 return pEnv ? pEnv->DownloadFromURL(wsURL.c_str()) : nullptr; | |
| 212 } | |
| 213 | |
| 214 FX_BOOL CPDFXFA_App::PostRequestURL(const CFX_WideString& wsURL, | |
| 215 const CFX_WideString& wsData, | |
| 216 const CFX_WideString& wsContentType, | |
| 217 const CFX_WideString& wsEncode, | |
| 218 const CFX_WideString& wsHeader, | |
| 219 CFX_WideString& wsResponse) { | |
| 220 CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); | |
| 221 if (!pEnv) | |
| 222 return FALSE; | |
| 223 | |
| 224 wsResponse = | |
| 225 pEnv->PostRequestURL(wsURL.c_str(), wsData.c_str(), wsContentType.c_str(), | |
| 226 wsEncode.c_str(), wsHeader.c_str()); | |
| 227 return TRUE; | |
| 228 } | |
| 229 | |
| 230 FX_BOOL CPDFXFA_App::PutRequestURL(const CFX_WideString& wsURL, | |
| 231 const CFX_WideString& wsData, | |
| 232 const CFX_WideString& wsEncode) { | |
| 233 CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); | |
| 234 return pEnv && | |
| 235 pEnv->PutRequestURL(wsURL.c_str(), wsData.c_str(), wsEncode.c_str()); | |
| 236 } | |
| 237 | |
| 238 void CPDFXFA_App::LoadString(int32_t iStringID, CFX_WideString& wsString) { | |
| 239 switch (iStringID) { | |
| 240 case XFA_IDS_ValidateFailed: | |
| 241 wsString = L"%s validation failed"; | |
| 242 return; | |
| 243 case XFA_IDS_CalcOverride: | |
| 244 wsString = L"Calculate Override"; | |
| 245 return; | |
| 246 case XFA_IDS_ModifyField: | |
| 247 wsString = L"Are you sure you want to modify this field?"; | |
| 248 return; | |
| 249 case XFA_IDS_NotModifyField: | |
| 250 wsString = L"You are not allowed to modify this field."; | |
| 251 return; | |
| 252 case XFA_IDS_AppName: | |
| 253 wsString = L"pdfium"; | |
| 254 return; | |
| 255 case XFA_IDS_Unable_TO_SET: | |
| 256 wsString = L"Unable to set "; | |
| 257 return; | |
| 258 case XFA_IDS_INVAlID_PROP_SET: | |
| 259 wsString = L"Invalid property set operation."; | |
| 260 return; | |
| 261 case XFA_IDS_NOT_DEFAUL_VALUE: | |
| 262 wsString = L" doesn't have a default property."; | |
| 263 return; | |
| 264 case XFA_IDS_UNABLE_SET_LANGUAGE: | |
| 265 wsString = L"Unable to set language value."; | |
| 266 return; | |
| 267 case XFA_IDS_UNABLE_SET_NUMPAGES: | |
| 268 wsString = L"Unable to set numPages value."; | |
| 269 return; | |
| 270 case XFA_IDS_UNABLE_SET_PLATFORM: | |
| 271 wsString = L"Unable to set platform value."; | |
| 272 return; | |
| 273 case XFA_IDS_UNABLE_SET_VARIATION: | |
| 274 wsString = L"Unable to set variation value."; | |
| 275 return; | |
| 276 case XFA_IDS_UNABLE_SET_VERSION: | |
| 277 wsString = L"Unable to set version value."; | |
| 278 return; | |
| 279 case XFA_IDS_UNABLE_SET_READY: | |
| 280 wsString = L"Unable to set ready value."; | |
| 281 return; | |
| 282 case XFA_IDS_COMPILER_ERROR: | |
| 283 wsString = L"Compiler error."; | |
| 284 return; | |
| 285 case XFA_IDS_DIVIDE_ZERO: | |
| 286 wsString = L"Divide by zero."; | |
| 287 return; | |
| 288 case XFA_IDS_ACCESS_PROPERTY_IN_NOT_OBJECT: | |
| 289 wsString = | |
| 290 L"An attempt was made to reference property '%s' of a non-object in " | |
| 291 L"SOM expression %s."; | |
| 292 return; | |
| 293 case XFA_IDS_INDEX_OUT_OF_BOUNDS: | |
| 294 wsString = L"Index value is out of bounds."; | |
| 295 return; | |
| 296 case XFA_IDS_INCORRECT_NUMBER_OF_METHOD: | |
| 297 wsString = L"Incorrect number of parameters calling method '%s'."; | |
| 298 return; | |
| 299 case XFA_IDS_ARGUMENT_MISMATCH: | |
| 300 wsString = L"Argument mismatch in property or function argument."; | |
| 301 return; | |
| 302 case XFA_IDS_NOT_HAVE_PROPERTY: | |
| 303 wsString = L"'%s' doesn't have property '%s'."; | |
| 304 return; | |
| 305 case XFA_IDS_VIOLATE_BOUNDARY: | |
| 306 wsString = | |
| 307 L"The element [%s] has violated its allowable number of occurrences."; | |
| 308 return; | |
| 309 case XFA_IDS_SERVER_DENY: | |
| 310 wsString = L"Server does not permit."; | |
| 311 return; | |
| 312 case XFA_IDS_ValidateLimit: | |
| 313 wsString = | |
| 314 L"Message limit exceeded. Remaining %d validation errors not " | |
| 315 L"reported."; | |
| 316 return; | |
| 317 case XFA_IDS_ValidateNullWarning: | |
| 318 wsString = | |
| 319 L"%s cannot be blank. To ignore validations for %s, click Ignore."; | |
| 320 return; | |
| 321 case XFA_IDS_ValidateNullError: | |
| 322 wsString = L"%s cannot be blank."; | |
| 323 return; | |
| 324 case XFA_IDS_ValidateWarning: | |
| 325 wsString = | |
| 326 L"The value you entered for %s is invalid. To ignore validations for " | |
| 327 L"%s, click Ignore."; | |
| 328 return; | |
| 329 case XFA_IDS_ValidateError: | |
| 330 wsString = L"The value you entered for %s is invalid."; | |
| 331 return; | |
| 332 } | |
| 333 } | |
| 334 | |
| 335 IFWL_AdapterTimerMgr* CPDFXFA_App::GetTimerMgr() { | |
| 336 CXFA_FWLAdapterTimerMgr* pAdapter = nullptr; | |
| 337 CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); | |
| 338 if (pEnv) | |
| 339 pAdapter = new CXFA_FWLAdapterTimerMgr(pEnv); | |
| 340 return pAdapter; | |
| 341 } | |
| OLD | NEW |