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 | |
Dan Sinclair | aa403d3 | 2016-03-15 14:57:22 -0400 | [diff] [blame] | 11 | #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
| 12 | #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
| 13 | #include "core/fpdfapi/include/cpdf_modulemgr.h" |
tsepez | ddffb57 | 2016-05-24 16:20:29 -0700 | [diff] [blame] | 14 | #include "core/fxcrt/include/fx_basic.h" |
Dan Sinclair | a8a28e0 | 2016-03-23 15:41:39 -0400 | [diff] [blame] | 15 | #include "core/fxcrt/include/fx_xml.h" |
Lei Zhang | bde53d2 | 2015-11-12 22:21:30 -0800 | [diff] [blame] | 16 | #include "fpdfsdk/include/fsdk_define.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 17 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 18 | #ifdef PDF_ENABLE_XFA |
dsinclair | 89bdd08 | 2016-04-06 10:47:54 -0700 | [diff] [blame] | 19 | #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 20 | #endif // PDF_ENABLE_XFA |
| 21 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 22 | #define FPDFSDK_UNSUPPORT_CALL 100 |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 23 | |
tsepez | ddffb57 | 2016-05-24 16:20:29 -0700 | [diff] [blame] | 24 | class CFSDK_UnsupportInfo_Adapter : public CFX_Deletable { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 25 | public: |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 26 | explicit CFSDK_UnsupportInfo_Adapter(UNSUPPORT_INFO* unsp_info) |
| 27 | : m_unsp_info(unsp_info) {} |
| 28 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 29 | void ReportError(int nErrorType); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 30 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 31 | private: |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 32 | UNSUPPORT_INFO* const m_unsp_info; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 33 | }; |
| 34 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 35 | void CFSDK_UnsupportInfo_Adapter::ReportError(int nErrorType) { |
| 36 | if (m_unsp_info && m_unsp_info->FSDK_UnSupport_Handler) { |
| 37 | m_unsp_info->FSDK_UnSupport_Handler(m_unsp_info, nErrorType); |
| 38 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 39 | } |
| 40 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 41 | FX_BOOL FPDF_UnSupportError(int nError) { |
| 42 | CFSDK_UnsupportInfo_Adapter* pAdapter = |
tsepez | ddffb57 | 2016-05-24 16:20:29 -0700 | [diff] [blame] | 43 | static_cast<CFSDK_UnsupportInfo_Adapter*>( |
| 44 | CPDF_ModuleMgr::Get()->GetUnsupportInfoAdapter()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 45 | if (!pAdapter) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 46 | return FALSE; |
tsepez | ddffb57 | 2016-05-24 16:20:29 -0700 | [diff] [blame] | 47 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 48 | pAdapter->ReportError(nError); |
| 49 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 52 | DLLEXPORT FPDF_BOOL STDCALL |
| 53 | FSDK_SetUnSpObjProcessHandler(UNSUPPORT_INFO* unsp_info) { |
| 54 | if (!unsp_info || unsp_info->version != 1) |
| 55 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 56 | |
tsepez | ddffb57 | 2016-05-24 16:20:29 -0700 | [diff] [blame] | 57 | CPDF_ModuleMgr::Get()->SetUnsupportInfoAdapter(std::unique_ptr<CFX_Deletable>( |
| 58 | new CFSDK_UnsupportInfo_Adapter(unsp_info))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 59 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 62 | void CheckUnSupportAnnot(CPDF_Document* pDoc, const CPDF_Annot* pPDFAnnot) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 63 | CFX_ByteString cbSubType = pPDFAnnot->GetSubType(); |
| 64 | if (cbSubType.Compare("3D") == 0) { |
| 65 | FPDF_UnSupportError(FPDF_UNSP_ANNOT_3DANNOT); |
| 66 | } else if (cbSubType.Compare("Screen") == 0) { |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 67 | const CPDF_Dictionary* pAnnotDict = pPDFAnnot->GetAnnotDict(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 68 | CFX_ByteString cbString; |
| 69 | if (pAnnotDict->KeyExist("IT")) |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 70 | cbString = pAnnotDict->GetStringBy("IT"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 71 | if (cbString.Compare("Img") != 0) |
| 72 | FPDF_UnSupportError(FPDF_UNSP_ANNOT_SCREEN_MEDIA); |
| 73 | } else if (cbSubType.Compare("Movie") == 0) { |
| 74 | FPDF_UnSupportError(FPDF_UNSP_ANNOT_MOVIE); |
| 75 | } else if (cbSubType.Compare("Sound") == 0) { |
| 76 | FPDF_UnSupportError(FPDF_UNSP_ANNOT_SOUND); |
| 77 | } else if (cbSubType.Compare("RichMedia") == 0) { |
| 78 | FPDF_UnSupportError(FPDF_UNSP_ANNOT_SCREEN_RICHMEDIA); |
| 79 | } else if (cbSubType.Compare("FileAttachment") == 0) { |
| 80 | FPDF_UnSupportError(FPDF_UNSP_ANNOT_ATTACHMENT); |
| 81 | } else if (cbSubType.Compare("Widget") == 0) { |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 82 | const CPDF_Dictionary* pAnnotDict = pPDFAnnot->GetAnnotDict(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 83 | CFX_ByteString cbString; |
| 84 | if (pAnnotDict->KeyExist("FT")) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 85 | cbString = pAnnotDict->GetStringBy("FT"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 86 | } |
| 87 | if (cbString.Compare("Sig") == 0) { |
| 88 | FPDF_UnSupportError(FPDF_UNSP_ANNOT_SIG); |
| 89 | } |
| 90 | } |
| 91 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 92 | |
Lei Zhang | 119dc64 | 2015-08-11 14:08:47 -0700 | [diff] [blame] | 93 | FX_BOOL CheckSharedForm(const CXML_Element* pElement, CFX_ByteString cbName) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 94 | int count = pElement->CountAttrs(); |
| 95 | int i = 0; |
| 96 | for (i = 0; i < count; i++) { |
| 97 | CFX_ByteString space, name; |
| 98 | CFX_WideString value; |
| 99 | pElement->GetAttrByIndex(i, space, name, value); |
Lei Zhang | d983b09 | 2015-12-14 16:58:33 -0800 | [diff] [blame] | 100 | if (space == "xmlns" && name == "adhocwf" && |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 101 | value == L"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/") { |
tsepez | 28f97ff | 2016-04-04 16:41:35 -0700 | [diff] [blame] | 102 | CXML_Element* pVersion = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 103 | pElement->GetElement("adhocwf", cbName.AsStringC()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 104 | if (!pVersion) |
| 105 | continue; |
tsepez | 28f97ff | 2016-04-04 16:41:35 -0700 | [diff] [blame] | 106 | CFX_WideString wsContent = pVersion->GetContent(0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 107 | int nType = wsContent.GetInteger(); |
| 108 | switch (nType) { |
| 109 | case 1: |
| 110 | FPDF_UnSupportError(FPDF_UNSP_DOC_SHAREDFORM_ACROBAT); |
| 111 | break; |
| 112 | case 2: |
| 113 | FPDF_UnSupportError(FPDF_UNSP_DOC_SHAREDFORM_FILESYSTEM); |
| 114 | break; |
| 115 | case 0: |
| 116 | FPDF_UnSupportError(FPDF_UNSP_DOC_SHAREDFORM_EMAIL); |
| 117 | break; |
| 118 | } |
| 119 | } |
| 120 | } |
Tom Sepez | ca3ac5e | 2015-06-10 17:38:11 -0700 | [diff] [blame] | 121 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 122 | uint32_t nCount = pElement->CountChildren(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 123 | for (i = 0; i < (int)nCount; i++) { |
| 124 | CXML_Element::ChildType childType = pElement->GetChildType(i); |
| 125 | if (childType == CXML_Element::Element) { |
| 126 | CXML_Element* pChild = pElement->GetElement(i); |
| 127 | if (CheckSharedForm(pChild, cbName)) |
| 128 | return TRUE; |
| 129 | } |
| 130 | } |
| 131 | return FALSE; |
| 132 | } |
Tom Sepez | ca3ac5e | 2015-06-10 17:38:11 -0700 | [diff] [blame] | 133 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 134 | void CheckUnSupportError(CPDF_Document* pDoc, uint32_t err_code) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 135 | // Security |
| 136 | if (err_code == FPDF_ERR_SECURITY) { |
| 137 | FPDF_UnSupportError(FPDF_UNSP_DOC_SECURITY); |
| 138 | return; |
| 139 | } |
| 140 | if (!pDoc) |
| 141 | return; |
Tom Sepez | ca3ac5e | 2015-06-10 17:38:11 -0700 | [diff] [blame] | 142 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 143 | // Portfolios and Packages |
| 144 | CPDF_Dictionary* pRootDict = pDoc->GetRoot(); |
| 145 | if (pRootDict) { |
| 146 | CFX_ByteString cbString; |
| 147 | if (pRootDict->KeyExist("Collection")) { |
| 148 | FPDF_UnSupportError(FPDF_UNSP_DOC_PORTABLECOLLECTION); |
| 149 | return; |
| 150 | } |
| 151 | if (pRootDict->KeyExist("Names")) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 152 | CPDF_Dictionary* pNameDict = pRootDict->GetDictBy("Names"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 153 | if (pNameDict && pNameDict->KeyExist("EmbeddedFiles")) { |
| 154 | FPDF_UnSupportError(FPDF_UNSP_DOC_ATTACHMENT); |
| 155 | return; |
Tom Sepez | 468e589 | 2015-10-13 15:49:36 -0700 | [diff] [blame] | 156 | } |
| 157 | if (pNameDict && pNameDict->KeyExist("JavaScript")) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 158 | CPDF_Dictionary* pJSDict = pNameDict->GetDictBy("JavaScript"); |
| 159 | CPDF_Array* pArray = pJSDict ? pJSDict->GetArrayBy("Names") : NULL; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 160 | if (pArray) { |
Wei Li | e1aebd4 | 2016-04-11 10:02:09 -0700 | [diff] [blame] | 161 | for (size_t i = 0; i < pArray->GetCount(); i++) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 162 | CFX_ByteString cbStr = pArray->GetStringAt(i); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 163 | if (cbStr.Compare("com.adobe.acrobat.SharedReview.Register") == 0) { |
| 164 | FPDF_UnSupportError(FPDF_UNSP_DOC_SHAREDREVIEW); |
| 165 | return; |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | // SharedForm |
Lei Zhang | 119dc64 | 2015-08-11 14:08:47 -0700 | [diff] [blame] | 174 | CPDF_Metadata metaData(pDoc); |
| 175 | const CXML_Element* pElement = metaData.GetRoot(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 176 | if (pElement) |
| 177 | CheckSharedForm(pElement, "workflowType"); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 178 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 179 | #ifndef PDF_ENABLE_XFA |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 180 | // XFA Forms |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 181 | CPDF_InterForm interform(pDoc); |
| 182 | if (interform.HasXFAForm()) |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 183 | FPDF_UnSupportError(FPDF_UNSP_DOC_XFAFORM); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 184 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 185 | } |
| 186 | |
thestig | a55880d | 2016-05-23 09:11:54 -0700 | [diff] [blame] | 187 | DLLEXPORT int STDCALL FPDFDoc_GetPageMode(FPDF_DOCUMENT document) { |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 188 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 189 | if (!pDoc) |
Tom Sepez | ca3ac5e | 2015-06-10 17:38:11 -0700 | [diff] [blame] | 190 | return PAGEMODE_UNKNOWN; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 191 | |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 192 | CPDF_Dictionary* pRoot = pDoc->GetRoot(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 193 | if (!pRoot) |
| 194 | return PAGEMODE_UNKNOWN; |
| 195 | |
tsepez | bd56755 | 2016-03-29 14:51:50 -0700 | [diff] [blame] | 196 | CPDF_Object* pName = pRoot->GetObjectBy("PageMode"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 197 | if (!pName) |
| 198 | return PAGEMODE_USENONE; |
| 199 | |
| 200 | CFX_ByteString strPageMode = pName->GetString(); |
| 201 | if (strPageMode.IsEmpty() || strPageMode.EqualNoCase("UseNone")) |
| 202 | return PAGEMODE_USENONE; |
| 203 | if (strPageMode.EqualNoCase("UseOutlines")) |
| 204 | return PAGEMODE_USEOUTLINES; |
| 205 | if (strPageMode.EqualNoCase("UseThumbs")) |
| 206 | return PAGEMODE_USETHUMBS; |
| 207 | if (strPageMode.EqualNoCase("FullScreen")) |
| 208 | return PAGEMODE_FULLSCREEN; |
| 209 | if (strPageMode.EqualNoCase("UseOC")) |
| 210 | return PAGEMODE_USEOC; |
| 211 | if (strPageMode.EqualNoCase("UseAttachments")) |
| 212 | return PAGEMODE_USEATTACHMENTS; |
| 213 | |
| 214 | return PAGEMODE_UNKNOWN; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 215 | } |