| 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 "fpdfsdk/fpdfxfa/cpdfxfa_document.h" | 7 #include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/parser/cpdf_document.h" | 9 #include "core/fpdfapi/parser/cpdf_document.h" |
| 10 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" | 10 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
| 11 #include "fpdfsdk/cpdfsdk_interform.h" | 11 #include "fpdfsdk/cpdfsdk_interform.h" |
| 12 #include "fpdfsdk/cpdfsdk_pageview.h" | 12 #include "fpdfsdk/cpdfsdk_pageview.h" |
| 13 #include "fpdfsdk/fpdfxfa/cpdfxfa_app.h" | 13 #include "fpdfsdk/fpdfxfa/cpdfxfa_app.h" |
| 14 #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" | 14 #include "fpdfsdk/fpdfxfa/cpdfxfa_page.h" |
| 15 #include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h" | 15 #include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h" |
| 16 #include "fpdfsdk/fsdk_define.h" | 16 #include "fpdfsdk/fsdk_define.h" |
| 17 #include "fpdfsdk/javascript/ijs_runtime.h" | 17 #include "fpdfsdk/javascript/ijs_runtime.h" |
| 18 #include "public/fpdf_formfill.h" | 18 #include "public/fpdf_formfill.h" |
| 19 #include "third_party/base/ptr_util.h" |
| 19 #include "xfa/fxfa/cxfa_eventparam.h" | 20 #include "xfa/fxfa/cxfa_eventparam.h" |
| 20 #include "xfa/fxfa/xfa_ffapp.h" | 21 #include "xfa/fxfa/xfa_ffapp.h" |
| 21 #include "xfa/fxfa/xfa_ffdoc.h" | 22 #include "xfa/fxfa/xfa_ffdoc.h" |
| 22 #include "xfa/fxfa/xfa_ffdocview.h" | 23 #include "xfa/fxfa/xfa_ffdocview.h" |
| 23 #include "xfa/fxfa/xfa_ffpageview.h" | 24 #include "xfa/fxfa/xfa_ffpageview.h" |
| 24 #include "xfa/fxfa/xfa_ffwidgethandler.h" | 25 #include "xfa/fxfa/xfa_ffwidgethandler.h" |
| 25 | 26 |
| 26 #ifndef _WIN32 | 27 #ifndef _WIN32 |
| 27 extern void SetLastError(int err); | 28 extern void SetLastError(int err); |
| 28 extern int GetLastError(); | 29 extern int GetLastError(); |
| 29 #endif | 30 #endif |
| 30 | 31 |
| 31 CPDFXFA_Document::CPDFXFA_Document(std::unique_ptr<CPDF_Document> pPDFDoc, | 32 CPDFXFA_Document::CPDFXFA_Document(std::unique_ptr<CPDF_Document> pPDFDoc) |
| 32 CPDFXFA_App* pProvider) | |
| 33 : m_iDocType(DOCTYPE_PDF), | 33 : m_iDocType(DOCTYPE_PDF), |
| 34 m_pPDFDoc(std::move(pPDFDoc)), | 34 m_pPDFDoc(std::move(pPDFDoc)), |
| 35 m_pFormFillEnv(nullptr), | 35 m_pFormFillEnv(nullptr), |
| 36 m_pXFADocView(nullptr), | 36 m_pXFADocView(nullptr), |
| 37 m_pApp(pProvider), | |
| 38 m_nLoadStatus(FXFA_LOADSTATUS_PRELOAD), | 37 m_nLoadStatus(FXFA_LOADSTATUS_PRELOAD), |
| 39 m_nPageCount(0), | 38 m_nPageCount(0), |
| 40 m_DocEnv(this) {} | 39 m_DocEnv(this) {} |
| 41 | 40 |
| 42 CPDFXFA_Document::~CPDFXFA_Document() { | 41 CPDFXFA_Document::~CPDFXFA_Document() { |
| 43 m_nLoadStatus = FXFA_LOADSTATUS_CLOSING; | 42 m_nLoadStatus = FXFA_LOADSTATUS_CLOSING; |
| 44 | 43 |
| 44 // Must happen before we remove the form fill environment. |
| 45 if (m_pXFADoc) { |
| 46 if (CXFA_FFApp* pApp = GetApp()->GetXFAApp()) |
| 47 CloseXFADoc(pApp->GetDocHandler()); |
| 48 } |
| 49 |
| 45 if (m_pFormFillEnv) { | 50 if (m_pFormFillEnv) { |
| 46 m_pFormFillEnv->ClearAllFocusedAnnots(); | 51 m_pFormFillEnv->ClearAllFocusedAnnots(); |
| 47 // Once we're deleted the FormFillEnvironment will point at a bad underlying | 52 // Once we're deleted the FormFillEnvironment will point at a bad underlying |
| 48 // doc so we need to reset it ... | 53 // doc so we need to reset it ... |
| 49 m_pFormFillEnv->ResetXFADocument(); | 54 m_pFormFillEnv->ResetXFADocument(); |
| 50 m_pFormFillEnv = nullptr; | 55 m_pFormFillEnv = nullptr; |
| 51 } | 56 } |
| 52 | 57 |
| 53 if (m_pXFADoc) { | |
| 54 CXFA_FFApp* pApp = m_pApp->GetXFAApp(); | |
| 55 if (pApp) { | |
| 56 CXFA_FFDocHandler* pDocHandler = pApp->GetDocHandler(); | |
| 57 if (pDocHandler) | |
| 58 CloseXFADoc(pDocHandler); | |
| 59 } | |
| 60 m_pXFADoc.reset(); | |
| 61 } | |
| 62 | |
| 63 m_nLoadStatus = FXFA_LOADSTATUS_CLOSED; | 58 m_nLoadStatus = FXFA_LOADSTATUS_CLOSED; |
| 64 } | 59 } |
| 65 | 60 |
| 61 void CPDFXFA_Document::CloseXFADoc(CXFA_FFDocHandler* pDoc) { |
| 62 if (!pDoc) |
| 63 return; |
| 64 m_pXFADoc->CloseDoc(); |
| 65 m_pXFADoc.reset(); |
| 66 m_pXFADocView = nullptr; |
| 67 } |
| 68 |
| 69 CPDFXFA_App* CPDFXFA_Document::GetApp() { |
| 70 if (!m_pApp) |
| 71 m_pApp = pdfium::MakeUnique<CPDFXFA_App>(); |
| 72 return m_pApp.get(); |
| 73 } |
| 74 |
| 66 FX_BOOL CPDFXFA_Document::LoadXFADoc() { | 75 FX_BOOL CPDFXFA_Document::LoadXFADoc() { |
| 67 m_nLoadStatus = FXFA_LOADSTATUS_LOADING; | 76 m_nLoadStatus = FXFA_LOADSTATUS_LOADING; |
| 68 | 77 |
| 69 if (!m_pPDFDoc) | 78 if (!m_pPDFDoc) |
| 70 return FALSE; | 79 return FALSE; |
| 71 | 80 |
| 72 m_XFAPageList.RemoveAll(); | 81 m_XFAPageList.RemoveAll(); |
| 73 | 82 |
| 74 CXFA_FFApp* pApp = m_pApp->GetXFAApp(); | 83 CXFA_FFApp* pApp = GetApp()->GetXFAApp(); |
| 75 if (!pApp) | 84 if (!pApp) |
| 76 return FALSE; | 85 return FALSE; |
| 77 | 86 |
| 78 m_pXFADoc.reset(pApp->CreateDoc(&m_DocEnv, m_pPDFDoc.get())); | 87 m_pXFADoc.reset(pApp->CreateDoc(&m_DocEnv, m_pPDFDoc.get())); |
| 79 if (!m_pXFADoc) { | 88 if (!m_pXFADoc) { |
| 80 SetLastError(FPDF_ERR_XFALOAD); | 89 SetLastError(FPDF_ERR_XFALOAD); |
| 81 return FALSE; | 90 return FALSE; |
| 82 } | 91 } |
| 83 | 92 |
| 84 CXFA_FFDocHandler* pDocHandler = pApp->GetDocHandler(); | 93 CXFA_FFDocHandler* pDocHandler = pApp->GetDocHandler(); |
| 85 if (!pDocHandler) { | 94 if (!pDocHandler) { |
| 86 SetLastError(FPDF_ERR_XFALOAD); | 95 SetLastError(FPDF_ERR_XFALOAD); |
| 87 return FALSE; | 96 return FALSE; |
| 88 } | 97 } |
| 89 | 98 |
| 90 m_pXFADoc->StartLoad(); | 99 m_pXFADoc->StartLoad(); |
| 91 int iStatus = m_pXFADoc->DoLoad(nullptr); | 100 int iStatus = m_pXFADoc->DoLoad(nullptr); |
| 92 if (iStatus != XFA_PARSESTATUS_Done) { | 101 if (iStatus != XFA_PARSESTATUS_Done) { |
| 93 CloseXFADoc(pDocHandler); | 102 CloseXFADoc(pDocHandler); |
| 94 SetLastError(FPDF_ERR_XFALOAD); | 103 SetLastError(FPDF_ERR_XFALOAD); |
| 95 return FALSE; | 104 return FALSE; |
| 96 } | 105 } |
| 97 m_pXFADoc->StopLoad(); | 106 m_pXFADoc->StopLoad(); |
| 98 m_pXFADoc->GetXFADoc()->InitScriptContext(m_pApp->GetJSERuntime()); | 107 m_pXFADoc->GetXFADoc()->InitScriptContext(GetApp()->GetJSERuntime()); |
| 99 | 108 |
| 100 if (m_pXFADoc->GetDocType() == XFA_DOCTYPE_Dynamic) | 109 if (m_pXFADoc->GetDocType() == XFA_DOCTYPE_Dynamic) |
| 101 m_iDocType = DOCTYPE_DYNAMIC_XFA; | 110 m_iDocType = DOCTYPE_DYNAMIC_XFA; |
| 102 else | 111 else |
| 103 m_iDocType = DOCTYPE_STATIC_XFA; | 112 m_iDocType = DOCTYPE_STATIC_XFA; |
| 104 | 113 |
| 105 m_pXFADocView = m_pXFADoc->CreateDocView(XFA_DOCVIEW_View); | 114 m_pXFADocView = m_pXFADoc->CreateDocView(XFA_DOCVIEW_View); |
| 106 if (m_pXFADocView->StartLayout() < 0) { | 115 if (m_pXFADocView->StartLayout() < 0) { |
| 107 CloseXFADoc(pDocHandler); | 116 CloseXFADoc(pDocHandler); |
| 108 SetLastError(FPDF_ERR_XFALAYOUT); | 117 SetLastError(FPDF_ERR_XFALAYOUT); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 205 } |
| 197 | 206 |
| 198 void CPDFXFA_Document::RemovePage(CPDFXFA_Page* page) { | 207 void CPDFXFA_Document::RemovePage(CPDFXFA_Page* page) { |
| 199 m_XFAPageList.SetAt(page->GetPageIndex(), nullptr); | 208 m_XFAPageList.SetAt(page->GetPageIndex(), nullptr); |
| 200 } | 209 } |
| 201 | 210 |
| 202 void CPDFXFA_Document::ClearChangeMark() { | 211 void CPDFXFA_Document::ClearChangeMark() { |
| 203 if (m_pFormFillEnv) | 212 if (m_pFormFillEnv) |
| 204 m_pFormFillEnv->ClearChangeMark(); | 213 m_pFormFillEnv->ClearChangeMark(); |
| 205 } | 214 } |
| OLD | NEW |