• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
12 #include "core/fxcrt/unowned_ptr.h"
13 #include "xfa/fwl/cfwl_app.h"
14 #include "xfa/fxfa/cxfa_fontmgr.h"
15 #include "xfa/fxfa/fxfa.h"
16 
17 class CFGAS_FontMgr;
18 class CFWL_WidgetMgr;
19 class CXFA_FWLAdapterWidgetMgr;
20 class CXFA_FWLTheme;
21 
22 class CXFA_FFApp : public CFWL_App::AdapterIface {
23  public:
24   static void SkipFontLoadForTesting(bool skip);
25 
26   explicit CXFA_FFApp(IXFA_AppProvider* pProvider);
27   ~CXFA_FFApp() override;
28 
29   // CFWL_App::AdapterIface:
30   CFWL_WidgetMgr::AdapterIface* GetWidgetMgrAdapter() override;
31   TimerHandlerIface* GetTimerHandler() override;
32 
GetFWLWidgetMgr()33   CFWL_WidgetMgr* GetFWLWidgetMgr() const { return m_pFWLApp->GetWidgetMgr(); }
34   CFGAS_FontMgr* GetFDEFontMgr();
35   CXFA_FWLTheme* GetFWLTheme(CXFA_FFDoc* doc);
36 
GetAppProvider()37   IXFA_AppProvider* GetAppProvider() const { return m_pProvider.Get(); }
GetFWLApp()38   const CFWL_App* GetFWLApp() const { return m_pFWLApp.get(); }
GetXFAFontMgr()39   CXFA_FontMgr* GetXFAFontMgr() { return &m_pFontMgr; }
40 
41   void ClearEventTargets();
42 
43  private:
44   UnownedPtr<IXFA_AppProvider> const m_pProvider;
45 
46   // The fonts stored in the font manager may have been created by the default
47   // font manager. The GEFont::LoadFont call takes the manager as a param and
48   // stores it internally. When you destroy the GEFont it tries to unregister
49   // from the font manager and if the default font manager was destroyed first
50   // you get a use-after-free. The m_pFWLTheme can try to cleanup a GEFont
51   // when it frees, so make sure it gets cleaned up first. That requires
52   // m_pFWLApp to be cleaned up as well.
53   //
54   // TODO(dsinclair): The GEFont should have the FontMgr as the pointer instead
55   // of the DEFFontMgr so this goes away. Bug 561.
56   std::unique_ptr<CFGAS_FontMgr> m_pFDEFontMgr;
57   CXFA_FontMgr m_pFontMgr;
58 
59   std::unique_ptr<CXFA_FWLAdapterWidgetMgr> m_pAdapterWidgetMgr;
60 
61   // |m_pFWLApp| has to be released first, then |m_pFWLTheme| since the former
62   // may refers to theme manager and the latter refers to font manager.
63   std::unique_ptr<CXFA_FWLTheme> m_pFWLTheme;
64   std::unique_ptr<CFWL_App> m_pFWLApp;
65 };
66 
67 #endif  // XFA_FXFA_CXFA_FFAPP_H_
68