Bug 728071 part 2 - Include application.ini.h in APKOpen.cpp instead of nsAndroidStartup.cpp. r=blassey
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 22 Feb 2012 08:12:15 +0100
changeset 90263 9eaacb130b4c9133224b86775e95992b87ce267e
parent 90262 0e2ee581bf9365e8b7f7933c72da7b57a8ecbaf5
child 90264 b8c9749cfff715824e35fd0349155311beab6e67
push id783
push userlsblakk@mozilla.com
push dateTue, 24 Apr 2012 17:33:42 +0000
treeherdermozilla-beta@11faed19f136 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersblassey
bugs728071
milestone13.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 728071 part 2 - Include application.ini.h in APKOpen.cpp instead of nsAndroidStartup.cpp. r=blassey
mozglue/android/APKOpen.cpp
mozglue/android/Makefile.in
toolkit/xre/Makefile.in
toolkit/xre/nsAndroidStartup.cpp
--- a/mozglue/android/APKOpen.cpp
+++ b/mozglue/android/APKOpen.cpp
@@ -64,16 +64,17 @@
 #include <sys/time.h>
 #include <sys/resource.h>
 #include "Zip.h"
 #include "sqlite3.h"
 #include "SQLiteBridge.h"
 #ifndef MOZ_OLD_LINKER
 #include "ElfLoader.h"
 #endif
