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 "xfa/fxfa/parser/xfa_script_imp.h" | 7 #include "xfa/fxfa/parser/xfa_script_imp.h" |
8 | 8 |
9 #include "core/fxcrt/include/fx_ext.h" | 9 #include "core/fxcrt/include/fx_ext.h" |
10 #include "xfa/fxfa/app/xfa_ffnotify.h" | 10 #include "xfa/fxfa/app/xfa_ffnotify.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(lpOrginalNode); | 117 CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(lpOrginalNode); |
118 CFX_WideString wsPropName = CFX_WideString::FromUTF8( | 118 CFX_WideString wsPropName = CFX_WideString::FromUTF8( |
119 (const FX_CHAR*)szPropName.raw_str(), szPropName.GetLength()); | 119 (const FX_CHAR*)szPropName.raw_str(), szPropName.GetLength()); |
120 uint32_t dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings | | 120 uint32_t dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings | |
121 XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | | 121 XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | |
122 XFA_RESOLVENODE_Attributes; | 122 XFA_RESOLVENODE_Attributes; |
123 CXFA_Node* pRefNode = ToNode(lpScriptContext->GetThisObject()); | 123 CXFA_Node* pRefNode = ToNode(lpScriptContext->GetThisObject()); |
124 if (lpOrginalNode->GetObjectType() == XFA_OBJECTTYPE_VariablesThis) { | 124 if (lpOrginalNode->GetObjectType() == XFA_OBJECTTYPE_VariablesThis) { |
125 pRefNode = ToNode(lpCurNode); | 125 pRefNode = ToNode(lpCurNode); |
126 } | 126 } |
127 if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName, hValue, dwFlag, | 127 if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsWideStringC(), |
128 TRUE)) { | 128 hValue, dwFlag, TRUE)) { |
129 return; | 129 return; |
130 } | 130 } |
131 if (lpOrginalNode->GetObjectType() == XFA_OBJECTTYPE_VariablesThis) { | 131 if (lpOrginalNode->GetObjectType() == XFA_OBJECTTYPE_VariablesThis) { |
132 if (FXJSE_Value_IsUndefined(hValue)) { | 132 if (FXJSE_Value_IsUndefined(hValue)) { |
133 FXJSE_Value_SetObjectOwnProp(hObject, szPropName, hValue); | 133 FXJSE_Value_SetObjectOwnProp(hObject, szPropName, hValue); |
134 return; | 134 return; |
135 } | 135 } |
136 } | 136 } |
137 CXFA_FFNotify* pNotify = pDoc->GetNotify(); | 137 CXFA_FFNotify* pNotify = pDoc->GetNotify(); |
138 if (!pNotify) { | 138 if (!pNotify) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 return; | 191 return; |
192 } | 192 } |
193 } | 193 } |
194 } | 194 } |
195 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | | 195 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | |
196 XFA_RESOLVENODE_Attributes; | 196 XFA_RESOLVENODE_Attributes; |
197 CXFA_Node* pRefNode = ToNode(lpScriptContext->GetThisObject()); | 197 CXFA_Node* pRefNode = ToNode(lpScriptContext->GetThisObject()); |
198 if (pOrginalObject->GetObjectType() == XFA_OBJECTTYPE_VariablesThis) { | 198 if (pOrginalObject->GetObjectType() == XFA_OBJECTTYPE_VariablesThis) { |
199 pRefNode = ToNode(lpCurNode); | 199 pRefNode = ToNode(lpCurNode); |
200 } | 200 } |
201 if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName, hValue, dwFlag, | 201 if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsWideStringC(), |
202 FALSE)) { | 202 hValue, dwFlag, FALSE)) { |
203 return; | 203 return; |
204 } | 204 } |
205 dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; | 205 dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; |
206 if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName, hValue, dwFlag, | 206 if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsWideStringC(), |
207 FALSE)) { | 207 hValue, dwFlag, FALSE)) { |
208 return; | 208 return; |
209 } | 209 } |
210 CXFA_Object* pScriptObject = | 210 CXFA_Object* pScriptObject = |
211 lpScriptContext->GetVariablesThis(pOrginalObject, TRUE); | 211 lpScriptContext->GetVariablesThis(pOrginalObject, TRUE); |
212 if (pScriptObject && | 212 if (pScriptObject && |
213 lpScriptContext->QueryVariableHValue(pScriptObject->AsNode(), szPropName, | 213 lpScriptContext->QueryVariableHValue(pScriptObject->AsNode(), szPropName, |
214 hValue, TRUE)) { | 214 hValue, TRUE)) { |
215 return; | 215 return; |
216 } | 216 } |
217 CXFA_FFNotify* pNotify = pDoc->GetNotify(); | 217 CXFA_FFNotify* pNotify = pDoc->GetNotify(); |
(...skipping 18 matching lines...) Expand all Loading... |
236 (CXFA_ScriptContext*)pOrginalObject->GetDocument()->GetScriptContext(); | 236 (CXFA_ScriptContext*)pOrginalObject->GetDocument()->GetScriptContext(); |
237 CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOrginalObject); | 237 CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOrginalObject); |
238 if (wsPropName == FX_WSTRC(L"xfa")) { | 238 if (wsPropName == FX_WSTRC(L"xfa")) { |
239 FXJSE_HVALUE pValue = lpScriptContext->GetJSValueFromMap( | 239 FXJSE_HVALUE pValue = lpScriptContext->GetJSValueFromMap( |
240 lpScriptContext->GetDocument()->GetRoot()); | 240 lpScriptContext->GetDocument()->GetRoot()); |
241 FXJSE_Value_Set(hValue, pValue); | 241 FXJSE_Value_Set(hValue, pValue); |
242 return; | 242 return; |
243 } | 243 } |
244 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | | 244 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | |
245 XFA_RESOLVENODE_Attributes; | 245 XFA_RESOLVENODE_Attributes; |
246 FX_BOOL bRet = lpScriptContext->QueryNodeByFlag(ToNode(pObject), wsPropName, | 246 FX_BOOL bRet = lpScriptContext->QueryNodeByFlag( |
247 hValue, dwFlag, FALSE); | 247 ToNode(pObject), wsPropName.AsWideStringC(), hValue, dwFlag, FALSE); |
248 if (bRet) { | 248 if (bRet) { |
249 return; | 249 return; |
250 } | 250 } |
251 if (pObject == lpScriptContext->GetThisObject() || | 251 if (pObject == lpScriptContext->GetThisObject() || |
252 (lpScriptContext->GetType() == XFA_SCRIPTLANGTYPE_Javascript && | 252 (lpScriptContext->GetType() == XFA_SCRIPTLANGTYPE_Javascript && |
253 !lpScriptContext->IsStrictScopeInJavaScript())) { | 253 !lpScriptContext->IsStrictScopeInJavaScript())) { |
254 dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; | 254 dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; |
255 bRet = lpScriptContext->QueryNodeByFlag(ToNode(pObject), wsPropName, hValue, | 255 bRet = lpScriptContext->QueryNodeByFlag( |
256 dwFlag, FALSE); | 256 ToNode(pObject), wsPropName.AsWideStringC(), hValue, dwFlag, FALSE); |
257 } | 257 } |
258 if (bRet) { | 258 if (bRet) { |
259 return; | 259 return; |
260 } | 260 } |
261 CXFA_Object* pScriptObject = | 261 CXFA_Object* pScriptObject = |
262 lpScriptContext->GetVariablesThis(pOrginalObject, TRUE); | 262 lpScriptContext->GetVariablesThis(pOrginalObject, TRUE); |
263 if (pScriptObject) { | 263 if (pScriptObject) { |
264 bRet = lpScriptContext->QueryVariableHValue(ToNode(pScriptObject), | 264 bRet = lpScriptContext->QueryVariableHValue(ToNode(pScriptObject), |
265 szPropName, hValue, TRUE); | 265 szPropName, hValue, TRUE); |
266 } | 266 } |
267 if (!bRet) { | 267 if (!bRet) { |
268 FXJSE_Value_SetUndefined(hValue); | 268 FXJSE_Value_SetUndefined(hValue); |
269 } | 269 } |
270 } | 270 } |
271 void CXFA_ScriptContext::NormalPropertySetter(FXJSE_HOBJECT hObject, | 271 void CXFA_ScriptContext::NormalPropertySetter(FXJSE_HOBJECT hObject, |
272 const CFX_ByteStringC& szPropName, | 272 const CFX_ByteStringC& szPropName, |
273 FXJSE_HVALUE hValue) { | 273 FXJSE_HVALUE hValue) { |
274 CXFA_Object* pOrginalObject = | 274 CXFA_Object* pOrginalObject = |
275 (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); | 275 (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); |
276 if (pOrginalObject == NULL) { | 276 if (pOrginalObject == NULL) { |
277 return; | 277 return; |
278 } | 278 } |
279 CXFA_ScriptContext* lpScriptContext = | 279 CXFA_ScriptContext* lpScriptContext = |
280 (CXFA_ScriptContext*)pOrginalObject->GetDocument()->GetScriptContext(); | 280 (CXFA_ScriptContext*)pOrginalObject->GetDocument()->GetScriptContext(); |
281 CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOrginalObject); | 281 CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOrginalObject); |
282 CFX_WideString wsPropName = CFX_WideString::FromUTF8( | 282 CFX_WideString wsPropName = CFX_WideString::FromUTF8( |
283 (const FX_CHAR*)szPropName.raw_str(), szPropName.GetLength()); | 283 (const FX_CHAR*)szPropName.raw_str(), szPropName.GetLength()); |
284 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = | 284 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = XFA_GetScriptAttributeByName( |
285 XFA_GetScriptAttributeByName(pObject->GetClassID(), wsPropName); | 285 pObject->GetClassID(), wsPropName.AsWideStringC()); |
286 if (lpAttributeInfo) { | 286 if (lpAttributeInfo) { |
287 (pObject->*(lpAttributeInfo->lpfnCallback))( | 287 (pObject->*(lpAttributeInfo->lpfnCallback))( |
288 hValue, TRUE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); | 288 hValue, TRUE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); |
289 } else { | 289 } else { |
290 if (pObject->IsNode()) { | 290 if (pObject->IsNode()) { |
291 if (wsPropName.GetAt(0) == '#') { | 291 if (wsPropName.GetAt(0) == '#') { |
292 wsPropName = wsPropName.Right(wsPropName.GetLength() - 1); | 292 wsPropName = wsPropName.Right(wsPropName.GetLength() - 1); |
293 } | 293 } |
294 CXFA_Node* pNode = ToNode(pObject); | 294 CXFA_Node* pNode = ToNode(pObject); |
295 CXFA_Node* pPropOrChild = NULL; | 295 CXFA_Node* pPropOrChild = NULL; |
296 const XFA_ELEMENTINFO* lpElementInfo = XFA_GetElementByName(wsPropName); | 296 const XFA_ELEMENTINFO* lpElementInfo = |
| 297 XFA_GetElementByName(wsPropName.AsWideStringC()); |
297 if (lpElementInfo) { | 298 if (lpElementInfo) { |
298 pPropOrChild = pNode->GetProperty(0, lpElementInfo->eName); | 299 pPropOrChild = pNode->GetProperty(0, lpElementInfo->eName); |
299 } else { | 300 } else { |
300 pPropOrChild = pNode->GetFirstChildByName(wsPropName); | 301 pPropOrChild = pNode->GetFirstChildByName(wsPropName.AsWideStringC()); |
301 } | 302 } |
302 if (pPropOrChild) { | 303 if (pPropOrChild) { |
303 CFX_WideString wsDefaultName = FX_WSTRC(L"{default}"); | 304 CFX_WideString wsDefaultName = FX_WSTRC(L"{default}"); |
304 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = | 305 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = |
305 XFA_GetScriptAttributeByName(pPropOrChild->GetClassID(), | 306 XFA_GetScriptAttributeByName(pPropOrChild->GetClassID(), |
306 wsDefaultName); | 307 wsDefaultName.AsWideStringC()); |
307 if (lpAttributeInfo) { | 308 if (lpAttributeInfo) { |
308 (pPropOrChild->*(lpAttributeInfo->lpfnCallback))( | 309 (pPropOrChild->*(lpAttributeInfo->lpfnCallback))( |
309 hValue, TRUE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); | 310 hValue, TRUE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); |
310 return; | 311 return; |
311 } | 312 } |
312 } | 313 } |
313 } | 314 } |
314 CXFA_Object* pScriptObject = | 315 CXFA_Object* pScriptObject = |
315 lpScriptContext->GetVariablesThis(pOrginalObject, TRUE); | 316 lpScriptContext->GetVariablesThis(pOrginalObject, TRUE); |
316 if (pScriptObject) { | 317 if (pScriptObject) { |
317 lpScriptContext->QueryVariableHValue(ToNode(pScriptObject), szPropName, | 318 lpScriptContext->QueryVariableHValue(ToNode(pScriptObject), szPropName, |
318 hValue, FALSE); | 319 hValue, FALSE); |
319 } | 320 } |
320 } | 321 } |
321 } | 322 } |
322 int32_t CXFA_ScriptContext::NormalPropTypeGetter( | 323 int32_t CXFA_ScriptContext::NormalPropTypeGetter( |
323 FXJSE_HOBJECT hObject, | 324 FXJSE_HOBJECT hObject, |
324 const CFX_ByteStringC& szPropName, | 325 const CFX_ByteStringC& szPropName, |
325 FX_BOOL bQueryIn) { | 326 FX_BOOL bQueryIn) { |
326 CXFA_Object* pObject = (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); | 327 CXFA_Object* pObject = (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); |
327 if (pObject == NULL) { | 328 if (pObject == NULL) { |
328 return FXJSE_ClassPropType_None; | 329 return FXJSE_ClassPropType_None; |
329 } | 330 } |
330 CXFA_ScriptContext* lpScriptContext = | 331 CXFA_ScriptContext* lpScriptContext = |
331 (CXFA_ScriptContext*)pObject->GetDocument()->GetScriptContext(); | 332 (CXFA_ScriptContext*)pObject->GetDocument()->GetScriptContext(); |
332 pObject = lpScriptContext->GetVariablesThis(pObject); | 333 pObject = lpScriptContext->GetVariablesThis(pObject); |
333 XFA_ELEMENT objElement = pObject->GetClassID(); | 334 XFA_ELEMENT objElement = pObject->GetClassID(); |
334 CFX_WideString wsPropName = CFX_WideString::FromUTF8( | 335 CFX_WideString wsPropName = CFX_WideString::FromUTF8( |
335 (const FX_CHAR*)szPropName.raw_str(), szPropName.GetLength()); | 336 (const FX_CHAR*)szPropName.raw_str(), szPropName.GetLength()); |
336 if (XFA_GetMethodByName(objElement, wsPropName)) { | 337 if (XFA_GetMethodByName(objElement, wsPropName.AsWideStringC())) { |
337 return FXJSE_ClassPropType_Method; | 338 return FXJSE_ClassPropType_Method; |
338 } | 339 } |
339 if (bQueryIn && !XFA_GetScriptAttributeByName(objElement, wsPropName)) { | 340 if (bQueryIn && |
| 341 !XFA_GetScriptAttributeByName(objElement, wsPropName.AsWideStringC())) { |
340 return FXJSE_ClassPropType_None; | 342 return FXJSE_ClassPropType_None; |
341 } | 343 } |
342 return FXJSE_ClassPropType_Property; | 344 return FXJSE_ClassPropType_Property; |
343 } | 345 } |
344 int32_t CXFA_ScriptContext::GlobalPropTypeGetter( | 346 int32_t CXFA_ScriptContext::GlobalPropTypeGetter( |
345 FXJSE_HOBJECT hObject, | 347 FXJSE_HOBJECT hObject, |
346 const CFX_ByteStringC& szPropName, | 348 const CFX_ByteStringC& szPropName, |
347 FX_BOOL bQueryIn) { | 349 FX_BOOL bQueryIn) { |
348 CXFA_Object* pObject = (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); | 350 CXFA_Object* pObject = (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); |
349 if (pObject == NULL) { | 351 if (pObject == NULL) { |
350 return FXJSE_ClassPropType_None; | 352 return FXJSE_ClassPropType_None; |
351 } | 353 } |
352 CXFA_ScriptContext* lpScriptContext = | 354 CXFA_ScriptContext* lpScriptContext = |
353 (CXFA_ScriptContext*)pObject->GetDocument()->GetScriptContext(); | 355 (CXFA_ScriptContext*)pObject->GetDocument()->GetScriptContext(); |
354 pObject = lpScriptContext->GetVariablesThis(pObject); | 356 pObject = lpScriptContext->GetVariablesThis(pObject); |
355 XFA_ELEMENT objElement = pObject->GetClassID(); | 357 XFA_ELEMENT objElement = pObject->GetClassID(); |
356 CFX_WideString wsPropName = CFX_WideString::FromUTF8( | 358 CFX_WideString wsPropName = CFX_WideString::FromUTF8( |
357 (const FX_CHAR*)szPropName.raw_str(), szPropName.GetLength()); | 359 (const FX_CHAR*)szPropName.raw_str(), szPropName.GetLength()); |
358 if (XFA_GetMethodByName(objElement, wsPropName)) { | 360 if (XFA_GetMethodByName(objElement, wsPropName.AsWideStringC())) { |
359 return FXJSE_ClassPropType_Method; | 361 return FXJSE_ClassPropType_Method; |
360 } | 362 } |
361 return FXJSE_ClassPropType_Property; | 363 return FXJSE_ClassPropType_Property; |
362 } | 364 } |
363 void CXFA_ScriptContext::NormalMethodCall(FXJSE_HOBJECT hThis, | 365 void CXFA_ScriptContext::NormalMethodCall(FXJSE_HOBJECT hThis, |
364 const CFX_ByteStringC& szFuncName, | 366 const CFX_ByteStringC& szFuncName, |
365 CFXJSE_Arguments& args) { | 367 CFXJSE_Arguments& args) { |
366 CXFA_Object* pObject = (CXFA_Object*)FXJSE_Value_ToObject(hThis, NULL); | 368 CXFA_Object* pObject = (CXFA_Object*)FXJSE_Value_ToObject(hThis, NULL); |
367 if (pObject == NULL) { | 369 if (pObject == NULL) { |
368 return; | 370 return; |
369 } | 371 } |
370 CXFA_ScriptContext* lpScriptContext = | 372 CXFA_ScriptContext* lpScriptContext = |
371 (CXFA_ScriptContext*)pObject->GetDocument()->GetScriptContext(); | 373 (CXFA_ScriptContext*)pObject->GetDocument()->GetScriptContext(); |
372 pObject = lpScriptContext->GetVariablesThis(pObject); | 374 pObject = lpScriptContext->GetVariablesThis(pObject); |
373 CFX_WideString wsFunName = CFX_WideString::FromUTF8( | 375 CFX_WideString wsFunName = CFX_WideString::FromUTF8( |
374 (const FX_CHAR*)szFuncName.raw_str(), szFuncName.GetLength()); | 376 (const FX_CHAR*)szFuncName.raw_str(), szFuncName.GetLength()); |
375 const XFA_METHODINFO* lpMethodInfo = | 377 const XFA_METHODINFO* lpMethodInfo = |
376 XFA_GetMethodByName(pObject->GetClassID(), wsFunName); | 378 XFA_GetMethodByName(pObject->GetClassID(), wsFunName.AsWideStringC()); |
377 if (NULL == lpMethodInfo) { | 379 if (NULL == lpMethodInfo) { |
378 return; | 380 return; |
379 } | 381 } |
380 (pObject->*(lpMethodInfo->lpfnCallback))(&args); | 382 (pObject->*(lpMethodInfo->lpfnCallback))(&args); |
381 } | 383 } |
382 FX_BOOL CXFA_ScriptContext::IsStrictScopeInJavaScript() { | 384 FX_BOOL CXFA_ScriptContext::IsStrictScopeInJavaScript() { |
383 return m_pDocument->HasFlag(XFA_DOCFLAG_StrictScoping); | 385 return m_pDocument->HasFlag(XFA_DOCFLAG_StrictScoping); |
384 } | 386 } |
385 XFA_SCRIPTLANGTYPE CXFA_ScriptContext::GetType() { | 387 XFA_SCRIPTLANGTYPE CXFA_ScriptContext::GetType() { |
386 return m_eScriptType; | 388 return m_eScriptType; |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 } | 773 } |
772 } | 774 } |
773 void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) { | 775 void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) { |
774 if (!m_pScriptNodeArray) { | 776 if (!m_pScriptNodeArray) { |
775 return; | 777 return; |
776 } | 778 } |
777 if (m_pScriptNodeArray->Find(pNode) == -1) { | 779 if (m_pScriptNodeArray->Find(pNode) == -1) { |
778 m_pScriptNodeArray->Add(pNode); | 780 m_pScriptNodeArray->Add(pNode); |
779 } | 781 } |
780 } | 782 } |
OLD | NEW |