Bug 889881 - Refactor and add a Gecko handler to ThreadUtils; r=blassey

This commit is contained in:
Jim Chen 2013-07-09 16:25:55 -04:00
parent 26cb0d9f4e
commit bef2e265c2
5 changed files with 13 additions and 4 deletions

View File

@ -1435,7 +1435,6 @@ abstract public class GeckoApp
if (!mIsRestoringActivity) {
sGeckoThread = new GeckoThread(intent, passedUri);
ThreadUtils.setGeckoThread(sGeckoThread);
}
if (!ACTION_DEBUG.equals(action) &&
GeckoThread.checkAndSetLaunchState(GeckoThread.LaunchState.Launching, GeckoThread.LaunchState.Launched)) {

View File

@ -293,7 +293,6 @@ public class GeckoAppShell
}
public static void runGecko(String apkPath, String args, String url, String type) {
Looper.prepare();
// run gecko -- it will spawn its own thread
GeckoAppShell.nativeInit();

View File

@ -7,6 +7,7 @@ package org.mozilla.gecko;
import org.mozilla.gecko.mozglue.GeckoLoader;
import org.mozilla.gecko.util.GeckoEventListener;
import org.mozilla.gecko.util.ThreadUtils;
import org.json.JSONObject;
@ -14,6 +15,8 @@ import android.content.Intent;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
import android.util.Log;
import android.app.Activity;
@ -100,6 +103,9 @@ public class GeckoThread extends Thread implements GeckoEventListener {
@Override
public void run() {
Looper.prepare();
ThreadUtils.setGeckoThread(this, new Handler());
String path = initGeckoEnvironment();
Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - runGecko");

View File

@ -54,7 +54,6 @@ public class GeckoView extends LayerView
GeckoAppShell.registerEventListener("Gecko:Ready", this);
sGeckoThread = new GeckoThread(intent, url);
ThreadUtils.setGeckoThread(sGeckoThread);
ThreadUtils.setUiThread(Thread.currentThread(), new Handler());
initializeView(GeckoAppShell.getEventDispatcher());
if (GeckoThread.checkAndSetLaunchState(GeckoThread.LaunchState.Launching, GeckoThread.LaunchState.Launched)) {

View File

@ -18,6 +18,7 @@ public final class ThreadUtils {
private static Thread sBackgroundThread;
private static Handler sUiHandler;
private static Handler sGeckoHandler;
@SuppressWarnings("serial")
public static class UiThreadBlockedException extends RuntimeException {
@ -55,8 +56,9 @@ public final class ThreadUtils {
sUiHandler = handler;
}
public static void setGeckoThread(Thread thread) {
public static void setGeckoThread(Thread thread, Handler handler) {
sGeckoThread = thread;
sGeckoHandler = handler;
}
public static void setBackgroundThread(Thread thread) {
@ -79,6 +81,10 @@ public final class ThreadUtils {
return sGeckoThread;
}
public static Handler getGeckoHandler() {
return sGeckoHandler;
}
public static Thread getBackgroundThread() {
return sBackgroundThread;
}