Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: fpdfsdk/src/fpdfxfa/fpdfxfa_app.cpp

Issue 1799773002: Move fpdfsdk/src up to fpdfsdk/. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase to master Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/src/fpdfview_embeddertest.cpp ('k') | fpdfsdk/src/fpdfxfa/fpdfxfa_doc.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/include/fpdfxfa/fpdfxfa_app.h"
8 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h"
9 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_util.h"
10 #include "fpdfsdk/include/fsdk_define.h"
11 #include "fpdfsdk/include/fsdk_mgr.h"
12 #include "fpdfsdk/include/javascript/IJavaScript.h"
13 #include "public/fpdf_formfill.h"
14 #include "xfa/include/fxbarcode/BC_BarCode.h"
15
16 CPDFXFA_App* CPDFXFA_App::g_pApp = NULL;
17
18 CPDFXFA_App* CPDFXFA_App::GetInstance() {
19 if (!g_pApp) {
20 g_pApp = new CPDFXFA_App();
21 }
22 return g_pApp;
23 }
24
25 void CPDFXFA_App::ReleaseInstance() {
26 delete g_pApp;
27 g_pApp = NULL;
28 }
29
30 CPDFXFA_App::CPDFXFA_App()
31 : m_bJavaScriptInitialized(FALSE),
32 m_pXFAApp(NULL),
33 m_pFontMgr(NULL),
34 m_hJSERuntime(NULL),
35 m_csAppType(JS_STR_VIEWERTYPE_STANDARD),
36 m_bOwnedRuntime(false) {
37 m_pEnvList.RemoveAll();
38 }
39
40 CPDFXFA_App::~CPDFXFA_App() {
41 delete m_pFontMgr;
42 m_pFontMgr = NULL;
43
44 delete m_pXFAApp;
45 m_pXFAApp = NULL;
46
47 #ifdef PDF_ENABLE_XFA
48 FXJSE_Runtime_Release(m_hJSERuntime, m_bOwnedRuntime);
49 m_hJSERuntime = NULL;
50
51 FXJSE_Finalize();
52 BC_Library_Destory();
53 #endif
54 }
55
56 FX_BOOL CPDFXFA_App::Initialize(FXJSE_HRUNTIME hRuntime) {
57 #ifdef PDF_ENABLE_XFA
58 BC_Library_Init();
59 FXJSE_Initialize();
60
61 m_bOwnedRuntime = !hRuntime;
62 m_hJSERuntime = hRuntime ? hRuntime : FXJSE_Runtime_Create();
63 if (!m_hJSERuntime)
64 return FALSE;
65
66 m_pXFAApp = IXFA_App::Create(this);
67 if (!m_pXFAApp)
68 return FALSE;
69
70 m_pFontMgr = IXFA_FontMgr::CreateDefault();
71 if (!m_pFontMgr)
72 return FALSE;
73
74 m_pXFAApp->SetDefaultFontMgr(m_pFontMgr);
75 #endif
76 return TRUE;
77 }
78
79 FX_BOOL CPDFXFA_App::AddFormFillEnv(CPDFDoc_Environment* pEnv) {
80 if (!pEnv)
81 return FALSE;
82
83 m_pEnvList.Add(pEnv);
84 return TRUE;
85 }
86
87 FX_BOOL CPDFXFA_App::RemoveFormFillEnv(CPDFDoc_Environment* pEnv) {
88 if (!pEnv)
89 return FALSE;
90
91 int nFind = m_pEnvList.Find(pEnv);
92 if (nFind != -1) {
93 m_pEnvList.RemoveAt(nFind);
94 return TRUE;
95 }
96
97 return FALSE;
98 }
99
100 void CPDFXFA_App::GetAppType(CFX_WideString& wsAppType) {
101 wsAppType = m_csAppType;
102 }
103
104 void CPDFXFA_App::GetAppName(CFX_WideString& wsName) {
105 CPDFDoc_Environment* pEnv = m_pEnvList.GetAt(0);
106 if (pEnv) {
107 wsName = pEnv->FFI_GetAppName();
108 }
109 }
110
111 void CPDFXFA_App::SetAppType(const CFX_WideStringC& wsAppType) {
112 m_csAppType = wsAppType;
113 }
114
115 void CPDFXFA_App::GetLanguage(CFX_WideString& wsLanguage) {
116 CPDFDoc_Environment* pEnv = m_pEnvList.GetAt(0);
117 if (pEnv) {
118 wsLanguage = pEnv->FFI_GetLanguage();
119 }
120 }
121
122 void CPDFXFA_App::GetPlatform(CFX_WideString& wsPlatform) {
123 CPDFDoc_Environment* pEnv = m_pEnvList.GetAt(0);
124 if (pEnv) {
125 wsPlatform = pEnv->FFI_GetPlatform();
126 }
127 }
128
129 void CPDFXFA_App::GetVariation(CFX_WideString& wsVariation) {
130 wsVariation = JS_STR_VIEWERVARIATION;
131 }
132
133 void CPDFXFA_App::GetVersion(CFX_WideString& wsVersion) {
134 wsVersion = JS_STR_VIEWERVERSION_XFA;
135 }
136
137 void CPDFXFA_App::Beep(FX_DWORD dwType) {
138 CPDFDoc_Environment* pEnv = m_pEnvList.GetAt(0);
139 if (pEnv) {
140 pEnv->JS_appBeep(dwType);
141 }
142 }
143
144 int32_t CPDFXFA_App::MsgBox(const CFX_WideStringC& wsMessage,
145 const CFX_WideStringC& wsTitle,
146 FX_DWORD dwIconType,
147 FX_DWORD dwButtonType) {
148 CPDFDoc_Environment* pEnv = m_pEnvList.GetAt(0);
149 if (!pEnv)
150 return -1;
151
152 FX_DWORD iconType = 0;
153 int iButtonType = 0;
154 switch (dwIconType) {
155 case XFA_MBICON_Error:
156 iconType |= 0;
157 break;
158 case XFA_MBICON_Warning:
159 iconType |= 1;
160 break;
161 case XFA_MBICON_Question:
162 iconType |= 2;
163 break;
164 case XFA_MBICON_Status:
165 iconType |= 3;
166 break;
167 }
168 switch (dwButtonType) {
169 case XFA_MB_OK:
170 iButtonType |= 0;
171 break;
172 case XFA_MB_OKCancel:
173 iButtonType |= 1;
174 break;
175 case XFA_MB_YesNo:
176 iButtonType |= 2;
177 break;
178 case XFA_MB_YesNoCancel:
179 iButtonType |= 3;
180 break;
181 }
182 int32_t iRet = pEnv->JS_appAlert(wsMessage.GetPtr(), wsTitle.GetPtr(),
183 iButtonType, iconType);
184 switch (iRet) {
185 case 1:
186 return XFA_IDOK;
187 case 2:
188 return XFA_IDCancel;
189 case 3:
190 return XFA_IDNo;
191 case 4:
192 return XFA_IDYes;
193 }
194 return XFA_IDYes;
195 }
196
197 void CPDFXFA_App::Response(CFX_WideString& wsAnswer,
198 const CFX_WideStringC& wsQuestion,
199 const CFX_WideStringC& wsTitle,
200 const CFX_WideStringC& wsDefaultAnswer,
201 FX_BOOL bMark) {
202 CPDFDoc_Environment* pEnv = m_pEnvList.GetAt(0);
203 if (pEnv) {
204 int nLength = 2048;
205 char* pBuff = new char[nLength];
206 nLength = pEnv->JS_appResponse(wsQuestion.GetPtr(), wsTitle.GetPtr(),
207 wsDefaultAnswer.GetPtr(), NULL, bMark, pBuff,
208 nLength);
209 if (nLength > 0) {
210 nLength = nLength > 2046 ? 2046 : nLength;
211 pBuff[nLength] = 0;
212 pBuff[nLength + 1] = 0;
213 wsAnswer = CFX_WideString::FromUTF16LE(
214 reinterpret_cast<const unsigned short*>(pBuff),
215 nLength / sizeof(unsigned short));
216 }
217 delete[] pBuff;
218 }
219 }
220
221 int32_t CPDFXFA_App::GetCurDocumentInBatch() {
222 CPDFDoc_Environment* pEnv = m_pEnvList.GetAt(0);
223 if (pEnv) {
224 return pEnv->FFI_GetCurDocument();
225 }
226 return 0;
227 }
228
229 int32_t CPDFXFA_App::GetDocumentCountInBatch() {
230 CPDFDoc_Environment* pEnv = m_pEnvList.GetAt(0);
231 if (pEnv) {
232 return pEnv->FFI_GetDocumentCount();
233 }
234
235 return 0;
236 }
237
238 IFX_FileRead* CPDFXFA_App::DownloadURL(const CFX_WideStringC& wsURL) {
239 CPDFDoc_Environment* pEnv = m_pEnvList.GetAt(0);
240 if (pEnv) {
241 return pEnv->FFI_DownloadFromURL(wsURL.GetPtr());
242 }
243 return NULL;
244 }
245
246 FX_BOOL CPDFXFA_App::PostRequestURL(const CFX_WideStringC& wsURL,
247 const CFX_WideStringC& wsData,
248 const CFX_WideStringC& wsContentType,
249 const CFX_WideStringC& wsEncode,
250 const CFX_WideStringC& wsHeader,
251 CFX_WideString& wsResponse) {
252 CPDFDoc_Environment* pEnv = m_pEnvList.GetAt(0);
253 if (pEnv) {
254 wsResponse = pEnv->FFI_PostRequestURL(wsURL.GetPtr(), wsData.GetPtr(),
255 wsContentType.GetPtr(),
256 wsEncode.GetPtr(), wsHeader.GetPtr());
257 return TRUE;
258 }
259 return FALSE;
260 }
261
262 FX_BOOL CPDFXFA_App::PutRequestURL(const CFX_WideStringC& wsURL,
263 const CFX_WideStringC& wsData,
264 const CFX_WideStringC& wsEncode) {
265 CPDFDoc_Environment* pEnv = m_pEnvList.GetAt(0);
266 if (pEnv) {
267 return pEnv->FFI_PutRequestURL(wsURL.GetPtr(), wsData.GetPtr(),
268 wsEncode.GetPtr());
269 }
270 return FALSE;
271 }
272
273 void CPDFXFA_App::LoadString(int32_t iStringID, CFX_WideString& wsString) {
274 switch (iStringID) {
275 case XFA_IDS_ValidateFailed:
276 wsString = L"%s validate failed";
277 return;
278 case XFA_IDS_CalcOverride:
279 wsString = L"Calculate Override";
280 return;
281 case XFA_IDS_ModifyField:
282 wsString = L"Are you sure you want to modify this field?";
283 return;
284 case XFA_IDS_NotModifyField:
285 wsString = L"You are not allowed to modify this field.";
286 return;
287 case XFA_IDS_AppName:
288 wsString = L"Foxit";
289 return;
290 case XFA_IDS_ImageFilter:
291 wsString =
292 L"Image "
293 L"Files(*.bmp;*.jpg;*.png;*.gif;*.tif)|*.bmp;*.jpg;*.png;*.gif;*.tif|"
294 L"All Files(*.*)|*.*||";
295 return;
296 case XFA_IDS_UNKNOW_CATCHED:
297 wsString = L"unknown error is catched!";
298 return;
299 case XFA_IDS_Unable_TO_SET:
300 wsString = L"Unable to set ";
301 return;
302 case XFA_IDS_VALUE_EXCALMATORY:
303 wsString = L" value!";
304 return;
305 case XFA_IDS_INVALID_ENUM_VALUE:
306 wsString = L"Invalid enumerated value: ";
307 return;
308 case XFA_IDS_UNSUPPORT_METHOD:
309 wsString = L"unsupport %s method.";
310 return;
311 case XFA_IDS_UNSUPPORT_PROP:
312 wsString = L"unsupport %s property.";
313 return;
314 case XFA_IDS_INVAlID_PROP_SET:
315 wsString = L"Invalid property set operation;";
316 return;
317 case XFA_IDS_NOT_DEFAUL_VALUE:
318 wsString = L" doesn't have a default property";
319 return;
320 case XFA_IDS_UNABLE_SET_LANGUAGE:
321 wsString = L"Unable to set language value!";
322 return;
323 case XFA_IDS_UNABLE_SET_NUMPAGES:
324 wsString = L"Unable to set numPages value!";
325 return;
326 case XFA_IDS_UNABLE_SET_PLATFORM:
327 wsString = L"Unable to set platform value!";
328 return;
329 case XFA_IDS_UNABLE_SET_VALIDATIONENABLE:
330 wsString = L"Unable to set validationsEnabled value!";
331 return;
332 case XFA_IDS_UNABLE_SET_VARIATION:
333 wsString = L"Unable to set variation value!";
334 return;
335 case XFA_IDS_UNABLE_SET_VERSION:
336 wsString = L"Unable to set version value!";
337 return;
338 case XFA_IDS_UNABLE_SET_READY:
339 wsString = L"Unable to set ready value!";
340 return;
341 case XFA_IDS_NUMBER_OF_OCCUR:
342 wsString =
343 L"The element [%s] has violated its allowable number of occurrences";
344 return;
345 case XFA_IDS_UNABLE_SET_CLASS_NAME:
346 wsString = L"Unable to set className value!";
347 return;
348 case XFA_IDS_UNABLE_SET_LENGTH_VALUE:
349 wsString = L"Unable to set length value!";
350 return;
351 case XFA_IDS_UNSUPPORT_CHAR:
352 wsString = L"unsupported char '%c'";
353 return;
354 case XFA_IDS_BAD_SUFFIX:
355 wsString = L"bad suffix on number";
356 return;
357 case XFA_IDS_EXPECTED_IDENT:
358 wsString = L"expected identifier instead of '%s'";
359 return;
360 case XFA_IDS_EXPECTED_STRING:
361 wsString = L"expected '%s' instead of '%s'";
362 return;
363 case XFA_IDS_INVALIDATE_CHAR:
364 wsString = L"invalidate char '%c'";
365 return;
366 case XFA_IDS_REDEFINITION:
367 wsString = L"'%s' redefinition ";
368 return;
369 case XFA_IDS_INVALIDATE_TOKEN:
370 wsString = L"invalidate token '%s'";
371 return;
372 case XFA_IDS_INVALIDATE_EXPRESSION:
373 wsString = L"invalidate expression '%s'";
374 return;
375 case XFA_IDS_UNDEFINE_IDENTIFIER:
376 wsString = L"undefined identifier '%s'";
377 return;
378 case XFA_IDS_INVALIDATE_LEFTVALUE:
379 wsString = L"invalidate left-value '%s'";
380 return;
381 case XFA_IDS_COMPILER_ERROR:
382 wsString = L"compiler error";
383 return;
384 case XFA_IDS_CANNOT_MODIFY_VALUE:
385 wsString = L"can't modify the '%s' value";
386 return;
387 case XFA_IDS_ERROR_PARAMETERS:
388 wsString = L"function '%s' has not %d parameters";
389 return;
390 case XFA_IDS_EXPECT_ENDIF:
391 wsString = L"expected 'endif' instead of '%s'";
392 return;
393 case XFA_IDS_UNEXPECTED_EXPRESSION:
394 wsString = L"unexpected expression '%s'";
395 return;
396 case XFA_IDS_CONDITION_IS_NULL:
397 wsString = L"condition is null";
398 return;
399 case XFA_IDS_ILLEGALBREAK:
400 wsString = L"illegal break";
401 return;
402 case XFA_IDS_ILLEGALCONTINUE:
403 wsString = L"illegal continue";
404 return;
405 case XFA_IDS_EXPECTED_OPERATOR:
406 wsString = L"expected operator '%s' instead of '%s'";
407 return;
408 case XFA_IDS_DIVIDE_ZERO:
409 wsString = L"divide by zero";
410 return;
411 case XFA_IDS_CANNOT_COVERT_OBJECT:
412 wsString = L"%s.%s can not covert to object";
413 return;
414 case XFA_IDS_NOT_FOUND_CONTAINER:
415 wsString = L"can not found container '%s'";
416 return;
417 case XFA_IDS_NOT_FOUND_PROPERTY:
418 wsString = L"can not found property '%s'";
419 return;
420 case XFA_IDS_NOT_FOUND_METHOD:
421 wsString = L"can not found method '%s'";
422 return;
423 case XFA_IDS_NOT_FOUND_CONST:
424 wsString = L"can not found const '%s'";
425 return;
426 case XFA_IDS_NOT_ASSIGN_OBJECT:
427 wsString = L"can not direct assign value to object";
428 return;
429 case XFA_IDS_IVALIDATE_INSTRUCTION:
430 wsString = L"invalidate instruction";
431 return;
432 case XFA_IDS_EXPECT_NUMBER:
433 wsString = L"expected number instead of '%s'";
434 return;
435 case XFA_IDS_VALIDATE_OUT_ARRAY:
436 wsString = L"validate access index '%s' out of array";
437 return;
438 case XFA_IDS_CANNOT_ASSIGN_IDENT:
439 wsString = L"can not assign to %s";
440 return;
441 case XFA_IDS_NOT_FOUNT_FUNCTION:
442 wsString = L"can not found '%s' function";
443 return;
444 case XFA_IDS_NOT_ARRAY:
445 wsString = L"'%s' doesn't an array";
446 return;
447 case XFA_IDS_OUT_ARRAY:
448 wsString = L"out of range of '%s' array";
449 return;
450 case XFA_IDS_NOT_SUPPORT_CALC:
451 wsString = L"'%s' operator can not support array calculate";
452 return;
453 case XFA_IDS_ARGUMENT_NOT_ARRAY:
454 wsString = L"'%s' function's %d argument can not be array";
455 return;
456 case XFA_IDS_ARGUMENT_EXPECT_CONTAINER:
457 wsString = L"'%s' argument expected a container";
458 return;
459 case XFA_IDS_ACCESS_PROPERTY_IN_NOT_OBJECT:
460 wsString =
461 L"an attempt was made to reference property '%s' of a non-object in "
462 L"SOM expression %s";
463 return;
464 case XFA_IDS_FUNCTION_IS_BUILDIN:
465 wsString = L"function '%s' is buildin";
466 return;
467 case XFA_IDS_ERROR_MSG:
468 wsString = L"%s : %s";
469 return;
470 case XFA_IDS_INDEX_OUT_OF_BOUNDS:
471 wsString = L"Index value is out of bounds";
472 return;
473 case XFA_IDS_INCORRECT_NUMBER_OF_METHOD:
474 wsString = L"Incorrect number of parameters calling method '%s'";
475 return;
476 case XFA_IDS_ARGUMENT_MISMATCH:
477 wsString = L"Argument mismatch in property or function argument";
478 return;
479 case XFA_IDS_INVALID_ENUMERATE:
480 wsString = L"Invalid enumerated value: %s";
481 return;
482 case XFA_IDS_INVALID_APPEND:
483 wsString =
484 L"Invalid append operation: %s cannot have a child element of %s";
485 return;
486 case XFA_IDS_SOM_EXPECTED_LIST:
487 wsString =
488 L"SOM expression returned list when single result was expected";
489 return;
490 case XFA_IDS_NOT_HAVE_PROPERTY:
491 wsString = L"'%s' doesn't have property '%s'";
492 return;
493 case XFA_IDS_INVALID_NODE_TYPE:
494 wsString = L"Invalid node type : '%s'";
495 return;
496 case XFA_IDS_VIOLATE_BOUNDARY:
497 wsString =
498 L"The element [%s] has violated its allowable number of occurrences";
499 return;
500 case XFA_IDS_SERVER_DENY:
501 wsString = L"Server does not permit";
502 return;
503 case XFA_IDS_ValidateLimit:
504 wsString = FX_WSTRC(
505 L"Message limit exceeded. Remaining %d validation errors not "
506 L"reported.");
507 return;
508 case XFA_IDS_ValidateNullWarning:
509 wsString = FX_WSTRC(
510 L"%s cannot be left blank. To ignore validations for %s, click "
511 L"Ignore.");
512 return;
513 case XFA_IDS_ValidateNullError:
514 wsString = FX_WSTRC(L"%s cannot be left blank.");
515 return;
516 case XFA_IDS_ValidateWarning:
517 wsString = FX_WSTRC(
518 L"The value you entered for %s is invalid. To ignore validations for "
519 L"%s, click Ignore.");
520 return;
521 case XFA_IDS_ValidateError:
522 wsString = FX_WSTRC(L"The value you entered for %s is invalid.");
523 return;
524 }
525 }
526
527 FX_BOOL CPDFXFA_App::ShowFileDialog(const CFX_WideStringC& wsTitle,
528 const CFX_WideStringC& wsFilter,
529 CFX_WideStringArray& wsPathArr,
530 FX_BOOL bOpen) {
531 return FALSE;
532 }
533
534 IFWL_AdapterTimerMgr* CPDFXFA_App::GetTimerMgr() {
535 CXFA_FWLAdapterTimerMgr* pAdapter = NULL;
536 CPDFDoc_Environment* pEnv = m_pEnvList.GetAt(0);
537 if (pEnv)
538 pAdapter = new CXFA_FWLAdapterTimerMgr(pEnv);
539 return pAdapter;
540 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/fpdfview_embeddertest.cpp ('k') | fpdfsdk/src/fpdfxfa/fpdfxfa_doc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698