| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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/cpdfsdk_formfillenvironment.h" | 7 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 CPDFSDK_FormFillEnvironment::~CPDFSDK_FormFillEnvironment() { | 46 CPDFSDK_FormFillEnvironment::~CPDFSDK_FormFillEnvironment() { |
| 47 m_bBeingDestroyed = TRUE; | 47 m_bBeingDestroyed = TRUE; |
| 48 | 48 |
| 49 ClearAllFocusedAnnots(); | 49 ClearAllFocusedAnnots(); |
| 50 for (auto& it : m_pageMap) | 50 for (auto& it : m_pageMap) |
| 51 delete it.second; | 51 delete it.second; |
| 52 m_pageMap.clear(); | 52 m_pageMap.clear(); |
| 53 | 53 |
| 54 #ifdef PDF_ENABLE_XFA | 54 #ifdef PDF_ENABLE_XFA |
| 55 CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); | 55 CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); |
| 56 if (pProvider->m_pEnvList.GetSize() == 0) | 56 if (pProvider->m_pFormFillEnvList.GetSize() == 0) |
| 57 pProvider->SetJavaScriptInitialized(FALSE); | 57 pProvider->SetJavaScriptInitialized(FALSE); |
| 58 #endif // PDF_ENABLE_XFA | 58 #endif // PDF_ENABLE_XFA |
| 59 if (m_pInfo && m_pInfo->Release) | 59 if (m_pInfo && m_pInfo->Release) |
| 60 m_pInfo->Release(m_pInfo); | 60 m_pInfo->Release(m_pInfo); |
| 61 } | 61 } |
| 62 | 62 |
| 63 int CPDFSDK_FormFillEnvironment::JS_appAlert(const FX_WCHAR* Msg, | 63 int CPDFSDK_FormFillEnvironment::JS_appAlert(const FX_WCHAR* Msg, |
| 64 const FX_WCHAR* Title, | 64 const FX_WCHAR* Title, |
| 65 uint32_t Type, | 65 uint32_t Type, |
| 66 uint32_t Icon) { | 66 uint32_t Icon) { |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetPageView( | 575 CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetPageView( |
| 576 UnderlyingPageType* pUnderlyingPage, | 576 UnderlyingPageType* pUnderlyingPage, |
| 577 bool ReNew) { | 577 bool ReNew) { |
| 578 auto it = m_pageMap.find(pUnderlyingPage); | 578 auto it = m_pageMap.find(pUnderlyingPage); |
| 579 if (it != m_pageMap.end()) | 579 if (it != m_pageMap.end()) |
| 580 return it->second; | 580 return it->second; |
| 581 | 581 |
| 582 if (!ReNew) | 582 if (!ReNew) |
| 583 return nullptr; | 583 return nullptr; |
| 584 | 584 |
| 585 CPDFSDK_PageView* pPageView = new CPDFSDK_PageView(GetEnv(), pUnderlyingPage); | 585 CPDFSDK_PageView* pPageView = new CPDFSDK_PageView(this, pUnderlyingPage); |
| 586 m_pageMap[pUnderlyingPage] = pPageView; | 586 m_pageMap[pUnderlyingPage] = pPageView; |
| 587 // Delay to load all the annotations, to avoid endless loop. | 587 // Delay to load all the annotations, to avoid endless loop. |
| 588 pPageView->LoadFXAnnots(); | 588 pPageView->LoadFXAnnots(); |
| 589 return pPageView; | 589 return pPageView; |
| 590 } | 590 } |
| 591 | 591 |
| 592 CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetCurrentView() { | 592 CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetCurrentView() { |
| 593 UnderlyingPageType* pPage = | 593 UnderlyingPageType* pPage = |
| 594 UnderlyingFromFPDFPage(GetCurrentPage(m_pUnderlyingDoc)); | 594 UnderlyingFromFPDFPage(GetCurrentPage(m_pUnderlyingDoc)); |
| 595 return pPage ? GetPageView(pPage, true) : nullptr; | 595 return pPage ? GetPageView(pPage, true) : nullptr; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 609 CPDF_Document* pPDFDoc = GetPDFDocument(); | 609 CPDF_Document* pPDFDoc = GetPDFDocument(); |
| 610 CPDF_DocJSActions docJS(pPDFDoc); | 610 CPDF_DocJSActions docJS(pPDFDoc); |
| 611 int iCount = docJS.CountJSActions(); | 611 int iCount = docJS.CountJSActions(); |
| 612 if (iCount < 1) | 612 if (iCount < 1) |
| 613 return; | 613 return; |
| 614 for (int i = 0; i < iCount; i++) { | 614 for (int i = 0; i < iCount; i++) { |
| 615 CFX_ByteString csJSName; | 615 CFX_ByteString csJSName; |
| 616 CPDF_Action jsAction = docJS.GetJSAction(i, csJSName); | 616 CPDF_Action jsAction = docJS.GetJSAction(i, csJSName); |
| 617 if (GetActionHander()) { | 617 if (GetActionHander()) { |
| 618 GetActionHander()->DoAction_JavaScript( | 618 GetActionHander()->DoAction_JavaScript( |
| 619 jsAction, CFX_WideString::FromLocal(csJSName.AsStringC()), GetEnv()); | 619 jsAction, CFX_WideString::FromLocal(csJSName.AsStringC()), this); |
| 620 } | 620 } |
| 621 } | 621 } |
| 622 } | 622 } |
| 623 | 623 |
| 624 FX_BOOL CPDFSDK_FormFillEnvironment::ProcOpenAction() { | 624 FX_BOOL CPDFSDK_FormFillEnvironment::ProcOpenAction() { |
| 625 if (!m_pUnderlyingDoc) | 625 if (!m_pUnderlyingDoc) |
| 626 return FALSE; | 626 return FALSE; |
| 627 | 627 |
| 628 CPDF_Dictionary* pRoot = GetPDFDocument()->GetRoot(); | 628 CPDF_Dictionary* pRoot = GetPDFDocument()->GetRoot(); |
| 629 if (!pRoot) | 629 if (!pRoot) |
| 630 return FALSE; | 630 return FALSE; |
| 631 | 631 |
| 632 CPDF_Object* pOpenAction = pRoot->GetDictFor("OpenAction"); | 632 CPDF_Object* pOpenAction = pRoot->GetDictFor("OpenAction"); |
| 633 if (!pOpenAction) | 633 if (!pOpenAction) |
| 634 pOpenAction = pRoot->GetArrayFor("OpenAction"); | 634 pOpenAction = pRoot->GetArrayFor("OpenAction"); |
| 635 | 635 |
| 636 if (!pOpenAction) | 636 if (!pOpenAction) |
| 637 return FALSE; | 637 return FALSE; |
| 638 | 638 |
| 639 if (pOpenAction->IsArray()) | 639 if (pOpenAction->IsArray()) |
| 640 return TRUE; | 640 return TRUE; |
| 641 | 641 |
| 642 if (CPDF_Dictionary* pDict = pOpenAction->AsDictionary()) { | 642 if (CPDF_Dictionary* pDict = pOpenAction->AsDictionary()) { |
| 643 CPDF_Action action(pDict); | 643 CPDF_Action action(pDict); |
| 644 if (GetActionHander()) | 644 if (GetActionHander()) |
| 645 GetActionHander()->DoAction_DocOpen(action, GetEnv()); | 645 GetActionHander()->DoAction_DocOpen(action, this); |
| 646 return TRUE; | 646 return TRUE; |
| 647 } | 647 } |
| 648 return FALSE; | 648 return FALSE; |
| 649 } | 649 } |
| 650 | 650 |
| 651 void CPDFSDK_FormFillEnvironment::RemovePageView( | 651 void CPDFSDK_FormFillEnvironment::RemovePageView( |
| 652 UnderlyingPageType* pUnderlyingPage) { | 652 UnderlyingPageType* pUnderlyingPage) { |
| 653 auto it = m_pageMap.find(pUnderlyingPage); | 653 auto it = m_pageMap.find(pUnderlyingPage); |
| 654 if (it == m_pageMap.end()) | 654 if (it == m_pageMap.end()) |
| 655 return; | 655 return; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 676 | 676 |
| 677 delete pPageView; | 677 delete pPageView; |
| 678 } | 678 } |
| 679 | 679 |
| 680 UnderlyingPageType* CPDFSDK_FormFillEnvironment::GetPage(int nIndex) { | 680 UnderlyingPageType* CPDFSDK_FormFillEnvironment::GetPage(int nIndex) { |
| 681 return UnderlyingFromFPDFPage(GetPage(m_pUnderlyingDoc, nIndex)); | 681 return UnderlyingFromFPDFPage(GetPage(m_pUnderlyingDoc, nIndex)); |
| 682 } | 682 } |
| 683 | 683 |
| 684 CPDFSDK_InterForm* CPDFSDK_FormFillEnvironment::GetInterForm() { | 684 CPDFSDK_InterForm* CPDFSDK_FormFillEnvironment::GetInterForm() { |
| 685 if (!m_pInterForm) | 685 if (!m_pInterForm) |
| 686 m_pInterForm = pdfium::MakeUnique<CPDFSDK_InterForm>(GetEnv()); | 686 m_pInterForm = pdfium::MakeUnique<CPDFSDK_InterForm>(this); |
| 687 return m_pInterForm.get(); | 687 return m_pInterForm.get(); |
| 688 } | 688 } |
| 689 | 689 |
| 690 void CPDFSDK_FormFillEnvironment::UpdateAllViews(CPDFSDK_PageView* pSender, | 690 void CPDFSDK_FormFillEnvironment::UpdateAllViews(CPDFSDK_PageView* pSender, |
| 691 CPDFSDK_Annot* pAnnot) { | 691 CPDFSDK_Annot* pAnnot) { |
| 692 for (const auto& it : m_pageMap) { | 692 for (const auto& it : m_pageMap) { |
| 693 CPDFSDK_PageView* pPageView = it.second; | 693 CPDFSDK_PageView* pPageView = it.second; |
| 694 if (pPageView != pSender) | 694 if (pPageView != pSender) |
| 695 pPageView->UpdateView(pAnnot); | 695 pPageView->UpdateView(pAnnot); |
| 696 } | 696 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 } else { | 756 } else { |
| 757 m_pFocusAnnot.Reset(pFocusAnnot.Get()); | 757 m_pFocusAnnot.Reset(pFocusAnnot.Get()); |
| 758 } | 758 } |
| 759 } | 759 } |
| 760 return FALSE; | 760 return FALSE; |
| 761 } | 761 } |
| 762 | 762 |
| 763 FX_BOOL CPDFSDK_FormFillEnvironment::GetPermissions(int nFlag) { | 763 FX_BOOL CPDFSDK_FormFillEnvironment::GetPermissions(int nFlag) { |
| 764 return GetPDFDocument()->GetUserPermissions() & nFlag; | 764 return GetPDFDocument()->GetUserPermissions() & nFlag; |
| 765 } | 765 } |
| OLD | NEW |