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 "core/fxcrt/fx_ext.h" | 9 #include "core/fxcrt/fx_ext.h" |
| 10 #include "third_party/base/ptr_util.h" |
10 #include "xfa/fgas/crt/fgas_codepage.h" | 11 #include "xfa/fgas/crt/fgas_codepage.h" |
11 #include "xfa/fxfa/fxfa.h" | 12 #include "xfa/fxfa/fxfa.h" |
12 #include "xfa/fxfa/parser/cxfa_document.h" | 13 #include "xfa/fxfa/parser/cxfa_document.h" |
13 #include "xfa/fxfa/parser/cxfa_widetextread.h" | 14 #include "xfa/fxfa/parser/cxfa_widetextread.h" |
14 #include "xfa/fxfa/parser/cxfa_xml_parser.h" | 15 #include "xfa/fxfa/parser/cxfa_xml_parser.h" |
15 #include "xfa/fxfa/parser/xfa_basic_data.h" | 16 #include "xfa/fxfa/parser/xfa_basic_data.h" |
16 #include "xfa/fxfa/parser/xfa_utils.h" | 17 #include "xfa/fxfa/parser/xfa_utils.h" |
17 #include "xfa/fxfa/xfa_checksum.h" | 18 #include "xfa/fxfa/xfa_checksum.h" |
18 | 19 |
19 namespace { | 20 namespace { |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 | 276 |
276 void CXFA_SimpleParser::SetFactory(CXFA_Document* pFactory) { | 277 void CXFA_SimpleParser::SetFactory(CXFA_Document* pFactory) { |
277 m_pFactory = pFactory; | 278 m_pFactory = pFactory; |
278 } | 279 } |
279 | 280 |
280 int32_t CXFA_SimpleParser::StartParse( | 281 int32_t CXFA_SimpleParser::StartParse( |
281 const CFX_RetainPtr<IFX_SeekableReadStream>& pStream, | 282 const CFX_RetainPtr<IFX_SeekableReadStream>& pStream, |
282 XFA_XDPPACKET ePacketID) { | 283 XFA_XDPPACKET ePacketID) { |
283 CloseParser(); | 284 CloseParser(); |
284 m_pFileRead = pStream; | 285 m_pFileRead = pStream; |
285 m_pStream.reset(IFGAS_Stream::CreateStream( | 286 m_pStream = IFGAS_Stream::CreateStream( |
286 pStream, FX_STREAMACCESS_Read | FX_STREAMACCESS_Text)); | 287 pStream, FX_STREAMACCESS_Read | FX_STREAMACCESS_Text); |
287 if (!m_pStream) | 288 if (!m_pStream) |
288 return XFA_PARSESTATUS_StreamErr; | 289 return XFA_PARSESTATUS_StreamErr; |
289 | 290 |
290 uint16_t wCodePage = m_pStream->GetCodePage(); | 291 uint16_t wCodePage = m_pStream->GetCodePage(); |
291 if (wCodePage != FX_CODEPAGE_UTF16LE && wCodePage != FX_CODEPAGE_UTF16BE && | 292 if (wCodePage != FX_CODEPAGE_UTF16LE && wCodePage != FX_CODEPAGE_UTF16BE && |
292 wCodePage != FX_CODEPAGE_UTF8) { | 293 wCodePage != FX_CODEPAGE_UTF8) { |
293 m_pStream->SetCodePage(FX_CODEPAGE_UTF8); | 294 m_pStream->SetCodePage(FX_CODEPAGE_UTF8); |
294 } | 295 } |
295 m_pXMLDoc.reset(new CFDE_XMLDoc); | 296 m_pXMLDoc.reset(new CFDE_XMLDoc); |
296 m_pXMLParser = new CXFA_XMLParser(m_pXMLDoc->GetRoot(), m_pStream.get()); | 297 m_pXMLParser = new CXFA_XMLParser(m_pXMLDoc->GetRoot(), m_pStream); |
297 if (!m_pXMLDoc->LoadXML(m_pXMLParser)) | 298 if (!m_pXMLDoc->LoadXML(m_pXMLParser)) |
298 return XFA_PARSESTATUS_StatusErr; | 299 return XFA_PARSESTATUS_StatusErr; |
299 | 300 |
300 m_ePacketID = ePacketID; | 301 m_ePacketID = ePacketID; |
301 return XFA_PARSESTATUS_Ready; | 302 return XFA_PARSESTATUS_Ready; |
302 } | 303 } |
303 | 304 |
304 int32_t CXFA_SimpleParser::DoParse(IFX_Pause* pPause) { | 305 int32_t CXFA_SimpleParser::DoParse(IFX_Pause* pPause) { |
305 if (!m_pXMLDoc || m_ePacketID == XFA_XDPPACKET_UNKNOWN) | 306 if (!m_pXMLDoc || m_ePacketID == XFA_XDPPACKET_UNKNOWN) |
306 return XFA_PARSESTATUS_StatusErr; | 307 return XFA_PARSESTATUS_StatusErr; |
307 | 308 |
308 int32_t iRet = m_pXMLDoc->DoLoad(pPause); | 309 int32_t iRet = m_pXMLDoc->DoLoad(pPause); |
309 if (iRet < 0) | 310 if (iRet < 0) |
310 return XFA_PARSESTATUS_SyntaxErr; | 311 return XFA_PARSESTATUS_SyntaxErr; |
311 if (iRet < 100) | 312 if (iRet < 100) |
312 return iRet / 2; | 313 return iRet / 2; |
313 | 314 |
314 m_pRootNode = ParseAsXDPPacket(GetDocumentNode(m_pXMLDoc.get()), m_ePacketID); | 315 m_pRootNode = ParseAsXDPPacket(GetDocumentNode(m_pXMLDoc.get()), m_ePacketID); |
315 m_pXMLDoc->CloseXML(); | 316 m_pXMLDoc->CloseXML(); |
316 m_pStream.reset(); | 317 m_pStream.Reset(); |
317 | |
318 if (!m_pRootNode) | 318 if (!m_pRootNode) |
319 return XFA_PARSESTATUS_StatusErr; | 319 return XFA_PARSESTATUS_StatusErr; |
| 320 |
320 return XFA_PARSESTATUS_Done; | 321 return XFA_PARSESTATUS_Done; |
321 } | 322 } |
322 | 323 |
323 int32_t CXFA_SimpleParser::ParseXMLData(const CFX_WideString& wsXML, | 324 int32_t CXFA_SimpleParser::ParseXMLData(const CFX_WideString& wsXML, |
324 CFDE_XMLNode*& pXMLNode, | 325 CFDE_XMLNode*& pXMLNode, |
325 IFX_Pause* pPause) { | 326 IFX_Pause* pPause) { |
326 CloseParser(); | 327 CloseParser(); |
327 pXMLNode = nullptr; | 328 pXMLNode = nullptr; |
328 | 329 |
329 std::unique_ptr<IFGAS_Stream> pStream(new CXFA_WideTextRead(wsXML)); | 330 auto pStream = pdfium::MakeRetain<CXFA_WideTextRead>(wsXML); |
330 m_pXMLDoc.reset(new CFDE_XMLDoc); | 331 m_pXMLDoc = pdfium::MakeUnique<CFDE_XMLDoc>(); |
331 CXFA_XMLParser* pParser = | 332 CXFA_XMLParser* pParser = new CXFA_XMLParser(m_pXMLDoc->GetRoot(), pStream); |
332 new CXFA_XMLParser(m_pXMLDoc->GetRoot(), pStream.get()); | |
333 pParser->m_dwCheckStatus = 0x03; | 333 pParser->m_dwCheckStatus = 0x03; |
334 if (!m_pXMLDoc->LoadXML(pParser)) | 334 if (!m_pXMLDoc->LoadXML(pParser)) |
335 return XFA_PARSESTATUS_StatusErr; | 335 return XFA_PARSESTATUS_StatusErr; |
336 | 336 |
337 int32_t iRet = m_pXMLDoc->DoLoad(pPause); | 337 int32_t iRet = m_pXMLDoc->DoLoad(pPause); |
338 if (iRet < 0 || iRet >= 100) | 338 if (iRet < 0 || iRet >= 100) |
339 m_pXMLDoc->CloseXML(); | 339 m_pXMLDoc->CloseXML(); |
340 if (iRet < 0) | 340 if (iRet < 0) |
341 return XFA_PARSESTATUS_SyntaxErr; | 341 return XFA_PARSESTATUS_SyntaxErr; |
342 if (iRet < 100) | 342 if (iRet < 100) |
(...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1299 if (pXMLInstruction->GetData(1, wsData) && | 1299 if (pXMLInstruction->GetData(1, wsData) && |
1300 wsData == FX_WSTRC(L"strictScoping")) { | 1300 wsData == FX_WSTRC(L"strictScoping")) { |
1301 pXFANode->GetDocument()->SetFlag(XFA_DOCFLAG_StrictScoping, true); | 1301 pXFANode->GetDocument()->SetFlag(XFA_DOCFLAG_StrictScoping, true); |
1302 } | 1302 } |
1303 } | 1303 } |
1304 } | 1304 } |
1305 } | 1305 } |
1306 | 1306 |
1307 void CXFA_SimpleParser::CloseParser() { | 1307 void CXFA_SimpleParser::CloseParser() { |
1308 m_pXMLDoc.reset(); | 1308 m_pXMLDoc.reset(); |
1309 m_pStream.reset(); | 1309 m_pStream.Reset(); |
1310 } | 1310 } |
OLD | NEW |