2010-06-03 18:16:20 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-06-03 18:16:20 -07:00
|
|
|
|
|
|
|
#include <android/log.h>
|
|
|
|
|
|
|
|
#include <jni.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsString.h"
|
2012-06-05 19:08:30 -07:00
|
|
|
#include "nsIFile.h"
|
2010-06-03 18:16:20 -07:00
|
|
|
#include "nsAppRunner.h"
|
|
|
|
#include "AndroidBridge.h"
|
2010-10-20 17:44:03 -07:00
|
|
|
#include "APKOpen.h"
|
|
|
|
#include "nsExceptionHandler.h"
|
2010-06-03 18:16:20 -07:00
|
|
|
|
|
|
|
#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, MOZ_APP_NAME, args)
|
|
|
|
|
2012-02-21 23:12:15 -08:00
|
|
|
// 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.
|
|
|
|
|
2010-06-03 18:16:20 -07:00
|
|
|
struct AutoAttachJavaThread {
|
|
|
|
AutoAttachJavaThread() {
|
2013-09-09 05:57:37 -07:00
|
|
|
attached = mozilla_AndroidBridge_SetMainThread(pthread_self());
|
2010-06-03 18:16:20 -07:00
|
|
|
}
|
|
|
|
~AutoAttachJavaThread() {
|
2013-09-09 05:57:37 -07:00
|
|
|
mozilla_AndroidBridge_SetMainThread(-1);
|
2011-10-17 07:59:28 -07:00
|
|
|
attached = false;
|
2010-06-03 18:16:20 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool attached;
|
2010-06-03 18:16:20 -07:00
|
|
|
};
|
|
|
|
|
2012-02-21 23:12:15 -08:00
|
|
|
extern "C" NS_EXPORT void
|
|
|
|
GeckoStart(void *data, const nsXREAppData *appData)
|
2010-06-03 18:16:20 -07:00
|
|
|
{
|
2010-10-20 17:44:03 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2010-10-29 12:22:28 -07:00
|
|
|
const struct mapping_info *info = getLibraryMapping();
|
2010-10-20 17:44:03 -07:00
|
|
|
while (info->name) {
|
2013-04-09 05:04:53 -07:00
|
|
|
CrashReporter::AddLibraryMapping(info->name, info->base,
|
2010-10-20 17:44:03 -07:00
|
|
|
info->len, info->offset);
|
|
|
|
info++;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-06-03 18:16:20 -07:00
|
|
|
AutoAttachJavaThread attacher;
|
|
|
|
if (!attacher.attached)
|
2012-02-21 23:12:15 -08:00
|
|
|
return;
|
2010-06-03 18:16:20 -07:00
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
LOG("Failed to get arguments for GeckoStart\n");
|
2012-02-21 23:12:15 -08:00
|
|
|
return;
|
2010-06-03 18:16:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<char *> targs;
|
|
|
|
char *arg = strtok(static_cast<char *>(data), " ");
|
|
|
|
while (arg) {
|
|
|
|
targs.AppendElement(arg);
|
2013-10-10 13:36:42 -07:00
|
|
|
arg = strtok(nullptr, " ");
|
2010-06-03 18:16:20 -07:00
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
targs.AppendElement(static_cast<char *>(nullptr));
|
2010-10-20 17:44:03 -07:00
|
|
|
|
2012-05-25 03:01:29 -07:00
|
|
|
int result = XRE_main(targs.Length() - 1, targs.Elements(), appData, 0);
|
2010-06-03 18:16:20 -07:00
|
|
|
|
|
|
|
if (result)
|
|
|
|
LOG("XRE_main returned %d", result);
|
|
|
|
|
2013-11-12 10:41:01 -08:00
|
|
|
mozilla::widget::android::GeckoAppShell::NotifyXreExit();
|
2010-06-03 18:16:20 -07:00
|
|
|
|
|
|
|
free(targs[0]);
|
|
|
|
nsMemory::Free(data);
|
2012-02-21 23:12:15 -08:00
|
|
|
return;
|
2010-06-03 18:16:20 -07:00
|
|
|
}
|