0

[unseasoned-pdf] Initialize gin::IsolateHolder for utility processes

When the "PdfUnseasoned" feature is enabled, gin::IsolateHolder
usually doesn't require being initialized because the plugin code lives
in a renderer process, where Blink has already performed the
initialization.

However, some utility processes use also use PDFium, and they still
require initialization.

Provide gin::IsolateHolder::Initialized() so PDFium can determine
whether the initialization has already been invoked.

Fixed: 1229814
Change-Id: I0e381297af32c9c615f06c92e882640b0012a522
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3033198
Reviewed-by: Jeremy Roman <jbroman@chromium.org>
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Cr-Commit-Position: refs/heads/master@{#902309}
This commit is contained in:
Daniel Hosseinian
2021-07-16 03:30:24 +00:00
committed by Chromium LUCI CQ
parent aaaf9285dc
commit b6c4aaaf47
3 changed files with 15 additions and 2 deletions

@ -55,11 +55,14 @@ IsolateHolder::IsolateHolder(
IsolateType isolate_type,
IsolateCreationMode isolate_creation_mode)
: access_mode_(access_mode), isolate_type_(isolate_type) {
CHECK(Initialized())
<< "You need to invoke gin::IsolateHolder::Initialize first";
DCHECK(task_runner);
DCHECK(task_runner->BelongsToCurrentThread());
v8::ArrayBuffer::Allocator* allocator = g_array_buffer_allocator;
CHECK(allocator) << "You need to invoke gin::IsolateHolder::Initialize first";
DCHECK(allocator);
isolate_ = v8::Isolate::Allocate();
isolate_data_ = std::make_unique<PerIsolateData>(isolate_, allocator,
@ -112,6 +115,11 @@ void IsolateHolder::Initialize(ScriptMode mode,
g_reference_table = reference_table;
}
// static
bool IsolateHolder::Initialized() {
return g_array_buffer_allocator;
}
void IsolateHolder::EnableIdleTasks(
std::unique_ptr<V8IdleTaskRunner> idle_task_runner) {
DCHECK(isolate_data_.get());

@ -91,6 +91,11 @@ class GIN_EXPORT IsolateHolder {
v8::ArrayBuffer::Allocator* allocator,
const intptr_t* reference_table = nullptr);
// Returns whether `Initialize` has already been invoked in the process.
// Initialization is a one-way operation (i.e., this method cannot return
// false after returning true).
static bool Initialized();
v8::Isolate* isolate() { return isolate_; }
// This method returns if v8::Locker is needed to access isolate.

@ -247,7 +247,7 @@ bool IsV8Initialized() {
}
void SetUpV8() {
if (!base::FeatureList::IsEnabled(features::kPdfUnseasoned)) {
if (!gin::IsolateHolder::Initialized()) {
// TODO(crbug.com/1111024): V8 flags for the Unseasoned Viewer need to be
// set up as soon as the renderer process is created in the constructor of
// `content::RenderProcessImpl`.