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 "fpdfsdk/javascript/app.h" | 7 #include "fpdfsdk/javascript/app.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <vector> | 10 #include <vector> |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 pJSDocument = | 245 pJSDocument = |
246 (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj); | 246 (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj); |
247 ASSERT(pJSDocument); | 247 ASSERT(pJSDocument); |
248 } | 248 } |
249 aDocs.SetElement(pRuntime->GetIsolate(), 0, | 249 aDocs.SetElement(pRuntime->GetIsolate(), 0, |
250 CJS_Value(pRuntime, pJSDocument)); | 250 CJS_Value(pRuntime, pJSDocument)); |
251 } | 251 } |
252 if (aDocs.GetLength() > 0) | 252 if (aDocs.GetLength() > 0) |
253 vp << aDocs; | 253 vp << aDocs; |
254 else | 254 else |
255 vp.SetNull(); | 255 vp.GetJSValue()->SetNull(pRuntime); |
256 | 256 |
257 return TRUE; | 257 return TRUE; |
258 } | 258 } |
259 | 259 |
260 FX_BOOL app::calculate(IJS_Context* cc, | 260 FX_BOOL app::calculate(IJS_Context* cc, |
261 CJS_PropValue& vp, | 261 CJS_PropValue& vp, |
262 CFX_WideString& sError) { | 262 CFX_WideString& sError) { |
263 if (vp.IsSetting()) { | 263 if (vp.IsSetting()) { |
264 bool bVP; | 264 bool bVP; |
265 vp >> bVP; | 265 vp >> bVP; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 std::vector<CJS_Value> newParams = JS_ExpandKeywordParams( | 398 std::vector<CJS_Value> newParams = JS_ExpandKeywordParams( |
399 pRuntime, params, 4, L"cMsg", L"nIcon", L"nType", L"cTitle"); | 399 pRuntime, params, 4, L"cMsg", L"nIcon", L"nType", L"cTitle"); |
400 | 400 |
401 if (newParams[0].GetType() == CJS_Value::VT_unknown) { | 401 if (newParams[0].GetType() == CJS_Value::VT_unknown) { |
402 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 402 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
403 return FALSE; | 403 return FALSE; |
404 } | 404 } |
405 | 405 |
406 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); | 406 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); |
407 if (!pApp) { | 407 if (!pApp) { |
408 vRet = 0; | 408 vRet = CJS_Value(pRuntime, 0); |
409 return TRUE; | 409 return TRUE; |
410 } | 410 } |
411 | 411 |
412 CFX_WideString swMsg; | 412 CFX_WideString swMsg; |
413 if (newParams[0].GetType() == CJS_Value::VT_object) { | 413 if (newParams[0].GetType() == CJS_Value::VT_object) { |
414 CJS_Array carray; | 414 CJS_Array carray; |
415 if (newParams[0].ConvertToArray(carray)) { | 415 if (newParams[0].ConvertToArray(pRuntime->GetIsolate(), carray)) { |
416 swMsg = L"["; | 416 swMsg = L"["; |
417 CJS_Value element(pRuntime); | 417 CJS_Value element(pRuntime); |
418 for (int i = 0; i < carray.GetLength(); ++i) { | 418 for (int i = 0; i < carray.GetLength(); ++i) { |
419 if (i) | 419 if (i) |
420 swMsg += L", "; | 420 swMsg += L", "; |
421 carray.GetElement(pRuntime->GetIsolate(), i, element); | 421 carray.GetElement(pRuntime->GetIsolate(), i, element); |
422 swMsg += element.ToCFXWideString(); | 422 swMsg += element.ToCFXWideString(pRuntime->GetIsolate()); |
423 } | 423 } |
424 swMsg += L"]"; | 424 swMsg += L"]"; |
425 } else { | 425 } else { |
426 swMsg = newParams[0].ToCFXWideString(); | 426 swMsg = newParams[0].ToCFXWideString(pRuntime->GetIsolate()); |
427 } | 427 } |
428 } else { | 428 } else { |
429 swMsg = newParams[0].ToCFXWideString(); | 429 swMsg = newParams[0].ToCFXWideString(pRuntime->GetIsolate()); |
430 } | 430 } |
431 | 431 |
432 int iIcon = 0; | 432 int iIcon = 0; |
433 if (newParams[1].GetType() != CJS_Value::VT_unknown) | 433 if (newParams[1].GetType() != CJS_Value::VT_unknown) |
434 iIcon = newParams[1].ToInt(); | 434 iIcon = newParams[1].ToInt(pRuntime->GetIsolate()); |
435 | 435 |
436 int iType = 0; | 436 int iType = 0; |
437 if (newParams[2].GetType() != CJS_Value::VT_unknown) | 437 if (newParams[2].GetType() != CJS_Value::VT_unknown) |
438 iType = newParams[2].ToInt(); | 438 iType = newParams[2].ToInt(pRuntime->GetIsolate()); |
439 | 439 |
440 CFX_WideString swTitle; | 440 CFX_WideString swTitle; |
441 if (newParams[3].GetType() != CJS_Value::VT_unknown) | 441 if (newParams[3].GetType() != CJS_Value::VT_unknown) |
442 swTitle = newParams[3].ToCFXWideString(); | 442 swTitle = newParams[3].ToCFXWideString(pRuntime->GetIsolate()); |
443 else | 443 else |
444 swTitle = JSGetStringFromID(pContext, IDS_STRING_JSALERT); | 444 swTitle = JSGetStringFromID(pContext, IDS_STRING_JSALERT); |
445 | 445 |
446 pRuntime->BeginBlock(); | 446 pRuntime->BeginBlock(); |
447 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) | 447 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) |
448 pDoc->KillFocusAnnot(); | 448 pDoc->KillFocusAnnot(); |
449 | 449 |
450 vRet = pApp->JS_appAlert(swMsg.c_str(), swTitle.c_str(), iType, iIcon); | 450 vRet = CJS_Value(pRuntime, pApp->JS_appAlert(swMsg.c_str(), swTitle.c_str(), |
| 451 iType, iIcon)); |
451 pRuntime->EndBlock(); | 452 pRuntime->EndBlock(); |
452 return TRUE; | 453 return TRUE; |
453 } | 454 } |
454 | 455 |
455 FX_BOOL app::beep(IJS_Context* cc, | 456 FX_BOOL app::beep(IJS_Context* cc, |
456 const std::vector<CJS_Value>& params, | 457 const std::vector<CJS_Value>& params, |
457 CJS_Value& vRet, | 458 CJS_Value& vRet, |
458 CFX_WideString& sError) { | 459 CFX_WideString& sError) { |
459 if (params.size() == 1) { | 460 if (params.size() == 1) { |
460 CJS_Context* pContext = (CJS_Context*)cc; | 461 CJS_Context* pContext = (CJS_Context*)cc; |
461 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 462 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
462 CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp(); | 463 CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp(); |
463 pEnv->JS_appBeep(params[0].ToInt()); | 464 pEnv->JS_appBeep(params[0].ToInt(pRuntime->GetIsolate())); |
464 return TRUE; | 465 return TRUE; |
465 } | 466 } |
466 | 467 |
467 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR); | 468 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR); |
468 return FALSE; | 469 return FALSE; |
469 } | 470 } |
470 | 471 |
471 FX_BOOL app::findComponent(IJS_Context* cc, | 472 FX_BOOL app::findComponent(IJS_Context* cc, |
472 const std::vector<CJS_Value>& params, | 473 const std::vector<CJS_Value>& params, |
473 CJS_Value& vRet, | 474 CJS_Value& vRet, |
(...skipping 10 matching lines...) Expand all Loading... |
484 | 485 |
485 FX_BOOL app::fs(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { | 486 FX_BOOL app::fs(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { |
486 return FALSE; | 487 return FALSE; |
487 } | 488 } |
488 | 489 |
489 FX_BOOL app::setInterval(IJS_Context* cc, | 490 FX_BOOL app::setInterval(IJS_Context* cc, |
490 const std::vector<CJS_Value>& params, | 491 const std::vector<CJS_Value>& params, |
491 CJS_Value& vRet, | 492 CJS_Value& vRet, |
492 CFX_WideString& sError) { | 493 CFX_WideString& sError) { |
493 CJS_Context* pContext = (CJS_Context*)cc; | 494 CJS_Context* pContext = (CJS_Context*)cc; |
| 495 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 496 |
494 if (params.size() > 2 || params.size() == 0) { | 497 if (params.size() > 2 || params.size() == 0) { |
495 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 498 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
496 return FALSE; | 499 return FALSE; |
497 } | 500 } |
498 | 501 |
499 CFX_WideString script = params.size() > 0 ? params[0].ToCFXWideString() : L""; | 502 CFX_WideString script = |
| 503 params.size() > 0 ? params[0].ToCFXWideString(pRuntime->GetIsolate()) |
| 504 : L""; |
500 if (script.IsEmpty()) { | 505 if (script.IsEmpty()) { |
501 sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE); | 506 sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE); |
502 return TRUE; | 507 return TRUE; |
503 } | 508 } |
504 | 509 |
505 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 510 uint32_t dwInterval = |
506 uint32_t dwInterval = params.size() > 1 ? params[1].ToInt() : 1000; | 511 params.size() > 1 ? params[1].ToInt(pRuntime->GetIsolate()) : 1000; |
507 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); | 512 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); |
508 m_Timers.push_back(std::unique_ptr<GlobalTimer>( | 513 m_Timers.push_back(std::unique_ptr<GlobalTimer>( |
509 new GlobalTimer(this, pApp, pRuntime, 0, script, dwInterval, 0))); | 514 new GlobalTimer(this, pApp, pRuntime, 0, script, dwInterval, 0))); |
510 | 515 |
511 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj( | 516 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj( |
512 pRuntime->GetIsolate(), pRuntime, CJS_TimerObj::g_nObjDefnID); | 517 pRuntime->GetIsolate(), pRuntime, CJS_TimerObj::g_nObjDefnID); |
513 CJS_TimerObj* pJS_TimerObj = static_cast<CJS_TimerObj*>( | 518 CJS_TimerObj* pJS_TimerObj = static_cast<CJS_TimerObj*>( |
514 FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj)); | 519 FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj)); |
515 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject()); | 520 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject()); |
516 pTimerObj->SetTimer(m_Timers.back().get()); | 521 pTimerObj->SetTimer(m_Timers.back().get()); |
517 | 522 |
518 vRet = pRetObj; | 523 vRet = CJS_Value(pRuntime, pRetObj); |
519 return TRUE; | 524 return TRUE; |
520 } | 525 } |
521 | 526 |
522 FX_BOOL app::setTimeOut(IJS_Context* cc, | 527 FX_BOOL app::setTimeOut(IJS_Context* cc, |
523 const std::vector<CJS_Value>& params, | 528 const std::vector<CJS_Value>& params, |
524 CJS_Value& vRet, | 529 CJS_Value& vRet, |
525 CFX_WideString& sError) { | 530 CFX_WideString& sError) { |
526 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 531 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 532 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 533 |
527 if (params.size() > 2 || params.size() == 0) { | 534 if (params.size() > 2 || params.size() == 0) { |
528 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 535 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
529 return FALSE; | 536 return FALSE; |
530 } | 537 } |
531 | 538 |
532 CFX_WideString script = params[0].ToCFXWideString(); | 539 CFX_WideString script = params[0].ToCFXWideString(pRuntime->GetIsolate()); |
533 if (script.IsEmpty()) { | 540 if (script.IsEmpty()) { |
534 sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE); | 541 sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE); |
535 return TRUE; | 542 return TRUE; |
536 } | 543 } |
537 | 544 |
538 uint32_t dwTimeOut = params.size() > 1 ? params[1].ToInt() : 1000; | 545 uint32_t dwTimeOut = |
539 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 546 params.size() > 1 ? params[1].ToInt(pRuntime->GetIsolate()) : 1000; |
540 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); | 547 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); |
541 m_Timers.push_back(std::unique_ptr<GlobalTimer>( | 548 m_Timers.push_back(std::unique_ptr<GlobalTimer>( |
542 new GlobalTimer(this, pApp, pRuntime, 1, script, dwTimeOut, dwTimeOut))); | 549 new GlobalTimer(this, pApp, pRuntime, 1, script, dwTimeOut, dwTimeOut))); |
543 | 550 |
544 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj( | 551 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj( |
545 pRuntime->GetIsolate(), pRuntime, CJS_TimerObj::g_nObjDefnID); | 552 pRuntime->GetIsolate(), pRuntime, CJS_TimerObj::g_nObjDefnID); |
546 | 553 |
547 CJS_TimerObj* pJS_TimerObj = static_cast<CJS_TimerObj*>( | 554 CJS_TimerObj* pJS_TimerObj = static_cast<CJS_TimerObj*>( |
548 FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj)); | 555 FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj)); |
549 | 556 |
550 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject()); | 557 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject()); |
551 pTimerObj->SetTimer(m_Timers.back().get()); | 558 pTimerObj->SetTimer(m_Timers.back().get()); |
552 | 559 |
553 vRet = pRetObj; | 560 vRet = CJS_Value(pRuntime, pRetObj); |
554 return TRUE; | 561 return TRUE; |
555 } | 562 } |
556 | 563 |
557 FX_BOOL app::clearTimeOut(IJS_Context* cc, | 564 FX_BOOL app::clearTimeOut(IJS_Context* cc, |
558 const std::vector<CJS_Value>& params, | 565 const std::vector<CJS_Value>& params, |
559 CJS_Value& vRet, | 566 CJS_Value& vRet, |
560 CFX_WideString& sError) { | 567 CFX_WideString& sError) { |
561 CJS_Context* pContext = (CJS_Context*)cc; | 568 CJS_Context* pContext = (CJS_Context*)cc; |
562 if (params.size() != 1) { | 569 if (params.size() != 1) { |
563 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 570 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
(...skipping 15 matching lines...) Expand all Loading... |
579 } | 586 } |
580 | 587 |
581 app::ClearTimerCommon(params[0]); | 588 app::ClearTimerCommon(params[0]); |
582 return TRUE; | 589 return TRUE; |
583 } | 590 } |
584 | 591 |
585 void app::ClearTimerCommon(const CJS_Value& param) { | 592 void app::ClearTimerCommon(const CJS_Value& param) { |
586 if (param.GetType() != CJS_Value::VT_object) | 593 if (param.GetType() != CJS_Value::VT_object) |
587 return; | 594 return; |
588 | 595 |
589 v8::Local<v8::Object> pObj = param.ToV8Object(); | 596 v8::Local<v8::Object> pObj = param.ToV8Object(GetJSObject()->GetIsolate()); |
590 if (FXJS_GetObjDefnID(pObj) != CJS_TimerObj::g_nObjDefnID) | 597 if (FXJS_GetObjDefnID(pObj) != CJS_TimerObj::g_nObjDefnID) |
591 return; | 598 return; |
592 | 599 |
593 CJS_Object* pJSObj = param.ToCJSObject(); | 600 CJS_Object* pJSObj = param.ToCJSObject(GetJSObject()->GetIsolate()); |
594 if (!pJSObj) | 601 if (!pJSObj) |
595 return; | 602 return; |
596 | 603 |
597 TimerObj* pTimerObj = static_cast<TimerObj*>(pJSObj->GetEmbedObject()); | 604 TimerObj* pTimerObj = static_cast<TimerObj*>(pJSObj->GetEmbedObject()); |
598 if (!pTimerObj) | 605 if (!pTimerObj) |
599 return; | 606 return; |
600 | 607 |
601 GlobalTimer::Cancel(pTimerObj->GetTimerID()); | 608 GlobalTimer::Cancel(pTimerObj->GetTimerID()); |
602 } | 609 } |
603 | 610 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 664 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
658 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 665 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
659 std::vector<CJS_Value> newParams = | 666 std::vector<CJS_Value> newParams = |
660 JS_ExpandKeywordParams(pRuntime, params, 6, L"bUI", L"cTo", L"cCc", | 667 JS_ExpandKeywordParams(pRuntime, params, 6, L"bUI", L"cTo", L"cCc", |
661 L"cBcc", L"cSubject", L"cMsg"); | 668 L"cBcc", L"cSubject", L"cMsg"); |
662 | 669 |
663 if (newParams[0].GetType() == CJS_Value::VT_unknown) { | 670 if (newParams[0].GetType() == CJS_Value::VT_unknown) { |
664 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 671 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
665 return FALSE; | 672 return FALSE; |
666 } | 673 } |
667 bool bUI = newParams[0].ToBool(); | 674 bool bUI = newParams[0].ToBool(pRuntime->GetIsolate()); |
668 | 675 |
669 CFX_WideString cTo; | 676 CFX_WideString cTo; |
670 if (newParams[1].GetType() != CJS_Value::VT_unknown) { | 677 if (newParams[1].GetType() != CJS_Value::VT_unknown) { |
671 cTo = newParams[1].ToCFXWideString(); | 678 cTo = newParams[1].ToCFXWideString(pRuntime->GetIsolate()); |
672 } else { | 679 } else { |
673 if (!bUI) { | 680 if (!bUI) { |
674 // cTo parameter required when UI not invoked. | 681 // cTo parameter required when UI not invoked. |
675 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 682 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
676 return FALSE; | 683 return FALSE; |
677 } | 684 } |
678 } | 685 } |
679 | 686 |
680 CFX_WideString cCc; | 687 CFX_WideString cCc; |
681 if (newParams[2].GetType() != CJS_Value::VT_unknown) | 688 if (newParams[2].GetType() != CJS_Value::VT_unknown) |
682 cCc = newParams[2].ToCFXWideString(); | 689 cCc = newParams[2].ToCFXWideString(pRuntime->GetIsolate()); |
683 | 690 |
684 CFX_WideString cBcc; | 691 CFX_WideString cBcc; |
685 if (newParams[3].GetType() != CJS_Value::VT_unknown) | 692 if (newParams[3].GetType() != CJS_Value::VT_unknown) |
686 cBcc = newParams[3].ToCFXWideString(); | 693 cBcc = newParams[3].ToCFXWideString(pRuntime->GetIsolate()); |
687 | 694 |
688 CFX_WideString cSubject; | 695 CFX_WideString cSubject; |
689 if (newParams[4].GetType() != CJS_Value::VT_unknown) | 696 if (newParams[4].GetType() != CJS_Value::VT_unknown) |
690 cSubject = newParams[4].ToCFXWideString(); | 697 cSubject = newParams[4].ToCFXWideString(pRuntime->GetIsolate()); |
691 | 698 |
692 CFX_WideString cMsg; | 699 CFX_WideString cMsg; |
693 if (newParams[5].GetType() != CJS_Value::VT_unknown) | 700 if (newParams[5].GetType() != CJS_Value::VT_unknown) |
694 cMsg = newParams[5].ToCFXWideString(); | 701 cMsg = newParams[5].ToCFXWideString(pRuntime->GetIsolate()); |
695 | 702 |
696 pRuntime->BeginBlock(); | 703 pRuntime->BeginBlock(); |
697 pContext->GetReaderApp()->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(), | 704 pContext->GetReaderApp()->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(), |
698 cSubject.c_str(), cCc.c_str(), | 705 cSubject.c_str(), cCc.c_str(), |
699 cBcc.c_str(), cMsg.c_str()); | 706 cBcc.c_str(), cMsg.c_str()); |
700 pRuntime->EndBlock(); | 707 pRuntime->EndBlock(); |
701 return TRUE; | 708 return TRUE; |
702 } | 709 } |
703 | 710 |
704 FX_BOOL app::launchURL(IJS_Context* cc, | 711 FX_BOOL app::launchURL(IJS_Context* cc, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 787 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
781 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 788 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
782 std::vector<CJS_Value> newParams = | 789 std::vector<CJS_Value> newParams = |
783 JS_ExpandKeywordParams(pRuntime, params, 5, L"cQuestion", L"cTitle", | 790 JS_ExpandKeywordParams(pRuntime, params, 5, L"cQuestion", L"cTitle", |
784 L"cDefault", L"bPassword", L"cLabel"); | 791 L"cDefault", L"bPassword", L"cLabel"); |
785 | 792 |
786 if (newParams[0].GetType() == CJS_Value::VT_unknown) { | 793 if (newParams[0].GetType() == CJS_Value::VT_unknown) { |
787 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 794 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
788 return FALSE; | 795 return FALSE; |
789 } | 796 } |
790 CFX_WideString swQuestion = newParams[0].ToCFXWideString(); | 797 CFX_WideString swQuestion = |
| 798 newParams[0].ToCFXWideString(pRuntime->GetIsolate()); |
791 | 799 |
792 CFX_WideString swTitle = L"PDF"; | 800 CFX_WideString swTitle = L"PDF"; |
793 if (newParams[1].GetType() != CJS_Value::VT_unknown) | 801 if (newParams[1].GetType() != CJS_Value::VT_unknown) |
794 swTitle = newParams[1].ToCFXWideString(); | 802 swTitle = newParams[1].ToCFXWideString(pRuntime->GetIsolate()); |
795 | 803 |
796 CFX_WideString swDefault; | 804 CFX_WideString swDefault; |
797 if (newParams[2].GetType() != CJS_Value::VT_unknown) | 805 if (newParams[2].GetType() != CJS_Value::VT_unknown) |
798 swDefault = newParams[2].ToCFXWideString(); | 806 swDefault = newParams[2].ToCFXWideString(pRuntime->GetIsolate()); |
799 | 807 |
800 bool bPassword = false; | 808 bool bPassword = false; |
801 if (newParams[3].GetType() != CJS_Value::VT_unknown) | 809 if (newParams[3].GetType() != CJS_Value::VT_unknown) |
802 bPassword = newParams[3].ToBool(); | 810 bPassword = newParams[3].ToBool(pRuntime->GetIsolate()); |
803 | 811 |
804 CFX_WideString swLabel; | 812 CFX_WideString swLabel; |
805 if (newParams[4].GetType() != CJS_Value::VT_unknown) | 813 if (newParams[4].GetType() != CJS_Value::VT_unknown) |
806 swLabel = newParams[4].ToCFXWideString(); | 814 swLabel = newParams[4].ToCFXWideString(pRuntime->GetIsolate()); |
807 | 815 |
808 const int MAX_INPUT_BYTES = 2048; | 816 const int MAX_INPUT_BYTES = 2048; |
809 std::unique_ptr<char[]> pBuff(new char[MAX_INPUT_BYTES + 2]); | 817 std::unique_ptr<char[]> pBuff(new char[MAX_INPUT_BYTES + 2]); |
810 memset(pBuff.get(), 0, MAX_INPUT_BYTES + 2); | 818 memset(pBuff.get(), 0, MAX_INPUT_BYTES + 2); |
811 | 819 |
812 int nLengthBytes = pContext->GetReaderApp()->JS_appResponse( | 820 int nLengthBytes = pContext->GetReaderApp()->JS_appResponse( |
813 swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(), | 821 swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(), |
814 bPassword, pBuff.get(), MAX_INPUT_BYTES); | 822 bPassword, pBuff.get(), MAX_INPUT_BYTES); |
815 | 823 |
816 if (nLengthBytes < 0 || nLengthBytes > MAX_INPUT_BYTES) { | 824 if (nLengthBytes < 0 || nLengthBytes > MAX_INPUT_BYTES) { |
817 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG); | 825 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG); |
818 return FALSE; | 826 return FALSE; |
819 } | 827 } |
820 | 828 |
821 vRet = CFX_WideString::FromUTF16LE(reinterpret_cast<uint16_t*>(pBuff.get()), | 829 vRet = CJS_Value(pRuntime, CFX_WideString::FromUTF16LE( |
822 nLengthBytes / sizeof(uint16_t)) | 830 reinterpret_cast<uint16_t*>(pBuff.get()), |
823 .c_str(); | 831 nLengthBytes / sizeof(uint16_t)) |
| 832 .c_str()); |
| 833 |
824 return TRUE; | 834 return TRUE; |
825 } | 835 } |
826 | 836 |
827 FX_BOOL app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { | 837 FX_BOOL app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { |
828 return FALSE; | 838 return FALSE; |
829 } | 839 } |
830 | 840 |
831 FX_BOOL app::execDialog(IJS_Context* cc, | 841 FX_BOOL app::execDialog(IJS_Context* cc, |
832 const std::vector<CJS_Value>& params, | 842 const std::vector<CJS_Value>& params, |
833 CJS_Value& vRet, | 843 CJS_Value& vRet, |
834 CFX_WideString& sError) { | 844 CFX_WideString& sError) { |
835 return TRUE; | 845 return TRUE; |
836 } | 846 } |
OLD | NEW |