mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 19:35:51 +00:00
Bug 730890 - Set up an Android Looper on the main Gecko thread r=cjones
This commit is contained in:
parent
840bca261e
commit
8af3688ba1
@ -67,20 +67,11 @@ anp_event_postEvent(NPP inst, const ANPEvent* event)
|
||||
{
|
||||
LOG("%s", __PRETTY_FUNCTION__);
|
||||
|
||||
JNIEnv* env = GetJNIForThread();
|
||||
if (!env)
|
||||
return;
|
||||
|
||||
if (!mozilla::AndroidBridge::Bridge()) {
|
||||
LOG("no bridge in %s!!!!", __PRETTY_FUNCTION__);
|
||||
return;
|
||||
}
|
||||
|
||||
nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(inst->ndata);
|
||||
NPPluginFuncs* pluginFunctions = pinst->GetPlugin()->PluginFuncs();
|
||||
mozilla::AndroidBridge::Bridge()->PostToJavaThread(env,
|
||||
new PluginEventRunnable(inst, const_cast<ANPEvent*>(event), pluginFunctions),
|
||||
true);
|
||||
PluginEventRunnable* e = new PluginEventRunnable(inst, const_cast<ANPEvent*>(event), pluginFunctions);
|
||||
|
||||
NS_DispatchToMainThread(e);
|
||||
LOG("returning from %s", __PRETTY_FUNCTION__);
|
||||
}
|
||||
|
||||
|
@ -47,6 +47,10 @@
|
||||
#include "base/logging.h"
|
||||
#include "base/scoped_nsautorelease_pool.h"
|
||||
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
#include "AndroidBridge.h"
|
||||
#endif
|
||||
|
||||
using mozilla::ipc::DoWorkRunnable;
|
||||
using mozilla::ipc::MessagePump;
|
||||
using mozilla::ipc::MessagePumpForChildProcess;
|
||||
@ -111,6 +115,10 @@ MessagePump::Run(MessagePump::Delegate* aDelegate)
|
||||
if (!keep_running_)
|
||||
break;
|
||||
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
AndroidBridge::Bridge()->PumpMessageLoop();
|
||||
#endif
|
||||
|
||||
did_work |= aDelegate->DoWork();
|
||||
if (!keep_running_)
|
||||
break;
|
||||
|
@ -137,6 +137,8 @@ public class GeckoAppShell
|
||||
|
||||
private static boolean mLocationHighAccuracy = false;
|
||||
|
||||
private static Handler sGeckoHandler;
|
||||
|
||||
/* The Android-side API: API methods that Android calls */
|
||||
|
||||
// Initialization methods
|
||||
@ -242,6 +244,10 @@ public class GeckoAppShell
|
||||
return GeckoApp.mAppContext.mMainHandler;
|
||||
}
|
||||
|
||||
public static Handler getGeckoHandler() {
|
||||
return sGeckoHandler;
|
||||
}
|
||||
|
||||
public static Handler getHandler() {
|
||||
return GeckoBackgroundThread.getHandler();
|
||||
}
|
||||
@ -431,6 +437,9 @@ public class GeckoAppShell
|
||||
}
|
||||
|
||||
public static void runGecko(String apkPath, String args, String url, boolean restoreSession) {
|
||||
Looper.prepare();
|
||||
sGeckoHandler = new Handler();
|
||||
|
||||
// run gecko -- it will spawn its own thread
|
||||
GeckoAppShell.nativeInit();
|
||||
|
||||
@ -2051,6 +2060,23 @@ public class GeckoAppShell
|
||||
GeckoScreenOrientationListener.getInstance().unlockScreenOrientation();
|
||||
}
|
||||
|
||||
public static void pumpMessageLoop() {
|
||||
// We're going to run the Looper below, but we need a way to break out, so
|
||||
// we post this Runnable that causes a divide by zero error. The Runnable
|
||||
// is added to the end of the queue, so it will be executed after anything
|
||||
// else that has been added prior.
|
||||
sGeckoHandler.post(new Runnable() {
|
||||
public void run() {
|
||||
int zero = 0;
|
||||
int foo = 0xdeadbeef / zero;
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
Looper.loop();
|
||||
} catch(Exception ex) {}
|
||||
}
|
||||
|
||||
static class AsyncResultHandler extends GeckoApp.FilePickerResultHandler {
|
||||
private long mId;
|
||||
AsyncResultHandler(long id) {
|
||||
|
@ -191,6 +191,7 @@ AndroidBridge::Init(JNIEnv *jEnv,
|
||||
jDisableScreenOrientationNotifications = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "disableScreenOrientationNotifications", "()V");
|
||||
jLockScreenOrientation = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "lockScreenOrientation", "(I)V");
|
||||
jUnlockScreenOrientation = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "unlockScreenOrientation", "()V");
|
||||
jPumpMessageLoop = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "pumpMessageLoop", "()V");
|
||||
|
||||
jEGLContextClass = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("javax/microedition/khronos/egl/EGLContext"));
|
||||
jEGL10Class = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("javax/microedition/khronos/egl/EGL10"));
|
||||
@ -2130,6 +2131,15 @@ AndroidBridge::UnlockScreenOrientation()
|
||||
mJNIEnv->CallStaticVoidMethod(mGeckoAppShellClass, jUnlockScreenOrientation);
|
||||
}
|
||||
|
||||
void
|
||||
AndroidBridge::PumpMessageLoop()
|
||||
{
|
||||
if (!mJNIEnv)
|
||||
return;
|
||||
|
||||
mJNIEnv->CallStaticVoidMethod(mGeckoAppShellClass, jPumpMessageLoop);
|
||||
}
|
||||
|
||||
/* attribute nsIAndroidBrowserApp browserApp; */
|
||||
NS_IMETHODIMP nsAndroidBridge::GetBrowserApp(nsIAndroidBrowserApp * *aBrowserApp)
|
||||
{
|
||||
|
@ -437,6 +437,8 @@ public:
|
||||
void LockScreenOrientation(const dom::ScreenOrientationWrapper& aOrientation);
|
||||
void UnlockScreenOrientation();
|
||||
|
||||
void PumpMessageLoop();
|
||||
|
||||
protected:
|
||||
static AndroidBridge *sBridge;
|
||||
|
||||
@ -548,6 +550,7 @@ protected:
|
||||
jmethodID jDisableScreenOrientationNotifications;
|
||||
jmethodID jLockScreenOrientation;
|
||||
jmethodID jUnlockScreenOrientation;
|
||||
jmethodID jPumpMessageLoop;
|
||||
|
||||
// stuff we need for CallEglCreateWindowSurface
|
||||
jclass jEGLSurfaceImplClass;
|
||||
|
Loading…
Reference in New Issue
Block a user