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

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

Issue 498773004: Fix confusion between length in bytes and length in characters in app::response(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Tabify. 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 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 CFX_WideString swDefault = L""; 1038 CFX_WideString swDefault = L"";
1039 bool bPassWord = false; 1039 bool bPassWord = false;
1040 1040
1041 v8::Isolate* isolate = GetIsolate(cc); 1041 v8::Isolate* isolate = GetIsolate(cc);
1042 1042
1043 int iLength = params.size(); 1043 int iLength = params.size();
1044 if (iLength > 0 && params[0].GetType() == VT_object) 1044 if (iLength > 0 && params[0].GetType() == VT_object)
1045 { 1045 {
1046 JSObject pObj = (JSObject )params[0]; 1046 JSObject pObj = (JSObject )params[0];
1047 v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"cQuestion"); 1047 v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"cQuestion");
1048 » » » swQuestion = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pVa lue)).operator CFX_WideString(); 1048 » » swQuestion = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).op erator CFX_WideString();
1049 1049
1050 pValue = JS_GetObjectElement(isolate,pObj,L"cTitle"); 1050 pValue = JS_GetObjectElement(isolate,pObj,L"cTitle");
1051 » » » swTitle = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue )).operator CFX_WideString(); 1051 » » swTitle = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).opera tor CFX_WideString();
1052 1052
1053 pValue = JS_GetObjectElement(isolate,pObj,L"cDefault"); 1053 pValue = JS_GetObjectElement(isolate,pObj,L"cDefault");
1054 » » » swDefault = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pVal ue)).operator CFX_WideString(); 1054 » » swDefault = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ope rator CFX_WideString();
1055 1055
1056 pValue = JS_GetObjectElement(isolate,pObj,L"cLabel"); 1056 pValue = JS_GetObjectElement(isolate,pObj,L"cLabel");
1057 » » » swLabel = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue )).operator CFX_WideString(); 1057 » » swLabel = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).opera tor CFX_WideString();
1058 1058
1059 pValue = JS_GetObjectElement(isolate,pObj,L"bPassword"); 1059 pValue = JS_GetObjectElement(isolate,pObj,L"bPassword");
1060 » » » bPassWord = (bool)CJS_Value(isolate,pValue,GET_VALUE_TYP E(pValue)); 1060 » » bPassWord = (bool)CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue ));
1061 } 1061 }
1062 else 1062 else
1063 { 1063 {
1064 switch(iLength) 1064 switch(iLength)
1065 { 1065 {
1066 case 5:
1067 swLabel = params[4];
1068 // FALLTHROUGH
1069 case 4:
1070 bPassWord = params[3];
1071 // FALLTHROUGH
1072 case 3:
1073 swDefault = params[2];
1074 // FALLTHROUGH
1075 case 2:
1076 swTitle = params[1];
1077 // FALLTHROUGH
1066 case 1: 1078 case 1:
1067 swQuestion = params[0]; 1079 swQuestion = params[0];
1068 » » » break; 1080 » » » // FALLTHROUGH
1069 » » case 2:
1070 » » » swQuestion = params[0];
1071 » » » swTitle = params[1];
1072 » » » break;
1073 » » case 3:
1074 » » » swQuestion = params[0];
1075 » » » swTitle = params[1];
1076 » » » swDefault = params[2];
1077 » » » break;
1078 » » case 4:
1079 » » » swQuestion = params[0];
1080 » » » swTitle = params[1];
1081 » » » swDefault = params[2];
1082 » » » bPassWord = params[3];
1083 » » » break;
1084 » » case 5:
1085 » » » swQuestion = params[0];
1086 » » » swTitle = params[1];
1087 » » » swDefault = params[2];
1088 » » » bPassWord = params[3];
1089 » » » swLabel = params[4];
1090 » » » break;
1091 default: 1081 default:
1092 break; 1082 break;
1093 } 1083 }
1094 } 1084 }
1095 1085
1096 CJS_Context* pContext = (CJS_Context *)cc; 1086 CJS_Context* pContext = (CJS_Context *)cc;
1097 ASSERT(pContext != NULL); 1087 ASSERT(pContext != NULL);
1098 1088
1099 CPDFDoc_Environment* pApp = pContext->GetReaderApp(); 1089 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
1100 ASSERT(pApp != NULL); 1090 ASSERT(pApp != NULL);
1101 1091
1102 const int MAX_INPUT_BYTES = 2048; 1092 const int MAX_INPUT_BYTES = 2048;
1103 char* pBuff = new char[MAX_INPUT_BYTES + 2]; 1093 char* pBuff = new char[MAX_INPUT_BYTES + 2];
1104 if (!pBuff) 1094 if (!pBuff)
1105 return FALSE; 1095 return FALSE;
1106 1096
1107 memset(pBuff, 0, MAX_INPUT_BYTES + 2); 1097 memset(pBuff, 0, MAX_INPUT_BYTES + 2);
1108 int nLengthBytes = pApp->JS_appResponse(swQuestion, swTitle, swDefault, swLabel, bPassWord, pBuff, MAX_INPUT_BYTES); 1098 int nLengthBytes = pApp->JS_appResponse(swQuestion, swTitle, swDefault, swLabel, bPassWord, pBuff, MAX_INPUT_BYTES);
1109 if (nLengthBytes <= 0) 1099 if (nLengthBytes <= 0)
1110 { 1100 {
1111 vRet.SetNull(); 1101 vRet.SetNull();
1112 delete[] pBuff; 1102 delete[] pBuff;
1113 return FALSE; 1103 return FALSE;
1114 } 1104 }
1115 if (nLengthBytes > MAX_INPUT_BYTES) 1105 if (nLengthBytes > MAX_INPUT_BYTES)
1116 nLengthBytes = MAX_INPUT_BYTES; 1106 nLengthBytes = MAX_INPUT_BYTES;
1117 1107
1118 » vRet = CFX_WideString::FromUTF16LE((unsigned short*)pBuff, nLengthBytes) ; 1108 » vRet = CFX_WideString::FromUTF16LE((unsigned short*)pBuff, nLengthBytes / sizeof(unsigned short));
1119 delete[] pBuff; 1109 delete[] pBuff;
1120 return TRUE; 1110 return TRUE;
1121 } 1111 }
1122 1112
1123 FX_BOOL app::media(OBJ_PROP_PARAMS) 1113 FX_BOOL app::media(OBJ_PROP_PARAMS)
1124 { 1114 {
1125 return FALSE; 1115 return FALSE;
1126 } 1116 }
1127 1117
1128 FX_BOOL app::execDialog(OBJ_METHOD_PARAMS) 1118 FX_BOOL app::execDialog(OBJ_METHOD_PARAMS)
1129 { 1119 {
1130 return TRUE; 1120 return TRUE;
1131 } 1121 }
1132 1122
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