summaryrefslogtreecommitdiff
path: root/fpdfsdk/src/javascript
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-11-25 16:05:49 -0800
committerTom Sepez <tsepez@chromium.org>2015-11-25 16:05:49 -0800
commit51da093564cdfd32a6ac02ad75e981787a0f1b35 (patch)
tree9885c9445759de43e45db33a975b79de45b8dd8a /fpdfsdk/src/javascript
parent43dd873cb0e92ca777d3ed9d905bc7955556220b (diff)
downloadpdfium-51da093564cdfd32a6ac02ad75e981787a0f1b35.tar.xz
Inflict PDF_ENABLE_XFA ifdefs on XFA fpdfsdk/
R=thestig@chromium.org Review URL: https://codereview.chromium.org/1477583002 .
Diffstat (limited to 'fpdfsdk/src/javascript')
-rw-r--r--fpdfsdk/src/javascript/JS_Context.cpp2
-rw-r--r--fpdfsdk/src/javascript/JS_Runtime.cpp31
-rw-r--r--fpdfsdk/src/javascript/JS_Runtime.h2
-rw-r--r--fpdfsdk/src/javascript/JS_Runtime_Stub.cpp2
-rw-r--r--fpdfsdk/src/javascript/app.cpp4
5 files changed, 41 insertions, 0 deletions
diff --git a/fpdfsdk/src/javascript/JS_Context.cpp b/fpdfsdk/src/javascript/JS_Context.cpp
index 76988d5ef6..e59b1a77ed 100644
--- a/fpdfsdk/src/javascript/JS_Context.cpp
+++ b/fpdfsdk/src/javascript/JS_Context.cpp
@@ -35,7 +35,9 @@ CPDFDoc_Environment* CJS_Context::GetReaderApp() {
FX_BOOL CJS_Context::RunScript(const CFX_WideString& script,
CFX_WideString* info) {
v8::Isolate::Scope isolate_scope(m_pRuntime->GetIsolate());
+#ifdef PDF_ENABLE_XFA
v8::Locker locker(m_pRuntime->GetIsolate());
+#endif
v8::HandleScope handle_scope(m_pRuntime->GetIsolate());
v8::Local<v8::Context> context = m_pRuntime->NewJSContext();
v8::Context::Scope context_scope(context);
diff --git a/fpdfsdk/src/javascript/JS_Runtime.cpp b/fpdfsdk/src/javascript/JS_Runtime.cpp
index b195b42957..2d0d7f6e76 100644
--- a/fpdfsdk/src/javascript/JS_Runtime.cpp
+++ b/fpdfsdk/src/javascript/JS_Runtime.cpp
@@ -6,8 +6,10 @@
#include "JS_Runtime.h"
+#ifdef PDF_ENABLE_XFA
#include "../../../xfa/src/fxjse/src/value.h"
#include "../../include/fpdfxfa/fpdfxfa_app.h"
+#endif
#include "Consts.h"
#include "Document.h"
#include "Field.h"
@@ -51,6 +53,15 @@ CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp)
m_bBlocking(FALSE),
m_isolate(NULL),
m_isolateManaged(false) {
+#ifndef PDF_ENABLE_XFA
+ IPDF_JSPLATFORM* pPlatform = m_pApp->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;
+#else
if (CPDFXFA_App::GetInstance()->GetJSERuntime()) {
// TODO(tsepez): CPDFXFA_App should also use the embedder provided isolate.
m_isolate = (v8::Isolate*)CPDFXFA_App::GetInstance()->GetJSERuntime();
@@ -64,7 +75,11 @@ CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp)
embedderDataSlot = pPlatform->m_v8EmbedderSlot;
}
FXJS_Initialize(embedderDataSlot, pExternalIsolate);
+#endif
}
+#ifndef PDF_ENABLE_XFA
+ FXJS_Initialize(embedderDataSlot, pExternalIsolate);
+#else
m_isolateManaged = FXJS_GetIsolate(&m_isolate);
}
@@ -77,13 +92,20 @@ CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp)
FXJS_InitializeRuntime(GetIsolate(), this, &m_context, &m_StaticObjects);
ReleaseContext(pContext);
return;
+#endif
}
+#ifndef PDF_ENABLE_XFA
+ m_isolateManaged = FXJS_GetIsolate(&m_isolate);
+#else
+#endif
if (m_isolateManaged || FXJS_GlobalIsolateRefCount() == 0)
DefineJSObjects();
+#ifdef PDF_ENABLE_XFA
CPDFXFA_App::GetInstance()->SetJavaScriptInitialized(TRUE);
+#endif
CJS_Context* pContext = (CJS_Context*)NewContext();
FXJS_InitializeRuntime(GetIsolate(), this, &m_context, &m_StaticObjects);
ReleaseContext(pContext);
@@ -97,6 +119,9 @@ CJS_Runtime::~CJS_Runtime() {
delete m_ContextArray.GetAt(i);
m_ContextArray.RemoveAll();
+#ifndef PDF_ENABLE_XFA
+ FXJS_ReleaseRuntime(GetIsolate(), &m_context, &m_StaticObjects);
+#endif
m_pApp = NULL;
m_pDocument = NULL;
@@ -108,7 +133,9 @@ CJS_Runtime::~CJS_Runtime() {
void CJS_Runtime::DefineJSObjects() {
v8::Isolate::Scope isolate_scope(GetIsolate());
+#ifdef PDF_ENABLE_XFA
v8::Locker locker(GetIsolate());
+#endif
v8::HandleScope handle_scope(GetIsolate());
v8::Local<v8::Context> context = v8::Context::New(GetIsolate());
v8::Context::Scope context_scope(context);
@@ -181,7 +208,9 @@ IJS_Context* CJS_Runtime::GetCurrentContext() {
void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc) {
if (m_pDocument != pReaderDoc) {
v8::Isolate::Scope isolate_scope(m_isolate);
+#ifdef PDF_ENABLE_XFA
v8::Locker locker(m_isolate);
+#endif
v8::HandleScope handle_scope(m_isolate);
v8::Local<v8::Context> context =
v8::Local<v8::Context>::New(m_isolate, m_context);
@@ -227,6 +256,7 @@ v8::Local<v8::Context> CJS_Runtime::NewJSContext() {
return v8::Local<v8::Context>::New(m_isolate, m_context);
}
+#ifdef PDF_ENABLE_XFA
CFX_WideString ChangeObjName(const CFX_WideString& str) {
CFX_WideString sRet = str;
sRet.Replace(L"_", L".");
@@ -293,6 +323,7 @@ FX_BOOL CJS_Runtime::SetHValueByName(const CFX_ByteStringC& utf8Name,
return TRUE;
}
+#endif
void CJS_Runtime::AddObserver(Observer* observer) {
ASSERT(m_observers.find(observer) == m_observers.end());
m_observers.insert(observer);
diff --git a/fpdfsdk/src/javascript/JS_Runtime.h b/fpdfsdk/src/javascript/JS_Runtime.h
index 2353517016..6de2b705a5 100644
--- a/fpdfsdk/src/javascript/JS_Runtime.h
+++ b/fpdfsdk/src/javascript/JS_Runtime.h
@@ -58,12 +58,14 @@ class CJS_Runtime : public IJS_Runtime {
v8::Isolate* GetIsolate() const { return m_isolate; }
v8::Local<v8::Context> NewJSContext();
+#ifdef PDF_ENABLE_XFA
// IJS_Runtime:
FX_BOOL GetHValueByName(const CFX_ByteStringC& utf8Name,
FXJSE_HVALUE hValue) override;
FX_BOOL SetHValueByName(const CFX_ByteStringC& utf8Name,
FXJSE_HVALUE hValue) override;
+#endif
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
diff --git a/fpdfsdk/src/javascript/JS_Runtime_Stub.cpp b/fpdfsdk/src/javascript/JS_Runtime_Stub.cpp
index 90d19d9451..b538066190 100644
--- a/fpdfsdk/src/javascript/JS_Runtime_Stub.cpp
+++ b/fpdfsdk/src/javascript/JS_Runtime_Stub.cpp
@@ -136,6 +136,7 @@ class CJS_RuntimeStub final : public IJS_Runtime {
}
CPDFSDK_Document* GetReaderDocument() override { return m_pDoc; }
+#ifdef PDF_ENABLE_XFA
virtual FX_BOOL GetHValueByName(const CFX_ByteStringC&,
FXJSE_HVALUE) override {
return FALSE;
@@ -146,6 +147,7 @@ class CJS_RuntimeStub final : public IJS_Runtime {
return FALSE;
}
+#endif
int Execute(IJS_Context* cc,
const wchar_t* script,
CFX_WideString* info) override {
diff --git a/fpdfsdk/src/javascript/app.cpp b/fpdfsdk/src/javascript/app.cpp
index 09b14440fb..d18e0322ab 100644
--- a/fpdfsdk/src/javascript/app.cpp
+++ b/fpdfsdk/src/javascript/app.cpp
@@ -47,7 +47,9 @@ CJS_Timer* TimerObj::GetTimer() const {
#define JS_STR_PLATFORM L"WIN"
#define JS_STR_LANGUANGE L"ENU"
#define JS_NUM_VIEWERVERSION 8
+#ifdef PDF_ENABLE_XFA
#define JS_NUM_VIEWERVERSION_XFA 11
+#endif
#define JS_NUM_FORMSVERSION 7
BEGIN_JS_STATIC_CONST(CJS_App)
@@ -198,6 +200,7 @@ FX_BOOL app::viewerVersion(IJS_Context* cc,
if (!vp.IsGetting())
return FALSE;
+#ifdef PDF_ENABLE_XFA
CJS_Context* pContext = (CJS_Context*)cc;
CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument();
CPDFXFA_Document* pDoc = pCurDoc->GetXFADocument();
@@ -206,6 +209,7 @@ FX_BOOL app::viewerVersion(IJS_Context* cc,
return TRUE;
}
+#endif
vp << JS_NUM_VIEWERVERSION;
return TRUE;
}