Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: fpdfsdk/src/javascript/app.cpp

Issue 1658753002: Merge to XFA: Use JS_ExpandKeywordParams() in app.response() (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | samples/pdfium_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 672 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 const std::vector<CJS_Value>& params, 683 const std::vector<CJS_Value>& params,
684 CJS_Value& vRet, 684 CJS_Value& vRet,
685 CFX_WideString& sError) { 685 CFX_WideString& sError) {
686 return FALSE; 686 return FALSE;
687 } 687 }
688 688
689 FX_BOOL app::response(IJS_Context* cc, 689 FX_BOOL app::response(IJS_Context* cc,
690 const std::vector<CJS_Value>& params, 690 const std::vector<CJS_Value>& params,
691 CJS_Value& vRet, 691 CJS_Value& vRet,
692 CFX_WideString& sError) { 692 CFX_WideString& sError) {
693 CFX_WideString swQuestion = L""; 693 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
694 CFX_WideString swLabel = L""; 694 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
695 std::vector<CJS_Value> newParams =
696 JS_ExpandKeywordParams(pRuntime, params, 5, L"cQuestion", L"cTitle",
697 L"cDefault", L"bPassword", L"cLabel");
698
699 if (newParams[0].GetType() == CJS_Value::VT_unknown) {
700 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
701 return FALSE;
702 }
703 CFX_WideString swQuestion = newParams[0].ToCFXWideString();
704
695 CFX_WideString swTitle = L"PDF"; 705 CFX_WideString swTitle = L"PDF";
696 CFX_WideString swDefault = L""; 706 if (newParams[1].GetType() != CJS_Value::VT_unknown)
697 bool bPassWord = false; 707 swTitle = newParams[1].ToCFXWideString();
698 708
699 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); 709 CFX_WideString swDefault;
700 v8::Isolate* isolate = pRuntime->GetIsolate(); 710 if (newParams[2].GetType() != CJS_Value::VT_unknown)
711 swDefault = newParams[2].ToCFXWideString();
701 712
702 int iLength = params.size(); 713 bool bPassword = false;
703 if (iLength > 0 && params[0].GetType() == CJS_Value::VT_object) { 714 if (newParams[3].GetType() != CJS_Value::VT_unknown)
704 v8::Local<v8::Object> pObj = params[0].ToV8Object(); 715 bPassword = newParams[3].ToBool();
705 v8::Local<v8::Value> pValue =
706 FXJS_GetObjectElement(isolate, pObj, L"cQuestion");
707 swQuestion =
708 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
709 716
710 pValue = FXJS_GetObjectElement(isolate, pObj, L"cTitle"); 717 CFX_WideString swLabel;
711 swTitle = 718 if (newParams[4].GetType() != CJS_Value::VT_unknown)
712 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); 719 swLabel = newParams[4].ToCFXWideString();
713
714 pValue = FXJS_GetObjectElement(isolate, pObj, L"cDefault");
715 swDefault =
716 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
717
718 pValue = FXJS_GetObjectElement(isolate, pObj, L"cLabel");
719 swLabel =
720 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
721
722 pValue = FXJS_GetObjectElement(isolate, pObj, L"bPassword");
723 bPassWord = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToBool();
724 } else {
725 switch (iLength) {
726 case 5:
727 swLabel = params[4].ToCFXWideString();
728 // FALLTHROUGH
729 case 4:
730 bPassWord = params[3].ToBool();
731 // FALLTHROUGH
732 case 3:
733 swDefault = params[2].ToCFXWideString();
734 // FALLTHROUGH
735 case 2:
736 swTitle = params[1].ToCFXWideString();
737 // FALLTHROUGH
738 case 1:
739 swQuestion = params[0].ToCFXWideString();
740 // FALLTHROUGH
741 default:
742 break;
743 }
744 }
745
746 CJS_Context* pContext = (CJS_Context*)cc;
747 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
748 720
749 const int MAX_INPUT_BYTES = 2048; 721 const int MAX_INPUT_BYTES = 2048;
750 std::unique_ptr<char[]> pBuff(new char[MAX_INPUT_BYTES + 2]); 722 std::unique_ptr<char[]> pBuff(new char[MAX_INPUT_BYTES + 2]);
751 memset(pBuff.get(), 0, MAX_INPUT_BYTES + 2); 723 memset(pBuff.get(), 0, MAX_INPUT_BYTES + 2);
752 int nLengthBytes = pApp->JS_appResponse( 724
725 int nLengthBytes = pContext->GetReaderApp()->JS_appResponse(
753 swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(), 726 swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(),
754 bPassWord, pBuff.get(), MAX_INPUT_BYTES); 727 bPassword, pBuff.get(), MAX_INPUT_BYTES);
755 if (nLengthBytes <= 0) { 728
756 vRet.SetNull(); 729 if (nLengthBytes < 0 || nLengthBytes > MAX_INPUT_BYTES) {
730 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG);
757 return FALSE; 731 return FALSE;
758 } 732 }
759 nLengthBytes = std::min(nLengthBytes, MAX_INPUT_BYTES);
760 733
761 CFX_WideString ret_string = CFX_WideString::FromUTF16LE( 734 vRet = CFX_WideString::FromUTF16LE(reinterpret_cast<uint16_t*>(pBuff.get()),
762 (unsigned short*)pBuff.get(), nLengthBytes / sizeof(unsigned short)); 735 nLengthBytes / sizeof(uint16_t))
763 vRet = ret_string.c_str(); 736 .c_str();
764 return TRUE; 737 return TRUE;
765 } 738 }
766 739
767 FX_BOOL app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { 740 FX_BOOL app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) {
768 return FALSE; 741 return FALSE;
769 } 742 }
770 743
771 FX_BOOL app::execDialog(IJS_Context* cc, 744 FX_BOOL app::execDialog(IJS_Context* cc,
772 const std::vector<CJS_Value>& params, 745 const std::vector<CJS_Value>& params,
773 CJS_Value& vRet, 746 CJS_Value& vRet,
774 CFX_WideString& sError) { 747 CFX_WideString& sError) {
775 return TRUE; 748 return TRUE;
776 } 749 }
OLDNEW
« no previous file with comments | « no previous file | samples/pdfium_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698