+#include "application.ini.h"
 
 /* Android headers don't define RUSAGE_THREAD */
 #ifndef RUSAGE_THREAD
 #define RUSAGE_THREAD 1
 #endif
 
 enum StartupEvent {
 #define mozilla_StartupTimeline_Event(ev, z) ev,
@@ -277,17 +278,16 @@ typedef return_type (*name ## _t)(JNIEnv
 static name ## _t f_ ## name; \
 extern "C" NS_EXPORT return_type JNICALL \
 Java_org_mozilla_gecko_GeckoAppShell_ ## name(JNIEnv *jenv, jclass jc, type1 one, type2 two, type3 three, type4 four, type5 five, type6 six, type7 seven, type8 eight) \
 { \
   return f_ ## name(jenv, jc, one, two, three, four, five, six, seven, eight); \
 }
 
 SHELL_WRAPPER0(nativeInit)
-SHELL_WRAPPER1(nativeRun, jstring)
 SHELL_WRAPPER1(notifyGeckoOfEvent, jobject)
 SHELL_WRAPPER0(processNextNativeEvent)
 SHELL_WRAPPER1(setSurfaceView, jobject)
 SHELL_WRAPPER1(setSoftwareLayerClient, jobject)
 SHELL_WRAPPER0(onResume)
 SHELL_WRAPPER0(onLowMemory)
 SHELL_WRAPPER3(callObserver, jstring, jstring, jstring)
 SHELL_WRAPPER1(removeObserver, jstring)
@@ -689,17 +689,16 @@ loadGeckoLibs(const char *apkName)
   file_ids = NULL;
 #endif
 
   if (!xul_handle)
     __android_log_print(ANDROID_LOG_ERROR, "GeckoLibLoad", "Couldn't get a handle to libxul!");
 
 #define GETFUNC(name) f_ ## name = (name ## _t) __wrap_dlsym(xul_handle, "Java_org_mozilla_gecko_GeckoAppShell_" #name)
   GETFUNC(nativeInit);
-  GETFUNC(nativeRun);
   GETFUNC(notifyGeckoOfEvent);
   GETFUNC(processNextNativeEvent);
   GETFUNC(setSurfaceView);
   GETFUNC(setSoftwareLayerClient);
   GETFUNC(onResume);
   GETFUNC(onLowMemory);
   GETFUNC(callObserver);
   GETFUNC(removeObserver);
@@ -808,16 +807,35 @@ Java_org_mozilla_gecko_GeckoAppShell_loa
   str = jenv->GetStringUTFChars(jApkName, NULL);
   if (str == NULL)
     return;
 
   loadSQLiteLibs(str);
   jenv->ReleaseStringUTFChars(jApkName, str);
 }
 
+typedef void (*GeckoStart_t)(void *, const nsXREAppData *);
+
+extern "C" NS_EXPORT void JNICALL
+Java_org_mozilla_gecko_GeckoAppShell_nativeRun(JNIEnv *jenv, jclass jc, jstring jargs)
+{
+  GeckoStart_t GeckoStart = (GeckoStart_t) __wrap_dlsym(xul_handle, "GeckoStart");
+  if (GeckoStart == NULL)
+    return;
+  // XXX: java doesn't give us true UTF8, we should figure out something
+  // better to do here
+  int len = jenv->GetStringUTFLength(jargs);
+  // GeckoStart needs to write in the args buffer, so we need a copy.
+  char *args = (char *) malloc(len + 1);
+  jenv->GetStringUTFRegion(jargs, 0, len, args);
+  args[len] = '\0';
+  GeckoStart(args, &sAppData);
+  free(args);
+}
+
 typedef int GeckoProcessType;
 typedef int nsresult;
 
 extern "C" NS_EXPORT int
 ChildProcessInit(int argc, char* argv[])
 {
   int i;
   for (i = 0; i < (argc - 1); i++) {
--- a/mozglue/android/Makefile.in
+++ b/mozglue/android/Makefile.in
@@ -52,16 +52,19 @@ DEFINES += \
   $(NULL)
 
 CPPSRCS = \
   nsGeckoUtils.cpp \
   APKOpen.cpp \
   SQLiteBridge.cpp \
   $(NULL)
 
+LOCAL_INCLUDES += -I$(DEPTH)/build
+LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/build
+
 LOCAL_INCLUDES += -I$(srcdir)/../linker
 LOCAL_INCLUDES += -I$(topsrcdir)/toolkit/components/startup
 LOCAL_INCLUDES += -I$(topsrcdir)/db/sqlite3/src
 ifdef MOZ_OLD_LINKER
 DEFINES += -DMOZ_OLD_LINKER
 LOCAL_INCLUDES += -I$(topsrcdir)/other-licenses/android
 ifeq ($(CPU_ARCH),arm)
 DEFINES += -DANDROID_ARM_LINKER
--- a/toolkit/xre/Makefile.in
+++ b/toolkit/xre/Makefile.in
@@ -194,21 +194,16 @@ LOCAL_INCLUDES += \
   $(NULL)
 
 LOCAL_INCLUDES += \
   -I$(srcdir) \
   -I$(srcdir)/../profile \
   -I$(topsrcdir)/config \
   $(NULL)
 
-ifdef MOZ_APP_STATIC_INI
-LOCAL_INCLUDES += -I$(DEPTH)/build
-DEFINES += -DMOZ_APP_STATIC_INI
-endif
-
 CXXFLAGS += $(TK_CFLAGS) $(MOZ_DBUS_CFLAGS) $(MOZ_DBUS_GLIB_CFLAGS)
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
 CXXFLAGS += $(MOZ_PANGO_CFLAGS)
 endif
 
 DEFINES += \
   -DOS_TARGET=\"$(OS_TARGET)\" \
--- a/toolkit/xre/nsAndroidStartup.cpp
+++ b/toolkit/xre/nsAndroidStartup.cpp
@@ -34,19 +34,16 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-#include "nsXULAppAPI.h"
-#include "application.ini.h"
-
 #include <android/log.h>
 
 #include <jni.h>
 
 #include <stdlib.h>
 #include <string.h>
 #include <pthread.h>
 
@@ -55,81 +52,68 @@
 #include "nsILocalFile.h"
 #include "nsAppRunner.h"
 #include "AndroidBridge.h"
 #include "APKOpen.h"
 #include "nsExceptionHandler.h"
 
 #define LOG(args...) __android_log_print(ANDROID_LOG_INFO, MOZ_APP_NAME, args)
 
+// We need to put Gecko on a even more separate thread, because
+// otherwise this JNI method never returns; this leads to problems
+// with local references overrunning the local refs table, among
+// other things, since GC can't ever run on them.
+
+// Note that we don't have xpcom initialized yet, so we can't use the
+// thread manager for this.  Instead, we use pthreads directly.
+
 struct AutoAttachJavaThread {
     AutoAttachJavaThread() {
         attached = mozilla_AndroidBridge_SetMainThread((void*)pthread_self());
     }
     ~AutoAttachJavaThread() {
         mozilla_AndroidBridge_SetMainThread(nsnull);
         attached = false;
     }
 
     bool attached;
 };
 
-static void*
-GeckoStart(void *data)
+extern "C" NS_EXPORT void
+GeckoStart(void *data, const nsXREAppData *appData)
 {
 #ifdef MOZ_CRASHREPORTER
     const struct mapping_info *info = getLibraryMapping();
     while (info->name) {
       CrashReporter::AddLibraryMapping(info->name, info->file_id, info->base,
                                        info->len, info->offset);
       info++;
     }
 #endif
 
     AutoAttachJavaThread attacher;
     if (!attacher.attached)
-        return 0;
+        return;
 
     if (!data) {
         LOG("Failed to get arguments for GeckoStart\n");
-        return 0;
+        return;
     }
 
     nsTArray<char *> targs;
     char *arg = strtok(static_cast<char *>(data), " ");
     while (arg) {
         targs.AppendElement(arg);
         arg = strtok(NULL, " ");
     }
     targs.AppendElement(static_cast<char *>(nsnull));
 
-    int result = XRE_main(targs.Length() - 1, targs.Elements(), &sAppData);
+    int result = XRE_main(targs.Length() - 1, targs.Elements(), appData);
 
     if (result)
         LOG("XRE_main returned %d", result);
 
     mozilla::AndroidBridge::Bridge()->NotifyXreExit();
 
     free(targs[0]);
     nsMemory::Free(data);
-    return 0;
+    return;
 }
-
-extern "C" NS_EXPORT void JNICALL
-Java_org_mozilla_gecko_GeckoAppShell_nativeRun(JNIEnv *jenv, jclass jc, jstring jargs)
-{
-    // We need to put Gecko on a even more separate thread, because
-    // otherwise this JNI method never returns; this leads to problems
-    // with local references overrunning the local refs table, among
-    // other things, since GC can't ever run on them.
-
-    // Note that we don't have xpcom initialized yet, so we can't use the
-    // thread manager for this.  Instead, we use pthreads directly.
-
-    nsAutoString wargs;
-    int len = jenv->GetStringLength(jargs);
-    wargs.SetLength(jenv->GetStringLength(jargs));
-    jenv->GetStringRegion(jargs, 0, len, wargs.BeginWriting());
-    char *args = ToNewUTF8String(wargs);
-
-    GeckoStart(args);
-}
-