2010-06-04 05:16:20 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 15:12:37 +04: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-04 05:16:20 +04: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-06 06:08:30 +04:00
|
|
|
#include "nsIFile.h"
|
2010-06-04 05:16:20 +04:00
|
|
|
#include "nsAppRunner.h"
|
|
|
|
#include "AndroidBridge.h"
|
2010-10-21 04:44:03 +04:00
|
|
|
#include "APKOpen.h"
|
|
|
|
#include "nsExceptionHandler.h"
|
2010-06-04 05:16:20 +04:00
|
|
|
|
|
|
|
#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, MOZ_APP_NAME, args)
|
|
|
|
|
2012-02-22 11:12:15 +04: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-04 05:16:20 +04:00
|
|
|
struct AutoAttachJavaThread {
|
|
|
|
AutoAttachJavaThread() {
|
2013-09-09 16:57:37 +04:00
|
|
|
attached = mozilla_AndroidBridge_SetMainThread(pthread_self());
|
2010-06-04 05:16:20 +04:00
|
|
|
}
|
|
|
|
~AutoAttachJavaThread() {
|
2013-09-09 16:57:37 +04:00
|
|
|
mozilla_AndroidBridge_SetMainThread(-1);
|
2011-10-17 18:59:28 +04:00
|
|
|
attached = false;
|
2010-06-04 05:16:20 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool attached;
|
2010-06-04 05:16:20 +04:00
|
|
|
};
|
|
|
|
|
2012-02-22 11:12:15 +04:00
|
|
|
extern "C" NS_EXPORT void
|
|
|
|
GeckoStart(void *data, const nsXREAppData *appData)
|
2010-06-04 05:16:20 +04:00
|
|
|
{
|
2010-10-21 04:44:03 +04:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2010-10-29 23:22:28 +04:00
|
|
|
const struct mapping_info *info = getLibraryMapping();
|
2010-10-21 04:44:03 +04:00
|
|
|
while (info->name) {
|
2013-04-09 16:04:53 +04:00
|
|
|
CrashReporter::AddLibraryMapping(info->name, info->base,
|
2010-10-21 04:44:03 +04:00
|
|
|
info->len, info->offset);
|
|
|
|
info++;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-06-04 05:16:20 +04:00
|
|
|
AutoAttachJavaThread attacher;
|
|
|
|
if (!attacher.attached)
|
2012-02-22 11:12:15 +04:00
|
|
|
return;
|
2010-06-04 05:16:20 +04:00
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
LOG("Failed to get arguments for GeckoStart\n");
|
2012-02-22 11:12:15 +04:00
|
|
|
return;
|
2010-06-04 05:16:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<char *> targs;
|
|
|
|
char *arg = strtok(static_cast<char *>(data), " ");
|
|
|
|
while (arg) {
|
|
|
|
targs.AppendElement(arg);
|
2013-10-11 00:36:42 +04:00
|
|
|
arg = strtok(nullptr, " ");
|
2010-06-04 05:16:20 +04:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
targs.AppendElement(static_cast<char *>(nullptr));
|
2010-10-21 04:44:03 +04:00
|
|
|
|
2012-05-25 14:01:29 +04:00
|
|
|
int result = XRE_main(targs.Length() - 1, targs.Elements(), appData, 0);
|
2010-06-04 05:16:20 +04:00
|
|
|
|
|
|
|
if (result)
|
|
|
|
LOG("XRE_main returned %d", result);
|
|
|
|
|
2013-11-12 22:41:01 +04:00
|
|
|
mozilla::widget::android::GeckoAppShell::NotifyXreExit();
|
2010-06-04 05:16:20 +04:00
|
|
|
|
|
|
|
free(targs[0]);
|
|
|
|
nsMemory::Free(data);
|
2012-02-22 11:12:15 +04:00
|
|
|
return;
|
2010-06-04 05:16:20 +04:00
|
|
|
}
|