Home | History | Annotate | Download | only in fxfa
      1 // Copyright 2014 PDFium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
      6 
      7 #ifndef XFA_FXFA_CXFA_FFAPP_H_
      8 #define XFA_FXFA_CXFA_FFAPP_H_
      9 
     10 #include <memory>
     11 #include <vector>
     12 
     13 #include "core/fpdfapi/parser/cpdf_stream.h"
     14 #include "core/fpdfapi/parser/cpdf_stream_acc.h"
     15 #include "core/fxcrt/retain_ptr.h"
     16 #include "core/fxcrt/unowned_ptr.h"
     17 #include "xfa/fwl/cfwl_app.h"
     18 #include "xfa/fxfa/fxfa.h"
     19 
     20 class CFGAS_DefaultFontManager;
     21 class CFGAS_FontMgr;
     22 class CFWL_WidgetMgr;
     23 class CPDF_Document;
     24 class CXFA_FFDocHandler;
     25 class CXFA_FontMgr;
     26 class CXFA_FWLAdapterWidgetMgr;
     27 class CXFA_FWLTheme;
     28 class IFWL_AdapterTimerMgr;
     29 
     30 class CXFA_FFApp {
     31  public:
     32   explicit CXFA_FFApp(IXFA_AppProvider* pProvider);
     33   ~CXFA_FFApp();
     34 
     35   std::unique_ptr<CXFA_FFDoc> CreateDoc(IXFA_DocEnvironment* pDocEnvironment,
     36                                         CPDF_Document* pPDFDoc);
     37   void SetDefaultFontMgr(std::unique_ptr<CFGAS_DefaultFontManager> pFontMgr);
     38 
     39   CXFA_FWLAdapterWidgetMgr* GetFWLAdapterWidgetMgr();
     40   CFWL_WidgetMgr* GetFWLWidgetMgr() const { return m_pFWLApp->GetWidgetMgr(); }
     41 
     42   CFGAS_FontMgr* GetFDEFontMgr();
     43   CXFA_FWLTheme* GetFWLTheme();
     44 
     45   IXFA_AppProvider* GetAppProvider() const { return m_pProvider.Get(); }
     46   const CFWL_App* GetFWLApp() const { return m_pFWLApp.get(); }
     47   IFWL_AdapterTimerMgr* GetTimerMgr() const;
     48   CXFA_FontMgr* GetXFAFontMgr() const;
     49 
     50   void ClearEventTargets();
     51 
     52  private:
     53   UnownedPtr<IXFA_AppProvider> const m_pProvider;
     54 
     55   // The fonts stored in the font manager may have been created by the default
     56   // font manager. The GEFont::LoadFont call takes the manager as a param and
     57   // stores it internally. When you destroy the GEFont it tries to unregister
     58   // from the font manager and if the default font manager was destroyed first
     59   // get get a use-after-free. The m_pFWLTheme can try to cleanup a GEFont
     60   // when it frees, so make sure it gets cleaned up first. That requires
     61   // m_pFWLApp to be cleaned up as well.
     62   //
     63   // TODO(dsinclair): The GEFont should have the FontMgr as the pointer instead
     64   // of the DEFFontMgr so this goes away. Bug 561.
     65   std::unique_ptr<CFGAS_FontMgr> m_pFDEFontMgr;
     66   std::unique_ptr<CXFA_FontMgr> m_pFontMgr;
     67 
     68   std::unique_ptr<CXFA_FWLAdapterWidgetMgr> m_pAdapterWidgetMgr;
     69 
     70   // |m_pFWLApp| has to be released first, then |m_pFWLTheme| since the former
     71   // may refers to theme manager and the latter refers to font manager.
     72   std::unique_ptr<CXFA_FWLTheme> m_pFWLTheme;
     73   std::unique_ptr<CFWL_App> m_pFWLApp;
     74 };
     75 
     76 #endif  // XFA_FXFA_CXFA_FFAPP_H_
     77