OLD | NEW |
| (Empty) |
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 | |
7 #include "xfa/fxfa/parser/xfa_script_signaturepseudomodel.h" | |
8 | |
9 #include "fxjs/include/cfxjse_arguments.h" | |
10 #include "xfa/fxfa/app/xfa_ffnotify.h" | |
11 #include "xfa/fxfa/parser/xfa_doclayout.h" | |
12 #include "xfa/fxfa/parser/xfa_document.h" | |
13 #include "xfa/fxfa/parser/xfa_localemgr.h" | |
14 #include "xfa/fxfa/parser/xfa_object.h" | |
15 #include "xfa/fxfa/parser/xfa_script.h" | |
16 #include "xfa/fxfa/parser/xfa_script_imp.h" | |
17 #include "xfa/fxfa/parser/xfa_utils.h" | |
18 | |
19 CScript_SignaturePseudoModel::CScript_SignaturePseudoModel( | |
20 CXFA_Document* pDocument) | |
21 : CXFA_Object(pDocument, | |
22 XFA_ObjectType::Object, | |
23 XFA_Element::SignaturePseudoModel, | |
24 CFX_WideStringC(L"signaturePseudoModel")) {} | |
25 | |
26 CScript_SignaturePseudoModel::~CScript_SignaturePseudoModel() {} | |
27 | |
28 void CScript_SignaturePseudoModel::Verify(CFXJSE_Arguments* pArguments) { | |
29 int32_t iLength = pArguments->GetLength(); | |
30 if (iLength < 1 || iLength > 4) { | |
31 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"verify"); | |
32 return; | |
33 } | |
34 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
35 if (!pNotify) { | |
36 return; | |
37 } | |
38 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); | |
39 CXFA_Node* pNode = nullptr; | |
40 if (iLength >= 1) { | |
41 pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); | |
42 } | |
43 int32_t bVerify = pNotify->GetDocProvider()->Verify(hDoc, pNode); | |
44 CFXJSE_Value* pValue = pArguments->GetReturnValue(); | |
45 if (pValue) | |
46 pValue->SetInteger(bVerify); | |
47 } | |
48 | |
49 void CScript_SignaturePseudoModel::Sign(CFXJSE_Arguments* pArguments) { | |
50 int32_t iLength = pArguments->GetLength(); | |
51 if (iLength < 3 || iLength > 7) { | |
52 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"sign"); | |
53 return; | |
54 } | |
55 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
56 if (!pNotify) { | |
57 return; | |
58 } | |
59 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); | |
60 CXFA_NodeList* pNodeList = nullptr; | |
61 CFX_WideString wsExpression; | |
62 CFX_WideString wsXMLIdent; | |
63 if (iLength >= 1) { | |
64 pNodeList = (CXFA_NodeList*)pArguments->GetObject(0); | |
65 } | |
66 if (iLength >= 2) { | |
67 CFX_ByteString bsExpression = pArguments->GetUTF8String(1); | |
68 wsExpression = CFX_WideString::FromUTF8(bsExpression.AsStringC()); | |
69 } | |
70 if (iLength >= 3) { | |
71 CFX_ByteString bsXMLIdent = pArguments->GetUTF8String(2); | |
72 wsXMLIdent = CFX_WideString::FromUTF8(bsXMLIdent.AsStringC()); | |
73 } | |
74 FX_BOOL bSign = pNotify->GetDocProvider()->Sign( | |
75 hDoc, pNodeList, wsExpression.AsStringC(), wsXMLIdent.AsStringC()); | |
76 CFXJSE_Value* pValue = pArguments->GetReturnValue(); | |
77 if (pValue) | |
78 pValue->SetBoolean(bSign); | |
79 } | |
80 | |
81 void CScript_SignaturePseudoModel::Enumerate(CFXJSE_Arguments* pArguments) { | |
82 int32_t iLength = pArguments->GetLength(); | |
83 if (iLength != 0) { | |
84 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"enumerate"); | |
85 return; | |
86 } | |
87 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
88 if (!pNotify) { | |
89 return; | |
90 } | |
91 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); | |
92 CXFA_NodeList* pList = pNotify->GetDocProvider()->Enumerate(hDoc); | |
93 if (!pList) | |
94 return; | |
95 pArguments->GetReturnValue()->Assign( | |
96 m_pDocument->GetScriptContext()->GetJSValueFromMap(pList)); | |
97 } | |
98 | |
99 void CScript_SignaturePseudoModel::Clear(CFXJSE_Arguments* pArguments) { | |
100 int32_t iLength = pArguments->GetLength(); | |
101 if (iLength < 1 || iLength > 2) { | |
102 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"clear"); | |
103 return; | |
104 } | |
105 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
106 if (!pNotify) { | |
107 return; | |
108 } | |
109 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); | |
110 CXFA_Node* pNode = nullptr; | |
111 FX_BOOL bClear = TRUE; | |
112 if (iLength >= 1) { | |
113 pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); | |
114 } | |
115 if (iLength >= 2) { | |
116 bClear = pArguments->GetInt32(1) == 0 ? FALSE : TRUE; | |
117 } | |
118 FX_BOOL bFlag = pNotify->GetDocProvider()->Clear(hDoc, pNode, bClear); | |
119 CFXJSE_Value* pValue = pArguments->GetReturnValue(); | |
120 if (pValue) | |
121 pValue->SetBoolean(bFlag); | |
122 } | |
OLD | NEW |