summaryrefslogtreecommitdiff
path: root/fpdfsdk/src
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk/src')
-rw-r--r--fpdfsdk/src/javascript/app.cpp79
1 files changed, 40 insertions, 39 deletions
diff --git a/fpdfsdk/src/javascript/app.cpp b/fpdfsdk/src/javascript/app.cpp
index 3b92a992d9..0546be8f86 100644
--- a/fpdfsdk/src/javascript/app.cpp
+++ b/fpdfsdk/src/javascript/app.cpp
@@ -153,8 +153,8 @@ FX_BOOL app::activeDocs(OBJ_PROP_PARAMS)
CJS_Array aDocs(pRuntime->GetIsolate());
// int iNumDocs = pApp->CountDocuments();
-// for(int iIndex = 0; iIndex<iNumDocs; iIndex++)
-// {
+// for(int iIndex = 0; iIndex<iNumDocs; iIndex++)
+// {
CPDFSDK_Document* pDoc = pApp->GetCurrentDoc();
if (pDoc)
{
@@ -210,10 +210,10 @@ FX_BOOL app::calculate(OBJ_PROP_PARAMS)
ASSERT(pRuntime != NULL);
CJS_Array aDocs(pRuntime->GetIsolate());
-// int iNumDocs = pApp->CountDocuments();
-//
-// for (int iIndex = 0;iIndex < iNumDocs; iIndex++)
-// {
+// int iNumDocs = pApp->CountDocuments();
+//
+// for (int iIndex = 0;iIndex < iNumDocs; iIndex++)
+// {
if (CPDFSDK_Document* pDoc = pApp->GetCurrentDoc())
{
CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDoc->GetInterForm();
@@ -251,10 +251,10 @@ FX_BOOL app::viewerType(OBJ_PROP_PARAMS)
if (vp.IsGetting())
{
-// if (pApp->GetAppName() == PHANTOM)
-// vp << JS_STR_VIEWERTYPE_STANDARD;
-// else
-// vp << JS_STR_VIEWERTYPE_READER;
+// if (pApp->GetAppName() == PHANTOM)
+// vp << JS_STR_VIEWERTYPE_STANDARD;
+// else
+// vp << JS_STR_VIEWERTYPE_READER;
vp << L"unknown";
//vp << pApp->GetAppTitle();
@@ -367,8 +367,8 @@ FX_BOOL app::alert(OBJ_METHOD_PARAMS)
CJS_Value* pValue = new CJS_Value(isolate);
// if (iLenth == 1)
// pValue = new CJS_Value(isolate);
-// else if (iLenth > 1)
-// pValue = new CJS_Value[iLenth];
+// else if (iLenth > 1)
+// pValue = new CJS_Value[iLenth];
for(int i = 0; i < iLenth; i++)
{
@@ -379,16 +379,16 @@ FX_BOOL app::alert(OBJ_METHOD_PARAMS)
}
if(pValue) delete pValue;
-// if ((iLenth > 1) && pValue)
-// {
-// delete[]pValue;
-// pValue = NULL;
-// }
-// else if ((iLenth == 1) && pValue)
-// {
-// delete pValue;
-// pValue = NULL;
-// }
+// if ((iLenth > 1) && pValue)
+// {
+// delete[]pValue;
+// pValue = NULL;
+// }
+// else if ((iLenth == 1) && pValue)
+// {
+// delete pValue;
+// pValue = NULL;
+// }
}
}
@@ -947,7 +947,7 @@ FX_BOOL app::browseForDoc(OBJ_METHOD_PARAMS)
JS_PutObjectString(isolate,pRetObj, L"cFS", CFX_WideString::FromLocal("DOS"));
}
- vRet = pRetObj;
+ vRet = pRetObj;
return TRUE;
}
@@ -1037,15 +1037,13 @@ FX_BOOL app::response(OBJ_METHOD_PARAMS)
CFX_WideString swTitle = L"PDF";
#endif
CFX_WideString swDefault = L"";
- CFX_WideString swResponse = L"";
bool bPassWord = false;
-
+
v8::Isolate* isolate = GetIsolate(cc);
-
- int iLength = params.size();
+
+ int iLength = params.size();
if (iLength > 0 && params[0].GetType() == VT_object)
{
-
JSObject pObj = (JSObject )params[0];
v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj,L"cQuestion");
swQuestion = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
@@ -1101,22 +1099,25 @@ FX_BOOL app::response(OBJ_METHOD_PARAMS)
CPDFDoc_Environment* pApp = pContext->GetReaderApp();
ASSERT(pApp != NULL);
- int nLength = 2048;
- char* pBuff = new char[nLength];
- nLength = pApp->JS_appResponse(swQuestion, swTitle, swDefault, swLabel, bPassWord, pBuff, nLength);
- if(nLength<=0)
+
+ 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)
{
- delete[] pBuff;
vRet.SetNull();
+ delete[] pBuff;
return FALSE;
}
- else
- {
- nLength = nLength > sizeof(pBuff) ? sizeof(pBuff) : nLength;
- vRet = swResponse = CFX_WideString::FromUTF16LE((unsigned short*)pBuff, nLength / 2);
- }
- delete[] pBuff;
+ if (nLengthBytes > MAX_INPUT_BYTES)
+ nLengthBytes = MAX_INPUT_BYTES;
+ vRet = CFX_WideString::FromUTF16LE((unsigned short*)pBuff, nLengthBytes);
+ delete[] pBuff;
return TRUE;
}