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_ext.h" |
| 8 | |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 9 | #include <memory> |
| 10 | |
dsinclair | 39c62fd | 2016-09-29 12:49:17 -0700 | [diff] [blame] | 11 | #include "core/fpdfapi/cpdf_modulemgr.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 12 | #include "core/fpdfapi/parser/cpdf_array.h" |
| 13 | #include "core/fpdfapi/parser/cpdf_document.h" |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 14 | #include "core/fpdfdoc/cpdf_annot.h" |
| 15 | #include "core/fpdfdoc/cpdf_interform.h" |
| 16 | #include "core/fpdfdoc/cpdf_metadata.h" |
dsinclair | a52ab74 | 2016-09-29 13:59:29 -0700 | [diff] [blame] | 17 | #include "core/fxcrt/fx_basic.h" |
| 18 | #include "core/fxcrt/fx_memory.h" |
Tom Sepez | 8a6fdad | 2017-05-09 15:03:33 -0700 | [diff] [blame] | 19 | #include "core/fxcrt/xml/cxml_content.h" |
Dan Sinclair | 908c848 | 2017-03-30 14:33:28 -0400 | [diff] [blame] | 20 | #include "core/fxcrt/xml/cxml_element.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 21 | #include "fpdfsdk/fsdk_define.h" |
tsepez | 36eb4bd | 2016-10-03 15:24:27 -0700 | [diff] [blame] | 22 | #include "third_party/base/ptr_util.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 23 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 24 | #ifdef PDF_ENABLE_XFA |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 25 | #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 26 | #endif // PDF_ENABLE_XFA |
| 27 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 28 | bool FPDF_UnSupportError(int nError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 29 | CFSDK_UnsupportInfo_Adapter* pAdapter = |
weili | 9f515bc | 2016-07-24 08:08:24 -0700 | [diff] [blame] | 30 | CPDF_ModuleMgr::Get()->GetUnsupportInfoAdapter(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 31 | if (!pAdapter) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 32 | return false; |
tsepez | ddffb57 | 2016-05-24 16:20:29 -0700 | [diff] [blame] | 33 | |
weili | 9f515bc | 2016-07-24 08:08:24 -0700 | [diff] [blame] | 34 | UNSUPPORT_INFO* info = static_cast<UNSUPPORT_INFO*>(pAdapter->GetUnspInfo()); |
| 35 | if (info && info->FSDK_UnSupport_Handler) |
| 36 | info->FSDK_UnSupport_Handler(info, nError); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 37 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 40 | DLLEXPORT FPDF_BOOL STDCALL |
| 41 | FSDK_SetUnSpObjProcessHandler(UNSUPPORT_INFO* unsp_info) { |
| 42 | if (!unsp_info || unsp_info->version != 1) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 43 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 44 | |
weili | 9f515bc | 2016-07-24 08:08:24 -0700 | [diff] [blame] | 45 | CPDF_ModuleMgr::Get()->SetUnsupportInfoAdapter( |
tsepez | 36eb4bd | 2016-10-03 15:24:27 -0700 | [diff] [blame] | 46 | pdfium::MakeUnique<CFSDK_UnsupportInfo_Adapter>(unsp_info)); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 47 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 50 | void CheckUnSupportAnnot(CPDF_Document* pDoc, const CPDF_Annot* pPDFAnnot) { |
jaepark | 956553e | 2016-08-31 06:49:27 -0700 | [diff] [blame] | 51 | CPDF_Annot::Subtype nAnnotSubtype = pPDFAnnot->GetSubtype(); |
| 52 | if (nAnnotSubtype == CPDF_Annot::Subtype::THREED) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 53 | FPDF_UnSupportError(FPDF_UNSP_ANNOT_3DANNOT); |
jaepark | 956553e | 2016-08-31 06:49:27 -0700 | [diff] [blame] | 54 | } else if (nAnnotSubtype == CPDF_Annot::Subtype::SCREEN) { |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 55 | const CPDF_Dictionary* pAnnotDict = pPDFAnnot->GetAnnotDict(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 56 | CFX_ByteString cbString; |
| 57 | if (pAnnotDict->KeyExist("IT")) |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 58 | cbString = pAnnotDict->GetStringFor("IT"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 59 | if (cbString.Compare("Img") != 0) |
| 60 | FPDF_UnSupportError(FPDF_UNSP_ANNOT_SCREEN_MEDIA); |
jaepark | 956553e | 2016-08-31 06:49:27 -0700 | [diff] [blame] | 61 | } else if (nAnnotSubtype == CPDF_Annot::Subtype::MOVIE) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 62 | FPDF_UnSupportError(FPDF_UNSP_ANNOT_MOVIE); |
jaepark | 956553e | 2016-08-31 06:49:27 -0700 | [diff] [blame] | 63 | } else if (nAnnotSubtype == CPDF_Annot::Subtype::SOUND) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 64 | FPDF_UnSupportError(FPDF_UNSP_ANNOT_SOUND); |
jaepark | 956553e | 2016-08-31 06:49:27 -0700 | [diff] [blame] | 65 | } else if (nAnnotSubtype == CPDF_Annot::Subtype::RICHMEDIA) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 66 | FPDF_UnSupportError(FPDF_UNSP_ANNOT_SCREEN_RICHMEDIA); |
jaepark | 956553e | 2016-08-31 06:49:27 -0700 | [diff] [blame] | 67 | } else if (nAnnotSubtype == CPDF_Annot::Subtype::FILEATTACHMENT) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 68 | FPDF_UnSupportError(FPDF_UNSP_ANNOT_ATTACHMENT); |
jaepark | 956553e | 2016-08-31 06:49:27 -0700 | [diff] [blame] | 69 | } else if (nAnnotSubtype == CPDF_Annot::Subtype::WIDGET) { |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 70 | const CPDF_Dictionary* pAnnotDict = pPDFAnnot->GetAnnotDict(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 71 | CFX_ByteString cbString; |
jaepark | 956553e | 2016-08-31 06:49:27 -0700 | [diff] [blame] | 72 | if (pAnnotDict->KeyExist("FT")) |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 73 | cbString = pAnnotDict->GetStringFor("FT"); |
jaepark | 956553e | 2016-08-31 06:49:27 -0700 | [diff] [blame] | 74 | if (cbString.Compare("Sig") == 0) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 75 | FPDF_UnSupportError(FPDF_UNSP_ANNOT_SIG); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 76 | } |
| 77 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 78 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 79 | bool CheckSharedForm(const CXML_Element* pElement, CFX_ByteString cbName) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 80 | int count = pElement->CountAttrs(); |
| 81 | int i = 0; |
| 82 | for (i = 0; i < count; i++) { |
Tom Sepez | ec8ff7d | 2017-04-07 16:58:00 -0700 | [diff] [blame] | 83 | CFX_ByteString space; |
| 84 | CFX_ByteString name; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 85 | CFX_WideString value; |
Tom Sepez | ec8ff7d | 2017-04-07 16:58:00 -0700 | [diff] [blame] | 86 | pElement->GetAttrByIndex(i, &space, &name, &value); |
Lei Zhang | d983b09 | 2015-12-14 16:58:33 -0800 | [diff] [blame] | 87 | if (space == "xmlns" && name == "adhocwf" && |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 88 | value == L"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/") { |
tsepez | 28f97ff | 2016-04-04 16:41:35 -0700 | [diff] [blame] | 89 | CXML_Element* pVersion = |
Tom Sepez | 8a6fdad | 2017-05-09 15:03:33 -0700 | [diff] [blame] | 90 | pElement->GetElement("adhocwf", cbName.AsStringC(), 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 91 | if (!pVersion) |
| 92 | continue; |
Tom Sepez | 8a6fdad | 2017-05-09 15:03:33 -0700 | [diff] [blame] | 93 | CXML_Content* pContent = ToContent(pVersion->GetChild(0)); |
| 94 | if (!pContent) |
| 95 | continue; |
| 96 | switch (pContent->m_Content.GetInteger()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 97 | case 1: |
| 98 | FPDF_UnSupportError(FPDF_UNSP_DOC_SHAREDFORM_ACROBAT); |
| 99 | break; |
| 100 | case 2: |
| 101 | FPDF_UnSupportError(FPDF_UNSP_DOC_SHAREDFORM_FILESYSTEM); |
| 102 | break; |
| 103 | case 0: |
| 104 | FPDF_UnSupportError(FPDF_UNSP_DOC_SHAREDFORM_EMAIL); |
| 105 | break; |
| 106 | } |
| 107 | } |
| 108 | } |
Tom Sepez | ca3ac5e | 2015-06-10 17:38:11 -0700 | [diff] [blame] | 109 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 110 | uint32_t nCount = pElement->CountChildren(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 111 | for (i = 0; i < (int)nCount; i++) { |
Tom Sepez | 8a6fdad | 2017-05-09 15:03:33 -0700 | [diff] [blame] | 112 | CXML_Element* pChild = ToElement(pElement->GetChild(i)); |
| 113 | if (pChild && CheckSharedForm(pChild, cbName)) |
| 114 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 115 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 116 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 117 | } |
Tom Sepez | ca3ac5e | 2015-06-10 17:38:11 -0700 | [diff] [blame] | 118 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 119 | void CheckUnSupportError(CPDF_Document* pDoc, uint32_t err_code) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 120 | // Security |
| 121 | if (err_code == FPDF_ERR_SECURITY) { |
| 122 | FPDF_UnSupportError(FPDF_UNSP_DOC_SECURITY); |
| 123 | return; |
| 124 | } |
| 125 | if (!pDoc) |
| 126 | return; |
Tom Sepez | ca3ac5e | 2015-06-10 17:38:11 -0700 | [diff] [blame] | 127 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 128 | // Portfolios and Packages |
| 129 | CPDF_Dictionary* pRootDict = pDoc->GetRoot(); |
| 130 | if (pRootDict) { |
| 131 | CFX_ByteString cbString; |
| 132 | if (pRootDict->KeyExist("Collection")) { |
| 133 | FPDF_UnSupportError(FPDF_UNSP_DOC_PORTABLECOLLECTION); |
| 134 | return; |
| 135 | } |
| 136 | if (pRootDict->KeyExist("Names")) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 137 | CPDF_Dictionary* pNameDict = pRootDict->GetDictFor("Names"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 138 | if (pNameDict && pNameDict->KeyExist("EmbeddedFiles")) { |
| 139 | FPDF_UnSupportError(FPDF_UNSP_DOC_ATTACHMENT); |
| 140 | return; |
Tom Sepez | 468e589 | 2015-10-13 15:49:36 -0700 | [diff] [blame] | 141 | } |
| 142 | if (pNameDict && pNameDict->KeyExist("JavaScript")) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 143 | CPDF_Dictionary* pJSDict = pNameDict->GetDictFor("JavaScript"); |
| 144 | CPDF_Array* pArray = pJSDict ? pJSDict->GetArrayFor("Names") : nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 145 | if (pArray) { |
Wei Li | e1aebd4 | 2016-04-11 10:02:09 -0700 | [diff] [blame] | 146 | for (size_t i = 0; i < pArray->GetCount(); i++) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 147 | CFX_ByteString cbStr = pArray->GetStringAt(i); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 148 | if (cbStr.Compare("com.adobe.acrobat.SharedReview.Register") == 0) { |
| 149 | FPDF_UnSupportError(FPDF_UNSP_DOC_SHAREDREVIEW); |
| 150 | return; |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | // SharedForm |
Lei Zhang | 119dc64 | 2015-08-11 14:08:47 -0700 | [diff] [blame] | 159 | CPDF_Metadata metaData(pDoc); |
| 160 | const CXML_Element* pElement = metaData.GetRoot(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 161 | if (pElement) |
| 162 | CheckSharedForm(pElement, "workflowType"); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 163 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 164 | #ifndef PDF_ENABLE_XFA |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 165 | // XFA Forms |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 166 | CPDF_InterForm interform(pDoc); |
| 167 | if (interform.HasXFAForm()) |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 168 | FPDF_UnSupportError(FPDF_UNSP_DOC_XFAFORM); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 169 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 170 | } |
| 171 | |
thestig | a55880d | 2016-05-23 09:11:54 -0700 | [diff] [blame] | 172 | DLLEXPORT int STDCALL FPDFDoc_GetPageMode(FPDF_DOCUMENT document) { |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 173 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 174 | if (!pDoc) |
Tom Sepez | ca3ac5e | 2015-06-10 17:38:11 -0700 | [diff] [blame] | 175 | return PAGEMODE_UNKNOWN; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 176 | |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 177 | CPDF_Dictionary* pRoot = pDoc->GetRoot(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 178 | if (!pRoot) |
| 179 | return PAGEMODE_UNKNOWN; |
| 180 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 181 | CPDF_Object* pName = pRoot->GetObjectFor("PageMode"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 182 | if (!pName) |
| 183 | return PAGEMODE_USENONE; |
| 184 | |
| 185 | CFX_ByteString strPageMode = pName->GetString(); |
| 186 | if (strPageMode.IsEmpty() || strPageMode.EqualNoCase("UseNone")) |
| 187 | return PAGEMODE_USENONE; |
| 188 | if (strPageMode.EqualNoCase("UseOutlines")) |
| 189 | return PAGEMODE_USEOUTLINES; |
| 190 | if (strPageMode.EqualNoCase("UseThumbs")) |
| 191 | return PAGEMODE_USETHUMBS; |
| 192 | if (strPageMode.EqualNoCase("FullScreen")) |
| 193 | return PAGEMODE_FULLSCREEN; |
| 194 | if (strPageMode.EqualNoCase("UseOC")) |
| 195 | return PAGEMODE_USEOC; |
| 196 | if (strPageMode.EqualNoCase("UseAttachments")) |
| 197 | return PAGEMODE_USEATTACHMENTS; |
| 198 | |
| 199 | return PAGEMODE_UNKNOWN; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 200 | } |