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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 } | 157 } |
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, CFX_WideString::FromUTF8(bsValue, bsValue.GetLength())); | 167 hDoc, |
| 168 CFX_WideString::FromUTF8(bsValue, bsValue.GetLength()).AsWideStringC()); |
168 return; | 169 return; |
169 } | 170 } |
170 CFX_WideString wsTitle; | 171 CFX_WideString wsTitle; |
171 pNotify->GetDocProvider()->GetTitle(hDoc, wsTitle); | 172 pNotify->GetDocProvider()->GetTitle(hDoc, wsTitle); |
172 FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsTitle).AsByteStringC()); | 173 FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsTitle).AsByteStringC()); |
173 } | 174 } |
174 void CScript_HostPseudoModel::Script_HostPseudoModel_ValidationsEnabled( | 175 void CScript_HostPseudoModel::Script_HostPseudoModel_ValidationsEnabled( |
175 FXJSE_HVALUE hValue, | 176 FXJSE_HVALUE hValue, |
176 FX_BOOL bSetting, | 177 FX_BOOL bSetting, |
177 XFA_ATTRIBUTE eAttribute) { | 178 XFA_ATTRIBUTE eAttribute) { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); | 286 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); |
286 if (!pNotify) { | 287 if (!pNotify) { |
287 return; | 288 return; |
288 } | 289 } |
289 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); | 290 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); |
290 CFX_WideString wsURL; | 291 CFX_WideString wsURL; |
291 if (iLength >= 1) { | 292 if (iLength >= 1) { |
292 CFX_ByteString bsURL = pArguments->GetUTF8String(0); | 293 CFX_ByteString bsURL = pArguments->GetUTF8String(0); |
293 wsURL = CFX_WideString::FromUTF8(bsURL, bsURL.GetLength()); | 294 wsURL = CFX_WideString::FromUTF8(bsURL, bsURL.GetLength()); |
294 } | 295 } |
295 pNotify->GetDocProvider()->GotoURL(hDoc, wsURL); | 296 pNotify->GetDocProvider()->GotoURL(hDoc, wsURL.AsWideStringC()); |
296 } | 297 } |
297 void CScript_HostPseudoModel::Script_HostPseudoModel_OpenList( | 298 void CScript_HostPseudoModel::Script_HostPseudoModel_OpenList( |
298 CFXJSE_Arguments* pArguments) { | 299 CFXJSE_Arguments* pArguments) { |
299 if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { | 300 if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { |
300 return; | 301 return; |
301 } | 302 } |
302 int32_t iLength = pArguments->GetLength(); | 303 int32_t iLength = pArguments->GetLength(); |
303 if (iLength != 1) { | 304 if (iLength != 1) { |
304 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"openList"); | 305 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"openList"); |
305 return; | 306 return; |
(...skipping 18 matching lines...) Expand all Loading... |
324 return; | 325 return; |
325 } | 326 } |
326 CXFA_Object* pObject = pScriptContext->GetThisObject(); | 327 CXFA_Object* pObject = pScriptContext->GetThisObject(); |
327 if (!pObject) { | 328 if (!pObject) { |
328 FXJSE_Value_Release(hValue); | 329 FXJSE_Value_Release(hValue); |
329 return; | 330 return; |
330 } | 331 } |
331 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Parent | | 332 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Parent | |
332 XFA_RESOLVENODE_Siblings; | 333 XFA_RESOLVENODE_Siblings; |
333 XFA_RESOLVENODE_RS resoveNodeRS; | 334 XFA_RESOLVENODE_RS resoveNodeRS; |
334 int32_t iRet = pScriptContext->ResolveObjects(pObject, wsExpression, | 335 int32_t iRet = pScriptContext->ResolveObjects( |
335 resoveNodeRS, dwFlag); | 336 pObject, wsExpression.AsWideStringC(), resoveNodeRS, dwFlag); |
336 if (iRet < 1 || !resoveNodeRS.nodes[0]->IsNode()) { | 337 if (iRet < 1 || !resoveNodeRS.nodes[0]->IsNode()) { |
337 FXJSE_Value_Release(hValue); | 338 FXJSE_Value_Release(hValue); |
338 return; | 339 return; |
339 } | 340 } |
340 pNode = resoveNodeRS.nodes[0]->AsNode(); | 341 pNode = resoveNodeRS.nodes[0]->AsNode(); |
341 } | 342 } |
342 FXJSE_Value_Release(hValue); | 343 FXJSE_Value_Release(hValue); |
343 } | 344 } |
344 CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout(); | 345 CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout(); |
345 if (!pDocLayout) { | 346 if (!pDocLayout) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 } | 379 } |
379 if (iLength >= 3) { | 380 if (iLength >= 3) { |
380 CFX_ByteString bsDefaultAnswer = pArguments->GetUTF8String(2); | 381 CFX_ByteString bsDefaultAnswer = pArguments->GetUTF8String(2); |
381 wsDefaultAnswer = | 382 wsDefaultAnswer = |
382 CFX_WideString::FromUTF8(bsDefaultAnswer, bsDefaultAnswer.GetLength()); | 383 CFX_WideString::FromUTF8(bsDefaultAnswer, bsDefaultAnswer.GetLength()); |
383 } | 384 } |
384 if (iLength >= 4) { | 385 if (iLength >= 4) { |
385 bMark = pArguments->GetInt32(3) == 0 ? FALSE : TRUE; | 386 bMark = pArguments->GetInt32(3) == 0 ? FALSE : TRUE; |
386 } | 387 } |
387 CFX_WideString wsAnswer; | 388 CFX_WideString wsAnswer; |
388 pNotify->GetAppProvider()->Response(wsAnswer, wsQuestion, wsTitle, | 389 pNotify->GetAppProvider()->Response(wsAnswer, wsQuestion.AsWideStringC(), |
389 wsDefaultAnswer, bMark); | 390 wsTitle.AsWideStringC(), |
| 391 wsDefaultAnswer.AsWideStringC(), bMark); |
390 FXJSE_HVALUE hValue = pArguments->GetReturnValue(); | 392 FXJSE_HVALUE hValue = pArguments->GetReturnValue(); |
391 if (hValue) { | 393 if (hValue) { |
392 FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsAnswer).AsByteStringC()); | 394 FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsAnswer).AsByteStringC()); |
393 } | 395 } |
394 } | 396 } |
395 void CScript_HostPseudoModel::Script_HostPseudoModel_DocumentInBatch( | 397 void CScript_HostPseudoModel::Script_HostPseudoModel_DocumentInBatch( |
396 CFXJSE_Arguments* pArguments) { | 398 CFXJSE_Arguments* pArguments) { |
397 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); | 399 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); |
398 if (!pNotify) { | 400 if (!pNotify) { |
399 return; | 401 return; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 } | 449 } |
448 if (wsExpression.IsEmpty()) { | 450 if (wsExpression.IsEmpty()) { |
449 pNotify->ResetData(); | 451 pNotify->ResetData(); |
450 return; | 452 return; |
451 } | 453 } |
452 int32_t iStart = 0; | 454 int32_t iStart = 0; |
453 CFX_WideString wsName; | 455 CFX_WideString wsName; |
454 CXFA_Node* pNode = NULL; | 456 CXFA_Node* pNode = NULL; |
455 int32_t iExpLength = wsExpression.GetLength(); | 457 int32_t iExpLength = wsExpression.GetLength(); |
456 while (iStart < iExpLength) { | 458 while (iStart < iExpLength) { |
457 iStart = XFA_FilterName(wsExpression, iStart, wsName); | 459 iStart = XFA_FilterName(wsExpression.AsWideStringC(), iStart, wsName); |
458 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); | 460 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
459 if (!pScriptContext) { | 461 if (!pScriptContext) { |
460 return; | 462 return; |
461 } | 463 } |
462 CXFA_Object* pObject = pScriptContext->GetThisObject(); | 464 CXFA_Object* pObject = pScriptContext->GetThisObject(); |
463 if (!pObject) { | 465 if (!pObject) { |
464 return; | 466 return; |
465 } | 467 } |
466 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Parent | | 468 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Parent | |
467 XFA_RESOLVENODE_Siblings; | 469 XFA_RESOLVENODE_Siblings; |
468 XFA_RESOLVENODE_RS resoveNodeRS; | 470 XFA_RESOLVENODE_RS resoveNodeRS; |
469 int32_t iRet = | 471 int32_t iRet = pScriptContext->ResolveObjects( |
470 pScriptContext->ResolveObjects(pObject, wsName, resoveNodeRS, dwFlag); | 472 pObject, wsName.AsWideStringC(), resoveNodeRS, dwFlag); |
471 if (iRet < 1 || !resoveNodeRS.nodes[0]->IsNode()) { | 473 if (iRet < 1 || !resoveNodeRS.nodes[0]->IsNode()) { |
472 continue; | 474 continue; |
473 } | 475 } |
474 pNode = resoveNodeRS.nodes[0]->AsNode(); | 476 pNode = resoveNodeRS.nodes[0]->AsNode(); |
475 pNotify->ResetData(pNode->GetWidgetData()); | 477 pNotify->ResetData(pNode->GetWidgetData()); |
476 } | 478 } |
477 if (!pNode) { | 479 if (!pNode) { |
478 pNotify->ResetData(); | 480 pNotify->ResetData(); |
479 } | 481 } |
480 } | 482 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 return; | 530 return; |
529 } | 531 } |
530 CXFA_Object* pObject = pScriptContext->GetThisObject(); | 532 CXFA_Object* pObject = pScriptContext->GetThisObject(); |
531 if (!pObject) { | 533 if (!pObject) { |
532 FXJSE_Value_Release(hValue); | 534 FXJSE_Value_Release(hValue); |
533 return; | 535 return; |
534 } | 536 } |
535 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Parent | | 537 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Parent | |
536 XFA_RESOLVENODE_Siblings; | 538 XFA_RESOLVENODE_Siblings; |
537 XFA_RESOLVENODE_RS resoveNodeRS; | 539 XFA_RESOLVENODE_RS resoveNodeRS; |
538 int32_t iRet = pScriptContext->ResolveObjects(pObject, wsExpression, | 540 int32_t iRet = pScriptContext->ResolveObjects( |
539 resoveNodeRS, dwFlag); | 541 pObject, wsExpression.AsWideStringC(), resoveNodeRS, dwFlag); |
540 if (iRet < 1 || !resoveNodeRS.nodes[0]->IsNode()) { | 542 if (iRet < 1 || !resoveNodeRS.nodes[0]->IsNode()) { |
541 FXJSE_Value_Release(hValue); | 543 FXJSE_Value_Release(hValue); |
542 return; | 544 return; |
543 } | 545 } |
544 pNode = resoveNodeRS.nodes[0]->AsNode(); | 546 pNode = resoveNodeRS.nodes[0]->AsNode(); |
545 } | 547 } |
546 FXJSE_Value_Release(hValue); | 548 FXJSE_Value_Release(hValue); |
547 } | 549 } |
548 pNotify->SetFocusWidgetNode(pNode); | 550 pNotify->SetFocusWidgetNode(pNode); |
549 } | 551 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 dwMessageType = XFA_MBICON_Error; | 596 dwMessageType = XFA_MBICON_Error; |
595 } | 597 } |
596 } | 598 } |
597 if (iLength >= 4) { | 599 if (iLength >= 4) { |
598 dwButtonType = pArguments->GetInt32(3); | 600 dwButtonType = pArguments->GetInt32(3); |
599 if (dwButtonType > XFA_MB_YesNoCancel) { | 601 if (dwButtonType > XFA_MB_YesNoCancel) { |
600 dwButtonType = XFA_MB_OK; | 602 dwButtonType = XFA_MB_OK; |
601 } | 603 } |
602 } | 604 } |
603 int32_t iValue = pNotify->GetAppProvider()->MsgBox( | 605 int32_t iValue = pNotify->GetAppProvider()->MsgBox( |
604 wsMessage, bsTitle, dwMessageType, dwButtonType); | 606 wsMessage.AsWideStringC(), bsTitle.AsWideStringC(), dwMessageType, |
| 607 dwButtonType); |
605 FXJSE_HVALUE hValue = pArguments->GetReturnValue(); | 608 FXJSE_HVALUE hValue = pArguments->GetReturnValue(); |
606 if (hValue) { | 609 if (hValue) { |
607 FXJSE_Value_SetInteger(hValue, iValue); | 610 FXJSE_Value_SetInteger(hValue, iValue); |
608 } | 611 } |
609 } | 612 } |
610 FX_BOOL CScript_HostPseudoModel::Script_HostPseudoModel_ValidateArgsForMsg( | 613 FX_BOOL CScript_HostPseudoModel::Script_HostPseudoModel_ValidateArgsForMsg( |
611 CFXJSE_Arguments* pArguments, | 614 CFXJSE_Arguments* pArguments, |
612 int32_t iArgIndex, | 615 int32_t iArgIndex, |
613 CFX_WideString& wsValue) { | 616 CFX_WideString& wsValue) { |
614 if (pArguments == NULL || iArgIndex < 0) { | 617 if (pArguments == NULL || iArgIndex < 0) { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); | 729 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); |
727 if (!pNotify) { | 730 if (!pNotify) { |
728 return; | 731 return; |
729 } | 732 } |
730 CFX_WideString wsFilePath; | 733 CFX_WideString wsFilePath; |
731 if (iLength > 0) { | 734 if (iLength > 0) { |
732 CFX_ByteString bsFilePath = pArguments->GetUTF8String(0); | 735 CFX_ByteString bsFilePath = pArguments->GetUTF8String(0); |
733 wsFilePath = CFX_WideString::FromUTF8(bsFilePath, bsFilePath.GetLength()); | 736 wsFilePath = CFX_WideString::FromUTF8(bsFilePath, bsFilePath.GetLength()); |
734 } | 737 } |
735 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); | 738 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); |
736 pNotify->GetDocProvider()->ImportData(hDoc, wsFilePath); | 739 pNotify->GetDocProvider()->ImportData(hDoc, wsFilePath.AsWideStringC()); |
737 } | 740 } |
738 void CScript_HostPseudoModel::Script_HostPseudoModel_ExportData( | 741 void CScript_HostPseudoModel::Script_HostPseudoModel_ExportData( |
739 CFXJSE_Arguments* pArguments) { | 742 CFXJSE_Arguments* pArguments) { |
740 int32_t iLength = pArguments->GetLength(); | 743 int32_t iLength = pArguments->GetLength(); |
741 if (iLength < 0 || iLength > 2) { | 744 if (iLength < 0 || iLength > 2) { |
742 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"exportData"); | 745 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"exportData"); |
743 return; | 746 return; |
744 } | 747 } |
745 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); | 748 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); |
746 if (!pNotify) { | 749 if (!pNotify) { |
747 return; | 750 return; |
748 } | 751 } |
749 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); | 752 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); |
750 CFX_WideString wsFilePath; | 753 CFX_WideString wsFilePath; |
751 FX_BOOL bXDP = TRUE; | 754 FX_BOOL bXDP = TRUE; |
752 if (iLength >= 1) { | 755 if (iLength >= 1) { |
753 CFX_ByteString bsFilePath = pArguments->GetUTF8String(0); | 756 CFX_ByteString bsFilePath = pArguments->GetUTF8String(0); |
754 wsFilePath = CFX_WideString::FromUTF8(bsFilePath, bsFilePath.GetLength()); | 757 wsFilePath = CFX_WideString::FromUTF8(bsFilePath, bsFilePath.GetLength()); |
755 } | 758 } |
756 if (iLength >= 2) { | 759 if (iLength >= 2) { |
757 bXDP = pArguments->GetInt32(1) == 0 ? FALSE : TRUE; | 760 bXDP = pArguments->GetInt32(1) == 0 ? FALSE : TRUE; |
758 } | 761 } |
759 pNotify->GetDocProvider()->ExportData(hDoc, wsFilePath, bXDP); | 762 pNotify->GetDocProvider()->ExportData(hDoc, wsFilePath.AsWideStringC(), bXDP); |
760 } | 763 } |
761 void CScript_HostPseudoModel::Script_HostPseudoModel_PageUp( | 764 void CScript_HostPseudoModel::Script_HostPseudoModel_PageUp( |
762 CFXJSE_Arguments* pArguments) { | 765 CFXJSE_Arguments* pArguments) { |
763 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); | 766 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); |
764 if (!pNotify) { | 767 if (!pNotify) { |
765 return; | 768 return; |
766 } | 769 } |
767 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); | 770 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); |
768 int32_t nCurPage = pNotify->GetDocProvider()->GetCurrentPage(hDoc); | 771 int32_t nCurPage = pNotify->GetDocProvider()->GetCurrentPage(hDoc); |
769 int32_t nNewPage = 0; | 772 int32_t nNewPage = 0; |
(...skipping 29 matching lines...) Expand all Loading... |
799 if (!pNotify) { | 802 if (!pNotify) { |
800 return; | 803 return; |
801 } | 804 } |
802 CFX_WideString wsDataTime = pNotify->GetCurrentDateTime(); | 805 CFX_WideString wsDataTime = pNotify->GetCurrentDateTime(); |
803 FXJSE_HVALUE hValue = pArguments->GetReturnValue(); | 806 FXJSE_HVALUE hValue = pArguments->GetReturnValue(); |
804 if (hValue) { | 807 if (hValue) { |
805 FXJSE_Value_SetUTF8String(hValue, | 808 FXJSE_Value_SetUTF8String(hValue, |
806 FX_UTF8Encode(wsDataTime).AsByteStringC()); | 809 FX_UTF8Encode(wsDataTime).AsByteStringC()); |
807 } | 810 } |
808 } | 811 } |
OLD | NEW |