[fpdfapi] Refactor references in `CPDF_PageModule` class into separate functions

Prevent polluting the global namespace.

Fixed: 381214203
Change-Id: Ibe9ac14358837c5fd60fca077140c52d5002f225
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/126690
Commit-Queue: Thomas Sepez <tsepez@google.com>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Thomas Sepez <tsepez@google.com>
diff --git a/core/fpdfapi/page/cpdf_pageimagecache_unittest.cpp b/core/fpdfapi/page/cpdf_pageimagecache_unittest.cpp
index 50986f1..9919f738 100644
--- a/core/fpdfapi/page/cpdf_pageimagecache_unittest.cpp
+++ b/core/fpdfapi/page/cpdf_pageimagecache_unittest.cpp
@@ -19,13 +19,15 @@
 #include "testing/gtest/include/gtest/gtest.h"
 #include "testing/utils/path_service.h"
 
+namespace pdfium {
+
 TEST(CPDFPageImageCache, RenderBug1924) {
   // If you render a page with a JPEG2000 image as a thumbnail (small picture)
   // first, the image that gets cached has a low resolution. If you afterwards
   // render it full-size, you should get a larger image - the image cache will
   // be regenerate.
 
-  CPDF_PageModule::Create();
+  InitializePageModule();
   {
     std::string file_path = PathService::GetTestFilePath("jpx_lzw.pdf");
     ASSERT_FALSE(file_path.empty());
@@ -77,5 +79,7 @@
     ASSERT_TRUE(page->AsPDFPage());
     page->AsPDFPage()->ClearView();
   }
-  CPDF_PageModule::Destroy();
+  DestroyPageModule();
 }
+
+}  // namespace pdfium
diff --git a/core/fpdfapi/page/cpdf_pagemodule.cpp b/core/fpdfapi/page/cpdf_pagemodule.cpp
index f606c28..c00ed3f 100644
--- a/core/fpdfapi/page/cpdf_pagemodule.cpp
+++ b/core/fpdfapi/page/cpdf_pagemodule.cpp
@@ -10,17 +10,19 @@
 #include "core/fpdfapi/page/cpdf_colorspace.h"
 #include "core/fpdfapi/page/cpdf_streamcontentparser.h"
 
