1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
7 #include "../../include/javascript/JavaScript.h"
8 #include "../../include/javascript/IJavaScript.h"
9 #include "../../include/javascript/JS_Define.h"
10 #include "../../include/javascript/JS_Object.h"
11 #include "../../include/javascript/JS_Value.h"
12 #include "../../include/javascript/app.h"
13 #include "../../include/javascript/JS_EventHandler.h"
14 #include "../../include/javascript/resource.h"
15 #include "../../include/javascript/JS_Context.h"
16 #include "../../include/javascript/JS_Runtime.h"
17 #include "../../include/javascript/Document.h"
20 static v8::Isolate* GetIsolate(IFXJS_Context* cc)
22 CJS_Context* pContext = (CJS_Context *)cc;
23 ASSERT(pContext != NULL);
25 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
26 ASSERT(pRuntime != NULL);
28 return pRuntime->GetIsolate();
31 /* ---------------------------- TimerObj ---------------------------- */
33 BEGIN_JS_STATIC_CONST(CJS_TimerObj)
36 BEGIN_JS_STATIC_PROP(CJS_TimerObj)
39 BEGIN_JS_STATIC_METHOD(CJS_TimerObj)
40 END_JS_STATIC_METHOD()
42 IMPLEMENT_JS_CLASS(CJS_TimerObj, TimerObj)
44 TimerObj::TimerObj(CJS_Object* pJSObject)
45 : CJS_EmbedObj(pJSObject),
55 void TimerObj::SetTimer(CJS_Timer* pTimer)
60 CJS_Timer* TimerObj::GetTimer() const
65 #define JS_STR_VIEWERTYPE_READER L"Reader"
66 #define JS_STR_VIEWERTYPE_STANDARD L"Exchange"
67 #define JS_STR_VIEWERVARIATION L"Full"
68 #define JS_STR_PLATFORM L"WIN"
69 #define JS_STR_LANGUANGE L"ENU"
70 #define JS_STR_VIEWERVERSION 8
71 #define JS_NUM_FORMSVERSION 7
73 #define JS_FILEPATH_MAXLEN 2000
75 /* ---------------------------- app ---------------------------- */
77 BEGIN_JS_STATIC_CONST(CJS_App)
80 BEGIN_JS_STATIC_PROP(CJS_App)
81 JS_STATIC_PROP_ENTRY(activeDocs)
82 JS_STATIC_PROP_ENTRY(calculate)
83 JS_STATIC_PROP_ENTRY(formsVersion)
84 JS_STATIC_PROP_ENTRY(fs)
85 JS_STATIC_PROP_ENTRY(fullscreen)
86 JS_STATIC_PROP_ENTRY(language)
87 JS_STATIC_PROP_ENTRY(media)
88 JS_STATIC_PROP_ENTRY(platform)
89 JS_STATIC_PROP_ENTRY(runtimeHighlight)
90 JS_STATIC_PROP_ENTRY(viewerType)
91 JS_STATIC_PROP_ENTRY(viewerVariation)
92 JS_STATIC_PROP_ENTRY(viewerVersion)
95 BEGIN_JS_STATIC_METHOD(CJS_App)
96 JS_STATIC_METHOD_ENTRY(alert)
97 JS_STATIC_METHOD_ENTRY(beep)
98 JS_STATIC_METHOD_ENTRY(browseForDoc)
99 JS_STATIC_METHOD_ENTRY(clearInterval)
100 JS_STATIC_METHOD_ENTRY(clearTimeOut)
101 JS_STATIC_METHOD_ENTRY(execDialog)
102 JS_STATIC_METHOD_ENTRY(execMenuItem)
103 JS_STATIC_METHOD_ENTRY(findComponent)
104 JS_STATIC_METHOD_ENTRY(goBack)
105 JS_STATIC_METHOD_ENTRY(goForward)
106 JS_STATIC_METHOD_ENTRY(launchURL)
107 JS_STATIC_METHOD_ENTRY(mailMsg)
108 JS_STATIC_METHOD_ENTRY(newFDF)
109 JS_STATIC_METHOD_ENTRY(newDoc)
110 JS_STATIC_METHOD_ENTRY(openDoc)
111 JS_STATIC_METHOD_ENTRY(openFDF)
112 JS_STATIC_METHOD_ENTRY(popUpMenuEx)
113 JS_STATIC_METHOD_ENTRY(popUpMenu)
114 JS_STATIC_METHOD_ENTRY(response)
115 JS_STATIC_METHOD_ENTRY(setInterval)
116 JS_STATIC_METHOD_ENTRY(setTimeOut)
117 END_JS_STATIC_METHOD()
119 IMPLEMENT_JS_CLASS(CJS_App,app)
121 app::app(CJS_Object * pJSObject) : CJS_EmbedObj(pJSObject) ,
123 m_bRuntimeHighLight(false)
130 for (int i=0,sz=m_aTimer.GetSize(); i<sz; i++)
133 m_aTimer.RemoveAll();
136 FX_BOOL app::activeDocs(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
141 CJS_Context* pContext = (CJS_Context *)cc;
142 ASSERT(pContext != NULL);
144 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
145 ASSERT(pApp != NULL);
147 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
148 ASSERT(pRuntime != NULL);
150 CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument();
152 CJS_Array aDocs(pRuntime->GetIsolate());
153 // int iNumDocs = pApp->CountDocuments();
155 // for(int iIndex = 0; iIndex<iNumDocs; iIndex++)
157 CPDFSDK_Document* pDoc = pApp->GetCurrentDoc();
160 CJS_Document * pJSDocument = NULL;
164 JSFXObject pObj = JS_GetThisObj(*pRuntime);
166 if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"Document"))
168 pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj);
173 JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime,L"Document"));
174 pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj);
175 ASSERT(pJSDocument != NULL);
178 // pDocument->AttachDoc(pDoc);
181 aDocs.SetElement(0,CJS_Value(pRuntime->GetIsolate(),pJSDocument));
185 if (aDocs.GetLength() > 0)
194 FX_BOOL app::calculate(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
200 m_bCalculate = (FX_BOOL)bVP;
202 CJS_Context* pContext = (CJS_Context*)cc;
203 ASSERT(pContext != NULL);
205 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
206 ASSERT(pApp != NULL);
208 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
209 ASSERT(pRuntime != NULL);
211 CJS_Array aDocs(pRuntime->GetIsolate());
212 if (CPDFSDK_Document* pDoc = pApp->GetCurrentDoc())
214 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDoc->GetInterForm();
215 ASSERT(pInterForm != NULL);
216 pInterForm->EnableCalculate((FX_BOOL)m_bCalculate);
221 vp << (bool)m_bCalculate;
227 FX_BOOL app::formsVersion(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
231 vp << JS_NUM_FORMSVERSION;
238 FX_BOOL app::viewerType(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
249 FX_BOOL app::viewerVariation(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
253 vp << JS_STR_VIEWERVARIATION;
260 FX_BOOL app::viewerVersion(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
264 vp << JS_STR_VIEWERVERSION;
271 FX_BOOL app::platform(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
275 vp << JS_STR_PLATFORM;
282 FX_BOOL app::language(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
286 vp << JS_STR_LANGUANGE;
293 //creates a new fdf object that contains no data
294 //comment: need reader support
296 //CFDF_Document * CPDFDoc_Environment::NewFDF();
297 FX_BOOL app::newFDF(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
301 //opens a specified pdf document and returns its document object
302 //comment:need reader support
303 //note: as defined in js reference, the proto of this function's fourth parmeters, how old an fdf document while do not show it.
304 //CFDF_Document * CPDFDoc_Environment::OpenFDF(string strPath,bool bUserConv);
306 FX_BOOL app::openFDF(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
311 FX_BOOL app::alert(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
313 int iSize = params.size();
317 CFX_WideString swMsg = L"";
318 CFX_WideString swTitle = L"";
322 v8::Isolate* isolate = GetIsolate(cc);
326 if (params[0].GetType() == VT_object)
328 JSObject pObj = params[0].ToV8Object();
330 v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate, pObj, L"cMsg");
331 swMsg = CJS_Value(isolate, pValue, VT_unknown).ToCFXWideString();
333 pValue = JS_GetObjectElement(isolate, pObj, L"cTitle");
334 swTitle = CJS_Value(isolate, pValue, VT_unknown).ToCFXWideString();
336 pValue = JS_GetObjectElement(isolate, pObj, L"nIcon");
337 iIcon = CJS_Value(isolate, pValue, VT_unknown).ToInt();
339 pValue = JS_GetObjectElement(isolate, pObj, L"nType");
340 iType = CJS_Value(isolate, pValue, VT_unknown).ToInt();
345 CJS_Array carray(isolate);
346 if (params[0].ConvertToArray(carray))
348 int iLenth = carray.GetLength();
349 CJS_Value* pValue = new CJS_Value(isolate);
351 // pValue = new CJS_Value(isolate);
352 // else if (iLenth > 1)
353 // pValue = new CJS_Value[iLenth];
355 for(int i = 0; i < iLenth; i++)
357 carray.GetElement(i, *pValue);
358 swMsg += (*pValue).ToCFXWideString();
363 if(pValue) delete pValue;
368 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
370 else if (params[0].GetType() == VT_boolean)
372 FX_BOOL bGet = params[0].ToBool();
378 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
382 swMsg = params[0].ToCFXWideString();
383 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
388 if (params[0].GetType() == VT_boolean)
390 FX_BOOL bGet = params[0].ToBool();
398 swMsg = params[0].ToCFXWideString();
400 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
402 for(int i = 1;i<iSize;i++)
405 iIcon = params[i].ToInt();
407 iType = params[i].ToInt();
409 swTitle = params[i].ToCFXWideString();
414 CJS_Context* pContext = (CJS_Context*)cc;
415 ASSERT(pContext != NULL);
416 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
417 ASSERT(pRuntime != NULL);
418 pRuntime->BeginBlock();
419 vRet = MsgBox(pRuntime->GetReaderApp(), JSGetPageView(cc), swMsg.c_str(), swTitle.c_str(), iType, iIcon);
420 pRuntime->EndBlock();
426 FX_BOOL app::beep(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
428 if (params.size() == 1)
430 CJS_Context* pContext = (CJS_Context*)cc;
431 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
432 CPDFDoc_Environment * pEnv = pRuntime->GetReaderApp();
433 pEnv->JS_appBeep(params[0].ToInt());
437 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
441 FX_BOOL app::findComponent(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
446 FX_BOOL app::popUpMenuEx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
451 FX_BOOL app::fs(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
456 FX_BOOL app::setInterval(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
458 CJS_Context* pContext = (CJS_Context*)cc;
459 if (params.size() > 2 || params.size() == 0)
461 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
465 CFX_WideString script = params.size() > 0 ? params[0].ToCFXWideString() : L"";
466 if (script.IsEmpty())
468 sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE);
472 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
473 FX_DWORD dwInterval = params.size() > 1 ? params[1].ToInt() : 1000;
475 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
477 CJS_Timer* pTimer = new CJS_Timer(this, pApp);
478 m_aTimer.Add(pTimer);
481 pTimer->SetRuntime(pRuntime);
482 pTimer->SetJScript(script);
483 pTimer->SetTimeOut(0);
484 // pTimer->SetStartTime(GetTickCount());
485 pTimer->SetJSTimer(dwInterval);
487 JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"TimerObj"));
489 CJS_TimerObj* pJS_TimerObj = (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetIsolate(),pRetObj);
490 ASSERT(pJS_TimerObj != NULL);
492 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
493 ASSERT(pTimerObj != NULL);
495 pTimerObj->SetTimer(pTimer);
502 FX_BOOL app::setTimeOut(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
504 if (params.size() > 2 || params.size() == 0)
506 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
510 CJS_Context* pContext = (CJS_Context*)cc;
511 ASSERT(pContext != NULL);
512 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
513 ASSERT(pRuntime != NULL);
515 CFX_WideString script = params.size() > 0 ? params[0].ToCFXWideString() : L"";
516 if (script.IsEmpty())
518 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSAFNUMBER_KEYSTROKE);
522 FX_DWORD dwTimeOut = params.size() > 1 ? params[1].ToInt() : 1000;
524 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
527 CJS_Timer* pTimer = new CJS_Timer(this, pApp);
528 m_aTimer.Add(pTimer);
531 pTimer->SetRuntime(pRuntime);
532 pTimer->SetJScript(script);
533 pTimer->SetTimeOut(dwTimeOut);
534 pTimer->SetJSTimer(dwTimeOut);
536 JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"TimerObj"));
538 CJS_TimerObj* pJS_TimerObj = (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetIsolate(),pRetObj);
539 ASSERT(pJS_TimerObj != NULL);
541 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
542 ASSERT(pTimerObj != NULL);
544 pTimerObj->SetTimer(pTimer);
551 FX_BOOL app::clearTimeOut(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
553 CJS_Context* pContext = (CJS_Context*)cc;
554 ASSERT(pContext != NULL);
555 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
556 ASSERT(pRuntime != NULL);
558 if (params.size() != 1)
560 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
564 if (params[0].GetType() == VT_fxobject)
566 JSFXObject pObj = params[0].ToV8Object();
568 if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"TimerObj"))
570 if (CJS_Object* pJSObj = params[0].ToCJSObject())
572 if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject())
574 if (CJS_Timer* pTimer = pTimerObj->GetTimer())
576 pTimer->KillJSTimer();
578 for (int i=0,sz=m_aTimer.GetSize(); i<sz; i++)
580 if (m_aTimer[i] == pTimer)
582 m_aTimer.RemoveAt(i);
588 pTimerObj->SetTimer(NULL);
599 FX_BOOL app::clearInterval(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
601 CJS_Context* pContext = (CJS_Context*)cc;
602 ASSERT(pContext != NULL);
603 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
604 ASSERT(pRuntime != NULL);
606 if (params.size() != 1)
608 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
612 if (params[0].GetType() == VT_fxobject)
614 JSFXObject pObj = params[0].ToV8Object();
616 if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"TimerObj"))
618 if (CJS_Object* pJSObj = params[0].ToCJSObject())
620 if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject())
622 if (CJS_Timer* pTimer = pTimerObj->GetTimer())
624 pTimer->KillJSTimer();
626 for (int i=0,sz=m_aTimer.GetSize(); i<sz; i++)
628 if (m_aTimer[i] == pTimer)
630 m_aTimer.RemoveAt(i);
636 pTimerObj->SetTimer(NULL);
647 FX_BOOL app::execMenuItem(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
652 void app::TimerProc(CJS_Timer* pTimer)
654 ASSERT(pTimer != NULL);
656 switch (pTimer->GetType())
659 RunJsScript(pTimer->GetRuntime(), pTimer->GetJScript());
662 if (pTimer->GetTimeOut() > 0)
664 RunJsScript(pTimer->GetRuntime(), pTimer->GetJScript());
665 pTimer->KillJSTimer();
672 void app::RunJsScript(CJS_Runtime* pRuntime,const CFX_WideString& wsScript)
674 ASSERT(pRuntime != NULL);
676 if (!pRuntime->IsBlocking())
678 IFXJS_Context* pContext = pRuntime->NewContext();
679 ASSERT(pContext != NULL);
680 pContext->OnExternal_Exec();
681 CFX_WideString wtInfo;
682 pContext->RunScript(wsScript,wtInfo);
683 pRuntime->ReleaseContext(pContext);
687 FX_BOOL app::goBack(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
693 FX_BOOL app::goForward(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
699 FX_BOOL app::mailMsg(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
701 CJS_Context* pContext = (CJS_Context*)cc;
702 v8::Isolate* isolate = GetIsolate(cc);
705 CFX_WideString cTo = L"";
706 CFX_WideString cCc = L"";
707 CFX_WideString cBcc = L"";
708 CFX_WideString cSubject = L"";
709 CFX_WideString cMsg = L"";
711 if (params.size() < 1)
714 if (params[0].GetType() == VT_object)
716 JSObject pObj = params[0].ToV8Object();
718 v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate, pObj, L"bUI");
719 bUI = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool();
721 pValue = JS_GetObjectElement(isolate, pObj, L"cTo");
722 cTo = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
724 pValue = JS_GetObjectElement(isolate, pObj, L"cCc");
725 cCc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
727 pValue = JS_GetObjectElement(isolate, pObj, L"cBcc");
728 cBcc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
730 pValue = JS_GetObjectElement(isolate, pObj, L"cSubject");
731 cSubject = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
733 pValue = JS_GetObjectElement(isolate, pObj, L"cMsg");
734 cMsg = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
736 if (params.size() < 2)
739 bUI = params[0].ToBool();
740 cTo = params[1].ToCFXWideString();
742 if (params.size() >= 3)
743 cCc = params[2].ToCFXWideString();
744 if (params.size() >= 4)
745 cBcc = params[3].ToCFXWideString();
746 if (params.size() >= 5)
747 cSubject = params[4].ToCFXWideString();
748 if (params.size() >= 6)
749 cMsg = params[5].ToCFXWideString();
752 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
753 ASSERT(pRuntime != NULL);
755 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
756 ASSERT(pApp != NULL);
758 pRuntime->BeginBlock();
759 pApp->JS_docmailForm(NULL, 0, bUI, cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), cMsg.c_str());
760 pRuntime->EndBlock();
765 FX_BOOL app::launchURL(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
767 // Unsafe, not supported.
771 FX_BOOL app::runtimeHighlight(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
775 vp>>m_bRuntimeHighLight;
779 vp<<m_bRuntimeHighLight;
785 FX_BOOL app::fullscreen(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
790 FX_BOOL app::popUpMenu(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
796 FX_BOOL app::browseForDoc(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
798 // Unsafe, not supported.
802 CFX_WideString app::SysPathToPDFPath(const CFX_WideString& sOldPath)
804 CFX_WideString sRet = L"/";
806 for (int i=0,sz=sOldPath.GetLength(); i<sz; i++)
808 wchar_t c = sOldPath.GetAt(i);
828 FX_BOOL app::newDoc(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
833 FX_BOOL app::openDoc(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
838 FX_BOOL app::response(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)
840 CFX_WideString swQuestion = L"";
841 CFX_WideString swLabel = L"";
842 CFX_WideString swTitle = L"PDF";
843 CFX_WideString swDefault = L"";
844 bool bPassWord = false;
846 v8::Isolate* isolate = GetIsolate(cc);
848 int iLength = params.size();
849 if (iLength > 0 && params[0].GetType() == VT_object)
851 JSObject pObj = params[0].ToV8Object();
852 v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj,L"cQuestion");
853 swQuestion = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString();
855 pValue = JS_GetObjectElement(isolate,pObj,L"cTitle");
856 swTitle = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString();
858 pValue = JS_GetObjectElement(isolate,pObj,L"cDefault");
859 swDefault = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString();
861 pValue = JS_GetObjectElement(isolate,pObj,L"cLabel");
862 swLabel = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString();
864 pValue = JS_GetObjectElement(isolate,pObj,L"bPassword");
865 bPassWord = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToBool();
872 swLabel = params[4].ToCFXWideString();
875 bPassWord = params[3].ToBool();
878 swDefault = params[2].ToCFXWideString();
881 swTitle = params[1].ToCFXWideString();
884 swQuestion = params[0].ToCFXWideString();
891 CJS_Context* pContext = (CJS_Context *)cc;
892 ASSERT(pContext != NULL);
894 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
895 ASSERT(pApp != NULL);
897 const int MAX_INPUT_BYTES = 2048;
898 char* pBuff = new char[MAX_INPUT_BYTES + 2];
902 memset(pBuff, 0, MAX_INPUT_BYTES + 2);
903 int nLengthBytes = pApp->JS_appResponse(swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(),
904 swLabel.c_str(), bPassWord, pBuff, MAX_INPUT_BYTES);
905 if (nLengthBytes <= 0)
911 if (nLengthBytes > MAX_INPUT_BYTES)
912 nLengthBytes = MAX_INPUT_BYTES;
914 vRet = CFX_WideString::FromUTF16LE((unsigned short*)pBuff, nLengthBytes / sizeof(unsigned short)).c_str();
919 FX_BOOL app::media(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
924 FX_BOOL app::execDialog(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError)