From 1c79928b4ade95806d0351a21b4d4727d6c8ed38 Mon Sep 17 00:00:00 2001 From: Jochen Eisinger Date: Wed, 15 Jul 2015 14:31:29 +0200 Subject: Plumb in an externally created v8::Isolate In Chrome, all Isolates must be created by gin R=tsepez@chromium.org, ulan@chromium.org BUG= Review URL: https://codereview.chromium.org/1234053003 . --- fpdfsdk/src/javascript/JS_Runtime.cpp | 16 +++++++++++----- public/fpdf_formfill.h | 13 +++++++++++-- samples/pdfium_test.cc | 2 +- testing/embedder_test.cpp | 2 +- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/fpdfsdk/src/javascript/JS_Runtime.cpp b/fpdfsdk/src/javascript/JS_Runtime.cpp index c2c1a51400..6ceb640e58 100644 --- a/fpdfsdk/src/javascript/JS_Runtime.cpp +++ b/fpdfsdk/src/javascript/JS_Runtime.cpp @@ -110,13 +110,19 @@ CJS_Runtime::CJS_Runtime(CPDFDoc_Environment * pApp) : m_pDocument(NULL), m_bBlocking(FALSE), m_bRegistered(FALSE), - m_pFieldEventPath(NULL) + m_pFieldEventPath(NULL), + m_isolate(NULL) { - m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator()); + if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { + m_isolate = m_pApp->GetFormFillInfo()->m_pJsPlatform->m_isolate; + } + if (!m_isolate) { + m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator()); - v8::Isolate::CreateParams params; - params.array_buffer_allocator = m_pArrayBufferAllocator.get(); - m_isolate = v8::Isolate::New(params); + v8::Isolate::CreateParams params; + params.array_buffer_allocator = m_pArrayBufferAllocator.get(); + m_isolate = v8::Isolate::New(params); + } InitJSObjects(); diff --git a/public/fpdf_formfill.h b/public/fpdf_formfill.h index a1b9ec2a77..1cc5551e0b 100644 --- a/public/fpdf_formfill.h +++ b/public/fpdf_formfill.h @@ -18,11 +18,13 @@ extern "C" { typedef struct _IPDF_JsPlatform { -/** -* Version number of the interface. Currently must be 1. + /** + * Version number of the interface. Currently must be 2. **/ int version; + /* Version 1. */ + /** * Method: app_alert * pop up a dialog to show warning or hint. @@ -222,6 +224,13 @@ typedef struct _IPDF_JsPlatform * pointer to FPDF_FORMFILLINFO interface. **/ void* m_pFormfillinfo; + + /* Version 2. */ + + /** + * pointer to the v8::Isolate to use, or NULL to force PDFium to create one. + **/ + void* m_isolate; } IPDF_JSPLATFORM; // Flags for Cursor type diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc index be126149ac..8ca26abd05 100644 --- a/samples/pdfium_test.cc +++ b/samples/pdfium_test.cc @@ -426,7 +426,7 @@ void RenderPdf(const std::string& name, const char* pBuf, size_t len, IPDF_JSPLATFORM platform_callbacks; memset(&platform_callbacks, '\0', sizeof(platform_callbacks)); - platform_callbacks.version = 1; + platform_callbacks.version = 2; platform_callbacks.app_alert = ExampleAppAlert; platform_callbacks.Doc_gotoPage = ExampleDocGotoPage; diff --git a/testing/embedder_test.cpp b/testing/embedder_test.cpp index ba33ca6e49..6d9907eb7e 100644 --- a/testing/embedder_test.cpp +++ b/testing/embedder_test.cpp @@ -214,7 +214,7 @@ bool EmbedderTest::OpenDocument(const std::string& filename) { IPDF_JSPLATFORM* platform = static_cast(this); memset(platform, 0, sizeof(IPDF_JSPLATFORM)); - platform->version = 1; + platform->version = 2; platform->app_alert = AlertTrampoline; FPDF_FORMFILLINFO* formfillinfo = static_cast(this); -- cgit v1.2.3