forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdf_ppapi.cc
86 lines (65 loc) · 2.05 KB
/
pdf_ppapi.cc
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
// Copyright 2018 The Chromium 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 "pdf/pdf_ppapi.h"
#include <memory>
#include "pdf/out_of_process_instance.h"
#include "ppapi/c/ppp.h"
#include "ppapi/cpp/private/internal_module.h"
#include "ppapi/cpp/private/pdf.h"
#include "v8/include/v8.h"
namespace chrome_pdf {
namespace {
bool g_sdk_initialized_via_pepper = false;
class PDFModule : public pp::Module {
public:
PDFModule();
~PDFModule() override;
// pp::Module implementation.
bool Init() override;
pp::Instance* CreateInstance(PP_Instance instance) override;
};
PDFModule::PDFModule() = default;
PDFModule::~PDFModule() {
if (g_sdk_initialized_via_pepper) {
ShutdownSDK();
g_sdk_initialized_via_pepper = false;
}
}
bool PDFModule::Init() {
return true;
}
pp::Instance* PDFModule::CreateInstance(PP_Instance instance) {
if (!g_sdk_initialized_via_pepper) {
v8::StartupData snapshot;
pp::PDF::GetV8ExternalSnapshotData(pp::InstanceHandle(instance),
&snapshot.data, &snapshot.raw_size);
if (snapshot.data) {
v8::V8::SetSnapshotDataBlob(&snapshot);
}
InitializeSDK(/*enable_v8=*/true);
g_sdk_initialized_via_pepper = true;
}
return new OutOfProcessInstance(instance);
}
} // namespace
int32_t PPP_InitializeModule(PP_Module module_id,
PPB_GetInterface get_browser_interface) {
auto module = std::make_unique<PDFModule>();
if (!module->InternalInit(module_id, get_browser_interface))
return PP_ERROR_FAILED;
pp::InternalSetModuleSingleton(module.release());
return PP_OK;
}
void PPP_ShutdownModule() {
delete pp::Module::Get();
pp::InternalSetModuleSingleton(nullptr);
}
const void* PPP_GetInterface(const char* interface_name) {
auto* module = pp::Module::Get();
return module ? module->GetPluginInterface(interface_name) : nullptr;
}
bool IsSDKInitializedViaPepper() {
return g_sdk_initialized_via_pepper;
}
} // namespace chrome_pdf