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