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 <utility> |
| 10 |
9 #include "core/fxcrt/fx_ext.h" | 11 #include "core/fxcrt/fx_ext.h" |
10 #include "third_party/base/ptr_util.h" | 12 #include "third_party/base/ptr_util.h" |
11 #include "xfa/fgas/crt/fgas_codepage.h" | 13 #include "xfa/fgas/crt/fgas_codepage.h" |
12 #include "xfa/fxfa/fxfa.h" | 14 #include "xfa/fxfa/fxfa.h" |
13 #include "xfa/fxfa/parser/cxfa_document.h" | 15 #include "xfa/fxfa/parser/cxfa_document.h" |
14 #include "xfa/fxfa/parser/cxfa_widetextread.h" | 16 #include "xfa/fxfa/parser/cxfa_widetextread.h" |
15 #include "xfa/fxfa/parser/cxfa_xml_parser.h" | 17 #include "xfa/fxfa/parser/cxfa_xml_parser.h" |
16 #include "xfa/fxfa/parser/xfa_basic_data.h" | 18 #include "xfa/fxfa/parser/xfa_basic_data.h" |
17 #include "xfa/fxfa/parser/xfa_utils.h" | 19 #include "xfa/fxfa/parser/xfa_utils.h" |
18 #include "xfa/fxfa/xfa_checksum.h" | 20 #include "xfa/fxfa/xfa_checksum.h" |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 m_pStream = IFGAS_Stream::CreateStream( | 288 m_pStream = IFGAS_Stream::CreateStream( |
287 pStream, FX_STREAMACCESS_Read | FX_STREAMACCESS_Text); | 289 pStream, FX_STREAMACCESS_Read | FX_STREAMACCESS_Text); |
288 if (!m_pStream) | 290 if (!m_pStream) |
289 return XFA_PARSESTATUS_StreamErr; | 291 return XFA_PARSESTATUS_StreamErr; |
290 | 292 |
291 uint16_t wCodePage = m_pStream->GetCodePage(); | 293 uint16_t wCodePage = m_pStream->GetCodePage(); |
292 if (wCodePage != FX_CODEPAGE_UTF16LE && wCodePage != FX_CODEPAGE_UTF16BE && | 294 if (wCodePage != FX_CODEPAGE_UTF16LE && wCodePage != FX_CODEPAGE_UTF16BE && |
293 wCodePage != FX_CODEPAGE_UTF8) { | 295 wCodePage != FX_CODEPAGE_UTF8) { |
294 m_pStream->SetCodePage(FX_CODEPAGE_UTF8); | 296 m_pStream->SetCodePage(FX_CODEPAGE_UTF8); |
295 } | 297 } |
296 m_pXMLDoc.reset(new CFDE_XMLDoc); | 298 m_pXMLDoc = pdfium::MakeUnique<CFDE_XMLDoc>(); |
297 m_pXMLParser = new CXFA_XMLParser(m_pXMLDoc->GetRoot(), m_pStream); | 299 auto pNewParser = |
298 if (!m_pXMLDoc->LoadXML(m_pXMLParser)) | 300 pdfium::MakeUnique<CXFA_XMLParser>(m_pXMLDoc->GetRoot(), m_pStream); |
| 301 m_pXMLParser = pNewParser.get(); |
| 302 if (!m_pXMLDoc->LoadXML(std::move(pNewParser))) |
299 return XFA_PARSESTATUS_StatusErr; | 303 return XFA_PARSESTATUS_StatusErr; |
300 | 304 |
301 m_ePacketID = ePacketID; | 305 m_ePacketID = ePacketID; |
302 return XFA_PARSESTATUS_Ready; | 306 return XFA_PARSESTATUS_Ready; |
303 } | 307 } |
304 | 308 |
305 int32_t CXFA_SimpleParser::DoParse(IFX_Pause* pPause) { | 309 int32_t CXFA_SimpleParser::DoParse(IFX_Pause* pPause) { |
306 if (!m_pXMLDoc || m_ePacketID == XFA_XDPPACKET_UNKNOWN) | 310 if (!m_pXMLDoc || m_ePacketID == XFA_XDPPACKET_UNKNOWN) |
307 return XFA_PARSESTATUS_StatusErr; | 311 return XFA_PARSESTATUS_StatusErr; |
308 | 312 |
(...skipping 10 matching lines...) Expand all Loading... |
319 return XFA_PARSESTATUS_StatusErr; | 323 return XFA_PARSESTATUS_StatusErr; |
320 | 324 |
321 return XFA_PARSESTATUS_Done; | 325 return XFA_PARSESTATUS_Done; |
322 } | 326 } |
323 | 327 |
324 int32_t CXFA_SimpleParser::ParseXMLData(const CFX_WideString& wsXML, | 328 int32_t CXFA_SimpleParser::ParseXMLData(const CFX_WideString& wsXML, |
325 CFDE_XMLNode*& pXMLNode, | 329 CFDE_XMLNode*& pXMLNode, |
326 IFX_Pause* pPause) { | 330 IFX_Pause* pPause) { |
327 CloseParser(); | 331 CloseParser(); |
328 pXMLNode = nullptr; | 332 pXMLNode = nullptr; |
329 | 333 m_pXMLDoc = pdfium::MakeUnique<CFDE_XMLDoc>(); |
330 auto pStream = pdfium::MakeRetain<CXFA_WideTextRead>(wsXML); | 334 auto pStream = pdfium::MakeRetain<CXFA_WideTextRead>(wsXML); |
331 m_pXMLDoc = pdfium::MakeUnique<CFDE_XMLDoc>(); | 335 auto pParser = |
332 CXFA_XMLParser* pParser = new CXFA_XMLParser(m_pXMLDoc->GetRoot(), pStream); | 336 pdfium::MakeUnique<CXFA_XMLParser>(m_pXMLDoc->GetRoot(), pStream); |
333 pParser->m_dwCheckStatus = 0x03; | 337 pParser->m_dwCheckStatus = 0x03; |
334 if (!m_pXMLDoc->LoadXML(pParser)) | 338 if (!m_pXMLDoc->LoadXML(std::move(pParser))) |
335 return XFA_PARSESTATUS_StatusErr; | 339 return XFA_PARSESTATUS_StatusErr; |
336 | 340 |
337 int32_t iRet = m_pXMLDoc->DoLoad(pPause); | 341 int32_t iRet = m_pXMLDoc->DoLoad(pPause); |
338 if (iRet < 0 || iRet >= 100) | 342 if (iRet < 0 || iRet >= 100) |
339 m_pXMLDoc->CloseXML(); | 343 m_pXMLDoc->CloseXML(); |
340 if (iRet < 0) | 344 if (iRet < 0) |
341 return XFA_PARSESTATUS_SyntaxErr; | 345 return XFA_PARSESTATUS_SyntaxErr; |
342 if (iRet < 100) | 346 if (iRet < 100) |
343 return iRet / 2; | 347 return iRet / 2; |
344 | 348 |
(...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1301 pXFANode->GetDocument()->SetFlag(XFA_DOCFLAG_StrictScoping, true); | 1305 pXFANode->GetDocument()->SetFlag(XFA_DOCFLAG_StrictScoping, true); |
1302 } | 1306 } |
1303 } | 1307 } |
1304 } | 1308 } |
1305 } | 1309 } |
1306 | 1310 |
1307 void CXFA_SimpleParser::CloseParser() { | 1311 void CXFA_SimpleParser::CloseParser() { |
1308 m_pXMLDoc.reset(); | 1312 m_pXMLDoc.reset(); |
1309 m_pStream.Reset(); | 1313 m_pStream.Reset(); |
1310 } | 1314 } |
OLD | NEW |