extern ANPLogInterfaceV0 gLogI;
extern ANPPaintInterfaceV0 gPaintI;
extern ANPSurfaceInterfaceV0 gSurfaceI;
+extern ANPSystemInterfaceV0 gSystemI;
extern ANPTypefaceInterfaceV0 gTypefaceI;
#define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0]))
test_bitmaps(); // android bitmaps
test_domAccess();
test_javascript();
+ test_loadJavaClass();
}
BackgroundPlugin::~BackgroundPlugin() {
// free the memory allocated within the browser
browser->memfree(stringMem);
}
+
+///////////////////////////////////////////////////////////////////////////////
+// Load Java Classes Tests
+///////////////////////////////////////////////////////////////////////////////
+
+void BackgroundPlugin::test_loadJavaClass() {
+
+ JNIEnv* env = NULL;
+ if (gVM->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
+ gLogI.log(inst(), kError_ANPLogType, " ---- LoadJavaTest: failed to get env");
+ return;
+ }
+
+ const char* className = "com.android.sampleplugin.BackgroundTest";
+ jclass backgroundClass = gSystemI.loadJavaClass(inst(), className);
+
+ if(!backgroundClass) {
+ gLogI.log(inst(), kError_ANPLogType, " ---- LoadJavaTest: failed to load class");
+ return;
+ }
+
+ jmethodID constructor = env->GetMethodID(backgroundClass, "<init>", "()V");
+ jmethodID addMethod = env->GetMethodID(backgroundClass, "addInt", "(II)I");
+ jobject backgroundObject = env->NewObject(backgroundClass, constructor);
+
+ if(!backgroundObject) {
+ gLogI.log(inst(), kError_ANPLogType, " ---- LoadJavaTest: failed to construct object");
+ return;
+ }
+
+ jint result = env->CallIntMethod(backgroundObject, addMethod, 2, 2);
+
+ if (result != 4) {
+ gLogI.log(inst(), kError_ANPLogType, " ---- LoadJavaTest: invalid result (%d != 4)", result);
+ }
+}
// Scripting functions appeared in NPAPI version 14
if (browser->version >= 14) {
- instance->pdata = browser->createobject (instance, getPluginClass());
- obj = static_cast<PluginObject*>(instance->pdata);
- bzero(obj, sizeof(*obj));
+ instance->pdata = browser->createobject (instance, getPluginClass());
+ obj = static_cast<PluginObject*>(instance->pdata);
}
/* END: STANDARD PLUGIN FRAMEWORK */
PluginObject *obj = (PluginObject*) instance->pdata;
if (obj)
- browser->retainobject((NPObject*)obj);
+ browser->retainobject(&obj->header);
- *v = obj;
+ *v = &(obj->header);
return NPERR_NO_ERROR;
}