Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Attributes
CActiveScriptSite Class Reference

#include <ActiveScriptSite.h>

Collaboration diagram for CActiveScriptSite:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 CActiveScriptSite ()
virtual ~CActiveScriptSite ()
virtual HRESULT Attach (CLSID clsidScriptEngine)
virtual HRESULT AttachVBScript ()
virtual HRESULT AttachJScript ()
virtual HRESULT Detach ()
virtual SCRIPTSTATE GetScriptState () const
virtual HRESULT ParseScriptText (const TCHAR *szScript)
virtual HRESULT ParseScriptFile (const TCHAR *szFile)
virtual HRESULT AddNamedObject (const TCHAR *szName, IUnknown *pObject, BOOL bGlobalMembers=FALSE)
virtual HRESULT PlayScript ()
virtual HRESULT StopScript ()
virtual HRESULT STDMETHODCALLTYPE GetLCID (LCID __RPC_FAR *plcid)
virtual HRESULT STDMETHODCALLTYPE GetItemInfo (LPCOLESTR pstrName, DWORD dwReturnMask, IUnknown __RPC_FAR *__RPC_FAR *ppiunkItem, ITypeInfo __RPC_FAR *__RPC_FAR *ppti)
virtual HRESULT STDMETHODCALLTYPE GetDocVersionString (BSTR __RPC_FAR *pbstrVersion)
virtual HRESULT STDMETHODCALLTYPE OnScriptTerminate (const VARIANT __RPC_FAR *pvarResult, const EXCEPINFO __RPC_FAR *pexcepinfo)
virtual HRESULT STDMETHODCALLTYPE OnStateChange (SCRIPTSTATE ssScriptState)
virtual HRESULT STDMETHODCALLTYPE OnScriptError (IActiveScriptError __RPC_FAR *pscripterror)
virtual HRESULT STDMETHODCALLTYPE OnEnterScript (void)
virtual HRESULT STDMETHODCALLTYPE OnLeaveScript (void)

Private Attributes

CComQIPtr< IActiveScript,&IID_IActiveScript > m_spIActiveScript
CNamedObjectList m_cObjectList
SCRIPTSTATE m_ssScriptState

Detailed Description

Definition at line 42 of file ActiveScriptSite.h.


Constructor & Destructor Documentation

Definition at line 45 of file ActiveScriptSite.cpp.

{
    m_ssScriptState = SCRIPTSTATE_UNINITIALIZED;
}

Definition at line 51 of file ActiveScriptSite.cpp.

{
    Detach();
}

Here is the call graph for this function:


Member Function Documentation

HRESULT CActiveScriptSite::AddNamedObject ( const TCHAR szName,
IUnknown pObject,
BOOL  bGlobalMembers = FALSE 
) [virtual]

Definition at line 117 of file ActiveScriptSite.cpp.

{
    if (m_spIActiveScript == NULL)
    {
        return E_UNEXPECTED;
    }

    if (pObject == NULL || szName == NULL)
    {
        return E_INVALIDARG;
    }

    // Check for objects of the same name already
    CNamedObjectList::iterator i = m_cObjectList.find(szName);
    if (i != m_cObjectList.end())
    {
        return E_FAIL;
    }

    // Add object to the list
    m_cObjectList.insert(CNamedObjectList::value_type(szName, pObject));

    // Tell the script engine about the object
    HRESULT hr;
    USES_CONVERSION;
    DWORD dwFlags = SCRIPTITEM_ISSOURCE | SCRIPTITEM_ISVISIBLE;
    if (bGlobalMembers)
    {
        dwFlags |= SCRIPTITEM_GLOBALMEMBERS;
    }

    hr = m_spIActiveScript->AddNamedItem(T2OLE(szName), dwFlags);

    if (FAILED(hr))
    {
        m_cObjectList.erase(szName);
        return hr;
    }

    return S_OK;
}
HRESULT CActiveScriptSite::Attach ( CLSID  clsidScriptEngine) [virtual]

Definition at line 57 of file ActiveScriptSite.cpp.

