| 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 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 const std::vector<CJS_Value>& params, | 375 const std::vector<CJS_Value>& params, |
| 376 CJS_Value& vRet, | 376 CJS_Value& vRet, |
| 377 CFX_WideString& sError) { | 377 CFX_WideString& sError) { |
| 378 return TRUE; | 378 return TRUE; |
| 379 } | 379 } |
| 380 | 380 |
| 381 FX_BOOL app::alert(IJS_Context* cc, | 381 FX_BOOL app::alert(IJS_Context* cc, |
| 382 const std::vector<CJS_Value>& params, | 382 const std::vector<CJS_Value>& params, |
| 383 CJS_Value& vRet, | 383 CJS_Value& vRet, |
| 384 CFX_WideString& sError) { | 384 CFX_WideString& sError) { |
| 385 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | |
| 386 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 385 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 387 std::vector<CJS_Value> newParams = JS_ExpandKeywordParams( | 386 std::vector<CJS_Value> newParams = JS_ExpandKeywordParams( |
| 388 pRuntime, params, 4, L"cMsg", L"nIcon", L"nType", L"cTitle"); | 387 pRuntime, params, 4, L"cMsg", L"nIcon", L"nType", L"cTitle"); |
| 389 | 388 |
| 390 if (newParams[0].GetType() == CJS_Value::VT_unknown) { | 389 if (newParams[0].GetType() == CJS_Value::VT_unknown) { |
| 391 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 390 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 392 return FALSE; | 391 return FALSE; |
| 393 } | 392 } |
| 394 | 393 |
| 395 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); | 394 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); |
| 396 if (!pApp) { | 395 if (!pApp) { |
| 397 vRet = CJS_Value(pRuntime, 0); | 396 vRet = CJS_Value(pRuntime, 0); |
| 398 return TRUE; | 397 return TRUE; |
| 399 } | 398 } |
| 400 | 399 |
| 401 CFX_WideString swMsg; | 400 CFX_WideString swMsg; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 423 iIcon = newParams[1].ToInt(pRuntime); | 422 iIcon = newParams[1].ToInt(pRuntime); |
| 424 | 423 |
| 425 int iType = 0; | 424 int iType = 0; |
| 426 if (newParams[2].GetType() != CJS_Value::VT_unknown) | 425 if (newParams[2].GetType() != CJS_Value::VT_unknown) |
| 427 iType = newParams[2].ToInt(pRuntime); | 426 iType = newParams[2].ToInt(pRuntime); |
| 428 | 427 |
| 429 CFX_WideString swTitle; | 428 CFX_WideString swTitle; |
| 430 if (newParams[3].GetType() != CJS_Value::VT_unknown) | 429 if (newParams[3].GetType() != CJS_Value::VT_unknown) |
| 431 swTitle = newParams[3].ToCFXWideString(pRuntime); | 430 swTitle = newParams[3].ToCFXWideString(pRuntime); |
| 432 else | 431 else |
| 433 swTitle = JSGetStringFromID(pContext, IDS_STRING_JSALERT); | 432 swTitle = JSGetStringFromID(IDS_STRING_JSALERT); |
| 434 | 433 |
| 435 pRuntime->BeginBlock(); | 434 pRuntime->BeginBlock(); |
| 436 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) | 435 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) |
| 437 pDoc->KillFocusAnnot(); | 436 pDoc->KillFocusAnnot(); |
| 438 | 437 |
| 439 vRet = CJS_Value(pRuntime, pApp->JS_appAlert(swMsg.c_str(), swTitle.c_str(), | 438 vRet = CJS_Value(pRuntime, pApp->JS_appAlert(swMsg.c_str(), swTitle.c_str(), |
| 440 iType, iIcon)); | 439 iType, iIcon)); |
| 441 pRuntime->EndBlock(); | 440 pRuntime->EndBlock(); |
| 442 return TRUE; | 441 return TRUE; |
| 443 } | 442 } |
| 444 | 443 |
| 445 FX_BOOL app::beep(IJS_Context* cc, | 444 FX_BOOL app::beep(IJS_Context* cc, |
| 446 const std::vector<CJS_Value>& params, | 445 const std::vector<CJS_Value>& params, |
| 447 CJS_Value& vRet, | 446 CJS_Value& vRet, |
| 448 CFX_WideString& sError) { | 447 CFX_WideString& sError) { |
| 449 if (params.size() == 1) { | 448 if (params.size() == 1) { |
| 450 CJS_Context* pContext = (CJS_Context*)cc; | 449 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 451 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | |
| 452 CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp(); | 450 CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp(); |
| 453 pEnv->JS_appBeep(params[0].ToInt(pRuntime)); | 451 pEnv->JS_appBeep(params[0].ToInt(pRuntime)); |
| 454 return TRUE; | 452 return TRUE; |
| 455 } | 453 } |
| 456 | 454 |
| 457 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR); | 455 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 458 return FALSE; | 456 return FALSE; |
| 459 } | 457 } |
| 460 | 458 |
| 461 FX_BOOL app::findComponent(IJS_Context* cc, | 459 FX_BOOL app::findComponent(IJS_Context* cc, |
| 462 const std::vector<CJS_Value>& params, | 460 const std::vector<CJS_Value>& params, |
| 463 CJS_Value& vRet, | 461 CJS_Value& vRet, |
| 464 CFX_WideString& sError) { | 462 CFX_WideString& sError) { |
| 465 return TRUE; | 463 return TRUE; |
| 466 } | 464 } |
| 467 | 465 |
| 468 FX_BOOL app::popUpMenuEx(IJS_Context* cc, | 466 FX_BOOL app::popUpMenuEx(IJS_Context* cc, |
| 469 const std::vector<CJS_Value>& params, | 467 const std::vector<CJS_Value>& params, |
| 470 CJS_Value& vRet, | 468 CJS_Value& vRet, |
| 471 CFX_WideString& sError) { | 469 CFX_WideString& sError) { |
| 472 return FALSE; | 470 return FALSE; |
| 473 } | 471 } |
| 474 | 472 |
| 475 FX_BOOL app::fs(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { | 473 FX_BOOL app::fs(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { |
| 476 return FALSE; | 474 return FALSE; |
| 477 } | 475 } |
| 478 | 476 |
| 479 FX_BOOL app::setInterval(IJS_Context* cc, | 477 FX_BOOL app::setInterval(IJS_Context* cc, |
| 480 const std::vector<CJS_Value>& params, | 478 const std::vector<CJS_Value>& params, |
| 481 CJS_Value& vRet, | 479 CJS_Value& vRet, |
| 482 CFX_WideString& sError) { | 480 CFX_WideString& sError) { |
| 483 CJS_Context* pContext = (CJS_Context*)cc; | |
| 484 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | |
| 485 | |
| 486 if (params.size() > 2 || params.size() == 0) { | 481 if (params.size() > 2 || params.size() == 0) { |
| 487 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 482 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 488 return FALSE; | 483 return FALSE; |
| 489 } | 484 } |
| 490 | 485 |
| 486 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 491 CFX_WideString script = | 487 CFX_WideString script = |
| 492 params.size() > 0 ? params[0].ToCFXWideString(pRuntime) : L""; | 488 params.size() > 0 ? params[0].ToCFXWideString(pRuntime) : L""; |
| 493 if (script.IsEmpty()) { | 489 if (script.IsEmpty()) { |
| 494 sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE); | 490 sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE); |
| 495 return TRUE; | 491 return TRUE; |
| 496 } | 492 } |
| 497 | 493 |
| 498 uint32_t dwInterval = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000; | 494 uint32_t dwInterval = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000; |
| 499 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); | 495 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); |
| 500 | 496 |
| 501 GlobalTimer* timerRef = | 497 GlobalTimer* timerRef = |
| 502 new GlobalTimer(this, pApp, pRuntime, 0, script, dwInterval, 0); | 498 new GlobalTimer(this, pApp, pRuntime, 0, script, dwInterval, 0); |
| 503 m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef)); | 499 m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef)); |
| 504 | 500 |
| 505 v8::Local<v8::Object> pRetObj = | 501 v8::Local<v8::Object> pRetObj = |
| 506 pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID); | 502 pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID); |
| 507 CJS_TimerObj* pJS_TimerObj = | 503 CJS_TimerObj* pJS_TimerObj = |
| 508 static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj)); | 504 static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj)); |
| 509 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject()); | 505 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject()); |
| 510 pTimerObj->SetTimer(timerRef); | 506 pTimerObj->SetTimer(timerRef); |
| 511 | 507 |
| 512 vRet = CJS_Value(pRuntime, pRetObj); | 508 vRet = CJS_Value(pRuntime, pRetObj); |
| 513 return TRUE; | 509 return TRUE; |
| 514 } | 510 } |
| 515 | 511 |
| 516 FX_BOOL app::setTimeOut(IJS_Context* cc, | 512 FX_BOOL app::setTimeOut(IJS_Context* cc, |
| 517 const std::vector<CJS_Value>& params, | 513 const std::vector<CJS_Value>& params, |
| 518 CJS_Value& vRet, | 514 CJS_Value& vRet, |
| 519 CFX_WideString& sError) { | 515 CFX_WideString& sError) { |
| 520 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | |
| 521 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | |
| 522 | |
| 523 if (params.size() > 2 || params.size() == 0) { | 516 if (params.size() > 2 || params.size() == 0) { |
| 524 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 517 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 525 return FALSE; | 518 return FALSE; |
| 526 } | 519 } |
| 527 | 520 |
| 521 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 528 CFX_WideString script = params[0].ToCFXWideString(pRuntime); | 522 CFX_WideString script = params[0].ToCFXWideString(pRuntime); |
| 529 if (script.IsEmpty()) { | 523 if (script.IsEmpty()) { |
| 530 sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE); | 524 sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE); |
| 531 return TRUE; | 525 return TRUE; |
| 532 } | 526 } |
| 533 | 527 |
| 534 uint32_t dwTimeOut = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000; | 528 uint32_t dwTimeOut = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000; |
| 535 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); | 529 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp(); |
| 536 | 530 |
| 537 GlobalTimer* timerRef = | 531 GlobalTimer* timerRef = |
| 538 new GlobalTimer(this, pApp, pRuntime, 1, script, dwTimeOut, dwTimeOut); | 532 new GlobalTimer(this, pApp, pRuntime, 1, script, dwTimeOut, dwTimeOut); |
| 539 m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef)); | 533 m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef)); |
| 540 | 534 |
| 541 v8::Local<v8::Object> pRetObj = | 535 v8::Local<v8::Object> pRetObj = |
| 542 pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID); | 536 pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID); |
| 543 | 537 |
| 544 CJS_TimerObj* pJS_TimerObj = | 538 CJS_TimerObj* pJS_TimerObj = |
| 545 static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj)); | 539 static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj)); |
| 546 | 540 |
| 547 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject()); | 541 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject()); |
| 548 pTimerObj->SetTimer(timerRef); | 542 pTimerObj->SetTimer(timerRef); |
| 549 | 543 |
| 550 vRet = CJS_Value(pRuntime, pRetObj); | 544 vRet = CJS_Value(pRuntime, pRetObj); |
| 551 return TRUE; | 545 return TRUE; |
| 552 } | 546 } |
| 553 | 547 |
| 554 FX_BOOL app::clearTimeOut(IJS_Context* cc, | 548 FX_BOOL app::clearTimeOut(IJS_Context* cc, |
| 555 const std::vector<CJS_Value>& params, | 549 const std::vector<CJS_Value>& params, |
| 556 CJS_Value& vRet, | 550 CJS_Value& vRet, |
| 557 CFX_WideString& sError) { | 551 CFX_WideString& sError) { |
| 558 CJS_Context* pContext = (CJS_Context*)cc; | |
| 559 if (params.size() != 1) { | 552 if (params.size() != 1) { |
| 560 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 553 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 561 return FALSE; | 554 return FALSE; |
| 562 } | 555 } |
| 563 | 556 |
| 564 app::ClearTimerCommon(pContext->GetJSRuntime(), params[0]); | 557 app::ClearTimerCommon(CJS_Runtime::FromContext(cc), params[0]); |
| 565 return TRUE; | 558 return TRUE; |
| 566 } | 559 } |
| 567 | 560 |
| 568 FX_BOOL app::clearInterval(IJS_Context* cc, | 561 FX_BOOL app::clearInterval(IJS_Context* cc, |
| 569 const std::vector<CJS_Value>& params, | 562 const std::vector<CJS_Value>& params, |
| 570 CJS_Value& vRet, | 563 CJS_Value& vRet, |
| 571 CFX_WideString& sError) { | 564 CFX_WideString& sError) { |
| 572 CJS_Context* pContext = (CJS_Context*)cc; | |
| 573 if (params.size() != 1) { | 565 if (params.size() != 1) { |
| 574 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 566 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 575 return FALSE; | 567 return FALSE; |
| 576 } | 568 } |
| 577 | 569 |
| 578 app::ClearTimerCommon(pContext->GetJSRuntime(), params[0]); | 570 app::ClearTimerCommon(CJS_Runtime::FromContext(cc), params[0]); |
| 579 return TRUE; | 571 return TRUE; |
| 580 } | 572 } |
| 581 | 573 |
| 582 void app::ClearTimerCommon(CJS_Runtime* pRuntime, const CJS_Value& param) { | 574 void app::ClearTimerCommon(CJS_Runtime* pRuntime, const CJS_Value& param) { |
| 583 if (param.GetType() != CJS_Value::VT_object) | 575 if (param.GetType() != CJS_Value::VT_object) |
| 584 return; | 576 return; |
| 585 | 577 |
| 586 v8::Local<v8::Object> pObj = param.ToV8Object(pRuntime); | 578 v8::Local<v8::Object> pObj = param.ToV8Object(pRuntime); |
| 587 if (CFXJS_Engine::GetObjDefnID(pObj) != CJS_TimerObj::g_nObjDefnID) | 579 if (CFXJS_Engine::GetObjDefnID(pObj) != CJS_TimerObj::g_nObjDefnID) |
| 588 return; | 580 return; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 CJS_Value& vRet, | 630 CJS_Value& vRet, |
| 639 CFX_WideString& sError) { | 631 CFX_WideString& sError) { |
| 640 // Not supported. | 632 // Not supported. |
| 641 return TRUE; | 633 return TRUE; |
| 642 } | 634 } |
| 643 | 635 |
| 644 FX_BOOL app::mailMsg(IJS_Context* cc, | 636 FX_BOOL app::mailMsg(IJS_Context* cc, |
| 645 const std::vector<CJS_Value>& params, | 637 const std::vector<CJS_Value>& params, |
| 646 CJS_Value& vRet, | 638 CJS_Value& vRet, |
| 647 CFX_WideString& sError) { | 639 CFX_WideString& sError) { |
| 648 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 640 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 649 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | |
| 650 std::vector<CJS_Value> newParams = | 641 std::vector<CJS_Value> newParams = |
| 651 JS_ExpandKeywordParams(pRuntime, params, 6, L"bUI", L"cTo", L"cCc", | 642 JS_ExpandKeywordParams(pRuntime, params, 6, L"bUI", L"cTo", L"cCc", |
| 652 L"cBcc", L"cSubject", L"cMsg"); | 643 L"cBcc", L"cSubject", L"cMsg"); |
| 653 | 644 |
| 654 if (newParams[0].GetType() == CJS_Value::VT_unknown) { | 645 if (newParams[0].GetType() == CJS_Value::VT_unknown) { |
| 655 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 646 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 656 return FALSE; | 647 return FALSE; |
| 657 } | 648 } |
| 658 bool bUI = newParams[0].ToBool(pRuntime); | 649 bool bUI = newParams[0].ToBool(pRuntime); |
| 659 | 650 |
| 660 CFX_WideString cTo; | 651 CFX_WideString cTo; |
| 661 if (newParams[1].GetType() != CJS_Value::VT_unknown) { | 652 if (newParams[1].GetType() != CJS_Value::VT_unknown) { |
| 662 cTo = newParams[1].ToCFXWideString(pRuntime); | 653 cTo = newParams[1].ToCFXWideString(pRuntime); |
| 663 } else { | 654 } else { |
| 664 if (!bUI) { | 655 if (!bUI) { |
| 665 // cTo parameter required when UI not invoked. | 656 // cTo parameter required when UI not invoked. |
| 666 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 657 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 667 return FALSE; | 658 return FALSE; |
| 668 } | 659 } |
| 669 } | 660 } |
| 670 | 661 |
| 671 CFX_WideString cCc; | 662 CFX_WideString cCc; |
| 672 if (newParams[2].GetType() != CJS_Value::VT_unknown) | 663 if (newParams[2].GetType() != CJS_Value::VT_unknown) |
| 673 cCc = newParams[2].ToCFXWideString(pRuntime); | 664 cCc = newParams[2].ToCFXWideString(pRuntime); |
| 674 | 665 |
| 675 CFX_WideString cBcc; | 666 CFX_WideString cBcc; |
| 676 if (newParams[3].GetType() != CJS_Value::VT_unknown) | 667 if (newParams[3].GetType() != CJS_Value::VT_unknown) |
| 677 cBcc = newParams[3].ToCFXWideString(pRuntime); | 668 cBcc = newParams[3].ToCFXWideString(pRuntime); |
| 678 | 669 |
| 679 CFX_WideString cSubject; | 670 CFX_WideString cSubject; |
| 680 if (newParams[4].GetType() != CJS_Value::VT_unknown) | 671 if (newParams[4].GetType() != CJS_Value::VT_unknown) |
| 681 cSubject = newParams[4].ToCFXWideString(pRuntime); | 672 cSubject = newParams[4].ToCFXWideString(pRuntime); |
| 682 | 673 |
| 683 CFX_WideString cMsg; | 674 CFX_WideString cMsg; |
| 684 if (newParams[5].GetType() != CJS_Value::VT_unknown) | 675 if (newParams[5].GetType() != CJS_Value::VT_unknown) |
| 685 cMsg = newParams[5].ToCFXWideString(pRuntime); | 676 cMsg = newParams[5].ToCFXWideString(pRuntime); |
| 686 | 677 |
| 687 pRuntime->BeginBlock(); | 678 pRuntime->BeginBlock(); |
| 679 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 688 pContext->GetReaderApp()->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(), | 680 pContext->GetReaderApp()->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(), |
| 689 cSubject.c_str(), cCc.c_str(), | 681 cSubject.c_str(), cCc.c_str(), |
| 690 cBcc.c_str(), cMsg.c_str()); | 682 cBcc.c_str(), cMsg.c_str()); |
| 691 pRuntime->EndBlock(); | 683 pRuntime->EndBlock(); |
| 692 return TRUE; | 684 return TRUE; |
| 693 } | 685 } |
| 694 | 686 |
| 695 FX_BOOL app::launchURL(IJS_Context* cc, | 687 FX_BOOL app::launchURL(IJS_Context* cc, |
| 696 const std::vector<CJS_Value>& params, | 688 const std::vector<CJS_Value>& params, |
| 697 CJS_Value& vRet, | 689 CJS_Value& vRet, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 const std::vector<CJS_Value>& params, | 753 const std::vector<CJS_Value>& params, |
| 762 CJS_Value& vRet, | 754 CJS_Value& vRet, |
| 763 CFX_WideString& sError) { | 755 CFX_WideString& sError) { |
| 764 return FALSE; | 756 return FALSE; |
| 765 } | 757 } |
| 766 | 758 |
| 767 FX_BOOL app::response(IJS_Context* cc, | 759 FX_BOOL app::response(IJS_Context* cc, |
| 768 const std::vector<CJS_Value>& params, | 760 const std::vector<CJS_Value>& params, |
| 769 CJS_Value& vRet, | 761 CJS_Value& vRet, |
| 770 CFX_WideString& sError) { | 762 CFX_WideString& sError) { |
| 771 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | |
| 772 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 763 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 773 std::vector<CJS_Value> newParams = | 764 std::vector<CJS_Value> newParams = |
| 774 JS_ExpandKeywordParams(pRuntime, params, 5, L"cQuestion", L"cTitle", | 765 JS_ExpandKeywordParams(pRuntime, params, 5, L"cQuestion", L"cTitle", |
| 775 L"cDefault", L"bPassword", L"cLabel"); | 766 L"cDefault", L"bPassword", L"cLabel"); |
| 776 | 767 |
| 777 if (newParams[0].GetType() == CJS_Value::VT_unknown) { | 768 if (newParams[0].GetType() == CJS_Value::VT_unknown) { |
| 778 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 769 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 779 return FALSE; | 770 return FALSE; |
| 780 } | 771 } |
| 781 CFX_WideString swQuestion = newParams[0].ToCFXWideString(pRuntime); | 772 CFX_WideString swQuestion = newParams[0].ToCFXWideString(pRuntime); |
| 782 | 773 |
| 783 CFX_WideString swTitle = L"PDF"; | 774 CFX_WideString swTitle = L"PDF"; |
| 784 if (newParams[1].GetType() != CJS_Value::VT_unknown) | 775 if (newParams[1].GetType() != CJS_Value::VT_unknown) |
| 785 swTitle = newParams[1].ToCFXWideString(pRuntime); | 776 swTitle = newParams[1].ToCFXWideString(pRuntime); |
| 786 | 777 |
| 787 CFX_WideString swDefault; | 778 CFX_WideString swDefault; |
| 788 if (newParams[2].GetType() != CJS_Value::VT_unknown) | 779 if (newParams[2].GetType() != CJS_Value::VT_unknown) |
| 789 swDefault = newParams[2].ToCFXWideString(pRuntime); | 780 swDefault = newParams[2].ToCFXWideString(pRuntime); |
| 790 | 781 |
| 791 bool bPassword = false; | 782 bool bPassword = false; |
| 792 if (newParams[3].GetType() != CJS_Value::VT_unknown) | 783 if (newParams[3].GetType() != CJS_Value::VT_unknown) |
| 793 bPassword = newParams[3].ToBool(pRuntime); | 784 bPassword = newParams[3].ToBool(pRuntime); |
| 794 | 785 |
| 795 CFX_WideString swLabel; | 786 CFX_WideString swLabel; |
| 796 if (newParams[4].GetType() != CJS_Value::VT_unknown) | 787 if (newParams[4].GetType() != CJS_Value::VT_unknown) |
| 797 swLabel = newParams[4].ToCFXWideString(pRuntime); | 788 swLabel = newParams[4].ToCFXWideString(pRuntime); |
| 798 | 789 |
| 799 const int MAX_INPUT_BYTES = 2048; | 790 const int MAX_INPUT_BYTES = 2048; |
| 800 std::unique_ptr<char[]> pBuff(new char[MAX_INPUT_BYTES + 2]); | 791 std::unique_ptr<char[]> pBuff(new char[MAX_INPUT_BYTES + 2]); |
| 801 memset(pBuff.get(), 0, MAX_INPUT_BYTES + 2); | 792 memset(pBuff.get(), 0, MAX_INPUT_BYTES + 2); |
| 802 | 793 |
| 794 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 803 int nLengthBytes = pContext->GetReaderApp()->JS_appResponse( | 795 int nLengthBytes = pContext->GetReaderApp()->JS_appResponse( |
| 804 swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(), | 796 swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(), |
| 805 bPassword, pBuff.get(), MAX_INPUT_BYTES); | 797 bPassword, pBuff.get(), MAX_INPUT_BYTES); |
| 806 | 798 |
| 807 if (nLengthBytes < 0 || nLengthBytes > MAX_INPUT_BYTES) { | 799 if (nLengthBytes < 0 || nLengthBytes > MAX_INPUT_BYTES) { |
| 808 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG); | 800 sError = JSGetStringFromID(IDS_STRING_JSPARAM_TOOLONG); |
| 809 return FALSE; | 801 return FALSE; |
| 810 } | 802 } |
| 811 | 803 |
| 812 vRet = CJS_Value(pRuntime, CFX_WideString::FromUTF16LE( | 804 vRet = CJS_Value(pRuntime, CFX_WideString::FromUTF16LE( |
| 813 reinterpret_cast<uint16_t*>(pBuff.get()), | 805 reinterpret_cast<uint16_t*>(pBuff.get()), |
| 814 nLengthBytes / sizeof(uint16_t)) | 806 nLengthBytes / sizeof(uint16_t)) |
| 815 .c_str()); | 807 .c_str()); |
| 816 | 808 |
| 817 return TRUE; | 809 return TRUE; |
| 818 } | 810 } |
| 819 | 811 |
| 820 FX_BOOL app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { | 812 FX_BOOL app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { |
| 821 return FALSE; | 813 return FALSE; |
| 822 } | 814 } |
| 823 | 815 |
| 824 FX_BOOL app::execDialog(IJS_Context* cc, | 816 FX_BOOL app::execDialog(IJS_Context* cc, |
| 825 const std::vector<CJS_Value>& params, | 817 const std::vector<CJS_Value>& params, |
| 826 CJS_Value& vRet, | 818 CJS_Value& vRet, |
| 827 CFX_WideString& sError) { | 819 CFX_WideString& sError) { |
| 828 return TRUE; | 820 return TRUE; |
| 829 } | 821 } |
| OLD | NEW |