blob: 0a76a0d4beb77af6abaaa1c66e982ac38373ea2d [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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 Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Lei Zhangb4e7f302015-11-06 15:52:32 -08007#include "public/fpdf_ext.h"
8
thestigdb1a24e2016-05-23 16:55:09 -07009#include <memory>
10
Dan Sinclairaa403d32016-03-15 14:57:22 -040011#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"
tsepezddffb572016-05-24 16:20:29 -070014#include "core/fxcrt/include/fx_basic.h"
Dan Sinclaira8a28e02016-03-23 15:41:39 -040015#include "core/fxcrt/include/fx_xml.h"
Lei Zhangbde53d22015-11-12 22:21:30 -080016#include "fpdfsdk/include/fsdk_define.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070017
Tom Sepez40e9ff32015-11-30 12:39:54 -080018#ifdef PDF_ENABLE_XFA
dsinclair89bdd082016-04-06 10:47:54 -070019#include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080020#endif // PDF_ENABLE_XFA
21
Nico Weber9d8ec5a2015-08-04 13:00:21 -070022#define FPDFSDK_UNSUPPORT_CALL 100
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070023
tsepezddffb572016-05-24 16:20:29 -070024class CFSDK_UnsupportInfo_Adapter : public CFX_Deletable {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070025 public:
thestigdb1a24e2016-05-23 16:55:09 -070026 explicit CFSDK_UnsupportInfo_Adapter(UNSUPPORT_INFO* unsp_info)
27 : m_unsp_info(unsp_info) {}
28
Nico Weber9d8ec5a2015-08-04 13:00:21 -070029 void ReportError(int nErrorType);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070030
Nico Weber9d8ec5a2015-08-04 13:00:21 -070031 private:
thestigdb1a24e2016-05-23 16:55:09 -070032 UNSUPPORT_INFO* const m_unsp_info;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070033};
34
Nico Weber9d8ec5a2015-08-04 13:00:21 -070035void 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-Malek3f3b45c2014-05-23 17:28:10 -070039}
40
Nico Weber9d8ec5a2015-08-04 13:00:21 -070041FX_BOOL FPDF_UnSupportError(int nError) {
42 CFSDK_UnsupportInfo_Adapter* pAdapter =
tsepezddffb572016-05-24 16:20:29 -070043 static_cast<CFSDK_UnsupportInfo_Adapter*>(
44 CPDF_ModuleMgr::Get()->GetUnsupportInfoAdapter());
Nico Weber9d8ec5a2015-08-04 13:00:21 -070045 if (!pAdapter)
Tom Sepez2f2ffec2015-07-23 14:42:09 -070046 return FALSE;
tsepezddffb572016-05-24 16:20:29 -070047
Nico Weber9d8ec5a2015-08-04 13:00:21 -070048 pAdapter->ReportError(nError);
49 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070050}
51
Nico Weber9d8ec5a2015-08-04 13:00:21 -070052DLLEXPORT FPDF_BOOL STDCALL
53FSDK_SetUnSpObjProcessHandler(UNSUPPORT_INFO* unsp_info) {
54 if (!unsp_info || unsp_info->version != 1)
55 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070056
tsepezddffb572016-05-24 16:20:29 -070057 CPDF_ModuleMgr::Get()->SetUnsupportInfoAdapter(std::unique_ptr<CFX_Deletable>(
58 new CFSDK_UnsupportInfo_Adapter(unsp_info)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -070059 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070060}
61
Lei Zhang1b700c32015-10-30 23:55:35 -070062void CheckUnSupportAnnot(CPDF_Document* pDoc, const CPDF_Annot* pPDFAnnot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070063 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 Zhang1b700c32015-10-30 23:55:35 -070067 const CPDF_Dictionary* pAnnotDict = pPDFAnnot->GetAnnotDict();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070068 CFX_ByteString cbString;
69 if (pAnnotDict->KeyExist("IT"))
Wei Li9b761132016-01-29 15:44:20 -080070 cbString = pAnnotDict->GetStringBy("IT");
Nico Weber9d8ec5a2015-08-04 13:00:21 -070071 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 Zhang1b700c32015-10-30 23:55:35 -070082 const CPDF_Dictionary* pAnnotDict = pPDFAnnot->GetAnnotDict();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070083 CFX_ByteString cbString;
84 if (pAnnotDict->KeyExist("FT")) {
Wei Li9b761132016-01-29 15:44:20 -080085 cbString = pAnnotDict->GetStringBy("FT");
Nico Weber9d8ec5a2015-08-04 13:00:21 -070086 }
87 if (cbString.Compare("Sig") == 0) {
88 FPDF_UnSupportError(FPDF_UNSP_ANNOT_SIG);
89 }
90 }
91}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070092
Lei Zhang119dc642015-08-11 14:08:47 -070093FX_BOOL CheckSharedForm(const CXML_Element* pElement, CFX_ByteString cbName) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070094 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 Zhangd983b092015-12-14 16:58:33 -0800100 if (space == "xmlns" && name == "adhocwf" &&
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700101 value == L"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/") {
tsepez28f97ff2016-04-04 16:41:35 -0700102 CXML_Element* pVersion =
tsepez4c3debb2016-04-08 12:20:38 -0700103 pElement->GetElement("adhocwf", cbName.AsStringC());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700104 if (!pVersion)
105 continue;
tsepez28f97ff2016-04-04 16:41:35 -0700106 CFX_WideString wsContent = pVersion->GetContent(0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700107 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 Sepezca3ac5e2015-06-10 17:38:11 -0700121
tsepezc3255f52016-03-25 14:52:27 -0700122 uint32_t nCount = pElement->CountChildren();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700123 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 Sepezca3ac5e2015-06-10 17:38:11 -0700133
tsepezc3255f52016-03-25 14:52:27 -0700134void CheckUnSupportError(CPDF_Document* pDoc, uint32_t err_code) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700135 // Security
136 if (err_code == FPDF_ERR_SECURITY) {
137 FPDF_UnSupportError(FPDF_UNSP_DOC_SECURITY);
138 return;
139 }
140 if (!pDoc)
141 return;
Tom Sepezca3ac5e2015-06-10 17:38:11 -0700142
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700143 // 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 Li9b761132016-01-29 15:44:20 -0800152 CPDF_Dictionary* pNameDict = pRootDict->GetDictBy("Names");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700153 if (pNameDict && pNameDict->KeyExist("EmbeddedFiles")) {
154 FPDF_UnSupportError(FPDF_UNSP_DOC_ATTACHMENT);
155 return;
Tom Sepez468e5892015-10-13 15:49:36 -0700156 }
157 if (pNameDict && pNameDict->KeyExist("JavaScript")) {
Wei Li9b761132016-01-29 15:44:20 -0800158 CPDF_Dictionary* pJSDict = pNameDict->GetDictBy("JavaScript");
159 CPDF_Array* pArray = pJSDict ? pJSDict->GetArrayBy("Names") : NULL;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700160 if (pArray) {
Wei Lie1aebd42016-04-11 10:02:09 -0700161 for (size_t i = 0; i < pArray->GetCount(); i++) {
Wei Li9b761132016-01-29 15:44:20 -0800162 CFX_ByteString cbStr = pArray->GetStringAt(i);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700163 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 Zhang119dc642015-08-11 14:08:47 -0700174 CPDF_Metadata metaData(pDoc);
175 const CXML_Element* pElement = metaData.GetRoot();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700176 if (pElement)
177 CheckSharedForm(pElement, "workflowType");
Tom Sepez51da0932015-11-25 16:05:49 -0800178
Tom Sepez40e9ff32015-11-30 12:39:54 -0800179#ifndef PDF_ENABLE_XFA
Tom Sepez51da0932015-11-25 16:05:49 -0800180 // XFA Forms
thestigdb1a24e2016-05-23 16:55:09 -0700181 CPDF_InterForm interform(pDoc);
182 if (interform.HasXFAForm())
Tom Sepez51da0932015-11-25 16:05:49 -0800183 FPDF_UnSupportError(FPDF_UNSP_DOC_XFAFORM);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800184#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700185}
186
thestiga55880d2016-05-23 09:11:54 -0700187DLLEXPORT int STDCALL FPDFDoc_GetPageMode(FPDF_DOCUMENT document) {
Tom Sepez471a1032015-10-15 16:17:18 -0700188 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
189 if (!pDoc)
Tom Sepezca3ac5e2015-06-10 17:38:11 -0700190 return PAGEMODE_UNKNOWN;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700191
Tom Sepez471a1032015-10-15 16:17:18 -0700192 CPDF_Dictionary* pRoot = pDoc->GetRoot();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700193 if (!pRoot)
194 return PAGEMODE_UNKNOWN;
195
tsepezbd567552016-03-29 14:51:50 -0700196 CPDF_Object* pName = pRoot->GetObjectBy("PageMode");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700197 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-Malek3f3b45c2014-05-23 17:28:10 -0700215}