{
    // Detach to anything already attached to
    Detach();

    // Create the new script engine
    HRESULT hr = m_spIActiveScript.CoCreateInstance(clsidScriptEngine);
    if (FAILED(hr))
    {
        return hr;
    }

    // Attach the script engine to this site
    m_spIActiveScript->SetScriptSite(this);

    // Initialise the script engine
    CIPtr(IActiveScriptParse) spActiveScriptParse = m_spIActiveScript;
    if (spActiveScriptParse)
    {
        spActiveScriptParse->InitNew();
    }
    else
    {
    }

    return S_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 108 of file ActiveScriptSite.cpp.

{
    static const CLSID CLSID_JScript =
    { 0xF414C260, 0x6AC0, 0x11CF, { 0xB6, 0xD1, 0x00, 0xAA, 0x00, 0xBB, 0xBB, 0x58} };

    return Attach(CLSID_JScript);
}

Here is the call graph for this function:

Definition at line 99 of file ActiveScriptSite.cpp.

{
    static const CLSID CLSID_VBScript =
    { 0xB54F3741, 0x5B07, 0x11CF, { 0xA4, 0xB0, 0x00, 0xAA, 0x00, 0x4A, 0x55, 0xE8} };
    
    return Attach(CLSID_VBScript);
}

Here is the call graph for this function:

Definition at line 86 of file ActiveScriptSite.cpp.

{
    if (m_spIActiveScript)
    {
        StopScript();
        m_spIActiveScript->Close();
        m_spIActiveScript.Release();
    }

    return S_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

HRESULT STDMETHODCALLTYPE CActiveScriptSite::GetDocVersionString ( BSTR __RPC_FAR *  pbstrVersion) [virtual]

Definition at line 339 of file ActiveScriptSite.cpp.

{
    return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE CActiveScriptSite::GetItemInfo ( LPCOLESTR  pstrName,
DWORD  dwReturnMask,
IUnknown __RPC_FAR *__RPC_FAR *  ppiunkItem,
ITypeInfo __RPC_FAR *__RPC_FAR *  ppti 
) [virtual]

Definition at line 284 of file ActiveScriptSite.cpp.

{
    if (pstrName == NULL)
    {
        return E_INVALIDARG;
    }
    
    if (ppiunkItem)
    {
        *ppiunkItem = NULL;
    }

    if (ppti)
    {
        *ppti = NULL;
    }

    USES_CONVERSION;

    // Find object in list
    CIUnkPtr spUnkObject;
    CNamedObjectList::iterator i = m_cObjectList.find(OLE2T(pstrName));
    if (i != m_cObjectList.end())
    {
        spUnkObject = (*i).second;
    }

    // Fill in the output values
    if (spUnkObject == NULL) 
    {
        return TYPE_E_ELEMENTNOTFOUND;
    }
    if (dwReturnMask & SCRIPTINFO_IUNKNOWN) 
    {
        spUnkObject->QueryInterface(IID_IUnknown, (void **) ppiunkItem);
    }
    if (dwReturnMask & SCRIPTINFO_ITYPEINFO) 
    {
        // Return the typeinfo in ptti
        CIPtr(IDispatch) spIDispatch = spUnkObject;
        if (spIDispatch)
        {
            HRESULT hr;
            hr = spIDispatch->GetTypeInfo(0, GetSystemDefaultLCID(), ppti);
            if (FAILED(hr))
            {
                *ppti = NULL;
            }
        }
    }

    return S_OK;
}
HRESULT STDMETHODCALLTYPE CActiveScriptSite::GetLCID ( LCID __RPC_FAR *  plcid) [virtual]

Definition at line 277 of file ActiveScriptSite.cpp.

{
    // Use the system defined locale
    return E_NOTIMPL;
}
virtual SCRIPTSTATE CActiveScriptSite::GetScriptState ( ) const [inline, virtual]

Definition at line 71 of file ActiveScriptSite.h.

    {
        return m_ssScriptState;
    }
HRESULT STDMETHODCALLTYPE CActiveScriptSite::OnEnterScript ( void  ) [virtual]

Definition at line 389 of file ActiveScriptSite.cpp.

{
    return S_OK;
}
HRESULT STDMETHODCALLTYPE CActiveScriptSite::OnLeaveScript ( void  ) [virtual]

Definition at line 395 of file ActiveScriptSite.cpp.

{
    return S_OK;
}
HRESULT STDMETHODCALLTYPE CActiveScriptSite::OnScriptError ( IActiveScriptError __RPC_FAR *  pscripterror) [virtual]

Definition at line 358 of file ActiveScriptSite.cpp.

{
    BSTR bstrSourceLineText = NULL;
    DWORD dwSourceContext = 0;
    ULONG pulLineNumber = 0;
    LONG  ichCharPosition = 0;
    EXCEPINFO cExcepInfo;

    memset(&cExcepInfo, 0, sizeof(cExcepInfo));

    // Get error information
    pscripterror->GetSourcePosition(&dwSourceContext, &pulLineNumber, &ichCharPosition);
    pscripterror->GetSourceLineText(&bstrSourceLineText);
    pscripterror->GetExceptionInfo(&cExcepInfo);

    tstring szDescription(_T("(No description)"));
    if (cExcepInfo.bstrDescription)
    {
        // Dump info
        USES_CONVERSION;
        szDescription = OLE2T(cExcepInfo.bstrDescription);
    }

    ATLTRACE(_T("Script Error: %s, code=0x%08x\n"), szDescription.c_str(), cExcepInfo.scode);

    SysFreeString(bstrSourceLineText);

    return S_OK;
}

Here is the call graph for this function:

HRESULT STDMETHODCALLTYPE CActiveScriptSite::OnScriptTerminate ( const VARIANT __RPC_FAR *  pvarResult,
const EXCEPINFO __RPC_FAR *  pexcepinfo 
) [virtual]

Definition at line 345 of file ActiveScriptSite.cpp.

{
    return S_OK;
}
HRESULT STDMETHODCALLTYPE CActiveScriptSite::OnStateChange ( SCRIPTSTATE  ssScriptState) [virtual]

Definition at line 351 of file ActiveScriptSite.cpp.

{
    m_ssScriptState = ssScriptState;
    return S_OK;
}

Definition at line 160 of file ActiveScriptSite.cpp.

{
    USES_CONVERSION;
    const char *pszFileName = T2CA(szFile);
    
    // Stat the file and get its length;
    struct _stat cStat;
    _stat(pszFileName, &cStat);

    // Allocate a buffer
    size_t nBufSize = cStat.st_size + 1;
    char *pBuffer = (char *) malloc(nBufSize);
    if (pBuffer == NULL)
    {
        return E_OUTOFMEMORY;
    }
    memset(pBuffer, 0, nBufSize);

    // Read the script into the buffer and parse it
    HRESULT hr = E_FAIL;
    FILE *f = fopen(pszFileName, "rb");
    if (f)
    {
        fread(pBuffer, 1, nBufSize - 1, f);
        hr = ParseScriptText(A2T(pBuffer));
        fclose(f);
    }

    free(pBuffer);

    return hr;
}

Here is the call graph for this function:

Definition at line 194 of file ActiveScriptSite.cpp.

{
    if (m_spIActiveScript == NULL)
    {
        return E_UNEXPECTED;
    }

    CIPtr(IActiveScriptParse) spIActiveScriptParse = m_spIActiveScript;
    if (spIActiveScriptParse)
    {
        USES_CONVERSION;

        CComVariant vResult;
        DWORD dwCookie = 0; // TODO
        DWORD dwFlags = 0;
        EXCEPINFO cExcepInfo;
        HRESULT hr;

        hr = spIActiveScriptParse->ParseScriptText(
                    T2OLE(szScript),
                    NULL, NULL, NULL, dwCookie, 0, dwFlags,
                    &vResult, &cExcepInfo);

        if (FAILED(hr))
        {
            return E_FAIL;
        }
    }
    else
    {
        CIPtr(IPersistStream) spPersistStream = m_spIActiveScript;
        CIPtr(IStream) spStream;

        // Load text into the stream IPersistStream
        if (spPersistStream &&
            SUCCEEDED(CreateStreamOnHGlobal(NULL, TRUE, &spStream)))
        {
            USES_CONVERSION;
            LARGE_INTEGER cPos = { 0, 0 };
            LPOLESTR szText = T2OLE(szScript);
            spStream->Write(szText, wcslen(szText) * sizeof(WCHAR), NULL);
            spStream->Seek(cPos, STREAM_SEEK_SET, NULL);
            spPersistStream->Load(spStream);
        }
        else
        {
            return E_UNEXPECTED;
        }
    }

    return S_OK;
}

Here is the caller graph for this function:

Definition at line 248 of file ActiveScriptSite.cpp.

{
    if (m_spIActiveScript == NULL)
    {
        return E_UNEXPECTED;
    }

    m_spIActiveScript->SetScriptState(SCRIPTSTATE_CONNECTED);

    return S_OK;
}

Definition at line 261 of file ActiveScriptSite.cpp.

{
    if (m_spIActiveScript == NULL)
    {
        return E_UNEXPECTED;
    }

    m_spIActiveScript->SetScriptState(SCRIPTSTATE_DISCONNECTED);

    return S_OK;
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 49 of file ActiveScriptSite.h.

CComQIPtr<IActiveScript, &IID_IActiveScript> CActiveScriptSite::m_spIActiveScript [private]

Definition at line 46 of file ActiveScriptSite.h.

SCRIPTSTATE CActiveScriptSite::m_ssScriptState [private]

Definition at line 52 of file ActiveScriptSite.h.


The documentation for this class was generated from the following files: