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_XFA_FFAPP_H_
      8 #define XFA_FXFA_XFA_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/cfx_retain_ptr.h"
     16 #include "xfa/fgas/font/cfgas_fontmgr.h"
     17 #include "xfa/fwl/cfwl_app.h"
     18 #include "xfa/fxfa/fxfa.h"
     19 
     20 class CXFA_DefFontMgr;
     21 class CXFA_FWLAdapterWidgetMgr;
     22 class CXFA_FWLTheme;
     23 class CXFA_FFDocHandler;
     24 class CXFA_FontMgr;
     25 class IFWL_AdapterTimerMgr;
     26 class CFWL_WidgetMgrDelegate;
     27 
     28 // Layering prevents fxcrt from knowing about CPDF_Streams; this could go
     29 // in fpdfsdk, but it is XFA-Only.
     30 CFX_RetainPtr<IFX_SeekableReadStream> MakeSeekableReadStream(
     31     const std::vector<CPDF_Stream*>& streams);
     32 
     33 class CXFA_FFApp {
     34  public:
     35   explicit CXFA_FFApp(IXFA_AppProvider* pProvider);
     36   ~CXFA_FFApp();
     37 
     38   std::unique_ptr<CXFA_FFDoc> CreateDoc(IXFA_DocEnvironment* pDocEnvironment,
     39                                         CPDF_Document* pPDFDoc);
     40   void SetDefaultFontMgr(std::unique_ptr<CXFA_DefFontMgr> pFontMgr);
     41 
     42   CXFA_FFDocHandler* GetDocHandler();
     43   CXFA_FWLAdapterWidgetMgr* GetWidgetMgr(CFWL_WidgetMgrDelegate* pDelegate);
     44   CFGAS_FontMgr* GetFDEFontMgr();
     45   CXFA_FWLTheme* GetFWLTheme();
     46 
     47   IXFA_AppProvider* GetAppProvider() const { return m_pProvider; }
     48   const CFWL_App* GetFWLApp() const { return m_pFWLApp.get(); }
     49   IFWL_AdapterTimerMgr* GetTimerMgr() const;
     50   CXFA_FontMgr* GetXFAFontMgr() const;
     51   CFWL_WidgetMgrDelegate* GetWidgetMgrDelegate() const {
     52     return m_pWidgetMgrDelegate;
     53   }
     54 
     55   void ClearEventTargets();
     56 
     57  protected:
     58   std::unique_ptr<CXFA_FFDocHandler> m_pDocHandler;
     59   IXFA_AppProvider* const m_pProvider;
     60 
     61   // The fonts stored in the font manager may have been created by the default
     62   // font manager. The GEFont::LoadFont call takes the manager as a param and
     63   // stores it internally. When you destroy the GEFont it tries to unregister
     64   // from the font manager and if the default font manager was destroyed first
     65   // get get a use-after-free. The m_pFWLTheme can try to cleanup a GEFont
     66   // when it frees, so make sure it gets cleaned up first. That requires
     67   // m_pFWLApp to be cleaned up as well.
     68   //
     69   // TODO(dsinclair): The GEFont should have the FontMgr as the pointer instead
     70   // of the DEFFontMgr so this goes away. Bug 561.
     71   std::unique_ptr<CFGAS_FontMgr> m_pFDEFontMgr;
     72   std::unique_ptr<CXFA_FontMgr> m_pFontMgr;
     73 
     74 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
     75   std::unique_ptr<CFX_FontSourceEnum_File> m_pFontSource;
     76 #endif
     77   std::unique_ptr<CXFA_FWLAdapterWidgetMgr> m_pAdapterWidgetMgr;
     78   CFWL_WidgetMgrDelegate* m_pWidgetMgrDelegate;  // not owned.
     79 
     80   // |m_pFWLApp| has to be released first, then |m_pFWLTheme| since the former
     81   // may refers to theme manager and the latter refers to font manager.
     82   std::unique_ptr<CXFA_FWLTheme> m_pFWLTheme;
     83   std::unique_ptr<CFWL_App> m_pFWLApp;
     84 };
     85 
     86 #endif  // XFA_FXFA_XFA_FFAPP_H_
     87