diff options
-rw-r--r-- | BUILD.gn | 1 | ||||
-rw-r--r-- | core/fpdfapi/cpdf_modulemgr.h | 1 | ||||
-rw-r--r-- | fpdfsdk/fpdfview.cpp | 12 | ||||
-rw-r--r-- | fpdfsdk/fpdfview_unittest.cpp | 20 |
4 files changed, 31 insertions, 3 deletions
@@ -1734,6 +1734,7 @@ test("pdfium_unittests") { "core/fxge/dib/fx_dib_engine_unittest.cpp", "fpdfsdk/fpdfdoc_unittest.cpp", "fpdfsdk/fpdfeditimg_unittest.cpp", + "fpdfsdk/fpdfview_unittest.cpp", ] deps = [ ":pdfium", diff --git a/core/fpdfapi/cpdf_modulemgr.h b/core/fpdfapi/cpdf_modulemgr.h index 57c266619e..d31ffd5256 100644 --- a/core/fpdfapi/cpdf_modulemgr.h +++ b/core/fpdfapi/cpdf_modulemgr.h @@ -35,7 +35,6 @@ class CFSDK_UnsupportInfo_Adapter { class CPDF_ModuleMgr { public: static CPDF_ModuleMgr* Get(); - static void Create(); static void Destroy(); static const int kFileBufSize = 512; diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp index 1c27b6c69b..633cbe879e 100644 --- a/fpdfsdk/fpdfview.cpp +++ b/fpdfsdk/fpdfview.cpp @@ -50,6 +50,9 @@ namespace { +// Also indicates whether library is currently initialized. +CCodec_ModuleMgr* g_pCodecModule = nullptr; + void RenderPageImpl(CPDF_PageRenderContext* pContext, CPDF_Page* pPage, const CFX_Matrix& matrix, @@ -295,18 +298,20 @@ FPDF_BOOL FSDK_IsSandBoxPolicyEnabled(FPDF_DWORD policy) { } } -CCodec_ModuleMgr* g_pCodecModule = nullptr; - DLLEXPORT void STDCALL FPDF_InitLibrary() { FPDF_InitLibraryWithConfig(nullptr); } DLLEXPORT void STDCALL FPDF_InitLibraryWithConfig(const FPDF_LIBRARY_CONFIG* cfg) { + if (g_pCodecModule) + return; + g_pCodecModule = new CCodec_ModuleMgr(); CFX_GEModule* pModule = CFX_GEModule::Get(); pModule->Init(cfg ? cfg->m_pUserFontPaths : nullptr, g_pCodecModule); + CPDF_ModuleMgr* pModuleMgr = CPDF_ModuleMgr::Get(); pModuleMgr->SetCodecModule(g_pCodecModule); pModuleMgr->InitPageModule(); @@ -324,6 +329,9 @@ FPDF_InitLibraryWithConfig(const FPDF_LIBRARY_CONFIG* cfg) { } DLLEXPORT void STDCALL FPDF_DestroyLibrary() { + if (!g_pCodecModule) + return; + #ifdef PDF_ENABLE_XFA BC_Library_Destory(); FXJSE_Finalize(); diff --git a/fpdfsdk/fpdfview_unittest.cpp b/fpdfsdk/fpdfview_unittest.cpp new file mode 100644 index 0000000000..27680b3d4e --- /dev/null +++ b/fpdfsdk/fpdfview_unittest.cpp @@ -0,0 +1,20 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "public/fpdfview.h" + +#include "testing/gtest/include/gtest/gtest.h" +#include "testing/test_support.h" + +TEST(FPDFView, DoubleInit) { + FPDF_InitLibrary(); + FPDF_InitLibrary(); + FPDF_DestroyLibrary(); +} + +TEST(FPDFView, DoubleDestroy) { + FPDF_InitLibrary(); + FPDF_DestroyLibrary(); + FPDF_DestroyLibrary(); +} |