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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 ASSERT(pApp != NULL); | 146 ASSERT(pApp != NULL); |
147 | 147 |
148 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 148 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
149 ASSERT(pRuntime != NULL); | 149 ASSERT(pRuntime != NULL); |
150 | 150 |
151 CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument(); | 151 CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument(); |
152 | 152 |
153 CJS_Array aDocs(pRuntime->GetIsolate()); | 153 CJS_Array aDocs(pRuntime->GetIsolate()); |
154 // int iNumDocs = pApp->CountDocuments(); | 154 // int iNumDocs = pApp->CountDocuments(); |
155 | 155 |
156 // » » for(int iIndex = 0; iIndex<iNumDocs; iIndex++) | 156 //» » for(int iIndex = 0; iIndex<iNumDocs; iIndex++) |
157 // » » { | 157 //» » { |
158 CPDFSDK_Document* pDoc = pApp->GetCurrentDoc(); | 158 CPDFSDK_Document* pDoc = pApp->GetCurrentDoc(); |
159 if (pDoc) | 159 if (pDoc) |
160 { | 160 { |
161 CJS_Document * pJSDocument = NULL; | 161 CJS_Document * pJSDocument = NULL; |
162 | 162 |
163 if (pDoc == pCurDoc) | 163 if (pDoc == pCurDoc) |
164 { | 164 { |
165 JSFXObject pObj = JS_GetThisObj(*pRuntim
e); | 165 JSFXObject pObj = JS_GetThisObj(*pRuntim
e); |
166 | 166 |
167 if (JS_GetObjDefnID(pObj) == JS_GetObjDe
fnID(*pRuntime, L"Document")) | 167 if (JS_GetObjDefnID(pObj) == JS_GetObjDe
fnID(*pRuntime, L"Document")) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 CJS_Context* pContext = (CJS_Context*)cc; | 203 CJS_Context* pContext = (CJS_Context*)cc; |
204 ASSERT(pContext != NULL); | 204 ASSERT(pContext != NULL); |
205 | 205 |
206 CPDFDoc_Environment* pApp = pContext->GetReaderApp(); | 206 CPDFDoc_Environment* pApp = pContext->GetReaderApp(); |
207 ASSERT(pApp != NULL); | 207 ASSERT(pApp != NULL); |
208 | 208 |
209 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 209 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
210 ASSERT(pRuntime != NULL); | 210 ASSERT(pRuntime != NULL); |
211 | 211 |
212 CJS_Array aDocs(pRuntime->GetIsolate()); | 212 CJS_Array aDocs(pRuntime->GetIsolate()); |
213 // » » int iNumDocs = pApp->CountDocuments(); | 213 //» » int iNumDocs = pApp->CountDocuments(); |
214 // » » | 214 //» » |
215 // » » for (int iIndex = 0;iIndex < iNumDocs; iIndex++) | 215 //» » for (int iIndex = 0;iIndex < iNumDocs; iIndex++) |
216 // » » { | 216 //» » { |
217 if (CPDFSDK_Document* pDoc = pApp->GetCurrentDoc()) | 217 if (CPDFSDK_Document* pDoc = pApp->GetCurrentDoc()) |
218 { | 218 { |
219 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterFo
rm*)pDoc->GetInterForm(); | 219 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterFo
rm*)pDoc->GetInterForm(); |
220 ASSERT(pInterForm != NULL); | 220 ASSERT(pInterForm != NULL); |
221 pInterForm->EnableCalculate((FX_BOOL)m_bCalculat
e); | 221 pInterForm->EnableCalculate((FX_BOOL)m_bCalculat
e); |
222 } | 222 } |
223 // } | 223 // } |
224 } | 224 } |
225 else | 225 else |
226 { | 226 { |
(...skipping 17 matching lines...) Expand all Loading... |
244 FX_BOOL app::viewerType(OBJ_PROP_PARAMS) | 244 FX_BOOL app::viewerType(OBJ_PROP_PARAMS) |
245 { | 245 { |
246 | 246 |
247 | 247 |
248 | 248 |
249 | 249 |
250 | 250 |
251 | 251 |
252 if (vp.IsGetting()) | 252 if (vp.IsGetting()) |
253 { | 253 { |
254 // » » if (pApp->GetAppName() == PHANTOM) | 254 //» » if (pApp->GetAppName() == PHANTOM) |
255 // » » » vp << JS_STR_VIEWERTYPE_STANDARD; | 255 //» » » vp << JS_STR_VIEWERTYPE_STANDARD; |
256 // » » else | 256 //» » else |
257 // » » » vp << JS_STR_VIEWERTYPE_READER; | 257 //» » » vp << JS_STR_VIEWERTYPE_READER; |
258 vp << L"unknown"; | 258 vp << L"unknown"; |
259 | 259 |
260 //vp << pApp->GetAppTitle(); | 260 //vp << pApp->GetAppTitle(); |
261 return TRUE; | 261 return TRUE; |
262 } | 262 } |
263 | 263 |
264 return FALSE; | 264 return FALSE; |
265 } | 265 } |
266 | 266 |
267 FX_BOOL app::viewerVariation(OBJ_PROP_PARAMS) | 267 FX_BOOL app::viewerVariation(OBJ_PROP_PARAMS) |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 | 360 |
361 if (swMsg == L"") | 361 if (swMsg == L"") |
362 { | 362 { |
363 CJS_Array carray(isolate); | 363 CJS_Array carray(isolate); |
364 if (params[0].ConvertToArray(carray)) | 364 if (params[0].ConvertToArray(carray)) |
365 { | 365 { |
366 int iLenth = carray.GetLength(); | 366 int iLenth = carray.GetLength(); |
367 CJS_Value* pValue = new CJS_Value(isolat
e); | 367 CJS_Value* pValue = new CJS_Value(isolat
e); |
368 // if (iLenth == 1) | 368 // if (iLenth == 1) |
369 // pValue = new CJS_Value(isolate); | 369 // pValue = new CJS_Value(isolate); |
370 // » » » » » else if (iLenth > 1) | 370 //» » » » » else if (iLenth > 1) |
371 // » » » » » » pValue = new CJS_Value[iLenth]; | 371 //» » » » » » pValue = new CJS_Value[iLenth]; |
372 | 372 |
373 for(int i = 0; i < iLenth; i++) | 373 for(int i = 0; i < iLenth; i++) |
374 { | 374 { |
375 carray.GetElement(i, *pValue); | 375 carray.GetElement(i, *pValue); |
376 swMsg += (*pValue).operator CFX_
WideString(); | 376 swMsg += (*pValue).operator CFX_
WideString(); |
377 if (i < iLenth - 1) | 377 if (i < iLenth - 1) |
378 swMsg += L", "; | 378 swMsg += L", "; |
379 } | 379 } |
380 | 380 |
381 if(pValue) delete pValue; | 381 if(pValue) delete pValue; |
382 // » » » » » if ((iLenth > 1) && pValue) | 382 //» » » » » if ((iLenth > 1) && pValue) |
383 // » » » » » { | 383 //» » » » » { |
384 // » » » » » » delete[]pValue; | 384 //» » » » » » delete[]pValue; |
385 // » » » » » » pValue = NULL; | 385 //» » » » » » pValue = NULL; |
386 // » » » » » } | 386 //» » » » » } |
387 // » » » » » else if ((iLenth == 1) && pValue) | 387 //» » » » » else if ((iLenth == 1) && pValue) |
388 // » » » » » { | 388 //» » » » » { |
389 // » » » » » » delete pValue; | 389 //» » » » » » delete pValue; |
390 // » » » » » » pValue = NULL; | 390 //» » » » » » pValue = NULL; |
391 // » » » » » } | 391 //» » » » » } |
392 } | 392 } |
393 } | 393 } |
394 | 394 |
395 if (swTitle == L"") | 395 if (swTitle == L"") |
396 swTitle = JSGetStringFromID((CJS_Context*)cc, ID
S_STRING_JSALERT); | 396 swTitle = JSGetStringFromID((CJS_Context*)cc, ID
S_STRING_JSALERT); |
397 } | 397 } |
398 else if (params[0].GetType() == VT_boolean) | 398 else if (params[0].GetType() == VT_boolean) |
399 { | 399 { |
400 FX_BOOL bGet = (FX_BOOL)params[0]; | 400 FX_BOOL bGet = (FX_BOOL)params[0]; |
401 if (bGet) | 401 if (bGet) |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 | 940 |
941 if (!cFSInit.IsEmpty()) | 941 if (!cFSInit.IsEmpty()) |
942 { | 942 { |
943 JS_PutObjectString(isolate,pRetObj, L"cFS", CFX_WideString::From
Local(cFSInit.GetBuffer(cFSInit.GetLength()))); | 943 JS_PutObjectString(isolate,pRetObj, L"cFS", CFX_WideString::From
Local(cFSInit.GetBuffer(cFSInit.GetLength()))); |
944 } | 944 } |
945 else | 945 else |
946 { | 946 { |
947 JS_PutObjectString(isolate,pRetObj, L"cFS", CFX_WideString::From
Local("DOS")); | 947 JS_PutObjectString(isolate,pRetObj, L"cFS", CFX_WideString::From
Local("DOS")); |
948 } | 948 } |
949 | 949 |
950 » vRet = pRetObj; | 950 » vRet =» pRetObj; |
951 | 951 |
952 return TRUE; | 952 return TRUE; |
953 } | 953 } |
954 | 954 |
955 CFX_WideString app::SysPathToPDFPath(const CFX_WideString& sOldPath) | 955 CFX_WideString app::SysPathToPDFPath(const CFX_WideString& sOldPath) |
956 { | 956 { |
957 CFX_WideString sRet = L"/"; | 957 CFX_WideString sRet = L"/"; |
958 | 958 |
959 for (int i=0,sz=sOldPath.GetLength(); i<sz; i++) | 959 for (int i=0,sz=sOldPath.GetLength(); i<sz; i++) |
960 { | 960 { |
(...skipping 69 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 MAX_INPUT_BYTES = 2048; |
1106 » nLength = pApp->JS_appResponse(swQuestion, swTitle, swDefault, swLabel,
bPassWord, pBuff, nLength); | 1104 » char* pBuff = new char[MAX_INPUT_BYTES + 2]; |
1107 » if(nLength<=0) | 1105 » if (!pBuff) |
| 1106 » » return FALSE; |
| 1107 |
| 1108 » memset(pBuff, 0, MAX_INPUT_BYTES + 2); |
| 1109 » int nLengthBytes = pApp->JS_appResponse(swQuestion, swTitle, swDefault,
swLabel, bPassWord, pBuff, MAX_INPUT_BYTES); |
| 1110 » if (nLengthBytes <= 0) |
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 » if (nLengthBytes > MAX_INPUT_BYTES) |
1114 » { | 1117 » » nLengthBytes = MAX_INPUT_BYTES; |
1115 » » nLength = nLength > sizeof(pBuff) ? sizeof(pBuff) : nLength; | 1118 |
1116 vRet = swResponse = CFX_WideString::FromUTF16LE((unsigned short*)pBuff,
nLength / 2); | 1119 » vRet = CFX_WideString::FromUTF16LE((unsigned short*)pBuff, nLengthBytes)
; |
1117 » } | |
1118 delete[] pBuff; | 1120 delete[] pBuff; |
1119 | |
1120 return TRUE; | 1121 return TRUE; |
1121 } | 1122 } |
1122 | 1123 |
1123 FX_BOOL app::media(OBJ_PROP_PARAMS) | 1124 FX_BOOL app::media(OBJ_PROP_PARAMS) |
1124 { | 1125 { |
1125 return FALSE; | 1126 return FALSE; |
1126 } | 1127 } |
1127 | 1128 |
1128 FX_BOOL app::execDialog(OBJ_METHOD_PARAMS) | 1129 FX_BOOL app::execDialog(OBJ_METHOD_PARAMS) |
1129 { | 1130 { |
1130 return TRUE; | 1131 return TRUE; |
1131 } | 1132 } |
1132 | 1133 |
OLD | NEW |