| 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 |
| 75 void CPDFXFA_Document::SetFormFillEnv( |
| 76 CPDFSDK_FormFillEnvironment* pFormFillEnv) { |
| 77 // The layout data can have pointers back into the script context. That |
| 78 // context will be different if the form fill environment closes, so, force |
| 79 // the layout data to clear. |
| 80 if (m_pXFADoc && m_pXFADoc->GetXFADoc()) |
| 81 m_pXFADoc->GetXFADoc()->ClearLayoutData(); |
| 82 |
| 83 GetApp()->SetFormFillEnv(pFormFillEnv); |
| 84 m_pFormFillEnv = pFormFillEnv; |
| 85 } |
| 86 |
| 66 FX_BOOL CPDFXFA_Document::LoadXFADoc() { | 87 FX_BOOL CPDFXFA_Document::LoadXFADoc() { |
| 67 m_nLoadStatus = FXFA_LOADSTATUS_LOADING; | 88 m_nLoadStatus = FXFA_LOADSTATUS_LOADING; |
| 68 | 89 |
| 69 if (!m_pPDFDoc) | 90 if (!m_pPDFDoc) |
| 70 return FALSE; | 91 return FALSE; |
| 71 | 92 |
| 72 m_XFAPageList.RemoveAll(); | 93 m_XFAPageList.RemoveAll(); |
| 73 | 94 |
| 74 CXFA_FFApp* pApp = m_pApp->GetXFAApp(); | 95 CXFA_FFApp* pApp = GetApp()->GetXFAApp(); |
| 75 if (!pApp) | 96 if (!pApp) |
| 76 return FALSE; | 97 return FALSE; |
| 77 | 98 |
| 78 m_pXFADoc.reset(pApp->CreateDoc(&m_DocEnv, m_pPDFDoc.get())); | 99 m_pXFADoc.reset(pApp->CreateDoc(&m_DocEnv, m_pPDFDoc.get())); |
| 79 if (!m_pXFADoc) { | 100 if (!m_pXFADoc) { |
| 80 SetLastError(FPDF_ERR_XFALOAD); | 101 SetLastError(FPDF_ERR_XFALOAD); |
| 81 return FALSE; | 102 return FALSE; |
| 82 } | 103 } |
| 83 | 104 |
| 84 CXFA_FFDocHandler* pDocHandler = pApp->GetDocHandler(); | 105 CXFA_FFDocHandler* pDocHandler = pApp->GetDocHandler(); |
| 85 if (!pDocHandler) { | 106 if (!pDocHandler) { |
| 86 SetLastError(FPDF_ERR_XFALOAD); | 107 SetLastError(FPDF_ERR_XFALOAD); |
| 87 return FALSE; | 108 return FALSE; |
| 88 } | 109 } |
| 89 | 110 |
| 90 m_pXFADoc->StartLoad(); | 111 m_pXFADoc->StartLoad(); |
| 91 int iStatus = m_pXFADoc->DoLoad(nullptr); | 112 int iStatus = m_pXFADoc->DoLoad(nullptr); |
| 92 if (iStatus != XFA_PARSESTATUS_Done) { | 113 if (iStatus != XFA_PARSESTATUS_Done) { |
| 93 CloseXFADoc(pDocHandler); | 114 CloseXFADoc(pDocHandler); |
| 94 SetLastError(FPDF_ERR_XFALOAD); | 115 SetLastError(FPDF_ERR_XFALOAD); |
| 95 return FALSE; | 116 return FALSE; |
| 96 } | 117 } |
| 97 m_pXFADoc->StopLoad(); | 118 m_pXFADoc->StopLoad(); |
| 98 m_pXFADoc->GetXFADoc()->InitScriptContext(m_pApp->GetJSERuntime()); | 119 m_pXFADoc->GetXFADoc()->InitScriptContext(GetApp()->GetJSERuntime()); |
| 99 | 120 |
| 100 if (m_pXFADoc->GetDocType() == XFA_DOCTYPE_Dynamic) | 121 if (m_pXFADoc->GetDocType() == XFA_DOCTYPE_Dynamic) |
| 101 m_iDocType = DOCTYPE_DYNAMIC_XFA; | 122 m_iDocType = DOCTYPE_DYNAMIC_XFA; |
| 102 else | 123 else |
| 103 m_iDocType = DOCTYPE_STATIC_XFA; | 124 m_iDocType = DOCTYPE_STATIC_XFA; |
| 104 | 125 |
| 105 m_pXFADocView = m_pXFADoc->CreateDocView(XFA_DOCVIEW_View); | 126 m_pXFADocView = m_pXFADoc->CreateDocView(XFA_DOCVIEW_View); |
| 106 if (m_pXFADocView->StartLayout() < 0) { | 127 if (m_pXFADocView->StartLayout() < 0) { |
| 107 CloseXFADoc(pDocHandler); | 128 CloseXFADoc(pDocHandler); |
| 108 SetLastError(FPDF_ERR_XFALAYOUT); | 129 SetLastError(FPDF_ERR_XFALAYOUT); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 217 } |
| 197 | 218 |
| 198 void CPDFXFA_Document::RemovePage(CPDFXFA_Page* page) { | 219 void CPDFXFA_Document::RemovePage(CPDFXFA_Page* page) { |
| 199 m_XFAPageList.SetAt(page->GetPageIndex(), nullptr); | 220 m_XFAPageList.SetAt(page->GetPageIndex(), nullptr); |
| 200 } | 221 } |
| 201 | 222 |
| 202 void CPDFXFA_Document::ClearChangeMark() { | 223 void CPDFXFA_Document::ClearChangeMark() { |
| 203 if (m_pFormFillEnv) | 224 if (m_pFormFillEnv) |
| 204 m_pFormFillEnv->ClearChangeMark(); | 225 m_pFormFillEnv->ClearChangeMark(); |
| 205 } | 226 } |
| OLD | NEW |