Back to index

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

#include <XPConnect.h>

Inheritance diagram for nsScriptablePeer:
Inheritance graph
[legend]
Collaboration diagram for nsScriptablePeer:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsScriptablePeer ()
 nsScriptablePeer (CPlugin *plugin)
 ~nsScriptablePeer ()
NS_IMETHOD QueryInterface (const nsIID &aIID, void **aInstancePtr)
 NS_IMETHOD_ (nsrefcnt) AddRef()
 NS_IMETHOD_ (nsrefcnt) Release()
 nsScriptablePeer (CPlugin *plugin)
 ~nsScriptablePeer ()
 nsScriptablePeer (nsPluginInstance *plugin)
 ~nsScriptablePeer ()
NS_IMETHOD QueryInterface (const nsIID &aIID, void **aInstancePtr)
 NS_IMETHOD_ (nsrefcnt) AddRef()
 NS_IMETHOD_ (nsrefcnt) Release()
NS_DECL_NSISCRIPTABLEPLUGINSAMPLE
void 
SetInstance (nsPluginInstance *plugin)
 nsScriptablePeer (nsPluginInstance *plugin)
virtual ~nsScriptablePeer ()
NS_IMETHOD QueryInterface (const nsIID &aIID, void **aInstancePtr)
 NS_IMETHOD_ (nsrefcnt) AddRef()
 NS_IMETHOD_ (nsrefcnt) Release()
NS_DECL_NSISCRIPTABLEPLUGINSAMPLE
void 
SetInstance (nsPluginInstance *plugin)
 nsScriptablePeer (nsPluginInstance *plugin)
 ~nsScriptablePeer ()
NS_IMETHOD QueryInterface (const nsIID &aIID, void **aInstancePtr)
 NS_IMETHOD_ (nsrefcnt) AddRef()
 NS_IMETHOD_ (nsrefcnt) Release()
NS_DECL_NSISCRIPTABLEPLUGINSAMPLE
void 
SetInstance (nsPluginInstance *plugin)
 nsScriptablePeer (nsPluginInstance *plugin)
 ~nsScriptablePeer ()
NS_IMETHOD QueryInterface (const nsIID &aIID, void **aInstancePtr)
 NS_IMETHOD_ (nsrefcnt) AddRef()
 NS_IMETHOD_ (nsrefcnt) Release()
NS_DECL_NSISIMPLEPLUGIN void SetInstance (nsPluginInstance *plugin)
void getInterfaces (out PRUint32 count,[array, size_is(count), retval] out nsIIDPtr array)
 Get an ordered list of the interface ids that instances of the class promise to implement.
nsISupports getHelperForLanguage (in PRUint32 language)
 Get a language mapping specific helper object that may assist in using objects of this class in a specific lanaguage.
void showVersion ()
void showVersion ()
void showVersion ()
void clear ()
void clear ()
void clear ()
void showVersion ()
void clear ()
void setWindow (in acmeIScriptObject window)
void invoke (in string str)
void invoke1 (in string str, in nsIVariant a)
void invoke2 (in string str, in nsIVariant a, in nsIVariant b)
void invoke3 (in string str, in nsIVariant a, in nsIVariant b, in nsIVariant c)
void invoke4 (in string str, in nsIVariant a, in nsIVariant b, in nsIVariant c, in nsIVariant d)
nsIVariant getProperty (in string propertyName)
void setProperty (in string propertyName, in nsIVariant propertyValue)

Public Attributes

nsScriptablePeerTearOffmTearOff
PluginInstanceDatamPlugin
readonly attribute string version
readonly attribute string contractID
 A contract ID through which an instance of this class can be created (or accessed as a service, if |flags & SINGLETON|), or null.
readonly attribute string classDescription
 A human readable string naming the class, or null.
readonly attribute nsCIDPtr classID
 A class ID through which an instance of this class can be created (or accessed as a service, if |flags & SINGLETON|), or null.
readonly attribute PRUint32 implementationLanguage
 Return language type from list in nsIProgrammingLanguage.
const PRUint32 SINGLETON = 1 << 0
 Bitflags for 'flags' attribute.
