Merge to XFA: Kill overloaded cast operators in CJS_Value.
[pdfium.git] / fpdfsdk / src / javascript / app.cpp
index c1ef76c..45998b0 100644 (file)
-// Copyright 2014 PDFium Authors. All rights reserved.\r
-// Use of this source code is governed by a BSD-style license that can be\r
-// found in the LICENSE file.\r
\r
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
-\r
-#include "../../include/javascript/JavaScript.h"\r
-#include "../../include/javascript/IJavaScript.h"\r
-#include "../../include/javascript/JS_Define.h"\r
-#include "../../include/javascript/JS_Object.h"\r
-#include "../../include/javascript/JS_Value.h"\r
-#include "../../include/javascript/app.h"\r
-#include "../../include/javascript/JS_EventHandler.h"\r
-#include "../../include/javascript/resource.h"\r
-#include "../../include/javascript/JS_Context.h"\r
-#include "../../include/javascript/JS_Runtime.h"\r
-#include "../../include/javascript/Document.h"\r
-\r
-\r
-static v8::Isolate* GetIsolate(IFXJS_Context* cc)\r
-{\r
-       CJS_Context* pContext = (CJS_Context *)cc;\r
-       ASSERT(pContext != NULL);\r
-\r
-       CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
-       ASSERT(pRuntime != NULL);\r
-\r
-       return pRuntime->GetIsolate();\r
-}\r
-\r
-/* ---------------------------- TimerObj ---------------------------- */\r
-\r
-BEGIN_JS_STATIC_CONST(CJS_TimerObj)\r
-END_JS_STATIC_CONST()\r
-\r
-BEGIN_JS_STATIC_PROP(CJS_TimerObj)\r
-END_JS_STATIC_PROP()\r
-\r
-BEGIN_JS_STATIC_METHOD(CJS_TimerObj)\r
-END_JS_STATIC_METHOD()\r
-\r
-IMPLEMENT_JS_CLASS(CJS_TimerObj, TimerObj)\r
-\r
-TimerObj::TimerObj(CJS_Object* pJSObject)\r
-: CJS_EmbedObj(pJSObject),\r
-m_pTimer(NULL)\r
-{\r
-       \r
-}\r
-\r
-TimerObj::~TimerObj()\r
-{\r
-}\r
-\r
-void TimerObj::SetTimer(CJS_Timer* pTimer)\r
-{\r
-       m_pTimer = pTimer;\r
-}\r
-\r
-CJS_Timer* TimerObj::GetTimer() const\r
-{\r
-       return m_pTimer;\r
-}\r
-\r
-#define JS_STR_VIEWERTYPE_READER               L"Reader"\r
-#define JS_STR_VIEWERTYPE_STANDARD             L"Exchange"\r
-#define JS_STR_VIEWERVARIATION                 L"Full"\r
-#define JS_STR_PLATFORM                                        L"WIN"\r
-#define JS_STR_LANGUANGE                               L"ENU"\r
-#define JS_STR_VIEWERVERSION                   8\r
-#define JS_NUM_FORMSVERSION                            7\r
-\r
-#define JS_FILEPATH_MAXLEN                             2000\r
-\r
-/* ---------------------------- app ---------------------------- */\r
-\r
-BEGIN_JS_STATIC_CONST(CJS_App)\r
-END_JS_STATIC_CONST()\r
-\r
-BEGIN_JS_STATIC_PROP(CJS_App)\r
-       JS_STATIC_PROP_ENTRY(activeDocs)\r
-       JS_STATIC_PROP_ENTRY(calculate)\r
-       JS_STATIC_PROP_ENTRY(formsVersion)\r
-       JS_STATIC_PROP_ENTRY(fs)\r
-       JS_STATIC_PROP_ENTRY(fullscreen)\r
-       JS_STATIC_PROP_ENTRY(language)\r
-       JS_STATIC_PROP_ENTRY(media)\r
-       JS_STATIC_PROP_ENTRY(platform)\r
-       JS_STATIC_PROP_ENTRY(runtimeHighlight)\r
-       JS_STATIC_PROP_ENTRY(viewerType)\r
-       JS_STATIC_PROP_ENTRY(viewerVariation)\r
-       JS_STATIC_PROP_ENTRY(viewerVersion)     \r
-END_JS_STATIC_PROP()\r
-\r
-BEGIN_JS_STATIC_METHOD(CJS_App)\r
-       JS_STATIC_METHOD_ENTRY(alert, 6)\r
-       JS_STATIC_METHOD_ENTRY(beep, 1)\r
-       JS_STATIC_METHOD_ENTRY(browseForDoc, 0)\r
-       JS_STATIC_METHOD_ENTRY(clearInterval, 1)\r
-       JS_STATIC_METHOD_ENTRY(clearTimeOut, 1)\r
-       JS_STATIC_METHOD_ENTRY(execDialog, 3)\r
-       JS_STATIC_METHOD_ENTRY(execMenuItem,  1)\r
-       JS_STATIC_METHOD_ENTRY(findComponent, 1)\r
-       JS_STATIC_METHOD_ENTRY(goBack, 0)\r
-       JS_STATIC_METHOD_ENTRY(goForward, 0)\r
-       JS_STATIC_METHOD_ENTRY(launchURL, 0)\r
-       JS_STATIC_METHOD_ENTRY(mailMsg, 0)      \r
-       JS_STATIC_METHOD_ENTRY(newFDF, 0)\r
-       JS_STATIC_METHOD_ENTRY(newDoc, 0)\r
-       JS_STATIC_METHOD_ENTRY(openDoc, 0)\r
-       JS_STATIC_METHOD_ENTRY(openFDF, 5)\r
-       JS_STATIC_METHOD_ENTRY(popUpMenuEx, 0)\r
-       JS_STATIC_METHOD_ENTRY(popUpMenu, 0)\r
-       JS_STATIC_METHOD_ENTRY(response, 0)\r
-       JS_STATIC_METHOD_ENTRY(setInterval, 2)\r
-       JS_STATIC_METHOD_ENTRY(setTimeOut, 2)\r
-END_JS_STATIC_METHOD()\r
-\r
-IMPLEMENT_JS_CLASS(CJS_App,app)\r
-\r
-app::app(CJS_Object * pJSObject) : CJS_EmbedObj(pJSObject) ,\r
-       m_bCalculate(true),\r
-       m_pRuntime(NULL),\r
-       m_bRuntimeHighLight(false)\r
-//     m_pMenuHead(NULL)\r
-{\r
-}\r
-\r
-app::~app(void)\r
-{\r
-       for (int i=0,sz=m_aTimer.GetSize(); i<sz; i++)\r
-               delete m_aTimer[i];\r
-\r
-       m_aTimer.RemoveAll();\r
-}\r
-\r
-FX_BOOL app::activeDocs(OBJ_PROP_PARAMS)\r
-{\r
-       if (vp.IsGetting())\r
-       {\r
-\r
-               CJS_Context* pContext = (CJS_Context *)cc;\r
-               ASSERT(pContext != NULL);\r
-               \r
-               CPDFDoc_Environment* pApp = pContext->GetReaderApp();\r
-               ASSERT(pApp != NULL);\r
-\r
-               CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
-               ASSERT(pRuntime != NULL);\r
-               \r
-               CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument();\r
-               \r
-               CJS_Array aDocs(pRuntime->GetIsolate());\r
-//             int iNumDocs = pApp->CountDocuments();\r
-               \r
-//             for(int iIndex = 0; iIndex<iNumDocs; iIndex++)\r
-//             {\r
-                       CPDFSDK_Document* pDoc = pApp->GetCurrentDoc();\r
-                       if (pDoc)\r
-                       {\r
-                               CJS_Document * pJSDocument = NULL;\r
-                               \r
-                               if (pDoc == pCurDoc)\r
-                               {\r
-                                       JSFXObject pObj = JS_GetThisObj(*pRuntime);\r
-                                       \r
-                                       if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"Document"))\r
-                                       {\r
-                                               pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj);\r
-                                       }\r
-                               }\r
-                               else\r
-                               {\r
-                                       JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime,L"Document"));\r
-                                       pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj);\r
-                                       ASSERT(pJSDocument != NULL);\r
-                                       \r
-                                       \r
-                                       //                      pDocument->AttachDoc(pDoc);\r
-                               }\r
-                               \r
-                               aDocs.SetElement(0,CJS_Value(pRuntime->GetIsolate(),pJSDocument));\r
-                       }\r
-       //              }\r
-               \r
-               if (aDocs.GetLength() > 0)\r
-                       vp << aDocs;\r
-               else\r
-                       vp.SetNull();\r
-               return TRUE;\r
-       }\r
-       return FALSE;\r
-}\r
-\r
-FX_BOOL app::calculate(OBJ_PROP_PARAMS)\r
-{\r
-       if (vp.IsSetting())\r
-       {\r
-               bool bVP;\r
-               vp >> bVP;\r
-               m_bCalculate = (FX_BOOL)bVP;\r
-\r
-               CJS_Context* pContext = (CJS_Context*)cc;\r
-               ASSERT(pContext != NULL);\r
-               \r
-               CPDFDoc_Environment* pApp = pContext->GetReaderApp();\r
-               ASSERT(pApp != NULL);\r
-               \r
-               CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
-               ASSERT(pRuntime != NULL);\r
-\r
-               CJS_Array aDocs(pRuntime->GetIsolate());\r
-//             int iNumDocs = pApp->CountDocuments();\r
-//             \r
-//             for (int iIndex = 0;iIndex < iNumDocs; iIndex++)\r
-//             {\r
-                       if (CPDFSDK_Document* pDoc = pApp->GetCurrentDoc())\r
-                       {\r
-                               CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDoc->GetInterForm();\r
-                               ASSERT(pInterForm != NULL);\r
-                               pInterForm->EnableCalculate((FX_BOOL)m_bCalculate);\r
-                       }                       \r
-//             }\r
-       }\r
-       else\r
-       {\r
-               vp << (bool)m_bCalculate;\r
-       }\r
-       \r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL app::formsVersion(OBJ_PROP_PARAMS)\r
-{\r
-       if (vp.IsGetting())\r
-       {\r
-               vp << JS_NUM_FORMSVERSION;\r
-               return TRUE;\r
-       }\r
-       \r
-       return FALSE;\r
-}\r
-\r
-FX_BOOL app::viewerType(OBJ_PROP_PARAMS)\r
-{\r
-\r
-\r
-       \r
-       \r
-       \r
-\r
-       if (vp.IsGetting())\r
-       {\r
-//             if (pApp->GetAppName() == PHANTOM)\r
-//                     vp << JS_STR_VIEWERTYPE_STANDARD;\r
-//             else\r
-//                     vp << JS_STR_VIEWERTYPE_READER;\r
-               vp << L"unknown";\r
-\r
-               //vp << pApp->GetAppTitle();\r
-               return TRUE;\r
-       }\r
-       \r
-       return FALSE;\r
-}\r
-\r
-FX_BOOL app::viewerVariation(OBJ_PROP_PARAMS)\r
-{\r
-       if (vp.IsGetting())\r
-       {\r
-               vp << JS_STR_VIEWERVARIATION;\r
-               return TRUE;\r
-       }\r
-       \r
-       return FALSE;\r
-}\r
-\r
-FX_BOOL app::viewerVersion(OBJ_PROP_PARAMS)\r
-{\r
-       if (vp.IsGetting())\r
-       {\r
-               vp << JS_STR_VIEWERVERSION;\r
-               return TRUE;\r
-       }\r
-       \r
-       return FALSE;\r
-}\r
-\r
-FX_BOOL app::platform(OBJ_PROP_PARAMS)\r
-{\r
-       if (vp.IsGetting())\r
-       {\r
-               vp << JS_STR_PLATFORM;\r
-               return TRUE;\r
-       }\r
-       \r
-       return FALSE;\r
-}\r
-\r
-FX_BOOL app::language(OBJ_PROP_PARAMS)\r
-{\r
-       if (vp.IsGetting())\r
-       {\r
-               vp << JS_STR_LANGUANGE;\r
-               return TRUE;\r
-       }\r
-       \r
-       return FALSE;\r
-}\r
-\r
-//creates a new fdf object that contains no data\r
-//comment: need reader support\r
-//note:\r
-//CFDF_Document * CPDFDoc_Environment::NewFDF();\r
-FX_BOOL app::newFDF(OBJ_METHOD_PARAMS)\r
-{\r
-       return TRUE;\r
-}\r
-//opens a specified pdf document and returns its document object\r
-//comment:need reader support\r
-//note: as defined in js reference, the proto of this function's fourth parmeters, how old an fdf document while do not show it.\r
-//CFDF_Document * CPDFDoc_Environment::OpenFDF(string strPath,bool bUserConv);\r
-\r
-FX_BOOL app::openFDF(OBJ_METHOD_PARAMS)\r
-{\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL app::alert(OBJ_METHOD_PARAMS)\r
-{\r
-       int iSize = params.size();\r
-       if (iSize < 1)\r
-               return FALSE;\r
-\r
-       CFX_WideString swMsg = L"";\r
-       CFX_WideString swTitle = L"";\r
-       int iIcon = 0;\r
-       int iType = 0;\r
-\r
-       v8::Isolate* isolate = GetIsolate(cc);\r
-\r
-       if (iSize == 1)\r
-       {\r
-               if (params[0].GetType() == VT_object)\r
-               {\r
-                       JSObject pObj = params[0];\r
-                       {\r
-                               v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate, pObj, L"cMsg");\r
-                               swMsg = CJS_Value(isolate,pValue,VT_unknown).operator CFX_WideString();\r
-\r
-                               pValue = JS_GetObjectElement(isolate,pObj,L"cTitle");\r
-                               swTitle = CJS_Value(isolate, pValue,VT_unknown).operator CFX_WideString();\r
-\r
-                               pValue = JS_GetObjectElement(isolate,pObj,L"nIcon");\r
-                               iIcon = (int)CJS_Value(isolate,pValue,VT_unknown);\r
-\r
-                               pValue = JS_GetObjectElement(isolate,pObj,L"nType");\r
-                               iType = (int)CJS_Value(isolate,pValue,VT_unknown);\r
-                       }\r
-\r
-                       if (swMsg == L"")\r
-                       {\r
-                               CJS_Array carray(isolate);\r
-                               if (params[0].ConvertToArray(carray))\r
-                               {\r
-                                       int iLenth = carray.GetLength();\r
-                                       CJS_Value* pValue = new CJS_Value(isolate);\r
-//                                     if (iLenth == 1)\r
-//                                             pValue = new CJS_Value(isolate);\r
-//                                     else if (iLenth > 1)\r
-//                                             pValue = new CJS_Value[iLenth];\r
-\r
-                                       for(int i = 0; i < iLenth; i++)\r
-                                       {\r
-                                               carray.GetElement(i, *pValue);\r
-                                               swMsg += (*pValue).operator CFX_WideString();\r
-                                               if (i < iLenth - 1)\r
-                                                       swMsg += L",  ";\r
-                                       }\r
-\r
-                                       if(pValue) delete pValue;\r
-//                                     if ((iLenth > 1) && pValue)\r
-//                                     {\r
-//                                             delete[]pValue;\r
-//                                             pValue = NULL;\r
-//                                     }\r
-//                                     else if ((iLenth == 1) && pValue)\r
-//                                     {\r
-//                                             delete pValue;\r
-//                                             pValue = NULL;\r
-//                                     }\r
-                               }\r
-                       }\r
-\r
-                       if (swTitle == L"")\r
-                               swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);\r
-               }\r
-               else if (params[0].GetType() == VT_boolean)\r
-               {\r
-                       FX_BOOL bGet = (FX_BOOL)params[0];\r
-                       if (bGet)\r
-                               swMsg = L"true";\r
-                       else\r
-                               swMsg = L"false";\r
-\r
-                       swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);\r
-               }\r
-               else\r
-               {\r
-                       swMsg = params[0];\r
-                       swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);\r
-               }\r
-       }\r
-       else\r
-       {\r
-               if (params[0].GetType() == VT_boolean)\r
-               {\r
-                       FX_BOOL bGet = (FX_BOOL)params[0];\r
-                       if (bGet)\r
-                               swMsg = L"true";\r
-                       else\r
-                               swMsg = L"false";\r
-               }\r
-               else\r
-               {\r
-                       swMsg = params[0];\r
-               }\r
-               swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);\r
-               \r
-               for(int i = 1;i<iSize;i++)\r
-               {\r
-                       if (i == 1)\r
-                               iIcon = int(params[i]);\r
-                       if (i == 2)\r
-                               iType = int(params[i]);\r
-                       if (i == 3)\r
-                               swTitle = params[i];                    \r
-               }\r
-       }\r
-\r
-\r
-       CJS_Context* pContext = (CJS_Context*)cc;\r
-       ASSERT(pContext != NULL);\r
-       CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
-       ASSERT(pRuntime != NULL);\r
-       pRuntime->BeginBlock();\r
-       vRet = MsgBox(pRuntime->GetReaderApp(), JSGetPageView(cc),swMsg,swTitle,iType,iIcon);\r
-       pRuntime->EndBlock();\r
-       \r
-       return TRUE;\r
-}\r
-\r
-\r
-FX_BOOL app::beep(OBJ_METHOD_PARAMS)\r
-{\r
-       if (params.size() == 1)\r
-       {\r
-               CJS_Context* pContext = (CJS_Context*)cc;\r
-               CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
-               CPDFDoc_Environment * pEnv = pRuntime->GetReaderApp();\r
-               pEnv->JS_appBeep((int)params[0]);\r
-\r
-               return TRUE;\r
-       }\r
-       else\r
-       {\r
-               sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);\r
-               return FALSE;\r
-       }\r
-}\r
-\r
-FX_BOOL app::findComponent(OBJ_METHOD_PARAMS)\r
-{\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL app::popUpMenuEx(OBJ_METHOD_PARAMS)\r
-{      \r
-       return FALSE;\r
-}\r
-\r
-FX_BOOL app::fs(OBJ_PROP_PARAMS)\r
-{\r
-#ifdef FOXIT_CHROME_BUILD\r
-       return FALSE;\r
-#else\r
-       CJS_Context* pContext = (CJS_Context*)cc;\r
-       ASSERT(pContext != NULL);\r
-       CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
-       ASSERT(pRuntime != NULL);\r
-\r
-       if (vp.IsGetting())\r
-       {\r
-               return TRUE;\r
-       }\r
-       else\r
-       {\r
-               return TRUE;\r
-       }\r
-#endif\r
-}\r
-\r
-FX_BOOL app::setInterval(OBJ_METHOD_PARAMS)\r
-{\r
-       if (params.size() > 2 || params.size() == 0) \r
-       {\r
-               sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);  \r
-               return FALSE;\r
-       }\r
-       \r
-       CJS_Context* pContext = (CJS_Context*)cc;\r
-       ASSERT(pContext != NULL);\r
-       CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
-       ASSERT(pRuntime != NULL);\r
-\r
-       CFX_WideString script = params.size() > 0 ?  (FX_LPCWSTR)(params[0].operator CFX_WideString()) : (FX_LPCWSTR)L"";\r
-       if (script.IsEmpty()) \r
-       {\r
-               sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSAFNUMBER_KEYSTROKE);\r
-               return TRUE;\r
-       }\r
-\r
-       FX_DWORD dwInterval = params.size() > 1 ? (int)params[1] : 1000;\r
-       \r
-       CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();\r
-       ASSERT(pApp);\r
-       CJS_Timer* pTimer = new CJS_Timer(this, pApp);\r
-       m_aTimer.Add(pTimer);\r
-\r
-       pTimer->SetType(0);\r
-       pTimer->SetRuntime(pRuntime);\r
-       pTimer->SetJScript(script);\r
-       pTimer->SetTimeOut(0);\r
-//     pTimer->SetStartTime(GetTickCount());\r
-       pTimer->SetJSTimer(dwInterval);\r
-       \r
-       JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"TimerObj"));\r
-       \r
-       CJS_TimerObj* pJS_TimerObj = (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetIsolate(),pRetObj);\r
-       ASSERT(pJS_TimerObj != NULL);\r
-       \r
-       TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();\r
-       ASSERT(pTimerObj != NULL);\r
-       \r
-       pTimerObj->SetTimer(pTimer); \r
-       \r
-       vRet = pRetObj;\r
-       \r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL app::setTimeOut(OBJ_METHOD_PARAMS)\r
-{\r
-       if (params.size() > 2 || params.size() == 0)\r
-       {\r
-               sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);  \r
-               return FALSE;\r
-       }\r
-       \r
-       CJS_Context* pContext = (CJS_Context*)cc;\r
-       ASSERT(pContext != NULL);\r
-       CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
-       ASSERT(pRuntime != NULL);\r
-       \r
-       CFX_WideString script = params.size() > 0 ?  (FX_LPCWSTR)(params[0].operator CFX_WideString()) : (FX_LPCWSTR)L"";\r
-       if (script.IsEmpty()) \r
-       {\r
-               sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSAFNUMBER_KEYSTROKE);\r
-               return TRUE;\r
-       }\r
-       \r
-       FX_DWORD dwTimeOut = params.size() > 1 ? (int)params[1] : 1000;\r
-       \r
-       CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();\r
-       ASSERT(pApp);\r
-       CJS_Timer* pTimer = new CJS_Timer(this, pApp);\r
-       m_aTimer.Add(pTimer);\r
-       \r
-       pTimer->SetType(1);\r
-       pTimer->SetRuntime(pRuntime);\r
-       pTimer->SetJScript(script);\r
-       pTimer->SetTimeOut(dwTimeOut);\r
-//     pTimer->SetStartTime(GetTickCount());\r
-//     pTimer->SetJSTimer(1000);\r
-       pTimer->SetJSTimer(dwTimeOut);\r
-       \r
-       JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"TimerObj"));\r
-//     ASSERT(pRetObj != NULL);\r
-       \r
-       CJS_TimerObj* pJS_TimerObj = (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetIsolate(),pRetObj);\r
-       ASSERT(pJS_TimerObj != NULL);\r
-       \r
-       TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();\r
-       ASSERT(pTimerObj != NULL);\r
-       \r
-       pTimerObj->SetTimer(pTimer); \r
-       \r
-       vRet = pRetObj;\r
-       \r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL app::clearTimeOut(OBJ_METHOD_PARAMS)\r
-{\r
-       CJS_Context* pContext = (CJS_Context*)cc;\r
-       ASSERT(pContext != NULL);\r
-       CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
-       ASSERT(pRuntime != NULL);\r
-       \r
-       if (params.size() != 1)\r
-       {\r
-               sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);  \r
-               return FALSE;\r
-       }\r
-       \r
-       if (params[0].GetType() == VT_fxobject)\r
-       {\r
-               JSFXObject pObj = (JSFXObject)params[0];\r
-               {\r
-                       if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"TimerObj"))\r
-                       {\r
-                               if (CJS_Object* pJSObj = (CJS_Object*)params[0])\r
-                               {\r
-                                       if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject())\r
-                                       {\r
-                                               if (CJS_Timer* pTimer = pTimerObj->GetTimer())\r
-                                               {\r
-                                                       pTimer->KillJSTimer();\r
-                                                       \r
-                                                       for (int i=0,sz=m_aTimer.GetSize(); i<sz; i++)\r
-                                                       {\r
-                                                               if (m_aTimer[i] == pTimer)\r
-                                                               {\r
-                                                                       m_aTimer.RemoveAt(i);\r
-                                                                       break;\r
-                                                               }\r
-                                                       }\r
-                                                       \r
-                                                       delete pTimer;\r
-                                                       pTimerObj->SetTimer(NULL);\r
-                                               }\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-       \r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL app::clearInterval(OBJ_METHOD_PARAMS)\r
-{\r
-       CJS_Context* pContext = (CJS_Context*)cc;\r
-       ASSERT(pContext != NULL);\r
-       CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
-       ASSERT(pRuntime != NULL);\r
-\r
-       if (params.size() != 1)\r
-       {\r
-               sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);  \r
-               return FALSE;\r
-       }\r
-       \r
-       if (params[0].GetType() == VT_fxobject)\r
-       {\r
-               JSFXObject pObj = (JSFXObject)params[0];\r
-               {\r
-                       if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"TimerObj"))\r
-                       {\r
-                               if (CJS_Object* pJSObj = (CJS_Object*)params[0])\r
-                               {\r
-                                       if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject())\r
-                                       {\r
-                                               if (CJS_Timer* pTimer = pTimerObj->GetTimer())\r
-                                               {\r
-                                                       pTimer->KillJSTimer();\r
-                                                       \r
-                                                       for (int i=0,sz=m_aTimer.GetSize(); i<sz; i++)\r
-                                                       {\r
-                                                               if (m_aTimer[i] == pTimer)\r
-                                                               {\r
-                                                                       m_aTimer.RemoveAt(i);\r
-                                                                       break;\r
-                                                               }\r
-                                                       }\r
-                                                       \r
-                                                       delete pTimer;\r
-                                                       pTimerObj->SetTimer(NULL);\r
-                                               }\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-       \r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL app::execMenuItem(OBJ_METHOD_PARAMS)\r
-{      \r
-       return FALSE;\r
-}\r
-\r
-void app::TimerProc(CJS_Timer* pTimer)\r
-{\r
-       ASSERT(pTimer != NULL);\r
-\r
-       switch (pTimer->GetType())\r
-       {\r
-       case 0: //interval\r
-               RunJsScript(pTimer->GetRuntime(), pTimer->GetJScript());\r
-               break;\r
-       case 1:\r
-               if (pTimer->GetTimeOut() > 0)\r
-               {\r
-                       RunJsScript(pTimer->GetRuntime(), pTimer->GetJScript());\r
-                       pTimer->KillJSTimer();\r
-               }\r
-               break;\r
-       }\r
-       \r
-}\r
-\r
-void app::RunJsScript(CJS_Runtime* pRuntime,const CFX_WideString& wsScript)\r
-{\r
-       ASSERT(pRuntime != NULL);\r
-\r
-       if (!pRuntime->IsBlocking())\r
-       {\r
-               IFXJS_Context* pContext = pRuntime->NewContext();\r
-               ASSERT(pContext != NULL);\r
-               pContext->OnExternal_Exec();\r
-               CFX_WideString wtInfo;\r
-               pContext->RunScript(wsScript,wtInfo);\r
-               pRuntime->ReleaseContext(pContext);\r
-       }\r
-}\r
-\r
-FX_BOOL app::goBack(OBJ_METHOD_PARAMS)\r
-{\r
-\r
-\r
-       \r
-       \r
-       \r
-       \r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL app::goForward(OBJ_METHOD_PARAMS)\r
-{      \r
-\r
-\r
-\r
-\r
-\r
-\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL app::mailMsg(OBJ_METHOD_PARAMS)\r
-{\r
-       CJS_Context* pContext = (CJS_Context*)cc;\r
-       ASSERT(pContext != NULL);\r
-\r
-       v8::Isolate* isolate = GetIsolate(cc);\r
-\r
-       FX_BOOL bUI = TRUE;\r
-       CFX_WideString cTo = L"";\r
-       CFX_WideString cCc = L"";\r
-       CFX_WideString cBcc = L"";\r
-       CFX_WideString cSubject = L"";\r
-       CFX_WideString cMsg = L"";\r
-       if(params.size() < 2)\r
-               return FALSE;\r
-\r
-       bUI = params.size()>=1?(int)params[0]:TRUE;\r
-       cTo = params.size()>=2?(const wchar_t*)(FX_LPCWSTR)params[1].operator CFX_WideString():L"";\r
-       cCc = params.size()>=3?(const wchar_t*)(FX_LPCWSTR)params[2].operator CFX_WideString():L"";\r
-       cBcc = params.size()>=4?(const wchar_t*)(FX_LPCWSTR)params[3].operator CFX_WideString():L"";\r
-       cSubject = params.size()>=5?(const wchar_t*)(FX_LPCWSTR)params[4].operator CFX_WideString():L"";\r
-       cMsg = params.size()>=6?(const wchar_t*)(FX_LPCWSTR)params[5].operator CFX_WideString():L"";            \r
-\r
-\r
-       if (params[0].GetType() == VT_object)\r
-       {\r
-               JSObject pObj = (JSObject)params[0];\r
-\r
-               v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"bUI");\r
-                       bUI = (int)CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue));\r
-\r
-               pValue = JS_GetObjectElement(isolate, pObj, L"cTo");\r
-                       cTo = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();\r
-\r
-               pValue = JS_GetObjectElement(isolate,pObj, L"cCc");\r
-                       cCc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();\r
-\r
-               pValue = JS_GetObjectElement(isolate,pObj, L"cBcc");\r
-                       cBcc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();\r
-\r
-               pValue = JS_GetObjectElement(isolate,pObj, L"cSubject");\r
-                       cSubject = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();\r
-\r
-               pValue = JS_GetObjectElement(isolate,pObj, L"cMsg");\r
-                       cMsg = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();\r
-       }\r
-       \r
-       \r
-\r
-       CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
-       ASSERT(pRuntime != NULL);\r
-\r
-       CPDFDoc_Environment* pApp = pContext->GetReaderApp();\r
-       ASSERT(pApp != NULL);\r
-\r
-       pRuntime->BeginBlock();\r
-       pApp->JS_docmailForm(NULL, 0, bUI, (FX_LPCWSTR)cTo, (FX_LPCWSTR)cSubject, (FX_LPCWSTR)cCc, (FX_LPCWSTR)cBcc, (FX_LPCWSTR)cMsg);\r
-       ///////////////////////////////////////////////////////////////////////////////////////////////\r
-       pRuntime->EndBlock();\r
-\r
-       //return bRet;\r
-       return FALSE;\r
-}\r
-\r
-FX_BOOL app::launchURL(OBJ_METHOD_PARAMS)\r
-{\r
-       if (IsSafeMode(cc)) return TRUE;\r
-\r
-       CJS_Context* pContext = (CJS_Context*)cc;\r
-       ASSERT(pContext != NULL);\r
-\r
-       \r
-\r
-\r
-       CFX_WideString swURL = params[0].operator CFX_WideString();\r
-\r
-       CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
-       ASSERT(pRuntime != NULL);\r
-\r
-       pRuntime->BeginBlock();\r
-//     FX_BOOL bRet = pApp->OpenURL(swURL);\r
-       pRuntime->EndBlock();\r
-\r
-//     return bRet;\r
-       return FALSE;\r
-}\r
-\r
-FX_BOOL app::runtimeHighlight(OBJ_PROP_PARAMS)\r
-{\r
-       if (vp.IsSetting())\r
-       {\r
-               vp>>m_bRuntimeHighLight;\r
-       }\r
-       else\r
-       {\r
-               vp<<m_bRuntimeHighLight;\r
-       }\r
-\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL app::fullscreen(OBJ_PROP_PARAMS)\r
-{\r
-       return FALSE;\r
-}\r
-\r
-FX_BOOL app::popUpMenu(OBJ_METHOD_PARAMS)\r
-{\r
-       return FALSE;\r
-}\r
-\r
-\r
-FX_BOOL app::browseForDoc(OBJ_METHOD_PARAMS)\r
-{\r
-       //This method may trigger a "file save" dialog,while enable user to save contents of the document.\r
-       //Such action is considered to be unsafe.\r
-       if (IsSafeMode(cc)) return TRUE;\r
-\r
-       v8::Isolate* isolate = GetIsolate(cc);\r
-\r
-       bool bSave = false;\r
-       CFX_ByteString cFilenameInit = CFX_ByteString();\r
-       CFX_ByteString cFSInit = CFX_ByteString();\r
-\r
-       if(params.size()>0 && (params[0].GetType() == VT_object))\r
-       {\r
-               JSObject pObj = (JSObject )params[0];\r
-\r
-               v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj,L"bSave");\r
-                       bSave = (bool)CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue));\r
-               \r
-               pValue = JS_GetObjectElement(isolate, pObj,L"cFilenameInit");\r
-               {\r
-                       CJS_Value t = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue));\r
-                       cFilenameInit = t.operator CFX_ByteString();\r
-               }\r
-               \r
-               pValue = JS_GetObjectElement(isolate,pObj,L"cFSInit");\r
-               {\r
-                       CJS_Value t = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue));\r
-                       cFSInit = t.operator CFX_ByteString();\r
-               }\r
-       }\r
-       else\r
-       {\r
-               if(params.size() >= 1)\r
-               {\r
-                       bSave = (bool)params[0];\r
-               }\r
-               if(params.size() >= 2)\r
-               {\r
-                       CJS_Value t = params[1];\r
-                       cFilenameInit = t.operator CFX_ByteString();\r
-               }\r
-               if(params.size() >= 3)\r
-               {\r
-                       CJS_Value t = params[2];\r
-                       cFSInit = t.operator CFX_ByteString();\r
-               }\r
-       }\r
-       CJS_Context* pContext = (CJS_Context *)cc;\r
-       ASSERT(pContext != NULL);\r
-       \r
-       CPDFDoc_Environment* pApp = pContext->GetReaderApp();\r
-       ASSERT(pApp != NULL);\r
-\r
-       CJS_Runtime* pRuntime = pContext->GetJSRuntime();\r
-       ASSERT(pRuntime != NULL);\r
-\r
-       CFX_WideString wsFileNameInit = CFX_WideString::FromLocal(cFilenameInit);\r
-       CFX_WideString wsFSInit = CFX_WideString::FromLocal(cFSInit);\r
-       CFX_WideString wsFilePath = pApp->JS_appbrowseForDoc(bSave, wsFileNameInit);\r
-       if(wsFilePath.IsEmpty())\r
-               return FALSE;\r
-\r
-       JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, -1);\r
-\r
-       JS_PutObjectString(isolate,pRetObj, L"cPath", SysPathToPDFPath(wsFilePath));    \r
-       JS_PutObjectString(isolate,pRetObj, L"cURL", SysPathToPDFPath(wsFilePath));\r
-\r
-       if (!cFSInit.IsEmpty())\r
-       {\r
-               JS_PutObjectString(isolate,pRetObj, L"cFS", CFX_WideString::FromLocal(cFSInit.GetBuffer(cFSInit.GetLength())));\r
-       }\r
-       else\r
-       {\r
-               JS_PutObjectString(isolate,pRetObj, L"cFS", CFX_WideString::FromLocal("DOS"));\r
-       }\r
-       \r
-       vRet =  pRetObj;\r
-\r
-       return TRUE;\r
-}\r
-\r
-CFX_WideString app::SysPathToPDFPath(const CFX_WideString& sOldPath)\r
-{\r
-       CFX_WideString sRet = L"/";\r
-       \r
-       for (int i=0,sz=sOldPath.GetLength(); i<sz; i++)\r
-       {\r
-               wchar_t c = sOldPath.GetAt(i);\r
-               if (c == L':')\r
-               {\r
-               }\r
-               else\r
-               {\r
-                       if (c == L'\\')\r
-                       {\r
-                               sRet += L"/";\r
-                       }\r
-                       else\r
-                       {\r
-                               sRet += c;\r
-                       }\r
-               }\r
-       }\r
-       \r
-       return sRet;\r
-}\r
-\r
-CFX_WideString app::PDFPathToSysPath(const CFX_WideString& sOldPath)\r
-{\r
-       //strLPath = "D:\temporay.fdf";\r
-       CFX_WideString strOPath = sOldPath;\r
-       strOPath.TrimLeft();\r
-       strOPath.TrimRight();\r
-       \r
-       if (strOPath.GetAt(0) == L'/' && strOPath.GetAt(2) == L'/')\r
-       {\r
-               wchar_t c_Drive = strOPath.GetAt(1);\r
-               if ((c_Drive >= L'a' && c_Drive <= L'z' )||( c_Drive >= L'A' && c_Drive <= L'Z'))\r
-               {\r
-                       strOPath.Replace((FX_LPCWSTR)L"/",(FX_LPCWSTR)L"\\");\r
-                       //strOPath.SetAt(0,'');\r
-                       strOPath.Insert(2,':');\r
-                       strOPath.Delete(0);\r
-               }\r
-       }\r
-       \r
-       return strOPath;\r
-}\r
-\r
-CFX_WideString app::RelativePathToSysPath(const CFX_WideString& sOldPath, const CFX_WideString& sFilePath)\r
-{\r
-//     if (!PathIsRelative(sOldPath)) return sOldPath;\r
-       \r
-       int nSplit = 0;\r
-       for (int i=sFilePath.GetLength()-1; i>=0; i--)\r
-       {\r
-               if (sFilePath[i] == '\\' || sFilePath[i] == '/')\r
-               {\r
-                       nSplit = i;\r
-                       break;\r
-               }\r
-       }\r
-       \r
-       return sFilePath.Left(nSplit+1) + sOldPath;\r
-}\r
-\r
-FX_BOOL app::newDoc(OBJ_METHOD_PARAMS)\r
-{\r
-       return FALSE;\r
-}\r
-\r
-FX_BOOL app::openDoc(OBJ_METHOD_PARAMS)\r
-{\r
-       return FALSE;\r
-}\r
-\r
-FX_BOOL app::response(OBJ_METHOD_PARAMS)\r
-{\r
-       CFX_WideString swQuestion = L"";\r
-       CFX_WideString swLabel = L"";\r
-#ifndef FOXIT_CHROME_BUILD\r
-       CFX_WideString swTitle = L"Foxit";\r
-#else\r
-       CFX_WideString swTitle = L"PDF";\r
-#endif\r
-       CFX_WideString swDefault = L"";\r
-       CFX_WideString swResponse = L"";\r
-       bool bPassWord = false;\r
-       \r
-       v8::Isolate* isolate = GetIsolate(cc);\r
-       \r
-       int iLength = params.size();    \r
-       if (iLength > 0 && params[0].GetType() == VT_object)\r
-       {\r
-               \r
-               JSObject pObj = (JSObject )params[0];\r
-               v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj,L"cQuestion");\r
-                       swQuestion = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();\r
-\r
-               pValue = JS_GetObjectElement(isolate,pObj,L"cTitle");\r
-                       swTitle = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();\r
-\r
-               pValue = JS_GetObjectElement(isolate,pObj,L"cDefault");\r
-                       swDefault = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();\r
-\r
-               pValue = JS_GetObjectElement(isolate,pObj,L"cLabel");\r
-                       swLabel = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();\r
-\r
-               pValue = JS_GetObjectElement(isolate,pObj,L"bPassword");\r
-                       bPassWord = (bool)CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue));\r
-       }\r
-       else\r
-       {\r
-               switch(iLength)\r
-               {\r
-               case 1:\r
-                       swQuestion = params[0];\r
-                       break;\r
-               case 2:\r
-                       swQuestion = params[0];\r
-                       swTitle = params[1];\r
-                       break;\r
-               case 3:\r
-                       swQuestion = params[0];\r
-                       swTitle = params[1];\r
-                       swDefault = params[2];\r
-                       break;\r
-               case 4:\r
-                       swQuestion = params[0];\r
-                       swTitle = params[1];\r
-                       swDefault = params[2];\r
-                       bPassWord = params[3];\r
-                       break;\r
-               case 5:\r
-                       swQuestion = params[0];\r
-                       swTitle = params[1];\r
-                       swDefault = params[2];\r
-                       bPassWord = params[3];\r
-                       swLabel = params[4];\r
-                       break;\r
-               default:\r
-                       break;\r
-               }\r
-       }\r
-\r
-       CJS_Context* pContext = (CJS_Context *)cc;\r
-       ASSERT(pContext != NULL);\r
-\r
-       CPDFDoc_Environment* pApp = pContext->GetReaderApp();\r
-       ASSERT(pApp != NULL);\r
-       int nLength = 2048;\r
-       char* pBuff = new char[nLength];\r
-       nLength = pApp->JS_appResponse(swQuestion, swTitle, swDefault, swLabel, bPassWord, pBuff, nLength);\r
-       if(nLength<=0)\r
-       {\r
-               vRet.SetNull();\r
-               return FALSE;\r
-       }\r
-       else\r
-       {\r
-               nLength = nLength>2046?2046:nLength;\r
-    pBuff[nLength] = 0;\r
-    pBuff[nLength+1] = 0;\r
-               swResponse = CFX_WideString::FromUTF16LE((unsigned short*)pBuff, nLength);\r
-               vRet = swResponse;\r
-       }\r
-       delete[] pBuff;\r
-\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL app::media(OBJ_PROP_PARAMS)\r
-{\r
-       return FALSE;\r
-}\r
-\r
-FX_BOOL app::execDialog(OBJ_METHOD_PARAMS)\r
-{\r
-       return TRUE;\r
-}\r
-\r
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/app.h"
+#include "../../include/javascript/JS_EventHandler.h"
+#include "../../include/javascript/resource.h"
+#include "../../include/javascript/JS_Context.h"
+#include "../../include/javascript/JS_Runtime.h"
+#include "../../include/javascript/Document.h"
+
+
+static v8::Isolate* GetIsolate(IFXJS_Context* cc)
+{
+       CJS_Context* pContext = (CJS_Context *)cc;
+       ASSERT(pContext != NULL);
+
+       CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+       ASSERT(pRuntime != NULL);
+
+       return pRuntime->GetIsolate();
+}
+
+/* ---------------------------- TimerObj ---------------------------- */
+
+BEGIN_JS_STATIC_CONST(CJS_TimerObj)
+END_JS_STATIC_CONST()
+
+BEGIN_JS_STATIC_PROP(CJS_TimerObj)
+END_JS_STATIC_PROP()
+
+BEGIN_JS_STATIC_METHOD(CJS_TimerObj)
+END_JS_STATIC_METHOD()
+
+IMPLEMENT_JS_CLASS(CJS_TimerObj, TimerObj)
+
+TimerObj::TimerObj(CJS_Object* pJSObject)
+: CJS_EmbedObj(pJSObject),
+m_pTimer(NULL)
+{
+
+}
+
+TimerObj::~TimerObj()
+{
+}
+
+void TimerObj::SetTimer(CJS_Timer* pTimer)
+{
+       m_pTimer = pTimer;
+}
+
+CJS_Timer* TimerObj::GetTimer() const
+{
+       return m_pTimer;
+}
+
+#define JS_STR_VIEWERTYPE_READER               L"Reader"
+#define JS_STR_VIEWERTYPE_STANDARD             L"Exchange"
+#define JS_STR_VIEWERVARIATION                 L"Full"
+#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
+
+/* ---------------------------- app ---------------------------- */
+
+BEGIN_JS_STATIC_CONST(CJS_App)
+END_JS_STATIC_CONST()
+
+BEGIN_JS_STATIC_PROP(CJS_App)
+       JS_STATIC_PROP_ENTRY(activeDocs)
+       JS_STATIC_PROP_ENTRY(calculate)
+       JS_STATIC_PROP_ENTRY(formsVersion)
+       JS_STATIC_PROP_ENTRY(fs)
+       JS_STATIC_PROP_ENTRY(fullscreen)
+       JS_STATIC_PROP_ENTRY(language)
+       JS_STATIC_PROP_ENTRY(media)
+       JS_STATIC_PROP_ENTRY(platform)
+       JS_STATIC_PROP_ENTRY(runtimeHighlight)
+       JS_STATIC_PROP_ENTRY(viewerType)
+       JS_STATIC_PROP_ENTRY(viewerVariation)
+       JS_STATIC_PROP_ENTRY(viewerVersion)
+END_JS_STATIC_PROP()
+
+BEGIN_JS_STATIC_METHOD(CJS_App)
+       JS_STATIC_METHOD_ENTRY(alert, 6)
+       JS_STATIC_METHOD_ENTRY(beep, 1)
+       JS_STATIC_METHOD_ENTRY(browseForDoc, 0)
+       JS_STATIC_METHOD_ENTRY(clearInterval, 1)
+       JS_STATIC_METHOD_ENTRY(clearTimeOut, 1)
+       JS_STATIC_METHOD_ENTRY(execDialog, 3)
+       JS_STATIC_METHOD_ENTRY(execMenuItem,  1)
+       JS_STATIC_METHOD_ENTRY(findComponent, 1)
+       JS_STATIC_METHOD_ENTRY(goBack, 0)
+       JS_STATIC_METHOD_ENTRY(goForward, 0)
+       JS_STATIC_METHOD_ENTRY(launchURL, 0)
+       JS_STATIC_METHOD_ENTRY(mailMsg, 0)
+       JS_STATIC_METHOD_ENTRY(newFDF, 0)
+       JS_STATIC_METHOD_ENTRY(newDoc, 0)
+       JS_STATIC_METHOD_ENTRY(openDoc, 0)
+       JS_STATIC_METHOD_ENTRY(openFDF, 5)
+       JS_STATIC_METHOD_ENTRY(popUpMenuEx, 0)
+       JS_STATIC_METHOD_ENTRY(popUpMenu, 0)
+       JS_STATIC_METHOD_ENTRY(response, 0)
+       JS_STATIC_METHOD_ENTRY(setInterval, 2)
+       JS_STATIC_METHOD_ENTRY(setTimeOut, 2)
+END_JS_STATIC_METHOD()
+
+IMPLEMENT_JS_CLASS(CJS_App,app)
+
+app::app(CJS_Object * pJSObject) : CJS_EmbedObj(pJSObject) ,
+       m_bCalculate(true),
+       m_bRuntimeHighLight(false)
+//     m_pMenuHead(NULL)
+{
+}
+
+app::~app(void)
+{
+       for (int i=0,sz=m_aTimer.GetSize(); i<sz; i++)
+               delete m_aTimer[i];
+
+       m_aTimer.RemoveAll();
+}
+
+FX_BOOL app::activeDocs(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
+{
+       if (vp.IsGetting())
+       {
+
+               CJS_Context* pContext = (CJS_Context *)cc;
+               ASSERT(pContext != NULL);
+
+               CPDFDoc_Environment* pApp = pContext->GetReaderApp();
+               ASSERT(pApp != NULL);
+
+               CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+               ASSERT(pRuntime != NULL);
+
+               CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument();
+
+               CJS_Array aDocs(pRuntime->GetIsolate());
+//             int iNumDocs = pApp->CountDocuments();
+
+//             for(int iIndex = 0; iIndex<iNumDocs; iIndex++)
+//             {
+                       CPDFSDK_Document* pDoc = pApp->GetCurrentDoc();
+                       if (pDoc)
+                       {
+                               CJS_Document * pJSDocument = NULL;
+
+                               if (pDoc == pCurDoc)
+                               {
+                                       JSFXObject pObj = JS_GetThisObj(*pRuntime);
+
+                                       if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"Document"))
+                                       {
+                                               pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj);
+                                       }
+                               }
+                               else
+                               {
+                                       JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime,L"Document"));
+                                       pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj);
+                                       ASSERT(pJSDocument != NULL);
+
+
+                                       //                      pDocument->AttachDoc(pDoc);
+                               }
+
+                               aDocs.SetElement(0,CJS_Value(pRuntime->GetIsolate(),pJSDocument));
+                       }
+       //              }
+
+               if (aDocs.GetLength() > 0)
+                       vp << aDocs;
+               else
+                       vp.SetNull();
+               return TRUE;
+       }
+       return FALSE;
+}
+
+FX_BOOL app::calculate(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
+{
+       if (vp.IsSetting())
+       {
+               bool bVP;
+               vp >> bVP;
+               m_bCalculate = (FX_BOOL)bVP;
+
+               CJS_Context* pContext = (CJS_Context*)cc;
+               ASSERT(pContext != NULL);
+
+               CPDFDoc_Environment* pApp = pContext->GetReaderApp();
+               ASSERT(pApp != NULL);
+
+               CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+               ASSERT(pRuntime != NULL);
+
+               CJS_Array aDocs(pRuntime->GetIsolate());
+               if (CPDFSDK_Document* pDoc = pApp->GetCurrentDoc())
+               {
+                       CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDoc->GetInterForm();
+                       ASSERT(pInterForm != NULL);
+                       pInterForm->EnableCalculate((FX_BOOL)m_bCalculate);
+               }
+       }
+       else
+       {
+               vp << (bool)m_bCalculate;
+       }
+
+       return TRUE;
+}
+
+FX_BOOL app::formsVersion(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
+{
+       if (vp.IsGetting())
+       {
+               vp << JS_NUM_FORMSVERSION;
+               return TRUE;
+       }
+
+       return FALSE;
+}
+
+FX_BOOL app::viewerType(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
+{
+       if (vp.IsGetting())
+       {
+               vp << L"unknown";
+               return TRUE;
+       }
+
+       return FALSE;
+}
+
+FX_BOOL app::viewerVariation(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
+{
+       if (vp.IsGetting())
+       {
+               vp << JS_STR_VIEWERVARIATION;
+               return TRUE;
+       }
+
+       return FALSE;
+}
+
+FX_BOOL app::viewerVersion(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
+{
+       if (vp.IsGetting())
+       {
+               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;
+       }
+
+       return FALSE;
+}
+
+FX_BOOL app::platform(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
+{
+       if (vp.IsGetting())
+       {
+               vp << JS_STR_PLATFORM;
+               return TRUE;
+       }
+
+       return FALSE;
+}
+
+FX_BOOL app::language(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
+{
+       if (vp.IsGetting())
+       {
+               vp << JS_STR_LANGUANGE;
+               return TRUE;
+       }
+
+       return FALSE;
+}
+
+//creates a new fdf object that contains no data
+//comment: need reader support
+//note:
+//CFDF_Document * CPDFDoc_Environment::NewFDF();
+FX_BOOL app::newFDF(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
+{
+       return TRUE;
+}
+//opens a specified pdf document and returns its document object
+//comment:need reader support
+//note: as defined in js reference, the proto of this function's fourth parmeters, how old an fdf document while do not show it.
+//CFDF_Document * CPDFDoc_Environment::OpenFDF(string strPath,bool bUserConv);
+
+FX_BOOL app::openFDF(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
+{
+       return TRUE;
+}
+
+FX_BOOL app::alert(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
+{
+       int iSize = params.size();
+       if (iSize < 1)
+               return FALSE;
+
+       CFX_WideString swMsg = L"";
+       CFX_WideString swTitle = L"";
+       int iIcon = 0;
+       int iType = 0;
+
+       v8::Isolate* isolate = GetIsolate(cc);
+
+       if (iSize == 1)
+       {
+               if (params[0].GetType() == VT_object)
+               {
+                       JSObject pObj = params[0].ToV8Object();
+                       {
+                               v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate, pObj, L"cMsg");
+                               swMsg = CJS_Value(isolate, pValue, VT_unknown).ToCFXWideString();
+
+                               pValue = JS_GetObjectElement(isolate, pObj, L"cTitle");
+                               swTitle = CJS_Value(isolate, pValue, VT_unknown).ToCFXWideString();
+
+                               pValue = JS_GetObjectElement(isolate, pObj, L"nIcon");
+                               iIcon = CJS_Value(isolate, pValue, VT_unknown).ToInt();
+
+                               pValue = JS_GetObjectElement(isolate, pObj, L"nType");
+                               iType = CJS_Value(isolate, pValue, VT_unknown).ToInt();
+                       }
+
+                       if (swMsg == L"")
+                       {
+                               CJS_Array carray(isolate);
+                               if (params[0].ConvertToArray(carray))
+                               {
+                                       int iLenth = carray.GetLength();
+                                       CJS_Value* pValue = new CJS_Value(isolate);
+//                                     if (iLenth == 1)
+//                                             pValue = new CJS_Value(isolate);
+//                                     else if (iLenth > 1)
+//                                             pValue = new CJS_Value[iLenth];
+
+                                       for(int i = 0; i < iLenth; i++)
+                                       {
+                                               carray.GetElement(i, *pValue);
+                                               swMsg += (*pValue).ToCFXWideString();
+                                               if (i < iLenth - 1)
+                                                       swMsg += L",  ";
+                                       }
+
+                                       if(pValue) delete pValue;
+                               }
+                       }
+
+                       if (swTitle == L"")
+                               swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
+               }
+               else if (params[0].GetType() == VT_boolean)
+               {
+                       FX_BOOL bGet = params[0].ToBool();
+                       if (bGet)
+                               swMsg = L"true";
+                       else
+                               swMsg = L"false";
+
+                       swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
+               }
+               else
+               {
+                       swMsg = params[0].ToCFXWideString();
+                       swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
+               }
+       }
+       else
+       {
+               if (params[0].GetType() == VT_boolean)
+               {
+                       FX_BOOL bGet = params[0].ToBool();
+                       if (bGet)
+                               swMsg = L"true";
+                       else
+                               swMsg = L"false";
+               }
+               else
+               {
+                       swMsg = params[0].ToCFXWideString();
+               }
+               swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
+
+               for(int i = 1;i<iSize;i++)
+               {
+                       if (i == 1)
+                               iIcon = params[i].ToInt();
+                       if (i == 2)
+                               iType = params[i].ToInt();
+                       if (i == 3)
+                               swTitle = params[i].ToCFXWideString();
+               }
+       }
+
+
+       CJS_Context* pContext = (CJS_Context*)cc;
+       ASSERT(pContext != NULL);
+       CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+       ASSERT(pRuntime != NULL);
+       pRuntime->BeginBlock();
+       vRet = MsgBox(pRuntime->GetReaderApp(), JSGetPageView(cc),swMsg,swTitle,iType,iIcon);
+       pRuntime->EndBlock();
+
+       return TRUE;
+}
+
+
+FX_BOOL app::beep(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
+{
+       if (params.size() == 1)
+       {
+               CJS_Context* pContext = (CJS_Context*)cc;
+               CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+               CPDFDoc_Environment * pEnv = pRuntime->GetReaderApp();
+               pEnv->JS_appBeep(params[0].ToInt());
+               return TRUE;
+       }
+
+       sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
+       return FALSE;
+}
+
+FX_BOOL app::findComponent(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
+{
+       return TRUE;
+}
+
+FX_BOOL app::popUpMenuEx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
+{
+       return FALSE;
+}
+
+FX_BOOL app::fs(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
+{
+       return FALSE;
+}
+
+FX_BOOL app::setInterval(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
+{
+       if (params.size() > 2 || params.size() == 0)
+       {
+               sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
+               return FALSE;
+       }
+
+       CJS_Context* pContext = (CJS_Context*)cc;
+       ASSERT(pContext != NULL);
+       CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+       ASSERT(pRuntime != NULL);
+
+       CFX_WideString script = params.size() > 0 ?  (FX_LPCWSTR)(params[0].ToCFXWideString()) : L"";
+       if (script.IsEmpty())
+       {
+               sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSAFNUMBER_KEYSTROKE);
+               return TRUE;
+       }
+
+       FX_DWORD dwInterval = params.size() > 1 ? params[1].ToInt() : 1000;
+
+       CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
+       ASSERT(pApp);
+       CJS_Timer* pTimer = new CJS_Timer(this, pApp);
+       m_aTimer.Add(pTimer);
+
+       pTimer->SetType(0);
+       pTimer->SetRuntime(pRuntime);
+       pTimer->SetJScript(script);
+       pTimer->SetTimeOut(0);
+//     pTimer->SetStartTime(GetTickCount());
+       pTimer->SetJSTimer(dwInterval);
+
+       JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"TimerObj"));
+
+       CJS_TimerObj* pJS_TimerObj = (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetIsolate(),pRetObj);
+       ASSERT(pJS_TimerObj != NULL);
+
+       TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
+       ASSERT(pTimerObj != NULL);
+
+       pTimerObj->SetTimer(pTimer);
+
+       vRet = pRetObj;
+
+       return TRUE;
+}
+
+FX_BOOL app::setTimeOut(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
+{
+       if (params.size() > 2 || params.size() == 0)
+       {
+               sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
+               return FALSE;
+       }
+
+       CJS_Context* pContext = (CJS_Context*)cc;
+       ASSERT(pContext != NULL);
+       CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+       ASSERT(pRuntime != NULL);
+
+       CFX_WideString script = params.size() > 0 ?  (FX_LPCWSTR)(params[0].ToCFXWideString()) : L"";
+       if (script.IsEmpty())
+       {
+               sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSAFNUMBER_KEYSTROKE);
+               return TRUE;
+       }
+
+       FX_DWORD dwTimeOut = params.size() > 1 ? params[1].ToInt() : 1000;
+
+       CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
+       ASSERT(pApp);
+
+       CJS_Timer* pTimer = new CJS_Timer(this, pApp);
+       m_aTimer.Add(pTimer);
+
+       pTimer->SetType(1);
+       pTimer->SetRuntime(pRuntime);
+       pTimer->SetJScript(script);
+       pTimer->SetTimeOut(dwTimeOut);
+       pTimer->SetJSTimer(dwTimeOut);
+
+       JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"TimerObj"));
+
+       CJS_TimerObj* pJS_TimerObj = (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetIsolate(),pRetObj);
+       ASSERT(pJS_TimerObj != NULL);
+
+       TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
+       ASSERT(pTimerObj != NULL);
+
+       pTimerObj->SetTimer(pTimer);
+
+       vRet = pRetObj;
+
+       return TRUE;
+}
+
+FX_BOOL app::clearTimeOut(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
+{
+       CJS_Context* pContext = (CJS_Context*)cc;
+       ASSERT(pContext != NULL);
+       CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+       ASSERT(pRuntime != NULL);
+
+       if (params.size() != 1)
+       {
+               sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
+               return FALSE;
+       }
+
+       if (params[0].GetType() == VT_fxobject)
+       {
+               JSFXObject pObj = params[0].ToV8Object();
+               {
+                       if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"TimerObj"))
+                       {
+                               if (CJS_Object* pJSObj = params[0].ToCJSObject())
+                               {
+                                       if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject())
+                                       {
+                                               if (CJS_Timer* pTimer = pTimerObj->GetTimer())
+                                               {
+                                                       pTimer->KillJSTimer();
+
+                                                       for (int i=0,sz=m_aTimer.GetSize(); i<sz; i++)
+                                                       {
+                                                               if (m_aTimer[i] == pTimer)
+                                                               {
+                                                                       m_aTimer.RemoveAt(i);
+                                                                       break;
+                                                               }
+                                                       }
+
+                                                       delete pTimer;
+                                                       pTimerObj->SetTimer(NULL);
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+
+       return TRUE;
+}
+
+FX_BOOL app::clearInterval(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
+{
+       CJS_Context* pContext = (CJS_Context*)cc;
+       ASSERT(pContext != NULL);
+       CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+       ASSERT(pRuntime != NULL);
+
+       if (params.size() != 1)
+       {
+               sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
+               return FALSE;
+       }
+
+       if (params[0].GetType() == VT_fxobject)
+       {
+               JSFXObject pObj = params[0].ToV8Object();
+               {
+                       if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"TimerObj"))
+                       {
+                               if (CJS_Object* pJSObj = params[0].ToCJSObject())
+                               {
+                                       if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject())
+                                       {
+                                               if (CJS_Timer* pTimer = pTimerObj->GetTimer())
+                                               {
+                                                       pTimer->KillJSTimer();
+
+                                                       for (int i=0,sz=m_aTimer.GetSize(); i<sz; i++)
+                                                       {
+                                                               if (m_aTimer[i] == pTimer)
+                                                               {
+                                                                       m_aTimer.RemoveAt(i);
+                                                                       break;
+                                                               }
+                                                       }
+
+                                                       delete pTimer;
+                                                       pTimerObj->SetTimer(NULL);
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+
+       return TRUE;
+}
+
+FX_BOOL app::execMenuItem(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
+{
+       return FALSE;
+}
+
+void app::TimerProc(CJS_Timer* pTimer)
+{
+       ASSERT(pTimer != NULL);
+
+       switch (pTimer->GetType())
+       {
+       case 0: //interval
+               RunJsScript(pTimer->GetRuntime(), pTimer->GetJScript());
+               break;
+       case 1:
+               if (pTimer->GetTimeOut() > 0)
+               {
+                       RunJsScript(pTimer->GetRuntime(), pTimer->GetJScript());
+                       pTimer->KillJSTimer();
+               }
+               break;
+       }
+
+}
+
+void app::RunJsScript(CJS_Runtime* pRuntime,const CFX_WideString& wsScript)
+{
+       ASSERT(pRuntime != NULL);
+
+       if (!pRuntime->IsBlocking())
+       {
+               IFXJS_Context* pContext = pRuntime->NewContext();
+               ASSERT(pContext != NULL);
+               pContext->OnExternal_Exec();
+               CFX_WideString wtInfo;
+               pContext->RunScript(wsScript,wtInfo);
+               pRuntime->ReleaseContext(pContext);
+       }
+}
+
+FX_BOOL app::goBack(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
+{
+  // Not supported.
+  return TRUE;
+}
+
+FX_BOOL app::goForward(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
+{
+  // Not supported.
+  return TRUE;
+}
+
+FX_BOOL app::mailMsg(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
+{
+       CJS_Context* pContext = (CJS_Context*)cc;
+       v8::Isolate* isolate = GetIsolate(cc);
+
+       FX_BOOL bUI = TRUE;
+       CFX_WideString cTo = L"";
+       CFX_WideString cCc = L"";
+       CFX_WideString cBcc = L"";
+       CFX_WideString cSubject = L"";
+       CFX_WideString cMsg = L"";
+
+       if (params.size() < 1)
+               return FALSE;
+
+       if (params[0].GetType() == VT_object)
+       {
+               JSObject pObj = params[0].ToV8Object();
+
+               v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate, pObj, L"bUI");
+               bUI = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool();
+
+               pValue = JS_GetObjectElement(isolate, pObj, L"cTo");
+               cTo = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
+
+               pValue = JS_GetObjectElement(isolate, pObj, L"cCc");
+               cCc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
+
+               pValue = JS_GetObjectElement(isolate, pObj, L"cBcc");
+               cBcc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
+
+               pValue = JS_GetObjectElement(isolate, pObj, L"cSubject");
+               cSubject = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
+
+               pValue = JS_GetObjectElement(isolate, pObj, L"cMsg");
+               cMsg = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
+       } else {
+               if (params.size() < 2)
+                       return FALSE;
+
+               bUI = params[0].ToBool();
+               cTo = params[1].ToCFXWideString();
+
+               if (params.size() >= 3)
+                       cCc = params[2].ToCFXWideString();
+               if (params.size() >= 4)
+                       cBcc = params[3].ToCFXWideString();
+               if (params.size() >= 5)
+                       cSubject = params[4].ToCFXWideString();
+               if (params.size() >= 6)
+                       cMsg = params[5].ToCFXWideString();
+       }
+
+       CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+       ASSERT(pRuntime != NULL);
+
+       CPDFDoc_Environment* pApp = pContext->GetReaderApp();
+       ASSERT(pApp != NULL);
+
+       pRuntime->BeginBlock();
+       pApp->JS_docmailForm(NULL, 0, bUI, cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), cMsg.c_str());
+       pRuntime->EndBlock();
+
+       return FALSE;
+}
+
+FX_BOOL app::launchURL(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
+{
+  // Unsafe, not supported.
+  return TRUE;
+}
+
+FX_BOOL app::runtimeHighlight(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
+{
+       if (vp.IsSetting())
+       {
+               vp>>m_bRuntimeHighLight;
+       }
+       else
+       {
+               vp<<m_bRuntimeHighLight;
+       }
+
+       return TRUE;
+}
+
+FX_BOOL app::fullscreen(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
+{
+       return FALSE;
+}
+
+FX_BOOL app::popUpMenu(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
+{
+       return FALSE;
+}
+
+
+FX_BOOL app::browseForDoc(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
+{
+  // Unsafe, not supported.
+  return TRUE;
+}
+
+CFX_WideString app::SysPathToPDFPath(const CFX_WideString& sOldPath)
+{
+       CFX_WideString sRet = L"/";
+
+       for (int i=0,sz=sOldPath.GetLength(); i<sz; i++)
+       {
+               wchar_t c = sOldPath.GetAt(i);
+               if (c == L':')
+               {
+               }
+               else
+               {
+                       if (c == L'\\')
+                       {
+                               sRet += L"/";
+                       }
+                       else
+                       {
+                               sRet += c;
+                       }
+               }
+       }
+
+       return sRet;
+}
+
+FX_BOOL app::newDoc(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
+{
+       return FALSE;
+}
+
+FX_BOOL app::openDoc(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
+{
+       return FALSE;
+}
+
+FX_BOOL app::response(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
+{
+       CFX_WideString swQuestion = L"";
+       CFX_WideString swLabel = L"";
+       CFX_WideString swTitle = L"PDF";
+       CFX_WideString swDefault = L"";
+       bool bPassWord = false;
+
+       v8::Isolate* isolate = GetIsolate(cc);
+
+       int iLength = params.size();
+       if (iLength > 0 && params[0].GetType() == VT_object)
+       {
+               JSObject pObj = params[0].ToV8Object();
+               v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj,L"cQuestion");
+               swQuestion = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString();
+
+               pValue = JS_GetObjectElement(isolate,pObj,L"cTitle");
+               swTitle = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString();
+
+               pValue = JS_GetObjectElement(isolate,pObj,L"cDefault");
+               swDefault = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString();
+
+               pValue = JS_GetObjectElement(isolate,pObj,L"cLabel");
+               swLabel = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString();
+
+               pValue = JS_GetObjectElement(isolate,pObj,L"bPassword");
+               bPassWord = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToBool();
+       }
+       else
+       {
+               switch(iLength)
+               {
+               case 5:
+                       swLabel = params[4].ToCFXWideString();
+                       // FALLTHROUGH
+               case 4:
+                       bPassWord = params[3].ToBool();
+                       // FALLTHROUGH
+               case 3:
+                       swDefault = params[2].ToCFXWideString();
+                       // FALLTHROUGH
+               case 2:
+                       swTitle = params[1].ToCFXWideString();
+                       // FALLTHROUGH
+               case 1:
+                       swQuestion = params[0].ToCFXWideString();
+                       // FALLTHROUGH
+               default:
+                       break;
+               }
+       }
+
+       CJS_Context* pContext = (CJS_Context *)cc;
+       ASSERT(pContext != NULL);
+
+       CPDFDoc_Environment* pApp = pContext->GetReaderApp();
+       ASSERT(pApp != NULL);
+
+       const int MAX_INPUT_BYTES = 2048;
+       char* pBuff = new char[MAX_INPUT_BYTES + 2];
+       if (!pBuff)
+               return FALSE;
+
+       memset(pBuff, 0, MAX_INPUT_BYTES + 2);
+       int nLengthBytes = pApp->JS_appResponse(swQuestion, swTitle, swDefault, swLabel, bPassWord, pBuff, MAX_INPUT_BYTES);
+       if (nLengthBytes <= 0)
+       {
+               vRet.SetNull();
+               delete[] pBuff;
+               return FALSE;
+       }
+       if (nLengthBytes > MAX_INPUT_BYTES)
+               nLengthBytes = MAX_INPUT_BYTES;
+
+       vRet = CFX_WideString::FromUTF16LE((unsigned short*)pBuff, nLengthBytes / sizeof(unsigned short));
+       delete[] pBuff;
+       return TRUE;
+}
+
+FX_BOOL app::media(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
+{
+       return FALSE;
+}
+
+FX_BOOL app::execDialog(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
+{
+       return TRUE;
+}