Skip to content

Commit

Permalink
added android support for npsimple
Browse files Browse the repository at this point in the history
  • Loading branch information
anselm authored and anselm committed Dec 14, 2009
1 parent 73efee7 commit 0304b3c
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 14 deletions.
55 changes: 55 additions & 0 deletions Android.mk
@@ -0,0 +1,55 @@
# general settings
OS = android
NDK_BASE = ${HOME}/android/ndk
ANDROID_HOME = ${HOME}/android/mydroid
INCS = -I$(ANDROID_HOME)/dalvik/libnativehelper/include/nativehelper \
-I$(NDK_BASE)/include/bionic/arch-arm/include \
-I$(NDK_BASE)/include/bionic/include \
-I$(NDK_BASE)/include/kernel/include \
-I$(NDK_BASE)/include/libm/include \
-I$(NDK_BASE)/include/libm/include/arm \
-I$(NDK_BASE)/include/libstdc++/include \
-I$(ANDROID_HOME)/external/webkit/WebCore/bridge \
-I$(ANDROID_HOME)/external/webkit/WebCore/plugins \
-I$(ANDROID_HOME)/system/core/include \
-I$(ANDROID_HOME)/frameworks/base/include

# flags
#CPPFLAGS += -DUNIX -DANDROID -DHAVE_CONFIG_H -D_DEBUG=1 -DAAPCS -D_GNU_SOURCE -DNOUNCRYPT
CPPFLAGS += -DUNIX -DANDROID -DHAVE_CONFIG_H -DAAPCS -D_GNU_SOURCE -DNOUNCRYPT
CFLAGS += -Os -fno-exceptions -static -c -fpic ${INCS} ${CPPFLAGS}
EXPAT_CFLAGS += -DHAVE_MEMMOVE
LDFLAGS = -fPIC -nostdlib -Wl,-soname,npsimple.so -Wl,-shared,-Bsymbolic -shared -Wl,--gc-sections --Wl,--wrap,__aeabi_atexit
LIBS = -L$(NDK_BASE)/lib -lc -lm -ldl
ALIB = $(NDK_BASE)/toolchain/lib/gcc/arm-eabi/4.2.1/interwork/libgcc.a
POSTLINK = -Wl,--no-undefined $(ALIB)

# compiler and linker
AR = $(NDK_BASE)/toolchain/bin/arm-eabi-ar
CC = $(NDK_BASE)/toolchain/bin/arm-eabi-g++
LD = $(NDK_BASE)/toolchain/bin/arm-eabi-ld
MAKE = make

SRC = npsimple.c
OBJ += ${SRC:.c=.o}

all: options npsimple.so

options:
@echo "OS = ${OS}"
@echo "CC = ${CC}"
@echo "CFLAGS = ${CFLAGS}"
@echo "LDFLAGS = ${LDFLAGS}"

%.o : %.c
@echo CC $<
@${CC} ${CFLAGS} -o $@ -c $<

npsimple.so: ${OBJ}
@echo LINK -o $@ ${LDFLAGS} $^ $(LIBS) ${POSTLINK}
@${CC} -o $@ ${LDFLAGS} $^ $(LIBS) ${POSTLINK}

clean:
rm -f npsimple.so ${OBJ}

.PHONY: options all clean
2 changes: 1 addition & 1 deletion config.mk
Expand Up @@ -7,7 +7,7 @@ ifeq (${shell uname}, Darwin)
CPPFLAGS = -DVERSION=\"${VERSION}\" -DWEBKIT_DARWIN_SDK
LDFLAGS = -dynamiclib #-framework Carbon -framework CoreFoundation -framework WebKit
else
INCS = -I/usr/include/xulrunner-1.9/stable # apt-get install xulrunner-dev
INCS = -I/home/anselm/aplix/code/third_party/xulrunner-sdk # apt-get install xulrunner-dev
CPPFLAGS = -DVERSION=\"${VERSION}\" -DXULRUNNER_SDK
#LDFLAGS = -L/usr/lib -lc
endif
Expand Down
65 changes: 52 additions & 13 deletions npsimple.c
Expand Up @@ -20,28 +20,50 @@
#include <npapi.h>
#include <npupp.h>
#include <npruntime.h>
#elif defined(ANDROID)

#undef HAVE_LONG_LONG
#include <jni.h>
#include <npapi.h>
#include <npfunctions.h>
#include <npruntime.h>
#define OSCALL
#define NPP_WRITE_TYPE (NPP_WriteProcPtr)
#define NPStringText UTF8Characters
#define NPStringLen UTF8Length
extern JNIEnv *pluginJniEnv;

