summaryrefslogtreecommitdiff
path: root/fpdfsdk/src/javascript
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk/src/javascript')
-rw-r--r--fpdfsdk/src/javascript/Document.cpp26
-rw-r--r--fpdfsdk/src/javascript/Field.cpp2
-rw-r--r--fpdfsdk/src/javascript/JS_Context.cpp1
-rw-r--r--fpdfsdk/src/javascript/JS_GlobalData.cpp2
-rw-r--r--fpdfsdk/src/javascript/JS_Object.cpp4
-rw-r--r--fpdfsdk/src/javascript/JS_Runtime.cpp74
-rw-r--r--fpdfsdk/src/javascript/app.cpp25
-rw-r--r--fpdfsdk/src/javascript/global.cpp5
8 files changed, 108 insertions, 31 deletions
diff --git a/fpdfsdk/src/javascript/Document.cpp b/fpdfsdk/src/javascript/Document.cpp
index 229d9770a1..fa3b9de75b 100644
--- a/fpdfsdk/src/javascript/Document.cpp
+++ b/fpdfsdk/src/javascript/Document.cpp
@@ -605,7 +605,7 @@ FX_BOOL Document::mailForm(OBJ_METHOD_PARAMS)
ASSERT(pRuntime != NULL);
pRuntime->BeginBlock();
- pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, (FX_LPCWSTR)cTo, (FX_LPCWSTR)cSubject, (FX_LPCWSTR)cCc, (FX_LPCWSTR)cBcc, (FX_LPCWSTR)cMsg);
+ pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, (FX_LPCWSTR)cTo, (FX_LPCWSTR)cSubject, (FX_LPCWSTR)cCc, (FX_LPCWSTR)cBcc, (FX_LPCWSTR)cMsg);
pRuntime->EndBlock();
return TRUE;
}
@@ -723,7 +723,7 @@ FX_BOOL Document::removeField(OBJ_METHOD_PARAMS)
CFX_RectArray aRefresh;
aRefresh.Add(rcAnnot);
- CPDF_Page* pPage = pWidget->GetPDFPage();
+ CPDFXFA_Page* pPage = pWidget->GetPDFXFAPage();
ASSERT(pPage != NULL);
CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage);
@@ -1009,7 +1009,7 @@ FX_BOOL Document::author(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetPDFDoc()->GetInfo();
if (!pDictionary)return FALSE;
if (vp.IsGetting())
@@ -1033,7 +1033,7 @@ FX_BOOL Document::info(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetPDFDoc()->GetInfo();
if (!pDictionary)return FALSE;
CFX_WideString cwAuthor = pDictionary->GetUnicodeText("Author");
@@ -1092,7 +1092,7 @@ FX_BOOL Document::creationDate(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetPDFDoc()->GetInfo();
if (!pDictionary)return FALSE;
if (vp.IsGetting())
@@ -1117,7 +1117,7 @@ FX_BOOL Document::creator(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetPDFDoc()->GetInfo();
if (!pDictionary)return FALSE;
if (vp.IsGetting())
@@ -1183,7 +1183,7 @@ FX_BOOL Document::keywords(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetPDFDoc()->GetInfo();
if (!pDictionary)return FALSE;
if (vp.IsGetting())
@@ -1207,7 +1207,7 @@ FX_BOOL Document::modDate(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetPDFDoc()->GetInfo();
if (!pDictionary)return FALSE;
if (vp.IsGetting())
@@ -1231,7 +1231,7 @@ FX_BOOL Document::producer(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetPDFDoc()->GetInfo();
if (!pDictionary)return FALSE;
if (vp.IsGetting())
@@ -1255,7 +1255,7 @@ FX_BOOL Document::subject(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetPDFDoc()->GetInfo();
if (!pDictionary)return FALSE;
if (vp.IsGetting())
@@ -1282,7 +1282,7 @@ FX_BOOL Document::title(OBJ_PROP_PARAMS)
if (m_pDocument == NULL || m_pDocument->GetDocument() == NULL)
return FALSE;
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetPDFDoc()->GetInfo();
if (!pDictionary)return FALSE;
if (vp.IsGetting())
@@ -1874,7 +1874,7 @@ FX_BOOL Document::getPageNthWord(OBJ_METHOD_PARAMS)
int nWordNo = params.GetSize() > 1 ? (int)params[1] : 0;
bool bStrip = params.GetSize() > 2 ? (bool)params[2] : true;
- CPDF_Document* pDocument = m_pDocument->GetDocument();
+ CPDF_Document* pDocument = m_pDocument->GetDocument()->GetPDFDoc();
if (!pDocument) return FALSE;
if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount())
@@ -1945,7 +1945,7 @@ FX_BOOL Document::getPageNumWords(OBJ_METHOD_PARAMS)
int nPageNo = params.GetSize() > 0 ? (int)params[0] : 0;
- CPDF_Document* pDocument = m_pDocument->GetDocument();
+ CPDF_Document* pDocument = m_pDocument->GetDocument()->GetPDFDoc();
ASSERT(pDocument != NULL);
if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount())
diff --git a/fpdfsdk/src/javascript/Field.cpp b/fpdfsdk/src/javascript/Field.cpp
index f5f9bf0539..c484cbb1fd 100644
--- a/fpdfsdk/src/javascript/Field.cpp
+++ b/fpdfsdk/src/javascript/Field.cpp
@@ -3820,7 +3820,7 @@ FX_BOOL Field::setFocus(OBJ_METHOD_PARAMS)
{
CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
ASSERT(pEnv);
- CPDF_Page* pPage = (CPDF_Page*)pEnv->FFI_GetCurrentPage(m_pDocument->GetDocument());
+ CPDFXFA_Page* pPage = (CPDFXFA_Page*)pEnv->FFI_GetCurrentPage(m_pDocument->GetDocument());
if(!pPage)
return FALSE;
if (CPDFSDK_PageView* pCurPageView = m_pDocument->GetPageView(pPage))
diff --git a/fpdfsdk/src/javascript/JS_Context.cpp b/fpdfsdk/src/javascript/JS_Context.cpp
index a83e1e057d..31969e4858 100644
--- a/fpdfsdk/src/javascript/JS_Context.cpp
+++ b/fpdfsdk/src/javascript/JS_Context.cpp
@@ -107,6 +107,7 @@ FX_BOOL CJS_Context::DoJob(int nMode, const CFX_WideString& script, CFX_WideStri
FX_BOOL CJS_Context::RunScript(const CFX_WideString& script, CFX_WideString& info)
{
v8::Isolate::Scope isolate_scope(m_pRuntime->GetIsolate());
+ v8::Locker locker(m_pRuntime->GetIsolate());
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_GlobalData.cpp b/fpdfsdk/src/javascript/JS_GlobalData.cpp
index 83771dfe57..2207726890 100644
--- a/fpdfsdk/src/javascript/JS_GlobalData.cpp
+++ b/fpdfsdk/src/javascript/JS_GlobalData.cpp
@@ -117,7 +117,7 @@ static const FX_BYTE JS_RC4KEY[] = {0x19,0xa8,0xe8,0x01,0xf6,0xa8,0xb6,0x4d,0x82
0x55,0x8b,0x6e,0x6b,0x19,0xa0,0xf8,0x77,0xd5,0xa3
};
-CJS_GlobalData::CJS_GlobalData(CPDFDoc_Environment* pApp)
+CJS_GlobalData::CJS_GlobalData(CPDFDoc_Environment* pApp) : m_pApp(pApp)
{
// IBaseAnnot* pBaseAnnot = IBaseAnnot::GetBaseAnnot(m_pApp);
// ASSERT(pBaseAnnot != NULL);
diff --git a/fpdfsdk/src/javascript/JS_Object.cpp b/fpdfsdk/src/javascript/JS_Object.cpp
index 3b7774d4d8..09150e796b 100644
--- a/fpdfsdk/src/javascript/JS_Object.cpp
+++ b/fpdfsdk/src/javascript/JS_Object.cpp
@@ -16,7 +16,7 @@ int FXJS_MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView, FX_LPCWS
{
int nRet = 0;
- if(pApp)
+ if (pApp)
{
CPDFSDK_Document* pDoc = pApp->GetCurrentDoc();
if(pDoc)
@@ -65,7 +65,7 @@ void CJS_EmbedObj::Alert(CJS_Context* pContext, FX_LPCWSTR swMsg)
CJS_Object::Alert(pContext, swMsg);
}
-CJS_Timer* CJS_EmbedObj::BeginTimer(CPDFDoc_Environment * pApp,FX_UINT nElapse)
+CJS_Timer* CJS_EmbedObj::BeginTimer(CPDFDoc_Environment* pApp, FX_UINT nElapse)
{
CJS_Timer* pTimer = new CJS_Timer(this,pApp);
pTimer->SetJSTimer(nElapse);
diff --git a/fpdfsdk/src/javascript/JS_Runtime.cpp b/fpdfsdk/src/javascript/JS_Runtime.cpp
index d7802b572e..269f23bbd7 100644
--- a/fpdfsdk/src/javascript/JS_Runtime.cpp
+++ b/fpdfsdk/src/javascript/JS_Runtime.cpp
@@ -26,6 +26,12 @@
#include "../../include/javascript/JS_GlobalData.h"
#include "../../include/javascript/global.h"
#include "../../include/javascript/console.h"
+#include "../../include/fpdfxfa/fpdfxfa_app.h"
+#ifndef FOXIT_CHROME_BUILD
+#include "../../../fxjse/value.h"
+#else
+#include "../../../xfa/src/fxjse/src/value.h"
+#endif
#include <libplatform/libplatform.h>
@@ -101,16 +107,26 @@ void CJS_RuntimeFactory::ReleaseGlobalData()
}
/* ------------------------------ CJS_Runtime ------------------------------ */
-
-CJS_Runtime::CJS_Runtime(CPDFDoc_Environment * pApp) :
+extern v8::Persistent<v8::ObjectTemplate>& _getGlobalObjectTemplate(IJS_Runtime* pJSRuntime);
+CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) :
m_pApp(pApp),
m_pDocument(NULL),
m_bBlocking(FALSE),
m_pFieldEventPath(NULL),
m_bRegistered(FALSE)
{
- m_isolate = v8::Isolate::New();
+ m_isolate = FPDFXFA_GetApp()->GetJSERuntime()?(v8::Isolate*)FPDFXFA_GetApp()->GetJSERuntime():v8::Isolate::New();
//m_isolate->Enter();
+ v8::Isolate* isolate = m_isolate;
+ v8::Isolate::Scope isolate_scope(isolate);
+ v8::Locker locker(isolate);
+ v8::HandleScope handle_scope(isolate);
+ if (FPDFXFA_GetApp()->InitRuntime(FALSE)) {
+ CJS_Context * pContext = (CJS_Context*)NewContext();
+ JS_InitialRuntime(*this, this, pContext, m_context);
+ ReleaseContext(pContext);
+ return;
+ }
InitJSObjects();
@@ -121,12 +137,13 @@ CJS_Runtime::CJS_Runtime(CPDFDoc_Environment * pApp) :
CJS_Runtime::~CJS_Runtime()
{
- for (int i=0, sz=m_ContextArray.GetSize(); i<sz; i++)
+ int size = m_ContextArray.GetSize();
+ for (int i=0;i < size; i++)
delete m_ContextArray.GetAt(i);
m_ContextArray.RemoveAll();
- JS_ReleaseRuntime(*this, m_context);
+ //JS_ReleaseRuntime(*this, m_context);
RemoveEventsInLoop(m_pFieldEventPath);
@@ -136,12 +153,14 @@ CJS_Runtime::~CJS_Runtime()
m_context.Reset();
//m_isolate->Exit();
- m_isolate->Dispose();
+ //m_isolate->Dispose();
+ m_isolate = NULL;
}
FX_BOOL CJS_Runtime::InitJSObjects()
{
v8::Isolate::Scope isolate_scope(GetIsolate());
+ v8::Locker locker(GetIsolate());
v8::HandleScope handle_scope(GetIsolate());
v8::Handle<v8::Context> context = v8::Context::New(GetIsolate());
v8::Context::Scope context_scope(context);
@@ -215,6 +234,7 @@ void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc)
if (m_pDocument != pReaderDoc)
{
v8::Isolate::Scope isolate_scope(m_isolate);
+ v8::Locker locker(m_isolate);
v8::HandleScope handle_scope(m_isolate);
v8::Local<v8::Context> context =v8::Local<v8::Context>::New(m_isolate, m_context);
v8::Context::Scope context_scope(context);
@@ -476,3 +496,45 @@ void CJS_Runtime::Enter()
{
if(m_isolate) m_isolate->Enter();
}
+FX_BOOL CJS_Runtime::GetHValueByName(FX_BSTR utf8Name, FXJSE_HVALUE hValue)
+{
+ FX_LPCSTR name = utf8Name.GetCStr();
+
+ v8::Locker lock(GetIsolate());
+ v8::Isolate::Scope isolate_scope(GetIsolate());
+ v8::HandleScope handle_scope(GetIsolate());
+ v8::Local<v8::Context> context =
+ v8::Local<v8::Context>::New(GetIsolate(), m_context);
+ v8::Context::Scope context_scope(context);
+
+
+ //v8::Local<v8::Context> tmpCotext = v8::Local<v8::Context>::New(GetIsolate(), m_context);
+ v8::Local<v8::Value> propvalue = context->Global()->Get(v8::String::NewFromUtf8(GetIsolate(), name, v8::String::kNormalString, utf8Name.GetLength()));
+
+ if (propvalue.IsEmpty()) {
+ FXJSE_Value_SetUndefined(hValue);
+ return FALSE;
+ }
+ ((CFXJSE_Value*)hValue)->ForceSetValue(propvalue);
+
+ return TRUE;
+}
+FX_BOOL CJS_Runtime::SetHValueByName(FX_BSTR utf8Name, FXJSE_HVALUE hValue)
+{
+ if (utf8Name.IsEmpty() || hValue == NULL)
+ return FALSE;
+ FX_LPCSTR name = utf8Name.GetCStr();
+ v8::Isolate* pIsolate = GetIsolate();
+ v8::Locker lock(pIsolate);
+ v8::Isolate::Scope isolate_scope(pIsolate);
+ v8::HandleScope handle_scope(pIsolate);
+ v8::Local<v8::Context> context =
+ v8::Local<v8::Context>::New(pIsolate, m_context);
+ v8::Context::Scope context_scope(context);
+
+ //v8::Local<v8::Context> tmpCotext = v8::Local<v8::Context>::New(GetIsolate(), m_context);
+ v8::Local<v8::Value> propvalue = v8::Local<v8::Value>::New(GetIsolate(),((CFXJSE_Value*)hValue)->DirectGetValue());
+ context->Global()->Set(v8::String::NewFromUtf8(pIsolate, name, v8::String::kNormalString, utf8Name.GetLength()), propvalue);
+
+ return TRUE;
+}
diff --git a/fpdfsdk/src/javascript/app.cpp b/fpdfsdk/src/javascript/app.cpp
index 1c4da08ccb..42692382c8 100644
--- a/fpdfsdk/src/javascript/app.cpp
+++ b/fpdfsdk/src/javascript/app.cpp
@@ -68,6 +68,7 @@ CJS_Timer* TimerObj::GetTimer() const
#define JS_STR_PLATFORM L"WIN"
#define JS_STR_LANGUANGE L"ENU"
#define JS_STR_VIEWERVERSION 8
+#define JS_STR_VIEWERVERSION_XFA 11
#define JS_NUM_FORMSVERSION 7
#define JS_FILEPATH_MAXLEN 2000
@@ -152,8 +153,8 @@ FX_BOOL app::activeDocs(OBJ_PROP_PARAMS)
CJS_Array aDocs(pRuntime->GetIsolate());
// int iNumDocs = pApp->CountDocuments();
-// for(int iIndex = 0; iIndex<iNumDocs; iIndex++)
-// {
+// for(int iIndex = 0; iIndex<iNumDocs; iIndex++)
+// {
CPDFSDK_Document* pDoc = pApp->GetCurrentDoc();
if (pDoc)
{
@@ -209,10 +210,10 @@ FX_BOOL app::calculate(OBJ_PROP_PARAMS)
ASSERT(pRuntime != NULL);
CJS_Array aDocs(pRuntime->GetIsolate());
-// int iNumDocs = pApp->CountDocuments();
+// int iNumDocs = pApp->CountDocuments();
//
-// for (int iIndex = 0;iIndex < iNumDocs; iIndex++)
-// {
+// for (int iIndex = 0;iIndex < iNumDocs; iIndex++)
+// {
if (CPDFSDK_Document* pDoc = pApp->GetCurrentDoc())
{
CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDoc->GetInterForm();
@@ -278,7 +279,19 @@ FX_BOOL app::viewerVersion(OBJ_PROP_PARAMS)
{
if (vp.IsGetting())
{
- vp << JS_STR_VIEWERVERSION;
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+
+ CPDFDoc_Environment* pApp = pContext->GetReaderApp();
+ ASSERT(pApp != NULL);
+
+ CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument();
+
+ CPDFXFA_Document* pDoc = pCurDoc->GetDocument();
+ if (pDoc->GetDocType() == 1 || pDoc->GetDocType() == 2)
+ vp << JS_STR_VIEWERVERSION_XFA;
+ else
+ vp << JS_STR_VIEWERVERSION;
return TRUE;
}
diff --git a/fpdfsdk/src/javascript/global.cpp b/fpdfsdk/src/javascript/global.cpp
index 295a8d49af..6bf0861e1a 100644
--- a/fpdfsdk/src/javascript/global.cpp
+++ b/fpdfsdk/src/javascript/global.cpp
@@ -13,6 +13,7 @@
#include "../../include/javascript/global.h"
#include "../../include/javascript/JS_EventHandler.h"
#include "../../include/javascript/JS_Context.h"
+#include "../../include/fpdfxfa/fpdfxfa_app.h"
/* ---------------------------- global ---------------------------- */
@@ -54,7 +55,7 @@ global_alternate::~global_alternate(void)
// CommitGlobalPersisitentVariables();
DestroyGlobalPersisitentVariables();
- CJS_RuntimeFactory* pFactory = m_pApp->m_pJSRuntimeFactory;
+ CJS_RuntimeFactory* pFactory = FPDFXFA_GetApp()->GetRuntimeFactory();
ASSERT(pFactory);
pFactory->ReleaseGlobalData();
@@ -64,7 +65,7 @@ void global_alternate::Initial(CPDFDoc_Environment* pApp)
{
m_pApp = pApp;
- CJS_RuntimeFactory* pFactory = pApp->m_pJSRuntimeFactory;
+ CJS_RuntimeFactory* pFactory = FPDFXFA_GetApp()->GetRuntimeFactory();
ASSERT(pFactory);
m_pGlobalData = pFactory->NewGlobalData(pApp);
UpdateGlobalPersistentVariables();