OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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 "xfa/fxfa/parser/cxfa_simple_parser.h" | 7 #include "xfa/fxfa/parser/cxfa_simple_parser.h" |
8 | 8 |
| 9 #include "core/fxcrt/include/fx_ext.h" |
9 #include "xfa/fgas/crt/fgas_codepage.h" | 10 #include "xfa/fgas/crt/fgas_codepage.h" |
10 #include "xfa/fxfa/include/fxfa.h" | 11 #include "xfa/fxfa/include/fxfa.h" |
11 #include "xfa/fxfa/include/xfa_checksum.h" | 12 #include "xfa/fxfa/include/xfa_checksum.h" |
| 13 #include "xfa/fxfa/parser/cxfa_widetextread.h" |
12 #include "xfa/fxfa/parser/cxfa_xml_parser.h" | 14 #include "xfa/fxfa/parser/cxfa_xml_parser.h" |
| 15 #include "xfa/fxfa/parser/xfa_basic_data.h" |
13 #include "xfa/fxfa/parser/xfa_document.h" | 16 #include "xfa/fxfa/parser/xfa_document.h" |
| 17 #include "xfa/fxfa/parser/xfa_utils.h" |
14 | 18 |
15 namespace { | 19 namespace { |
16 | 20 |
17 CFDE_XMLNode* GetDocumentNode(CFDE_XMLDoc* pXMLDoc, | 21 CFDE_XMLNode* GetDocumentNode(CFDE_XMLDoc* pXMLDoc, |
18 FX_BOOL bVerifyWellFormness = FALSE) { | 22 FX_BOOL bVerifyWellFormness = FALSE) { |
19 if (!pXMLDoc) | 23 if (!pXMLDoc) |
20 return nullptr; | 24 return nullptr; |
21 | 25 |
22 for (CFDE_XMLNode* pXMLNode = | 26 for (CFDE_XMLNode* pXMLNode = |
23 pXMLDoc->GetRoot()->GetNodeItem(CFDE_XMLNode::FirstChild); | 27 pXMLDoc->GetRoot()->GetNodeItem(CFDE_XMLNode::FirstChild); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 wsOutput = wsCharData; | 221 wsOutput = wsCharData; |
218 break; | 222 break; |
219 } | 223 } |
220 default: | 224 default: |
221 ASSERT(FALSE); | 225 ASSERT(FALSE); |
222 break; | 226 break; |
223 } | 227 } |
224 } | 228 } |
225 } | 229 } |
226 | 230 |
| 231 const XFA_PACKETINFO* GetPacketByName(const CFX_WideStringC& wsName) { |
| 232 if (wsName.IsEmpty()) |
| 233 return nullptr; |
| 234 |
| 235 uint32_t uHash = FX_HashCode_GetW(wsName, false); |
| 236 int32_t iStart = 0; |
| 237 int32_t iEnd = g_iXFAPacketCount - 1; |
| 238 do { |
| 239 int32_t iMid = (iStart + iEnd) / 2; |
| 240 const XFA_PACKETINFO* pInfo = g_XFAPacketData + iMid; |
| 241 if (uHash == pInfo->uHash) |
| 242 return pInfo; |
| 243 if (uHash < pInfo->uHash) |
| 244 iEnd = iMid - 1; |
| 245 else |
| 246 iStart = iMid + 1; |
| 247 } while (iStart <= iEnd); |
| 248 return nullptr; |
| 249 } |
| 250 |
227 } // namespace | 251 } // namespace |
228 | 252 |
229 FX_BOOL XFA_RecognizeRichText(CFDE_XMLElement* pRichTextXMLNode) { | 253 FX_BOOL XFA_RecognizeRichText(CFDE_XMLElement* pRichTextXMLNode) { |
230 if (pRichTextXMLNode) { | 254 if (pRichTextXMLNode) { |
231 CFX_WideString wsNamespaceURI; | 255 CFX_WideString wsNamespaceURI; |
232 GetElementTagNamespaceURI(pRichTextXMLNode, wsNamespaceURI); | 256 GetElementTagNamespaceURI(pRichTextXMLNode, wsNamespaceURI); |
233 if (wsNamespaceURI == FX_WSTRC(L"http://www.w3.org/1999/xhtml")) | 257 if (wsNamespaceURI == FX_WSTRC(L"http://www.w3.org/1999/xhtml")) |
234 return TRUE; | 258 return TRUE; |
235 } | 259 } |
236 return FALSE; | 260 return FALSE; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 return XFA_PARSESTATUS_StatusErr; | 318 return XFA_PARSESTATUS_StatusErr; |
295 return XFA_PARSESTATUS_Done; | 319 return XFA_PARSESTATUS_Done; |
296 } | 320 } |
297 | 321 |
298 int32_t CXFA_SimpleParser::ParseXMLData(const CFX_WideString& wsXML, | 322 int32_t CXFA_SimpleParser::ParseXMLData(const CFX_WideString& wsXML, |
299 CFDE_XMLNode*& pXMLNode, | 323 CFDE_XMLNode*& pXMLNode, |
300 IFX_Pause* pPause) { | 324 IFX_Pause* pPause) { |
301 CloseParser(); | 325 CloseParser(); |
302 pXMLNode = nullptr; | 326 pXMLNode = nullptr; |
303 | 327 |
304 std::unique_ptr<IFX_Stream> pStream(XFA_CreateWideTextRead(wsXML)); | 328 std::unique_ptr<IFX_Stream> pStream(new CXFA_WideTextRead(wsXML)); |
305 if (!pStream) | |
306 return XFA_PARSESTATUS_StreamErr; | |
307 | |
308 m_pXMLDoc.reset(new CFDE_XMLDoc); | 329 m_pXMLDoc.reset(new CFDE_XMLDoc); |
309 CXFA_XMLParser* pParser = | 330 CXFA_XMLParser* pParser = |
310 new CXFA_XMLParser(m_pXMLDoc->GetRoot(), pStream.get()); | 331 new CXFA_XMLParser(m_pXMLDoc->GetRoot(), pStream.get()); |
311 pParser->m_dwCheckStatus = 0x03; | 332 pParser->m_dwCheckStatus = 0x03; |
312 if (!m_pXMLDoc->LoadXML(pParser)) | 333 if (!m_pXMLDoc->LoadXML(pParser)) |
313 return XFA_PARSESTATUS_StatusErr; | 334 return XFA_PARSESTATUS_StatusErr; |
314 | 335 |
315 int32_t iRet = m_pXMLDoc->DoLoad(pPause); | 336 int32_t iRet = m_pXMLDoc->DoLoad(pPause); |
316 if (iRet < 0 || iRet >= 100) | 337 if (iRet < 0 || iRet >= 100) |
317 m_pXMLDoc->CloseXML(); | 338 m_pXMLDoc->CloseXML(); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 if (!pChildItem || pChildItem->GetType() != FDE_XMLNODE_Element) | 518 if (!pChildItem || pChildItem->GetType() != FDE_XMLNODE_Element) |
498 continue; | 519 continue; |
499 if (pChildItem == pXMLConfigDOMRoot) | 520 if (pChildItem == pXMLConfigDOMRoot) |
500 continue; | 521 continue; |
501 | 522 |
502 CFDE_XMLElement* pElement = | 523 CFDE_XMLElement* pElement = |
503 reinterpret_cast<CFDE_XMLElement*>(pChildItem); | 524 reinterpret_cast<CFDE_XMLElement*>(pChildItem); |
504 CFX_WideString wsPacketName; | 525 CFX_WideString wsPacketName; |
505 pElement->GetLocalTagName(wsPacketName); | 526 pElement->GetLocalTagName(wsPacketName); |
506 const XFA_PACKETINFO* pPacketInfo = | 527 const XFA_PACKETINFO* pPacketInfo = |
507 XFA_GetPacketByName(wsPacketName.AsStringC()); | 528 GetPacketByName(wsPacketName.AsStringC()); |
508 if (pPacketInfo && pPacketInfo->pURI) { | 529 if (pPacketInfo && pPacketInfo->pURI) { |
509 if (!MatchNodeName(pElement, pPacketInfo->pName, pPacketInfo->pURI, | 530 if (!MatchNodeName(pElement, pPacketInfo->pName, pPacketInfo->pURI, |
510 pPacketInfo->eFlags)) { | 531 pPacketInfo->eFlags)) { |
511 pPacketInfo = nullptr; | 532 pPacketInfo = nullptr; |
512 } | 533 } |
513 } | 534 } |
514 XFA_XDPPACKET ePacket = | 535 XFA_XDPPACKET ePacket = |
515 pPacketInfo ? pPacketInfo->eName : XFA_XDPPACKET_USER; | 536 pPacketInfo ? pPacketInfo->eName : XFA_XDPPACKET_USER; |
516 if (ePacket == XFA_XDPPACKET_XDP) | 537 if (ePacket == XFA_XDPPACKET_XDP) |
517 continue; | 538 continue; |
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1279 pXFANode->GetDocument()->SetFlag(XFA_DOCFLAG_StrictScoping, TRUE); | 1300 pXFANode->GetDocument()->SetFlag(XFA_DOCFLAG_StrictScoping, TRUE); |
1280 } | 1301 } |
1281 } | 1302 } |
1282 } | 1303 } |
1283 } | 1304 } |
1284 | 1305 |
1285 void CXFA_SimpleParser::CloseParser() { | 1306 void CXFA_SimpleParser::CloseParser() { |
1286 m_pXMLDoc.reset(); | 1307 m_pXMLDoc.reset(); |
1287 m_pStream.reset(); | 1308 m_pStream.reset(); |
1288 } | 1309 } |
OLD | NEW |