Move the UNSUPPORT_INFO interface out of CPDF_ModuleMgr.
There's no need for the module manager mechanism, and the
UNSUPPORT_IFNO can live as a global singleton in cpdfsdk_helpers.cpp,
which is responsible for converting public/ types into things the
rest of PDFium can use.
In turn, there is no need to instantiate a CPDF_ModuleMgr object
as it now only contains static methods (after removing an
unimplemented declaration). A subsequent CL may remove
CPDF_ModuleMgr entirely.
Change-Id: I44077a6ff9922ac4ab17c77eb4b631d1df434737
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/58530
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/cpdf_modulemgr.cpp b/core/fpdfapi/cpdf_modulemgr.cpp
index 3ab5cb5..0cac7ef 100644
--- a/core/fpdfapi/cpdf_modulemgr.cpp
+++ b/core/fpdfapi/cpdf_modulemgr.cpp
@@ -9,38 +9,26 @@
#include "core/fpdfapi/font/cpdf_fontglobals.h"
#include "core/fpdfapi/page/cpdf_pagemodule.h"
#include "core/fxcodec/fx_codec.h"
-#include "third_party/base/ptr_util.h"
namespace {
-CPDF_ModuleMgr* g_pDefaultMgr = nullptr;
+bool g_bModuleMgrCreated = false;
} // namespace
// static
void CPDF_ModuleMgr::Create() {
- ASSERT(!g_pDefaultMgr);
- g_pDefaultMgr = new CPDF_ModuleMgr;
+ ASSERT(!g_bModuleMgrCreated);
fxcodec::ModuleMgr::Create();
CPDF_PageModule::Create();
CPDF_FontGlobals::GetInstance()->LoadEmbeddedMaps();
+ g_bModuleMgrCreated = true;
}
// static
void CPDF_ModuleMgr::Destroy() {
- ASSERT(g_pDefaultMgr);
+ ASSERT(g_bModuleMgrCreated);
CPDF_PageModule::Destroy();
fxcodec::ModuleMgr::Destroy();
- delete g_pDefaultMgr;
- g_pDefaultMgr = nullptr;
+ g_bModuleMgrCreated = false;
}
-
-// static
-CPDF_ModuleMgr* CPDF_ModuleMgr::Get() {
- ASSERT(g_pDefaultMgr);
- return g_pDefaultMgr;
-}
-
-CPDF_ModuleMgr::CPDF_ModuleMgr() = default;
-
-CPDF_ModuleMgr::~CPDF_ModuleMgr() = default;
diff --git a/core/fpdfapi/cpdf_modulemgr.h b/core/fpdfapi/cpdf_modulemgr.h
index 86fe988..8cc713b 100644
--- a/core/fpdfapi/cpdf_modulemgr.h
+++ b/core/fpdfapi/cpdf_modulemgr.h
@@ -7,44 +7,14 @@
#ifndef CORE_FPDFAPI_CPDF_MODULEMGR_H_
#define CORE_FPDFAPI_CPDF_MODULEMGR_H_
-#include <memory>
-#include <utility>
-
-namespace fpdfapi {
-
-class UnsupportedInfoAdapter {
- public:
- explicit UnsupportedInfoAdapter(void* info) : m_info(info) {}
-
- void* info() const { return m_info; }
-
- private:
- void* const m_info;
-};
-
-} // namespace fpdfapi
-
class CPDF_ModuleMgr {
public:
static void Create();
static void Destroy();
- static CPDF_ModuleMgr* Get();
-
- void SetUnsupportInfoAdapter(
- std::unique_ptr<fpdfapi::UnsupportedInfoAdapter> pAdapter) {
- m_pUnsupportInfoAdapter = std::move(pAdapter);
- }
- fpdfapi::UnsupportedInfoAdapter* GetUnsupportInfoAdapter() const {
- return m_pUnsupportInfoAdapter.get();
- }
private:
- CPDF_ModuleMgr();
- ~CPDF_ModuleMgr();
-
- void InitPageModule();
-
- std::unique_ptr<fpdfapi::UnsupportedInfoAdapter> m_pUnsupportInfoAdapter;
+ CPDF_ModuleMgr() = delete;
+ ~CPDF_ModuleMgr() = delete;
};
#endif // CORE_FPDFAPI_CPDF_MODULEMGR_H_
diff --git a/fpdfsdk/cpdfsdk_helpers.cpp b/fpdfsdk/cpdfsdk_helpers.cpp
index 24cf507..bafac5c 100644
--- a/fpdfsdk/cpdfsdk_helpers.cpp
+++ b/fpdfsdk/cpdfsdk_helpers.cpp
@@ -19,7 +19,6 @@
#include "core/fpdfdoc/cpdf_interactiveform.h"
#include "core/fpdfdoc/cpdf_metadata.h"
#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
-#include "public/fpdf_ext.h"
#ifdef PDF_ENABLE_XFA
#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h"
@@ -32,18 +31,18 @@
// 0 bit: FPDF_POLICY_MACHINETIME_ACCESS
uint32_t g_sandbox_policy = 0xFFFFFFFF;
+UNSUPPORT_INFO* g_unsupport_info = nullptr;
+
#if !defined(OS_WIN)
int g_last_error = 0;
#endif
bool RaiseUnsupportedError(int nError) {
- auto* pAdapter = CPDF_ModuleMgr::Get()->GetUnsupportInfoAdapter();
- if (!pAdapter)
+ if (!g_unsupport_info)
return false;
- UNSUPPORT_INFO* info = static_cast<UNSUPPORT_INFO*>(pAdapter->info());
- if (info && info->FSDK_UnSupport_Handler)
- info->FSDK_UnSupport_Handler(info, nError);
+ if (g_unsupport_info->FSDK_UnSupport_Handler)
+ g_unsupport_info->FSDK_UnSupport_Handler(g_unsupport_info, nError);
return true;
}
@@ -318,6 +317,14 @@
}
}
+void SetPDFUnsupportInfo(UNSUPPORT_INFO* unsp_info) {
+ g_unsupport_info = unsp_info;
+}
+
+UNSUPPORT_INFO* GetPDFUnssuportInto() {
+ return g_unsupport_info;
+}
+
void ReportUnsupportedFeatures(CPDF_Document* pDoc) {
const CPDF_Dictionary* pRootDict = pDoc->GetRoot();
if (pRootDict) {
diff --git a/fpdfsdk/cpdfsdk_helpers.h b/fpdfsdk/cpdfsdk_helpers.h
index f8d3574..8eca854 100644
--- a/fpdfsdk/cpdfsdk_helpers.h
+++ b/fpdfsdk/cpdfsdk_helpers.h
@@ -12,6 +12,7 @@
#include "core/fpdfapi/parser/cpdf_parser.h"
#include "core/fxge/dib/cfx_dibitmap.h"
#include "public/fpdf_doc.h"
+#include "public/fpdf_ext.h"
#include "public/fpdfview.h"
#ifdef PDF_ENABLE_XFA
@@ -275,6 +276,8 @@
bool bNeedToRestore,
IPDFSDK_PauseAdapter* pause);
+void SetPDFUnsupportInfo(UNSUPPORT_INFO* unsp_info);
+UNSUPPORT_INFO* GetPDFUnssuportInto();
void ReportUnsupportedFeatures(CPDF_Document* pDoc);
void CheckForUnsupportedAnnot(const CPDF_Annot* pAnnot);
diff --git a/fpdfsdk/fpdf_ext.cpp b/fpdfsdk/fpdf_ext.cpp
index e757481..acb40de 100644
--- a/fpdfsdk/fpdf_ext.cpp
+++ b/fpdfsdk/fpdf_ext.cpp
@@ -74,8 +74,7 @@
if (!unsp_info || unsp_info->version != 1)
return false;
- CPDF_ModuleMgr::Get()->SetUnsupportInfoAdapter(
- pdfium::MakeUnique<fpdfapi::UnsupportedInfoAdapter>(unsp_info));
+ SetPDFUnsupportInfo(unsp_info);
return true;
}