bug 876270 - crash in mozilla::plugins::parent::_getvalue r=snorp

This commit is contained in:
Brad Lassey 2013-05-28 12:49:04 -04:00
parent 388caa55f4
commit 97bbee45a5
3 changed files with 26 additions and 12 deletions

View File

@ -2261,16 +2261,14 @@ _getvalue(NPP npp, NPNVariable variable, void *result)
}
case kJavaContext_ANPGetValue: {
LOG("get context");
JNIEnv* env = GetJNIForThread();
if (!env)
AndroidBridge *bridge = AndroidBridge::Bridge();
if (!bridge)
return NPERR_GENERIC_ERROR;
jobject ret = bridge->GetContext();
if (!ret)
return NPERR_GENERIC_ERROR;
jclass cls = env->FindClass("org/mozilla/gecko/GeckoApp");
jfieldID field = env->GetStaticFieldID(cls, "mAppContext",
"Lorg/mozilla/gecko/GeckoApp;");
jobject ret = env->GetStaticObjectField(cls, field);
env->DeleteLocalRef(cls);
int32_t* i = reinterpret_cast<int32_t*>(result);
*i = reinterpret_cast<int32_t>(ret);
return NPERR_NO_ERROR;

View File

@ -2062,6 +2062,22 @@ AndroidBridge::LockWindow(void *window, unsigned char **bits, int *width, int *h
return true;
}
jobject
AndroidBridge::GetContext() {
JNIEnv *env = GetJNIForThread();
if (!env)
return 0;
jobject context = env->CallStaticObjectMethod(mGeckoAppShellClass, jGetContext);
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
env->ExceptionClear();
return 0;
}
return context;
}
jobject
AndroidBridge::GetGlobalContextRef() {
JNIEnv *env = GetJNIForThread();
@ -2070,10 +2086,7 @@ AndroidBridge::GetGlobalContextRef() {
AutoLocalJNIFrame jniFrame(env, 0);
jobject context = env->CallStaticObjectMethod(mGeckoAppShellClass, jGetContext);
if (jniFrame.CheckForException()) {
return 0;
}
jobject context = GetContext();
jobject globalRef = env->NewGlobalRef(context);
MOZ_ASSERT(globalRef);

View File

@ -311,6 +311,9 @@ public:
// DeleteGlobalRef() when the context is no longer needed.
jobject GetGlobalContextRef(void);
// Returns a local reference. Caller must manage this reference
jobject GetContext(void);
void UnlockBitmap(jobject bitmap);
bool UnlockProfile();