Permalink
Browse files

Bug 713803 - Rationalize JNI access accross android widget. r=blassey

  • Loading branch information...
dougt committed Jan 29, 2012
1 parent ffe81b8 commit 1c81f2dba4d939f67042eae56a33617f2c291a33
@@ -64,17 +64,20 @@ nsresult
PluginPRLibrary::NP_Initialize(NPNetscapeFuncs* bFuncs,
NPPluginFuncs* pFuncs, NPError* error)
{
+ JNIEnv* env = GetJNIForThread();
+ if (!env)
+ return NS_ERROR_FAILURE;
+
if (mNP_Initialize) {
- *error = mNP_Initialize(bFuncs, pFuncs, GetJNIForThread());
+ *error = mNP_Initialize(bFuncs, pFuncs, env);
} else {
NP_InitializeFunc pfNP_Initialize = (NP_InitializeFunc)
PR_FindFunctionSymbol(mLibrary, "NP_Initialize");
if (!pfNP_Initialize)
return NS_ERROR_FAILURE;
- *error = pfNP_Initialize(bFuncs, pFuncs, GetJNIForThread());
+ *error = pfNP_Initialize(bFuncs, pFuncs, env);
}
-
// Save pointers to functions that get called through PluginLibrary itself.
mNPP_New = pFuncs->newp;
mNPP_GetValue = pFuncs->getvalue;
@@ -140,6 +140,8 @@ NS_IMETHODIMP
AudioRunnable::Run()
{
JNIEnv* jenv = GetJNIForThread();
+ if (!jenv)
+ return NS_ERROR_FAILURE;
if (jenv->PushLocalFrame(128)) {
return NS_ERROR_FAILURE;
@@ -309,6 +311,9 @@ anp_audio_start(ANPAudioTrack* s)
}
JNIEnv *jenv = GetJNIForThread();
+ if (!jenv)
+ return;
+
jenv->CallVoidMethod(s->output_unit, at.play);
s->isStopped = false;
@@ -329,6 +334,8 @@ anp_audio_pause(ANPAudioTrack* s)
}
JNIEnv *jenv = GetJNIForThread();
+ if (!jenv)
+ return;
jenv->CallVoidMethod(s->output_unit, at.pause);
}
@@ -341,6 +348,8 @@ anp_audio_stop(ANPAudioTrack* s)
s->isStopped = true;
JNIEnv *jenv = GetJNIForThread();
+ if (!jenv)
+ return;
jenv->CallVoidMethod(s->output_unit, at.stop);
}
@@ -66,14 +66,21 @@ void
anp_event_postEvent(NPP inst, const ANPEvent* event)
{
LOG("%s", __PRETTY_FUNCTION__);
+
+ JNIEnv* env = GetJNIForThread();
+ if (!env)
+ return;
+
if (!mozilla::AndroidBridge::Bridge()) {
LOG("no bridge in %s!!!!", __PRETTY_FUNCTION__);
return;
}
+
nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(inst->ndata);
NPPluginFuncs* pluginFunctions = pinst->GetPlugin()->PluginFuncs();
- mozilla::AndroidBridge::Bridge()->PostToJavaThread(
- new PluginEventRunnable(inst, const_cast<ANPEvent*>(event), pluginFunctions), true);
+ mozilla::AndroidBridge::Bridge()->PostToJavaThread(env,
+ new PluginEventRunnable(inst, const_cast<ANPEvent*>(event), pluginFunctions),
+ true);
LOG("returning from %s", __PRETTY_FUNCTION__);
}
@@ -67,6 +67,9 @@ jclass anp_system_loadJavaClass(NPP instance, const char* className)
LOG("%s", __PRETTY_FUNCTION__);
JNIEnv* env = GetJNIForThread();
+ if (!env)
+ return nsnull;
+
jclass cls = env->FindClass("org/mozilla/gecko/GeckoAppShell");
jmethodID method = env->GetStaticMethodID(cls,
"loadPluginClass",
@@ -2384,7 +2384,10 @@ _getvalue(NPP npp, NPNVariable variable, void *result)
case kJavaContext_ANPGetValue: {
LOG("get context");
- JNIEnv* env = GetJNIForThread();
+ JNIEnv* env = GetJNIForThread();
+ if (!env)
+ return NPERR_GENERIC_ERROR;
+
jclass cls = env->FindClass("org/mozilla/gecko/GeckoApp");
jfieldID field = env->GetStaticFieldID(cls, "mAppContext",
"Lorg/mozilla/gecko/GeckoApp;");
@@ -749,7 +749,15 @@ class SurfaceGetter : public nsRunnable {
return NS_OK;
}
void RequestSurface() {
- mozilla::AndroidBridge::Bridge()->PostToJavaThread(this);
+ JNIEnv* env = GetJNIForThread();
+ if (!env)
+ return;
+
+ if (!mozilla::AndroidBridge::Bridge()) {
+ PLUGIN_LOG(PLUGIN_LOG_BASIC, ("nsNPAPIPluginInstance null AndroidBridge"));
+ return;
+ }
+ mozilla::AndroidBridge::Bridge()->PostToJavaThread(env, this);
}
private:
nsNPAPIPluginInstance* mInstance;
@@ -1745,31 +1745,32 @@ bool nsPluginInstanceOwner::AddPluginView(const gfxRect& aRect)
void nsPluginInstanceOwner::RemovePluginView()
{
- AndroidBridge::AutoLocalJNIFrame frame(1);
+ if (!mInstance || !mObjectFrame | !mPluginViewAdded)
+ return;
- if (mInstance && mObjectFrame && mPluginViewAdded) {
- mPluginViewAdded = false;
+ mPluginViewAdded = false;
- void* surface = mInstance->GetJavaSurface();
- if (surface) {
- JNIEnv* env = GetJNIForThread();
- if (env) {
- jclass cls = env->FindClass("org/mozilla/gecko/GeckoAppShell");
- jmethodID method = env->GetStaticMethodID(cls,
- "removePluginView",
- "(Landroid/view/View;)V");
- env->CallStaticVoidMethod(cls, method, surface);
+ void* surface = mInstance->GetJavaSurface();
+ if (!surface)
+ return;
- {
- ANPEvent event;
- event.inSize = sizeof(ANPEvent);
- event.eventType = kLifecycle_ANPEventType;
- event.data.lifecycle.action = kOffScreen_ANPLifecycleAction;
- mInstance->HandleEvent(&event, nsnull);
- }
- }
- }
- }
+ JNIEnv* env = GetJNIForThread();
+ if (!env)
+ return;
+
+ AndroidBridge::AutoLocalJNIFrame frame(env, 1);
+
+ jclass cls = env->FindClass("org/mozilla/gecko/GeckoAppShell");
+ jmethodID method = env->GetStaticMethodID(cls,
+ "removePluginView",
+ "(Landroid/view/View;)V");
+ env->CallStaticVoidMethod(cls, method, surface);
+
+ ANPEvent event;
+ event.inSize = sizeof(ANPEvent);
+ event.eventType = kLifecycle_ANPEventType;
+ event.data.lifecycle.action = kOffScreen_ANPLifecycleAction;
+ mInstance->HandleEvent(&event, nsnull);
}
#endif
Oops, something went wrong.

0 comments on commit 1c81f2d

Please sign in to comment.