Home | History | Annotate | Download | only in common
      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 #ifndef _FXFA_SCRIPT_H
      8 #define _FXFA_SCRIPT_H
      9 #define XFA_RESOLVENODE_Children 0x0001
     10 #define XFA_RESOLVENODE_Attributes 0x0004
     11 #define XFA_RESOLVENODE_Properties 0x0008
     12 #define XFA_RESOLVENODE_Siblings 0x0020
     13 #define XFA_RESOLVENODE_Parent 0x0040
     14 #define XFA_RESOLVENODE_AnyChild 0x0080
     15 #define XFA_RESOLVENODE_ALL 0x0100
     16 #define XFA_RESOLVENODE_CreateNode 0x0400
     17 #define XFA_RESOLVENODE_Bind 0x0800
     18 #define XFA_RESOLVENODE_BindNew 0x1000
     19 enum XFA_SCRIPTLANGTYPE {
     20   XFA_SCRIPTLANGTYPE_Formcalc = XFA_SCRIPTTYPE_Formcalc,
     21   XFA_SCRIPTLANGTYPE_Javascript = XFA_SCRIPTTYPE_Javascript,
     22   XFA_SCRIPTLANGTYPE_Unkown = XFA_SCRIPTTYPE_Unkown,
     23 };
     24 enum XFA_RESOVENODE_RSTYPE {
     25   XFA_RESOVENODE_RSTYPE_Nodes,
     26   XFA_RESOVENODE_RSTYPE_Attribute,
     27   XFA_RESOLVENODE_RSTYPE_CreateNodeOne,
     28   XFA_RESOLVENODE_RSTYPE_CreateNodeAll,
     29   XFA_RESOLVENODE_RSTYPE_CreateNodeMidAll,
     30   XFA_RESOVENODE_RSTYPE_ExistNodes,
     31 };
     32 class CXFA_HVALUEArray : public CFX_ArrayTemplate<FXJSE_HVALUE> {
     33  public:
     34   CXFA_HVALUEArray(FXJSE_HRUNTIME hRunTime) : m_hRunTime(hRunTime){};
     35   ~CXFA_HVALUEArray() {
     36     for (int32_t i = 0; i < GetSize(); i++) {
     37       FXJSE_Value_Release(GetAt(i));
     38     }
     39   }
     40   void GetAttributeObject(CXFA_ObjArray& objArray) {
     41     for (int32_t i = 0; i < GetSize(); i++) {
     42       CXFA_Object* pObject = (CXFA_Object*)FXJSE_Value_ToObject(GetAt(i), NULL);
     43       objArray.Add(pObject);
     44     }
     45   }
     46   FXJSE_HRUNTIME m_hRunTime;
     47 };
     48 typedef struct _XFA_RESOLVENODE_RS {
     49   _XFA_RESOLVENODE_RS()
     50       : dwFlags(XFA_RESOVENODE_RSTYPE_Nodes), pScriptAttribute(NULL) {}
     51   ~_XFA_RESOLVENODE_RS() { nodes.RemoveAll(); }
     52   int32_t GetAttributeResult(CXFA_HVALUEArray& hValueArray) const {
     53     if (pScriptAttribute && pScriptAttribute->eValueType == XFA_SCRIPT_Object) {
     54       FXJSE_HRUNTIME hRunTime = hValueArray.m_hRunTime;
     55       for (int32_t i = 0; i < nodes.GetSize(); i++) {
     56         FXJSE_HVALUE hValue = FXJSE_Value_Create(hRunTime);
     57         (nodes[i]->*(pScriptAttribute->lpfnCallback))(
     58             hValue, FALSE, (XFA_ATTRIBUTE)pScriptAttribute->eAttribute);
     59         hValueArray.Add(hValue);
     60       }
     61     }
     62     return hValueArray.GetSize();
     63   }
     64   CXFA_ObjArray nodes;
     65   XFA_RESOVENODE_RSTYPE dwFlags;
     66   XFA_LPCSCRIPTATTRIBUTEINFO pScriptAttribute;
     67 } XFA_RESOLVENODE_RS, *XFA_LPRESOLVENODE_RS;
     68 typedef struct _XFA_JSBUILTININFO {
     69   uint32_t uUnicodeHash;
     70   const FX_CHAR* pName;
     71 } XFA_JSBUILTININFO, *XFA_LPJSBUILTININFO;
     72 typedef XFA_JSBUILTININFO const* XFA_LPCJSBUILTININFO;
     73 XFA_LPCJSBUILTININFO XFA_GetJSBuiltinByHash(uint32_t uHashCode);
     74 class IXFA_ScriptContext {
     75  public:
     76   virtual ~IXFA_ScriptContext() {}
     77   virtual void Release() = 0;
     78   virtual void Initialize(FXJSE_HRUNTIME hRuntime) = 0;
     79 
     80   virtual void SetEventParam(CXFA_EventParam* pEventParam) = 0;
     81   virtual CXFA_EventParam* GetEventParam() = 0;
     82   virtual FX_BOOL RunScript(XFA_SCRIPTLANGTYPE eScriptType,
     83                             const CFX_WideStringC& wsScript,
     84                             FXJSE_HVALUE hRetValue,
     85                             CXFA_Object* pThisObject = NULL) = 0;
     86   virtual int32_t ResolveObjects(CXFA_Object* refNode,
     87                                  const CFX_WideStringC& wsExpression,
     88                                  XFA_RESOLVENODE_RS& resolveNodeRS,
     89                                  FX_DWORD dwStyles = XFA_RESOLVENODE_Children,
     90                                  CXFA_Node* bindNode = NULL) = 0;
     91   virtual FXJSE_HVALUE GetJSValueFromMap(CXFA_Object* pObject) = 0;
     92   virtual void CacheList(CXFA_NodeList* pList) = 0;
     93   virtual CXFA_Object* GetThisObject() const = 0;
     94   virtual FXJSE_HRUNTIME GetRuntime() const = 0;
     95   virtual int32_t GetIndexByName(CXFA_Node* refNode) = 0;
     96   virtual int32_t GetIndexByClassName(CXFA_Node* refNode) = 0;
     97   virtual void GetSomExpression(CXFA_Node* refNode,
     98                                 CFX_WideString& wsExpression) = 0;
     99 
    100   virtual void SetNodesOfRunScript(CXFA_NodeArray* pArray) = 0;
    101   virtual void AddNodesOfRunScript(const CXFA_NodeArray& nodes) = 0;
    102   virtual void AddNodesOfRunScript(CXFA_Node* pNode) = 0;
    103   virtual FXJSE_HCLASS GetJseNormalClass() = 0;
    104   virtual XFA_SCRIPTLANGTYPE GetType() = 0;
    105   virtual void AddJSBuiltinObject(XFA_LPCJSBUILTININFO pBuitinObject) = 0;
    106   virtual void SetRunAtType(XFA_ATTRIBUTEENUM eRunAt) = 0;
    107   virtual FX_BOOL IsRunAtClient() = 0;
    108 };
    109 IXFA_ScriptContext* XFA_ScriptContext_Create(CXFA_Document* pDocument);
    110 #endif
    111