summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJochen Eisinger <jochen@chromium.org>2015-07-30 17:44:35 +0200
committerJochen Eisinger <jochen@chromium.org>2015-07-30 17:44:35 +0200
commit06b60021edacf7e4f2d1b1468a3aa898bab10301 (patch)
tree6c0177fefc0d839594abe81224fde3aae9951352
parent4e57057c361897834b77b4c84b412f949427f974 (diff)
downloadpdfium-06b60021edacf7e4f2d1b1468a3aa898bab10301.tar.xz
Merge to XFA: Plumb in an externally created v8::Isolate
Origin Review URL: - https://codereview.chromium.org/1234053003 - https://codereview.chromium.org/1241863004 - https://codereview.chromium.org/1235303003 R=tsepez@chromium.org BUG= Review URL: https://codereview.chromium.org/1263963002 .
-rw-r--r--fpdfsdk/include/jsapi/fxjs_v8.h2
-rw-r--r--fpdfsdk/src/javascript/JS_Runtime.cpp18
-rw-r--r--fpdfsdk/src/jsapi/fxjs_v8.cpp33
-rw-r--r--public/fpdf_formfill.h22
-rw-r--r--samples/pdfium_test.cc2
-rw-r--r--testing/embedder_test.cpp2
6 files changed, 55 insertions, 24 deletions
diff --git a/fpdfsdk/include/jsapi/fxjs_v8.h b/fpdfsdk/include/jsapi/fxjs_v8.h
index 21a6365569..e291898701 100644
--- a/fpdfsdk/include/jsapi/fxjs_v8.h
+++ b/fpdfsdk/include/jsapi/fxjs_v8.h
@@ -63,7 +63,7 @@ int JS_DefineGlobalConst(IJS_Runtime* pJSRuntime, const wchar_t* sConstNa
void JS_InitialRuntime(IJS_Runtime* pJSRuntime,IFXJS_Runtime* pFXRuntime, IFXJS_Context* context, v8::Global<v8::Context>& v8PersistentContext);
void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, v8::Global<v8::Context>& v8PersistentContext);
-void JS_Initial();
+void JS_Initial(unsigned int embedderDataSlot);
void JS_Release();
int JS_Parse(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, const wchar_t* script, long length, FXJSErr* perror);
int JS_Execute(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, const wchar_t* script, long length, FXJSErr* perror);
diff --git a/fpdfsdk/src/javascript/JS_Runtime.cpp b/fpdfsdk/src/javascript/JS_Runtime.cpp
index 346b642913..d68b268591 100644
--- a/fpdfsdk/src/javascript/JS_Runtime.cpp
+++ b/fpdfsdk/src/javascript/JS_Runtime.cpp
@@ -37,7 +37,11 @@ IFXJS_Runtime* CJS_RuntimeFactory::NewJSRuntime(CPDFDoc_Environ
{
if (!m_bInit)
{
- JS_Initial();
+ unsigned int embedderDataSlot = 0;
+ if (pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) {
+ embedderDataSlot = pApp->GetFormFillInfo()->m_pJsPlatform->m_v8EmbedderSlot;
+ }
+ JS_Initial(embedderDataSlot);
m_bInit = TRUE;
}
return new CJS_Runtime(pApp);
@@ -107,16 +111,22 @@ CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) :
m_pApp(pApp),
m_pDocument(NULL),
m_bBlocking(FALSE),
- m_pFieldEventPath(NULL)
+ m_pFieldEventPath(NULL),
+ m_isolate(NULL)
{
if (CPDFXFA_App::GetInstance()->GetJSERuntime()) {
+ // TODO(tsepez): CPDFXFA_App should also use the embedder provided isolate.
m_isolate = (v8::Isolate*)CPDFXFA_App::GetInstance()->GetJSERuntime();
- } else {
+ } else if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) {
+ m_isolate = reinterpret_cast<v8::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* isolate = m_isolate;
v8::Isolate::Scope isolate_scope(isolate);
diff --git a/fpdfsdk/src/jsapi/fxjs_v8.cpp b/fpdfsdk/src/jsapi/fxjs_v8.cpp
index 24d7bcc50a..c3b1b925fa 100644
--- a/fpdfsdk/src/jsapi/fxjs_v8.cpp
+++ b/fpdfsdk/src/jsapi/fxjs_v8.cpp
@@ -26,6 +26,7 @@ static double GetNan()
{
return *(double*)g_nan;
}
+static unsigned int g_embedderDataSlot = 0u;
class CJS_PrivateData
@@ -78,11 +79,11 @@ int JS_DefineObj(IJS_Runtime* pJSRuntime, const wchar_t* sObjName, FXJSOBJTYPE e
v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray)
{
pArray = FX_NEW CFX_PtrArray();
- isolate->SetData(1, pArray);
+ isolate->SetData(g_embedderDataSlot, pArray);
}
CJS_ObjDefintion* pObjDef = FX_NEW CJS_ObjDefintion(isolate, sObjName, eObjType, pConstructor, pDestructor);
pArray->Add(pObjDef);
@@ -98,7 +99,7 @@ int JS_DefineObjMethod(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* s
CFX_WideString ws = CFX_WideString(sMethodName);
CFX_ByteString bsMethodName = ws.UTF8Encode();
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray) return 0;
if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0;
@@ -118,7 +119,7 @@ int JS_DefineObjProperty(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t*
CFX_WideString ws = CFX_WideString(sPropName);
CFX_ByteString bsPropertyName = ws.UTF8Encode();
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray) return 0;
if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0;
@@ -135,7 +136,7 @@ int JS_DefineObjAllProperties(IJS_Runtime* pJSRuntime, int nObjDefnID, v8::Named
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray) return 0;
if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0;
@@ -152,7 +153,7 @@ int JS_DefineObjConst(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sC
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray) return 0;
CFX_WideString ws = CFX_WideString(sConstName);
@@ -172,7 +173,7 @@ static v8::Global<v8::ObjectTemplate>& _getGlobalObjectTemplate(IJS_Runtime* pJS
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
ASSERT(pArray != NULL);
for(int i=0; i<pArray->GetSize(); i++)
{
@@ -245,9 +246,10 @@ void JS_InitialRuntime(IJS_Runtime* pJSRuntime,IFXJS_Runtime* pFXRuntime, IFXJS_
//v8::Local<External> ptr = External::New(isolate, pFXRuntime);
//v8Context->SetEmbedderData(1, ptr);
+ // TODO(tsepez): Don't use more than one embedder data slot.
isolate->SetData(2, pFXRuntime);
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray) return;
for(int i=0; i<pArray->GetSize(); i++)
@@ -291,7 +293,7 @@ void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, v8::Global<v8::Context>& v8Persi
v8::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray) return ;
for(int i=0; i<pArray->GetSize(); i++)
@@ -308,11 +310,14 @@ void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, v8::Global<v8::Context>& v8Persi
}
delete pArray;
isolate->SetData(1,NULL);
+ isolate->SetData(g_embedderDataSlot,NULL);
+ // TODO(tsepez): Don't use more than one embedder data slot.
isolate->SetData(2,NULL);
}
-void JS_Initial()
+void JS_Initial(unsigned int embedderDataSlot)
{
+ g_embedderDataSlot = embedderDataSlot;
}
void JS_Release()
{
@@ -374,7 +379,7 @@ v8::Local<v8::Object> JS_NewFxDynamicObj(IJS_Runtime* pJSRuntime, IFXJS_Context*
return v8::Local<v8::Object>();
}
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray) return v8::Local<v8::Object>();
@@ -399,7 +404,7 @@ v8::Local<v8::Object> JS_GetStaticObj(IJS_Runtime* pJSRuntime, int nObjDefnID)
v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
v8::Isolate::Scope isolate_scope(isolate);
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray) return v8::Local<v8::Object>();
if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return v8::Local<v8::Object>();
@@ -418,7 +423,7 @@ v8::Local<v8::Object> JS_GetThisObj(IJS_Runtime * pJSRuntime)
v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
v8::Isolate::Scope isolate_scope(isolate);
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray) return v8::Local<v8::Object>();
v8::Local<v8::Context> context = isolate->GetCurrentContext();
@@ -447,7 +452,7 @@ int JS_GetObjDefnID(IJS_Runtime * pJSRuntime, const wchar_t* pObjName)
v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
v8::Isolate::Scope isolate_scope(isolate);
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray) return -1;
for(int i=0; i<pArray->GetSize(); i++)
diff --git a/public/fpdf_formfill.h b/public/fpdf_formfill.h
index 4b0db76fcb..fda0a87f97 100644
--- a/public/fpdf_formfill.h
+++ b/public/fpdf_formfill.h
@@ -22,11 +22,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.
@@ -228,6 +230,20 @@ 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;
+
+ /**
+ * The embedder data slot to use in the v8::Isolate to store PDFium's
+ * per-isolate data. The value needs to be between 0 and
+ * v8::Internals::kNumIsolateDataLots (exclusive).
+ */
+ unsigned int m_v8EmbedderSlot;
} IPDF_JSPLATFORM;
// Flags for Cursor type
diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc
index aa171afe3f..7ecd9a2aee 100644
--- a/samples/pdfium_test.cc
+++ b/samples/pdfium_test.cc
@@ -427,7 +427,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 72b858d276..d819d9c2a2 100644
--- a/testing/embedder_test.cpp
+++ b/testing/embedder_test.cpp
@@ -224,7 +224,7 @@ bool EmbedderTest::OpenDocument(const std::string& filename) {
IPDF_JSPLATFORM* platform = static_cast<IPDF_JSPLATFORM*>(this);
memset(platform, 0, sizeof(IPDF_JSPLATFORM));
- platform->version = 1;
+ platform->version = 2;
platform->app_alert = AlertTrampoline;
FPDF_FORMFILLINFO* formfillinfo = static_cast<FPDF_FORMFILLINFO*>(this);