Bug 748531 - Guard against exceptions in JNI. r=blassey

This commit is contained in:
Kartikaya Gupta
2012-05-04 11:08:47 -04:00
parent 398a73b449
commit e3e3033e52
6 changed files with 407 additions and 209 deletions

View File

@@ -225,13 +225,22 @@ AndroidLocation::InitLocationClass(JNIEnv *jEnv)
nsGeoPosition*
AndroidLocation::CreateGeoPosition(JNIEnv *jenv, jobject jobj)
{
AutoLocalJNIFrame jniFrame(jenv);
double latitude = jenv->CallDoubleMethod(jobj, jGetLatitudeMethod);
if (jniFrame.CheckForException()) return NULL;
double longitude = jenv->CallDoubleMethod(jobj, jGetLongitudeMethod);
if (jniFrame.CheckForException()) return NULL;
double altitude = jenv->CallDoubleMethod(jobj, jGetAltitudeMethod);
if (jniFrame.CheckForException()) return NULL;
float accuracy = jenv->CallFloatMethod (jobj, jGetAccuracyMethod);
if (jniFrame.CheckForException()) return NULL;
float bearing = jenv->CallFloatMethod (jobj, jGetBearingMethod);
if (jniFrame.CheckForException()) return NULL;
float speed = jenv->CallFloatMethod (jobj, jGetSpeedMethod);
if (jniFrame.CheckForException()) return NULL;
long long time = jenv->CallLongMethod (jobj, jGetTimeMethod);
if (jniFrame.CheckForException()) return NULL;
return new nsGeoPosition(latitude, longitude,
altitude, accuracy,
@@ -631,7 +640,13 @@ AndroidGeckoSurfaceView::BeginDrawing()
if (!env)
return 0;
return env->CallIntMethod(wrapped_obj, jBeginDrawingMethod);
AutoLocalJNIFrame jniFrame(env, 0);
int ret = env->CallIntMethod(wrapped_obj, jBeginDrawingMethod);
if (jniFrame.CheckForException())
return 0;
return ret;
}
void
@@ -641,6 +656,7 @@ AndroidGeckoSurfaceView::EndDrawing()
if (!env)
return;
AutoLocalJNIFrame jniFrame(env, 0);
env->CallVoidMethod(wrapped_obj, jEndDrawingMethod);
}
@@ -651,6 +667,7 @@ AndroidGeckoSurfaceView::Draw2D(jobject bitmap, int width, int height)
if (!env)
return;
AutoLocalJNIFrame jniFrame(env, 0);
env->CallVoidMethod(wrapped_obj, jDraw2DBitmapMethod, bitmap, width, height);
}
@@ -661,6 +678,7 @@ AndroidGeckoSurfaceView::Draw2D(jobject buffer, int stride)
if (!env)
return;
AutoLocalJNIFrame jniFrame(env, 0);
env->CallVoidMethod(wrapped_obj, jDraw2DBufferMethod, buffer, stride);
}
@@ -673,7 +691,7 @@ AndroidGeckoLayerClient::SetFirstPaintViewport(float aOffsetX, float aOffsetY, f
if (!env)
return;
AndroidBridge::AutoLocalJNIFrame jniFrame(env);
AutoLocalJNIFrame jniFrame(env, 0);
return env->CallVoidMethod(wrapped_obj, jSetFirstPaintViewport, aOffsetX, aOffsetY, aZoom, aPageWidth, aPageHeight,
aCssPageWidth, aCssPageHeight);
}
@@ -686,7 +704,7 @@ AndroidGeckoLayerClient::SetPageSize(float aZoom, float aPageWidth, float aPageH
if (!env)
return;
AndroidBridge::AutoLocalJNIFrame jniFrame(env);
AutoLocalJNIFrame jniFrame(env, 0);
return env->CallVoidMethod(wrapped_obj, jSetPageSize, aZoom, aPageWidth, aPageHeight, aCssPageWidth, aCssPageHeight);
}
@@ -699,14 +717,18 @@ AndroidGeckoLayerClient::SyncViewportInfo(const nsIntRect& aDisplayPort, float a
if (!env)
return;
AndroidViewTransform viewTransform;
AndroidBridge::AutoLocalJNIFrame jniFrame(env);
AutoLocalJNIFrame jniFrame(env);
jobject viewTransformJObj = env->CallObjectMethod(wrapped_obj, jSyncViewportInfoMethod,
aDisplayPort.x, aDisplayPort.y,
aDisplayPort.width, aDisplayPort.height,
aDisplayResolution, aLayersUpdated);
if (jniFrame.CheckForException())
return;
NS_ABORT_IF_FALSE(viewTransformJObj, "No view transform object!");
AndroidViewTransform viewTransform;
viewTransform.Init(viewTransformJObj);
aScrollOffset = nsIntPoint(viewTransform.GetX(env), viewTransform.GetY(env));
@@ -714,51 +736,69 @@ AndroidGeckoLayerClient::SyncViewportInfo(const nsIntRect& aDisplayPort, float a
}
jobject
AndroidGeckoSurfaceView::GetSoftwareDrawBitmap()
AndroidGeckoSurfaceView::GetSoftwareDrawBitmap(JNIEnv *env, AutoLocalJNIFrame *jniFrame)
{
JNIEnv *env = AndroidBridge::GetJNIEnv();
if (!env)
if (!env || !jniFrame)
return nsnull;
return env->CallObjectMethod(wrapped_obj, jGetSoftwareDrawBitmapMethod);
jobject ret = env->CallObjectMethod(wrapped_obj, jGetSoftwareDrawBitmapMethod);
if (jniFrame->CheckForException())
return nsnull;
return ret;
}
jobject
AndroidGeckoSurfaceView::GetSoftwareDrawBuffer()
AndroidGeckoSurfaceView::GetSoftwareDrawBuffer(JNIEnv *env, AutoLocalJNIFrame *jniFrame)
{
JNIEnv *env = AndroidBridge::GetJNIEnv();
if (!env)
if (!env || !jniFrame)
return nsnull;
return env->CallObjectMethod(wrapped_obj, jGetSoftwareDrawBufferMethod);
jobject ret = env->CallObjectMethod(wrapped_obj, jGetSoftwareDrawBufferMethod);
if (jniFrame->CheckForException())
return nsnull;
return ret;
}
jobject
AndroidGeckoSurfaceView::GetSurface()
AndroidGeckoSurfaceView::GetSurface(JNIEnv *env, AutoLocalJNIFrame *jniFrame)
{
JNIEnv *env = AndroidBridge::GetJNIEnv();
if (!env)
if (!env || !jniFrame)
return nsnull;
return env->CallObjectMethod(wrapped_obj, jGetSurfaceMethod);
jobject ret = env->CallObjectMethod(wrapped_obj, jGetSurfaceMethod);
if (jniFrame->CheckForException())
return nsnull;
return ret;
}
jobject
AndroidGeckoSurfaceView::GetSurfaceHolder()
AndroidGeckoSurfaceView::GetSurfaceHolder(JNIEnv *env, AutoLocalJNIFrame *jniFrame)
{
JNIEnv *env = GetJNIForThread();
if (!env)
if (!env || !jniFrame)
return nsnull;
return env->CallObjectMethod(wrapped_obj, jGetHolderMethod);
jobject ret = env->CallObjectMethod(wrapped_obj, jGetHolderMethod);
if (jniFrame->CheckForException())
return nsnull;
return ret;
}
void
bool
AndroidGeckoLayerClient::CreateFrame(JNIEnv *env, AndroidLayerRendererFrame& aFrame)
{
AutoLocalJNIFrame jniFrame(env, 1);
jobject frameJObj = env->CallObjectMethod(wrapped_obj, jCreateFrameMethod);
if (jniFrame.CheckForException())
return false;
NS_ABORT_IF_FALSE(frameJObj, "No frame object!");
aFrame.Init(env, frameJObj);
return true;
}
void