John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 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. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Lei Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 7 | #include "public/fpdf_save.h" |
| 8 | |
Dan Sinclair | 85c8e7f | 2016-11-21 13:50:32 -0500 | [diff] [blame] | 9 | #include <memory> |
| 10 | #include <utility> |
Dan Sinclair | 3ebd121 | 2016-03-09 09:59:23 -0500 | [diff] [blame] | 11 | #include <vector> |
| 12 | |
dsinclair | 2415435 | 2016-10-04 11:01:48 -0700 | [diff] [blame] | 13 | #include "core/fpdfapi/edit/cpdf_creator.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 14 | #include "core/fpdfapi/parser/cpdf_array.h" |
| 15 | #include "core/fpdfapi/parser/cpdf_document.h" |
| 16 | #include "core/fpdfapi/parser/cpdf_reference.h" |
| 17 | #include "core/fpdfapi/parser/cpdf_stream_acc.h" |
| 18 | #include "core/fpdfapi/parser/cpdf_string.h" |
Dan Sinclair | 283a043 | 2017-04-20 14:11:21 -0400 | [diff] [blame] | 19 | #include "core/fxcrt/cfx_memorystream.h" |
Dan Sinclair | cfb1944 | 2017-04-20 13:13:04 -0400 | [diff] [blame] | 20 | #include "core/fxcrt/fx_extension.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 21 | #include "fpdfsdk/fsdk_define.h" |
Dan Sinclair | ae4656e | 2017-05-09 12:36:41 -0400 | [diff] [blame] | 22 | #include "fpdfsdk/fsdk_filewriteadapter.h" |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 23 | #include "public/fpdf_edit.h" |
| 24 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 25 | #ifdef PDF_ENABLE_XFA |
Dan Sinclair | ddb7016 | 2017-03-30 14:01:31 -0400 | [diff] [blame] | 26 | #include "core/fxcrt/cfx_checksumcontext.h" |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 27 | #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" |
dsinclair | 4d29e78 | 2016-10-04 14:02:47 -0700 | [diff] [blame] | 28 | #include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h" |
Lei Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 29 | #include "public/fpdf_formfill.h" |
dsinclair | 5b49309 | 2016-09-29 20:20:24 -0700 | [diff] [blame] | 30 | #include "xfa/fxfa/cxfa_eventparam.h" |
Dan Sinclair | 80c4878 | 2017-03-23 12:11:20 -0400 | [diff] [blame] | 31 | #include "xfa/fxfa/cxfa_ffapp.h" |
| 32 | #include "xfa/fxfa/cxfa_ffdocview.h" |
| 33 | #include "xfa/fxfa/cxfa_ffwidgethandler.h" |
| 34 | #include "xfa/fxfa/cxfa_widgetacciterator.h" |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 35 | #endif |
Tom Sepez | 1ed8a21 | 2015-05-11 15:25:39 -0700 | [diff] [blame] | 36 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 37 | #if _FX_OS_ == _FX_ANDROID_ |
Dan Sinclair | 85c8e7f | 2016-11-21 13:50:32 -0500 | [diff] [blame] | 38 | #include <time.h> |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 39 | #else |
| 40 | #include <ctime> |
| 41 | #endif |
| 42 | |
Tom Sepez | 7a73eff | 2016-02-08 13:39:53 -0800 | [diff] [blame] | 43 | namespace { |
| 44 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 45 | #ifdef PDF_ENABLE_XFA |
tsepez | 833619b | 2016-12-07 09:21:17 -0800 | [diff] [blame] | 46 | bool SaveXFADocumentData( |
| 47 | CPDFXFA_Context* pContext, |
| 48 | std::vector<CFX_RetainPtr<IFX_SeekableStream>>* fileList) { |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 49 | if (!pContext) |
Tom Sepez | 7a73eff | 2016-02-08 13:39:53 -0800 | [diff] [blame] | 50 | return false; |
| 51 | |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 52 | if (pContext->GetDocType() != XFA_DocType::Dynamic && |
| 53 | pContext->GetDocType() != XFA_DocType::Static) { |
Tom Sepez | 7a73eff | 2016-02-08 13:39:53 -0800 | [diff] [blame] | 54 | return true; |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 55 | } |
Tom Sepez | 7a73eff | 2016-02-08 13:39:53 -0800 | [diff] [blame] | 56 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 57 | CXFA_FFDocView* pXFADocView = pContext->GetXFADocView(); |
Tom Sepez | 7a73eff | 2016-02-08 13:39:53 -0800 | [diff] [blame] | 58 | if (!pXFADocView) |
| 59 | return true; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 60 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 61 | CPDF_Document* pPDFDocument = pContext->GetPDFDoc(); |
| 62 | if (!pPDFDocument) |
Tom Sepez | 7a73eff | 2016-02-08 13:39:53 -0800 | [diff] [blame] | 63 | return false; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 64 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 65 | CPDF_Dictionary* pRoot = pPDFDocument->GetRoot(); |
Tom Sepez | 7a73eff | 2016-02-08 13:39:53 -0800 | [diff] [blame] | 66 | if (!pRoot) |
| 67 | return false; |
| 68 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 69 | CPDF_Dictionary* pAcroForm = pRoot->GetDictFor("AcroForm"); |
Tom Sepez | 7a73eff | 2016-02-08 13:39:53 -0800 | [diff] [blame] | 70 | if (!pAcroForm) |
| 71 | return false; |
| 72 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 73 | CPDF_Object* pXFA = pAcroForm->GetObjectFor("XFA"); |
Tom Sepez | 7a73eff | 2016-02-08 13:39:53 -0800 | [diff] [blame] | 74 | if (!pXFA) |
| 75 | return true; |
| 76 | |
thestig | b8bf55f | 2016-05-21 21:08:05 -0700 | [diff] [blame] | 77 | CPDF_Array* pArray = pXFA->AsArray(); |
Tom Sepez | 7a73eff | 2016-02-08 13:39:53 -0800 | [diff] [blame] | 78 | if (!pArray) |
| 79 | return false; |
| 80 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 81 | int size = pArray->GetCount(); |
| 82 | int iFormIndex = -1; |
| 83 | int iDataSetsIndex = -1; |
| 84 | int iTemplate = -1; |
| 85 | int iLast = size - 2; |
| 86 | for (int i = 0; i < size - 1; i++) { |
tsepez | bd56755 | 2016-03-29 14:51:50 -0700 | [diff] [blame] | 87 | CPDF_Object* pPDFObj = pArray->GetObjectAt(i); |
Tom Sepez | 8e5cd19 | 2016-01-26 13:20:26 -0800 | [diff] [blame] | 88 | if (!pPDFObj->IsString()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 89 | continue; |
| 90 | if (pPDFObj->GetString() == "form") |
| 91 | iFormIndex = i + 1; |
| 92 | else if (pPDFObj->GetString() == "datasets") |
| 93 | iDataSetsIndex = i + 1; |
Lei Zhang | d983b09 | 2015-12-14 16:58:33 -0800 | [diff] [blame] | 94 | else if (pPDFObj->GetString() == "template") |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 95 | iTemplate = i + 1; |
| 96 | } |
Dan Sinclair | 0bb1333 | 2017-03-30 16:12:02 -0400 | [diff] [blame] | 97 | auto pChecksum = pdfium::MakeUnique<CFX_ChecksumContext>(); |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 98 | pChecksum->StartChecksum(); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 99 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 100 | // template |
| 101 | if (iTemplate > -1) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 102 | CPDF_Stream* pTemplateStream = pArray->GetStreamAt(iTemplate); |
Tom Sepez | afd0d1f | 2017-04-04 14:37:18 -0700 | [diff] [blame] | 103 | auto pAcc = pdfium::MakeRetain<CPDF_StreamAcc>(pTemplateStream); |
| 104 | pAcc->LoadAllData(); |
Dan Sinclair | 283a043 | 2017-04-20 14:11:21 -0400 | [diff] [blame] | 105 | CFX_RetainPtr<IFX_SeekableStream> pTemplate = |
| 106 | pdfium::MakeRetain<CFX_MemoryStream>( |
| 107 | const_cast<uint8_t*>(pAcc->GetData()), pAcc->GetSize(), false); |
tsepez | 833619b | 2016-12-07 09:21:17 -0800 | [diff] [blame] | 108 | pChecksum->UpdateChecksum(pTemplate); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 109 | } |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 110 | CPDF_Stream* pFormStream = nullptr; |
| 111 | CPDF_Stream* pDataSetsStream = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 112 | if (iFormIndex != -1) { |
| 113 | // Get form CPDF_Stream |
tsepez | bd56755 | 2016-03-29 14:51:50 -0700 | [diff] [blame] | 114 | CPDF_Object* pFormPDFObj = pArray->GetObjectAt(iFormIndex); |
Tom Sepez | 8e5cd19 | 2016-01-26 13:20:26 -0800 | [diff] [blame] | 115 | if (pFormPDFObj->IsReference()) { |
| 116 | CPDF_Object* pFormDirectObj = pFormPDFObj->GetDirect(); |
| 117 | if (pFormDirectObj && pFormDirectObj->IsStream()) { |
| 118 | pFormStream = (CPDF_Stream*)pFormDirectObj; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 119 | } |
Tom Sepez | 8e5cd19 | 2016-01-26 13:20:26 -0800 | [diff] [blame] | 120 | } else if (pFormPDFObj->IsStream()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 121 | pFormStream = (CPDF_Stream*)pFormPDFObj; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 122 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 123 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 124 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 125 | if (iDataSetsIndex != -1) { |
| 126 | // Get datasets CPDF_Stream |
tsepez | bd56755 | 2016-03-29 14:51:50 -0700 | [diff] [blame] | 127 | CPDF_Object* pDataSetsPDFObj = pArray->GetObjectAt(iDataSetsIndex); |
Tom Sepez | 8e5cd19 | 2016-01-26 13:20:26 -0800 | [diff] [blame] | 128 | if (pDataSetsPDFObj->IsReference()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 129 | CPDF_Reference* pDataSetsRefObj = (CPDF_Reference*)pDataSetsPDFObj; |
Tom Sepez | 8e5cd19 | 2016-01-26 13:20:26 -0800 | [diff] [blame] | 130 | CPDF_Object* pDataSetsDirectObj = pDataSetsRefObj->GetDirect(); |
| 131 | if (pDataSetsDirectObj && pDataSetsDirectObj->IsStream()) { |
| 132 | pDataSetsStream = (CPDF_Stream*)pDataSetsDirectObj; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 133 | } |
Tom Sepez | 8e5cd19 | 2016-01-26 13:20:26 -0800 | [diff] [blame] | 134 | } else if (pDataSetsPDFObj->IsStream()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 135 | pDataSetsStream = (CPDF_Stream*)pDataSetsPDFObj; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 136 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 137 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 138 | // L"datasets" |
| 139 | { |
Dan Sinclair | 283a043 | 2017-04-20 14:11:21 -0400 | [diff] [blame] | 140 | CFX_RetainPtr<IFX_SeekableStream> pDsfileWrite = |
| 141 | pdfium::MakeRetain<CFX_MemoryStream>(false); |
tsepez | 833619b | 2016-12-07 09:21:17 -0800 | [diff] [blame] | 142 | if (pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Datasets, pDsfileWrite, |
| 143 | nullptr) && |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 144 | pDsfileWrite->GetSize() > 0) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 145 | // Datasets |
tsepez | 833619b | 2016-12-07 09:21:17 -0800 | [diff] [blame] | 146 | pChecksum->UpdateChecksum(pDsfileWrite); |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 147 | pChecksum->FinishChecksum(); |
tsepez | 9e05ee1 | 2016-11-21 13:19:10 -0800 | [diff] [blame] | 148 | auto pDataDict = pdfium::MakeUnique<CPDF_Dictionary>( |
| 149 | pPDFDocument->GetByteStringPool()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 150 | if (iDataSetsIndex != -1) { |
tsepez | 9e05ee1 | 2016-11-21 13:19:10 -0800 | [diff] [blame] | 151 | if (pDataSetsStream) { |
tsepez | 833619b | 2016-12-07 09:21:17 -0800 | [diff] [blame] | 152 | pDataSetsStream->InitStreamFromFile(pDsfileWrite, |
tsepez | 9e05ee1 | 2016-11-21 13:19:10 -0800 | [diff] [blame] | 153 | std::move(pDataDict)); |
| 154 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 155 | } else { |
tsepez | 70c4afd | 2016-11-15 11:33:44 -0800 | [diff] [blame] | 156 | CPDF_Stream* pData = pPDFDocument->NewIndirect<CPDF_Stream>(); |
tsepez | 833619b | 2016-12-07 09:21:17 -0800 | [diff] [blame] | 157 | pData->InitStreamFromFile(pDsfileWrite, std::move(pDataDict)); |
Tom Sepez | 3343d14 | 2015-11-02 09:54:54 -0800 | [diff] [blame] | 158 | iLast = pArray->GetCount() - 2; |
tsepez | 8a3aa45 | 2016-11-16 12:26:06 -0800 | [diff] [blame] | 159 | pArray->InsertNewAt<CPDF_String>(iLast, "datasets", false); |
| 160 | pArray->InsertNewAt<CPDF_Reference>(iLast + 1, pPDFDocument, |
| 161 | pData->GetObjNum()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 162 | } |
Tom Sepez | 7a73eff | 2016-02-08 13:39:53 -0800 | [diff] [blame] | 163 | fileList->push_back(std::move(pDsfileWrite)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 164 | } |
| 165 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 166 | // L"form" |
| 167 | { |
Dan Sinclair | 283a043 | 2017-04-20 14:11:21 -0400 | [diff] [blame] | 168 | CFX_RetainPtr<IFX_SeekableStream> pfileWrite = |
| 169 | pdfium::MakeRetain<CFX_MemoryStream>(false); |
tsepez | 833619b | 2016-12-07 09:21:17 -0800 | [diff] [blame] | 170 | if (pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Form, pfileWrite, |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 171 | pChecksum.get()) && |
Tom Sepez | 7a73eff | 2016-02-08 13:39:53 -0800 | [diff] [blame] | 172 | pfileWrite->GetSize() > 0) { |
tsepez | 9e05ee1 | 2016-11-21 13:19:10 -0800 | [diff] [blame] | 173 | auto pDataDict = pdfium::MakeUnique<CPDF_Dictionary>( |
| 174 | pPDFDocument->GetByteStringPool()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 175 | if (iFormIndex != -1) { |
tsepez | 833619b | 2016-12-07 09:21:17 -0800 | [diff] [blame] | 176 | if (pFormStream) |
| 177 | pFormStream->InitStreamFromFile(pfileWrite, std::move(pDataDict)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 178 | } else { |
tsepez | 70c4afd | 2016-11-15 11:33:44 -0800 | [diff] [blame] | 179 | CPDF_Stream* pData = pPDFDocument->NewIndirect<CPDF_Stream>(); |
tsepez | 833619b | 2016-12-07 09:21:17 -0800 | [diff] [blame] | 180 | pData->InitStreamFromFile(pfileWrite, std::move(pDataDict)); |
Tom Sepez | 3343d14 | 2015-11-02 09:54:54 -0800 | [diff] [blame] | 181 | iLast = pArray->GetCount() - 2; |
tsepez | 8a3aa45 | 2016-11-16 12:26:06 -0800 | [diff] [blame] | 182 | pArray->InsertNewAt<CPDF_String>(iLast, "form", false); |
| 183 | pArray->InsertNewAt<CPDF_Reference>(iLast + 1, pPDFDocument, |
| 184 | pData->GetObjNum()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 185 | } |
Tom Sepez | 7a73eff | 2016-02-08 13:39:53 -0800 | [diff] [blame] | 186 | fileList->push_back(std::move(pfileWrite)); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 187 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 188 | } |
Tom Sepez | 7a73eff | 2016-02-08 13:39:53 -0800 | [diff] [blame] | 189 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 190 | } |
| 191 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 192 | bool SendPostSaveToXFADoc(CPDFXFA_Context* pContext) { |
| 193 | if (!pContext) |
Tom Sepez | 7a73eff | 2016-02-08 13:39:53 -0800 | [diff] [blame] | 194 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 195 | |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 196 | if (pContext->GetDocType() != XFA_DocType::Dynamic && |
| 197 | pContext->GetDocType() != XFA_DocType::Static) |
Tom Sepez | 7a73eff | 2016-02-08 13:39:53 -0800 | [diff] [blame] | 198 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 199 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 200 | CXFA_FFDocView* pXFADocView = pContext->GetXFADocView(); |
Tom Sepez | 7a73eff | 2016-02-08 13:39:53 -0800 | [diff] [blame] | 201 | if (!pXFADocView) |
| 202 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 203 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 204 | CXFA_FFWidgetHandler* pWidgetHander = pXFADocView->GetWidgetHandler(); |
Tom Sepez | 40badde | 2017-05-01 13:21:39 -0700 | [diff] [blame] | 205 | std::unique_ptr<CXFA_WidgetAccIterator> pWidgetAccIterator = |
| 206 | pXFADocView->CreateWidgetAccIterator(); |
tsepez | e7b2853 | 2016-05-18 12:10:49 -0700 | [diff] [blame] | 207 | while (CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 208 | CXFA_EventParam preParam; |
| 209 | preParam.m_eType = XFA_EVENT_PostSave; |
| 210 | pWidgetHander->ProcessEvent(pWidgetAcc, &preParam); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 211 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 212 | pXFADocView->UpdateDocView(); |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 213 | pContext->ClearChangeMark(); |
Tom Sepez | 7a73eff | 2016-02-08 13:39:53 -0800 | [diff] [blame] | 214 | return true; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 215 | } |
| 216 | |
tsepez | 833619b | 2016-12-07 09:21:17 -0800 | [diff] [blame] | 217 | bool SendPreSaveToXFADoc( |
| 218 | CPDFXFA_Context* pContext, |
| 219 | std::vector<CFX_RetainPtr<IFX_SeekableStream>>* fileList) { |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 220 | if (pContext->GetDocType() != XFA_DocType::Dynamic && |
| 221 | pContext->GetDocType() != XFA_DocType::Static) |
Tom Sepez | 7a73eff | 2016-02-08 13:39:53 -0800 | [diff] [blame] | 222 | return true; |
| 223 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 224 | CXFA_FFDocView* pXFADocView = pContext->GetXFADocView(); |
Tom Sepez | 7a73eff | 2016-02-08 13:39:53 -0800 | [diff] [blame] | 225 | if (!pXFADocView) |
| 226 | return true; |
| 227 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 228 | CXFA_FFWidgetHandler* pWidgetHander = pXFADocView->GetWidgetHandler(); |
Tom Sepez | 40badde | 2017-05-01 13:21:39 -0700 | [diff] [blame] | 229 | std::unique_ptr<CXFA_WidgetAccIterator> pWidgetAccIterator = |
| 230 | pXFADocView->CreateWidgetAccIterator(); |
tsepez | e7b2853 | 2016-05-18 12:10:49 -0700 | [diff] [blame] | 231 | while (CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 232 | CXFA_EventParam preParam; |
| 233 | preParam.m_eType = XFA_EVENT_PreSave; |
| 234 | pWidgetHander->ProcessEvent(pWidgetAcc, &preParam); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 235 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 236 | pXFADocView->UpdateDocView(); |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 237 | return SaveXFADocumentData(pContext, fileList); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 238 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 239 | #endif // PDF_ENABLE_XFA |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 240 | |
Tom Sepez | 7a73eff | 2016-02-08 13:39:53 -0800 | [diff] [blame] | 241 | bool FPDF_Doc_Save(FPDF_DOCUMENT document, |
| 242 | FPDF_FILEWRITE* pFileWrite, |
| 243 | FPDF_DWORD flags, |
| 244 | FPDF_BOOL bSetVersion, |
| 245 | int fileVerion) { |
Tom Sepez | 1b24628 | 2015-11-25 15:15:31 -0800 | [diff] [blame] | 246 | CPDF_Document* pPDFDoc = CPDFDocumentFromFPDFDocument(document); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 247 | if (!pPDFDoc) |
| 248 | return 0; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 249 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 250 | #ifdef PDF_ENABLE_XFA |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 251 | CPDFXFA_Context* pContext = static_cast<CPDFXFA_Context*>(document); |
tsepez | 833619b | 2016-12-07 09:21:17 -0800 | [diff] [blame] | 252 | std::vector<CFX_RetainPtr<IFX_SeekableStream>> fileList; |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 253 | SendPreSaveToXFADoc(pContext, &fileList); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 254 | #endif // PDF_ENABLE_XFA |
Tom Sepez | 1b24628 | 2015-11-25 15:15:31 -0800 | [diff] [blame] | 255 | |
Tom Sepez | 7a73eff | 2016-02-08 13:39:53 -0800 | [diff] [blame] | 256 | if (flags < FPDF_INCREMENTAL || flags > FPDF_REMOVE_SECURITY) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 257 | flags = 0; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 258 | |
Dan Sinclair | ae4656e | 2017-05-09 12:36:41 -0400 | [diff] [blame] | 259 | CPDF_Creator fileMaker(pPDFDoc, |
| 260 | pdfium::MakeRetain<FSDK_FileWriteAdapter>(pFileWrite)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 261 | if (bSetVersion) |
Dan Sinclair | ae4656e | 2017-05-09 12:36:41 -0400 | [diff] [blame] | 262 | fileMaker.SetFileVersion(fileVerion); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 263 | if (flags == FPDF_REMOVE_SECURITY) { |
| 264 | flags = 0; |
Dan Sinclair | ae4656e | 2017-05-09 12:36:41 -0400 | [diff] [blame] | 265 | fileMaker.RemoveSecurity(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 266 | } |
Tom Sepez | 1b24628 | 2015-11-25 15:15:31 -0800 | [diff] [blame] | 267 | |
Dan Sinclair | ae4656e | 2017-05-09 12:36:41 -0400 | [diff] [blame] | 268 | bool bRet = fileMaker.Create(flags); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 269 | #ifdef PDF_ENABLE_XFA |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 270 | SendPostSaveToXFADoc(pContext); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 271 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 272 | return bRet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 273 | } |
| 274 | |
Tom Sepez | 7a73eff | 2016-02-08 13:39:53 -0800 | [diff] [blame] | 275 | } // namespace |
| 276 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 277 | DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveAsCopy(FPDF_DOCUMENT document, |
| 278 | FPDF_FILEWRITE* pFileWrite, |
| 279 | FPDF_DWORD flags) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 280 | return FPDF_Doc_Save(document, pFileWrite, flags, false, 0); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 283 | DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveWithVersion(FPDF_DOCUMENT document, |
| 284 | FPDF_FILEWRITE* pFileWrite, |
| 285 | FPDF_DWORD flags, |
| 286 | int fileVersion) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 287 | return FPDF_Doc_Save(document, pFileWrite, flags, true, fileVersion); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 288 | } |