Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
dsinclair | c1515ef | 2016-07-20 06:16:06 -0700 | [diff] [blame] | 7 | #include "xfa/fxfa/parser/cscript_signaturepseudomodel.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 8 | |
dsinclair | 08fea80 | 2016-07-12 10:37:52 -0700 | [diff] [blame] | 9 | #include "fxjs/include/cfxjse_arguments.h" |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 10 | #include "xfa/fxfa/app/xfa_ffnotify.h" |
dsinclair | 31f8740 | 2016-07-20 06:34:45 -0700 | [diff] [blame^] | 11 | #include "xfa/fxfa/parser/cxfa_scriptcontext.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 12 | #include "xfa/fxfa/parser/xfa_doclayout.h" |
| 13 | #include "xfa/fxfa/parser/xfa_document.h" |
| 14 | #include "xfa/fxfa/parser/xfa_localemgr.h" |
| 15 | #include "xfa/fxfa/parser/xfa_object.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 16 | #include "xfa/fxfa/parser/xfa_utils.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 17 | |
| 18 | CScript_SignaturePseudoModel::CScript_SignaturePseudoModel( |
| 19 | CXFA_Document* pDocument) |
dsinclair | 937a113 | 2016-06-23 07:52:01 -0700 | [diff] [blame] | 20 | : CXFA_Object(pDocument, |
| 21 | XFA_ObjectType::Object, |
dsinclair | c1df5d4 | 2016-07-18 06:36:51 -0700 | [diff] [blame] | 22 | XFA_Element::SignaturePseudoModel, |
| 23 | CFX_WideStringC(L"signaturePseudoModel")) {} |
| 24 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 25 | CScript_SignaturePseudoModel::~CScript_SignaturePseudoModel() {} |
dsinclair | c1df5d4 | 2016-07-18 06:36:51 -0700 | [diff] [blame] | 26 | |
dsinclair | d1cf239 | 2016-07-11 06:46:59 -0700 | [diff] [blame] | 27 | void CScript_SignaturePseudoModel::Verify(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 28 | int32_t iLength = pArguments->GetLength(); |
| 29 | if (iLength < 1 || iLength > 4) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 30 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"verify"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 31 | return; |
| 32 | } |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 33 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 34 | if (!pNotify) { |
| 35 | return; |
| 36 | } |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 37 | CXFA_FFDoc* hDoc = pNotify->GetHDOC(); |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 38 | CXFA_Node* pNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 39 | if (iLength >= 1) { |
| 40 | pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); |
| 41 | } |
| 42 | int32_t bVerify = pNotify->GetDocProvider()->Verify(hDoc, pNode); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 43 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 44 | if (pValue) |
| 45 | pValue->SetInteger(bVerify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 46 | } |
dsinclair | c1df5d4 | 2016-07-18 06:36:51 -0700 | [diff] [blame] | 47 | |
dsinclair | d1cf239 | 2016-07-11 06:46:59 -0700 | [diff] [blame] | 48 | void CScript_SignaturePseudoModel::Sign(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 49 | int32_t iLength = pArguments->GetLength(); |
| 50 | if (iLength < 3 || iLength > 7) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 51 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"sign"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 52 | return; |
| 53 | } |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 54 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 55 | if (!pNotify) { |
| 56 | return; |
| 57 | } |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 58 | CXFA_FFDoc* hDoc = pNotify->GetHDOC(); |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 59 | CXFA_NodeList* pNodeList = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 60 | CFX_WideString wsExpression; |
| 61 | CFX_WideString wsXMLIdent; |
| 62 | if (iLength >= 1) { |
| 63 | pNodeList = (CXFA_NodeList*)pArguments->GetObject(0); |
| 64 | } |
| 65 | if (iLength >= 2) { |
| 66 | CFX_ByteString bsExpression = pArguments->GetUTF8String(1); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 67 | wsExpression = CFX_WideString::FromUTF8(bsExpression.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 68 | } |
| 69 | if (iLength >= 3) { |
| 70 | CFX_ByteString bsXMLIdent = pArguments->GetUTF8String(2); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 71 | wsXMLIdent = CFX_WideString::FromUTF8(bsXMLIdent.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 72 | } |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 73 | FX_BOOL bSign = pNotify->GetDocProvider()->Sign( |
| 74 | hDoc, pNodeList, wsExpression.AsStringC(), wsXMLIdent.AsStringC()); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 75 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 76 | if (pValue) |
| 77 | pValue->SetBoolean(bSign); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 78 | } |
dsinclair | c1df5d4 | 2016-07-18 06:36:51 -0700 | [diff] [blame] | 79 | |
dsinclair | d1cf239 | 2016-07-11 06:46:59 -0700 | [diff] [blame] | 80 | void CScript_SignaturePseudoModel::Enumerate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 81 | int32_t iLength = pArguments->GetLength(); |
| 82 | if (iLength != 0) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 83 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"enumerate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 84 | return; |
| 85 | } |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 86 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 87 | if (!pNotify) { |
| 88 | return; |
| 89 | } |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 90 | CXFA_FFDoc* hDoc = pNotify->GetHDOC(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 91 | CXFA_NodeList* pList = pNotify->GetDocProvider()->Enumerate(hDoc); |
| 92 | if (!pList) |
| 93 | return; |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 94 | pArguments->GetReturnValue()->Assign( |
| 95 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pList)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 96 | } |
dsinclair | c1df5d4 | 2016-07-18 06:36:51 -0700 | [diff] [blame] | 97 | |
dsinclair | d1cf239 | 2016-07-11 06:46:59 -0700 | [diff] [blame] | 98 | void CScript_SignaturePseudoModel::Clear(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 99 | int32_t iLength = pArguments->GetLength(); |
| 100 | if (iLength < 1 || iLength > 2) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 101 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"clear"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 102 | return; |
| 103 | } |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 104 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 105 | if (!pNotify) { |
| 106 | return; |
| 107 | } |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 108 | CXFA_FFDoc* hDoc = pNotify->GetHDOC(); |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 109 | CXFA_Node* pNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 110 | FX_BOOL bClear = TRUE; |
| 111 | if (iLength >= 1) { |
| 112 | pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); |
| 113 | } |
| 114 | if (iLength >= 2) { |
| 115 | bClear = pArguments->GetInt32(1) == 0 ? FALSE : TRUE; |
| 116 | } |
| 117 | FX_BOOL bFlag = pNotify->GetDocProvider()->Clear(hDoc, pNode, bClear); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 118 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 119 | if (pValue) |
| 120 | pValue->SetBoolean(bFlag); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 121 | } |