| 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 "app.h" | 7 #include "app.h" |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 const std::vector<CJS_Value>& params, | 273 const std::vector<CJS_Value>& params, |
| 274 CJS_Value& vRet, | 274 CJS_Value& vRet, |
| 275 CFX_WideString& sError) { | 275 CFX_WideString& sError) { |
| 276 return TRUE; | 276 return TRUE; |
| 277 } | 277 } |
| 278 | 278 |
| 279 FX_BOOL app::alert(IJS_Context* cc, | 279 FX_BOOL app::alert(IJS_Context* cc, |
| 280 const std::vector<CJS_Value>& params, | 280 const std::vector<CJS_Value>& params, |
| 281 CJS_Value& vRet, | 281 CJS_Value& vRet, |
| 282 CFX_WideString& sError) { | 282 CFX_WideString& sError) { |
| 283 int iSize = params.size(); | 283 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 284 if (iSize < 1) | 284 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 285 std::vector<CJS_Value> newParams = JS_ExpandKeywordParams( |
| 286 pRuntime, params, 4, L"cMsg", L"nIcon", L"nType", L"cTitle"); |
| 287 |
| 288 if (newParams[0].GetType() == CJS_Value::VT_unknown) { |
| 289 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 285 return FALSE; | 290 return FALSE; |
| 291 } |
| 286 | 292 |
| 287 CFX_WideString swMsg = L""; | 293 CFX_WideString swMsg; |
| 288 CFX_WideString swTitle = L""; | 294 if (newParams[0].GetType() == CJS_Value::VT_object) { |
| 289 int iIcon = 0; | 295 CJS_Array carray(pRuntime); |
| 290 int iType = 0; | 296 if (newParams[0].ConvertToArray(carray)) { |
| 291 | 297 swMsg = L"["; |
| 292 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 298 CJS_Value element(pRuntime); |
| 293 v8::Isolate* isolate = pRuntime->GetIsolate(); | 299 for (int i = 0; i < carray.GetLength(); ++i) { |
| 294 | 300 if (i) |
| 295 if (iSize == 1) { | 301 swMsg += L", "; |
| 296 if (params[0].GetType() == CJS_Value::VT_object) { | 302 carray.GetElement(i, element); |
| 297 v8::Local<v8::Object> pObj = params[0].ToV8Object(); | 303 swMsg += element.ToCFXWideString(); |
| 298 { | |
| 299 v8::Local<v8::Value> pValue = | |
| 300 FXJS_GetObjectElement(isolate, pObj, L"cMsg"); | |
| 301 swMsg = CJS_Value(pRuntime, pValue, CJS_Value::VT_unknown) | |
| 302 .ToCFXWideString(); | |
| 303 | |
| 304 pValue = FXJS_GetObjectElement(isolate, pObj, L"cTitle"); | |
| 305 swTitle = CJS_Value(pRuntime, pValue, CJS_Value::VT_unknown) | |
| 306 .ToCFXWideString(); | |
| 307 | |
| 308 pValue = FXJS_GetObjectElement(isolate, pObj, L"nIcon"); | |
| 309 iIcon = CJS_Value(pRuntime, pValue, CJS_Value::VT_unknown).ToInt(); | |
| 310 | |
| 311 pValue = FXJS_GetObjectElement(isolate, pObj, L"nType"); | |
| 312 iType = CJS_Value(pRuntime, pValue, CJS_Value::VT_unknown).ToInt(); | |
| 313 } | 304 } |
| 314 | 305 swMsg += L"]"; |
| 315 if (swMsg == L"") { | |
| 316 CJS_Array carray(pRuntime); | |
| 317 if (params[0].ConvertToArray(carray)) { | |
| 318 int iLength = carray.GetLength(); | |
| 319 CJS_Value* pValue = new CJS_Value(pRuntime); | |
| 320 for (int i = 0; i < iLength; ++i) { | |
| 321 carray.GetElement(i, *pValue); | |
| 322 swMsg += (*pValue).ToCFXWideString(); | |
| 323 if (i < iLength - 1) | |
| 324 swMsg += L", "; | |
| 325 } | |
| 326 | |
| 327 delete pValue; | |
| 328 } | |
| 329 } | |
| 330 | |
| 331 if (swTitle == L"") | |
| 332 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT); | |
| 333 } else if (params[0].GetType() == CJS_Value::VT_boolean) { | |
| 334 FX_BOOL bGet = params[0].ToBool(); | |
| 335 if (bGet) | |
| 336 swMsg = L"true"; | |
| 337 else | |
| 338 swMsg = L"false"; | |
| 339 | |
| 340 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT); | |
| 341 } else { | 306 } else { |
| 342 swMsg = params[0].ToCFXWideString(); | 307 swMsg = newParams[0].ToCFXWideString(); |
| 343 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT); | |
| 344 } | 308 } |
| 345 } else { | 309 } else { |
| 346 if (params[0].GetType() == CJS_Value::VT_boolean) { | 310 swMsg = newParams[0].ToCFXWideString(); |
| 347 FX_BOOL bGet = params[0].ToBool(); | 311 } |
| 348 if (bGet) | |
| 349 swMsg = L"true"; | |
| 350 else | |
| 351 swMsg = L"false"; | |
| 352 } else { | |
| 353 swMsg = params[0].ToCFXWideString(); | |
| 354 } | |
| 355 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT); | |
| 356 | 312 |
| 357 for (int i = 1; i < iSize; i++) { | 313 int iIcon = 0; |
| 358 if (i == 1) | 314 if (newParams[1].GetType() != CJS_Value::VT_unknown) |
| 359 iIcon = params[i].ToInt(); | 315 iIcon = newParams[1].ToInt(); |
| 360 if (i == 2) | 316 |
| 361 iType = params[i].ToInt(); | 317 int iType = 0; |
| 362 if (i == 3) | 318 if (newParams[2].GetType() != CJS_Value::VT_unknown) |
| 363 swTitle = params[i].ToCFXWideString(); | 319 iType = newParams[2].ToInt(); |
| 364 } | 320 |
| 365 } | 321 CFX_WideString swTitle; |
| 322 if (newParams[3].GetType() != CJS_Value::VT_unknown) |
| 323 swTitle = newParams[3].ToCFXWideString(); |
| 324 else |
| 325 swTitle = JSGetStringFromID(pContext, IDS_STRING_JSALERT); |
| 366 | 326 |
| 367 pRuntime->BeginBlock(); | 327 pRuntime->BeginBlock(); |
| 368 vRet = MsgBox(pRuntime->GetReaderApp(), swMsg.c_str(), swTitle.c_str(), iType, | 328 vRet = MsgBox(pRuntime->GetReaderApp(), swMsg.c_str(), swTitle.c_str(), iType, |
| 369 iIcon); | 329 iIcon); |
| 370 pRuntime->EndBlock(); | 330 pRuntime->EndBlock(); |
| 371 return TRUE; | 331 return TRUE; |
| 372 } | 332 } |
| 373 | 333 |
| 374 FX_BOOL app::beep(IJS_Context* cc, | 334 FX_BOOL app::beep(IJS_Context* cc, |
| 375 const std::vector<CJS_Value>& params, | 335 const std::vector<CJS_Value>& params, |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 FX_BOOL app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { | 784 FX_BOOL app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { |
| 825 return FALSE; | 785 return FALSE; |
| 826 } | 786 } |
| 827 | 787 |
| 828 FX_BOOL app::execDialog(IJS_Context* cc, | 788 FX_BOOL app::execDialog(IJS_Context* cc, |
| 829 const std::vector<CJS_Value>& params, | 789 const std::vector<CJS_Value>& params, |
| 830 CJS_Value& vRet, | 790 CJS_Value& vRet, |
| 831 CFX_WideString& sError) { | 791 CFX_WideString& sError) { |
| 832 return TRUE; | 792 return TRUE; |
| 833 } | 793 } |
| OLD | NEW |