Bug 948003 - Mark GeckoAppShell.loadPluginClass() as used from JNI. r=blassey, a=lsblakk
authorJames Willcox <snorp@snorp.net>
Wed, 11 Dec 2013 15:53:06 -0600
changeset 175236 3ec4c87136ca1e67157d3d13796be52e6e8ce7b6
parent 175235 4d297d7127921612e1bf6c3b6f401918be4cab0e
child 175237 8d0d66f5c4620a503a7e19d35d2f483c48a77cd4
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersblassey, lsblakk
bugs948003
milestone28.0a2
Bug 948003 - Mark GeckoAppShell.loadPluginClass() as used from JNI. r=blassey, a=lsblakk
dom/plugins/base/android/ANPSystem.cpp
mobile/android/base/GeckoAppShell.java
widget/android/GeneratedJNIWrappers.cpp
widget/android/GeneratedJNIWrappers.h
--- a/dom/plugins/base/android/ANPSystem.cpp
+++ b/dom/plugins/base/android/ANPSystem.cpp
@@ -45,43 +45,30 @@ anp_system_getApplicationDataDirectory(N
 }
 
 const char*
 anp_system_getApplicationDataDirectory()
 {
   return anp_system_getApplicationDataDirectory(nullptr);
 }
 
-jclass anp_system_loadJavaClass(NPP instance, const char* className)
+jclass anp_system_loadJavaClass(NPP instance, const char* classNameStr)
 {
   LOG("%s", __PRETTY_FUNCTION__);
 
-  JNIEnv* env = GetJNIForThread();
-  if (!env)
-    return nullptr;
-
-  jclass cls = env->FindClass("org/mozilla/gecko/GeckoAppShell");
-  jmethodID method = env->GetStaticMethodID(cls,
-                                            "loadPluginClass",
-                                            "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Class;");
-
-  // pass libname and classname, gotta create java strings
   nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
   mozilla::PluginPRLibrary* lib = static_cast<mozilla::PluginPRLibrary*>(pinst->GetPlugin()->GetLibrary());
 
-  nsCString libName;
-  lib->GetLibraryPath(libName);
+  NS_ConvertUTF8toUTF16 className(classNameStr);
 
-  jstring jclassName = env->NewStringUTF(className);
-  jstring jlibName = env->NewStringUTF(libName.get());
-  jobject obj = env->CallStaticObjectMethod(cls, method, jclassName, jlibName);
-  env->DeleteLocalRef(jlibName);
-  env->DeleteLocalRef(jclassName);
-  env->DeleteLocalRef(cls);
-  return reinterpret_cast<jclass>(obj);
+  nsCString libNameUtf8;
+  lib->GetLibraryPath(libNameUtf8);
+  NS_ConvertUTF8toUTF16 libName(libNameUtf8);
+
+  return GeckoAppShell::LoadPluginClass(className, libName);
 }
 
 void anp_system_setPowerState(NPP instance, ANPPowerState powerState)
 {
   nsNPAPIPluginInstance* pinst = nsNPAPIPluginInstance::GetFromNPP(instance);
 
   if (pinst) {
     pinst->SetWakeLock(powerState == kScreenOn_ANPPowerState);
--- a/mobile/android/base/GeckoAppShell.java
+++ b/mobile/android/base/GeckoAppShell.java
@@ -2076,16 +2076,17 @@ public class GeckoAppShell
             throws NameNotFoundException, ClassNotFoundException {
         Context pluginContext = getContext().createPackageContext(packageName,
                 Context.CONTEXT_INCLUDE_CODE |
                 Context.CONTEXT_IGNORE_SECURITY);
         ClassLoader pluginCL = pluginContext.getClassLoader();
         return pluginCL.loadClass(className);
     }
 
+    @WrapElementForJNI(allowMultithread = true)
     public static Class<?> loadPluginClass(String className, String libName) {
         if (getGeckoInterface() == null)
             return null;
         try {
             final String packageName = getPluginPackage(libName);
             final int contextFlags = Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY;
             final Context pluginContext = getContext().createPackageContext(packageName, contextFlags);
             return pluginContext.getClassLoader().loadClass(className);
--- a/widget/android/GeneratedJNIWrappers.cpp
+++ b/widget/android/GeneratedJNIWrappers.cpp
@@ -52,16 +52,17 @@ jmethodID GeckoAppShell::jGetShowPasswor
 jmethodID GeckoAppShell::jGetSystemColoursWrapper = 0;
 jmethodID GeckoAppShell::jHandleGeckoMessageWrapper = 0;
 jmethodID GeckoAppShell::jHideProgressDialog = 0;
 jmethodID GeckoAppShell::jInitCameraWrapper = 0;
 jmethodID GeckoAppShell::jIsNetworkLinkKnown = 0;
 jmethodID GeckoAppShell::jIsNetworkLinkUp = 0;
 jmethodID GeckoAppShell::jIsTablet = 0;
 jmethodID GeckoAppShell::jKillAnyZombies = 0;
+jmethodID GeckoAppShell::jLoadPluginClass = 0;
 jmethodID GeckoAppShell::jLockScreenOrientation = 0;
 jmethodID GeckoAppShell::jMarkURIVisited = 0;
 jmethodID GeckoAppShell::jMoveTaskToBack = 0;
 jmethodID GeckoAppShell::jNetworkLinkType = 0;
 jmethodID GeckoAppShell::jNotifyDefaultPrevented = 0;
 jmethodID GeckoAppShell::jNotifyIME = 0;
 jmethodID GeckoAppShell::jNotifyIMEChange = 0;
 jmethodID GeckoAppShell::jNotifyIMEContext = 0;
@@ -132,16 +133,17 @@ void GeckoAppShell::InitStubs(JNIEnv *jE
     jGetSystemColoursWrapper = getStaticMethod("getSystemColors", "()[I");
     jHandleGeckoMessageWrapper = getStaticMethod("handleGeckoMessage", "(Ljava/lang/String;)Ljava/lang/String;");
     jHideProgressDialog = getStaticMethod("hideProgressDialog", "()V");
     jInitCameraWrapper = getStaticMethod("initCamera", "(Ljava/lang/String;III)[I");
     jIsNetworkLinkKnown = getStaticMethod("isNetworkLinkKnown", "()Z");
     jIsNetworkLinkUp = getStaticMethod("isNetworkLinkUp", "()Z");
     jIsTablet = getStaticMethod("isTablet", "()Z");
     jKillAnyZombies = getStaticMethod("killAnyZombies", "()V");
+    jLoadPluginClass = getStaticMethod("loadPluginClass", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Class;");
     jLockScreenOrientation = getStaticMethod("lockScreenOrientation", "(I)V");
     jMarkURIVisited = getStaticMethod("markUriVisited", "(Ljava/lang/String;)V");
     jMoveTaskToBack = getStaticMethod("moveTaskToBack", "()V");
     jNetworkLinkType = getStaticMethod("networkLinkType", "()I");
     jNotifyDefaultPrevented = getStaticMethod("notifyDefaultPrevented", "(Z)V");
     jNotifyIME = getStaticMethod("notifyIME", "(I)V");
     jNotifyIMEChange = getStaticMethod("notifyIMEChange", "(Ljava/lang/String;III)V");
     jNotifyIMEContext = getStaticMethod("notifyIMEContext", "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
@@ -1472,16 +1474,47 @@ void GeckoAppShell::KillAnyZombies() {
         env->ExceptionClear();
         env->PopLocalFrame(NULL);
         return;
     }
 
     env->PopLocalFrame(NULL);
 }
 
+jclass GeckoAppShell::LoadPluginClass(const nsAString& a0, const nsAString& a1) {
+    JNIEnv *env = GetJNIForThread();
+    if (!env) {
+        ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
+        return nullptr;
+    }
+
+    if (env->PushLocalFrame(3) != 0) {
+        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
+        env->ExceptionDescribe();
+        env->ExceptionClear();
+        return nullptr;
+    }
+
+    jstring j0 = AndroidBridge::NewJavaString(env, a0);
+    jstring j1 = AndroidBridge::NewJavaString(env, a1);
+
+    jobject temp = env->CallStaticObjectMethod(mGeckoAppShellClass, jLoadPluginClass, j0, j1);
+
+    if (env->ExceptionCheck()) {
+        ALOG_BRIDGE("Exceptional exit of: %s", __PRETTY_FUNCTION__);
+        env->ExceptionDescribe();
+        env->ExceptionClear();
+        env->PopLocalFrame(NULL);
+        return nullptr;
+    }
+
+    jclass ret = static_cast<jclass>(env->PopLocalFrame(temp));
+    return ret;
+}
+
 void GeckoAppShell::LockScreenOrientation(int32_t a0) {
     JNIEnv *env = AndroidBridge::GetJNIEnv();
     if (!env) {
         ALOG_BRIDGE("Aborted: No env - %s", __PRETTY_FUNCTION__);
         return;
     }
 
     if (env->PushLocalFrame(0) != 0) {
--- a/widget/android/GeneratedJNIWrappers.h
+++ b/widget/android/GeneratedJNIWrappers.h
@@ -59,16 +59,17 @@ public:
     static jintArray GetSystemColoursWrapper();
     static jstring HandleGeckoMessageWrapper(const nsAString& a0);
     static void HideProgressDialog();
     static jintArray InitCameraWrapper(const nsAString& a0, int32_t a1, int32_t a2, int32_t a3);
     static bool IsNetworkLinkKnown();
     static bool IsNetworkLinkUp();
     static bool IsTablet();
     static void KillAnyZombies();
+    static jclass LoadPluginClass(const nsAString& a0, const nsAString& a1);
     static void LockScreenOrientation(int32_t a0);
     static void MarkURIVisited(const nsAString& a0);
     static void MoveTaskToBack();
     static int32_t NetworkLinkType();
     static void NotifyDefaultPrevented(bool a0);
     static void NotifyIME(int32_t a0);
     static void NotifyIMEChange(const nsAString& a0, int32_t a1, int32_t a2, int32_t a3);
     static void NotifyIMEContext(int32_t a0, const nsAString& a1, const nsAString& a2, const nsAString& a3);
@@ -138,16 +139,17 @@ protected:
     static jmethodID jGetSystemColoursWrapper;
     static jmethodID jHandleGeckoMessageWrapper;
     static jmethodID jHideProgressDialog;
     static jmethodID jInitCameraWrapper;
     static jmethodID jIsNetworkLinkKnown;
     static jmethodID jIsNetworkLinkUp;
     static jmethodID jIsTablet;
     static jmethodID jKillAnyZombies;
+    static jmethodID jLoadPluginClass;
     static jmethodID jLockScreenOrientation;
     static jmethodID jMarkURIVisited;
     static jmethodID jMoveTaskToBack;
     static jmethodID jNetworkLinkType;
     static jmethodID jNotifyDefaultPrevented;
     static jmethodID jNotifyIME;
     static jmethodID jNotifyIMEChange;
     static jmethodID jNotifyIMEContext;
@@ -158,17 +160,16 @@ protected:
     static jmethodID jPumpMessageLoop;
     static jmethodID jRegisterSurfaceTextureFrameListener;
     static jmethodID jRemovePluginView;
     static jmethodID jScanMedia;
     static jmethodID jScheduleRestart;
     static jmethodID jSendMessageWrapper;
     static jmethodID jSetFullScreen;
     static jmethodID jSetKeepScreenOn;
-    static jmethodID jSetSelectedLocale;
     static jmethodID jSetURITitle;
     static jmethodID jShowAlertNotificationWrapper;
     static jmethodID jShowFilePickerAsyncWrapper;
     static jmethodID jShowFilePickerForExtensionsWrapper;
     static jmethodID jShowFilePickerForMimeTypeWrapper;
     static jmethodID jShowInputMethodPicker;
     static jmethodID jUnlockProfile;
     static jmethodID jUnlockScreenOrientation;