summaryrefslogtreecommitdiff
path: root/fpdfsdk/src/javascript/app.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2014-07-29 14:01:21 -0700
committerTom Sepez <tsepez@chromium.org>2014-07-29 14:01:21 -0700
commit621d4de9672bf8def81edba90b9a6d4fd83ea1da (patch)
treec9f2a6e3321f12120e7bb6df1db897fa4253a198 /fpdfsdk/src/javascript/app.cpp
parent6c55495fcaf634e7f788f4dfe77fa1a106c9cd55 (diff)
downloadpdfium-621d4de9672bf8def81edba90b9a6d4fd83ea1da.tar.xz
Tidy up app::response().
Follow-up from https://codereview.chromium.org/424883002/ - Remove some stray whitespace. - Fix "else after return". - Remove unused swResponse local. - Treat unexpectedly large responses as errors. BUG= R=jun_fang@foxitsoftware.com Review URL: https://codereview.chromium.org/423953002
Diffstat (limited to 'fpdfsdk/src/javascript/app.cpp')
-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;
}