Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(397)

Side by Side Diff: fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp

Issue 2275773003: Flip document and parser ownership (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@private_parser
Patch Set: Rebase to master Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/fpdfview.cpp ('k') | fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" 7 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h"
8 8
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
(...skipping 27 matching lines...) Expand all
38 #define FXFA_XMPMETA 0x00010000 38 #define FXFA_XMPMETA 0x00010000
39 #define FXFA_XFDF 0x00100000 39 #define FXFA_XFDF 0x00100000
40 #define FXFA_FORM 0x01000000 40 #define FXFA_FORM 0x01000000
41 #define FXFA_PDF 0x10000000 41 #define FXFA_PDF 0x10000000
42 42
43 #ifndef _WIN32 43 #ifndef _WIN32
44 extern void SetLastError(int err); 44 extern void SetLastError(int err);
45 extern int GetLastError(); 45 extern int GetLastError();
46 #endif 46 #endif
47 47
48 CPDFXFA_Document::CPDFXFA_Document(CPDF_Document* pPDFDoc, 48 CPDFXFA_Document::CPDFXFA_Document(std::unique_ptr<CPDF_Document> pPDFDoc,
49 CPDFXFA_App* pProvider) 49 CPDFXFA_App* pProvider)
50 : m_iDocType(DOCTYPE_PDF), 50 : m_iDocType(DOCTYPE_PDF),
51 m_pPDFDoc(pPDFDoc), 51 m_pPDFDoc(std::move(pPDFDoc)),
52 m_pXFADocView(nullptr), 52 m_pXFADocView(nullptr),
53 m_pApp(pProvider), 53 m_pApp(pProvider),
54 m_pJSContext(nullptr), 54 m_pJSContext(nullptr),
55 m_nLoadStatus(FXFA_LOADSTATUS_PRELOAD), 55 m_nLoadStatus(FXFA_LOADSTATUS_PRELOAD),
56 m_nPageCount(0) {} 56 m_nPageCount(0) {}
57 57
58 CPDFXFA_Document::~CPDFXFA_Document() { 58 CPDFXFA_Document::~CPDFXFA_Document() {
59 m_nLoadStatus = FXFA_LOADSTATUS_CLOSING; 59 m_nLoadStatus = FXFA_LOADSTATUS_CLOSING;
60 60
61 if (m_pXFADoc) { 61 if (m_pXFADoc) {
62 CXFA_FFApp* pApp = m_pApp->GetXFAApp(); 62 CXFA_FFApp* pApp = m_pApp->GetXFAApp();
63 if (pApp) { 63 if (pApp) {
64 CXFA_FFDocHandler* pDocHandler = pApp->GetDocHandler(); 64 CXFA_FFDocHandler* pDocHandler = pApp->GetDocHandler();
65 if (pDocHandler) { 65 if (pDocHandler) {
66 CloseXFADoc(pDocHandler); 66 CloseXFADoc(pDocHandler);
67 } 67 }
68 } 68 }
69 m_pXFADoc.reset(); 69 m_pXFADoc.reset();
70 } 70 }
71 if (m_pJSContext && m_pSDKDoc && m_pSDKDoc->GetEnv()) 71 if (m_pJSContext && m_pSDKDoc && m_pSDKDoc->GetEnv())
72 m_pSDKDoc->GetEnv()->GetJSRuntime()->ReleaseContext(m_pJSContext); 72 m_pSDKDoc->GetEnv()->GetJSRuntime()->ReleaseContext(m_pJSContext);
73 // |m_pSDKDoc| has to be released before |pParser| and |m_pPDFDoc| since it
74 // needs to access them to kill focused annotations.
75 m_pSDKDoc.reset();
76 if (m_pPDFDoc) {
77 CPDF_Parser* pParser = m_pPDFDoc->GetParser();
78 if (pParser)
79 delete pParser;
80 else
81 delete m_pPDFDoc;
82 }
83 73
84 m_nLoadStatus = FXFA_LOADSTATUS_CLOSED; 74 m_nLoadStatus = FXFA_LOADSTATUS_CLOSED;
85 } 75 }
86 76
87 FX_BOOL CPDFXFA_Document::LoadXFADoc() { 77 FX_BOOL CPDFXFA_Document::LoadXFADoc() {
88 m_nLoadStatus = FXFA_LOADSTATUS_LOADING; 78 m_nLoadStatus = FXFA_LOADSTATUS_LOADING;
89 79
90 if (!m_pPDFDoc) 80 if (!m_pPDFDoc)
91 return FALSE; 81 return FALSE;
92 82
93 m_XFAPageList.RemoveAll(); 83 m_XFAPageList.RemoveAll();
94 84
95 CXFA_FFApp* pApp = m_pApp->GetXFAApp(); 85 CXFA_FFApp* pApp = m_pApp->GetXFAApp();
96 if (!pApp) 86 if (!pApp)
97 return FALSE; 87 return FALSE;
98 88
99 m_pXFADoc.reset(pApp->CreateDoc(this, m_pPDFDoc)); 89 m_pXFADoc.reset(pApp->CreateDoc(this, m_pPDFDoc.get()));
100 if (!m_pXFADoc) { 90 if (!m_pXFADoc) {
101 SetLastError(FPDF_ERR_XFALOAD); 91 SetLastError(FPDF_ERR_XFALOAD);
102 return FALSE; 92 return FALSE;
103 } 93 }
104 94
105 CXFA_FFDocHandler* pDocHandler = pApp->GetDocHandler(); 95 CXFA_FFDocHandler* pDocHandler = pApp->GetDocHandler();
106 if (!pDocHandler) { 96 if (!pDocHandler) {
107 SetLastError(FPDF_ERR_XFALOAD); 97 SetLastError(FPDF_ERR_XFALOAD);
108 return FALSE; 98 return FALSE;
109 } 99 }
(...skipping 1167 matching lines...) Expand 10 before | Expand all | Expand 10 after
1277 1267
1278 return m_pSDKDoc->GetEnv()->GetJSRuntime()->GetValueByName(szPropName, 1268 return m_pSDKDoc->GetEnv()->GetJSRuntime()->GetValueByName(szPropName,
1279 pValue); 1269 pValue);
1280 } 1270 }
1281 1271
1282 CPDF_Document* CPDFXFA_Document::OpenPDF(CXFA_FFDoc* hDoc, 1272 CPDF_Document* CPDFXFA_Document::OpenPDF(CXFA_FFDoc* hDoc,
1283 IFX_FileRead* pFile, 1273 IFX_FileRead* pFile,
1284 FX_BOOL bTakeOverFile) { 1274 FX_BOOL bTakeOverFile) {
1285 return nullptr; 1275 return nullptr;
1286 } 1276 }
OLDNEW
« no previous file with comments | « fpdfsdk/fpdfview.cpp ('k') | fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698