-
Notifications
You must be signed in to change notification settings - Fork 168
/
pdfium.patch
90 lines (80 loc) 路 2.62 KB
/
pdfium.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp
index 6b0a1c161..7a8788676 100644
--- a/fpdfsdk/fpdf_view.cpp
+++ b/fpdfsdk/fpdf_view.cpp
@@ -57,6 +57,9 @@
#ifdef PDF_ENABLE_V8
#include "fxjs/cfx_v8_array_buffer_allocator.h"
+#include "v8/include/libplatform/libplatform.h"
+#include "v8/include/v8-array-buffer.h"
+#include "v8/include/v8-initialization.h"
#endif
#ifdef PDF_ENABLE_XFA
@@ -117,6 +120,11 @@ namespace {
bool g_bLibraryInitialized = false;
+#ifdef PDF_ENABLE_V8
+v8::Platform* g_platform = nullptr;
+v8::Isolate* g_isolate = nullptr;
+#endif
+
void SetRendererType(FPDF_RENDERER_TYPE public_type) {
// Internal definition of renderer types must stay updated with respect to
// the public definition, such that all public definitions can be mapped to
@@ -229,6 +237,22 @@ FPDF_InitLibraryWithConfig(const FPDF_LIBRARY_CONFIG* config) {
if (g_bLibraryInitialized)
return;
+#ifdef PDF_ENABLE_V8
+ g_platform = v8::platform::NewDefaultPlatform().release();
+ v8::V8::InitializePlatform(g_platform);
+
+#ifdef PDF_ENABLE_XFA
+ cppgc::InitializeProcess(g_platform->GetPageAllocator());
+#endif
+
+ v8::V8::Initialize();
+
+ v8::Isolate::CreateParams params;
+ params.array_buffer_allocator = static_cast<v8::ArrayBuffer::Allocator*>(
+ FPDF_GetArrayBufferAllocatorSharedInstance());
+ g_isolate = v8::Isolate::New(params);
+#endif // PDF_ENABLE_V8
+
FX_InitializeMemoryAllocators();
CFX_Timer::InitializeGlobals();
CFX_GEModule::Create(config ? config->m_pUserFontPaths : nullptr);
@@ -242,14 +266,13 @@ FPDF_InitLibraryWithConfig(const FPDF_LIBRARY_CONFIG* config) {
CPDFXFA_ModuleInit();
#endif // PDF_ENABLE_XFA
- if (config && config->version >= 2) {
- void* platform = config->version >= 3 ? config->m_pPlatform : nullptr;
- IJS_Runtime::Initialize(config->m_v8EmbedderSlot, config->m_pIsolate,
- platform);
+#if PDF_ENABLE_V8
+ IJS_Runtime::Initialize(0, g_isolate, g_platform);
+#endif // PDF_ENABLE_V8
+
+ if (config && config->version >= 4)
+ SetRendererType(config->m_RendererType);
- if (config->version >= 4)
- SetRendererType(config->m_RendererType);
- }
g_bLibraryInitialized = true;
}
@@ -275,6 +298,19 @@ FPDF_EXPORT void FPDF_CALLCONV FPDF_DestroyLibrary() {
CFX_Timer::DestroyGlobals();
FX_DestroyMemoryAllocators();
+#ifdef PDF_ENABLE_XFA
+ cppgc::ShutdownProcess();
+#endif
+
+#ifdef PDF_ENABLE_V8
+ g_isolate->Dispose();
+ g_isolate = nullptr;
+ v8::V8::Dispose();
+ v8::V8::DisposePlatform();
+ delete g_platform;
+ g_platform = nullptr;
+#endif // PDF_ENABLE_V8
+
g_bLibraryInitialized = false;
}