const PRUint32 THREADSAFE = 1 << 1
const PRUint32 MAIN_THREAD_ONLY = 1 << 2
const PRUint32 DOM_OBJECT = 1 << 3
const PRUint32 PLUGIN_OBJECT = 1 << 4
const PRUint32 EAGER_CLASSINFO = 1 << 5
const PRUint32 CONTENT_NODE = 1 << 6
 'flags' attribute bitflag: whether objects of this type implement nsIContent.
const PRUint32 RESERVED = 1 << 31
readonly attribute PRUint32 flags
readonly attribute nsCID classIDNoAlloc
 Also a class ID through which an instance of this class can be created (or accessed as a service, if |flags & SINGLETON|).
readonly attribute string version

Protected Member Functions

virtual ~nsScriptablePeer ()
HRESULT GetIDispatch (IDispatch **pdisp)
HRESULT ConvertVariants (nsIVariant *aIn, VARIANT *aOut)
HRESULT ConvertVariants (VARIANT *aIn, nsIVariant **aOut)
nsresult HR2NS (HRESULT hr) const
NS_IMETHOD InternalInvoke (const char *aMethod, unsigned int aNumArgs, nsIVariant *aArgs[])

Protected Attributes

nsrefcnt mRefCnt
CPluginmPlugin
acmeIScriptObjectmWindow
nsPluginInstancemPlugin

Private Attributes

friend nsScriptablePeerTearOff

Detailed Description

Definition at line 89 of file XPConnect.h.


Constructor & Destructor Documentation

nsScriptablePeer::~nsScriptablePeer ( ) [protected, virtual]

Definition at line 92 of file XPConnect.cpp.

Definition at line 85 of file XPConnect.cpp.

                                   :
    mTearOff(new nsScriptablePeerTearOff(this))
{
    NS_ASSERTION(mTearOff, "can't create tearoff");
    MozAxPlugin::AddRef();
}

Here is the call graph for this function:

Definition at line 57 of file nsScriptablePeer.cpp.

{
  mRefCnt = 0;
  mPlugin = aPlugin;
  mWindow = nsnull;
}

Definition at line 54 of file nsScriptablePeer.cpp.

{
  mPlugin = aPlugin;
  mRefCnt = 0;
}
virtual nsScriptablePeer::~nsScriptablePeer ( ) [virtual]

Member Function Documentation

HRESULT nsScriptablePeer::ConvertVariants ( nsIVariant aIn,
VARIANT *  aOut 
) [protected]

Definition at line 185 of file XPConnect.cpp.

