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 "xfa/fxfa/parser/xfa_script_hostpseudomodel.h" | 7 #include "xfa/fxfa/parser/xfa_script_hostpseudomodel.h" |
8 | 8 |
9 #include "xfa/fxfa/app/xfa_ffnotify.h" | 9 #include "xfa/fxfa/app/xfa_ffnotify.h" |
10 #include "xfa/fxfa/fm2js/xfa_fm2jsapi.h" | 10 #include "xfa/fxfa/fm2js/xfa_fm2jsapi.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); | 158 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); |
159 if (!pNotify) { | 159 if (!pNotify) { |
160 return; | 160 return; |
161 } | 161 } |
162 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); | 162 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); |
163 if (bSetting) { | 163 if (bSetting) { |
164 CFX_ByteString bsValue; | 164 CFX_ByteString bsValue; |
165 FXJSE_Value_ToUTF8String(hValue, bsValue); | 165 FXJSE_Value_ToUTF8String(hValue, bsValue); |
166 pNotify->GetDocProvider()->SetTitle( | 166 pNotify->GetDocProvider()->SetTitle( |
167 hDoc, | 167 hDoc, |
168 CFX_WideString::FromUTF8(bsValue, bsValue.GetLength()).AsWideStringC()); | 168 CFX_WideString::FromUTF8(bsValue.AsByteStringC()).AsWideStringC()); |
169 return; | 169 return; |
170 } | 170 } |
171 CFX_WideString wsTitle; | 171 CFX_WideString wsTitle; |
172 pNotify->GetDocProvider()->GetTitle(hDoc, wsTitle); | 172 pNotify->GetDocProvider()->GetTitle(hDoc, wsTitle); |
173 FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsTitle).AsByteStringC()); | 173 FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsTitle).AsByteStringC()); |
174 } | 174 } |
175 void CScript_HostPseudoModel::Script_HostPseudoModel_ValidationsEnabled( | 175 void CScript_HostPseudoModel::Script_HostPseudoModel_ValidationsEnabled( |
176 FXJSE_HVALUE hValue, | 176 FXJSE_HVALUE hValue, |
177 FX_BOOL bSetting, | 177 FX_BOOL bSetting, |
178 XFA_ATTRIBUTE eAttribute) { | 178 XFA_ATTRIBUTE eAttribute) { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 return; | 284 return; |
285 } | 285 } |
286 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); | 286 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); |
287 if (!pNotify) { | 287 if (!pNotify) { |
288 return; | 288 return; |
289 } | 289 } |
290 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); | 290 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); |
291 CFX_WideString wsURL; | 291 CFX_WideString wsURL; |
292 if (iLength >= 1) { | 292 if (iLength >= 1) { |
293 CFX_ByteString bsURL = pArguments->GetUTF8String(0); | 293 CFX_ByteString bsURL = pArguments->GetUTF8String(0); |
294 wsURL = CFX_WideString::FromUTF8(bsURL, bsURL.GetLength()); | 294 wsURL = CFX_WideString::FromUTF8(bsURL.AsByteStringC()); |
295 } | 295 } |
296 pNotify->GetDocProvider()->GotoURL(hDoc, wsURL.AsWideStringC()); | 296 pNotify->GetDocProvider()->GotoURL(hDoc, wsURL.AsWideStringC()); |
297 } | 297 } |
298 void CScript_HostPseudoModel::Script_HostPseudoModel_OpenList( | 298 void CScript_HostPseudoModel::Script_HostPseudoModel_OpenList( |
299 CFXJSE_Arguments* pArguments) { | 299 CFXJSE_Arguments* pArguments) { |
300 if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { | 300 if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { |
301 return; | 301 return; |
302 } | 302 } |
303 int32_t iLength = pArguments->GetLength(); | 303 int32_t iLength = pArguments->GetLength(); |
304 if (iLength != 1) { | 304 if (iLength != 1) { |
305 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"openList"); | 305 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"openList"); |
306 return; | 306 return; |
307 } | 307 } |
308 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); | 308 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); |
309 if (!pNotify) { | 309 if (!pNotify) { |
310 return; | 310 return; |
311 } | 311 } |
312 CXFA_Node* pNode = NULL; | 312 CXFA_Node* pNode = NULL; |
313 if (iLength >= 1) { | 313 if (iLength >= 1) { |
314 FXJSE_HVALUE hValue = pArguments->GetValue(0); | 314 FXJSE_HVALUE hValue = pArguments->GetValue(0); |
315 if (FXJSE_Value_IsObject(hValue)) { | 315 if (FXJSE_Value_IsObject(hValue)) { |
316 pNode = static_cast<CXFA_Node*>(FXJSE_Value_ToObject(hValue, nullptr)); | 316 pNode = static_cast<CXFA_Node*>(FXJSE_Value_ToObject(hValue, nullptr)); |
317 } else if (FXJSE_Value_IsUTF8String(hValue)) { | 317 } else if (FXJSE_Value_IsUTF8String(hValue)) { |
318 CFX_ByteString bsString; | 318 CFX_ByteString bsString; |
319 FXJSE_Value_ToUTF8String(hValue, bsString); | 319 FXJSE_Value_ToUTF8String(hValue, bsString); |
320 CFX_WideString wsExpression = | 320 CFX_WideString wsExpression = |
321 CFX_WideString::FromUTF8(bsString, bsString.GetLength()); | 321 CFX_WideString::FromUTF8(bsString.AsByteStringC()); |
322 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); | 322 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
323 if (!pScriptContext) { | 323 if (!pScriptContext) { |
324 FXJSE_Value_Release(hValue); | 324 FXJSE_Value_Release(hValue); |
325 return; | 325 return; |
326 } | 326 } |
327 CXFA_Object* pObject = pScriptContext->GetThisObject(); | 327 CXFA_Object* pObject = pScriptContext->GetThisObject(); |
328 if (!pObject) { | 328 if (!pObject) { |
329 FXJSE_Value_Release(hValue); | 329 FXJSE_Value_Release(hValue); |
330 return; | 330 return; |
331 } | 331 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); | 364 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); |
365 if (!pNotify) { | 365 if (!pNotify) { |
366 return; | 366 return; |
367 } | 367 } |
368 CFX_WideString wsQuestion; | 368 CFX_WideString wsQuestion; |
369 CFX_WideString wsTitle; | 369 CFX_WideString wsTitle; |
370 CFX_WideString wsDefaultAnswer; | 370 CFX_WideString wsDefaultAnswer; |
371 FX_BOOL bMark = FALSE; | 371 FX_BOOL bMark = FALSE; |
372 if (iLength >= 1) { | 372 if (iLength >= 1) { |
373 CFX_ByteString bsQuestion = pArguments->GetUTF8String(0); | 373 CFX_ByteString bsQuestion = pArguments->GetUTF8String(0); |
374 wsQuestion = CFX_WideString::FromUTF8(bsQuestion, bsQuestion.GetLength()); | 374 wsQuestion = CFX_WideString::FromUTF8(bsQuestion.AsByteStringC()); |
375 } | 375 } |
376 if (iLength >= 2) { | 376 if (iLength >= 2) { |
377 CFX_ByteString bsTitle = pArguments->GetUTF8String(1); | 377 CFX_ByteString bsTitle = pArguments->GetUTF8String(1); |
378 wsTitle = CFX_WideString::FromUTF8(bsTitle, bsTitle.GetLength()); | 378 wsTitle = CFX_WideString::FromUTF8(bsTitle.AsByteStringC()); |
379 } | 379 } |
380 if (iLength >= 3) { | 380 if (iLength >= 3) { |
381 CFX_ByteString bsDefaultAnswer = pArguments->GetUTF8String(2); | 381 CFX_ByteString bsDefaultAnswer = pArguments->GetUTF8String(2); |
382 wsDefaultAnswer = | 382 wsDefaultAnswer = CFX_WideString::FromUTF8(bsDefaultAnswer.AsByteStringC()); |
383 CFX_WideString::FromUTF8(bsDefaultAnswer, bsDefaultAnswer.GetLength()); | |
384 } | 383 } |
385 if (iLength >= 4) { | 384 if (iLength >= 4) { |
386 bMark = pArguments->GetInt32(3) == 0 ? FALSE : TRUE; | 385 bMark = pArguments->GetInt32(3) == 0 ? FALSE : TRUE; |
387 } | 386 } |
388 CFX_WideString wsAnswer; | 387 CFX_WideString wsAnswer; |
389 pNotify->GetAppProvider()->Response(wsAnswer, wsQuestion.AsWideStringC(), | 388 pNotify->GetAppProvider()->Response(wsAnswer, wsQuestion.AsWideStringC(), |
390 wsTitle.AsWideStringC(), | 389 wsTitle.AsWideStringC(), |
391 wsDefaultAnswer.AsWideStringC(), bMark); | 390 wsDefaultAnswer.AsWideStringC(), bMark); |
392 FXJSE_HVALUE hValue = pArguments->GetReturnValue(); | 391 FXJSE_HVALUE hValue = pArguments->GetReturnValue(); |
393 if (hValue) { | 392 if (hValue) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resetData"); | 436 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resetData"); |
438 return; | 437 return; |
439 } | 438 } |
440 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); | 439 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); |
441 if (!pNotify) { | 440 if (!pNotify) { |
442 return; | 441 return; |
443 } | 442 } |
444 CFX_WideString wsExpression; | 443 CFX_WideString wsExpression; |
445 if (iLength >= 1) { | 444 if (iLength >= 1) { |
446 CFX_ByteString bsExpression = pArguments->GetUTF8String(0); | 445 CFX_ByteString bsExpression = pArguments->GetUTF8String(0); |
447 wsExpression = | 446 wsExpression = CFX_WideString::FromUTF8(bsExpression.AsByteStringC()); |
448 CFX_WideString::FromUTF8(bsExpression, bsExpression.GetLength()); | |
449 } | 447 } |
450 if (wsExpression.IsEmpty()) { | 448 if (wsExpression.IsEmpty()) { |
451 pNotify->ResetData(); | 449 pNotify->ResetData(); |
452 return; | 450 return; |
453 } | 451 } |
454 int32_t iStart = 0; | 452 int32_t iStart = 0; |
455 CFX_WideString wsName; | 453 CFX_WideString wsName; |
456 CXFA_Node* pNode = NULL; | 454 CXFA_Node* pNode = NULL; |
457 int32_t iExpLength = wsExpression.GetLength(); | 455 int32_t iExpLength = wsExpression.GetLength(); |
458 while (iStart < iExpLength) { | 456 while (iStart < iExpLength) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 } | 514 } |
517 CXFA_Node* pNode = NULL; | 515 CXFA_Node* pNode = NULL; |
518 if (iLength >= 1) { | 516 if (iLength >= 1) { |
519 FXJSE_HVALUE hValue = pArguments->GetValue(0); | 517 FXJSE_HVALUE hValue = pArguments->GetValue(0); |
520 if (FXJSE_Value_IsObject(hValue)) { | 518 if (FXJSE_Value_IsObject(hValue)) { |
521 pNode = static_cast<CXFA_Node*>(FXJSE_Value_ToObject(hValue, NULL)); | 519 pNode = static_cast<CXFA_Node*>(FXJSE_Value_ToObject(hValue, NULL)); |
522 } else if (FXJSE_Value_IsUTF8String(hValue)) { | 520 } else if (FXJSE_Value_IsUTF8String(hValue)) { |
523 CFX_ByteString bsString; | 521 CFX_ByteString bsString; |
524 FXJSE_Value_ToUTF8String(hValue, bsString); | 522 FXJSE_Value_ToUTF8String(hValue, bsString); |
525 CFX_WideString wsExpression = | 523 CFX_WideString wsExpression = |
526 CFX_WideString::FromUTF8(bsString, bsString.GetLength()); | 524 CFX_WideString::FromUTF8(bsString.AsByteStringC()); |
527 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); | 525 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
528 if (!pScriptContext) { | 526 if (!pScriptContext) { |
529 FXJSE_Value_Release(hValue); | 527 FXJSE_Value_Release(hValue); |
530 return; | 528 return; |
531 } | 529 } |
532 CXFA_Object* pObject = pScriptContext->GetThisObject(); | 530 CXFA_Object* pObject = pScriptContext->GetThisObject(); |
533 if (!pObject) { | 531 if (!pObject) { |
534 FXJSE_Value_Release(hValue); | 532 FXJSE_Value_Release(hValue); |
535 return; | 533 return; |
536 } | 534 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 if (!FXJSE_Value_IsUTF8String(hValueArg) && bIsJsType) { | 624 if (!FXJSE_Value_IsUTF8String(hValueArg) && bIsJsType) { |
627 ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH); | 625 ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH); |
628 FXJSE_Value_Release(hValueArg); | 626 FXJSE_Value_Release(hValueArg); |
629 return FALSE; | 627 return FALSE; |
630 } | 628 } |
631 if (FXJSE_Value_IsNull(hValueArg)) { | 629 if (FXJSE_Value_IsNull(hValueArg)) { |
632 wsValue = FX_WSTRC(L""); | 630 wsValue = FX_WSTRC(L""); |
633 } else { | 631 } else { |
634 CFX_ByteString byMessage; | 632 CFX_ByteString byMessage; |
635 FXJSE_Value_ToUTF8String(hValueArg, byMessage); | 633 FXJSE_Value_ToUTF8String(hValueArg, byMessage); |
636 wsValue = CFX_WideString::FromUTF8(byMessage, byMessage.GetLength()); | 634 wsValue = CFX_WideString::FromUTF8(byMessage.AsByteStringC()); |
637 } | 635 } |
638 FXJSE_Value_Release(hValueArg); | 636 FXJSE_Value_Release(hValueArg); |
639 return TRUE; | 637 return TRUE; |
640 } | 638 } |
641 void CScript_HostPseudoModel::Script_HostPseudoModel_DocumentCountInBatch( | 639 void CScript_HostPseudoModel::Script_HostPseudoModel_DocumentCountInBatch( |
642 CFXJSE_Arguments* pArguments) { | 640 CFXJSE_Arguments* pArguments) { |
643 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); | 641 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); |
644 if (!pNotify) { | 642 if (!pNotify) { |
645 return; | 643 return; |
646 } | 644 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"importData"); | 724 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"importData"); |
727 return; | 725 return; |
728 } | 726 } |
729 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); | 727 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); |
730 if (!pNotify) { | 728 if (!pNotify) { |
731 return; | 729 return; |
732 } | 730 } |
733 CFX_WideString wsFilePath; | 731 CFX_WideString wsFilePath; |
734 if (iLength > 0) { | 732 if (iLength > 0) { |
735 CFX_ByteString bsFilePath = pArguments->GetUTF8String(0); | 733 CFX_ByteString bsFilePath = pArguments->GetUTF8String(0); |
736 wsFilePath = CFX_WideString::FromUTF8(bsFilePath, bsFilePath.GetLength()); | 734 wsFilePath = CFX_WideString::FromUTF8(bsFilePath.AsByteStringC()); |
737 } | 735 } |
738 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); | 736 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); |
739 pNotify->GetDocProvider()->ImportData(hDoc, wsFilePath.AsWideStringC()); | 737 pNotify->GetDocProvider()->ImportData(hDoc, wsFilePath.AsWideStringC()); |
740 } | 738 } |
741 void CScript_HostPseudoModel::Script_HostPseudoModel_ExportData( | 739 void CScript_HostPseudoModel::Script_HostPseudoModel_ExportData( |
742 CFXJSE_Arguments* pArguments) { | 740 CFXJSE_Arguments* pArguments) { |
743 int32_t iLength = pArguments->GetLength(); | 741 int32_t iLength = pArguments->GetLength(); |
744 if (iLength < 0 || iLength > 2) { | 742 if (iLength < 0 || iLength > 2) { |
745 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"exportData"); | 743 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"exportData"); |
746 return; | 744 return; |
747 } | 745 } |
748 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); | 746 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); |
749 if (!pNotify) { | 747 if (!pNotify) { |
750 return; | 748 return; |
751 } | 749 } |
752 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); | 750 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); |
753 CFX_WideString wsFilePath; | 751 CFX_WideString wsFilePath; |
754 FX_BOOL bXDP = TRUE; | 752 FX_BOOL bXDP = TRUE; |
755 if (iLength >= 1) { | 753 if (iLength >= 1) { |
756 CFX_ByteString bsFilePath = pArguments->GetUTF8String(0); | 754 CFX_ByteString bsFilePath = pArguments->GetUTF8String(0); |
757 wsFilePath = CFX_WideString::FromUTF8(bsFilePath, bsFilePath.GetLength()); | 755 wsFilePath = CFX_WideString::FromUTF8(bsFilePath.AsByteStringC()); |
758 } | 756 } |
759 if (iLength >= 2) { | 757 if (iLength >= 2) { |
760 bXDP = pArguments->GetInt32(1) == 0 ? FALSE : TRUE; | 758 bXDP = pArguments->GetInt32(1) == 0 ? FALSE : TRUE; |
761 } | 759 } |
762 pNotify->GetDocProvider()->ExportData(hDoc, wsFilePath.AsWideStringC(), bXDP); | 760 pNotify->GetDocProvider()->ExportData(hDoc, wsFilePath.AsWideStringC(), bXDP); |
763 } | 761 } |
764 void CScript_HostPseudoModel::Script_HostPseudoModel_PageUp( | 762 void CScript_HostPseudoModel::Script_HostPseudoModel_PageUp( |
765 CFXJSE_Arguments* pArguments) { | 763 CFXJSE_Arguments* pArguments) { |
766 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); | 764 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); |
767 if (!pNotify) { | 765 if (!pNotify) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 if (!pNotify) { | 800 if (!pNotify) { |
803 return; | 801 return; |
804 } | 802 } |
805 CFX_WideString wsDataTime = pNotify->GetCurrentDateTime(); | 803 CFX_WideString wsDataTime = pNotify->GetCurrentDateTime(); |
806 FXJSE_HVALUE hValue = pArguments->GetReturnValue(); | 804 FXJSE_HVALUE hValue = pArguments->GetReturnValue(); |
807 if (hValue) { | 805 if (hValue) { |
808 FXJSE_Value_SetUTF8String(hValue, | 806 FXJSE_Value_SetUTF8String(hValue, |
809 FX_UTF8Encode(wsDataTime).AsByteStringC()); | 807 FX_UTF8Encode(wsDataTime).AsByteStringC()); |
810 } | 808 } |
811 } | 809 } |
OLD | NEW |