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 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 const std::vector<CJS_Value>& params, | 649 const std::vector<CJS_Value>& params, |
650 CJS_Value& vRet, | 650 CJS_Value& vRet, |
651 CFX_WideString& sError) { | 651 CFX_WideString& sError) { |
652 return FALSE; | 652 return FALSE; |
653 } | 653 } |
654 | 654 |
655 FX_BOOL app::response(IJS_Context* cc, | 655 FX_BOOL app::response(IJS_Context* cc, |
656 const std::vector<CJS_Value>& params, | 656 const std::vector<CJS_Value>& params, |
657 CJS_Value& vRet, | 657 CJS_Value& vRet, |
658 CFX_WideString& sError) { | 658 CFX_WideString& sError) { |
659 CFX_WideString swQuestion = L""; | 659 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
660 CFX_WideString swLabel = L""; | 660 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 661 std::vector<CJS_Value> newParams = |
| 662 JS_ExpandKeywordParams(pRuntime, params, 5, L"cQuestion", L"cTitle", |
| 663 L"cDefault", L"bPassword", L"cLabel"); |
| 664 |
| 665 if (newParams[0].GetType() == CJS_Value::VT_unknown) { |
| 666 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 667 return FALSE; |
| 668 } |
| 669 CFX_WideString swQuestion = newParams[0].ToCFXWideString(); |
| 670 |
661 CFX_WideString swTitle = L"PDF"; | 671 CFX_WideString swTitle = L"PDF"; |
662 CFX_WideString swDefault = L""; | 672 if (newParams[1].GetType() != CJS_Value::VT_unknown) |
663 bool bPassWord = false; | 673 swTitle = newParams[1].ToCFXWideString(); |
664 | 674 |
665 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 675 CFX_WideString swDefault; |
666 v8::Isolate* isolate = pRuntime->GetIsolate(); | 676 if (newParams[2].GetType() != CJS_Value::VT_unknown) |
| 677 swDefault = newParams[2].ToCFXWideString(); |
667 | 678 |
668 int iLength = params.size(); | 679 bool bPassword = false; |
669 if (iLength > 0 && params[0].GetType() == CJS_Value::VT_object) { | 680 if (newParams[3].GetType() != CJS_Value::VT_unknown) |
670 v8::Local<v8::Object> pObj = params[0].ToV8Object(); | 681 bPassword = newParams[3].ToBool(); |
671 v8::Local<v8::Value> pValue = | |
672 FXJS_GetObjectElement(isolate, pObj, L"cQuestion"); | |
673 swQuestion = | |
674 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); | |
675 | 682 |
676 pValue = FXJS_GetObjectElement(isolate, pObj, L"cTitle"); | 683 CFX_WideString swLabel; |
677 swTitle = | 684 if (newParams[4].GetType() != CJS_Value::VT_unknown) |
678 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); | 685 swLabel = newParams[4].ToCFXWideString(); |
679 | |
680 pValue = FXJS_GetObjectElement(isolate, pObj, L"cDefault"); | |
681 swDefault = | |
682 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); | |
683 | |
684 pValue = FXJS_GetObjectElement(isolate, pObj, L"cLabel"); | |
685 swLabel = | |
686 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); | |
687 | |
688 pValue = FXJS_GetObjectElement(isolate, pObj, L"bPassword"); | |
689 bPassWord = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToBool(); | |
690 } else { | |
691 switch (iLength) { | |
692 case 5: | |
693 swLabel = params[4].ToCFXWideString(); | |
694 // FALLTHROUGH | |
695 case 4: | |
696 bPassWord = params[3].ToBool(); | |
697 // FALLTHROUGH | |
698 case 3: | |
699 swDefault = params[2].ToCFXWideString(); | |
700 // FALLTHROUGH | |
701 case 2: | |
702 swTitle = params[1].ToCFXWideString(); | |
703 // FALLTHROUGH | |
704 case 1: | |
705 swQuestion = params[0].ToCFXWideString(); | |
706 // FALLTHROUGH | |
707 default: | |
708 break; | |
709 } | |
710 } | |
711 | |
712 CJS_Context* pContext = (CJS_Context*)cc; | |
713 CPDFDoc_Environment* pApp = pContext->GetReaderApp(); | |
714 | 686 |
715 const int MAX_INPUT_BYTES = 2048; | 687 const int MAX_INPUT_BYTES = 2048; |
716 std::unique_ptr<char[]> pBuff(new char[MAX_INPUT_BYTES + 2]); | 688 std::unique_ptr<char[]> pBuff(new char[MAX_INPUT_BYTES + 2]); |
717 memset(pBuff.get(), 0, MAX_INPUT_BYTES + 2); | 689 memset(pBuff.get(), 0, MAX_INPUT_BYTES + 2); |
718 int nLengthBytes = pApp->JS_appResponse( | 690 |
| 691 int nLengthBytes = pContext->GetReaderApp()->JS_appResponse( |
719 swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(), | 692 swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(), |
720 bPassWord, pBuff.get(), MAX_INPUT_BYTES); | 693 bPassword, pBuff.get(), MAX_INPUT_BYTES); |
721 if (nLengthBytes <= 0) { | 694 |
722 vRet.SetNull(); | 695 if (nLengthBytes < 0 || nLengthBytes > MAX_INPUT_BYTES) { |
| 696 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG); |
723 return FALSE; | 697 return FALSE; |
724 } | 698 } |
725 nLengthBytes = std::min(nLengthBytes, MAX_INPUT_BYTES); | |
726 | 699 |
727 CFX_WideString ret_string = CFX_WideString::FromUTF16LE( | 700 vRet = CFX_WideString::FromUTF16LE(reinterpret_cast<uint16_t*>(pBuff.get()), |
728 (unsigned short*)pBuff.get(), nLengthBytes / sizeof(unsigned short)); | 701 nLengthBytes / sizeof(uint16_t)) |
729 vRet = ret_string.c_str(); | 702 .c_str(); |
730 return TRUE; | 703 return TRUE; |
731 } | 704 } |
732 | 705 |
733 FX_BOOL app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { | 706 FX_BOOL app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { |
734 return FALSE; | 707 return FALSE; |
735 } | 708 } |
736 | 709 |
737 FX_BOOL app::execDialog(IJS_Context* cc, | 710 FX_BOOL app::execDialog(IJS_Context* cc, |
738 const std::vector<CJS_Value>& params, | 711 const std::vector<CJS_Value>& params, |
739 CJS_Value& vRet, | 712 CJS_Value& vRet, |
740 CFX_WideString& sError) { | 713 CFX_WideString& sError) { |
741 return TRUE; | 714 return TRUE; |
742 } | 715 } |
OLD | NEW |