Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(410)

Side by Side Diff: fpdfsdk/src/javascript/app.cpp

Issue 423953002: Tidy up app::response(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Address comments. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../../include/javascript/JavaScript.h" 7 #include "../../include/javascript/JavaScript.h"
8 #include "../../include/javascript/IJavaScript.h" 8 #include "../../include/javascript/IJavaScript.h"
9 #include "../../include/javascript/JS_Define.h" 9 #include "../../include/javascript/JS_Define.h"
10 #include "../../include/javascript/JS_Object.h" 10 #include "../../include/javascript/JS_Object.h"
(...skipping 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 FX_BOOL app::response(OBJ_METHOD_PARAMS) 1030 FX_BOOL app::response(OBJ_METHOD_PARAMS)
1031 { 1031 {
1032 CFX_WideString swQuestion = L""; 1032 CFX_WideString swQuestion = L"";
1033 CFX_WideString swLabel = L""; 1033 CFX_WideString swLabel = L"";
1034 #ifndef FOXIT_CHROME_BUILD 1034 #ifndef FOXIT_CHROME_BUILD
1035 CFX_WideString swTitle = L"Foxit"; 1035 CFX_WideString swTitle = L"Foxit";
1036 #else 1036 #else
1037 CFX_WideString swTitle = L"PDF"; 1037 CFX_WideString swTitle = L"PDF";
1038 #endif 1038 #endif
1039 CFX_WideString swDefault = L""; 1039 CFX_WideString swDefault = L"";
1040 CFX_WideString swResponse = L"";
1041 bool bPassWord = false; 1040 bool bPassWord = false;
1042 » 1041
1043 v8::Isolate* isolate = GetIsolate(cc); 1042 v8::Isolate* isolate = GetIsolate(cc);
1044 » 1043
1045 » int iLength = params.size();» 1044 » int iLength = params.size();
1046 if (iLength > 0 && params[0].GetType() == VT_object) 1045 if (iLength > 0 && params[0].GetType() == VT_object)
1047 { 1046 {
1048
1049 JSObject pObj = (JSObject )params[0]; 1047 JSObject pObj = (JSObject )params[0];
1050 v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"cQuestion"); 1048 v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"cQuestion");
1051 swQuestion = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pVa lue)).operator CFX_WideString(); 1049 swQuestion = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pVa lue)).operator CFX_WideString();
1052 1050
1053 pValue = JS_GetObjectElement(isolate,pObj,L"cTitle"); 1051 pValue = JS_GetObjectElement(isolate,pObj,L"cTitle");
1054 swTitle = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue )).operator CFX_WideString(); 1052 swTitle = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue )).operator CFX_WideString();
1055 1053
1056 pValue = JS_GetObjectElement(isolate,pObj,L"cDefault"); 1054 pValue = JS_GetObjectElement(isolate,pObj,L"cDefault");
1057 swDefault = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pVal ue)).operator CFX_WideString(); 1055 swDefault = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pVal ue)).operator CFX_WideString();
1058 1056
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 default: 1092 default:
1095 break; 1093 break;
1096 } 1094 }
1097 } 1095 }
1098 1096
1099 CJS_Context* pContext = (CJS_Context *)cc; 1097 CJS_Context* pContext = (CJS_Context *)cc;
1100 ASSERT(pContext != NULL); 1098 ASSERT(pContext != NULL);
1101 1099
1102 CPDFDoc_Environment* pApp = pContext->GetReaderApp(); 1100 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
1103 ASSERT(pApp != NULL); 1101 ASSERT(pApp != NULL);
1104 » int nLength = 2048; 1102
1105 » char* pBuff = new char[nLength]; 1103 » const int kMaxInputBytes = 2048;
jun_fang 2014/07/29 18:12:24 It's suggested to use uppercase like MAX_INPUT_BYP
1106 » nLength = pApp->JS_appResponse(swQuestion, swTitle, swDefault, swLabel, bPassWord, pBuff, nLength); 1104 » char* pBuff = new char[kMaxInputBytes + 2];
1107 » if(nLength<=0) 1105 if (!pBuff)
1106 return FALSE;
1107
1108 memset(pBuff, 0, kMaxInputBytes + 2);
1109 » int nLengthBytes = pApp->JS_appResponse(swQuestion, swTitle, swDefault, swLabel, bPassWord, pBuff, kMaxInputBytes);
1110 » if (nLengthBytes <= 0 || nLengthBytes > kMaxInputBytes)
jun_fang 2014/07/29 18:03:36 I saw the comments for the function of app_respons
1108 { 1111 {
1112 vRet.SetNull();
1109 delete[] pBuff; 1113 delete[] pBuff;
1110 vRet.SetNull();
1111 return FALSE; 1114 return FALSE;
1112 } 1115 }
1113 » else 1116
1114 » { 1117 vRet = CFX_WideString::FromUTF16LE((unsigned short*)pBuff, nLengthBytes / 2);
1115 » » nLength = nLength > sizeof(pBuff) ? sizeof(pBuff) : nLength;
1116 vRet = swResponse = CFX_WideString::FromUTF16LE((unsigned short*)pBuff, nLength / 2);
1117 » }
1118 delete[] pBuff; 1118 delete[] pBuff;
1119
1120 return TRUE; 1119 return TRUE;
1121 } 1120 }
1122 1121
1123 FX_BOOL app::media(OBJ_PROP_PARAMS) 1122 FX_BOOL app::media(OBJ_PROP_PARAMS)
1124 { 1123 {
1125 return FALSE; 1124 return FALSE;
1126 } 1125 }
1127 1126
1128 FX_BOOL app::execDialog(OBJ_METHOD_PARAMS) 1127 FX_BOOL app::execDialog(OBJ_METHOD_PARAMS)
1129 { 1128 {
1130 return TRUE; 1129 return TRUE;
1131 } 1130 }
1132 1131
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698