1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/xre/nsAndroidStartup.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,83 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include <android/log.h> 1.10 + 1.11 +#include <jni.h> 1.12 + 1.13 +#include <stdlib.h> 1.14 +#include <string.h> 1.15 +#include <pthread.h> 1.16 + 1.17 +#include "nsTArray.h" 1.18 +#include "nsString.h" 1.19 +#include "nsIFile.h" 1.20 +#include "nsAppRunner.h" 1.21 +#include "AndroidBridge.h" 1.22 +#include "APKOpen.h" 1.23 +#include "nsExceptionHandler.h" 1.24 + 1.25 +#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, MOZ_APP_NAME, args) 1.26 + 1.27 +// We need to put Gecko on a even more separate thread, because 1.28 +// otherwise this JNI method never returns; this leads to problems 1.29 +// with local references overrunning the local refs table, among 1.30 +// other things, since GC can't ever run on them. 1.31 + 1.32 +// Note that we don't have xpcom initialized yet, so we can't use the 1.33 +// thread manager for this. Instead, we use pthreads directly. 1.34 + 1.35 +struct AutoAttachJavaThread { 1.36 + AutoAttachJavaThread() { 1.37 + attached = mozilla_AndroidBridge_SetMainThread(pthread_self()); 1.38 + } 1.39 + ~AutoAttachJavaThread() { 1.40 + mozilla_AndroidBridge_SetMainThread(-1); 1.41 + attached = false; 1.42 + } 1.43 + 1.44 + bool attached; 1.45 +}; 1.46 + 1.47 +extern "C" NS_EXPORT void 1.48 +GeckoStart(void *data, const nsXREAppData *appData) 1.49 +{ 1.50 +#ifdef MOZ_CRASHREPORTER 1.51 + const struct mapping_info *info = getLibraryMapping(); 1.52 + while (info->name) { 1.53 + CrashReporter::AddLibraryMapping(info->name, info->base, 1.54 + info->len, info->offset); 1.55 + info++; 1.56 + } 1.57 +#endif 1.58 + 1.59 + AutoAttachJavaThread attacher; 1.60 + if (!attacher.attached) 1.61 + return; 1.62 + 1.63 + if (!data) { 1.64 + LOG("Failed to get arguments for GeckoStart\n"); 1.65 + return; 1.66 + } 1.67 + 1.68 + nsTArray<char *> targs; 1.69 + char *arg = strtok(static_cast<char *>(data), " "); 1.70 + while (arg) { 1.71 + targs.AppendElement(arg); 1.72 + arg = strtok(nullptr, " "); 1.73 + } 1.74 + targs.AppendElement(static_cast<char *>(nullptr)); 1.75 + 1.76 + int result = XRE_main(targs.Length() - 1, targs.Elements(), appData, 0); 1.77 + 1.78 + if (result) 1.79 + LOG("XRE_main returned %d", result); 1.80 + 1.81 + mozilla::widget::android::GeckoAppShell::NotifyXreExit(); 1.82 + 1.83 + free(targs[0]); 1.84 + nsMemory::Free(data); 1.85 + return; 1.86 +}