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