{
    if (aIn == NULL || aOut == NULL)
    {
        return NS_ERROR_INVALID_ARG;
    }

    PRBool isWritable = PR_FALSE;
    nsCOMPtr<nsIWritableVariant> writable = do_QueryInterface(aIn);
    if (writable)
    {
        writable->GetWritable(&isWritable);
    }

    PRUint16 type;
    nsresult rv = aIn->GetDataType(&type);
    switch (type)
    {
    case nsIDataType::VTYPE_INT8:
        {
            PRUint8 value = 0;
            rv = aIn->GetAsInt8(&value);
            aOut->vt = VT_I1;
            aOut->cVal = value;
        }
        break;
    case nsIDataType::VTYPE_INT16:
        {
            PRInt16 value = 0;
            rv = aIn->GetAsInt16(&value);
            aOut->vt = VT_I2;
            aOut->iVal = value;
        }
        break;
    case nsIDataType::VTYPE_INT32:
        {
            PRInt32 value = 0;
            rv = aIn->GetAsInt32(&value);
            aOut->vt = VT_I4;
            aOut->lVal = value;
        }
        break;
    case nsIDataType::VTYPE_CHAR:
    case nsIDataType::VTYPE_UINT8:
        {
            PRUint8 value = 0;
            rv = aIn->GetAsInt8(&value);
            aOut->vt = VT_UI1;
            aOut->bVal = value;
        }
        break;
    case nsIDataType::VTYPE_WCHAR:
    case nsIDataType::VTYPE_UINT16:
        {
            PRUint16 value = 0;
            rv = aIn->GetAsUint16(&value);
            aOut->vt = VT_I2;
            aOut->uiVal = value;
        }
        break;
    case nsIDataType::VTYPE_UINT32:
        {
            PRUint32 value = 0;
            rv = aIn->GetAsUint32(&value);
            aOut->vt = VT_I4;
            aOut->ulVal = value;
        }
        break;
    case nsIDataType::VTYPE_FLOAT:
        {
            float value = 0;
            rv = aIn->GetAsFloat(&value);
            aOut->vt = VT_R4;
            aOut->fltVal = value;
        }
        break;
    case nsIDataType::VTYPE_DOUBLE:
        {
            double value = 0;
            rv = aIn->GetAsDouble(&value);
            aOut->vt = VT_R4;
            aOut->dblVal = value;
        }
        break;
    case nsIDataType::VTYPE_BOOL:
        {
            PRBool value = 0;
            rv = aIn->GetAsBool(&value);
            aOut->vt = VT_BOOL;
            aOut->dblVal = value ? VARIANT_TRUE : VARIANT_FALSE;
        }
        break;
    case nsIDataType::VTYPE_EMPTY:
        VariantClear(aOut);
        break;

    case nsIDataType::VTYPE_STRING_SIZE_IS:
    case nsIDataType::VTYPE_CHAR_STR:
        {
            nsXPIDLCString value;
            aIn->GetAsString(getter_Copies(value));
            nsAutoString valueWide; valueWide.AssignWithConversion(value);
            aOut->vt = VT_BSTR;
            aOut->bstrVal = SysAllocString(valueWide.get());
        }
        break;
    case nsIDataType::VTYPE_WSTRING_SIZE_IS:
    case nsIDataType::VTYPE_WCHAR_STR:
        {
            nsXPIDLString value;
            aIn->GetAsWString(getter_Copies(value));
            aOut->vt = VT_BSTR;
            aOut->bstrVal = SysAllocString(value.get());
        }
        break;

    case nsIDataType::VTYPE_ASTRING:
        {
            nsAutoString value;
            aIn->GetAsAString(value);
            aOut->vt = VT_BSTR;
            aOut->bstrVal = SysAllocString(value.get());
        }
        break;

    case nsIDataType::VTYPE_DOMSTRING:
        {
            nsAutoString value;
            aIn->GetAsAString(value);
            aOut->vt = VT_BSTR;
            aOut->bstrVal = SysAllocString(value.get());
        }
        break;

    case nsIDataType::VTYPE_CSTRING:
        {
            nsCAutoString value;
            aIn->GetAsACString(value);
            nsAutoString valueWide; valueWide.AssignWithConversion(value.get());
            aOut->vt = VT_BSTR;
            aOut->bstrVal = SysAllocString(valueWide.get());
        }
        break;
    case nsIDataType::VTYPE_UTF8STRING:
        {
            nsCAutoString value;
            aIn->GetAsAUTF8String(value);
            nsAutoString valueWide;
            CopyUTF8toUTF16(value, valueWide);
            aOut->vt = VT_BSTR;
            aOut->bstrVal = SysAllocString(valueWide.get());
        }

    // Unsupported types
    default:
    case nsIDataType::VTYPE_INT64:
    case nsIDataType::VTYPE_UINT64:
    case nsIDataType::VTYPE_VOID:
    case nsIDataType::VTYPE_ID:
    case nsIDataType::VTYPE_INTERFACE:
    case nsIDataType::VTYPE_INTERFACE_IS:
    case nsIDataType::VTYPE_ARRAY:
    case nsIDataType::VTYPE_EMPTY_ARRAY:
        return E_INVALIDARG;
    }

    return S_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

HRESULT nsScriptablePeer::ConvertVariants ( VARIANT *  aIn,
nsIVariant **  aOut 
) [protected]

Definition at line 356 of file XPConnect.cpp.

{
    if (aIn == NULL || aOut == NULL)
    {
        return NS_ERROR_INVALID_ARG;
    }

    *aOut = nsnull;

    nsresult rv;
    nsCOMPtr<nsIWritableVariant> v = do_CreateInstance("@mozilla.org/variant;1", &rv);

    // NOTE: THIS IS AN UGLY BACKWARDS COMPATIBILITY HACK TO WORKAROUND
    // XPCOM GLUE'S INABILITY TO FIND A CERTAIN ENTRY POINT IN MOZ1.0.x/NS7.0!
    // DO NOT TAUNT THE HACK
    if (NS_FAILED(rv))
    {
        // do_CreateInstance macro is broken so load the component manager by
        // hand and get it to create the component.
        HMODULE hlib = ::LoadLibrary("xpcom.dll");
        if (hlib)
        {
            nsIComponentManager *pManager = nsnull; // A frozen interface, even in 1.0.x
            typedef nsresult (PR_CALLBACK *Moz1XGetComponentManagerFunc)(nsIComponentManager* *result);
            Moz1XGetComponentManagerFunc compMgr = (Moz1XGetComponentManagerFunc)
                ::GetProcAddress(hlib, "NS_GetComponentManager");
            if (compMgr)
            {
                compMgr(&pManager);
                if (pManager)
                {
                    rv = pManager->CreateInstanceByContractID("@mozilla.org/variant;1",
                        nsnull, NS_GET_IID(nsIWritableVariant),
                        getter_AddRefs(v));
                    pManager->Release();
                }
            }
            ::FreeLibrary(hlib);
        }
    }
    // END HACK
    NS_ENSURE_SUCCESS(rv, rv);

    switch (aIn->vt)
    {
    case VT_EMPTY:
        v->SetAsEmpty();
        break;
    case VT_BSTR:
        v->SetAsWString(aIn->bstrVal);
        break;
    case VT_I1:
        v->SetAsInt8(aIn->cVal);
        break;
    case VT_I2:
        v->SetAsInt16(aIn->iVal);
        break;
    case VT_I4:
        v->SetAsInt32(aIn->lVal);
        break;
    case VT_UI1:
        v->SetAsUint8(aIn->bVal);
        break;
    case VT_UI2:
        v->SetAsUint16(aIn->uiVal);
        break;
    case VT_UI4:
        v->SetAsUint32(aIn->ulVal);
        break;
    case VT_BOOL:
        v->SetAsBool(aIn->boolVal == VARIANT_TRUE ? PR_TRUE : PR_FALSE);
        break;
    case VT_R4:
        v->SetAsFloat(aIn->fltVal);
        break;
    case VT_R8:
        v->SetAsDouble(aIn->dblVal);
        break;
    }

    *aOut = v;
    NS_ADDREF(*aOut);

    return NS_OK;
} 

Here is the call graph for this function:

nsISupports nsIClassInfo::getHelperForLanguage ( in PRUint32  language) [inherited]

Get a language mapping specific helper object that may assist in using objects of this class in a specific lanaguage.

For instance, if asked for the helper for nsIProgrammingLanguage::JAVASCRIPT this might return an object that can be QI'd into the nsIXPCScriptable interface to assist XPConnect in supplying JavaScript specific behavior to callers of the instance object.

see: nsIProgrammingLanguage.idl

Should return null if no helper available for given language.

Definition at line 130 of file XPConnect.cpp.

{
    if (pdisp == NULL)
    {
        return E_INVALIDARG;
    }
    *pdisp = NULL;

    IUnknownPtr unk;
    HRESULT hr = mPlugin->pControlSite->GetControlUnknown(&unk);
    if (unk.GetInterfacePtr() == NULL)
    {
              return E_FAIL; 
       }

    IDispatchPtr disp = unk;
    if (disp.GetInterfacePtr() == NULL)
    { 
        return E_FAIL; 
    }

    *pdisp = disp.GetInterfacePtr();
    (*pdisp)->AddRef();

    return S_OK;
}

Here is the caller graph for this function:

void nsIClassInfo::getInterfaces ( out PRUint32  count,
[array, size_is(count), retval] out nsIIDPtr  array 
) [inherited]

Get an ordered list of the interface ids that instances of the class promise to implement.

Note that nsISupports is an implicit member of any such list and need not be included.

Should set *count = 0 and *array = null and return NS_OK if getting the list is not supported.

nsIVariant nsIMozAxPlugin::getProperty ( in string  propertyName) [inherited]
nsresult nsScriptablePeer::HR2NS ( HRESULT  hr) const [protected]

Definition at line 158 of file XPConnect.cpp.

{
    switch (hr)
    {
    case S_OK:
        return NS_OK;
    case E_NOTIMPL:
        return NS_ERROR_NOT_IMPLEMENTED;
    case E_NOINTERFACE:
        return NS_ERROR_NO_INTERFACE;
    case E_INVALIDARG:
        return NS_ERROR_INVALID_ARG;
    case E_ABORT:
        return NS_ERROR_ABORT;
    case E_UNEXPECTED:
        return NS_ERROR_UNEXPECTED;
    case E_OUTOFMEMORY:
        return NS_ERROR_OUT_OF_MEMORY;
    case E_POINTER:
        return NS_ERROR_INVALID_POINTER;
    case E_FAIL:
    default:
        return NS_ERROR_FAILURE;
    }
}
NS_IMETHODIMP nsScriptablePeer::InternalInvoke ( const char *  aMethod,
unsigned int  aNumArgs,
nsIVariant aArgs[] 
) [protected]

Definition at line 443 of file XPConnect.cpp.

{
    HRESULT hr;
    DISPID dispid;

    IDispatchPtr disp;
    if (FAILED(GetIDispatch(&disp)))
    {
        return NPERR_GENERIC_ERROR; 
    }

    USES_CONVERSION;
    OLECHAR FAR* szMember = A2OLE(aMethod);
    hr = disp->GetIDsOfNames(IID_NULL, &szMember, 1, LOCALE_USER_DEFAULT, &dispid);
    if (FAILED(hr))
    { 
        return NPERR_GENERIC_ERROR; 
    }
    
    _variant_t *pArgs = NULL;
    if (aNumArgs > 0)
    {
        pArgs = new _variant_t[aNumArgs];
        if (pArgs == NULL)
        {
            return NS_ERROR_OUT_OF_MEMORY;
        }
        for (unsigned int i = 0; i < aNumArgs; i++)
        {
            hr = ConvertVariants(aArgs[i], &pArgs[i]);
            if (FAILED(hr))
            {
                delete []pArgs;
                return NS_ERROR_INVALID_ARG;
            }
        }
    }

    DISPPARAMS dispparams = {NULL, NULL, 0, 0};
    _variant_t vResult;

    dispparams.cArgs = aNumArgs;
    dispparams.rgvarg = pArgs;

    hr = disp->Invoke(
        dispid,
        IID_NULL,
        LOCALE_USER_DEFAULT,
        DISPATCH_METHOD,
        &dispparams, &vResult, NULL, NULL);

    if (pArgs)
    {
        delete []pArgs;
    }

    if (FAILED(hr))
    { 
        return NPERR_GENERIC_ERROR; 
    }

    return NS_OK;
}

Here is the call graph for this function:

void nsIMozAxPlugin::invoke ( in string  str) [inherited]
void nsIMozAxPlugin::invoke1 ( in string  str,
in nsIVariant  a 
) [inherited]
void nsIMozAxPlugin::invoke2 ( in string  str,
in nsIVariant  a,
in nsIVariant  b 
) [inherited]
void nsIMozAxPlugin::invoke3 ( in string  str,
in nsIVariant  a,
in nsIVariant  b,
in nsIVariant  c 
) [inherited]
void nsIMozAxPlugin::invoke4 ( in string  str,
in nsIVariant  a,
in nsIVariant  b,
in nsIVariant  c,
in nsIVariant  d 
) [inherited]
NS_IMETHOD nsScriptablePeer::QueryInterface ( const nsIID aIID,
void **  aInstancePtr 
)
NS_IMETHOD nsScriptablePeer::QueryInterface ( const nsIID aIID,
void **  aInstancePtr 
)
NS_IMETHOD nsScriptablePeer::QueryInterface ( const nsIID aIID,
void **  aInstancePtr 
)
NS_IMETHODIMP nsScriptablePeer::QueryInterface ( const nsIID aIID,
void **  aInstancePtr 
)

Definition at line 103 of file XPConnect.cpp.

{
    NS_ASSERTION(aInstancePtr, "QueryInterface requires a non-NULL destination!");
    if (!aInstancePtr)
        return NS_ERROR_NULL_POINTER;
    *aInstancePtr = nsnull;

    nsISupports* foundInterface = nsnull;
    if (aIID.Equals(NS_GET_IID(nsISupports)))
        foundInterface = NS_STATIC_CAST(nsISupports *, NS_STATIC_CAST(nsIClassInfo *, this));
    else if (aIID.Equals(NS_GET_IID(nsIClassInfo)))
        foundInterface = NS_STATIC_CAST(nsIClassInfo*, this);
    else if (aIID.Equals(NS_GET_IID(nsIMozAxPlugin)))
        foundInterface = NS_STATIC_CAST(nsIMozAxPlugin*, this);
    else if (memcmp(&aIID, &__uuidof(IDispatch), sizeof(nsID)) == 0)
    {
        HRESULT hr = mTearOff->QueryInterface(__uuidof(IDispatch), aInstancePtr);
        if (SUCCEEDED(hr)) return NS_OK;
        return E_FAIL;
    }

    NS_IF_ADDREF(foundInterface);
    *aInstancePtr = foundInterface;
    return (*aInstancePtr) ? NS_OK : NS_NOINTERFACE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHOD nsScriptablePeer::QueryInterface ( const nsIID aIID,
void **  aInstancePtr 
)
NS_DECL_NSISCRIPTABLEPLUGINSAMPLE void nsScriptablePeer::SetInstance ( nsPluginInstance plugin)

Definition at line 110 of file nsScriptablePeer.cpp.

{
  mPlugin = plugin;
}
NS_DECL_NSISCRIPTABLEPLUGINSAMPLE void nsScriptablePeer::SetInstance ( nsPluginInstance plugin)
NS_DECL_NSISIMPLEPLUGIN void nsScriptablePeer::SetInstance ( nsPluginInstance plugin)
void nsIMozAxPlugin::setProperty ( in string  propertyName,
in nsIVariant  propertyValue 
) [inherited]

Member Data Documentation

A human readable string naming the class, or null.

Definition at line 86 of file nsIClassInfo.idl.

readonly attribute nsCIDPtr nsIClassInfo::classID [inherited]

A class ID through which an instance of this class can be created (or accessed as a service, if |flags & SINGLETON|), or null.

Definition at line 92 of file nsIClassInfo.idl.

Also a class ID through which an instance of this class can be created (or accessed as a service, if |flags & SINGLETON|).

If the class does not have a CID, it should return NS_ERROR_NOT_AVAILABLE. This attribute exists so C++ callers can avoid allocating and freeing a CID, as would happen if they used classID.

Definition at line 130 of file nsIClassInfo.idl.

'flags' attribute bitflag: whether objects of this type implement nsIContent.

Definition at line 113 of file nsIClassInfo.idl.

A contract ID through which an instance of this class can be created (or accessed as a service, if |flags & SINGLETON|), or null.

Definition at line 81 of file nsIClassInfo.idl.

const PRUint32 nsIClassInfo::DOM_OBJECT = 1 << 3 [inherited]

Definition at line 106 of file nsIClassInfo.idl.

Definition at line 108 of file nsIClassInfo.idl.

readonly attribute PRUint32 nsIClassInfo::flags [inherited]

Definition at line 121 of file nsIClassInfo.idl.

Return language type from list in nsIProgrammingLanguage.

Definition at line 98 of file nsIClassInfo.idl.

Definition at line 105 of file nsIClassInfo.idl.

Definition at line 101 of file XPConnect.h.

Definition at line 102 of file nsScriptablePeer.h.

Definition at line 104 of file nsScriptablePeer.h.

Definition at line 95 of file nsScriptablePeer.h.

Definition at line 100 of file XPConnect.h.

Definition at line 103 of file nsScriptablePeer.h.

Definition at line 93 of file XPConnect.h.

Definition at line 107 of file nsIClassInfo.idl.

const PRUint32 nsIClassInfo::RESERVED = 1 << 31 [inherited]

Definition at line 118 of file nsIClassInfo.idl.

const PRUint32 nsIClassInfo::SINGLETON = 1 << 0 [inherited]

Bitflags for 'flags' attribute.

Definition at line 103 of file nsIClassInfo.idl.

const PRUint32 nsIClassInfo::THREADSAFE = 1 << 1 [inherited]

Definition at line 104 of file nsIClassInfo.idl.

Definition at line 43 of file nsISimplePlugin.idl.

Definition at line 48 of file nsI4xScriptablePlugin.idl.


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