Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(544)

Unified Diff: fpdfsdk/javascript/cjs_runtime.cpp

Issue 2421603002: Reland: Make the CPDFXFA_App non-global (Closed)
Patch Set: Review feedback Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « fpdfsdk/fpdfxfa/cpdfxfa_document.cpp ('k') | fxjs/fxjs_v8.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fpdfsdk/javascript/cjs_runtime.cpp
diff --git a/fpdfsdk/javascript/cjs_runtime.cpp b/fpdfsdk/javascript/cjs_runtime.cpp
index d41726b315fa5752e984297cae26df9163a77962..637fa0a411b03ad99a27d3ec70e069fe0ba545aa 100644
--- a/fpdfsdk/javascript/cjs_runtime.cpp
+++ b/fpdfsdk/javascript/cjs_runtime.cpp
@@ -68,7 +68,7 @@ CJS_Runtime::CJS_Runtime(CPDFSDK_FormFillEnvironment* pFormFillEnv)
m_bBlocking(false),
m_isolateManaged(false) {
v8::Isolate* pIsolate = nullptr;
-#ifndef PDF_ENABLE_XFA
+
IPDF_JSPLATFORM* pPlatform = m_pFormFillEnv->GetFormFillInfo()->m_pJsPlatform;
if (pPlatform->version <= 2) {
unsigned int embedderDataSlot = 0;
@@ -81,44 +81,15 @@ CJS_Runtime::CJS_Runtime(CPDFSDK_FormFillEnvironment* pFormFillEnv)
}
m_isolateManaged = FXJS_GetIsolate(&pIsolate);
SetIsolate(pIsolate);
-#else
- if (CPDFXFA_App::GetInstance()->GetJSERuntime()) {
- // TODO(tsepez): CPDFXFA_App should also use the embedder provided isolate.
- pIsolate = CPDFXFA_App::GetInstance()->GetJSERuntime();
- SetIsolate(pIsolate);
- } else {
- IPDF_JSPLATFORM* pPlatform =
- m_pFormFillEnv->GetFormFillInfo()->m_pJsPlatform;
- if (pPlatform->version <= 2) {
- unsigned int embedderDataSlot = 0;
- v8::Isolate* pExternalIsolate = nullptr;
- if (pPlatform->version == 2) {
- pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate);
- embedderDataSlot = pPlatform->m_v8EmbedderSlot;
- }
- FXJS_Initialize(embedderDataSlot, pExternalIsolate);
- }
- m_isolateManaged = FXJS_GetIsolate(&pIsolate);
- SetIsolate(pIsolate);
- }
+#ifdef PDF_ENABLE_XFA
v8::Isolate::Scope isolate_scope(pIsolate);
v8::HandleScope handle_scope(pIsolate);
- if (CPDFXFA_App::GetInstance()->IsJavaScriptInitialized()) {
- CJS_Context* pContext = (CJS_Context*)NewContext();
- InitializeEngine();
- ReleaseContext(pContext);
- return;
- }
#endif
if (m_isolateManaged || FXJS_GlobalIsolateRefCount() == 0)
DefineJSObjects();
-#ifdef PDF_ENABLE_XFA
- CPDFXFA_App::GetInstance()->SetJavaScriptInitialized(TRUE);
-#endif
-
CJS_Context* pContext = (CJS_Context*)NewContext();
InitializeEngine();
ReleaseContext(pContext);
@@ -261,19 +232,9 @@ FX_BOOL CJS_Runtime::GetValueByName(const CFX_ByteStringC& utf8Name,
v8::Isolate::Scope isolate_scope(GetIsolate());
v8::HandleScope handle_scope(GetIsolate());
- v8::Local<v8::Context> old_context = GetIsolate()->GetCurrentContext();
v8::Local<v8::Context> context = NewLocalContext();
v8::Context::Scope context_scope(context);
- // Caution: We're about to hand to XFA an object that in order to invoke
- // methods will require that the current v8::Context always has a pointer
- // to a CJS_Runtime in its embedder data slot. Unfortunately, XFA creates
- // its own v8::Context which has not initialized the embedder data slot.
- // Do so now.
- // TODO(tsepez): redesign PDF-side objects to not rely on v8::Context's
- // embedder data slots, and/or to always use the right context.
- CFXJS_Engine::SetForV8Context(old_context, this);
-
v8::Local<v8::Value> propvalue =
context->Global()->Get(v8::String::NewFromUtf8(
GetIsolate(), name, v8::String::kNormalString, utf8Name.GetLength()));
« no previous file with comments | « fpdfsdk/fpdfxfa/cpdfxfa_document.cpp ('k') | fxjs/fxjs_v8.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698