NOT PART OF BUILD. Support for most primitive data types in LiveConnect impl.

This commit is contained in:
locka%iol.ie 2002-05-08 13:22:03 +00:00
parent 1a8c17c59a
commit 8a564932c6
4 changed files with 220 additions and 33 deletions

View File

@ -44,6 +44,13 @@
#ifdef MOZ_ACTIVEX_PLUGIN_LIVECONNECT
#include "_gen/java_lang_String.h"
#include "_gen/java_lang_Boolean.h"
#include "_gen/java_lang_Number.h"
#include "_gen/java_lang_Integer.h"
#include "_gen/java_lang_Long.h"
//#include "_gen/java_lang_Double.h"
//#include "_gen/java_lang_Float.h"
#include "_gen/java_lang_Character.h"
#include "_gen/netscape_plugin_Plugin.h"
#include "_gen/MozAxPlugin.h"
#endif
@ -100,6 +107,13 @@ void NPP_Shutdown(void)
unuse_MozAxPlugin(env);
unuse_netscape_plugin_Plugin(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);
}
#endif
@ -117,9 +131,19 @@ jref NPP_GetJavaClass(void)
#ifdef MOZ_ACTIVEX_PLUGIN_LIVECONNECT
JRIEnv* env = NPN_GetJavaEnv();
if (env) {
// use_java_lang_String(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_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;
}
#endif
@ -1123,11 +1147,71 @@ _GetIDispatchFromJRI(JRIEnv *env, struct MozAxPlugin* self, IDispatch **pdisp)
return S_OK;
}
HRESULT
_VariantToJRIObject(JRIEnv *env, VARIANT *v, jref **o)
{
// TODO make a JRI object from a variant
return E_NOTIMPL;
}
HRESULT
_JRIObjectToVariant(java_lang_Object *o, VARIANT *v)
_JRIObjectToVariant(JRIEnv *env, java_lang_Object *o, VARIANT *v)
{
// TODO
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_UI1;
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;
}
@ -1146,25 +1230,40 @@ _InvokeFromJRI(JRIEnv *env, struct MozAxPlugin* self, struct java_lang_String *f
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;
// TODO throw JRI exception
return NULL;
}
}
USES_CONVERSION;
OLECHAR FAR* szMember = A2OLE(funcName);
hr = disp->GetIDsOfNames(IID_NULL, &szMember, 1, LOCALE_USER_DEFAULT, &dispid);
if (FAILED(hr))
{
// TODO throw JRI exception
return NULL;
}
DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
DISPPARAMS dispparams = {NULL, NULL, 0, 0};
dispparams.rgvarg = vargs;
dispparams.cArgs = nargs;
hr = disp->Invoke(
dispid,
IID_NULL,
LOCALE_USER_DEFAULT,
DISPATCH_METHOD,
&dispparamsNoArgs, NULL, NULL, NULL);
&dispparams, NULL, NULL, NULL);
if (FAILED(hr))
{
// TODO throw JRI exception
return NULL;
}
@ -1296,13 +1395,6 @@ native_MozAxPlugin_xgetProperty(JRIEnv* env, struct MozAxPlugin* self, struct ja
extern "C" JRI_PUBLIC_API(void)
native_MozAxPlugin_xsetProperty2(JRIEnv* env, struct MozAxPlugin* self, struct java_lang_String *a, struct java_lang_Object *b)
{
// TODO
}
/*** private native xsetProperty1 (Ljava/lang/String;Ljava/lang/String;)V ***/
extern "C" JRI_PUBLIC_API(void)
native_MozAxPlugin_xsetProperty1(JRIEnv* env, struct MozAxPlugin* self, struct java_lang_String *a, struct java_lang_String *b)
{
HRESULT hr;
DISPID dispid;
@ -1322,10 +1414,13 @@ native_MozAxPlugin_xsetProperty1(JRIEnv* env, struct MozAxPlugin* self, struct j
return;
}
VARIANT *pvars = new VARIANT[1];
VariantInit(&pvars[0]);
pvars->vt = VT_BSTR;
pvars->bstrVal = A2OLE(JRI_GetStringUTFChars(env, b));
_variant_t *pvars = new _variant_t[1];
if (FAILED(_JRIObjectToVariant(env, b, &pvars[0])))
{
delete []pvars;
// TODO throw JRI exception
return;
}
DISPID dispIdPut = DISPID_PROPERTYPUT;
@ -1346,8 +1441,18 @@ native_MozAxPlugin_xsetProperty1(JRIEnv* env, struct MozAxPlugin* self, struct j
if (FAILED(hr))
{
// TODO throw JRI exception
return;
}
}
/*** private native xsetProperty1 (Ljava/lang/String;Ljava/lang/String;)V ***/
extern "C" JRI_PUBLIC_API(void)
native_MozAxPlugin_xsetProperty1(JRIEnv* env, struct MozAxPlugin* self, struct java_lang_String *a, struct java_lang_String *b)
{
native_MozAxPlugin_xsetProperty2(env, self, a, reinterpret_cast<java_lang_Object *>(b));
}
#endif

View File

@ -2,8 +2,14 @@
with the JDK generated code.
*/
// #define NO_JDK
#define IMPLEMENT_MozAxPlugin
#include "_stubs/MozAxPlugin.c"
#include "_stubs/netscape_plugin_Plugin.c"
#include "_stubs/java_lang_String.c"
#include "_stubs/java_lang_Boolean.c"
#include "_stubs/java_lang_Number.c"
#include "_stubs/java_lang_Integer.c"
#include "_stubs/java_lang_Long.c"
//#include "_stubs/java_lang_Double.c"
//#include "_stubs/java_lang_Float.c"
#include "_stubs/java_lang_Character.c"

View File

@ -49,17 +49,20 @@ MOZ_ACTIVEX_PLUGIN_SUPPORT = 1
# MOZ_ACTIVEX_PLUGIN_LIVECONNECT = 1
# Specify where the PluginSDK, Java compiler, header file
# generator and classes live.
# Settings that specify where the PluginSDK, Java compiler (javac or oldjavac),
# Java header file generator (javah) and classes live.
#
# You need the Netscape PluginSDK:
#
# http://home.netscape.com/comprod/development_partners/plugin_api/index.html
#
# You also need a JDK with an oldstyle java compiler. Anything from 1.3 downwards
# should do. See here for various JDK releases:
# You also need a JDK with the old java compiler. Anything from 1.3
# downwards should do. See here for various JDK releases:
#
# http://java.sun.com/products/archive/index.html
#
# You should use the javah found in the plugin SDK because this generates
# the JRI stubs.
!ifdef MOZ_ACTIVEX_PLUGIN_LIVECONNECT
MOZ_PLUGINSDK = C:\m\PluginSDK3
@ -70,15 +73,19 @@ JAVACLASSES = $(MOZ_PLUGINSDK)\classes\java_30.zip
CLASSPATH = $(JAVACLASSES);.
!endif
############
# XPConnect settings
# MOZ_ACTIVEX_PLUGIN_XPCONNECT = 1
# Uncomment these if you wish the plugin to support LiveConnect (Netscape4.x)
# or XPConnect (Netscape 6.x/Mozilla) for scripting purposes.
############
# Other settings
# Path to the Mozilla ActiveX control (some files are copied from there)
MOZCTLSRC=../control
@ -175,22 +182,64 @@ $(DEFFILE) : mkctldef.bat
$(JAVAH) -classpath $(CLASSPATH) -jri -d _gen MozAxPlugin
$(JAVAH) -classpath $(CLASSPATH) -jri -stubs -d _stubs MozAxPlugin
.\_gen\java_lang_Object.h : $(JAVACLASSES)
$(JAVAH) -classpath $(CLASSPATH) -jri -d _gen java.lang.Object
.\_gen\java_lang_Object.h \
.\_stubs\java_lang_Object.c : $(JAVACLASSES)
$(JAVAH) -classpath $(CLASSPATH) -jri -d _gen java.lang.Object
$(JAVAH) -classpath $(CLASSPATH) -jri -stubs -d _stubs java.lang.Object
.\_gen\java_lang_String.h : $(JAVACLASSES)
$(JAVAH) -classpath $(CLASSPATH) -jri -d _gen java.lang.String
.\_gen\java_lang_String.h \
.\_stubs\java_lang_String.c : $(JAVACLASSES)
$(JAVAH) -classpath $(CLASSPATH) -jri -d _gen java.lang.String
$(JAVAH) -classpath $(CLASSPATH) -jri -stubs -d _stubs java.lang.String
.\_gen\netscape_plugin_Plugin.h : $(JAVACLASSES)
$(JAVAH) -classpath $(CLASSPATH) -jri -d _gen netscape.plugin.Plugin
.\_gen\java_lang_Boolean.h \
.\_stubs\java_lang_Boolean.c : $(JAVACLASSES)
$(JAVAH) -classpath $(CLASSPATH) -jri -d _gen java.lang.Boolean
$(JAVAH) -classpath $(CLASSPATH) -jri -stubs -d _stubs java.lang.Boolean
.\_gen\java_lang_Number.h \
.\_stubs\java_lang_Number.c : $(JAVACLASSES)
$(JAVAH) -classpath $(CLASSPATH) -jri -d _gen java.lang.Number
$(JAVAH) -classpath $(CLASSPATH) -jri -stubs -d _stubs java.lang.Number
.\_gen\java_lang_Integer.h \
.\_stubs\java_lang_Integer.c : $(JAVACLASSES)
$(JAVAH) -classpath $(CLASSPATH) -jri -d _gen java.lang.Integer
$(JAVAH) -classpath $(CLASSPATH) -jri -stubs -d _stubs java.lang.Integer
.\_gen\java_lang_Short.h \
.\_stubs\java_lang_Short.c : $(JAVACLASSES)
$(JAVAH) -classpath $(CLASSPATH) -jri -d _gen java.lang.Short
$(JAVAH) -classpath $(CLASSPATH) -jri -stubs -d _stubs java.lang.Short
.\_gen\java_lang_Long.h \
.\_stubs\java_lang_Long.c : $(JAVACLASSES)
$(JAVAH) -classpath $(CLASSPATH) -jri -d _gen java.lang.Long
$(JAVAH) -classpath $(CLASSPATH) -jri -stubs -d _stubs java.lang.Long
.\_gen\java_lang_Double.h \
.\_stubs\java_lang_Double.c : $(JAVACLASSES)
$(JAVAH) -classpath $(CLASSPATH) -jri -d _gen java.lang.Double
$(JAVAH) -classpath $(CLASSPATH) -jri -stubs -d _stubs java.lang.Double
.\_gen\java_lang_Float.h \
.\_stubs\java_lang_Float.c : $(JAVACLASSES)
$(JAVAH) -classpath $(CLASSPATH) -jri -d _gen java.lang.Float
$(JAVAH) -classpath $(CLASSPATH) -jri -stubs -d _stubs java.lang.Float
.\_gen\java_lang_Byte.h \
.\_stubs\java_lang_Byte.c : $(JAVACLASSES)
$(JAVAH) -classpath $(CLASSPATH) -jri -d _gen java.lang.Byte
$(JAVAH) -classpath $(CLASSPATH) -jri -stubs -d _stubs java.lang.Byte
.\_gen\java_lang_Character.h \
.\_stubs\java_lang_Character.c : $(JAVACLASSES)
$(JAVAH) -classpath $(CLASSPATH) -jri -d _gen java.lang.Character
$(JAVAH) -classpath $(CLASSPATH) -jri -stubs -d _stubs java.lang.Character
.\_gen\netscape_plugin_Plugin.h \
.\_stubs\netscape_plugin_Plugin.c : $(JAVACLASSES)
$(JAVAH) -classpath $(CLASSPATH) -jri -d _gen netscape.plugin.Plugin
$(JAVAH) -classpath $(CLASSPATH) -jri -stubs -d _stubs netscape.plugin.Plugin
!endif
@ -213,6 +262,13 @@ javastubs.c : \
.\_stubs\netscape_plugin_Plugin.c \
.\_stubs\java_lang_Object.c \
.\_stubs\java_lang_String.c \
.\_stubs\java_lang_Boolean.c \
.\_stubs\java_lang_Number.c \
.\_stubs\java_lang_Integer.c \
.\_stubs\java_lang_Long.c \
.\_stubs\java_lang_Double.c \
.\_stubs\java_lang_Float.c \
.\_stubs\java_lang_Character.c \
$(NULL)
!endif
@ -225,6 +281,13 @@ LegacyPlugin.cpp: StdAfx.h \
.\_gen\netscape_plugin_Plugin.h \
.\_gen\java_lang_Object.h \
.\_gen\java_lang_String.h \
.\_gen\java_lang_Boolean.h \
.\_gen\java_lang_Number.h \
.\_gen\java_lang_Integer.h \
.\_gen\java_lang_Long.h \
.\_gen\java_lang_Double.h \
.\_gen\java_lang_Float.h \
.\_gen\java_lang_Character.h \
!endif
$(NULL)

View File

@ -31,6 +31,10 @@ installed to see anything</p>
<form action="#" method="post">
<input type="button" value="<< Last Month" onclick="prevMonth()"></input>
<input type="button" value="Next Month >>" onclick="nextMonth()"></input><br>
<input type="button" value="<< Last Day" onclick="prevDay()"></input>
<input type="button" value="Next Day >>" onclick="nextDay()"></input><br>
Change the current day: <input name="day_to_set" type="text" size="3" value="1"></input>
<input type="button" value="Set" onclick="setDay()"></input><br>
<input type="button" value="Sanity test" onclick="document.cal.x(1)"></input>
</form>
<p>
@ -40,15 +44,24 @@ installed to see anything</p>
document.write("<p>Plugin window =" + document.cal.getWindow() + "</p>");
function prevMonth()
{
// document.cal.x(1);
document.cal.invoke("previousMonth");
}
function nextMonth()
{
// document.cal.x();
document.cal.invoke("nextMonth");
}
function prevDay()
{
document.cal.invoke("previousDay");
}
function nextDay()
{
document.cal.invoke("nextDay");
}
function setDay()
{
document.cal.setProperty("day", document.forms[0].elements["day_to_set"].value);
}
</script>
</p>