| 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 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 m_pXMLDoc(nullptr), | 30 m_pXMLDoc(nullptr), |
| 31 m_pStream(nullptr), | 31 m_pStream(nullptr), |
| 32 m_pFileRead(nullptr), | 32 m_pFileRead(nullptr), |
| 33 m_pFactory(pFactory), | 33 m_pFactory(pFactory), |
| 34 m_pRootNode(nullptr), | 34 m_pRootNode(nullptr), |
| 35 m_ePacketID(XFA_XDPPACKET_UNKNOWN), | 35 m_ePacketID(XFA_XDPPACKET_UNKNOWN), |
| 36 m_bDocumentParser(bDocumentParser) {} | 36 m_bDocumentParser(bDocumentParser) {} |
| 37 CXFA_SimpleParser::~CXFA_SimpleParser() { | 37 CXFA_SimpleParser::~CXFA_SimpleParser() { |
| 38 CloseParser(); | 38 CloseParser(); |
| 39 } | 39 } |
| 40 void CXFA_SimpleParser::Release() { |
| 41 delete this; |
| 42 } |
| 40 void CXFA_SimpleParser::SetFactory(CXFA_Document* pFactory) { | 43 void CXFA_SimpleParser::SetFactory(CXFA_Document* pFactory) { |
| 41 m_pFactory = pFactory; | 44 m_pFactory = pFactory; |
| 42 } | 45 } |
| 43 static CFDE_XMLNode* XFA_FDEExtension_GetDocumentNode( | 46 static CFDE_XMLNode* XFA_FDEExtension_GetDocumentNode( |
| 44 CFDE_XMLDoc* pXMLDoc, | 47 CFDE_XMLDoc* pXMLDoc, |
| 45 FX_BOOL bVerifyWellFormness = FALSE) { | 48 FX_BOOL bVerifyWellFormness = FALSE) { |
| 46 if (!pXMLDoc) { | 49 if (!pXMLDoc) { |
| 47 return NULL; | 50 return NULL; |
| 48 } | 51 } |
| 49 CFDE_XMLNode* pXMLFakeRoot = pXMLDoc->GetRoot(); | 52 CFDE_XMLNode* pXMLFakeRoot = pXMLDoc->GetRoot(); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 m_pRootNode = DataLoader(pXFANode, pXMLNode, TRUE); | 187 m_pRootNode = DataLoader(pXFANode, pXMLNode, TRUE); |
| 185 } | 188 } |
| 186 } else if (pXFANode->GetObjectType() == XFA_OBJECTTYPE_ContentNode) { | 189 } else if (pXFANode->GetObjectType() == XFA_OBJECTTYPE_ContentNode) { |
| 187 ParseContentNode(pXFANode, pXMLNode, ePacketID); | 190 ParseContentNode(pXFANode, pXMLNode, ePacketID); |
| 188 m_pRootNode = pXFANode; | 191 m_pRootNode = pXFANode; |
| 189 } else { | 192 } else { |
| 190 m_pRootNode = NormalLoader(pXFANode, pXMLNode, ePacketID); | 193 m_pRootNode = NormalLoader(pXFANode, pXMLNode, ePacketID); |
| 191 } | 194 } |
| 192 } | 195 } |
| 193 | 196 |
| 197 CXFA_Document* CXFA_SimpleParser::GetFactory() const { |
| 198 return m_pFactory; |
| 199 } |
| 200 |
| 201 CXFA_Node* CXFA_SimpleParser::GetRootNode() const { |
| 202 return m_pRootNode; |
| 203 } |
| 204 |
| 205 CFDE_XMLDoc* CXFA_SimpleParser::GetXMLDoc() const { |
| 206 return m_pXMLDoc; |
| 207 } |
| 208 |
| 194 FX_BOOL XFA_FDEExtension_ResolveNamespaceQualifier( | 209 FX_BOOL XFA_FDEExtension_ResolveNamespaceQualifier( |
| 195 CFDE_XMLElement* pNode, | 210 CFDE_XMLElement* pNode, |
| 196 const CFX_WideStringC& wsQualifier, | 211 const CFX_WideStringC& wsQualifier, |
| 197 CFX_WideString& wsNamespaceURI) { | 212 CFX_WideString& wsNamespaceURI) { |
| 198 if (!pNode) { | 213 if (!pNode) { |
| 199 return FALSE; | 214 return FALSE; |
| 200 } | 215 } |
| 201 CFDE_XMLNode* pFakeRoot = pNode->GetNodeItem(CFDE_XMLNode::Root); | 216 CFDE_XMLNode* pFakeRoot = pNode->GetNodeItem(CFDE_XMLNode::Root); |
| 202 CFX_WideString wsNSAttribute; | 217 CFX_WideString wsNSAttribute; |
| 203 FX_BOOL bRet = FALSE; | 218 FX_BOOL bRet = FALSE; |
| (...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1340 m_pStream->Release(); | 1355 m_pStream->Release(); |
| 1341 m_pStream = NULL; | 1356 m_pStream = NULL; |
| 1342 } | 1357 } |
| 1343 } | 1358 } |
| 1344 | 1359 |
| 1345 CXFA_DocumentParser::CXFA_DocumentParser(CXFA_FFNotify* pNotify) | 1360 CXFA_DocumentParser::CXFA_DocumentParser(CXFA_FFNotify* pNotify) |
| 1346 : m_nodeParser(NULL, TRUE), m_pNotify(pNotify), m_pDocument(NULL) {} | 1361 : m_nodeParser(NULL, TRUE), m_pNotify(pNotify), m_pDocument(NULL) {} |
| 1347 CXFA_DocumentParser::~CXFA_DocumentParser() { | 1362 CXFA_DocumentParser::~CXFA_DocumentParser() { |
| 1348 CloseParser(); | 1363 CloseParser(); |
| 1349 } | 1364 } |
| 1365 |
| 1366 void CXFA_DocumentParser::Release() { |
| 1367 delete this; |
| 1368 } |
| 1350 int32_t CXFA_DocumentParser::StartParse(IFX_FileRead* pStream, | 1369 int32_t CXFA_DocumentParser::StartParse(IFX_FileRead* pStream, |
| 1351 XFA_XDPPACKET ePacketID) { | 1370 XFA_XDPPACKET ePacketID) { |
| 1352 CloseParser(); | 1371 CloseParser(); |
| 1353 int32_t nRetStatus = m_nodeParser.StartParse(pStream, ePacketID); | 1372 int32_t nRetStatus = m_nodeParser.StartParse(pStream, ePacketID); |
| 1354 if (nRetStatus == XFA_PARSESTATUS_Ready) { | 1373 if (nRetStatus == XFA_PARSESTATUS_Ready) { |
| 1355 m_pDocument = new CXFA_Document(this); | 1374 m_pDocument = new CXFA_Document(this); |
| 1356 m_nodeParser.SetFactory(m_pDocument); | 1375 m_nodeParser.SetFactory(m_pDocument); |
| 1357 } | 1376 } |
| 1358 return nRetStatus; | 1377 return nRetStatus; |
| 1359 } | 1378 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1381 if (!pXFANode || !pXMLNode) { | 1400 if (!pXFANode || !pXMLNode) { |
| 1382 return; | 1401 return; |
| 1383 } | 1402 } |
| 1384 m_nodeParser.ConstructXFANode(pXFANode, pXMLNode); | 1403 m_nodeParser.ConstructXFANode(pXFANode, pXMLNode); |
| 1385 CXFA_Node* pRootNode = m_nodeParser.GetRootNode(); | 1404 CXFA_Node* pRootNode = m_nodeParser.GetRootNode(); |
| 1386 if (m_pDocument && pRootNode) { | 1405 if (m_pDocument && pRootNode) { |
| 1387 m_pDocument->SetRoot(pRootNode); | 1406 m_pDocument->SetRoot(pRootNode); |
| 1388 } | 1407 } |
| 1389 } | 1408 } |
| 1390 | 1409 |
| 1410 CXFA_Document* CXFA_DocumentParser::GetFactory() const { |
| 1411 return m_nodeParser.GetFactory(); |
| 1412 } |
| 1413 |
| 1414 CXFA_Node* CXFA_DocumentParser::GetRootNode() const { |
| 1415 return m_nodeParser.GetRootNode(); |
| 1416 } |
| 1417 |
| 1418 CFDE_XMLDoc* CXFA_DocumentParser::GetXMLDoc() const { |
| 1419 return m_nodeParser.GetXMLDoc(); |
| 1420 } |
| 1421 |
| 1422 CXFA_FFNotify* CXFA_DocumentParser::GetNotify() const { |
| 1423 return m_pNotify; |
| 1424 } |
| 1425 |
| 1426 CXFA_Document* CXFA_DocumentParser::GetDocument() const { |
| 1427 return m_pDocument; |
| 1428 } |
| 1429 |
| 1391 void CXFA_DocumentParser::CloseParser() { | 1430 void CXFA_DocumentParser::CloseParser() { |
| 1392 delete m_pDocument; | 1431 delete m_pDocument; |
| 1393 m_pDocument = nullptr; | 1432 m_pDocument = nullptr; |
| 1394 m_nodeParser.CloseParser(); | 1433 m_nodeParser.CloseParser(); |
| 1395 } | 1434 } |
| 1396 | 1435 |
| 1397 CXFA_XMLParser::CXFA_XMLParser(CFDE_XMLNode* pRoot, IFX_Stream* pStream) | 1436 CXFA_XMLParser::CXFA_XMLParser(CFDE_XMLNode* pRoot, IFX_Stream* pStream) |
| 1398 : m_nElementStart(0), | 1437 : m_nElementStart(0), |
| 1399 m_dwCheckStatus(0), | 1438 m_dwCheckStatus(0), |
| 1400 m_dwCurrentCheckStatus(0), | 1439 m_dwCurrentCheckStatus(0), |
| 1401 m_pRoot(pRoot), | 1440 m_pRoot(pRoot), |
| 1402 m_pStream(pStream), | 1441 m_pStream(pStream), |
| 1403 m_pParser(nullptr), | 1442 m_pParser(nullptr), |
| 1404 m_pParent(pRoot), | 1443 m_pParent(pRoot), |
| 1405 m_pChild(nullptr), | 1444 m_pChild(nullptr), |
| 1406 m_NodeStack(16), | 1445 m_NodeStack(16), |
| 1407 m_syntaxParserResult(FDE_XmlSyntaxResult::None) { | 1446 m_syntaxParserResult(FDE_XmlSyntaxResult::None) { |
| 1408 ASSERT(m_pParent && m_pStream); | 1447 ASSERT(m_pParent && m_pStream); |
| 1409 m_NodeStack.Push(m_pParent); | 1448 m_NodeStack.Push(m_pParent); |
| 1410 m_pParser = new CFDE_XMLSyntaxParser; | 1449 m_pParser = new CFDE_XMLSyntaxParser; |
| 1411 m_pParser->Init(m_pStream, 32 * 1024, 1024 * 1024); | 1450 m_pParser->Init(m_pStream, 32 * 1024, 1024 * 1024); |
| 1412 } | 1451 } |
| 1452 |
| 1413 CXFA_XMLParser::~CXFA_XMLParser() { | 1453 CXFA_XMLParser::~CXFA_XMLParser() { |
| 1414 if (m_pParser) { | 1454 if (m_pParser) { |
| 1415 m_pParser->Release(); | 1455 m_pParser->Release(); |
| 1416 } | 1456 } |
| 1417 m_NodeStack.RemoveAll(); | 1457 m_NodeStack.RemoveAll(); |
| 1418 m_ws1.clear(); | 1458 m_ws1.clear(); |
| 1419 m_ws2.clear(); | 1459 m_ws2.clear(); |
| 1420 } | 1460 } |
| 1461 |
| 1462 void CXFA_XMLParser::Release() { |
| 1463 delete this; |
| 1464 } |
| 1465 |
| 1421 int32_t CXFA_XMLParser::DoParser(IFX_Pause* pPause) { | 1466 int32_t CXFA_XMLParser::DoParser(IFX_Pause* pPause) { |
| 1422 if (m_syntaxParserResult == FDE_XmlSyntaxResult::Error) | 1467 if (m_syntaxParserResult == FDE_XmlSyntaxResult::Error) |
| 1423 return -1; | 1468 return -1; |
| 1424 if (m_syntaxParserResult == FDE_XmlSyntaxResult::EndOfString) | 1469 if (m_syntaxParserResult == FDE_XmlSyntaxResult::EndOfString) |
| 1425 return 100; | 1470 return 100; |
| 1426 | 1471 |
| 1427 int32_t iCount = 0; | 1472 int32_t iCount = 0; |
| 1428 while (TRUE) { | 1473 while (TRUE) { |
| 1429 m_syntaxParserResult = m_pParser->DoSyntaxParse(); | 1474 m_syntaxParserResult = m_pParser->DoSyntaxParse(); |
| 1430 switch (m_syntaxParserResult) { | 1475 switch (m_syntaxParserResult) { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1553 } | 1598 } |
| 1554 if (pPause && iCount > 500 && pPause->NeedToPauseNow()) { | 1599 if (pPause && iCount > 500 && pPause->NeedToPauseNow()) { |
| 1555 break; | 1600 break; |
| 1556 } | 1601 } |
| 1557 } | 1602 } |
| 1558 return (m_syntaxParserResult == FDE_XmlSyntaxResult::Error || | 1603 return (m_syntaxParserResult == FDE_XmlSyntaxResult::Error || |
| 1559 m_NodeStack.GetSize() != 1) | 1604 m_NodeStack.GetSize() != 1) |
| 1560 ? -1 | 1605 ? -1 |
| 1561 : m_pParser->GetStatus(); | 1606 : m_pParser->GetStatus(); |
| 1562 } | 1607 } |
| OLD | NEW |