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> |
10 | 11 |
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
12 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
13 #include "core/fpdfdoc/include/fpdf_doc.h" | 14 #include "core/fpdfdoc/include/fpdf_doc.h" |
14 #include "core/fxcrt/include/fx_ext.h" | 15 #include "core/fxcrt/include/fx_ext.h" |
15 #include "core/fxcrt/include/fx_memory.h" | 16 #include "core/fxcrt/include/fx_memory.h" |
16 #include "xfa/fde/xml/fde_xml_imp.h" | 17 #include "xfa/fde/xml/fde_xml_imp.h" |
17 #include "xfa/fgas/crt/fgas_algorithm.h" | 18 #include "xfa/fgas/crt/fgas_algorithm.h" |
18 #include "xfa/fwl/core/fwl_noteimp.h" | 19 #include "xfa/fwl/core/fwl_noteimp.h" |
19 #include "xfa/fxfa/app/xfa_ffnotify.h" | 20 #include "xfa/fxfa/app/xfa_ffnotify.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 } | 139 } |
139 if (!pXFAReader) { | 140 if (!pXFAReader) { |
140 return XFA_PARSESTATUS_SyntaxErr; | 141 return XFA_PARSESTATUS_SyntaxErr; |
141 } | 142 } |
142 CPDF_Document* pPDFDocument = | 143 CPDF_Document* pPDFDocument = |
143 GetDocProvider()->OpenPDF(this, pXFAReader, TRUE); | 144 GetDocProvider()->OpenPDF(this, pXFAReader, TRUE); |
144 ASSERT(!m_pPDFDoc); | 145 ASSERT(!m_pPDFDoc); |
145 if (!OpenDoc(pPDFDocument)) { | 146 if (!OpenDoc(pPDFDocument)) { |
146 return XFA_PARSESTATUS_SyntaxErr; | 147 return XFA_PARSESTATUS_SyntaxErr; |
147 } | 148 } |
148 IXFA_Parser* pParser = IXFA_Parser::Create(m_pDocument, TRUE); | 149 std::unique_ptr<IXFA_Parser> pParser( |
149 if (!pParser) { | 150 IXFA_Parser::Create(m_pDocument, TRUE)); |
| 151 if (!pParser) |
150 return XFA_PARSESTATUS_SyntaxErr; | 152 return XFA_PARSESTATUS_SyntaxErr; |
151 } | 153 |
152 CXFA_Node* pRootNode = NULL; | 154 CXFA_Node* pRootNode = NULL; |
153 if (pParser->StartParse(m_pStream) == XFA_PARSESTATUS_Ready && | 155 if (pParser->StartParse(m_pStream) == XFA_PARSESTATUS_Ready && |
154 pParser->DoParse(NULL) == XFA_PARSESTATUS_Done) { | 156 pParser->DoParse(NULL) == XFA_PARSESTATUS_Done) { |
155 pRootNode = pParser->GetRootNode(); | 157 pRootNode = pParser->GetRootNode(); |
156 } | 158 } |
157 if (pRootNode && m_pDocument->GetRoot()) { | 159 if (pRootNode && m_pDocument->GetRoot()) { |
158 XFA_XPDPacket_MergeRootNode(m_pDocument->GetRoot(), pRootNode); | 160 XFA_XPDPacket_MergeRootNode(m_pDocument->GetRoot(), pRootNode); |
159 iStatus = XFA_PARSESTATUS_Done; | 161 iStatus = XFA_PARSESTATUS_Done; |
160 } else { | 162 } else { |
161 iStatus = XFA_PARSESTATUS_StatusErr; | 163 iStatus = XFA_PARSESTATUS_StatusErr; |
162 } | 164 } |
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->GetParser()->Release(); | 268 m_pDocument->DestroyParser(); |
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 |