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 "xfa/fde/xml/fde_xml_imp.h" | 9 #include "xfa/fde/xml/fde_xml_imp.h" |
10 #include "xfa/fgas/crt/fgas_codepage.h" | 10 #include "xfa/fgas/crt/fgas_codepage.h" |
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 static_cast<CFDE_XMLElement*>(pXMLDocumentNode) | 673 static_cast<CFDE_XMLElement*>(pXMLDocumentNode) |
674 ->RemoveAttribute(L"xmlns:xfa"); | 674 ->RemoveAttribute(L"xmlns:xfa"); |
675 } | 675 } |
676 pDataElement->InsertChildNode(pXMLDocumentNode); | 676 pDataElement->InsertChildNode(pXMLDocumentNode); |
677 pDataXMLNode = pDataElement; | 677 pDataXMLNode = pDataElement; |
678 } | 678 } |
679 if (pDataXMLNode) { | 679 if (pDataXMLNode) { |
680 CXFA_Node* pNode = | 680 CXFA_Node* pNode = |
681 m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, XFA_ELEMENT_DataGroup); | 681 m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, XFA_ELEMENT_DataGroup); |
682 if (!pNode) { | 682 if (!pNode) { |
683 if (pDataXMLNode != pXMLDocumentNode) | 683 if (pDataXMLNode != pXMLDocumentNode) { |
684 delete pDataXMLNode; | 684 pDataXMLNode->Release(); |
685 return nullptr; | 685 } |
| 686 return NULL; |
686 } | 687 } |
687 CFX_WideString wsLocalName; | 688 CFX_WideString wsLocalName; |
688 static_cast<CFDE_XMLElement*>(pDataXMLNode)->GetLocalTagName(wsLocalName); | 689 static_cast<CFDE_XMLElement*>(pDataXMLNode)->GetLocalTagName(wsLocalName); |
689 pNode->SetCData(XFA_ATTRIBUTE_Name, wsLocalName); | 690 pNode->SetCData(XFA_ATTRIBUTE_Name, wsLocalName); |
690 if (!DataLoader(pNode, pDataXMLNode, TRUE)) { | 691 if (!DataLoader(pNode, pDataXMLNode, TRUE)) { |
691 return NULL; | 692 return NULL; |
692 } | 693 } |
693 pNode->SetXMLMappingNode(pDataXMLNode); | 694 pNode->SetXMLMappingNode(pDataXMLNode); |
694 if (pDataXMLNode != pXMLDocumentNode) { | 695 if (pDataXMLNode != pXMLDocumentNode) { |
695 pNode->SetFlag(XFA_NODEFLAG_OwnXMLNode, false); | 696 pNode->SetFlag(XFA_NODEFLAG_OwnXMLNode, false); |
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1327 if (pXMLInstruction->GetData(0, wsData) && | 1328 if (pXMLInstruction->GetData(0, wsData) && |
1328 wsData == FX_WSTRC(L"JavaScript")) { | 1329 wsData == FX_WSTRC(L"JavaScript")) { |
1329 if (pXMLInstruction->GetData(1, wsData) && | 1330 if (pXMLInstruction->GetData(1, wsData) && |
1330 wsData == FX_WSTRC(L"strictScoping")) { | 1331 wsData == FX_WSTRC(L"strictScoping")) { |
1331 pXFANode->GetDocument()->SetFlag(XFA_DOCFLAG_StrictScoping, TRUE); | 1332 pXFANode->GetDocument()->SetFlag(XFA_DOCFLAG_StrictScoping, TRUE); |
1332 } | 1333 } |
1333 } | 1334 } |
1334 } | 1335 } |
1335 } | 1336 } |
1336 void CXFA_SimpleParser::CloseParser() { | 1337 void CXFA_SimpleParser::CloseParser() { |
1337 delete m_pXMLDoc; | 1338 if (m_pXMLDoc) { |
1338 m_pXMLDoc = nullptr; | 1339 m_pXMLDoc->Release(); |
| 1340 m_pXMLDoc = NULL; |
| 1341 } |
1339 if (m_pStream) { | 1342 if (m_pStream) { |
1340 m_pStream->Release(); | 1343 m_pStream->Release(); |
1341 m_pStream = nullptr; | 1344 m_pStream = NULL; |
1342 } | 1345 } |
1343 } | 1346 } |
1344 | 1347 |
1345 CXFA_DocumentParser::CXFA_DocumentParser(CXFA_FFNotify* pNotify) | 1348 CXFA_DocumentParser::CXFA_DocumentParser(CXFA_FFNotify* pNotify) |
1346 : m_nodeParser(NULL, TRUE), m_pNotify(pNotify), m_pDocument(NULL) {} | 1349 : m_nodeParser(NULL, TRUE), m_pNotify(pNotify), m_pDocument(NULL) {} |
1347 CXFA_DocumentParser::~CXFA_DocumentParser() { | 1350 CXFA_DocumentParser::~CXFA_DocumentParser() { |
1348 CloseParser(); | 1351 CloseParser(); |
1349 } | 1352 } |
1350 int32_t CXFA_DocumentParser::StartParse(IFX_FileRead* pStream, | 1353 int32_t CXFA_DocumentParser::StartParse(IFX_FileRead* pStream, |
1351 XFA_XDPPACKET ePacketID) { | 1354 XFA_XDPPACKET ePacketID) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1400 m_dwCurrentCheckStatus(0), | 1403 m_dwCurrentCheckStatus(0), |
1401 m_pRoot(pRoot), | 1404 m_pRoot(pRoot), |
1402 m_pStream(pStream), | 1405 m_pStream(pStream), |
1403 m_pParser(nullptr), | 1406 m_pParser(nullptr), |
1404 m_pParent(pRoot), | 1407 m_pParent(pRoot), |
1405 m_pChild(nullptr), | 1408 m_pChild(nullptr), |
1406 m_NodeStack(16), | 1409 m_NodeStack(16), |
1407 m_syntaxParserResult(FDE_XmlSyntaxResult::None) { | 1410 m_syntaxParserResult(FDE_XmlSyntaxResult::None) { |
1408 ASSERT(m_pParent && m_pStream); | 1411 ASSERT(m_pParent && m_pStream); |
1409 m_NodeStack.Push(m_pParent); | 1412 m_NodeStack.Push(m_pParent); |
1410 m_pParser.reset(new CFDE_XMLSyntaxParser); | 1413 m_pParser = new CFDE_XMLSyntaxParser; |
1411 m_pParser->Init(m_pStream, 32 * 1024, 1024 * 1024); | 1414 m_pParser->Init(m_pStream, 32 * 1024, 1024 * 1024); |
1412 } | 1415 } |
1413 | |
1414 CXFA_XMLParser::~CXFA_XMLParser() { | 1416 CXFA_XMLParser::~CXFA_XMLParser() { |
| 1417 if (m_pParser) { |
| 1418 m_pParser->Release(); |
| 1419 } |
1415 m_NodeStack.RemoveAll(); | 1420 m_NodeStack.RemoveAll(); |
1416 m_ws1.clear(); | 1421 m_ws1.clear(); |
1417 m_ws2.clear(); | 1422 m_ws2.clear(); |
1418 } | 1423 } |
1419 | |
1420 int32_t CXFA_XMLParser::DoParser(IFX_Pause* pPause) { | 1424 int32_t CXFA_XMLParser::DoParser(IFX_Pause* pPause) { |
1421 if (m_syntaxParserResult == FDE_XmlSyntaxResult::Error) | 1425 if (m_syntaxParserResult == FDE_XmlSyntaxResult::Error) |
1422 return -1; | 1426 return -1; |
1423 if (m_syntaxParserResult == FDE_XmlSyntaxResult::EndOfString) | 1427 if (m_syntaxParserResult == FDE_XmlSyntaxResult::EndOfString) |
1424 return 100; | 1428 return 100; |
1425 | 1429 |
1426 int32_t iCount = 0; | 1430 int32_t iCount = 0; |
1427 while (TRUE) { | 1431 while (TRUE) { |
1428 m_syntaxParserResult = m_pParser->DoSyntaxParse(); | 1432 m_syntaxParserResult = m_pParser->DoSyntaxParse(); |
1429 switch (m_syntaxParserResult) { | 1433 switch (m_syntaxParserResult) { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1552 } | 1556 } |
1553 if (pPause && iCount > 500 && pPause->NeedToPauseNow()) { | 1557 if (pPause && iCount > 500 && pPause->NeedToPauseNow()) { |
1554 break; | 1558 break; |
1555 } | 1559 } |
1556 } | 1560 } |
1557 return (m_syntaxParserResult == FDE_XmlSyntaxResult::Error || | 1561 return (m_syntaxParserResult == FDE_XmlSyntaxResult::Error || |
1558 m_NodeStack.GetSize() != 1) | 1562 m_NodeStack.GetSize() != 1) |
1559 ? -1 | 1563 ? -1 |
1560 : m_pParser->GetStatus(); | 1564 : m_pParser->GetStatus(); |
1561 } | 1565 } |
OLD | NEW |