Home | History | Annotate | Download | only in parser
      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/foxitlib.h"
      8 #include "xfa/src/fxfa/src/common/xfa_utils.h"
      9 #include "xfa/src/fxfa/src/common/xfa_object.h"
     10 #include "xfa/src/fxfa/src/common/xfa_document.h"
     11 #include "xfa/src/fxfa/src/common/xfa_parser.h"
     12 #include "xfa/src/fxfa/src/common/xfa_script.h"
     13 #include "xfa/src/fxfa/src/common/xfa_docdata.h"
     14 #include "xfa/src/fxfa/src/common/xfa_doclayout.h"
     15 #include "xfa/src/fxfa/src/common/xfa_localemgr.h"
     16 #include "xfa/src/fxfa/src/common/xfa_fm2jsapi.h"
     17 #include "xfa_script_hostpseudomodel.h"
     18 CScript_HostPseudoModel::CScript_HostPseudoModel(CXFA_Document* pDocument)
     19     : CXFA_OrdinaryObject(pDocument, XFA_ELEMENT_HostPseudoModel) {
     20   m_uScriptHash = XFA_HASHCODE_Host;
     21 }
     22 CScript_HostPseudoModel::~CScript_HostPseudoModel() {}
     23 void CScript_HostPseudoModel::Script_HostPseudoModel_LoadString(
     24     FXJSE_HVALUE hValue,
     25     IXFA_Notify* pNotify,
     26     FX_DWORD dwFlag) {
     27   CFX_WideString wsValue;
     28   pNotify->GetAppProvider()->LoadString(dwFlag, wsValue);
     29   FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsValue));
     30 }
     31 void CScript_HostPseudoModel::Script_HostPseudoModel_AppType(
     32     FXJSE_HVALUE hValue,
     33     FX_BOOL bSetting,
     34     XFA_ATTRIBUTE eAttribute) {
     35   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
     36   if (!pNotify) {
     37     return;
     38   }
     39   if (bSetting) {
     40     ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);
     41     return;
     42   }
     43   CFX_WideString wsAppType;
     44   pNotify->GetAppProvider()->GetAppType(wsAppType);
     45   FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsAppType));
     46 }
     47 void CScript_HostPseudoModel::Script_HostPseudoModel_FoxitAppType(
     48     FXJSE_HVALUE hValue,
     49     FX_BOOL bSetting,
     50     XFA_ATTRIBUTE eAttribute) {
     51   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
     52   if (!pNotify) {
     53     return;
     54   }
     55   if (bSetting) {
     56     ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);
     57     return;
     58   }
     59   CFX_WideString wsAppType;
     60   pNotify->GetAppProvider()->GetFoxitAppType(wsAppType);
     61   FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsAppType));
     62 }
     63 void CScript_HostPseudoModel::Script_HostPseudoModel_CalculationsEnabled(
     64     FXJSE_HVALUE hValue,
     65     FX_BOOL bSetting,
     66     XFA_ATTRIBUTE eAttribute) {
     67   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
     68   if (!pNotify) {
     69     return;
     70   }
     71   IXFA_Doc* hDoc = pNotify->GetHDOC();
     72   if (bSetting) {
     73     pNotify->GetDocProvider()->SetCalculationsEnabled(
     74         hDoc, FXJSE_Value_ToBoolean(hValue));
     75     return;
     76   }
     77   FX_BOOL bEnabled = pNotify->GetDocProvider()->IsCalculationsEnabled(hDoc);
     78   FXJSE_Value_SetBoolean(hValue, bEnabled);
     79 }
     80 void CScript_HostPseudoModel::Script_HostPseudoModel_CurrentPage(
     81     FXJSE_HVALUE hValue,
     82     FX_BOOL bSetting,
     83     XFA_ATTRIBUTE eAttribute) {
     84   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
     85   if (!pNotify) {
     86     return;
     87   }
     88   IXFA_Doc* hDoc = pNotify->GetHDOC();
     89   if (bSetting) {
     90     pNotify->GetDocProvider()->SetCurrentPage(hDoc,
     91                                               FXJSE_Value_ToInteger(hValue));
     92     return;
     93   }
     94   int32_t iCurrentPage = pNotify->GetDocProvider()->GetCurrentPage(hDoc);
     95   FXJSE_Value_SetInteger(hValue, iCurrentPage);
     96 }
     97 void CScript_HostPseudoModel::Script_HostPseudoModel_Language(
     98     FXJSE_HVALUE hValue,
     99     FX_BOOL bSetting,
    100     XFA_ATTRIBUTE eAttribute) {
    101   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    102   if (!pNotify) {
    103     return;
    104   }
    105   if (bSetting) {
    106     ThrowScriptErrorMessage(XFA_IDS_UNABLE_SET_LANGUAGE);
    107     return;
    108   }
    109   CFX_WideString wsLanguage;
    110   pNotify->GetAppProvider()->GetLanguage(wsLanguage);
    111   FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsLanguage));
    112 }
    113 void CScript_HostPseudoModel::Script_HostPseudoModel_NumPages(
    114     FXJSE_HVALUE hValue,
    115     FX_BOOL bSetting,
    116     XFA_ATTRIBUTE eAttribute) {
    117   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    118   if (!pNotify) {
    119     return;
    120   }
    121   IXFA_Doc* hDoc = pNotify->GetHDOC();
    122   if (bSetting) {
    123     ThrowScriptErrorMessage(XFA_IDS_UNABLE_SET_NUMPAGES);
    124     return;
    125   }
    126   int32_t iNumPages = pNotify->GetDocProvider()->CountPages(hDoc);
    127   FXJSE_Value_SetInteger(hValue, iNumPages);
    128 }
    129 void CScript_HostPseudoModel::Script_HostPseudoModel_Platform(
    130     FXJSE_HVALUE hValue,
    131     FX_BOOL bSetting,
    132     XFA_ATTRIBUTE eAttribute) {
    133   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    134   if (!pNotify) {
    135     return;
    136   }
    137   if (bSetting) {
    138     ThrowScriptErrorMessage(XFA_IDS_UNABLE_SET_PLATFORM);
    139     return;
    140   }
    141   CFX_WideString wsPlatform;
    142   pNotify->GetAppProvider()->GetPlatform(wsPlatform);
    143   FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsPlatform));
    144 }
    145 void CScript_HostPseudoModel::Script_HostPseudoModel_Title(
    146     FXJSE_HVALUE hValue,
    147     FX_BOOL bSetting,
    148     XFA_ATTRIBUTE eAttribute) {
    149   if (!m_pDocument->GetScriptContext()->IsRunAtClient()) {
    150     return;
    151   }
    152   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    153   if (!pNotify) {
    154     return;
    155   }
    156   IXFA_Doc* hDoc = pNotify->GetHDOC();
    157   if (bSetting) {
    158     CFX_ByteString bsValue;
    159     FXJSE_Value_ToUTF8String(hValue, bsValue);
    160     pNotify->GetDocProvider()->SetTitle(
    161         hDoc, CFX_WideString::FromUTF8(bsValue, bsValue.GetLength()));
    162     return;
    163   }
    164   CFX_WideString wsTitle;
    165   pNotify->GetDocProvider()->GetTitle(hDoc, wsTitle);
    166   FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsTitle));
    167 }
    168 void CScript_HostPseudoModel::Script_HostPseudoModel_ValidationsEnabled(
    169     FXJSE_HVALUE hValue,
    170     FX_BOOL bSetting,
    171     XFA_ATTRIBUTE eAttribute) {
    172   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    173   if (!pNotify) {
    174     return;
    175   }
    176   IXFA_Doc* hDoc = pNotify->GetHDOC();
    177   if (bSetting) {
    178     pNotify->GetDocProvider()->SetValidationsEnabled(
    179         hDoc, FXJSE_Value_ToBoolean(hValue));
    180     return;
    181   }
    182   FX_BOOL bEnabled = pNotify->GetDocProvider()->IsValidationsEnabled(hDoc);
    183   FXJSE_Value_SetBoolean(hValue, bEnabled);
    184 }
    185 void CScript_HostPseudoModel::Script_HostPseudoModel_Variation(
    186     FXJSE_HVALUE hValue,
    187     FX_BOOL bSetting,
    188     XFA_ATTRIBUTE eAttribute) {
    189   if (!m_pDocument->GetScriptContext()->IsRunAtClient()) {
    190     return;
    191   }
    192   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    193   if (!pNotify) {
    194     return;
    195   }
    196   if (bSetting) {
    197     ThrowScriptErrorMessage(XFA_IDS_UNABLE_SET_VARIATION);
    198     return;
    199   }
    200   CFX_WideString wsVariation;
    201   pNotify->GetAppProvider()->GetVariation(wsVariation);
    202   FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsVariation));
    203 }
    204 void CScript_HostPseudoModel::Script_HostPseudoModel_Version(
    205     FXJSE_HVALUE hValue,
    206     FX_BOOL bSetting,
    207     XFA_ATTRIBUTE eAttribute) {
    208   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    209   if (!pNotify) {
    210     return;
    211   }
    212   if (bSetting) {
    213     ThrowScriptErrorMessage(XFA_IDS_UNABLE_SET_VERSION);
    214     return;
    215   }
    216   CFX_WideString wsVersion;
    217   pNotify->GetAppProvider()->GetVersion(wsVersion);
    218   FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsVersion));
    219 }
    220 void CScript_HostPseudoModel::Script_HostPseudoModel_FoxitVersion(
    221     FXJSE_HVALUE hValue,
    222     FX_BOOL bSetting,
    223     XFA_ATTRIBUTE eAttribute) {
    224   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    225   if (!pNotify) {
    226     return;
    227   }
    228   if (bSetting) {
    229     ThrowScriptErrorMessage(XFA_IDS_UNABLE_SET_VERSION);
    230     return;
    231   }
    232   CFX_WideString wsVersion;
    233   pNotify->GetAppProvider()->GetFoxitVersion(wsVersion);
    234   FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsVersion));
    235 }
    236 void CScript_HostPseudoModel::Script_HostPseudoModel_Name(
    237     FXJSE_HVALUE hValue,
    238     FX_BOOL bSetting,
    239     XFA_ATTRIBUTE eAttribute) {
    240   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    241   if (!pNotify) {
    242     return;
    243   }
    244   if (bSetting) {
    245     ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);
    246     return;
    247   }
    248   CFX_WideString wsAppName;
    249   pNotify->GetAppProvider()->GetAppName(wsAppName);
    250   FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsAppName));
    251 }
    252 void CScript_HostPseudoModel::Script_HostPseudoModel_FoxitName(
    253     FXJSE_HVALUE hValue,
    254     FX_BOOL bSetting,
    255     XFA_ATTRIBUTE eAttribute) {
    256   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    257   if (!pNotify) {
    258     return;
    259   }
    260   if (bSetting) {
    261     ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);
    262     return;
    263   }
    264   CFX_WideString wsFoxitAppName;
    265   pNotify->GetAppProvider()->GetFoxitAppName(wsFoxitAppName);
    266   FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsFoxitAppName));
    267 }
    268 void CScript_HostPseudoModel::Script_HostPseudoModel_GotoURL(
    269     CFXJSE_Arguments* pArguments) {
    270   if (!m_pDocument->GetScriptContext()->IsRunAtClient()) {
    271     return;
    272   }
    273   int32_t iLength = pArguments->GetLength();
    274   if (iLength != 1) {
    275     ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"gotoURL");
    276     return;
    277   }
    278   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    279   if (!pNotify) {
    280     return;
    281   }
    282   IXFA_Doc* hDoc = pNotify->GetHDOC();
    283   CFX_WideString wsURL;
    284   if (iLength >= 1) {
    285     CFX_ByteString bsURL = pArguments->GetUTF8String(0);
    286     wsURL = CFX_WideString::FromUTF8(bsURL, bsURL.GetLength());
    287   }
    288   pNotify->GetDocProvider()->GotoURL(hDoc, wsURL);
    289 }
    290 void CScript_HostPseudoModel::Script_HostPseudoModel_OpenList(
    291     CFXJSE_Arguments* pArguments) {
    292   if (!m_pDocument->GetScriptContext()->IsRunAtClient()) {
    293     return;
    294   }
    295   int32_t iLength = pArguments->GetLength();
    296   if (iLength != 1) {
    297     ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"openList");
    298     return;
    299   }
    300   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    301   if (!pNotify) {
    302     return;
    303   }
    304   CXFA_Node* pNode = NULL;
    305   if (iLength >= 1) {
    306     FXJSE_HVALUE hValue = pArguments->GetValue(0);
    307     if (FXJSE_Value_IsObject(hValue)) {
    308       pNode = (CXFA_Node*)FXJSE_Value_ToObject(hValue, NULL);
    309     } else if (FXJSE_Value_IsUTF8String(hValue)) {
    310       CFX_ByteString bsString;
    311       FXJSE_Value_ToUTF8String(hValue, bsString);
    312       CFX_WideString wsExpression =
    313           CFX_WideString::FromUTF8(bsString, bsString.GetLength());
    314       IXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
    315       if (!pScriptContext) {
    316         FXJSE_Value_Release(hValue);
    317         return;
    318       }
    319       CXFA_Object* pObject = pScriptContext->GetThisObject();
    320       if (!pObject) {
    321         FXJSE_Value_Release(hValue);
    322         return;
    323       }
    324       FX_DWORD dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Parent |
    325                         XFA_RESOLVENODE_Siblings;
    326       XFA_RESOLVENODE_RS resoveNodeRS;
    327       int32_t iRet = pScriptContext->ResolveObjects(pObject, wsExpression,
    328                                                     resoveNodeRS, dwFlag);
    329       if (iRet < 1 || !resoveNodeRS.nodes[0]->IsNode()) {
    330         FXJSE_Value_Release(hValue);
    331         return;
    332       }
    333       pNode = (CXFA_Node*)resoveNodeRS.nodes[0];
    334     }
    335     FXJSE_Value_Release(hValue);
    336   }
    337   IXFA_DocLayout* pDocLayout = m_pDocument->GetDocLayout();
    338   if (!pDocLayout) {
    339     return;
    340   }
    341   IXFA_Widget* hWidget = pNotify->GetHWidget(pDocLayout->GetLayoutItem(pNode));
    342   if (!hWidget) {
    343     return;
    344   }
    345   pNotify->GetDocProvider()->SetFocusWidget(pNotify->GetHDOC(), hWidget);
    346   pNotify->OpenDropDownList(hWidget);
    347 }
    348 void CScript_HostPseudoModel::Script_HostPseudoModel_Response(
    349     CFXJSE_Arguments* pArguments) {
    350   int32_t iLength = pArguments->GetLength();
    351   if (iLength < 1 || iLength > 4) {
    352     ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"response");
    353     return;
    354   }
    355   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    356   if (!pNotify) {
    357     return;
    358   }
    359   CFX_WideString wsQuestion;
    360   CFX_WideString wsTitle;
    361   CFX_WideString wsDefaultAnswer;
    362   FX_BOOL bMark = FALSE;
    363   if (iLength >= 1) {
    364     CFX_ByteString bsQuestion = pArguments->GetUTF8String(0);
    365     wsQuestion = CFX_WideString::FromUTF8(bsQuestion, bsQuestion.GetLength());
    366   }
    367   if (iLength >= 2) {
    368     CFX_ByteString bsTitle = pArguments->GetUTF8String(1);
    369     wsTitle = CFX_WideString::FromUTF8(bsTitle, bsTitle.GetLength());
    370   }
    371   if (iLength >= 3) {
    372     CFX_ByteString bsDefaultAnswer = pArguments->GetUTF8String(2);
    373     wsDefaultAnswer =
    374         CFX_WideString::FromUTF8(bsDefaultAnswer, bsDefaultAnswer.GetLength());
    375   }
    376   if (iLength >= 4) {
    377     bMark = pArguments->GetInt32(3) == 0 ? FALSE : TRUE;
    378   }
    379   CFX_WideString wsAnswer;
    380   pNotify->GetAppProvider()->Response(wsAnswer, wsQuestion, wsTitle,
    381                                       wsDefaultAnswer, bMark);
    382   FXJSE_HVALUE hValue = pArguments->GetReturnValue();
    383   if (hValue) {
    384     FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsAnswer));
    385   }
    386 }
    387 void CScript_HostPseudoModel::Script_HostPseudoModel_DocumentInBatch(
    388     CFXJSE_Arguments* pArguments) {
    389   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    390   if (!pNotify) {
    391     return;
    392   }
    393   int32_t iCur = pNotify->GetAppProvider()->GetCurDocumentInBatch();
    394   FXJSE_HVALUE hValue = pArguments->GetReturnValue();
    395   if (hValue) {
    396     FXJSE_Value_SetInteger(hValue, iCur);
    397   }
    398 }
    399 static int32_t XFA_FilterName(const CFX_WideStringC& wsExpression,
    400                               int32_t nStart,
    401                               CFX_WideString& wsFilter) {
    402   FXSYS_assert(nStart > -1);
    403   int32_t iLength = wsExpression.GetLength();
    404   if (nStart >= iLength) {
    405     return iLength;
    406   }
    407   FX_WCHAR* pBuf = wsFilter.GetBuffer(iLength - nStart);
    408   int32_t nCount = 0;
    409   const FX_WCHAR* pSrc = wsExpression.GetPtr();
    410   FX_WCHAR wCur;
    411   while (nStart < iLength) {
    412     wCur = pSrc[nStart++];
    413     if (wCur == ',') {
    414       break;
    415     }
    416     pBuf[nCount++] = wCur;
    417   }
    418   wsFilter.ReleaseBuffer(nCount);
    419   wsFilter.TrimLeft();
    420   wsFilter.TrimRight();
    421   return nStart;
    422 }
    423 void CScript_HostPseudoModel::Script_HostPseudoModel_ResetData(
    424     CFXJSE_Arguments* pArguments) {
    425   int32_t iLength = pArguments->GetLength();
    426   if (iLength < 0 || iLength > 1) {
    427     ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resetData");
    428     return;
    429   }
    430   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    431   if (!pNotify) {
    432     return;
    433   }
    434   CFX_WideString wsExpression;
    435   if (iLength >= 1) {
    436     CFX_ByteString bsExpression = pArguments->GetUTF8String(0);
    437     wsExpression =
    438         CFX_WideString::FromUTF8(bsExpression, bsExpression.GetLength());
    439   }
    440   if (wsExpression.IsEmpty()) {
    441     pNotify->ResetData();
    442     return;
    443   }
    444   int32_t iStart = 0;
    445   CFX_WideString wsName;
    446   CXFA_Node* pNode = NULL;
    447   int32_t iExpLength = wsExpression.GetLength();
    448   while (iStart < iExpLength) {
    449     iStart = XFA_FilterName(wsExpression, iStart, wsName);
    450     IXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
    451     if (!pScriptContext) {
    452       return;
    453     }
    454     CXFA_Object* pObject = pScriptContext->GetThisObject();
    455     if (!pObject) {
    456       return;
    457     }
    458     FX_DWORD dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Parent |
    459                       XFA_RESOLVENODE_Siblings;
    460     XFA_RESOLVENODE_RS resoveNodeRS;
    461     int32_t iRet =
    462         pScriptContext->ResolveObjects(pObject, wsName, resoveNodeRS, dwFlag);
    463     if (iRet < 1 || !resoveNodeRS.nodes[0]->IsNode()) {
    464       continue;
    465     }
    466     pNode = (CXFA_Node*)resoveNodeRS.nodes[0];
    467     pNotify->ResetData(pNode->GetWidgetData());
    468   }
    469   if (!pNode) {
    470     pNotify->ResetData();
    471   }
    472 }
    473 void CScript_HostPseudoModel::Script_HostPseudoModel_Beep(
    474     CFXJSE_Arguments* pArguments) {
    475   if (!m_pDocument->GetScriptContext()->IsRunAtClient()) {
    476     return;
    477   }
    478   int32_t iLength = pArguments->GetLength();
    479   if (iLength < 0 || iLength > 1) {
    480     ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"beep");
    481     return;
    482   }
    483   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    484   if (!pNotify) {
    485     return;
    486   }
    487   FX_DWORD dwType = 4;
    488   if (iLength >= 1) {
    489     dwType = pArguments->GetInt32(0);
    490   }
    491   pNotify->GetAppProvider()->Beep(dwType);
    492 }
    493 void CScript_HostPseudoModel::Script_HostPseudoModel_SetFocus(
    494     CFXJSE_Arguments* pArguments) {
    495   if (!m_pDocument->GetScriptContext()->IsRunAtClient()) {
    496     return;
    497   }
    498   int32_t iLength = pArguments->GetLength();
    499   if (iLength != 1) {
    500     ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setFocus");
    501     return;
    502   }
    503   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    504   if (!pNotify) {
    505     return;
    506   }
    507   CXFA_Node* pNode = NULL;
    508   if (iLength >= 1) {
    509     FXJSE_HVALUE hValue = pArguments->GetValue(0);
    510     if (FXJSE_Value_IsObject(hValue)) {
    511       pNode = (CXFA_Node*)FXJSE_Value_ToObject(hValue, NULL);
    512     } else if (FXJSE_Value_IsUTF8String(hValue)) {
    513       CFX_ByteString bsString;
    514       FXJSE_Value_ToUTF8String(hValue, bsString);
    515       CFX_WideString wsExpression =
    516           CFX_WideString::FromUTF8(bsString, bsString.GetLength());
    517       IXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
    518       if (!pScriptContext) {
    519         FXJSE_Value_Release(hValue);
    520         return;
    521       }
    522       CXFA_Object* pObject = pScriptContext->GetThisObject();
    523       if (!pObject) {
    524         FXJSE_Value_Release(hValue);
    525         return;
    526       }
    527       FX_DWORD dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Parent |
    528                         XFA_RESOLVENODE_Siblings;
    529       XFA_RESOLVENODE_RS resoveNodeRS;
    530       int32_t iRet = pScriptContext->ResolveObjects(pObject, wsExpression,
    531                                                     resoveNodeRS, dwFlag);
    532       if (iRet < 1 || !resoveNodeRS.nodes[0]->IsNode()) {
    533         FXJSE_Value_Release(hValue);
    534         return;
    535       }
    536       pNode = (CXFA_Node*)resoveNodeRS.nodes[0];
    537     }
    538     FXJSE_Value_Release(hValue);
    539   }
    540   pNotify->SetFocusWidgetNode(pNode);
    541 }
    542 void CScript_HostPseudoModel::Script_HostPseudoModel_GetFocus(
    543     CFXJSE_Arguments* pArguments) {
    544   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    545   if (!pNotify) {
    546     return;
    547   }
    548   CXFA_Node* pNode = pNotify->GetFocusWidgetNode();
    549   if (!pNode) {
    550     return;
    551   }
    552   FXJSE_Value_Set(pArguments->GetReturnValue(),
    553                   m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode));
    554 }
    555 void CScript_HostPseudoModel::Script_HostPseudoModel_MessageBox(
    556     CFXJSE_Arguments* pArguments) {
    557   if (!m_pDocument->GetScriptContext()->IsRunAtClient()) {
    558     return;
    559   }
    560   int32_t iLength = pArguments->GetLength();
    561   if (iLength < 1 || iLength > 4) {
    562     ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"messageBox");
    563     return;
    564   }
    565   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    566   if (!pNotify) {
    567     return;
    568   }
    569   CFX_WideString wsMessage;
    570   CFX_WideString bsTitle;
    571   FX_DWORD dwMessageType = XFA_MBICON_Error;
    572   FX_DWORD dwButtonType = XFA_MB_OK;
    573   if (iLength >= 1) {
    574     if (!Script_HostPseudoModel_ValidateArgsForMsg(pArguments, 0, wsMessage)) {
    575       return;
    576     }
    577   }
    578   if (iLength >= 2) {
    579     if (!Script_HostPseudoModel_ValidateArgsForMsg(pArguments, 1, bsTitle)) {
    580       return;
    581     }
    582   }
    583   if (iLength >= 3) {
    584     dwMessageType = pArguments->GetInt32(2);
    585     if (dwMessageType > XFA_MBICON_Status) {
    586       dwMessageType = XFA_MBICON_Error;
    587     }
    588   }
    589   if (iLength >= 4) {
    590     dwButtonType = pArguments->GetInt32(3);
    591     if (dwButtonType > XFA_MB_YesNoCancel) {
    592       dwButtonType = XFA_MB_OK;
    593     }
    594   }
    595   int32_t iValue = pNotify->GetAppProvider()->MsgBox(
    596       wsMessage, bsTitle, dwMessageType, dwButtonType);
    597   FXJSE_HVALUE hValue = pArguments->GetReturnValue();
    598   if (hValue) {
    599     FXJSE_Value_SetInteger(hValue, iValue);
    600   }
    601 }
    602 FX_BOOL CScript_HostPseudoModel::Script_HostPseudoModel_ValidateArgsForMsg(
    603     CFXJSE_Arguments* pArguments,
    604     int32_t iArgIndex,
    605     CFX_WideString& wsValue) {
    606   if (pArguments == NULL || iArgIndex < 0) {
    607     return FALSE;
    608   }
    609   FX_BOOL bIsJsType = FALSE;
    610   if (m_pDocument->GetScriptContext()->GetType() ==
    611       XFA_SCRIPTLANGTYPE_Javascript) {
    612     bIsJsType = TRUE;
    613   }
    614   FXJSE_HVALUE hValueArg = pArguments->GetValue(iArgIndex);
    615   if (!FXJSE_Value_IsUTF8String(hValueArg) && bIsJsType) {
    616     ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH);
    617     FXJSE_Value_Release(hValueArg);
    618     return FALSE;
    619   }
    620   if (FXJSE_Value_IsNull(hValueArg)) {
    621     wsValue = FX_WSTRC(L"");
    622   } else {
    623     CFX_ByteString byMessage;
    624     FXJSE_Value_ToUTF8String(hValueArg, byMessage);
    625     wsValue = CFX_WideString::FromUTF8(byMessage, byMessage.GetLength());
    626   }
    627   FXJSE_Value_Release(hValueArg);
    628   return TRUE;
    629 }
    630 void CScript_HostPseudoModel::Script_HostPseudoModel_DocumentCountInBatch(
    631     CFXJSE_Arguments* pArguments) {
    632   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    633   if (!pNotify) {
    634     return;
    635   }
    636   int32_t iValue = pNotify->GetAppProvider()->GetDocumentCountInBatch();
    637   FXJSE_HVALUE hValue = pArguments->GetReturnValue();
    638   if (hValue) {
    639     FXJSE_Value_SetInteger(hValue, iValue);
    640   }
    641 }
    642 void CScript_HostPseudoModel::Script_HostPseudoModel_Print(
    643     CFXJSE_Arguments* pArguments) {
    644   if (!m_pDocument->GetScriptContext()->IsRunAtClient()) {
    645     return;
    646   }
    647   int32_t iLength = pArguments->GetLength();
    648   if (iLength != 8) {
    649     ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"print");
    650     return;
    651   }
    652   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    653   if (!pNotify) {
    654     return;
    655   }
    656   IXFA_Doc* hDoc = pNotify->GetHDOC();
    657   FX_DWORD dwOptions = 0;
    658   FX_BOOL bShowDialog = TRUE;
    659   if (iLength >= 1) {
    660     bShowDialog = pArguments->GetInt32(0) == 0 ? FALSE : TRUE;
    661   }
    662   if (bShowDialog) {
    663     dwOptions |= XFA_PRINTOPT_ShowDialog;
    664   }
    665   int32_t nStartPage = 0;
    666   if (iLength >= 2) {
    667     nStartPage = pArguments->GetInt32(1);
    668   }
    669   int32_t nEndPage = 0;
    670   if (iLength >= 3) {
    671     nEndPage = pArguments->GetInt32(2);
    672   }
    673   FX_BOOL bCanCancel = TRUE;
    674   if (iLength >= 4) {
    675     bCanCancel = pArguments->GetInt32(3) == 0 ? FALSE : TRUE;
    676   }
    677   if (bCanCancel) {
    678     dwOptions |= XFA_PRINTOPT_CanCancel;
    679   }
    680   FX_BOOL bShrinkPage = TRUE;
    681   if (iLength >= 5) {
    682     bShrinkPage = pArguments->GetInt32(4) == 0 ? FALSE : TRUE;
    683   }
    684   if (bShrinkPage) {
    685     dwOptions |= XFA_PRINTOPT_ShrinkPage;
    686   }
    687   FX_BOOL bAsImage = TRUE;
    688   if (iLength >= 6) {
    689     bAsImage = pArguments->GetInt32(5) == 0 ? FALSE : TRUE;
    690   }
    691   if (bAsImage) {
    692     dwOptions |= XFA_PRINTOPT_AsImage;
    693   }
    694   FX_BOOL bReverseOrder = TRUE;
    695   if (iLength >= 7) {
    696     bAsImage = pArguments->GetInt32(5) == 0 ? FALSE : TRUE;
    697   }
    698   bReverseOrder = pArguments->GetInt32(6) == 0 ? FALSE : TRUE;
    699   if (bReverseOrder) {
    700     dwOptions |= XFA_PRINTOPT_ReverseOrder;
    701   }
    702   FX_BOOL bPrintAnnot = TRUE;
    703   if (iLength >= 8) {
    704     bPrintAnnot = pArguments->GetInt32(7) == 0 ? FALSE : TRUE;
    705   }
    706   if (bPrintAnnot) {
    707     dwOptions |= XFA_PRINTOPT_PrintAnnot;
    708   }
    709   pNotify->GetDocProvider()->Print(hDoc, nStartPage, nEndPage, dwOptions);
    710 }
    711 void CScript_HostPseudoModel::Script_HostPseudoModel_ImportData(
    712     CFXJSE_Arguments* pArguments) {
    713   int32_t iLength = pArguments->GetLength();
    714   if (iLength < 0 || iLength > 1) {
    715     ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"importData");
    716     return;
    717   }
    718   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    719   if (!pNotify) {
    720     return;
    721   }
    722   CFX_WideString wsFilePath;
    723   if (iLength > 0) {
    724     CFX_ByteString bsFilePath = pArguments->GetUTF8String(0);
    725     wsFilePath = CFX_WideString::FromUTF8(bsFilePath, bsFilePath.GetLength());
    726   }
    727   IXFA_Doc* hDoc = pNotify->GetHDOC();
    728   pNotify->GetDocProvider()->ImportData(hDoc, wsFilePath);
    729 }
    730 void CScript_HostPseudoModel::Script_HostPseudoModel_ExportData(
    731     CFXJSE_Arguments* pArguments) {
    732   int32_t iLength = pArguments->GetLength();
    733   if (iLength < 0 || iLength > 2) {
    734     ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"exportData");
    735     return;
    736   }
    737   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    738   if (!pNotify) {
    739     return;
    740   }
    741   IXFA_Doc* hDoc = pNotify->GetHDOC();
    742   CFX_WideString wsFilePath;
    743   FX_BOOL bXDP = TRUE;
    744   if (iLength >= 1) {
    745     CFX_ByteString bsFilePath = pArguments->GetUTF8String(0);
    746     wsFilePath = CFX_WideString::FromUTF8(bsFilePath, bsFilePath.GetLength());
    747   }
    748   if (iLength >= 2) {
    749     bXDP = pArguments->GetInt32(1) == 0 ? FALSE : TRUE;
    750   }
    751   pNotify->GetDocProvider()->ExportData(hDoc, wsFilePath, bXDP);
    752 }
    753 void CScript_HostPseudoModel::Script_HostPseudoModel_PageUp(
    754     CFXJSE_Arguments* pArguments) {
    755   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    756   if (!pNotify) {
    757     return;
    758   }
    759   IXFA_Doc* hDoc = pNotify->GetHDOC();
    760   int32_t nCurPage = pNotify->GetDocProvider()->GetCurrentPage(hDoc);
    761   int32_t nNewPage = 0;
    762   if (nCurPage <= 1) {
    763     return;
    764   }
    765   nNewPage = nCurPage - 1;
    766   pNotify->GetDocProvider()->SetCurrentPage(hDoc, nNewPage);
    767 }
    768 void CScript_HostPseudoModel::Script_HostPseudoModel_PageDown(
    769     CFXJSE_Arguments* pArguments) {
    770   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    771   if (!pNotify) {
    772     return;
    773   }
    774   IXFA_Doc* hDoc = pNotify->GetHDOC();
    775   int32_t nCurPage = pNotify->GetDocProvider()->GetCurrentPage(hDoc);
    776   int32_t nPageCount = pNotify->GetDocProvider()->CountPages(hDoc);
    777   if (!nPageCount || nCurPage == nPageCount) {
    778     return;
    779   }
    780   int32_t nNewPage = 0;
    781   if (nCurPage >= nPageCount) {
    782     nNewPage = nPageCount - 1;
    783   } else {
    784     nNewPage = nCurPage + 1;
    785   }
    786   pNotify->GetDocProvider()->SetCurrentPage(hDoc, nNewPage);
    787 }
    788 void CScript_HostPseudoModel::Script_HostPseudoModel_CurrentDateTime(
    789     CFXJSE_Arguments* pArguments) {
    790   IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    791   if (!pNotify) {
    792     return;
    793   }
    794   CFX_WideString wsDataTime = pNotify->GetCurrentDateTime();
    795   FXJSE_HVALUE hValue = pArguments->GetReturnValue();
    796   if (hValue) {
    797     FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsDataTime));
    798   }
    799 }
    800