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/src/fxfa/parser/xfa_script_signaturepseudomodel.h" | |
8 | |
9 #include "xfa/src/fxfa/fm2js/xfa_fm2jsapi.h" | |
10 #include "xfa/src/fxfa/parser/xfa_docdata.h" | |
11 #include "xfa/src/fxfa/parser/xfa_doclayout.h" | |
12 #include "xfa/src/fxfa/parser/xfa_document.h" | |
13 #include "xfa/src/fxfa/parser/xfa_localemgr.h" | |
14 #include "xfa/src/fxfa/parser/xfa_object.h" | |
15 #include "xfa/src/fxfa/parser/xfa_parser.h" | |
16 #include "xfa/src/fxfa/parser/xfa_script.h" | |
17 #include "xfa/src/fxfa/parser/xfa_utils.h" | |
18 | |
19 CScript_SignaturePseudoModel::CScript_SignaturePseudoModel( | |
20 CXFA_Document* pDocument) | |
21 : CXFA_OrdinaryObject(pDocument, XFA_ELEMENT_SignaturePseudoModel) { | |
22 m_uScriptHash = XFA_HASHCODE_Signature; | |
23 } | |
24 CScript_SignaturePseudoModel::~CScript_SignaturePseudoModel() {} | |
25 void CScript_SignaturePseudoModel::Script_SignaturePseudoModel_Verify( | |
26 CFXJSE_Arguments* pArguments) { | |
27 int32_t iLength = pArguments->GetLength(); | |
28 if (iLength < 1 || iLength > 4) { | |
29 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"verify"); | |
30 return; | |
31 } | |
32 IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify(); | |
33 if (!pNotify) { | |
34 return; | |
35 } | |
36 IXFA_Doc* hDoc = pNotify->GetHDOC(); | |
37 CXFA_Node* pNode = NULL; | |
38 if (iLength >= 1) { | |
39 pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); | |
40 } | |
41 int32_t bVerify = pNotify->GetDocProvider()->Verify(hDoc, pNode); | |
42 FXJSE_HVALUE hValue = pArguments->GetReturnValue(); | |
43 if (hValue) { | |
44 FXJSE_Value_SetInteger(hValue, bVerify); | |
45 } | |
46 } | |
47 void CScript_SignaturePseudoModel::Script_SignaturePseudoModel_Sign( | |
48 CFXJSE_Arguments* pArguments) { | |
49 int32_t iLength = pArguments->GetLength(); | |
50 if (iLength < 3 || iLength > 7) { | |
51 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"sign"); | |
52 return; | |
53 } | |
54 IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify(); | |
55 if (!pNotify) { | |
56 return; | |
57 } | |
58 IXFA_Doc* hDoc = pNotify->GetHDOC(); | |
59 CXFA_NodeList* pNodeList = NULL; | |
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); | |
67 wsExpression = | |
68 CFX_WideString::FromUTF8(bsExpression, bsExpression.GetLength()); | |
69 } | |
70 if (iLength >= 3) { | |
71 CFX_ByteString bsXMLIdent = pArguments->GetUTF8String(2); | |
72 wsXMLIdent = CFX_WideString::FromUTF8(bsXMLIdent, bsXMLIdent.GetLength()); | |
73 } | |
74 FX_BOOL bSign = pNotify->GetDocProvider()->Sign(hDoc, pNodeList, wsExpression, | |
75 wsXMLIdent); | |
76 FXJSE_HVALUE hValue = pArguments->GetReturnValue(); | |
77 if (hValue) { | |
78 FXJSE_Value_SetBoolean(hValue, bSign); | |
79 } | |
80 } | |
81 void CScript_SignaturePseudoModel::Script_SignaturePseudoModel_Enumerate( | |
82 CFXJSE_Arguments* pArguments) { | |
83 int32_t iLength = pArguments->GetLength(); | |
84 if (iLength != 0) { | |
85 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"enumerate"); | |
86 return; | |
87 } | |
88 IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify(); | |
89 if (!pNotify) { | |
90 return; | |
91 } | |
92 IXFA_Doc* hDoc = pNotify->GetHDOC(); | |
93 CXFA_NodeList* pList = pNotify->GetDocProvider()->Enumerate(hDoc); | |
94 if (!pList) | |
95 return; | |
96 FXJSE_Value_Set(pArguments->GetReturnValue(), | |
97 m_pDocument->GetScriptContext()->GetJSValueFromMap(pList)); | |
98 } | |
99 void CScript_SignaturePseudoModel::Script_SignaturePseudoModel_Clear( | |
100 CFXJSE_Arguments* pArguments) { | |
101 int32_t iLength = pArguments->GetLength(); | |
102 if (iLength < 1 || iLength > 2) { | |
103 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"clear"); | |
104 return; | |
105 } | |
106 IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify(); | |
107 if (!pNotify) { | |
108 return; | |
109 } | |
110 IXFA_Doc* hDoc = pNotify->GetHDOC(); | |
111 CXFA_Node* pNode = NULL; | |
112 FX_BOOL bClear = TRUE; | |
113 if (iLength >= 1) { | |
114 pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); | |
115 } | |
116 if (iLength >= 2) { | |
117 bClear = pArguments->GetInt32(1) == 0 ? FALSE : TRUE; | |
118 } | |
119 FX_BOOL bFlag = pNotify->GetDocProvider()->Clear(hDoc, pNode, bClear); | |
120 FXJSE_HVALUE hValue = pArguments->GetReturnValue(); | |
121 if (hValue) { | |
122 FXJSE_Value_SetBoolean(hValue, bFlag); | |
123 } | |
124 } | |
OLD | NEW |