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_environment.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 "third_party/base/ptr_util.h" |
15 #include "xfa/fxbarcode/BC_Library.h" | 15 #include "xfa/fxbarcode/BC_Library.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 namespace { |
20 | 20 |
21 CPDFXFA_App* g_pApp = nullptr; | 21 CPDFXFA_App* g_pApp = nullptr; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_Environment* pEnv) { | 67 FX_BOOL CPDFXFA_App::AddFormFillEnv(CPDFSDK_FormFillEnvironment* pEnv) { |
68 if (!pEnv) | 68 if (!pEnv) |
69 return FALSE; | 69 return FALSE; |
70 | 70 |
71 m_pEnvList.Add(pEnv); | 71 m_pEnvList.Add(pEnv); |
72 return TRUE; | 72 return TRUE; |
73 } | 73 } |
74 | 74 |
75 FX_BOOL CPDFXFA_App::RemoveFormFillEnv(CPDFSDK_Environment* pEnv) { | 75 FX_BOOL CPDFXFA_App::RemoveFormFillEnv(CPDFSDK_FormFillEnvironment* pEnv) { |
76 if (!pEnv) | 76 if (!pEnv) |
77 return FALSE; | 77 return FALSE; |
78 | 78 |
79 int nFind = m_pEnvList.Find(pEnv); | 79 int nFind = m_pEnvList.Find(pEnv); |
80 if (nFind != -1) { | 80 if (nFind != -1) { |
81 m_pEnvList.RemoveAt(nFind); | 81 m_pEnvList.RemoveAt(nFind); |
82 return TRUE; | 82 return TRUE; |
83 } | 83 } |
84 | 84 |
85 return FALSE; | 85 return FALSE; |
86 } | 86 } |
87 | 87 |
88 void CPDFXFA_App::GetAppType(CFX_WideString& wsAppType) { | 88 void CPDFXFA_App::GetAppType(CFX_WideString& wsAppType) { |
89 wsAppType = m_csAppType; | 89 wsAppType = m_csAppType; |
90 } | 90 } |
91 | 91 |
92 void CPDFXFA_App::GetAppName(CFX_WideString& wsName) { | 92 void CPDFXFA_App::GetAppName(CFX_WideString& wsName) { |
93 CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); | 93 CPDFSDK_FormFillEnvironment* pEnv = m_pEnvList.GetAt(0); |
94 if (pEnv) { | 94 if (pEnv) { |
95 wsName = pEnv->FFI_GetAppName(); | 95 wsName = pEnv->FFI_GetAppName(); |
96 } | 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_Environment* pEnv = m_pEnvList.GetAt(0); | 104 CPDFSDK_FormFillEnvironment* pEnv = m_pEnvList.GetAt(0); |
105 if (pEnv) | 105 if (pEnv) |
106 wsLanguage = pEnv->GetLanguage(); | 106 wsLanguage = pEnv->GetLanguage(); |
107 } | 107 } |
108 | 108 |
109 void CPDFXFA_App::GetPlatform(CFX_WideString& wsPlatform) { | 109 void CPDFXFA_App::GetPlatform(CFX_WideString& wsPlatform) { |
110 CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); | 110 CPDFSDK_FormFillEnvironment* pEnv = m_pEnvList.GetAt(0); |
111 if (pEnv) { | 111 if (pEnv) { |
112 wsPlatform = pEnv->GetPlatform(); | 112 wsPlatform = pEnv->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_Environment* pEnv = m_pEnvList.GetAt(0); | 125 CPDFSDK_FormFillEnvironment* pEnv = m_pEnvList.GetAt(0); |
126 if (pEnv) { | 126 if (pEnv) { |
127 pEnv->JS_appBeep(dwType); | 127 pEnv->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_Environment* pEnv = m_pEnvList.GetAt(0); | 135 CPDFSDK_FormFillEnvironment* pEnv = m_pEnvList.GetAt(0); |
136 if (!pEnv) | 136 if (!pEnv) |
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: |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_Environment* pEnv = m_pEnvList.GetAt(0); | 189 CPDFSDK_FormFillEnvironment* pEnv = m_pEnvList.GetAt(0); |
190 if (pEnv) { | 190 if (pEnv) { |
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 = pEnv->JS_appResponse(wsQuestion.c_str(), wsTitle.c_str(), |
194 wsDefaultAnswer.c_str(), nullptr, bMark, | 194 wsDefaultAnswer.c_str(), nullptr, bMark, |
195 pBuff, nLength); | 195 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_Environment* pEnv = m_pEnvList.GetAt(0); | 210 CPDFSDK_FormFillEnvironment* pEnv = m_pEnvList.GetAt(0); |
211 return pEnv ? pEnv->DownloadFromURL(wsURL.c_str()) : nullptr; | 211 return pEnv ? pEnv->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_Environment* pEnv = m_pEnvList.GetAt(0); | 220 CPDFSDK_FormFillEnvironment* pEnv = m_pEnvList.GetAt(0); |
221 if (!pEnv) | 221 if (!pEnv) |
222 return FALSE; | 222 return FALSE; |
223 | 223 |
224 wsResponse = | 224 wsResponse = |
225 pEnv->PostRequestURL(wsURL.c_str(), wsData.c_str(), wsContentType.c_str(), | 225 pEnv->PostRequestURL(wsURL.c_str(), wsData.c_str(), 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_Environment* pEnv = m_pEnvList.GetAt(0); | 233 CPDFSDK_FormFillEnvironment* pEnv = m_pEnvList.GetAt(0); |
234 return pEnv && | 234 return pEnv && |
235 pEnv->PutRequestURL(wsURL.c_str(), wsData.c_str(), wsEncode.c_str()); | 235 pEnv->PutRequestURL(wsURL.c_str(), wsData.c_str(), wsEncode.c_str()); |
236 } | 236 } |
237 | 237 |
238 void CPDFXFA_App::LoadString(int32_t iStringID, CFX_WideString& wsString) { | 238 void CPDFXFA_App::LoadString(int32_t iStringID, CFX_WideString& wsString) { |
239 switch (iStringID) { | 239 switch (iStringID) { |
240 case XFA_IDS_ValidateFailed: | 240 case XFA_IDS_ValidateFailed: |
241 wsString = L"%s validation failed"; | 241 wsString = L"%s validation failed"; |
242 return; | 242 return; |
243 case XFA_IDS_CalcOverride: | 243 case XFA_IDS_CalcOverride: |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 L"%s, click Ignore."; | 327 L"%s, click Ignore."; |
328 return; | 328 return; |
329 case XFA_IDS_ValidateError: | 329 case XFA_IDS_ValidateError: |
330 wsString = L"The value you entered for %s is invalid."; | 330 wsString = L"The value you entered for %s is invalid."; |
331 return; | 331 return; |
332 } | 332 } |
333 } | 333 } |
334 | 334 |
335 IFWL_AdapterTimerMgr* CPDFXFA_App::GetTimerMgr() { | 335 IFWL_AdapterTimerMgr* CPDFXFA_App::GetTimerMgr() { |
336 CXFA_FWLAdapterTimerMgr* pAdapter = nullptr; | 336 CXFA_FWLAdapterTimerMgr* pAdapter = nullptr; |
337 CPDFSDK_Environment* pEnv = m_pEnvList.GetAt(0); | 337 CPDFSDK_FormFillEnvironment* pEnv = m_pEnvList.GetAt(0); |
338 if (pEnv) | 338 if (pEnv) |
339 pAdapter = new CXFA_FWLAdapterTimerMgr(pEnv); | 339 pAdapter = new CXFA_FWLAdapterTimerMgr(pEnv); |
340 return pAdapter; | 340 return pAdapter; |
341 } | 341 } |
OLD | NEW |