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/include/xfa_ffdoc.h" | 7 #include "xfa/fxfa/include/xfa_ffdoc.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | |
11 | 10 |
12 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
13 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
14 #include "core/fpdfdoc/include/fpdf_doc.h" | 13 #include "core/fpdfdoc/include/fpdf_doc.h" |
15 #include "core/fxcrt/include/fx_ext.h" | 14 #include "core/fxcrt/include/fx_ext.h" |
16 #include "core/fxcrt/include/fx_memory.h" | 15 #include "core/fxcrt/include/fx_memory.h" |
17 #include "xfa/fde/xml/fde_xml_imp.h" | 16 #include "xfa/fde/xml/fde_xml_imp.h" |
18 #include "xfa/fgas/crt/fgas_algorithm.h" | 17 #include "xfa/fgas/crt/fgas_algorithm.h" |
19 #include "xfa/fwl/core/fwl_noteimp.h" | 18 #include "xfa/fwl/core/fwl_noteimp.h" |
20 #include "xfa/fxfa/app/xfa_ffnotify.h" | 19 #include "xfa/fxfa/app/xfa_ffnotify.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 } | 138 } |
140 if (!pXFAReader) { | 139 if (!pXFAReader) { |
141 return XFA_PARSESTATUS_SyntaxErr; | 140 return XFA_PARSESTATUS_SyntaxErr; |
142 } | 141 } |
143 CPDF_Document* pPDFDocument = | 142 CPDF_Document* pPDFDocument = |
144 GetDocProvider()->OpenPDF(this, pXFAReader, TRUE); | 143 GetDocProvider()->OpenPDF(this, pXFAReader, TRUE); |
145 ASSERT(!m_pPDFDoc); | 144 ASSERT(!m_pPDFDoc); |
146 if (!OpenDoc(pPDFDocument)) { | 145 if (!OpenDoc(pPDFDocument)) { |
147 return XFA_PARSESTATUS_SyntaxErr; | 146 return XFA_PARSESTATUS_SyntaxErr; |
148 } | 147 } |
149 std::unique_ptr<IXFA_Parser> pParser( | 148 IXFA_Parser* pParser = IXFA_Parser::Create(m_pDocument, TRUE); |
150 IXFA_Parser::Create(m_pDocument, TRUE)); | 149 if (!pParser) { |
151 if (!pParser) | |
152 return XFA_PARSESTATUS_SyntaxErr; | 150 return XFA_PARSESTATUS_SyntaxErr; |
153 | 151 } |
154 CXFA_Node* pRootNode = NULL; | 152 CXFA_Node* pRootNode = NULL; |
155 if (pParser->StartParse(m_pStream) == XFA_PARSESTATUS_Ready && | 153 if (pParser->StartParse(m_pStream) == XFA_PARSESTATUS_Ready && |
156 pParser->DoParse(NULL) == XFA_PARSESTATUS_Done) { | 154 pParser->DoParse(NULL) == XFA_PARSESTATUS_Done) { |
157 pRootNode = pParser->GetRootNode(); | 155 pRootNode = pParser->GetRootNode(); |
158 } | 156 } |
159 if (pRootNode && m_pDocument->GetRoot()) { | 157 if (pRootNode && m_pDocument->GetRoot()) { |
160 XFA_XPDPacket_MergeRootNode(m_pDocument->GetRoot(), pRootNode); | 158 XFA_XPDPacket_MergeRootNode(m_pDocument->GetRoot(), pRootNode); |
161 iStatus = XFA_PARSESTATUS_Done; | 159 iStatus = XFA_PARSESTATUS_Done; |
162 } else { | 160 } else { |
163 iStatus = XFA_PARSESTATUS_StatusErr; | 161 iStatus = XFA_PARSESTATUS_StatusErr; |
164 } | 162 } |
| 163 pParser->Release(); |
| 164 pParser = NULL; |
165 } | 165 } |
166 return iStatus; | 166 return iStatus; |
167 } | 167 } |
168 void CXFA_FFDoc::StopLoad() { | 168 void CXFA_FFDoc::StopLoad() { |
169 m_pApp->GetXFAFontMgr()->LoadDocFonts(this); | 169 m_pApp->GetXFAFontMgr()->LoadDocFonts(this); |
170 m_dwDocType = XFA_DOCTYPE_Static; | 170 m_dwDocType = XFA_DOCTYPE_Static; |
171 CXFA_Node* pConfig = ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config)); | 171 CXFA_Node* pConfig = ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config)); |
172 if (!pConfig) { | 172 if (!pConfig) { |
173 return; | 173 return; |
174 } | 174 } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 FX_BOOL CXFA_FFDoc::CloseDoc() { | 258 FX_BOOL CXFA_FFDoc::CloseDoc() { |
259 for (const auto& pair : m_TypeToDocViewMap) | 259 for (const auto& pair : m_TypeToDocViewMap) |
260 pair.second->RunDocClose(); | 260 pair.second->RunDocClose(); |
261 | 261 |
262 if (m_pDocument) | 262 if (m_pDocument) |
263 m_pDocument->ClearLayoutData(); | 263 m_pDocument->ClearLayoutData(); |
264 | 264 |
265 m_TypeToDocViewMap.clear(); | 265 m_TypeToDocViewMap.clear(); |
266 | 266 |
267 if (m_pDocument) { | 267 if (m_pDocument) { |
268 m_pDocument->DestroyParser(); | 268 m_pDocument->GetParser()->Release(); |
269 m_pDocument = nullptr; | 269 m_pDocument = nullptr; |
270 } | 270 } |
271 | 271 |
272 delete m_pNotify; | 272 delete m_pNotify; |
273 m_pNotify = nullptr; | 273 m_pNotify = nullptr; |
274 | 274 |
275 m_pApp->GetXFAFontMgr()->ReleaseDocFonts(this); | 275 m_pApp->GetXFAFontMgr()->ReleaseDocFonts(this); |
276 | 276 |
277 if (m_dwDocType != XFA_DOCTYPE_XDP && m_pStream && m_bOwnStream) { | 277 if (m_dwDocType != XFA_DOCTYPE_XDP && m_pStream && m_bOwnStream) { |
278 m_pStream->Release(); | 278 m_pStream->Release(); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 } | 386 } |
387 pExport->Release(); | 387 pExport->Release(); |
388 return bFlags; | 388 return bFlags; |
389 } | 389 } |
390 FX_BOOL CXFA_FFDoc::ImportData(IFX_FileRead* pStream, FX_BOOL bXDP) { | 390 FX_BOOL CXFA_FFDoc::ImportData(IFX_FileRead* pStream, FX_BOOL bXDP) { |
391 std::unique_ptr<CXFA_DataImporter, ReleaseDeleter<CXFA_DataImporter>> | 391 std::unique_ptr<CXFA_DataImporter, ReleaseDeleter<CXFA_DataImporter>> |
392 importer(new CXFA_DataImporter(m_pDocument)); | 392 importer(new CXFA_DataImporter(m_pDocument)); |
393 | 393 |
394 return importer->ImportData(pStream); | 394 return importer->ImportData(pStream); |
395 } | 395 } |
OLD | NEW |