int16_t VideoPlugin::handleEvent(const ANPEvent* evt) { switch (evt->eventType) { case kLifecycle_ANPEventType: { switch (evt->data.lifecycle.action) { case kEnterFullScreen_ANPLifecycleAction: gLogI.log(kDebug_ANPLogType, " ---- %p entering fullscreen", inst()); break; case kExitFullScreen_ANPLifecycleAction: gLogI.log(kDebug_ANPLogType, " ---- %p exiting fullscreen", inst()); break; } break; // end kLifecycle_ANPEventType } case kDraw_ANPEventType: gLogI.log(kError_ANPLogType, " ------ %p the plugin did not request draw events", inst()); break; case kTouch_ANPEventType: if (kDown_ANPTouchAction == evt->data.touch.action) { gLogI.log(kDebug_ANPLogType, " ------ %p requesting fullscreen mode", inst()); gWindowI.requestFullScreen(inst()); } return 1; case kKey_ANPEventType: gLogI.log(kError_ANPLogType, " ------ %p the plugin did not request key events", inst()); break; default: break; } return 0; // unknown or unhandled event }
void BackgroundPlugin::test_loadJavaClass() { JNIEnv* env = NULL; if (gVM->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { gLogI.log(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(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(kError_ANPLogType, " ---- LoadJavaTest: failed to construct object"); return; } jint result = env->CallIntMethod(backgroundObject, addMethod, 2, 2); if (result != 4) { gLogI.log(kError_ANPLogType, " ---- LoadJavaTest: invalid result (%d != 4)", result); } }
static void test_formats(NPP instance) { // TODO pull names from enum in npapi instead of hardcoding them static const struct { ANPBitmapFormat fFormat; const char* fName; } gRecs[] = { { kUnknown_ANPBitmapFormat, "unknown" }, { kRGBA_8888_ANPBitmapFormat, "8888" }, { kRGB_565_ANPBitmapFormat, "565" }, }; ANPPixelPacking packing; for (size_t i = 0; i < ARRAY_COUNT(gRecs); i++) { if (gBitmapI.getPixelPacking(gRecs[i].fFormat, &packing)) { gLogI.log(kDebug_ANPLogType, "pixel format [%d] %s has packing ARGB [%d %d] [%d %d] [%d %d] [%d %d]\n", gRecs[i].fFormat, gRecs[i].fName, packing.AShift, packing.ABits, packing.RShift, packing.RBits, packing.GShift, packing.GBits, packing.BShift, packing.BBits); } else { gLogI.log(kDebug_ANPLogType, "pixel format [%d] %s has no packing\n", gRecs[i].fFormat, gRecs[i].fName); } } }
int16_t BackgroundPlugin::handleEvent(const ANPEvent* evt) { switch (evt->eventType) { case kDraw_ANPEventType: gLogI.log(kError_ANPLogType, " ------ %p the plugin did not request draw events", inst()); break; case kLifecycle_ANPEventType: switch (evt->data.lifecycle.action) { case kOnLoad_ANPLifecycleAction: gLogI.log(kDebug_ANPLogType, " ------ %p onLoad", inst()); return 1; case kOnScreen_ANPLifecycleAction: gLogI.log(kDebug_ANPLogType, " ------ %p onScreen", inst()); return 1; case kOffScreen_ANPLifecycleAction: gLogI.log(kDebug_ANPLogType, " ------ %p offScreen", inst()); return 1; } break; // end kLifecycle_ANPEventType case kTouch_ANPEventType: if (kLongPress_ANPTouchAction == evt->data.touch.action) { browser->geturl(inst(), "javascript:alert('Detected long press event.')", 0); gWindowI.requestFullScreen(inst()); } else if (kDoubleTap_ANPTouchAction == evt->data.touch.action) browser->geturl(inst(), "javascript:alert('Detected double tap event.')", 0); break; case kKey_ANPEventType: gLogI.log(kError_ANPLogType, " ------ %p the plugin did not request key events", inst()); break; default: break; } return 0; // unknown or unhandled event }
jobject BackgroundPlugin::getSurface() { if (m_surface) { return m_surface; } // load the appropriate java class and instantiate it JNIEnv* env = NULL; if (gVM->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { gLogI.log(kError_ANPLogType, " ---- getSurface: failed to get env"); return NULL; } const char* className = "com.android.sampleplugin.BackgroundSurface"; jclass backgroundClass = gSystemI.loadJavaClass(inst(), className); if(!backgroundClass) { gLogI.log(kError_ANPLogType, " ---- getSurface: failed to load class"); return NULL; } jmethodID constructor = env->GetMethodID(backgroundClass, "<init>", "(Landroid/content/Context;)V"); jobject backgroundSurface = env->NewObject(backgroundClass, constructor, m_context); if(!backgroundSurface) { gLogI.log(kError_ANPLogType, " ---- getSurface: failed to construct object"); return NULL; } m_surface = env->NewGlobalRef(backgroundSurface); return m_surface; }
jobject PaintPlugin::getSurface() { if (m_surface) { return m_surface; } // load the appropriate java class and instantiate it JNIEnv* env = NULL; if (gVM->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { gLogI.log(kError_ANPLogType, " ---- getSurface: failed to get env"); return NULL; } const char* className = "com.android.sampleplugin.PaintSurface"; jclass paintClass = gSystemI.loadJavaClass(inst(), className); if(!paintClass) { gLogI.log(kError_ANPLogType, " ---- getSurface: failed to load class"); return NULL; } PluginObject *obj = (PluginObject*) inst()->pdata; const int pW = obj->window->width; const int pH = obj->window->height; jmethodID constructor = env->GetMethodID(paintClass, "<init>", "(Landroid/content/Context;III)V"); jobject paintSurface = env->NewObject(paintClass, constructor, m_context, (int)inst(), pW, pH); if(!paintSurface) { gLogI.log(kError_ANPLogType, " ---- getSurface: failed to construct object"); return NULL; } m_surface = env->NewGlobalRef(paintSurface); return m_surface; }
NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved) { gLogI.log(instance, kDebug_ANPLogType, "creating plugin"); PluginObject *obj = NULL; // 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)); } else { return NPERR_GENERIC_ERROR; } // select the drawing model ANPDrawingModel model = kBitmap_ANPDrawingModel; // notify the plugin API of the drawing model we wish to use. This must be // done prior to creating certain subPlugin objects (e.g. surfaceViews) NPError err = browser->setvalue(instance, kRequestDrawingModel_ANPSetValue, reinterpret_cast<void*>(model)); if (err) { gLogI.log(instance, kError_ANPLogType, "request model %d err %d", model, err); return err; } // create the sub-plugin obj->subPlugin = new EventPlugin(instance); return NPERR_NO_ERROR; }
void BackgroundPlugin::test_javascript() { NPP instance = this->inst(); gLogI.log(kDebug_ANPLogType, " ------ %p Testing JavaScript Access", instance); // Get the plugin's DOM object NPObject* windowObject = NULL; browser->getvalue(instance, NPNVWindowNPObject, &windowObject); if (!windowObject) gLogI.log(kError_ANPLogType, " ------ %p Unable to retrieve DOM Window", instance); // create a string (JS code) that is stored in memory allocated by the browser const char* jsString = "1200 + 34"; void* stringMem = browser->memalloc(strlen(jsString)); memcpy(stringMem, jsString, strlen(jsString)); // execute the javascript in the plugin's DOM object NPString script = { (char*)stringMem, strlen(jsString) }; NPVariant scriptVariant; if (!browser->evaluate(instance, windowObject, &script, &scriptVariant)) gLogI.log(kError_ANPLogType, " ------ %p Unable to eval the JS.", instance); if (scriptVariant.type == NPVariantType_Int32) { if (scriptVariant.value.intValue != 1234) gLogI.log(kError_ANPLogType, " ------ %p Invalid Value for JS Return: %d,1234", instance, scriptVariant.value.intValue); } else { gLogI.log(kError_ANPLogType, " ------ %p Invalid Variant type for JS Return: %d,%d", instance, scriptVariant.type, NPVariantType_Int32); } // free the memory allocated within the browser browser->memfree(stringMem); }
void BackgroundPlugin::test_logging() { NPP instance = this->inst(); //LOG_ERROR(instance, " ------ %p Testing Log Error", instance); gLogI.log(kError_ANPLogType, " ------ %p Testing Log Error", instance); gLogI.log(kWarning_ANPLogType, " ------ %p Testing Log Warning", instance); gLogI.log(kDebug_ANPLogType, " ------ %p Testing Log Debug", instance); }
static void surfaceDestroyed(JNIEnv* jniEnv, jobject thiz, jint npp) { // give up all handles to the VM and any VM objects! NPP instance = (NPP)npp; if(!instance) return; gLogI.log(instance, kDebug_ANPLogType, "jni-bridge surfaceDestroyed() instance=%p ...",instance); /* SurfaceSubPlugin* obj = getPluginObject(npp); if(obj) obj->surfaceDestroyed(); // call PaintPlugin.cpp surfaceDestroyed() */ if(instance->pdata!=NULL) { PluginObject* plugin = static_cast<PluginObject*>(instance->pdata); gLogI.log(instance, kDebug_ANPLogType, "jni-bridge surfaceDestroyed() plugin=%p",plugin); /* if(plugin) { if((int)plugin<0x10000) { gLogI.log(instance, kDebug_ANPLogType, "jni-bridge surfaceDestroyed() plugin<0x10000 ############################################"); return; } gLogI.log(instance, kDebug_ANPLogType, "jni-bridge surfaceDestroyed() plugin->dexLoaderClass=%p",plugin->dexLoaderClass); // call applet stop() via DexLoader.callstop() if(plugin->dexLoaderClass && !needDexInit) { const char* stopMethodName = "callStop"; gLogI.log(instance, kDebug_ANPLogType, "jni-bridge surfaceDestroyed() GetStaticMethodID(%s)...",stopMethodName); jmethodID stopMethod = jniEnv->GetStaticMethodID(plugin->dexLoaderClass, stopMethodName, "()V"); if(stopMethod == NULL) { gLogI.log(instance, kError_ANPLogType, "jni-bridge surfaceCreated() JavaVM unable to find %s() via dexLoaderClass ################################################", stopMethodName); } else { jniEnv->CallStaticVoidMethod(plugin->dexLoaderClass, stopMethod, NULL); } } } */ } needDexInit=true; gLogI.log(instance, kDebug_ANPLogType, "jni-bridge surfaceDestroyed done"); }
void BackgroundPlugin::drawPlugin(int surfaceWidth, int surfaceHeight) { // get the plugin's dimensions according to the DOM PluginObject *obj = (PluginObject*) inst()->pdata; const int W = obj->window->width; const int H = obj->window->height; // compute the current zoom level const float zoomFactorW = static_cast<float>(surfaceWidth) / W; const float zoomFactorH = static_cast<float>(surfaceHeight) / H; // check to make sure the zoom level is uniform if (zoomFactorW + .01 < zoomFactorH && zoomFactorW - .01 > zoomFactorH) gLogI.log(kError_ANPLogType, " ------ %p zoom is out of sync (%f,%f)", inst(), zoomFactorW, zoomFactorH); // scale the variables based on the zoom level const int fontSize = (int)(zoomFactorW * 16); const int leftMargin = (int)(zoomFactorW * 10); // lock the surface ANPBitmap bitmap; JNIEnv* env = NULL; if (!m_surface || gVM->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK || !gSurfaceI.lock(env, m_surface, &bitmap, NULL)) { gLogI.log(kError_ANPLogType, " ------ %p unable to lock the plugin", inst()); return; } // create a canvas ANPCanvas* canvas = gCanvasI.newCanvas(&bitmap); gCanvasI.drawColor(canvas, 0xFFFFFFFF); ANPPaint* paint = gPaintI.newPaint(); gPaintI.setFlags(paint, gPaintI.getFlags(paint) | kAntiAlias_ANPPaintFlag); gPaintI.setColor(paint, 0xFFFF0000); gPaintI.setTextSize(paint, fontSize); ANPTypeface* tf = gTypefaceI.createFromName("serif", kItalic_ANPTypefaceStyle); gPaintI.setTypeface(paint, tf); gTypefaceI.unref(tf); ANPFontMetrics fm; gPaintI.getFontMetrics(paint, &fm); gPaintI.setColor(paint, 0xFF0000FF); const char c[] = "This is a background plugin."; gCanvasI.drawText(canvas, c, sizeof(c)-1, leftMargin, -fm.fTop, paint); // clean up variables and unlock the surface gPaintI.deletePaint(paint); gCanvasI.deleteCanvas(canvas); gSurfaceI.unlock(env, m_surface); }
void AudioPlugin::handleTouch(int x, int y) { NPP instance = this->inst(); // if the track is null then return if (NULL == m_soundPlay->track) { gLogI.log(kError_ANPLogType, "---- %p unable to create track", instance); return; } // check to make sure the currentRect matches the activeRect ANPRectF* currentRect = validTouch(x,y); if (m_activeTouchRect != currentRect) return; if (currentRect == &m_playRect) { gLogI.log(kDebug_ANPLogType, "---- %p starting track (%d)", m_soundPlay->track, gSoundI.isStopped(m_soundPlay->track)); if (gSoundI.isStopped(m_soundPlay->track)) { gSoundI.start(m_soundPlay->track); } } else if (currentRect == &m_pauseRect) { gLogI.log(kDebug_ANPLogType, "---- %p pausing track (%d)", m_soundPlay->track, gSoundI.isStopped(m_soundPlay->track)); if (!gSoundI.isStopped(m_soundPlay->track)) { gSoundI.pause(m_soundPlay->track); } } else if (currentRect == &m_stopRect) { gLogI.log(kDebug_ANPLogType, "---- %p stopping track (%d)", m_soundPlay->track, gSoundI.isStopped(m_soundPlay->track)); if (!gSoundI.isStopped(m_soundPlay->track)) { gSoundI.stop(m_soundPlay->track); } if (m_soundPlay->file) { fseek(m_soundPlay->file, 0, SEEK_SET); } } else { gLogI.log(kDebug_ANPLogType, "---- touch x:%d, y:%d ", x, y); return; } // set the currentRect to be the activeRect m_activeRect = currentRect; inval(instance); }
bool NavigationPlugin::handleNavigation(ANPKeyCode keyCode) { NPP instance = this->inst(); gLogI.log(kDebug_ANPLogType, "----%p Received Key %d", instance, keyCode); switch (keyCode) { case kDpadUp_ANPKeyCode: m_activeNav = &m_navUp; break; case kDpadDown_ANPKeyCode: m_activeNav = &m_navDown; break; case kDpadLeft_ANPKeyCode: m_activeNav = &m_navLeft; break; case kDpadRight_ANPKeyCode: m_activeNav = &m_navRight; break; case kDpadCenter_ANPKeyCode: m_activeNav = &m_navCenter; break; case kQ_ANPKeyCode: case kDel_ANPKeyCode: m_activeNav = NULL; return false; default: m_activeNav = NULL; break; } return true; }
BackgroundPlugin::BackgroundPlugin(NPP inst) : SurfaceSubPlugin(inst) { // initialize the drawing surface m_surface = NULL; //initialize bitmap transparency variables mFinishedStageOne = false; mFinishedStageTwo = false; mFinishedStageThree = false; // test basic plugin functionality test_logging(); // android logging test_timers(); // plugin timers test_bitmaps(); // android bitmaps test_domAccess(); test_javascript(); test_loadJavaClass(); //register for touch events ANPEventFlags flags = kTouch_ANPEventFlag; NPError err = browser->setvalue(inst, kAcceptEvents_ANPSetValue, &flags); if (err != NPERR_NO_ERROR) { gLogI.log(kError_ANPLogType, "Error selecting input events."); } }
NPError NPP_GetValue(NPP instance, NPPVariable variable, void* value) { if (variable == NPPVpluginScriptableNPObject) { void **v = (void **)value; PluginObject *obj = (PluginObject*) instance->pdata; if (obj) browser->retainobject(&obj->header); *v = &(obj->header); return NPERR_NO_ERROR; } if (variable == kJavaSurface_ANPGetValue) { //get the surface sub-plugin PluginObject* obj = static_cast<PluginObject*>(instance->pdata); if (obj && obj->activePlugin) { if(obj->activePlugin->supportsDrawingModel(kSurface_ANPDrawingModel) || obj->activePlugin->supportsDrawingModel(kOpenGL_ANPDrawingModel)) { SurfaceSubPlugin* plugin = static_cast<SurfaceSubPlugin*>(obj->activePlugin); jobject* surface = static_cast<jobject*>(value); *surface = plugin->getSurface(); return NPERR_NO_ERROR; } else { gLogI.log(kError_ANPLogType, "-- %p Tried to retrieve surface for non-surface plugin", instance); } } } return NPERR_GENERIC_ERROR; }
bool FormPlugin::handleNavigation(ANPKeyCode keyCode) { NPP instance = this->inst(); gLogI.log(kDebug_ANPLogType, "----%p Recvd Nav Key %d", instance, keyCode); if (!m_activeInput) { gWindowI.showKeyboard(instance, true); switchActiveInput(&m_usernameInput); } else if (m_activeInput == &m_usernameInput) { if (keyCode == kDpadDown_ANPKeyCode) { switchActiveInput(&m_passwordInput); } else if (keyCode == kDpadCenter_ANPKeyCode) gWindowI.showKeyboard(instance, false); else if (keyCode == kDpadUp_ANPKeyCode) return false; } else if (m_activeInput == &m_passwordInput) { if (keyCode == kDpadUp_ANPKeyCode) { switchActiveInput(&m_usernameInput); } else if (keyCode == kDpadCenter_ANPKeyCode) gWindowI.showKeyboard(instance, false); else if (keyCode == kDpadDown_ANPKeyCode) return false; } return true; }
int16_t NavigationPlugin::handleEvent(const ANPEvent* evt) { NPP instance = this->inst(); switch (evt->eventType) { case kDraw_ANPEventType: switch (evt->data.draw.model) { case kBitmap_ANPDrawingModel: drawPlugin(evt->data.draw.data.bitmap, evt->data.draw.clip); return 1; default: break; // unknown drawing model } break; case kLifecycle_ANPEventType: if (evt->data.lifecycle.action == kLoseFocus_ANPLifecycleAction) { gLogI.log(kDebug_ANPLogType, "----%p Loosing Focus", instance); m_hasFocus = false; inval(instance); return 1; } else if (evt->data.lifecycle.action == kGainFocus_ANPLifecycleAction) { gLogI.log(kDebug_ANPLogType, "----%p Gaining Focus", instance); m_hasFocus = true; inval(instance); return 1; } break; case kMouse_ANPEventType: return 1; case kKey_ANPEventType: if (evt->data.key.action == kDown_ANPKeyAction) { bool result = handleNavigation(evt->data.key.nativeCode); inval(instance); return result; } return 1; default: break; } return 0; // unknown or unhandled event }
static void timer_repeat(NPP instance, uint32_t timerID) { BackgroundPlugin *obj = ((BackgroundPlugin*) ((PluginObject*) instance->pdata)->activePlugin); gLogI.log(kDebug_ANPLogType, "-------- repeat timer %d\n", obj->mTimerRepeatCount); if (--obj->mTimerRepeatCount == 0) { browser->unscheduletimer(instance, timerID); } }
int16_t AudioPlugin::handleEvent(const ANPEvent* evt) { //NPP instance = this->inst(); gLogI.log(kError_ANPLogType, "AudioPlugin::handleEvent:%d, action:%d", evt->eventType, evt->data.touch.action); switch (evt->eventType) { case kDraw_ANPEventType: switch (evt->data.draw.model) { case kBitmap_ANPDrawingModel: drawPlugin(evt->data.draw.data.bitmap, evt->data.draw.clip); return 1; default: break; // unknown drawing model } case kTouch_ANPEventType: case kMultiTouch_ANPEventType: { int x = evt->data.touch.x; int y = evt->data.touch.y; gLogI.log(kError_ANPLogType, "kTouch_ANPEventType:x:%d, y%d", x, y); if (kDown_ANPTouchAction == evt->data.touch.action) { m_activeTouchRect = validTouch(x,y); if(m_activeTouchRect) { m_activeTouch = true; return 1; } } else if (kUp_ANPTouchAction == evt->data.touch.action && m_activeTouch) { handleTouch(x, y); m_activeTouch = false; return 1; } else if (kCancel_ANPTouchAction == evt->data.touch.action) { m_activeTouch = false; } break; } default: break; } return 0; // unknown or unhandled event }
PaintPlugin::PaintPlugin(NPP inst) : SurfaceSubPlugin(inst) { m_isTouchActive = false; m_isTouchCurrentInput = true; m_activePaintColor = s_redColor; memset(&m_drawingSurface, 0, sizeof(m_drawingSurface)); memset(&m_inputToggle, 0, sizeof(m_inputToggle)); memset(&m_colorToggle, 0, sizeof(m_colorToggle)); memset(&m_fullScreenToggle, 0, sizeof(m_fullScreenToggle)); memset(&m_clearSurface, 0, sizeof(m_clearSurface)); // initialize the drawing surface m_surface = NULL; // initialize the path m_touchPath = gPathI.newPath(); if(!m_touchPath) gLogI.log(kError_ANPLogType, "----%p Unable to create the touch path", inst); // initialize the paint colors m_paintSurface = gPaintI.newPaint(); gPaintI.setFlags(m_paintSurface, gPaintI.getFlags(m_paintSurface) | kAntiAlias_ANPPaintFlag); gPaintI.setColor(m_paintSurface, 0xFFC0C0C0); gPaintI.setTextSize(m_paintSurface, 18); m_paintButton = gPaintI.newPaint(); gPaintI.setFlags(m_paintButton, gPaintI.getFlags(m_paintButton) | kAntiAlias_ANPPaintFlag); gPaintI.setColor(m_paintButton, 0xFFA8A8A8); // initialize the typeface (set the colors) ANPTypeface* tf = gTypefaceI.createFromName("serif", kItalic_ANPTypefaceStyle); gPaintI.setTypeface(m_paintSurface, tf); gTypefaceI.unref(tf); //register for touch events ANPEventFlags flags = kTouch_ANPEventFlag; NPError err = browser->setvalue(inst, kAcceptEvents_ANPSetValue, &flags); if (err != NPERR_NO_ERROR) { gLogI.log(kError_ANPLogType, "Error selecting input events."); } }
void BackgroundPlugin::test_domAccess() { NPP instance = this->inst(); gLogI.log(kDebug_ANPLogType, " ------ %p Testing DOM Access", instance); // Get the plugin's DOM object NPObject* windowObject = NULL; browser->getvalue(instance, NPNVWindowNPObject, &windowObject); if (!windowObject) gLogI.log(kError_ANPLogType, " ------ %p Unable to retrieve DOM Window", instance); // Retrieve a property from the plugin's DOM object NPIdentifier topIdentifier = browser->getstringidentifier("top"); NPVariant topObjectVariant; browser->getproperty(instance, windowObject, topIdentifier, &topObjectVariant); if (topObjectVariant.type != NPVariantType_Object) gLogI.log(kError_ANPLogType, " ------ %p Invalid Variant type for DOM Property: %d,%d", instance, topObjectVariant.type, NPVariantType_Object); }
VideoPlugin::VideoPlugin(NPP inst) : SurfaceSubPlugin(inst) { // initialize the drawing surface m_surface = NULL; //register for touch events ANPEventFlags flags = kTouch_ANPEventFlag; NPError err = NPN_SetValue(inst, kAcceptEvents_ANPSetValue, &flags); if (err != NPERR_NO_ERROR) { gLogI.log(kError_ANPLogType, "Error selecting input events."); } }
static void surfaceChanged(JNIEnv* jniEnv, jobject thiz, jint npp, jint format, jint width, jint height) { NPP instance = (NPP)npp; if(!instance) return; gLogI.log(instance, kDebug_ANPLogType, "jni-bridge surfaceChanged()..."); //// NEEDED FOR DRAWING //SurfaceSubPlugin* obj = getPluginObject(npp); //if(obj) // obj->surfaceChanged(format, width, height); //gLogI.log(instance, kDebug_ANPLogType, "jni-bridge surfaceChanged() done"); }
int16 NPP_HandleEvent(NPP instance, void* event) { PluginObject *obj = reinterpret_cast<PluginObject*>(instance->pdata); const ANPEvent* evt = reinterpret_cast<const ANPEvent*>(event); if(!obj->subPlugin) { gLogI.log(instance, kError_ANPLogType, "the sub-plugin is null."); return 0; // unknown or unhandled event } else { return obj->subPlugin->handleEvent(evt); } }
void BackgroundPlugin::test_bitmap_transparency(const ANPEvent* evt) { NPP instance = this->inst(); // check default & set transparent if (!mFinishedStageOne) { gLogI.log(kDebug_ANPLogType, "BEGIN: testing bitmap transparency"); //check to make sure it is not transparent if (evt->data.draw.data.bitmap.format == kRGBA_8888_ANPBitmapFormat) { gLogI.log(kError_ANPLogType, "bitmap default format is transparent"); } //make it transparent (any non-null value will set it to true) bool value = true; NPError err = browser->setvalue(instance, NPPVpluginTransparentBool, &value); if (err != NPERR_NO_ERROR) { gLogI.log(kError_ANPLogType, "Error setting transparency."); } mFinishedStageOne = true; browser->invalidaterect(instance, NULL); } // check transparent & set opaque else if (!mFinishedStageTwo) { //check to make sure it is transparent if (evt->data.draw.data.bitmap.format != kRGBA_8888_ANPBitmapFormat) { gLogI.log(kError_ANPLogType, "bitmap did not change to transparent format"); } //make it opaque NPError err = browser->setvalue(instance, NPPVpluginTransparentBool, NULL); if (err != NPERR_NO_ERROR) { gLogI.log(kError_ANPLogType, "Error setting transparency."); } mFinishedStageTwo = true; } // check opaque else if (!mFinishedStageThree) { //check to make sure it is not transparent if (evt->data.draw.data.bitmap.format == kRGBA_8888_ANPBitmapFormat) { gLogI.log(kError_ANPLogType, "bitmap default format is transparent"); } gLogI.log(kDebug_ANPLogType, "END: testing bitmap transparency"); mFinishedStageThree = true; } }
void NavigationPlugin::draw(ANPCanvas* canvas) { NPP instance = this->inst(); PluginObject *obj = (PluginObject*) instance->pdata; const int W = obj->window->width; const int H = obj->window->height; const int Wm = W/2; const int Hm = H/2; // color the plugin canvas gCanvasI.drawColor(canvas, (m_hasFocus) ? 0xFFCDCDCD : 0xFF545454); // draw the nav up box (5 px from the top edge) m_navUp.left = Wm - 15; m_navUp.top = 5; m_navUp.right = m_navUp.left + 30; m_navUp.bottom = m_navUp.top + 30; gCanvasI.drawRect(canvas, &m_navUp, getPaint(&m_navUp)); // draw the nav down box (5 px from the bottom edge) m_navDown.left = Wm - 15; m_navDown.top = H - (30 + 5); m_navDown.right = m_navDown.left + 30; m_navDown.bottom = m_navDown.top + 30; gCanvasI.drawRect(canvas, &m_navDown, getPaint(&m_navDown)); // draw the nav left box (5 px from the left edge) m_navLeft.left = 5; m_navLeft.top = Hm - 15; m_navLeft.right = m_navLeft.left + 30; m_navLeft.bottom = m_navLeft.top + 30; gCanvasI.drawRect(canvas, &m_navLeft, getPaint(&m_navLeft)); // draw the nav right box (5 px from the right edge) m_navRight.left = W - (30 + 5); m_navRight.top = Hm - 15; m_navRight.right = m_navRight.left + 30; m_navRight.bottom = m_navRight.top + 30; gCanvasI.drawRect(canvas, &m_navRight, getPaint(&m_navRight)); // draw the nav center box m_navCenter.left = Wm - 15; m_navCenter.top = Hm - 15; m_navCenter.right = m_navCenter.left + 30; m_navCenter.bottom = m_navCenter.top + 30; gCanvasI.drawRect(canvas, &m_navCenter, getPaint(&m_navCenter)); gLogI.log(kDebug_ANPLogType, "----%p Drawing Plugin", inst()); }
VideoPlugin::VideoPlugin(NPP inst, const char * path) : SurfaceSubPlugin(inst) { // initialize the drawing surface m_surface = NULL; //register for touch events ANPEventFlags flags = kTouch_ANPEventFlag; NPError err = browser->setvalue(inst, kAcceptEvents_ANPSetValue, &flags); if (err != NPERR_NO_ERROR) { gLogI.log(kError_ANPLogType, "Error selecting input events."); } if (path != NULL) { strcpy(mFilepath, path); } }
// called by PluginAppletViewer.java nativeInvokeNative() static jboolean invokeNative(JNIEnv* jniEnv, jobject thiz, // TODO ??? jint jnpp, // root npp instance given to jni-bridge::surfaceCreated() -> handed over to DexLoader.loadDexInit() jint jsobj_addr, // via JsObject from pluginAppletViewer.getWindow(); jstring jmethodName, // may be null jobject args[]) { NPP npp = (NPP)jnpp; if(npp) { if(jniEnv && browser && browser->pluginthreadasynccall) { InvokeNativeObject* invokeNativeObject = (InvokeNativeObject*)malloc(sizeof(InvokeNativeObject)); if(invokeNativeObject) { const char* methodName = NULL; if(jmethodName) methodName = jniEnv->GetStringUTFChars(jmethodName, NULL); // if(methodName) // gLogI.log(npp, kDebug_ANPLogType, "jni-bridge invokeNative() npp=%p jsobj_addr=%p methodname=%s ...",npp,jsobj_addr,methodName); // else // gLogI.log(npp, kDebug_ANPLogType, "jni-bridge invokeNative() npp=%p jsobj_addr=%p ...",npp,jsobj_addr); bzero(invokeNativeObject, sizeof(InvokeNativeObject)); invokeNativeObject->npp = npp; invokeNativeObject->jsobj = (NPObject*)jsobj_addr; if(methodName) strcpy(invokeNativeObject->methodName,methodName); //invokeNativeObject->args = args; // todo //gLogI.log(npp, kDebug_ANPLogType, "jni-bridge invokeNative() npp=%p jsobj=%p use pluginthreadasynccall()...",npp,invokeNativeObject->jsobj); browser->pluginthreadasynccall(npp, &invokeNativeAsync, (void*)invokeNativeObject); // invokeNativeObject may now be freed //gLogI.log(npp, kDebug_ANPLogType, "jni-bridge invokeNative() called ... "); if(jmethodName) jniEnv->ReleaseStringUTFChars(jmethodName, methodName); //gLogI.log(npp, kDebug_ANPLogType, "jni-bridge invokeNative() done"); return true; } } gLogI.log(npp, kDebug_ANPLogType, "jni-bridge invokeNative() done fail"); } return false; }
NavigationPlugin::NavigationPlugin(NPP inst) : SubPlugin(inst) { m_hasFocus = false; m_activeNav = NULL; m_paintDisabled = gPaintI.newPaint(); gPaintI.setFlags(m_paintDisabled, gPaintI.getFlags(m_paintDisabled) | kAntiAlias_ANPPaintFlag); gPaintI.setColor(m_paintDisabled, 0xFFFFFFFF); m_paintActive = gPaintI.newPaint(); gPaintI.setFlags(m_paintActive, gPaintI.getFlags(m_paintActive) | kAntiAlias_ANPPaintFlag); gPaintI.setColor(m_paintActive, 0xFFFFFF00); //register for key events ANPEventFlags flags = kKey_ANPEventFlag; NPError err = browser->setvalue(inst, kAcceptEvents_ANPSetValue, &flags); if (err != NPERR_NO_ERROR) { gLogI.log(kError_ANPLogType, "Error selecting input events."); } }
FormPlugin::FormPlugin(NPP inst) : SubPlugin(inst) { m_hasFocus = false; m_activeInput = NULL; memset(&m_usernameInput, 0, sizeof(m_usernameInput)); memset(&m_passwordInput, 0, sizeof(m_passwordInput)); m_usernameInput.text[0] = '\0'; m_usernameInput.charPtr = 0; m_passwordInput.text[0] = '\0'; m_passwordInput.charPtr = 0; m_paintInput = gPaintI.newPaint(); gPaintI.setFlags(m_paintInput, gPaintI.getFlags(m_paintInput) | kAntiAlias_ANPPaintFlag); gPaintI.setColor(m_paintInput, 0xFFFFFFFF); m_paintActive = gPaintI.newPaint(); gPaintI.setFlags(m_paintActive, gPaintI.getFlags(m_paintActive) | kAntiAlias_ANPPaintFlag); gPaintI.setColor(m_paintActive, 0xFFFFFF00); m_paintText = gPaintI.newPaint(); gPaintI.setFlags(m_paintText, gPaintI.getFlags(m_paintText) | kAntiAlias_ANPPaintFlag); gPaintI.setColor(m_paintText, 0xFF000000); gPaintI.setTextSize(m_paintText, 18); ANPTypeface* tf = gTypefaceI.createFromName("serif", kItalic_ANPTypefaceStyle); gPaintI.setTypeface(m_paintText, tf); gTypefaceI.unref(tf); //register for key and visibleRect events ANPEventFlags flags = kKey_ANPEventFlag; NPError err = browser->setvalue(inst, kAcceptEvents_ANPSetValue, &flags); if (err != NPERR_NO_ERROR) { gLogI.log(kError_ANPLogType, "Error selecting input events."); } }