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