| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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_docenvironment.h" | 7 #include "fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h" |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "core/fpdfapi/parser/cpdf_array.h" | 11 #include "core/fpdfapi/parser/cpdf_array.h" |
| 12 #include "core/fpdfapi/parser/cpdf_stream_acc.h" | 12 #include "core/fpdfapi/parser/cpdf_stream_acc.h" |
| 13 #include "core/fpdfapi/parser/cpdf_string.h" | 13 #include "core/fpdfapi/parser/cpdf_string.h" |
| 14 #include "core/fxcrt/cfx_retain_ptr.h" |
| 14 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" | 15 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
| 15 #include "fpdfsdk/cpdfsdk_interform.h" | 16 #include "fpdfsdk/cpdfsdk_interform.h" |
| 16 #include "fpdfsdk/cpdfsdk_pageview.h" | 17 #include "fpdfsdk/cpdfsdk_pageview.h" |
| 17 #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" | 18 #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" |
| 18 #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" | 19 #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" |
| 19 #include "fpdfsdk/javascript/ijs_runtime.h" | 20 #include "fpdfsdk/javascript/ijs_runtime.h" |
| 20 #include "xfa/fxfa/xfa_ffdocview.h" | 21 #include "xfa/fxfa/xfa_ffdocview.h" |
| 21 #include "xfa/fxfa/xfa_ffwidget.h" | 22 #include "xfa/fxfa/xfa_ffwidget.h" |
| 22 #include "xfa/fxfa/xfa_ffwidgethandler.h" | 23 #include "xfa/fxfa/xfa_ffwidgethandler.h" |
| 23 | 24 |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 bs = filepath.UTF16LE_Encode(); | 431 bs = filepath.UTF16LE_Encode(); |
| 431 } | 432 } |
| 432 int len = bs.GetLength(); | 433 int len = bs.GetLength(); |
| 433 FPDF_FILEHANDLER* pFileHandler = | 434 FPDF_FILEHANDLER* pFileHandler = |
| 434 pFormFillEnv->OpenFile(bXDP ? FXFA_SAVEAS_XDP : FXFA_SAVEAS_XML, | 435 pFormFillEnv->OpenFile(bXDP ? FXFA_SAVEAS_XDP : FXFA_SAVEAS_XML, |
| 435 (FPDF_WIDESTRING)bs.GetBuffer(len), "wb"); | 436 (FPDF_WIDESTRING)bs.GetBuffer(len), "wb"); |
| 436 bs.ReleaseBuffer(len); | 437 bs.ReleaseBuffer(len); |
| 437 if (!pFileHandler) | 438 if (!pFileHandler) |
| 438 return; | 439 return; |
| 439 | 440 |
| 440 std::unique_ptr<IFX_SeekableStream, ReleaseDeleter<IFX_SeekableStream>> | 441 CFX_RetainPtr<IFX_SeekableStream> fileWrite = |
| 441 fileWrite(MakeSeekableStream(pFileHandler)); | 442 MakeSeekableStream(pFileHandler); |
| 442 CFX_ByteString content; | 443 CFX_ByteString content; |
| 443 if (fileType == FXFA_SAVEAS_XML) { | 444 if (fileType == FXFA_SAVEAS_XML) { |
| 444 content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"; | 445 content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"; |
| 445 fileWrite->WriteBlock(content.c_str(), fileWrite->GetSize(), | 446 fileWrite->WriteBlock(content.c_str(), fileWrite->GetSize(), |
| 446 content.GetLength()); | 447 content.GetLength()); |
| 447 m_pContext->GetXFADocView()->GetDoc()->SavePackage( | 448 m_pContext->GetXFADocView()->GetDoc()->SavePackage(XFA_HASHCODE_Data, |
| 448 XFA_HASHCODE_Data, fileWrite.get(), nullptr); | 449 fileWrite, nullptr); |
| 449 } else if (fileType == FXFA_SAVEAS_XDP) { | 450 } else if (fileType == FXFA_SAVEAS_XDP) { |
| 450 if (!m_pContext->GetPDFDoc()) | 451 if (!m_pContext->GetPDFDoc()) |
| 451 return; | 452 return; |
| 452 | 453 |
| 453 CPDF_Dictionary* pRoot = m_pContext->GetPDFDoc()->GetRoot(); | 454 CPDF_Dictionary* pRoot = m_pContext->GetPDFDoc()->GetRoot(); |
| 454 if (!pRoot) | 455 if (!pRoot) |
| 455 return; | 456 return; |
| 456 | 457 |
| 457 CPDF_Dictionary* pAcroForm = pRoot->GetDictFor("AcroForm"); | 458 CPDF_Dictionary* pAcroForm = pRoot->GetDictFor("AcroForm"); |
| 458 if (!pAcroForm) | 459 if (!pAcroForm) |
| 459 return; | 460 return; |
| 460 | 461 |
| 461 CPDF_Array* pArray = ToArray(pAcroForm->GetObjectFor("XFA")); | 462 CPDF_Array* pArray = ToArray(pAcroForm->GetObjectFor("XFA")); |
| 462 if (!pArray) | 463 if (!pArray) |
| 463 return; | 464 return; |
| 464 | 465 |
| 465 int size = pArray->GetCount(); | 466 int size = pArray->GetCount(); |
| 466 for (int i = 1; i < size; i += 2) { | 467 for (int i = 1; i < size; i += 2) { |
| 467 CPDF_Object* pPDFObj = pArray->GetObjectAt(i); | 468 CPDF_Object* pPDFObj = pArray->GetObjectAt(i); |
| 468 CPDF_Object* pPrePDFObj = pArray->GetObjectAt(i - 1); | 469 CPDF_Object* pPrePDFObj = pArray->GetObjectAt(i - 1); |
| 469 if (!pPrePDFObj->IsString()) | 470 if (!pPrePDFObj->IsString()) |
| 470 continue; | 471 continue; |
| 471 if (!pPDFObj->IsReference()) | 472 if (!pPDFObj->IsReference()) |
| 472 continue; | 473 continue; |
| 473 | 474 |
| 474 CPDF_Stream* pStream = ToStream(pPDFObj->GetDirect()); | 475 CPDF_Stream* pStream = ToStream(pPDFObj->GetDirect()); |
| 475 if (!pStream) | 476 if (!pStream) |
| 476 continue; | 477 continue; |
| 477 if (pPrePDFObj->GetString() == "form") { | 478 if (pPrePDFObj->GetString() == "form") { |
| 478 m_pContext->GetXFADocView()->GetDoc()->SavePackage( | 479 m_pContext->GetXFADocView()->GetDoc()->SavePackage(XFA_HASHCODE_Form, |
| 479 XFA_HASHCODE_Form, fileWrite.get(), nullptr); | 480 fileWrite, nullptr); |
| 480 continue; | 481 continue; |
| 481 } | 482 } |
| 482 if (pPrePDFObj->GetString() == "datasets") { | 483 if (pPrePDFObj->GetString() == "datasets") { |
| 483 m_pContext->GetXFADocView()->GetDoc()->SavePackage( | 484 m_pContext->GetXFADocView()->GetDoc()->SavePackage( |
| 484 XFA_HASHCODE_Datasets, fileWrite.get(), nullptr); | 485 XFA_HASHCODE_Datasets, fileWrite, nullptr); |
| 485 continue; | 486 continue; |
| 486 } | 487 } |
| 487 if (i == size - 1) { | 488 if (i == size - 1) { |
| 488 CFX_WideString wPath = CFX_WideString::FromUTF16LE( | 489 CFX_WideString wPath = CFX_WideString::FromUTF16LE( |
| 489 reinterpret_cast<const unsigned short*>(bs.c_str()), | 490 reinterpret_cast<const unsigned short*>(bs.c_str()), |
| 490 bs.GetLength() / sizeof(unsigned short)); | 491 bs.GetLength() / sizeof(unsigned short)); |
| 491 CFX_ByteString bPath = wPath.UTF8Encode(); | 492 CFX_ByteString bPath = wPath.UTF8Encode(); |
| 492 const char* szFormat = | 493 const char* szFormat = |
| 493 "\n<pdf href=\"%s\" xmlns=\"http://ns.adobe.com/xdp/pdf/\"/>"; | 494 "\n<pdf href=\"%s\" xmlns=\"http://ns.adobe.com/xdp/pdf/\"/>"; |
| 494 content.Format(szFormat, bPath.c_str()); | 495 content.Format(szFormat, bPath.c_str()); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 bool CPDFXFA_DocEnvironment::SubmitData(CXFA_FFDoc* hDoc, CXFA_Submit submit) { | 693 bool CPDFXFA_DocEnvironment::SubmitData(CXFA_FFDoc* hDoc, CXFA_Submit submit) { |
| 693 if (!NotifySubmit(true) || !m_pContext->GetXFADocView()) | 694 if (!NotifySubmit(true) || !m_pContext->GetXFADocView()) |
| 694 return false; | 695 return false; |
| 695 | 696 |
| 696 m_pContext->GetXFADocView()->UpdateDocView(); | 697 m_pContext->GetXFADocView()->UpdateDocView(); |
| 697 bool ret = SubmitDataInternal(hDoc, submit); | 698 bool ret = SubmitDataInternal(hDoc, submit); |
| 698 NotifySubmit(false); | 699 NotifySubmit(false); |
| 699 return ret; | 700 return ret; |
| 700 } | 701 } |
| 701 | 702 |
| 702 IFX_SeekableReadStream* CPDFXFA_DocEnvironment::OpenLinkedFile( | 703 CFX_RetainPtr<IFX_SeekableReadStream> CPDFXFA_DocEnvironment::OpenLinkedFile( |
| 703 CXFA_FFDoc* hDoc, | 704 CXFA_FFDoc* hDoc, |
| 704 const CFX_WideString& wsLink) { | 705 const CFX_WideString& wsLink) { |
| 705 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); | 706 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); |
| 706 if (!pFormFillEnv) | 707 if (!pFormFillEnv) |
| 707 return nullptr; | 708 return nullptr; |
| 708 | 709 |
| 709 CFX_ByteString bs = wsLink.UTF16LE_Encode(); | 710 CFX_ByteString bs = wsLink.UTF16LE_Encode(); |
| 710 int len = bs.GetLength(); | 711 int len = bs.GetLength(); |
| 711 FPDF_FILEHANDLER* pFileHandler = | 712 FPDF_FILEHANDLER* pFileHandler = |
| 712 pFormFillEnv->OpenFile(0, (FPDF_WIDESTRING)bs.GetBuffer(len), "rb"); | 713 pFormFillEnv->OpenFile(0, (FPDF_WIDESTRING)bs.GetBuffer(len), "rb"); |
| 713 bs.ReleaseBuffer(len); | 714 bs.ReleaseBuffer(len); |
| 714 if (!pFileHandler) | 715 if (!pFileHandler) |
| 715 return nullptr; | 716 return nullptr; |
| 716 | 717 |
| 717 return MakeSeekableStream(pFileHandler); | 718 return MakeSeekableStream(pFileHandler); |
| 718 } | 719 } |
| 719 | 720 |
| 720 bool CPDFXFA_DocEnvironment::ExportSubmitFile(FPDF_FILEHANDLER* pFileHandler, | 721 bool CPDFXFA_DocEnvironment::ExportSubmitFile(FPDF_FILEHANDLER* pFileHandler, |
| 721 int fileType, | 722 int fileType, |
| 722 FPDF_DWORD encodeType, | 723 FPDF_DWORD encodeType, |
| 723 FPDF_DWORD flag) { | 724 FPDF_DWORD flag) { |
| 724 if (!m_pContext->GetXFADocView()) | 725 if (!m_pContext->GetXFADocView()) |
| 725 return false; | 726 return false; |
| 726 | 727 |
| 727 CFX_ByteString content; | 728 CFX_ByteString content; |
| 728 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); | 729 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); |
| 729 if (!pFormFillEnv) | 730 if (!pFormFillEnv) |
| 730 return false; | 731 return false; |
| 731 | 732 |
| 732 std::unique_ptr<IFX_SeekableStream, ReleaseDeleter<IFX_SeekableStream>> | 733 CFX_RetainPtr<IFX_SeekableStream> fileStream = |
| 733 fileStream(MakeSeekableStream(pFileHandler)); | 734 MakeSeekableStream(pFileHandler); |
| 734 | 735 |
| 735 if (fileType == FXFA_SAVEAS_XML) { | 736 if (fileType == FXFA_SAVEAS_XML) { |
| 736 const char kContent[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"; | 737 const char kContent[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"; |
| 737 fileStream->WriteBlock(kContent, 0, strlen(kContent)); | 738 fileStream->WriteBlock(kContent, 0, strlen(kContent)); |
| 738 m_pContext->GetXFADoc()->SavePackage(XFA_HASHCODE_Data, fileStream.get(), | 739 m_pContext->GetXFADoc()->SavePackage(XFA_HASHCODE_Data, fileStream, |
| 739 nullptr); | 740 nullptr); |
| 740 return true; | 741 return true; |
| 741 } | 742 } |
| 742 | 743 |
| 743 if (fileType != FXFA_SAVEAS_XDP) | 744 if (fileType != FXFA_SAVEAS_XDP) |
| 744 return true; | 745 return true; |
| 745 | 746 |
| 746 if (!flag) { | 747 if (!flag) { |
| 747 flag = FXFA_CONFIG | FXFA_TEMPLATE | FXFA_LOCALESET | FXFA_DATASETS | | 748 flag = FXFA_CONFIG | FXFA_TEMPLATE | FXFA_LOCALESET | FXFA_DATASETS | |
| 748 FXFA_XMPMETA | FXFA_XFDF | FXFA_FORM; | 749 FXFA_XMPMETA | FXFA_XFDF | FXFA_FORM; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 continue; | 791 continue; |
| 791 if (pPrePDFObj->GetString() == "datasets" && !(flag & FXFA_DATASETS)) | 792 if (pPrePDFObj->GetString() == "datasets" && !(flag & FXFA_DATASETS)) |
| 792 continue; | 793 continue; |
| 793 if (pPrePDFObj->GetString() == "xmpmeta" && !(flag & FXFA_XMPMETA)) | 794 if (pPrePDFObj->GetString() == "xmpmeta" && !(flag & FXFA_XMPMETA)) |
| 794 continue; | 795 continue; |
| 795 if (pPrePDFObj->GetString() == "xfdf" && !(flag & FXFA_XFDF)) | 796 if (pPrePDFObj->GetString() == "xfdf" && !(flag & FXFA_XFDF)) |
| 796 continue; | 797 continue; |
| 797 if (pPrePDFObj->GetString() == "form" && !(flag & FXFA_FORM)) | 798 if (pPrePDFObj->GetString() == "form" && !(flag & FXFA_FORM)) |
| 798 continue; | 799 continue; |
| 799 if (pPrePDFObj->GetString() == "form") { | 800 if (pPrePDFObj->GetString() == "form") { |
| 800 m_pContext->GetXFADoc()->SavePackage(XFA_HASHCODE_Form, fileStream.get(), | 801 m_pContext->GetXFADoc()->SavePackage(XFA_HASHCODE_Form, fileStream, |
| 801 nullptr); | 802 nullptr); |
| 802 } else if (pPrePDFObj->GetString() == "datasets") { | 803 } else if (pPrePDFObj->GetString() == "datasets") { |
| 803 m_pContext->GetXFADoc()->SavePackage(XFA_HASHCODE_Datasets, | 804 m_pContext->GetXFADoc()->SavePackage(XFA_HASHCODE_Datasets, fileStream, |
| 804 fileStream.get(), nullptr); | 805 nullptr); |
| 805 } else { | 806 } else { |
| 806 // PDF,creator. | 807 // PDF,creator. |
| 807 } | 808 } |
| 808 } | 809 } |
| 809 return true; | 810 return true; |
| 810 } | 811 } |
| 811 | 812 |
| 812 void CPDFXFA_DocEnvironment::ToXFAContentFlags(CFX_WideString csSrcContent, | 813 void CPDFXFA_DocEnvironment::ToXFAContentFlags(CFX_WideString csSrcContent, |
| 813 FPDF_DWORD& flag) { | 814 FPDF_DWORD& flag) { |
| 814 if (csSrcContent.Find(L" config ", 0) != -1) | 815 if (csSrcContent.Find(L" config ", 0) != -1) |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 !m_pContext->GetFormFillEnv()->GetJSRuntime()) { | 1021 !m_pContext->GetFormFillEnv()->GetJSRuntime()) { |
| 1021 return false; | 1022 return false; |
| 1022 } | 1023 } |
| 1023 | 1024 |
| 1024 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); | 1025 CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); |
| 1025 if (!m_pJSContext) | 1026 if (!m_pJSContext) |
| 1026 m_pJSContext = pFormFillEnv->GetJSRuntime()->NewContext(); | 1027 m_pJSContext = pFormFillEnv->GetJSRuntime()->NewContext(); |
| 1027 | 1028 |
| 1028 return pFormFillEnv->GetJSRuntime()->GetValueByName(szPropName, pValue); | 1029 return pFormFillEnv->GetJSRuntime()->GetValueByName(szPropName, pValue); |
| 1029 } | 1030 } |
| OLD | NEW |