init_ClassName(env)
. The new
way is to declare use_ClassName(env)
.
jref NPP_GetJavaClass(void) { JRIEnv* env = NPN_GetJavaEnv(); jref myClass = use_JavaTestPlugin(env); /* others that we're using: */ use_netscape_plugin_Plugin(env); use_java_lang_Class(env); use_java_lang_String(env); return myClass; }
You'll need to do this for every class whose methods you call. And
if you need to call a method on a superclass (e.g.
netscape_plugin_Plugin_getPeer(env, p)
), you'll also have
to declare that you're using that superclass
(e.g. use_netscape_plugin_Plugin(env)
).
DEBUG
symbol defined. This will give you much better
error messages if you forget to "use" some class that you're actually
using.
javah
-generated .c
file
(e.g. ClassName.c
) in your project in order to get
the use_ClassName
functions. The
ClassName.c
also defines the stub functions that
are needed to invoke your native methods, but are now placed in an
#ifdef IMPLEMENT_ClassName
. If you're including
ClassName.c
in the DLL that defines the native
methods, you'll need to be sure to #define
IMPLEMENT_ClassName
before compiling this file. We often
define a dummy stub.c
file like this:
#define IMPLEMENT_ClassName #include "_stubs/ClassName.c"
NPP_Shutdown
function you'll want to
declare that you're done using using these classes with
unuse_ClassName(env)
:
void NPP_Shutdown(void) { JRIEnv* env = NPN_GetJavaEnv(); unuse_JavaTestPlugin(env); unuse_netscape_plugin_Plugin(env); unuse_java_lang_Class(env); unuse_java_lang_String(env); }
JRIMethodThunk*
parameters from
your native methods:
/* public native foo(D)D */ JRI_PUBLIC_API(jdouble) native_JavaTestPlugin_foo(JRIEnv* env,struct JavaTestPlugin* self, jdouble d) { return d + 1e10; }
JRI_PUBLIC_API
macro or you'll get a link error on the
PC.
JRI_CopyString
or
JRI_CopyStringUTF
, you'll need to change these to
JRI_GetStringChars
and
JRI_GetStringUTFChars
. These return pointers to garbage
collected strings. You'll need to copy them yourself if you want to
munge the string or keep it longer than you keep the local reference
to the string object.
We had to change these because they were malloc
'ing
the strings and you either needed a JRI free call to free the string,
or you needed to be able to supply your own malloc
procedure. This method avoids the malloc
issue
altogether.
JRI_GetTypeArrayData
macros, you'll need to change
the name to JRI_GetTypeArrayElements
.
This is most likely because you didn't define
IMPLEMENT__ClassName
before compiling the
ClassName.c
file (see above).
This is most likely because the class file for your plug-in wasn't found by the Navigator. JavaScript currently mis-reports this as missing properties rather than a missing class.
The ClassName.class
file should go in a
directory under the Navigator's plug-in directory. Typically this
would be something like
MyCompanyName/MyPackageName/MyClass.class
where there are as many subdirectories as there are packages (with the
same names). Other classes you define and ship should go in similar
subdirectories.
Alternatively, you can package up all the classes into a zip file
(uncompressed) and place this under your plug-in's directory:
MyCompanyName/MyProduct.zip
.
Your installer should do one of these two.
H
. E.g. struct Hjava_lang_String*
becomes
struct java_lang_String*
.
IMPORT_ClassName_methodName
for each method
you intend to use. Now, you get all the methods without having to do
anything.
However, if you're concerned about the bit of global data
used for each method (the "method thunk") then you can eliminate it by
instead defining UNUSED_ClassName_methodName
before compiling the ClassName.c
file.
IMPLEMENT_ClassName
to get at its
private and protected fields and methods from C and C++. Do this
before including the header file, "ClassName.h".
netscape_plugin_Plugin_nativeInstance
field (and
the corresponding get_
and set_
macros) has been
replaced by the netscape_plugin_Plugin_getPeer
method.
init_ClassName
) has change -- now you only have
to do it if you define native methods, not if you also want to access
fields.
NPN_GetJavaInstance
has been
renamed to NPN_GetJavaPeer
.
getWindow
method was added to class
Plugin
and the corresponding C function
netscape_plugin_Plugin_getWindow
was added (in C++,
netscape_plugin_Plugin::getWindow
).
Java_whatever
to
JRI_Whatever
. This includes the calls for
manipulating globals described in this document. Also the type
JavaGlobalRef
becomes JRIGlobalRef
and the
type JavaEnv
becomes JRIEnv
.