#elif defined(WEBKIT_DARWIN_SDK)

#include <Webkit/npapi.h>
#include <WebKit/npfunctions.h>
#include <WebKit/npruntime.h>
#define OSCALL

#elif defined(WEBKIT_WINMOBILE_SDK) /* WebKit SDK on Windows */

#ifndef PLATFORM
#define PLATFORM(x) defined(x)
#endif
#include <npfunctions.h>
#ifndef OSCALL
#define OSCALL WINAPI
#endif

#endif

static NPObject *so = NULL;
static NPObject *so = NULL;
static NPNetscapeFuncs *npnfuncs = NULL;
static NPP inst = NULL;

/* NPN */

static void logmsg(const char *msg) {
#ifndef _WINDOWS
#if defined(ANDROID)
FILE *out = fopen("/sdcard/npsimple.log", "a");
fputs(msg, out);
fclose(out);
#elif !defined(_WINDOWS)
fputs(msg, stderr);
#else
FILE *out = fopen("\\npsimple.log", "a");
Expand All @@ -67,15 +89,26 @@ invokeDefault(NPObject *obj, const NPVariant *args, uint32_t argCount, NPVariant
static bool
invoke(NPObject* obj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result) {
logmsg("npsimple: invoke\n");
int error = 1;
char *name = npnfuncs->utf8fromidentifier(methodName);
if(name && !strcmp((const char *)name, "foo")) {
return invokeDefault(obj, args, argCount, result);
}
else {
// aim exception handling
npnfuncs->setexception(obj, "exception during invocation");
return false;
if(name) {
if(!strcmp(name, "foo")) {
logmsg("npsimple: invoke foo\n");
return invokeDefault(obj, args, argCount, result);
}
else if(!strcmp(name, "callback")) {
if(argCount == 1 && args[0].type == NPVariantType_Object) {
static NPVariant v, r;

logmsg("npsimple: invoke callback function\n");
INT32_TO_NPVARIANT(42, v);
return npnfuncs->invokeDefault(inst, NPVARIANT_TO_OBJECT(args[0]), &v, 1, &r);
}
}
}
// aim exception handling
npnfuncs->setexception(obj, "exception during invocation");
return false;
}

static bool
Expand Down Expand Up @@ -108,6 +141,7 @@ static NPClass npcRefObject = {

static NPError
nevv(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char *argn[], char *argv[], NPSavedData *saved) {
inst = instance;
logmsg("npsimple: new\n");
return NPERR_NO_ERROR;
}
Expand All @@ -123,6 +157,7 @@ destroy(NPP instance, NPSavedData **save) {

static NPError
getValue(NPP instance, NPPVariable variable, void *value) {
inst = instance;
switch(variable) {
default:
logmsg("npsimple: getvalue - default\n");
Expand Down Expand Up @@ -154,12 +189,14 @@ getValue(NPP instance, NPPVariable variable, void *value) {

static NPError /* expected by Safari on Darwin */
handleEvent(NPP instance, void *ev) {
inst = instance;
logmsg("npsimple: handleEvent\n");
return NPERR_NO_ERROR;
}

static NPError /* expected by Opera */
setWindow(NPP instance, NPWindow* pNPWindow) {
inst = instance;
logmsg("npsimple: setWindow\n");
return NPERR_NO_ERROR;
}
Expand Down Expand Up @@ -188,11 +225,12 @@ NP_GetEntryPoints(NPPluginFuncs *nppfuncs) {

NPError OSCALL
NP_Initialize(NPNetscapeFuncs *npnf
#if !defined(_WINDOWS) && !defined(WEBKIT_DARWIN_SDK)
, NPPluginFuncs *nppfuncs)
#else
)
#if defined(ANDROID)
, NPPluginFuncs *nppfuncs, JNIEnv *env, jobject plugin_object
#elif !defined(_WINDOWS) && !defined(WEBKIT_DARWIN_SDK)
, NPPluginFuncs *nppfuncs
#endif
)
{
logmsg("npsimple: NP_Initialize\n");
if(npnf == NULL)
Expand Down Expand Up @@ -222,6 +260,7 @@ NP_GetMIMEDescription(void) {

NPError OSCALL /* needs to be present for WebKit based browsers */
NP_GetValue(void *npp, NPPVariable variable, void *value) {
inst = (NPP)npp;
return getValue((NPP)npp, variable, value);
}

Expand Down

0 comments on commit 0304b3c

Please sign in to comment.