1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include <android/log.h>
17 #include "nsAppRunner.h"
18 #include "AndroidBridge.h"
20 #include "nsExceptionHandler.h"
22 #define LOG(args...) __android_log_print(ANDROID_LOG_INFO, MOZ_APP_NAME, args)
24 // We need to put Gecko on a even more separate thread, because
25 // otherwise this JNI method never returns; this leads to problems
26 // with local references overrunning the local refs table, among
27 // other things, since GC can't ever run on them.
29 // Note that we don't have xpcom initialized yet, so we can't use the
30 // thread manager for this. Instead, we use pthreads directly.
32 struct AutoAttachJavaThread
{
33 AutoAttachJavaThread() {
34 attached
= mozilla_AndroidBridge_SetMainThread(pthread_self());
36 ~AutoAttachJavaThread() {
37 mozilla_AndroidBridge_SetMainThread(-1);
44 extern "C" NS_EXPORT
void
45 GeckoStart(void *data
, const nsXREAppData
*appData
)
47 #ifdef MOZ_CRASHREPORTER
48 const struct mapping_info
*info
= getLibraryMapping();
50 CrashReporter::AddLibraryMapping(info
->name
, info
->base
,
51 info
->len
, info
->offset
);
56 AutoAttachJavaThread attacher
;
57 if (!attacher
.attached
)
61 LOG("Failed to get arguments for GeckoStart\n");
65 nsTArray
<char *> targs
;
66 char *arg
= strtok(static_cast<char *>(data
), " ");
68 targs
.AppendElement(arg
);
69 arg
= strtok(nullptr, " ");
71 targs
.AppendElement(static_cast<char *>(nullptr));
73 int result
= XRE_main(targs
.Length() - 1, targs
.Elements(), appData
, 0);
76 LOG("XRE_main returned %d", result
);
78 mozilla::widget::android::GeckoAppShell::NotifyXreExit();