| 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 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 void CPDFXFA_App::ReleaseInstance() { | 32 void CPDFXFA_App::ReleaseInstance() { |
| 33 delete g_pApp; | 33 delete g_pApp; |
| 34 g_pApp = nullptr; | 34 g_pApp = nullptr; |
| 35 } | 35 } |
| 36 | 36 |
| 37 CPDFXFA_App::CPDFXFA_App() | 37 CPDFXFA_App::CPDFXFA_App() |
| 38 : m_bJavaScriptInitialized(FALSE), | 38 : m_bJavaScriptInitialized(FALSE), |
| 39 m_pIsolate(nullptr), | 39 m_pIsolate(nullptr), |
| 40 m_csAppType(JS_STR_VIEWERTYPE_STANDARD) { | 40 m_csAppType(JS_STR_VIEWERTYPE_STANDARD) { |
| 41 m_pEnvList.RemoveAll(); | 41 m_pFormFillEnvList.RemoveAll(); |
| 42 } | 42 } |
| 43 | 43 |
| 44 CPDFXFA_App::~CPDFXFA_App() { | 44 CPDFXFA_App::~CPDFXFA_App() { |
| 45 FXJSE_Runtime_Release(m_pIsolate); | 45 FXJSE_Runtime_Release(m_pIsolate); |
| 46 m_pIsolate = nullptr; | 46 m_pIsolate = nullptr; |
| 47 | 47 |
| 48 FXJSE_Finalize(); | 48 FXJSE_Finalize(); |
| 49 BC_Library_Destory(); | 49 BC_Library_Destory(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 FX_BOOL CPDFXFA_App::Initialize(v8::Isolate* pIsolate) { | 52 FX_BOOL CPDFXFA_App::Initialize(v8::Isolate* pIsolate) { |
| 53 BC_Library_Init(); | 53 BC_Library_Init(); |
| 54 FXJSE_Initialize(); | 54 FXJSE_Initialize(); |
| 55 | 55 |
| 56 m_pIsolate = pIsolate ? pIsolate : FXJSE_Runtime_Create_Own(); | 56 m_pIsolate = pIsolate ? pIsolate : FXJSE_Runtime_Create_Own(); |
| 57 if (!m_pIsolate) | 57 if (!m_pIsolate) |
| 58 return FALSE; | 58 return FALSE; |
| 59 | 59 |
| 60 m_pXFAApp = pdfium::MakeUnique<CXFA_FFApp>(this); | 60 m_pXFAApp = pdfium::MakeUnique<CXFA_FFApp>(this); |
| 61 m_pXFAApp->SetDefaultFontMgr( | 61 m_pXFAApp->SetDefaultFontMgr( |
| 62 std::unique_ptr<CXFA_DefFontMgr>(new CXFA_DefFontMgr)); | 62 std::unique_ptr<CXFA_DefFontMgr>(new CXFA_DefFontMgr)); |
| 63 | 63 |
| 64 return TRUE; | 64 return TRUE; |
| 65 } | 65 } |
| 66 | 66 |
| 67 FX_BOOL CPDFXFA_App::AddFormFillEnv(CPDFSDK_FormFillEnvironment* pEnv) { | 67 FX_BOOL CPDFXFA_App::AddFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv) { |
| 68 if (!pEnv) | 68 if (!pFormFillEnv) |
| 69 return FALSE; | 69 return FALSE; |
| 70 | 70 |
| 71 m_pEnvList.Add(pEnv); | 71 m_pFormFillEnvList.Add(pFormFillEnv); |
| 72 return TRUE; | 72 return TRUE; |
| 73 } | 73 } |
| 74 | 74 |
| 75 FX_BOOL CPDFXFA_App::RemoveFormFillEnv(CPDFSDK_FormFillEnvironment* pEnv) { | 75 FX_BOOL CPDFXFA_App::RemoveFormFillEnv( |
| 76 if (!pEnv) | 76 CPDFSDK_FormFillEnvironment* pFormFillEnv) { |
| 77 if (!pFormFillEnv) |
| 77 return FALSE; | 78 return FALSE; |
| 78 | 79 |
| 79 int nFind = m_pEnvList.Find(pEnv); | 80 int nFind = m_pFormFillEnvList.Find(pFormFillEnv); |
| 80 if (nFind != -1) { | 81 if (nFind != -1) { |
| 81 m_pEnvList.RemoveAt(nFind); | 82 m_pFormFillEnvList.RemoveAt(nFind); |
| 82 return TRUE; | 83 return TRUE; |
| 83 } | 84 } |
| 84 | 85 |
| 85 return FALSE; | 86 return FALSE; |
| 86 } | 87 } |
| 87 | 88 |
| 88 void CPDFXFA_App::GetAppType(CFX_WideString& wsAppType) { | 89 void CPDFXFA_App::GetAppType(CFX_WideString& wsAppType) { |
| 89 wsAppType = m_csAppType; | 90 wsAppType = m_csAppType; |
| 90 } | 91 } |
| 91 | 92 |
| 92 void CPDFXFA_App::GetAppName(CFX_WideString& wsName) { | 93 void CPDFXFA_App::GetAppName(CFX_WideString& wsName) { |
| 93 CPDFSDK_FormFillEnvironment* pEnv = m_pEnvList.GetAt(0); | 94 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0); |
| 94 if (pEnv) { | 95 if (pFormFillEnv) |
| 95 wsName = pEnv->FFI_GetAppName(); | 96 wsName = pFormFillEnv->FFI_GetAppName(); |
| 96 } | |
| 97 } | 97 } |
| 98 | 98 |
| 99 void CPDFXFA_App::SetAppType(const CFX_WideStringC& wsAppType) { | 99 void CPDFXFA_App::SetAppType(const CFX_WideStringC& wsAppType) { |
| 100 m_csAppType = wsAppType; | 100 m_csAppType = wsAppType; |
| 101 } | 101 } |
| 102 | 102 |
| 103 void CPDFXFA_App::GetLanguage(CFX_WideString& wsLanguage) { | 103 void CPDFXFA_App::GetLanguage(CFX_WideString& wsLanguage) { |
| 104 CPDFSDK_FormFillEnvironment* pEnv = m_pEnvList.GetAt(0); | 104 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0); |
| 105 if (pEnv) | 105 if (pFormFillEnv) |
| 106 wsLanguage = pEnv->GetLanguage(); | 106 wsLanguage = pFormFillEnv->GetLanguage(); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void CPDFXFA_App::GetPlatform(CFX_WideString& wsPlatform) { | 109 void CPDFXFA_App::GetPlatform(CFX_WideString& wsPlatform) { |
| 110 CPDFSDK_FormFillEnvironment* pEnv = m_pEnvList.GetAt(0); | 110 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0); |
| 111 if (pEnv) { | 111 if (pFormFillEnv) { |
| 112 wsPlatform = pEnv->GetPlatform(); | 112 wsPlatform = pFormFillEnv->GetPlatform(); |
| 113 } | 113 } |
| 114 } | 114 } |
| 115 | 115 |
| 116 void CPDFXFA_App::GetVariation(CFX_WideString& wsVariation) { | 116 void CPDFXFA_App::GetVariation(CFX_WideString& wsVariation) { |
| 117 wsVariation = JS_STR_VIEWERVARIATION; | 117 wsVariation = JS_STR_VIEWERVARIATION; |
| 118 } | 118 } |
| 119 | 119 |
| 120 void CPDFXFA_App::GetVersion(CFX_WideString& wsVersion) { | 120 void CPDFXFA_App::GetVersion(CFX_WideString& wsVersion) { |
| 121 wsVersion = JS_STR_VIEWERVERSION_XFA; | 121 wsVersion = JS_STR_VIEWERVERSION_XFA; |
| 122 } | 122 } |
| 123 | 123 |
| 124 void CPDFXFA_App::Beep(uint32_t dwType) { | 124 void CPDFXFA_App::Beep(uint32_t dwType) { |
| 125 CPDFSDK_FormFillEnvironment* pEnv = m_pEnvList.GetAt(0); | 125 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0); |
| 126 if (pEnv) { | 126 if (pFormFillEnv) { |
| 127 pEnv->JS_appBeep(dwType); | 127 pFormFillEnv->JS_appBeep(dwType); |
| 128 } | 128 } |
| 129 } | 129 } |
| 130 | 130 |
| 131 int32_t CPDFXFA_App::MsgBox(const CFX_WideString& wsMessage, | 131 int32_t CPDFXFA_App::MsgBox(const CFX_WideString& wsMessage, |
| 132 const CFX_WideString& wsTitle, | 132 const CFX_WideString& wsTitle, |
| 133 uint32_t dwIconType, | 133 uint32_t dwIconType, |
| 134 uint32_t dwButtonType) { | 134 uint32_t dwButtonType) { |
| 135 CPDFSDK_FormFillEnvironment* pEnv = m_pEnvList.GetAt(0); | 135 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0); |
| 136 if (!pEnv) | 136 if (!pFormFillEnv) |
| 137 return -1; | 137 return -1; |
| 138 | 138 |
| 139 uint32_t iconType = 0; | 139 uint32_t iconType = 0; |
| 140 int iButtonType = 0; | 140 int iButtonType = 0; |
| 141 switch (dwIconType) { | 141 switch (dwIconType) { |
| 142 case XFA_MBICON_Error: | 142 case XFA_MBICON_Error: |
| 143 iconType |= 0; | 143 iconType |= 0; |
| 144 break; | 144 break; |
| 145 case XFA_MBICON_Warning: | 145 case XFA_MBICON_Warning: |
| 146 iconType |= 1; | 146 iconType |= 1; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 159 case XFA_MB_OKCancel: | 159 case XFA_MB_OKCancel: |
| 160 iButtonType |= 1; | 160 iButtonType |= 1; |
| 161 break; | 161 break; |
| 162 case XFA_MB_YesNo: | 162 case XFA_MB_YesNo: |
| 163 iButtonType |= 2; | 163 iButtonType |= 2; |
| 164 break; | 164 break; |
| 165 case XFA_MB_YesNoCancel: | 165 case XFA_MB_YesNoCancel: |
| 166 iButtonType |= 3; | 166 iButtonType |= 3; |
| 167 break; | 167 break; |
| 168 } | 168 } |
| 169 int32_t iRet = pEnv->JS_appAlert(wsMessage.c_str(), wsTitle.c_str(), | 169 int32_t iRet = pFormFillEnv->JS_appAlert(wsMessage.c_str(), wsTitle.c_str(), |
| 170 iButtonType, iconType); | 170 iButtonType, iconType); |
| 171 switch (iRet) { | 171 switch (iRet) { |
| 172 case 1: | 172 case 1: |
| 173 return XFA_IDOK; | 173 return XFA_IDOK; |
| 174 case 2: | 174 case 2: |
| 175 return XFA_IDCancel; | 175 return XFA_IDCancel; |
| 176 case 3: | 176 case 3: |
| 177 return XFA_IDNo; | 177 return XFA_IDNo; |
| 178 case 4: | 178 case 4: |
| 179 return XFA_IDYes; | 179 return XFA_IDYes; |
| 180 } | 180 } |
| 181 return XFA_IDYes; | 181 return XFA_IDYes; |
| 182 } | 182 } |
| 183 | 183 |
| 184 CFX_WideString CPDFXFA_App::Response(const CFX_WideString& wsQuestion, | 184 CFX_WideString CPDFXFA_App::Response(const CFX_WideString& wsQuestion, |
| 185 const CFX_WideString& wsTitle, | 185 const CFX_WideString& wsTitle, |
| 186 const CFX_WideString& wsDefaultAnswer, | 186 const CFX_WideString& wsDefaultAnswer, |
| 187 FX_BOOL bMark) { | 187 FX_BOOL bMark) { |
| 188 CFX_WideString wsAnswer; | 188 CFX_WideString wsAnswer; |
| 189 CPDFSDK_FormFillEnvironment* pEnv = m_pEnvList.GetAt(0); | 189 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0); |
| 190 if (pEnv) { | 190 if (pFormFillEnv) { |
| 191 int nLength = 2048; | 191 int nLength = 2048; |
| 192 char* pBuff = new char[nLength]; | 192 char* pBuff = new char[nLength]; |
| 193 nLength = pEnv->JS_appResponse(wsQuestion.c_str(), wsTitle.c_str(), | 193 nLength = pFormFillEnv->JS_appResponse(wsQuestion.c_str(), wsTitle.c_str(), |
| 194 wsDefaultAnswer.c_str(), nullptr, bMark, | 194 wsDefaultAnswer.c_str(), nullptr, |
| 195 pBuff, nLength); | 195 bMark, pBuff, nLength); |
| 196 if (nLength > 0) { | 196 if (nLength > 0) { |
| 197 nLength = nLength > 2046 ? 2046 : nLength; | 197 nLength = nLength > 2046 ? 2046 : nLength; |
| 198 pBuff[nLength] = 0; | 198 pBuff[nLength] = 0; |
| 199 pBuff[nLength + 1] = 0; | 199 pBuff[nLength + 1] = 0; |
| 200 wsAnswer = CFX_WideString::FromUTF16LE( | 200 wsAnswer = CFX_WideString::FromUTF16LE( |
| 201 reinterpret_cast<const unsigned short*>(pBuff), | 201 reinterpret_cast<const unsigned short*>(pBuff), |
| 202 nLength / sizeof(unsigned short)); | 202 nLength / sizeof(unsigned short)); |
| 203 } | 203 } |
| 204 delete[] pBuff; | 204 delete[] pBuff; |
| 205 } | 205 } |
| 206 return wsAnswer; | 206 return wsAnswer; |
| 207 } | 207 } |
| 208 | 208 |
| 209 IFX_FileRead* CPDFXFA_App::DownloadURL(const CFX_WideString& wsURL) { | 209 IFX_FileRead* CPDFXFA_App::DownloadURL(const CFX_WideString& wsURL) { |
| 210 CPDFSDK_FormFillEnvironment* pEnv = m_pEnvList.GetAt(0); | 210 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0); |
| 211 return pEnv ? pEnv->DownloadFromURL(wsURL.c_str()) : nullptr; | 211 return pFormFillEnv ? pFormFillEnv->DownloadFromURL(wsURL.c_str()) : nullptr; |
| 212 } | 212 } |
| 213 | 213 |
| 214 FX_BOOL CPDFXFA_App::PostRequestURL(const CFX_WideString& wsURL, | 214 FX_BOOL CPDFXFA_App::PostRequestURL(const CFX_WideString& wsURL, |
| 215 const CFX_WideString& wsData, | 215 const CFX_WideString& wsData, |
| 216 const CFX_WideString& wsContentType, | 216 const CFX_WideString& wsContentType, |
| 217 const CFX_WideString& wsEncode, | 217 const CFX_WideString& wsEncode, |
| 218 const CFX_WideString& wsHeader, | 218 const CFX_WideString& wsHeader, |
| 219 CFX_WideString& wsResponse) { | 219 CFX_WideString& wsResponse) { |
| 220 CPDFSDK_FormFillEnvironment* pEnv = m_pEnvList.GetAt(0); | 220 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0); |
| 221 if (!pEnv) | 221 if (!pFormFillEnv) |
| 222 return FALSE; | 222 return FALSE; |
| 223 | 223 |
| 224 wsResponse = | 224 wsResponse = pFormFillEnv->PostRequestURL(wsURL.c_str(), wsData.c_str(), |
| 225 pEnv->PostRequestURL(wsURL.c_str(), wsData.c_str(), wsContentType.c_str(), | 225 wsContentType.c_str(), |
| 226 wsEncode.c_str(), wsHeader.c_str()); | 226 wsEncode.c_str(), wsHeader.c_str()); |
| 227 return TRUE; | 227 return TRUE; |
| 228 } | 228 } |
| 229 | 229 |
| 230 FX_BOOL CPDFXFA_App::PutRequestURL(const CFX_WideString& wsURL, | 230 FX_BOOL CPDFXFA_App::PutRequestURL(const CFX_WideString& wsURL, |
| 231 const CFX_WideString& wsData, | 231 const CFX_WideString& wsData, |
| 232 const CFX_WideString& wsEncode) { | 232 const CFX_WideString& wsEncode) { |
| 233 CPDFSDK_FormFillEnvironment* pEnv = m_pEnvList.GetAt(0); | 233 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0); |
| 234 return pEnv && | 234 return pFormFillEnv && |
| 235 pEnv->PutRequestURL(wsURL.c_str(), wsData.c_str(), wsEncode.c_str()); | 235 pFormFillEnv->PutRequestURL(wsURL.c_str(), wsData.c_str(), |
| 236 wsEncode.c_str()); |
| 236 } | 237 } |
| 237 | 238 |
| 238 void CPDFXFA_App::LoadString(int32_t iStringID, CFX_WideString& wsString) { | 239 void CPDFXFA_App::LoadString(int32_t iStringID, CFX_WideString& wsString) { |
| 239 switch (iStringID) { | 240 switch (iStringID) { |
| 240 case XFA_IDS_ValidateFailed: | 241 case XFA_IDS_ValidateFailed: |
| 241 wsString = L"%s validation failed"; | 242 wsString = L"%s validation failed"; |
| 242 return; | 243 return; |
| 243 case XFA_IDS_CalcOverride: | 244 case XFA_IDS_CalcOverride: |
| 244 wsString = L"Calculate Override"; | 245 wsString = L"Calculate Override"; |
| 245 return; | 246 return; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 L"%s, click Ignore."; | 328 L"%s, click Ignore."; |
| 328 return; | 329 return; |
| 329 case XFA_IDS_ValidateError: | 330 case XFA_IDS_ValidateError: |
| 330 wsString = L"The value you entered for %s is invalid."; | 331 wsString = L"The value you entered for %s is invalid."; |
| 331 return; | 332 return; |
| 332 } | 333 } |
| 333 } | 334 } |
| 334 | 335 |
| 335 IFWL_AdapterTimerMgr* CPDFXFA_App::GetTimerMgr() { | 336 IFWL_AdapterTimerMgr* CPDFXFA_App::GetTimerMgr() { |
| 336 CXFA_FWLAdapterTimerMgr* pAdapter = nullptr; | 337 CXFA_FWLAdapterTimerMgr* pAdapter = nullptr; |
| 337 CPDFSDK_FormFillEnvironment* pEnv = m_pEnvList.GetAt(0); | 338 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pFormFillEnvList.GetAt(0); |
| 338 if (pEnv) | 339 if (pFormFillEnv) |
| 339 pAdapter = new CXFA_FWLAdapterTimerMgr(pEnv); | 340 pAdapter = new CXFA_FWLAdapterTimerMgr(pFormFillEnv); |
| 340 return pAdapter; | 341 return pAdapter; |
| 341 } | 342 } |
| OLD | NEW |