Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 int nLength = 2048; |
| 1105 char* pBuff = new char[nLength]; | 1103 char* pBuff = new char[nLength]; |
|
jun_fang
2014/07/29 04:11:30
nLength is the length of content. Doesn't include
Tom Sepez
2014/07/29 16:55:57
Yeah, I'm having a hard time reconciling this with
jun_fang
2014/07/29 17:31:47
In theory, there is no difference between 2046 plu
| |
| 1106 nLength = pApp->JS_appResponse(swQuestion, swTitle, swDefault, swLabel, bPassWord, pBuff, nLength); | 1104 nLength = pApp->JS_appResponse(swQuestion, swTitle, swDefault, swLabel, bPassWord, pBuff, nLength); |
| 1107 » if(nLength<=0) | 1105 » if (nLength <= 0 || nLength > sizeof(pBuff)) |
|
jun_fang
2014/07/29 04:11:30
Sizeof(pBuff) is 4 which represents bytes of a poi
Tom Sepez
2014/07/29 16:55:57
Good catch. Looks like this has been wrong for ye
jun_fang
2014/07/29 17:31:47
Strlen depends upon the last char '\0'. That's why
| |
| 1108 { | 1106 { |
| 1107 vRet.SetNull(); | |
| 1109 delete[] pBuff; | 1108 delete[] pBuff; |
| 1110 vRet.SetNull(); | |
| 1111 return FALSE; | 1109 return FALSE; |
| 1112 } | 1110 } |
| 1113 » else | 1111 |
| 1114 » { | 1112 vRet = CFX_WideString::FromUTF16LE((unsigned short*)pBuff, nLength / 2); |
| 1115 » » nLength = nLength > sizeof(pBuff) ? sizeof(pBuff) : nLength; | |
| 1116 vRet = swResponse = CFX_WideString::FromUTF16LE((unsigned short*)pBuff, nLength / 2); | |
| 1117 » } | |
| 1118 delete[] pBuff; | 1113 delete[] pBuff; |
| 1119 | |
| 1120 return TRUE; | 1114 return TRUE; |
| 1121 } | 1115 } |
| 1122 | 1116 |
| 1123 FX_BOOL app::media(OBJ_PROP_PARAMS) | 1117 FX_BOOL app::media(OBJ_PROP_PARAMS) |
| 1124 { | 1118 { |
| 1125 return FALSE; | 1119 return FALSE; |
| 1126 } | 1120 } |
| 1127 | 1121 |
| 1128 FX_BOOL app::execDialog(OBJ_METHOD_PARAMS) | 1122 FX_BOOL app::execDialog(OBJ_METHOD_PARAMS) |
| 1129 { | 1123 { |
| 1130 return TRUE; | 1124 return TRUE; |
| 1131 } | 1125 } |
| 1132 | 1126 |
| OLD | NEW |