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