Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
LiveConnect.cpp File Reference
#include "stdafx.h"
#include "jni.h"
#include "npapi.h"
#include "_java/java_lang_Throwable.h"
#include "_java/java_lang_Error.h"
#include "_java/java_lang_String.h"
#include "_java/java_lang_Boolean.h"
#include "_java/java_lang_Number.h"
#include "_java/java_lang_Integer.h"
#include "_java/java_lang_Long.h"
#include "_java/java_lang_Character.h"
#include "_java/netscape_plugin_Plugin.h"
#include "_java/MozAxPlugin.h"
#include "LegacyPlugin.h"
#include "LiveConnect.h"

Go to the source code of this file.

Functions

void liveconnect_Shutdown ()
jref liveconnect_GetJavaClass ()
HRESULT _GetIDispatchFromJRI (JRIEnv *env, struct MozAxPlugin *self, IDispatch **pdisp)
HRESULT _VariantToJRIObject (JRIEnv *env, VARIANT *v, java_lang_Object **o)
HRESULT _JRIObjectToVariant (JRIEnv *env, java_lang_Object *o, VARIANT *v)
struct java_lang_Object * _InvokeFromJRI (JRIEnv *env, struct MozAxPlugin *self, struct java_lang_String *func, int nargs, java_lang_Object *args[])
 JRI_PUBLIC_API (struct java_lang_Object *) native_MozAxPlugin_xinvoke(JRIEnv *env
struct MozAxPlugin struct
java_lang_String *a return 
_InvokeFromJRI (env, self, a, 0, NULL)
return _InvokeFromJRI (env, self, a, sizeof(args)/sizeof(args[0]), args)
 if (length)
 free (args)
 if (FAILED(_GetIDispatchFromJRI(env, self,&disp)))
 if (FAILED(hr))
 _VariantToJRIObject (env,&vResult,&oResult)
 JRI_PUBLIC_API (void) native_MozAxPlugin_xsetProperty2(JRIEnv *env
 if (FAILED(_JRIObjectToVariant(env, b,&pvars[0])))
struct MozAxPlugin struct
java_lang_String struct
java_lang_String *b 
native_MozAxPlugin_xsetProperty2 (env, self, a, reinterpret_cast< java_lang_Object * >(b))
struct java_lang_Throwable
struct java_io_PrintStream *a 
JRI_PUBLIC_API (struct java_lang_Throwable *) native_java_lang_Throwable_fillInStackTrace(JRIEnv *env

Variables

struct MozAxPluginself
struct MozAxPlugin struct
java_lang_String * 
a
struct MozAxPlugin struct
java_lang_String struct
java_lang_Object *b
java_lang_Object * 
args [1] = b
struct MozAxPlugin struct
java_lang_String struct
java_lang_Object * 
b
struct MozAxPlugin struct
java_lang_String struct
java_lang_Object struct
java_lang_Object * 
c
struct MozAxPlugin struct
java_lang_String struct
java_lang_Object struct
java_lang_Object struct
java_lang_Object * 
d
struct MozAxPlugin struct
java_lang_String jobjectArray
b jsize 
length = JRI_GetObjectArrayLength(env, b)
java_lang_Object * o = _InvokeFromJRI(env, self, a, length, args)
struct MozAxPlugin struct
java_lang_String *a HRESULT 
hr = disp->GetIDsOfNames(IID_NULL, &szMember, 1, LOCALE_USER_DEFAULT, &dispid)
DISPID dispid
_variant_t vResult
IDispatchPtr disp
 USES_CONVERSION
OLECHAR FARszMember = A2OLE(JRI_GetStringUTFChars(env, a))
DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0}
java_lang_Object * oResult = NULL
VARIANT VarResult
_variant_t * pvars = new _variant_t[1]
DISPID dispIdPut = DISPID_PROPERTYPUT
DISPPARAMS functionArgs
functionArgs rgdispidNamedArgs = &dispIdPut
functionArgs rgvarg = pvars
functionArgs cArgs = 1
functionArgs cNamedArgs = 1

Function Documentation

HRESULT _GetIDispatchFromJRI ( JRIEnv env,
struct MozAxPlugin self,
IDispatch **  pdisp 
)

Definition at line 105 of file LiveConnect.cpp.

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

    // Note: You get a nasty crash calling self->getPeer(env), this obscure cast fixes
    //       it. More details in the link:
    //
    // http://groups.google.com/groups?selm=385D9543.4087F1C6%40ermapper.com.au&output=gplain

    NPP npp = (NPP) netscape_plugin_Plugin_getPeer(env,
            reinterpret_cast<netscape_plugin_Plugin*> (self));
    PluginInstanceData *pData = (PluginInstanceData *) npp->pdata;
    if (pData == NULL)
    { 
        return E_FAIL;
    }

    IUnknownPtr unk;
    HRESULT hr = pData->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 call graph for this function:

Here is the caller graph for this function:

struct java_lang_Object* _InvokeFromJRI ( JRIEnv env,
struct MozAxPlugin self,
struct java_lang_String *  func,
int  nargs,
java_lang_Object *  args[] 
) [read]

Definition at line 275 of file LiveConnect.cpp.

{
    HRESULT hr;
    DISPID dispid = 0;
    
    // call the requested function
    const char* funcName = JRI_GetStringUTFChars(env, func);

    IDispatchPtr disp;
    if (FAILED(_GetIDispatchFromJRI(env, self, &disp)))
    {
        return NULL;
    }

    _variant_t *vargs = new _variant_t[nargs];
    for (int i = 0; i < nargs; i++)
    {
        if (FAILED(_JRIObjectToVariant(env, args[i], &vargs[i])))
        {
            delete []vargs;
            char error[64];
            sprintf(error, "Argument %d could not be converted into a variant", i);
            JRI_ThrowNew(env, class_java_lang_Error(env), error); 
            return NULL;
        }
    }

    USES_CONVERSION;
    OLECHAR FAR* szMember = A2OLE(funcName);
    hr = disp->GetIDsOfNames(IID_NULL, &szMember, 1, LOCALE_USER_DEFAULT, &dispid);
    if (FAILED(hr))
    { 
        char error[128];
        memset(error, 0, sizeof(error));
        _snprintf(error, sizeof(error) - 1, "invoke failed, member \"%s\" not found, hr=0x%08x", funcName, hr);
        JRI_ThrowNew(env, class_java_lang_Error(env), error); 
        return NULL; 
    }

    DISPPARAMS dispparams = {NULL, NULL, 0, 0};
    dispparams.rgvarg = vargs;
    dispparams.cArgs = nargs;

    _variant_t vResult;
    hr = disp->Invoke(
        dispid,
        IID_NULL,
        LOCALE_USER_DEFAULT,
        DISPATCH_METHOD,
        &dispparams, &vResult, NULL, NULL);
    
    if (FAILED(hr))
    { 
        char error[64];
        sprintf(error, "invoke failed, result from object = 0x%08x", hr);
        JRI_ThrowNew(env, class_java_lang_Error(env), error); 
        return NULL; 
    }

    java_lang_Object *oResult = NULL;
    _VariantToJRIObject(env, &vResult, &oResult);

    return reinterpret_cast<java_lang_Object *>(oResult);
}

Here is the call graph for this function:

struct MozAxPlugin struct java_lang_String* a return _InvokeFromJRI ( env  ,
self  ,
a  ,
,
NULL   
) [read]
return _InvokeFromJRI ( env  ,
self  ,
a  ,
sizeof(args)/sizeof(args[0])  ,
args   
)
HRESULT _JRIObjectToVariant ( JRIEnv env,
java_lang_Object *  o,
VARIANT *  v 
)

Definition at line 214 of file LiveConnect.cpp.

{
    VariantInit(v);
    if (JRI_IsInstanceOf(env, (jref) o, class_java_lang_String(env)))
    {
        USES_CONVERSION;
        const char *value = JRI_GetStringUTFChars(env, reinterpret_cast<java_lang_String *>(o));
        v->vt = VT_BSTR;
        v->bstrVal = SysAllocString(A2COLE(value));
    }
    else if (JRI_IsInstanceOf(env, (jref) o, class_java_lang_Boolean(env)))
    {
        jbool value = java_lang_Boolean_booleanValue(env, reinterpret_cast<java_lang_Boolean *>(o));
        v->vt = VT_BOOL;
        v->boolVal = value == JRITrue ? VARIANT_TRUE : VARIANT_FALSE;
    }
    else if (JRI_IsInstanceOf(env, o, class_java_lang_Integer(env)))
    {
        jint value = java_lang_Integer_intValue(env, reinterpret_cast<java_lang_Integer *>(o));
        v->vt = VT_I4;
        v->lVal = value;
    }
    else if (JRI_IsInstanceOf(env, o, class_java_lang_Long(env)))
    {
        jlong value = java_lang_Long_longValue(env, reinterpret_cast<java_lang_Long *>(o));
        v->vt = VT_I4;
        v->lVal = value;
    }
/*  else if (JRI_IsInstanceOf(env, o, class_java_lang_Double(env)))
    {
        jdouble  value = java_lang_Double_doubleValue(env, reinterpret_cast<java_lang_Double *>(o));
        v->vt = VT_R8;
        v->dblVal = value;
    }
    else if (JRI_IsInstanceOf(env, o, class_java_lang_Float(env)))
    {
        jfloat value = java_lang_Float_floatValue(env, reinterpret_cast<java_lang_Float *>(o));
        v->vt = VT_R4;
        v->fltVal = value;
    } */
    else if (JRI_IsInstanceOf(env, o, class_java_lang_Character(env)))
    {
        jchar value = java_lang_Character_charValue(env, reinterpret_cast<java_lang_Character *>(o));
        v->vt = VT_UI1;
        v->bVal = value;
    }
    else if (JRI_IsInstanceOf(env, o, class_java_lang_Number(env)))
    {
        jlong value = java_lang_Number_longValue(env, reinterpret_cast<java_lang_Number *>(o));
        v->vt = VT_I4;
        v->lVal = value;
    }
    else
    {
        // TODO dump diagnostic error here
        return E_FAIL;
    }
    return S_OK;
}

Here is the caller graph for this function:

HRESULT _VariantToJRIObject ( JRIEnv env,
VARIANT *  v,
java_lang_Object **  o 
)

Definition at line 146 of file LiveConnect.cpp.

{
    if (v == NULL || env == NULL || o == NULL)
    {
        return E_INVALIDARG;
    }

    *o = NULL;

    // TODO - VT_BYREF will cause problems
    if (v->vt == VT_EMPTY)
    {
        return S_OK;
    }
    else if (v->vt == VT_BOOL)
    {
        jbool value = (v->boolVal == VARIANT_TRUE) ? JRITrue : JRIFalse;
        java_lang_Boolean *j = java_lang_Boolean_new(env,
            class_java_lang_Boolean(env), value);
        *o = reinterpret_cast<java_lang_Object *>(j);
        return S_OK;
    }
    else if (v->vt == VT_I4)
    {
        jlong value = v->lVal;
        java_lang_Long *j = java_lang_Long_new(env,
            class_java_lang_Long(env), value);
        *o = reinterpret_cast<java_lang_Object *>(j);
        return S_OK;
    }
    else if (v->vt == VT_I2)
    {
        jlong value = v->iVal;
        java_lang_Long *j = java_lang_Long_new(env,
            class_java_lang_Long(env), value);
        *o = reinterpret_cast<java_lang_Object *>(j);
        return S_OK;
    }
/*  else if (v->vt == VT_R4)
    {
        jfloat value = v->fltVal;
        java_lang_Float *j = java_lang_Float_new(env,
            class_java_lang_Float(env), value);
        *o = reinterpret_cast<java_lang_Object *>(j);
        return S_OK;
    }
    else if (v->vt == VT_R8)
    {
        jdouble value = v->dblVal;
        java_lang_Double *j = java_lang_Double_new(env,
            class_java_lang_Double(env), value);
        *o = reinterpret_cast<java_lang_Object *>(j);
        return S_OK;
    } */
    else if (v->vt == VT_BSTR)
    {
        USES_CONVERSION;
        char * value = OLE2A(v->bstrVal);
        java_lang_String *j = JRI_NewStringUTF(env, value, strlen(value));
        *o = reinterpret_cast<java_lang_Object *>(j);
        return S_OK;
    }
    /* TODO else if VT_UI1 etc. */

    return E_FAIL;
}

Here is the caller graph for this function:

_VariantToJRIObject ( env  ,
vResult,
oResult 
)
free ( args  )
if ( length  )

Definition at line 401 of file LiveConnect.cpp.

    {
        args = (java_lang_Object **) malloc(length * sizeof(java_lang_Object *));
        for (long i = 0; i < length; i++)
        {
             args[i] = reinterpret_cast<java_lang_Object *>(JRI_GetObjectArrayElement(env, b, i));
        }
    }

Definition at line 423 of file LiveConnect.cpp.

    {
        return NULL;
    }
if ( FAILED(hr )

Definition at line 432 of file LiveConnect.cpp.

    { 
        char error[128];
        memset(error, 0, sizeof(error));
        _snprintf(error, sizeof(error) - 1, "getProperty failed, member \"%s\" not found, hr=0x%08x", szMember, hr);
        JRI_ThrowNew(env, class_java_lang_Error(env), error); 
        return NULL; 
    }

Here is the call graph for this function:

if ( FAILED(_JRIObjectToVariant(env, b,&pvars[0]))  )

Definition at line 489 of file LiveConnect.cpp.

    {
        delete []pvars;
        char error[64];
        sprintf(error, "Property value could not be converted into a variant");
        JRI_ThrowNew(env, class_java_lang_Error(env), error); 
        return;
    }
JRI_PUBLIC_API ( struct java_lang_Object *  )
struct java_lang_Throwable struct java_io_PrintStream* a JRI_PUBLIC_API ( struct java_lang_Throwable *  ) [read]

Definition at line 80 of file LiveConnect.cpp.

{
    JRIEnv* env = NPN_GetJavaEnv();
    if (env) {
        // Note: The order of these is important (for some unknown reason)
        //       and was determined through trial and error. Do not rearrange
        //       without testing the new order!
        use_netscape_plugin_Plugin(env);
        jref myClass = (jref) use_MozAxPlugin(env);
        use_java_lang_Error(env);
//        use_java_lang_String(env);
        use_java_lang_Number(env);
        use_java_lang_Boolean(env);
        use_java_lang_Integer(env);
        use_java_lang_Long(env);
//        use_java_lang_Float(env);
//        use_java_lang_Double(env);
        use_java_lang_Character(env);
        return myClass;
    }
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 62 of file LiveConnect.cpp.

{
    JRIEnv* env = NPN_GetJavaEnv();
    if (env) {
        unuse_MozAxPlugin(env);
        unuse_netscape_plugin_Plugin(env);
        unuse_java_lang_Error(env);
//        unuse_java_lang_String(env);
        unuse_java_lang_Number(env);
        unuse_java_lang_Boolean(env);
        unuse_java_lang_Integer(env);
        unuse_java_lang_Long(env);
//        unuse_java_lang_Float(env);
//        unuse_java_lang_Double(env);
        unuse_java_lang_Character(env);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct MozAxPlugin struct java_lang_String struct java_lang_String* b native_MozAxPlugin_xsetProperty2 ( env  ,
self  ,
a  ,
reinterpret_cast< java_lang_Object * > 
) [read]

Variable Documentation

struct MozAxPlugin struct java_lang_String* a

Definition at line 354 of file LiveConnect.cpp.

java_lang_Object ** args = b

Definition at line 354 of file LiveConnect.cpp.

struct MozAxPlugin struct java_lang_String struct java_lang_Object* b

Definition at line 363 of file LiveConnect.cpp.

struct MozAxPlugin struct java_lang_String struct java_lang_Object struct java_lang_Object * c

Definition at line 373 of file LiveConnect.cpp.

Definition at line 503 of file LiveConnect.cpp.

Definition at line 504 of file LiveConnect.cpp.

Definition at line 384 of file LiveConnect.cpp.

IDispatchPtr disp

Definition at line 422 of file LiveConnect.cpp.

DISPID dispid

Definition at line 419 of file LiveConnect.cpp.

DISPID dispIdPut = DISPID_PROPERTYPUT

Definition at line 498 of file LiveConnect.cpp.

DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0}

Definition at line 440 of file LiveConnect.cpp.

DISPPARAMS functionArgs

Definition at line 500 of file LiveConnect.cpp.

struct MozAxPlugin struct java_lang_String struct java_lang_Object *b HRESULT hr = disp->GetIDsOfNames(IID_NULL, &szMember, 1, LOCALE_USER_DEFAULT, &dispid)

Definition at line 416 of file LiveConnect.cpp.

Definition at line 399 of file LiveConnect.cpp.

Definition at line 409 of file LiveConnect.cpp.

Definition at line 455 of file LiveConnect.cpp.

delete [] pvars = new _variant_t[1]

Definition at line 488 of file LiveConnect.cpp.

Definition at line 501 of file LiveConnect.cpp.

Definition at line 502 of file LiveConnect.cpp.

struct java_lang_Throwable struct java_io_PrintStream *a struct java_lang_Throwable *self return self

Definition at line 347 of file LiveConnect.cpp.

OLECHAR FAR * szMember = A2OLE(JRI_GetStringUTFChars(env, a))

Definition at line 430 of file LiveConnect.cpp.

Definition at line 429 of file LiveConnect.cpp.

VARIANT VarResult

Definition at line 468 of file LiveConnect.cpp.

_variant_t vResult

Definition at line 420 of file LiveConnect.cpp.