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