Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: fpdfsdk/cpdfsdk_formfillenvironment.cpp

Issue 2489663002: Fix CPDFSDK_FormFillEnvironment destruction order (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/cpdfsdk_formfillenvironment.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 23 matching lines...) Expand all
34 UnderlyingDocumentType* pDoc, 34 UnderlyingDocumentType* pDoc,
35 FPDF_FORMFILLINFO* pFFinfo) 35 FPDF_FORMFILLINFO* pFFinfo)
36 : m_pInfo(pFFinfo), 36 : m_pInfo(pFFinfo),
37 m_pUnderlyingDoc(pDoc), 37 m_pUnderlyingDoc(pDoc),
38 m_pSysHandler(new CFX_SystemHandler(this)), 38 m_pSysHandler(new CFX_SystemHandler(this)),
39 m_bChangeMask(false), 39 m_bChangeMask(false),
40 m_bBeingDestroyed(false) {} 40 m_bBeingDestroyed(false) {}
41 41
42 CPDFSDK_FormFillEnvironment::~CPDFSDK_FormFillEnvironment() { 42 CPDFSDK_FormFillEnvironment::~CPDFSDK_FormFillEnvironment() {
43 m_bBeingDestroyed = true; 43 m_bBeingDestroyed = true;
44
45 ClearAllFocusedAnnots(); 44 ClearAllFocusedAnnots();
46 45
47 // |m_pAnnotHandlerMgr| will try to access |m_pFormFiller| 46 // |m_PageMap| will try to access |m_pInterForm| when it cleans itself up.
48 // when it cleans up. So, we must make sure it is cleaned up before 47 // Make sure it is deleted before |m_pInterForm|.
49 // |m_pFormFiller|. 48 m_PageMap.clear();
49
50 // |m_pAnnotHandlerMgr| will try to access |m_pFormFiller| when it cleans
51 // itself up. Make sure it is deleted before |m_pFormFiller|.
50 m_pAnnotHandlerMgr.reset(); 52 m_pAnnotHandlerMgr.reset();
51 53
52 // Must destroy the |m_pFormFiller| before the environment (|this|) 54 // Must destroy the |m_pFormFiller| before the environment (|this|)
53 // because any created form widgets hold a pointer to the environment. 55 // because any created form widgets hold a pointer to the environment.
54 // Those widgets may call things like KillTimer() as they are shutdown. 56 // Those widgets may call things like KillTimer() as they are shutdown.
55 m_pFormFiller.reset(); 57 m_pFormFiller.reset();
56 58
57 if (m_pInfo && m_pInfo->Release) 59 if (m_pInfo && m_pInfo->Release)
58 m_pInfo->Release(m_pInfo); 60 m_pInfo->Release(m_pInfo);
59 } 61 }
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 } 558 }
557 559
558 void CPDFSDK_FormFillEnvironment::PageEvent(int iPageCount, 560 void CPDFSDK_FormFillEnvironment::PageEvent(int iPageCount,
559 uint32_t dwEventType) const { 561 uint32_t dwEventType) const {
560 if (m_pInfo && m_pInfo->FFI_PageEvent) 562 if (m_pInfo && m_pInfo->FFI_PageEvent)
561 m_pInfo->FFI_PageEvent(m_pInfo, iPageCount, dwEventType); 563 m_pInfo->FFI_PageEvent(m_pInfo, iPageCount, dwEventType);
562 } 564 }
563 #endif // PDF_ENABLE_XFA 565 #endif // PDF_ENABLE_XFA
564 566
565 void CPDFSDK_FormFillEnvironment::ClearAllFocusedAnnots() { 567 void CPDFSDK_FormFillEnvironment::ClearAllFocusedAnnots() {
566 for (auto& it : m_pageMap) { 568 for (auto& it : m_PageMap) {
567 if (it.second->IsValidSDKAnnot(GetFocusAnnot())) 569 if (it.second->IsValidSDKAnnot(GetFocusAnnot()))
568 KillFocusAnnot(0); 570 KillFocusAnnot(0);
569 } 571 }
570 } 572 }
571 573
572 CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetPageView( 574 CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetPageView(
573 UnderlyingPageType* pUnderlyingPage, 575 UnderlyingPageType* pUnderlyingPage,
574 bool renew) { 576 bool renew) {
575 auto it = m_pageMap.find(pUnderlyingPage); 577 auto it = m_PageMap.find(pUnderlyingPage);
576 if (it != m_pageMap.end()) 578 if (it != m_PageMap.end())
577 return it->second.get(); 579 return it->second.get();
578 580
579 if (!renew) 581 if (!renew)
580 return nullptr; 582 return nullptr;
581 583
582 CPDFSDK_PageView* pPageView = new CPDFSDK_PageView(this, pUnderlyingPage); 584 CPDFSDK_PageView* pPageView = new CPDFSDK_PageView(this, pUnderlyingPage);
583 m_pageMap[pUnderlyingPage].reset(pPageView); 585 m_PageMap[pUnderlyingPage].reset(pPageView);
584 // Delay to load all the annotations, to avoid endless loop. 586 // Delay to load all the annotations, to avoid endless loop.
585 pPageView->LoadFXAnnots(); 587 pPageView->LoadFXAnnots();
586 return pPageView; 588 return pPageView;
587 } 589 }
588 590
589 CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetCurrentView() { 591 CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetCurrentView() {
590 UnderlyingPageType* pPage = 592 UnderlyingPageType* pPage =
591 UnderlyingFromFPDFPage(GetCurrentPage(m_pUnderlyingDoc)); 593 UnderlyingFromFPDFPage(GetCurrentPage(m_pUnderlyingDoc));
592 return pPage ? GetPageView(pPage, true) : nullptr; 594 return pPage ? GetPageView(pPage, true) : nullptr;
593 } 595 }
594 596
595 CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetPageView(int nIndex) { 597 CPDFSDK_PageView* CPDFSDK_FormFillEnvironment::GetPageView(int nIndex) {
596 UnderlyingPageType* pTempPage = 598 UnderlyingPageType* pTempPage =
597 UnderlyingFromFPDFPage(GetPage(m_pUnderlyingDoc, nIndex)); 599 UnderlyingFromFPDFPage(GetPage(m_pUnderlyingDoc, nIndex));
598 if (!pTempPage) 600 if (!pTempPage)
599 return nullptr; 601 return nullptr;
600 602
601 auto it = m_pageMap.find(pTempPage); 603 auto it = m_PageMap.find(pTempPage);
602 return it != m_pageMap.end() ? it->second.get() : nullptr; 604 return it != m_PageMap.end() ? it->second.get() : nullptr;
603 } 605 }
604 606
605 void CPDFSDK_FormFillEnvironment::ProcJavascriptFun() { 607 void CPDFSDK_FormFillEnvironment::ProcJavascriptFun() {
606 CPDF_Document* pPDFDoc = GetPDFDocument(); 608 CPDF_Document* pPDFDoc = GetPDFDocument();
607 CPDF_DocJSActions docJS(pPDFDoc); 609 CPDF_DocJSActions docJS(pPDFDoc);
608 int iCount = docJS.CountJSActions(); 610 int iCount = docJS.CountJSActions();
609 if (iCount < 1) 611 if (iCount < 1)
610 return; 612 return;
611 for (int i = 0; i < iCount; i++) { 613 for (int i = 0; i < iCount; i++) {
612 CFX_ByteString csJSName; 614 CFX_ByteString csJSName;
(...skipping 27 matching lines...) Expand all
640 CPDF_Action action(pDict); 642 CPDF_Action action(pDict);
641 if (GetActionHander()) 643 if (GetActionHander())
642 GetActionHander()->DoAction_DocOpen(action, this); 644 GetActionHander()->DoAction_DocOpen(action, this);
643 return true; 645 return true;
644 } 646 }
645 return false; 647 return false;
646 } 648 }
647 649
648 void CPDFSDK_FormFillEnvironment::RemovePageView( 650 void CPDFSDK_FormFillEnvironment::RemovePageView(
649 UnderlyingPageType* pUnderlyingPage) { 651 UnderlyingPageType* pUnderlyingPage) {
650 auto it = m_pageMap.find(pUnderlyingPage); 652 auto it = m_PageMap.find(pUnderlyingPage);
651 if (it == m_pageMap.end()) 653 if (it == m_PageMap.end())
652 return; 654 return;
653 655
654 CPDFSDK_PageView* pPageView = it->second.get(); 656 CPDFSDK_PageView* pPageView = it->second.get();
655 if (pPageView->IsLocked() || pPageView->IsBeingDestroyed()) 657 if (pPageView->IsLocked() || pPageView->IsBeingDestroyed())
656 return; 658 return;
657 659
658 // Mark the page view so we do not come into |RemovePageView| a second 660 // Mark the page view so we do not come into |RemovePageView| a second
659 // time while we're in the process of removing. 661 // time while we're in the process of removing.
660 pPageView->SetBeingDestroyed(); 662 pPageView->SetBeingDestroyed();
661 663
662 // This must happen before we remove |pPageView| from the map because 664 // This must happen before we remove |pPageView| from the map because
663 // |KillFocusAnnot| can call into the |GetPage| method which will 665 // |KillFocusAnnot| can call into the |GetPage| method which will
664 // look for this page view in the map, if it doesn't find it a new one will 666 // look for this page view in the map, if it doesn't find it a new one will
665 // be created. We then have two page views pointing to the same page and 667 // be created. We then have two page views pointing to the same page and
666 // bad things happen. 668 // bad things happen.
667 if (pPageView->IsValidSDKAnnot(GetFocusAnnot())) 669 if (pPageView->IsValidSDKAnnot(GetFocusAnnot()))
668 KillFocusAnnot(0); 670 KillFocusAnnot(0);
669 671
670 // Remove the page from the map to make sure we don't accidentally attempt 672 // Remove the page from the map to make sure we don't accidentally attempt
671 // to use the |pPageView| while we're cleaning it up. 673 // to use the |pPageView| while we're cleaning it up.
672 m_pageMap.erase(it); 674 m_PageMap.erase(it);
673 } 675 }
674 676
675 UnderlyingPageType* CPDFSDK_FormFillEnvironment::GetPage(int nIndex) { 677 UnderlyingPageType* CPDFSDK_FormFillEnvironment::GetPage(int nIndex) {
676 return UnderlyingFromFPDFPage(GetPage(m_pUnderlyingDoc, nIndex)); 678 return UnderlyingFromFPDFPage(GetPage(m_pUnderlyingDoc, nIndex));
677 } 679 }
678 680
679 CPDFSDK_InterForm* CPDFSDK_FormFillEnvironment::GetInterForm() { 681 CPDFSDK_InterForm* CPDFSDK_FormFillEnvironment::GetInterForm() {
680 if (!m_pInterForm) 682 if (!m_pInterForm)
681 m_pInterForm = pdfium::MakeUnique<CPDFSDK_InterForm>(this); 683 m_pInterForm = pdfium::MakeUnique<CPDFSDK_InterForm>(this);
682 return m_pInterForm.get(); 684 return m_pInterForm.get();
683 } 685 }
684 686
685 void CPDFSDK_FormFillEnvironment::UpdateAllViews(CPDFSDK_PageView* pSender, 687 void CPDFSDK_FormFillEnvironment::UpdateAllViews(CPDFSDK_PageView* pSender,
686 CPDFSDK_Annot* pAnnot) { 688 CPDFSDK_Annot* pAnnot) {
687 for (const auto& it : m_pageMap) { 689 for (const auto& it : m_PageMap) {
688 CPDFSDK_PageView* pPageView = it.second.get(); 690 CPDFSDK_PageView* pPageView = it.second.get();
689 if (pPageView != pSender) 691 if (pPageView != pSender)
690 pPageView->UpdateView(pAnnot); 692 pPageView->UpdateView(pAnnot);
691 } 693 }
692 } 694 }
693 695
694 bool CPDFSDK_FormFillEnvironment::SetFocusAnnot( 696 bool CPDFSDK_FormFillEnvironment::SetFocusAnnot(
695 CPDFSDK_Annot::ObservedPtr* pAnnot) { 697 CPDFSDK_Annot::ObservedPtr* pAnnot) {
696 if (m_bBeingDestroyed) 698 if (m_bBeingDestroyed)
697 return false; 699 return false;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 } else { 753 } else {
752 m_pFocusAnnot.Reset(pFocusAnnot.Get()); 754 m_pFocusAnnot.Reset(pFocusAnnot.Get());
753 } 755 }
754 } 756 }
755 return false; 757 return false;
756 } 758 }
757 759
758 bool CPDFSDK_FormFillEnvironment::GetPermissions(int nFlag) { 760 bool CPDFSDK_FormFillEnvironment::GetPermissions(int nFlag) {
759 return !!(GetPDFDocument()->GetUserPermissions() & nFlag); 761 return !!(GetPDFDocument()->GetUserPermissions() & nFlag);
760 } 762 }
OLDNEW
« no previous file with comments | « fpdfsdk/cpdfsdk_formfillenvironment.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698