toolkit/xre/nsAndroidStartup.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include <android/log.h>
michael@0 7
michael@0 8 #include <jni.h>
michael@0 9
michael@0 10 #include <stdlib.h>
michael@0 11 #include <string.h>
michael@0 12 #include <pthread.h>
michael@0 13
michael@0 14 #include "nsTArray.h"
michael@0 15 #include "nsString.h"
michael@0 16 #include "nsIFile.h"
michael@0 17 #include "nsAppRunner.h"
michael@0 18 #include "AndroidBridge.h"
michael@0 19 #include "APKOpen.h"
michael@0 20 #include "nsExceptionHandler.h"
michael@0 21
michael@0 22 #define LOG(args...) __android_log_print(ANDROID_LOG_INFO, MOZ_APP_NAME, args)
michael@0 23
michael@0 24 // We need to put Gecko on a even more separate thread, because
michael@0 25 // otherwise this JNI method never returns; this leads to problems
michael@0 26 // with local references overrunning the local refs table, among
michael@0 27 // other things, since GC can't ever run on them.
michael@0 28
michael@0 29 // Note that we don't have xpcom initialized yet, so we can't use the
michael@0 30 // thread manager for this. Instead, we use pthreads directly.
michael@0 31
michael@0 32 struct AutoAttachJavaThread {
michael@0 33 AutoAttachJavaThread() {
michael@0 34 attached = mozilla_AndroidBridge_SetMainThread(pthread_self());
michael@0 35 }
michael@0 36 ~AutoAttachJavaThread() {
michael@0 37 mozilla_AndroidBridge_SetMainThread(-1);
michael@0 38 attached = false;
michael@0 39 }
michael@0 40
michael@0 41 bool attached;
michael@0 42 };
michael@0 43
michael@0 44 extern "C" NS_EXPORT void
michael@0 45 GeckoStart(void *data, const nsXREAppData *appData)
michael@0 46 {
michael@0 47 #ifdef MOZ_CRASHREPORTER
michael@0 48 const struct mapping_info *info = getLibraryMapping();
michael@0 49 while (info->name) {
michael@0 50 CrashReporter::AddLibraryMapping(info->name, info->base,
michael@0 51 info->len, info->offset);
michael@0 52 info++;
michael@0 53 }
michael@0 54 #endif
michael@0 55
michael@0 56 AutoAttachJavaThread attacher;
michael@0 57 if (!attacher.attached)
michael@0 58 return;
michael@0 59
michael@0 60 if (!data) {
michael@0 61 LOG("Failed to get arguments for GeckoStart\n");
michael@0 62 return;
michael@0 63 }
michael@0 64
michael@0 65 nsTArray<char *> targs;
michael@0 66 char *arg = strtok(static_cast<char *>(data), " ");
michael@0 67 while (arg) {
michael@0 68 targs.AppendElement(arg);
michael@0 69 arg = strtok(nullptr, " ");
michael@0 70 }
michael@0 71 targs.AppendElement(static_cast<char *>(nullptr));
michael@0 72
michael@0 73 int result = XRE_main(targs.Length() - 1, targs.Elements(), appData, 0);
michael@0 74
michael@0 75 if (result)
michael@0 76 LOG("XRE_main returned %d", result);
michael@0 77
michael@0 78 mozilla::widget::android::GeckoAppShell::NotifyXreExit();
michael@0 79
michael@0 80 free(targs[0]);
michael@0 81 nsMemory::Free(data);
michael@0 82 return;
michael@0 83 }

mercurial