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