| 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 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 1117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1328 m_pXMLDoc = nullptr; | 1319 m_pXMLDoc = nullptr; |
| 1329 } | 1320 } |
| 1330 if (m_pStream) { | 1321 if (m_pStream) { |
| 1331 m_pStream->Release(); | 1322 m_pStream->Release(); |
| 1332 m_pStream = nullptr; | 1323 m_pStream = nullptr; |
| 1333 } | 1324 } |
| 1334 } | 1325 } |
| 1335 | 1326 |
| 1336 CXFA_DocumentParser::CXFA_DocumentParser(CXFA_FFNotify* pNotify) | 1327 CXFA_DocumentParser::CXFA_DocumentParser(CXFA_FFNotify* pNotify) |
| 1337 : m_nodeParser(nullptr, TRUE), m_pNotify(pNotify), m_pDocument(nullptr) {} | 1328 : m_nodeParser(nullptr, TRUE), m_pNotify(pNotify), m_pDocument(nullptr) {} |
| 1329 |
| 1338 CXFA_DocumentParser::~CXFA_DocumentParser() { | 1330 CXFA_DocumentParser::~CXFA_DocumentParser() { |
| 1339 CloseParser(); | 1331 CloseParser(); |
| 1340 } | 1332 } |
| 1341 | 1333 |
| 1342 void CXFA_DocumentParser::Release() { | |
| 1343 delete this; | |
| 1344 } | |
| 1345 int32_t CXFA_DocumentParser::StartParse(IFX_FileRead* pStream, | 1334 int32_t CXFA_DocumentParser::StartParse(IFX_FileRead* pStream, |
| 1346 XFA_XDPPACKET ePacketID) { | 1335 XFA_XDPPACKET ePacketID) { |
| 1347 CloseParser(); | 1336 CloseParser(); |
| 1348 int32_t nRetStatus = m_nodeParser.StartParse(pStream, ePacketID); | 1337 int32_t nRetStatus = m_nodeParser.StartParse(pStream, ePacketID); |
| 1349 if (nRetStatus == XFA_PARSESTATUS_Ready) { | 1338 if (nRetStatus == XFA_PARSESTATUS_Ready) { |
| 1350 m_pDocument = new CXFA_Document(this); | 1339 m_pDocument.reset(new CXFA_Document(this)); |
| 1351 m_nodeParser.SetFactory(m_pDocument); | 1340 m_nodeParser.SetFactory(m_pDocument.get()); |
| 1352 } | 1341 } |
| 1353 return nRetStatus; | 1342 return nRetStatus; |
| 1354 } | 1343 } |
| 1344 |
| 1355 int32_t CXFA_DocumentParser::DoParse(IFX_Pause* pPause) { | 1345 int32_t CXFA_DocumentParser::DoParse(IFX_Pause* pPause) { |
| 1356 int32_t nRetStatus = m_nodeParser.DoParse(pPause); | 1346 int32_t nRetStatus = m_nodeParser.DoParse(pPause); |
| 1357 if (nRetStatus >= XFA_PARSESTATUS_Done) { | 1347 if (nRetStatus >= XFA_PARSESTATUS_Done) { |
| 1358 ASSERT(m_pDocument); | 1348 ASSERT(m_pDocument); |
| 1359 m_pDocument->SetRoot(m_nodeParser.GetRootNode()); | 1349 m_pDocument->SetRoot(m_nodeParser.GetRootNode()); |
| 1360 } | 1350 } |
| 1361 return nRetStatus; | 1351 return nRetStatus; |
| 1362 } | 1352 } |
| 1363 int32_t CXFA_DocumentParser::ParseXMLData(const CFX_WideString& wsXML, | |
| 1364 CFDE_XMLNode*& pXMLNode, | |
| 1365 IFX_Pause* pPause) { | |
| 1366 CloseParser(); | |
| 1367 int32_t nRetStatus = m_nodeParser.ParseXMLData(wsXML, pXMLNode, nullptr); | |
| 1368 if (nRetStatus == XFA_PARSESTATUS_Done && pXMLNode) { | |
| 1369 m_pDocument = new CXFA_Document(this); | |
| 1370 m_nodeParser.SetFactory(m_pDocument); | |
| 1371 } | |
| 1372 return nRetStatus; | |
| 1373 } | |
| 1374 void CXFA_DocumentParser::ConstructXFANode(CXFA_Node* pXFANode, | |
| 1375 CFDE_XMLNode* pXMLNode) { | |
| 1376 if (!pXFANode || !pXMLNode) { | |
| 1377 return; | |
| 1378 } | |
| 1379 m_nodeParser.ConstructXFANode(pXFANode, pXMLNode); | |
| 1380 CXFA_Node* pRootNode = m_nodeParser.GetRootNode(); | |
| 1381 if (m_pDocument && pRootNode) { | |
| 1382 m_pDocument->SetRoot(pRootNode); | |
| 1383 } | |
| 1384 } | |
| 1385 | |
| 1386 CXFA_Document* CXFA_DocumentParser::GetFactory() const { | |
| 1387 return m_nodeParser.GetFactory(); | |
| 1388 } | |
| 1389 | |
| 1390 CXFA_Node* CXFA_DocumentParser::GetRootNode() const { | |
| 1391 return m_nodeParser.GetRootNode(); | |
| 1392 } | |
| 1393 | 1353 |
| 1394 CFDE_XMLDoc* CXFA_DocumentParser::GetXMLDoc() const { | 1354 CFDE_XMLDoc* CXFA_DocumentParser::GetXMLDoc() const { |
| 1395 return m_nodeParser.GetXMLDoc(); | 1355 return m_nodeParser.GetXMLDoc(); |
| 1396 } | 1356 } |
| 1397 | 1357 |
| 1398 CXFA_FFNotify* CXFA_DocumentParser::GetNotify() const { | 1358 CXFA_FFNotify* CXFA_DocumentParser::GetNotify() const { |
| 1399 return m_pNotify; | 1359 return m_pNotify; |
| 1400 } | 1360 } |
| 1401 | 1361 |
| 1402 CXFA_Document* CXFA_DocumentParser::GetDocument() const { | 1362 CXFA_Document* CXFA_DocumentParser::GetDocument() const { |
| 1403 return m_pDocument; | 1363 return m_pDocument.get(); |
| 1404 } | 1364 } |
| 1405 | 1365 |
| 1406 void CXFA_DocumentParser::CloseParser() { | 1366 void CXFA_DocumentParser::CloseParser() { |
| 1407 delete m_pDocument; | 1367 m_pDocument.reset(); |
| 1408 m_pDocument = nullptr; | |
| 1409 m_nodeParser.CloseParser(); | 1368 m_nodeParser.CloseParser(); |
| 1410 } | 1369 } |
| 1411 | 1370 |
| 1412 CXFA_XMLParser::CXFA_XMLParser(CFDE_XMLNode* pRoot, IFX_Stream* pStream) | 1371 CXFA_XMLParser::CXFA_XMLParser(CFDE_XMLNode* pRoot, IFX_Stream* pStream) |
| 1413 : m_nElementStart(0), | 1372 : m_nElementStart(0), |
| 1414 m_dwCheckStatus(0), | 1373 m_dwCheckStatus(0), |
| 1415 m_dwCurrentCheckStatus(0), | 1374 m_dwCurrentCheckStatus(0), |
| 1416 m_pRoot(pRoot), | 1375 m_pRoot(pRoot), |
| 1417 m_pStream(pStream), | 1376 m_pStream(pStream), |
| 1418 m_pParser(nullptr), | 1377 m_pParser(nullptr), |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1574 } | 1533 } |
| 1575 if (pPause && iCount > 500 && pPause->NeedToPauseNow()) { | 1534 if (pPause && iCount > 500 && pPause->NeedToPauseNow()) { |
| 1576 break; | 1535 break; |
| 1577 } | 1536 } |
| 1578 } | 1537 } |
| 1579 return (m_syntaxParserResult == FDE_XmlSyntaxResult::Error || | 1538 return (m_syntaxParserResult == FDE_XmlSyntaxResult::Error || |
| 1580 m_NodeStack.GetSize() != 1) | 1539 m_NodeStack.GetSize() != 1) |
| 1581 ? -1 | 1540 ? -1 |
| 1582 : m_pParser->GetStatus(); | 1541 : m_pParser->GetStatus(); |
| 1583 } | 1542 } |
| OLD | NEW |