-// static
-void CPDF_PageModule::Create() {
+namespace pdfium {
+
+void InitializePageModule() {
   CPDF_ColorSpace::InitializeGlobals();
   CPDF_FontGlobals::Create();
   CPDF_FontGlobals::GetInstance()->LoadEmbeddedMaps();
   CPDF_StreamContentParser::InitializeGlobals();
 }
 
-// static
-void CPDF_PageModule::Destroy() {
+void DestroyPageModule() {
   CPDF_StreamContentParser::DestroyGlobals();
   CPDF_FontGlobals::Destroy();
   CPDF_ColorSpace::DestroyGlobals();
 }
+
+}  // namespace pdfium
diff --git a/core/fpdfapi/page/cpdf_pagemodule.h b/core/fpdfapi/page/cpdf_pagemodule.h
index bd55488..59fd779 100644
--- a/core/fpdfapi/page/cpdf_pagemodule.h
+++ b/core/fpdfapi/page/cpdf_pagemodule.h
@@ -7,12 +7,14 @@
 #ifndef CORE_FPDFAPI_PAGE_CPDF_PAGEMODULE_H_
 #define CORE_FPDFAPI_PAGE_CPDF_PAGEMODULE_H_
 
-// TODO(thestig): Replace with class with standalone functions without polluting
-// the global namespace.
-class CPDF_PageModule {
- public:
-  static void Create();
-  static void Destroy();
-};
+namespace pdfium {
+
+// Initializes the page module.
+void InitializePageModule();
+
+// Tears down the page module.
+void DestroyPageModule();
+
+}  // namespace pdfium
 
 #endif  // CORE_FPDFAPI_PAGE_CPDF_PAGEMODULE_H_
diff --git a/core/fpdfapi/page/test_with_page_module.cpp b/core/fpdfapi/page/test_with_page_module.cpp
index 0515ad9..92d842d 100644
--- a/core/fpdfapi/page/test_with_page_module.cpp
+++ b/core/fpdfapi/page/test_with_page_module.cpp
@@ -7,9 +7,9 @@
 #include "core/fpdfapi/page/cpdf_pagemodule.h"
 
 void TestWithPageModule::SetUp() {
-  CPDF_PageModule::Create();
+  pdfium::InitializePageModule();
 }
 
 void TestWithPageModule::TearDown() {
-  CPDF_PageModule::Destroy();
+  pdfium::DestroyPageModule();
 }
diff --git a/core/fpdfapi/parser/fpdf_parser_utility_unittest.cpp b/core/fpdfapi/parser/fpdf_parser_utility_unittest.cpp
index 898ab62..6b9caf5 100644
--- a/core/fpdfapi/parser/fpdf_parser_utility_unittest.cpp
+++ b/core/fpdfapi/parser/fpdf_parser_utility_unittest.cpp
@@ -15,6 +15,8 @@
 #include "core/fpdfapi/parser/cpdf_test_document.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
+namespace pdfium {
+
 TEST(ParserUtilityTest, NameDecode) {
   EXPECT_EQ("", PDF_NameDecode(""));
   EXPECT_EQ("A", PDF_NameDecode("A"));
@@ -53,7 +55,7 @@
 }
 
 TEST(ParserUtilityTest, ValidateDictAllResourcesOfType) {
-  CPDF_PageModule::Create();
+  InitializePageModule();
 
   {
     // Direct dictionary.
@@ -102,7 +104,7 @@
     EXPECT_FALSE(ValidateDictAllResourcesOfType(dict.Get(), "bar"));
   }
 
-  CPDF_PageModule::Destroy();
+  DestroyPageModule();
 }
 
 TEST(ParserUtilityTest, ValidateDictOptionalType) {
@@ -122,3 +124,5 @@
   EXPECT_TRUE(ValidateDictOptionalType(dict.Get(), "foo"));
   EXPECT_FALSE(ValidateDictOptionalType(dict.Get(), "bar"));
 }
+
+}  // namespace pdfium
diff --git a/core/fpdfdoc/cpdf_formfield_unittest.cpp b/core/fpdfdoc/cpdf_formfield_unittest.cpp
index 766a428..a3a92c5 100644
--- a/core/fpdfdoc/cpdf_formfield_unittest.cpp
+++ b/core/fpdfdoc/cpdf_formfield_unittest.cpp
@@ -31,8 +31,8 @@
  public:
   FX_STACK_ALLOCATED();
 
-  ScopedCPDF_PageModule() { CPDF_PageModule::Create(); }
-  ~ScopedCPDF_PageModule() { CPDF_PageModule::Destroy(); }
+  ScopedCPDF_PageModule() { pdfium::InitializePageModule(); }
+  ~ScopedCPDF_PageModule() { pdfium::DestroyPageModule(); }
 };
 
 void TestMultiselectFieldDict(RetainPtr<CPDF_Array> opt_array,
diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp
index 7b0caf7..4128b6c 100644
--- a/fpdfsdk/fpdf_view.cpp
+++ b/fpdfsdk/fpdf_view.cpp
@@ -233,7 +233,7 @@
   FX_InitializeMemoryAllocators();
   CFX_Timer::InitializeGlobals();
   CFX_GEModule::Create(config ? config->m_pUserFontPaths : nullptr);
-  CPDF_PageModule::Create();
+  pdfium::InitializePageModule();
 
 #if defined(PDF_USE_SKIA)
   CFX_GlyphCache::InitializeGlobals();
@@ -271,7 +271,7 @@
   CFX_GlyphCache::DestroyGlobals();
 #endif
 
-  CPDF_PageModule::Destroy();
+  pdfium::DestroyPageModule();
   CFX_GEModule::Destroy();
   CFX_Timer::DestroyGlobals();
   FX_DestroyMemoryAllocators();
diff --git a/xfa/fgas/crt/cfgas_stringformatter_unittest.cpp b/xfa/fgas/crt/cfgas_stringformatter_unittest.cpp
index 75fe732..8694960 100644
--- a/xfa/fgas/crt/cfgas_stringformatter_unittest.cpp
+++ b/xfa/fgas/crt/cfgas_stringformatter_unittest.cpp
@@ -23,9 +23,11 @@
 
 class CFGASStringFormatterTest : public FXGCUnitTest {
  public:
-  CFGASStringFormatterTest() : scoped_tz_("UTC") { CPDF_PageModule::Create(); }
+  CFGASStringFormatterTest() : scoped_tz_("UTC") {
+    pdfium::InitializePageModule();
+  }
 
-  ~CFGASStringFormatterTest() override { CPDF_PageModule::Destroy(); }
+  ~CFGASStringFormatterTest() override { pdfium::DestroyPageModule(); }
 
   CXFA_LocaleMgr* Mgr(const WideString& locale) {
     return cppgc::MakeGarbageCollected<CXFA_LocaleMgr>(