| 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 22 matching lines...) Expand all Loading... |
| 33 } | 33 } |
| 34 | 34 |
| 35 } // namespace | 35 } // namespace |
| 36 | 36 |
| 37 CPDFSDK_FormFillEnvironment::CPDFSDK_FormFillEnvironment( | 37 CPDFSDK_FormFillEnvironment::CPDFSDK_FormFillEnvironment( |
| 38 UnderlyingDocumentType* pDoc, | 38 UnderlyingDocumentType* pDoc, |
| 39 FPDF_FORMFILLINFO* pFFinfo) | 39 FPDF_FORMFILLINFO* pFFinfo) |
| 40 : m_pInfo(pFFinfo), | 40 : m_pInfo(pFFinfo), |
| 41 m_pUnderlyingDoc(pDoc), | 41 m_pUnderlyingDoc(pDoc), |
| 42 m_pSysHandler(new CFX_SystemHandler(this)), | 42 m_pSysHandler(new CFX_SystemHandler(this)), |
| 43 m_bChangeMask(FALSE), | 43 m_bChangeMask(false), |
| 44 m_bBeingDestroyed(FALSE) {} | 44 m_bBeingDestroyed(false) {} |
| 45 | 45 |
| 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) | |
| 51 delete it.second; | |
| 52 m_pageMap.clear(); | |
| 53 | 50 |
| 54 // |m_pAnnotHandlerMgr| will try to access |m_pFormFiller| | 51 // |m_pAnnotHandlerMgr| will try to access |m_pFormFiller| |
| 55 // when it cleans up. So, we must make sure it is cleaned up before | 52 // when it cleans up. So, we must make sure it is cleaned up before |
| 56 // |m_pFormFiller|. | 53 // |m_pFormFiller|. |
| 57 m_pAnnotHandlerMgr.reset(); | 54 m_pAnnotHandlerMgr.reset(); |
| 58 | 55 |
| 59 // Must destroy the |m_pFormFiller| before the environment (|this|) | 56 // Must destroy the |m_pFormFiller| before the environment (|this|) |
| 60 // because any created form widgets hold a pointer to the environment. | 57 // because any created form widgets hold a pointer to the environment. |
| 61 // Those widgets may call things like KillTimer() as they are shutdown. | 58 // Those widgets may call things like KillTimer() as they are shutdown. |
| 62 m_pFormFiller.reset(); | 59 m_pFormFiller.reset(); |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 | 574 |
| 578 void CPDFSDK_FormFillEnvironment::ClearAllFocusedAnnots() { | 575 void CPDFSDK_FormFillEnvironment::ClearAllFocusedAnnots() { |
| 579 for (auto& it : m_pageMap) { | 576 for (auto& it : m_pageMap) { |
| 580 if (it.second->IsValidSDKAnnot(GetFocusAnnot())) | 577 if (it.second->IsValidSDKAnnot(GetFocusAnnot())) |
| 581 KillFocusAnnot(0); | 578 KillFocusAnnot(0); |
| 582 } | 579 } |
| 583 } | 580 } |
| 584 | 581 |
| 585 CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetPageView( | 582 CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetPageView( |
| 586 UnderlyingPageType* pUnderlyingPage, | 583 UnderlyingPageType* pUnderlyingPage, |
| 587 bool ReNew) { | 584 bool renew) { |
| 588 auto it = m_pageMap.find(pUnderlyingPage); | 585 auto it = m_pageMap.find(pUnderlyingPage); |
| 589 if (it != m_pageMap.end()) | 586 if (it != m_pageMap.end()) |
| 590 return it->second; | 587 return it->second.get(); |
| 591 | 588 |
| 592 if (!ReNew) | 589 if (!renew) |
| 593 return nullptr; | 590 return nullptr; |
| 594 | 591 |
| 595 CPDFSDK_PageView* pPageView = new CPDFSDK_PageView(this, pUnderlyingPage); | 592 CPDFSDK_PageView* pPageView = new CPDFSDK_PageView(this, pUnderlyingPage); |
| 596 m_pageMap[pUnderlyingPage] = pPageView; | 593 m_pageMap[pUnderlyingPage].reset(pPageView); |
| 597 // Delay to load all the annotations, to avoid endless loop. | 594 // Delay to load all the annotations, to avoid endless loop. |
| 598 pPageView->LoadFXAnnots(); | 595 pPageView->LoadFXAnnots(); |
| 599 return pPageView; | 596 return pPageView; |
| 600 } | 597 } |
| 601 | 598 |
| 602 CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetCurrentView() { | 599 CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetCurrentView() { |
| 603 UnderlyingPageType* pPage = | 600 UnderlyingPageType* pPage = |
| 604 UnderlyingFromFPDFPage(GetCurrentPage(m_pUnderlyingDoc)); | 601 UnderlyingFromFPDFPage(GetCurrentPage(m_pUnderlyingDoc)); |
| 605 return pPage ? GetPageView(pPage, true) : nullptr; | 602 return pPage ? GetPageView(pPage, true) : nullptr; |
| 606 } | 603 } |
| 607 | 604 |
| 608 CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetPageView(int nIndex) { | 605 CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetPageView(int nIndex) { |
| 609 UnderlyingPageType* pTempPage = | 606 UnderlyingPageType* pTempPage = |
| 610 UnderlyingFromFPDFPage(GetPage(m_pUnderlyingDoc, nIndex)); | 607 UnderlyingFromFPDFPage(GetPage(m_pUnderlyingDoc, nIndex)); |
| 611 if (!pTempPage) | 608 if (!pTempPage) |
| 612 return nullptr; | 609 return nullptr; |
| 613 | 610 |
| 614 auto it = m_pageMap.find(pTempPage); | 611 auto it = m_pageMap.find(pTempPage); |
| 615 return it != m_pageMap.end() ? it->second : nullptr; | 612 return it != m_pageMap.end() ? it->second.get() : nullptr; |
| 616 } | 613 } |
| 617 | 614 |
| 618 void CPDFSDK_FormFillEnvironment::ProcJavascriptFun() { | 615 void CPDFSDK_FormFillEnvironment::ProcJavascriptFun() { |
| 619 CPDF_Document* pPDFDoc = GetPDFDocument(); | 616 CPDF_Document* pPDFDoc = GetPDFDocument(); |
| 620 CPDF_DocJSActions docJS(pPDFDoc); | 617 CPDF_DocJSActions docJS(pPDFDoc); |
| 621 int iCount = docJS.CountJSActions(); | 618 int iCount = docJS.CountJSActions(); |
| 622 if (iCount < 1) | 619 if (iCount < 1) |
| 623 return; | 620 return; |
| 624 for (int i = 0; i < iCount; i++) { | 621 for (int i = 0; i < iCount; i++) { |
| 625 CFX_ByteString csJSName; | 622 CFX_ByteString csJSName; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 } | 654 } |
| 658 return FALSE; | 655 return FALSE; |
| 659 } | 656 } |
| 660 | 657 |
| 661 void CPDFSDK_FormFillEnvironment::RemovePageView( | 658 void CPDFSDK_FormFillEnvironment::RemovePageView( |
| 662 UnderlyingPageType* pUnderlyingPage) { | 659 UnderlyingPageType* pUnderlyingPage) { |
| 663 auto it = m_pageMap.find(pUnderlyingPage); | 660 auto it = m_pageMap.find(pUnderlyingPage); |
| 664 if (it == m_pageMap.end()) | 661 if (it == m_pageMap.end()) |
| 665 return; | 662 return; |
| 666 | 663 |
| 667 CPDFSDK_PageView* pPageView = it->second; | 664 CPDFSDK_PageView* pPageView = it->second.get(); |
| 668 if (pPageView->IsLocked() || pPageView->IsBeingDestroyed()) | 665 if (pPageView->IsLocked() || pPageView->IsBeingDestroyed()) |
| 669 return; | 666 return; |
| 670 | 667 |
| 671 // Mark the page view so we do not come into |RemovePageView| a second | 668 // Mark the page view so we do not come into |RemovePageView| a second |
| 672 // time while we're in the process of removing. | 669 // time while we're in the process of removing. |
| 673 pPageView->SetBeingDestroyed(); | 670 pPageView->SetBeingDestroyed(); |
| 674 | 671 |
| 675 // This must happen before we remove |pPageView| from the map because | 672 // This must happen before we remove |pPageView| from the map because |
| 676 // |KillFocusAnnot| can call into the |GetPage| method which will | 673 // |KillFocusAnnot| can call into the |GetPage| method which will |
| 677 // look for this page view in the map, if it doesn't find it a new one will | 674 // look for this page view in the map, if it doesn't find it a new one will |
| 678 // be created. We then have two page views pointing to the same page and | 675 // be created. We then have two page views pointing to the same page and |
| 679 // bad things happen. | 676 // bad things happen. |
| 680 if (pPageView->IsValidSDKAnnot(GetFocusAnnot())) | 677 if (pPageView->IsValidSDKAnnot(GetFocusAnnot())) |
| 681 KillFocusAnnot(0); | 678 KillFocusAnnot(0); |
| 682 | 679 |
| 683 // Remove the page from the map to make sure we don't accidentally attempt | 680 // Remove the page from the map to make sure we don't accidentally attempt |
| 684 // to use the |pPageView| while we're cleaning it up. | 681 // to use the |pPageView| while we're cleaning it up. |
| 685 m_pageMap.erase(it); | 682 m_pageMap.erase(it); |
| 686 | |
| 687 delete pPageView; | |
| 688 } | 683 } |
| 689 | 684 |
| 690 UnderlyingPageType* CPDFSDK_FormFillEnvironment::GetPage(int nIndex) { | 685 UnderlyingPageType* CPDFSDK_FormFillEnvironment::GetPage(int nIndex) { |
| 691 return UnderlyingFromFPDFPage(GetPage(m_pUnderlyingDoc, nIndex)); | 686 return UnderlyingFromFPDFPage(GetPage(m_pUnderlyingDoc, nIndex)); |
| 692 } | 687 } |
| 693 | 688 |
| 694 CPDFSDK_InterForm* CPDFSDK_FormFillEnvironment::GetInterForm() { | 689 CPDFSDK_InterForm* CPDFSDK_FormFillEnvironment::GetInterForm() { |
| 695 if (!m_pInterForm) | 690 if (!m_pInterForm) |
| 696 m_pInterForm = pdfium::MakeUnique<CPDFSDK_InterForm>(this); | 691 m_pInterForm = pdfium::MakeUnique<CPDFSDK_InterForm>(this); |
| 697 return m_pInterForm.get(); | 692 return m_pInterForm.get(); |
| 698 } | 693 } |
| 699 | 694 |
| 700 void CPDFSDK_FormFillEnvironment::UpdateAllViews(CPDFSDK_PageView* pSender, | 695 void CPDFSDK_FormFillEnvironment::UpdateAllViews(CPDFSDK_PageView* pSender, |
| 701 CPDFSDK_Annot* pAnnot) { | 696 CPDFSDK_Annot* pAnnot) { |
| 702 for (const auto& it : m_pageMap) { | 697 for (const auto& it : m_pageMap) { |
| 703 CPDFSDK_PageView* pPageView = it.second; | 698 CPDFSDK_PageView* pPageView = it.second.get(); |
| 704 if (pPageView != pSender) | 699 if (pPageView != pSender) |
| 705 pPageView->UpdateView(pAnnot); | 700 pPageView->UpdateView(pAnnot); |
| 706 } | 701 } |
| 707 } | 702 } |
| 708 | 703 |
| 709 FX_BOOL CPDFSDK_FormFillEnvironment::SetFocusAnnot( | 704 FX_BOOL CPDFSDK_FormFillEnvironment::SetFocusAnnot( |
| 710 CPDFSDK_Annot::ObservedPtr* pAnnot) { | 705 CPDFSDK_Annot::ObservedPtr* pAnnot) { |
| 711 if (m_bBeingDestroyed) | 706 if (m_bBeingDestroyed) |
| 712 return FALSE; | 707 return FALSE; |
| 713 if (m_pFocusAnnot == *pAnnot) | 708 if (m_pFocusAnnot == *pAnnot) |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 } else { | 761 } else { |
| 767 m_pFocusAnnot.Reset(pFocusAnnot.Get()); | 762 m_pFocusAnnot.Reset(pFocusAnnot.Get()); |
| 768 } | 763 } |
| 769 } | 764 } |
| 770 return FALSE; | 765 return FALSE; |
| 771 } | 766 } |
| 772 | 767 |
| 773 FX_BOOL CPDFSDK_FormFillEnvironment::GetPermissions(int nFlag) { | 768 FX_BOOL CPDFSDK_FormFillEnvironment::GetPermissions(int nFlag) { |
| 774 return GetPDFDocument()->GetUserPermissions() & nFlag; | 769 return GetPDFDocument()->GetUserPermissions() & nFlag; |
| 775 } | 770 } |
| OLD | NEW |