| 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 "xfa/fxfa/parser/xfa_parser_imp.h" | 7 #include "xfa/fxfa/parser/xfa_parser_imp.h" |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "xfa/fde/xml/fde_xml_imp.h" | 11 #include "xfa/fde/xml/fde_xml_imp.h" |
| 12 #include "xfa/fgas/crt/fgas_codepage.h" | 12 #include "xfa/fgas/crt/fgas_codepage.h" |
| 13 #include "xfa/fxfa/include/xfa_checksum.h" | 13 #include "xfa/fxfa/include/xfa_checksum.h" |
| 14 #include "xfa/fxfa/parser/xfa_basic_imp.h" | 14 #include "xfa/fxfa/parser/xfa_basic_imp.h" |
| 15 #include "xfa/fxfa/parser/xfa_doclayout.h" | 15 #include "xfa/fxfa/parser/xfa_doclayout.h" |
| 16 #include "xfa/fxfa/parser/xfa_document.h" | 16 #include "xfa/fxfa/parser/xfa_document.h" |
| 17 #include "xfa/fxfa/parser/xfa_localemgr.h" | 17 #include "xfa/fxfa/parser/xfa_localemgr.h" |
| 18 #include "xfa/fxfa/parser/xfa_object.h" | 18 #include "xfa/fxfa/parser/xfa_object.h" |
| 19 #include "xfa/fxfa/parser/xfa_parser.h" | |
| 20 #include "xfa/fxfa/parser/xfa_script.h" | 19 #include "xfa/fxfa/parser/xfa_script.h" |
| 21 #include "xfa/fxfa/parser/xfa_utils.h" | 20 #include "xfa/fxfa/parser/xfa_utils.h" |
| 22 | 21 |
| 23 IXFA_Parser* IXFA_Parser::Create(CXFA_Document* pFactory, | |
| 24 FX_BOOL bDocumentParser) { | |
| 25 return new CXFA_SimpleParser(pFactory, bDocumentParser); | |
| 26 } | |
| 27 CXFA_SimpleParser::CXFA_SimpleParser(CXFA_Document* pFactory, | 22 CXFA_SimpleParser::CXFA_SimpleParser(CXFA_Document* pFactory, |
| 28 FX_BOOL bDocumentParser) | 23 FX_BOOL bDocumentParser) |
| 29 : m_pXMLParser(nullptr), | 24 : m_pXMLParser(nullptr), |
| 30 m_pXMLDoc(nullptr), | 25 m_pXMLDoc(nullptr), |
| 31 m_pStream(nullptr), | 26 m_pStream(nullptr), |
| 32 m_pFileRead(nullptr), | 27 m_pFileRead(nullptr), |
| 33 m_pFactory(pFactory), | 28 m_pFactory(pFactory), |
| 34 m_pRootNode(nullptr), | 29 m_pRootNode(nullptr), |
| 35 m_ePacketID(XFA_XDPPACKET_UNKNOWN), | 30 m_ePacketID(XFA_XDPPACKET_UNKNOWN), |
| 36 m_bDocumentParser(bDocumentParser) {} | 31 m_bDocumentParser(bDocumentParser) {} |
| 32 |
| 37 CXFA_SimpleParser::~CXFA_SimpleParser() { | 33 CXFA_SimpleParser::~CXFA_SimpleParser() { |
| 38 CloseParser(); | 34 CloseParser(); |
| 39 } | 35 } |
| 40 void CXFA_SimpleParser::Release() { | 36 |
| 41 delete this; | |
| 42 } | |
| 43 void CXFA_SimpleParser::SetFactory(CXFA_Document* pFactory) { | 37 void CXFA_SimpleParser::SetFactory(CXFA_Document* pFactory) { |
| 44 m_pFactory = pFactory; | 38 m_pFactory = pFactory; |
| 45 } | 39 } |
| 40 |
| 46 static CFDE_XMLNode* XFA_FDEExtension_GetDocumentNode( | 41 static CFDE_XMLNode* XFA_FDEExtension_GetDocumentNode( |
| 47 CFDE_XMLDoc* pXMLDoc, | 42 CFDE_XMLDoc* pXMLDoc, |
| 48 FX_BOOL bVerifyWellFormness = FALSE) { | 43 FX_BOOL bVerifyWellFormness = FALSE) { |
| 49 if (!pXMLDoc) { | 44 if (!pXMLDoc) { |
| 50 return nullptr; | 45 return nullptr; |
| 51 } | 46 } |
| 52 CFDE_XMLNode* pXMLFakeRoot = pXMLDoc->GetRoot(); | 47 CFDE_XMLNode* pXMLFakeRoot = pXMLDoc->GetRoot(); |
| 53 for (CFDE_XMLNode* pXMLNode = | 48 for (CFDE_XMLNode* pXMLNode = |
| 54 pXMLFakeRoot->GetNodeItem(CFDE_XMLNode::FirstChild); | 49 pXMLFakeRoot->GetNodeItem(CFDE_XMLNode::FirstChild); |
| 55 pXMLNode; pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { | 50 pXMLNode; pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 m_pRootNode = DataLoader(pXFANode, pXMLNode, TRUE); | 182 m_pRootNode = DataLoader(pXFANode, pXMLNode, TRUE); |
| 188 } | 183 } |
| 189 } else if (pXFANode->IsContentNode()) { | 184 } else if (pXFANode->IsContentNode()) { |
| 190 ParseContentNode(pXFANode, pXMLNode, ePacketID); | 185 ParseContentNode(pXFANode, pXMLNode, ePacketID); |
| 191 m_pRootNode = pXFANode; | 186 m_pRootNode = pXFANode; |
| 192 } else { | 187 } else { |
| 193 m_pRootNode = NormalLoader(pXFANode, pXMLNode, ePacketID); | 188 m_pRootNode = NormalLoader(pXFANode, pXMLNode, ePacketID); |
| 194 } | 189 } |
| 195 } | 190 } |
| 196 | 191 |
| 197 CXFA_Document* CXFA_SimpleParser::GetFactory() const { | |
| 198 return m_pFactory; | |
| 199 } | |
| 200 | |
| 201 CXFA_Node* CXFA_SimpleParser::GetRootNode() const { | 192 CXFA_Node* CXFA_SimpleParser::GetRootNode() const { |
| 202 return m_pRootNode; | 193 return m_pRootNode; |
| 203 } | 194 } |
| 204 | 195 |
| 205 CFDE_XMLDoc* CXFA_SimpleParser::GetXMLDoc() const { | 196 CFDE_XMLDoc* CXFA_SimpleParser::GetXMLDoc() const { |
| 206 return m_pXMLDoc; | 197 return m_pXMLDoc; |
| 207 } | 198 } |
| 208 | 199 |
| 209 FX_BOOL XFA_FDEExtension_ResolveNamespaceQualifier( | 200 FX_BOOL XFA_FDEExtension_ResolveNamespaceQualifier( |
| 210 CFDE_XMLElement* pNode, | 201 CFDE_XMLElement* pNode, |
| (...skipping 1137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1348 m_pXMLDoc = nullptr; | 1339 m_pXMLDoc = nullptr; |
| 1349 } | 1340 } |
| 1350 if (m_pStream) { | 1341 if (m_pStream) { |
| 1351 m_pStream->Release(); | 1342 m_pStream->Release(); |
| 1352 m_pStream = nullptr; | 1343 m_pStream = nullptr; |
| 1353 } | 1344 } |
| 1354 } | 1345 } |
| 1355 | 1346 |
| 1356 CXFA_DocumentParser::CXFA_DocumentParser(CXFA_FFNotify* pNotify) | 1347 CXFA_DocumentParser::CXFA_DocumentParser(CXFA_FFNotify* pNotify) |
| 1357 : m_nodeParser(nullptr, TRUE), m_pNotify(pNotify), m_pDocument(nullptr) {} | 1348 : m_nodeParser(nullptr, TRUE), m_pNotify(pNotify), m_pDocument(nullptr) {} |
| 1349 |
| 1358 CXFA_DocumentParser::~CXFA_DocumentParser() { | 1350 CXFA_DocumentParser::~CXFA_DocumentParser() { |
| 1359 CloseParser(); | |
| 1360 } | 1351 } |
| 1361 | 1352 |
| 1362 void CXFA_DocumentParser::Release() { | |
| 1363 delete this; | |
| 1364 } | |
| 1365 int32_t CXFA_DocumentParser::StartParse(IFX_FileRead* pStream, | 1353 int32_t CXFA_DocumentParser::StartParse(IFX_FileRead* pStream, |
| 1366 XFA_XDPPACKET ePacketID) { | 1354 XFA_XDPPACKET ePacketID) { |
| 1367 CloseParser(); | 1355 CloseParser(); |
| 1368 int32_t nRetStatus = m_nodeParser.StartParse(pStream, ePacketID); | 1356 int32_t nRetStatus = m_nodeParser.StartParse(pStream, ePacketID); |
| 1369 if (nRetStatus == XFA_PARSESTATUS_Ready) { | 1357 if (nRetStatus == XFA_PARSESTATUS_Ready) { |
| 1370 m_pDocument = new CXFA_Document(this); | 1358 m_pDocument.reset(new CXFA_Document(this)); |
| 1371 m_nodeParser.SetFactory(m_pDocument); | 1359 m_nodeParser.SetFactory(m_pDocument.get()); |
| 1372 } | 1360 } |
| 1373 return nRetStatus; | 1361 return nRetStatus; |
| 1374 } | 1362 } |
| 1363 |
| 1375 int32_t CXFA_DocumentParser::DoParse(IFX_Pause* pPause) { | 1364 int32_t CXFA_DocumentParser::DoParse(IFX_Pause* pPause) { |
| 1376 int32_t nRetStatus = m_nodeParser.DoParse(pPause); | 1365 int32_t nRetStatus = m_nodeParser.DoParse(pPause); |
| 1377 if (nRetStatus >= XFA_PARSESTATUS_Done) { | 1366 if (nRetStatus >= XFA_PARSESTATUS_Done) { |
| 1378 ASSERT(m_pDocument); | 1367 ASSERT(m_pDocument); |
| 1379 m_pDocument->SetRoot(m_nodeParser.GetRootNode()); | 1368 m_pDocument->SetRoot(m_nodeParser.GetRootNode()); |
| 1380 } | 1369 } |
| 1381 return nRetStatus; | 1370 return nRetStatus; |
| 1382 } | 1371 } |
| 1383 int32_t CXFA_DocumentParser::ParseXMLData(const CFX_WideString& wsXML, | |
| 1384 CFDE_XMLNode*& pXMLNode, | |
| 1385 IFX_Pause* pPause) { | |
| 1386 CloseParser(); | |
| 1387 int32_t nRetStatus = m_nodeParser.ParseXMLData(wsXML, pXMLNode, nullptr); | |
| 1388 if (nRetStatus == XFA_PARSESTATUS_Done && pXMLNode) { | |
| 1389 m_pDocument = new CXFA_Document(this); | |
| 1390 m_nodeParser.SetFactory(m_pDocument); | |
| 1391 } | |
| 1392 return nRetStatus; | |
| 1393 } | |
| 1394 void CXFA_DocumentParser::ConstructXFANode(CXFA_Node* pXFANode, | |
| 1395 CFDE_XMLNode* pXMLNode) { | |
| 1396 if (!pXFANode || !pXMLNode) { | |
| 1397 return; | |
| 1398 } | |
| 1399 m_nodeParser.ConstructXFANode(pXFANode, pXMLNode); | |
| 1400 CXFA_Node* pRootNode = m_nodeParser.GetRootNode(); | |
| 1401 if (m_pDocument && pRootNode) { | |
| 1402 m_pDocument->SetRoot(pRootNode); | |
| 1403 } | |
| 1404 } | |
| 1405 | |
| 1406 CXFA_Document* CXFA_DocumentParser::GetFactory() const { | |
| 1407 return m_nodeParser.GetFactory(); | |
| 1408 } | |
| 1409 | |
| 1410 CXFA_Node* CXFA_DocumentParser::GetRootNode() const { | |
| 1411 return m_nodeParser.GetRootNode(); | |
| 1412 } | |
| 1413 | 1372 |
| 1414 CFDE_XMLDoc* CXFA_DocumentParser::GetXMLDoc() const { | 1373 CFDE_XMLDoc* CXFA_DocumentParser::GetXMLDoc() const { |
| 1415 return m_nodeParser.GetXMLDoc(); | 1374 return m_nodeParser.GetXMLDoc(); |
| 1416 } | 1375 } |
| 1417 | 1376 |
| 1418 CXFA_FFNotify* CXFA_DocumentParser::GetNotify() const { | 1377 CXFA_FFNotify* CXFA_DocumentParser::GetNotify() const { |
| 1419 return m_pNotify; | 1378 return m_pNotify; |
| 1420 } | 1379 } |
| 1421 | 1380 |
| 1422 CXFA_Document* CXFA_DocumentParser::GetDocument() const { | 1381 CXFA_Document* CXFA_DocumentParser::GetDocument() const { |
| 1423 return m_pDocument; | 1382 return m_pDocument.get(); |
| 1424 } | 1383 } |
| 1425 | 1384 |
| 1426 void CXFA_DocumentParser::CloseParser() { | 1385 void CXFA_DocumentParser::CloseParser() { |
| 1427 delete m_pDocument; | 1386 m_pDocument.reset(nullptr); |
| 1428 m_pDocument = nullptr; | |
| 1429 m_nodeParser.CloseParser(); | 1387 m_nodeParser.CloseParser(); |
| 1430 } | 1388 } |
| 1431 | 1389 |
| 1432 CXFA_XMLParser::CXFA_XMLParser(CFDE_XMLNode* pRoot, IFX_Stream* pStream) | 1390 CXFA_XMLParser::CXFA_XMLParser(CFDE_XMLNode* pRoot, IFX_Stream* pStream) |
| 1433 : m_nElementStart(0), | 1391 : m_nElementStart(0), |
| 1434 m_dwCheckStatus(0), | 1392 m_dwCheckStatus(0), |
| 1435 m_dwCurrentCheckStatus(0), | 1393 m_dwCurrentCheckStatus(0), |
| 1436 m_pRoot(pRoot), | 1394 m_pRoot(pRoot), |
| 1437 m_pStream(pStream), | 1395 m_pStream(pStream), |
| 1438 m_pParser(nullptr), | 1396 m_pParser(nullptr), |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1594 } | 1552 } |
| 1595 if (pPause && iCount > 500 && pPause->NeedToPauseNow()) { | 1553 if (pPause && iCount > 500 && pPause->NeedToPauseNow()) { |
| 1596 break; | 1554 break; |
| 1597 } | 1555 } |
| 1598 } | 1556 } |
| 1599 return (m_syntaxParserResult == FDE_XmlSyntaxResult::Error || | 1557 return (m_syntaxParserResult == FDE_XmlSyntaxResult::Error || |
| 1600 m_NodeStack.GetSize() != 1) | 1558 m_NodeStack.GetSize() != 1) |
| 1601 ? -1 | 1559 ? -1 |
| 1602 : m_pParser->GetStatus(); | 1560 : m_pParser->GetStatus(); |
| 1603 } | 1561 } |
| OLD | NEW |