Bug 705386 - Allow AutoLocalJNIFrame callers to specify the JNIEnv. r=mwu
authorMounir Lamouri <mounir.lamouri@gmail.com>
Tue, 29 Nov 2011 17:34:52 +0100
changeset 82600 3a5731a6000237f39d311dcb8b3ad56fb9af09f4
parent 82599 9ff2a655cf0de0089d8d15a0605dc512cc31ecec
child 82601 604476c594958311b57e6cb0a78fb2d350d74eb2
push id519
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 00:38:35 +0000
treeherdermozilla-beta@788ea1ef610b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmwu
bugs705386
milestone11.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 705386 - Allow AutoLocalJNIFrame callers to specify the JNIEnv. r=mwu
widget/src/android/AndroidBridge.h
--- a/widget/src/android/AndroidBridge.h
+++ b/widget/src/android/AndroidBridge.h
@@ -228,40 +228,60 @@ public:
     void GetIconForExtension(const nsACString& aFileExt, PRUint32 aIconSize, PRUint8 * const aBuf);
 
     bool GetShowPasswordSetting();
 
     void FireAndWaitForTracerEvent();
 
     bool GetAccessibilityEnabled();
 
-    struct AutoLocalJNIFrame {
-        AutoLocalJNIFrame(int nEntries = 128) : mEntries(nEntries) {
-            // Make sure there is enough space to store a local ref to the
-            // exception.  I am not completely sure this is needed, but does
-            // not hurt.
-            AndroidBridge::Bridge()->JNI()->PushLocalFrame(mEntries + 1);
+    class AutoLocalJNIFrame {
+    public:
+        AutoLocalJNIFrame(int nEntries = 128)
+            : mEntries(nEntries)
+            , mJNIEnv(JNI())
+        {
+            Push();
         }
+
+        AutoLocalJNIFrame(JNIEnv* aJNIEnv, int nEntries = 128)
+            : mEntries(nEntries)
+            , mJNIEnv(aJNIEnv ? aJNIEnv : JNI())
+        {
+            Push();
+        }
+
         // Note! Calling Purge makes all previous local refs created in
         // the AutoLocalJNIFrame's scope INVALID; be sure that you locked down
         // any local refs that you need to keep around in global refs!
         void Purge() {
-            AndroidBridge::Bridge()->JNI()->PopLocalFrame(NULL);
-            AndroidBridge::Bridge()->JNI()->PushLocalFrame(mEntries);
+            mJNIEnv->PopLocalFrame(NULL);
+            Push();
         }
+
         ~AutoLocalJNIFrame() {
-            jthrowable exception =
-                AndroidBridge::Bridge()->JNI()->ExceptionOccurred();
+            jthrowable exception = mJNIEnv->ExceptionOccurred();
             if (exception) {
-                AndroidBridge::Bridge()->JNI()->ExceptionDescribe();
-                AndroidBridge::Bridge()->JNI()->ExceptionClear();
+                mJNIEnv->ExceptionDescribe();
+                mJNIEnv->ExceptionClear();
             }
-            AndroidBridge::Bridge()->JNI()->PopLocalFrame(NULL);
+
+            mJNIEnv->PopLocalFrame(NULL);
         }
+
+    private:
+        void Push() {
+            // Make sure there is enough space to store a local ref to the
+            // exception.  I am not completely sure this is needed, but does
+            // not hurt.
+            mJNIEnv->PushLocalFrame(mEntries + 1);
+        }
+
         int mEntries;
+        JNIEnv* mJNIEnv;
     };
 
     /* See GLHelpers.java as to why this is needed */
     void *CallEglCreateWindowSurface(void *dpy, void *config, AndroidGeckoSurfaceView& surfaceView);
 
     bool GetStaticStringField(const char *classID, const char *field, nsAString &result);
 
     bool GetStaticIntField(const char *className, const char *fieldName, PRInt32* aInt);