Bug 1225980 - Add a startGecko static method to GeckoService, to be used for GeckoCustomTabsService.warmup() r=rbarker

This commit is contained in:
Dylan Roeh 2016-11-09 11:22:45 -06:00
Родитель 5df0c97c52
Коммит bf12b08d30
2 изменённых файлов: 37 добавлений и 2 удалений

Просмотреть файл

@ -11,6 +11,8 @@ import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import java.io.File;
@ -205,4 +207,30 @@ public class GeckoService extends Service {
public IBinder onBind(final Intent intent) {
return null;
}
public static void startGecko(final GeckoProfile profile, final String args, final Context context) {
if (GeckoThread.isLaunched()) {
if (DEBUG) {
Log.v(LOGTAG, "already launched");
}
return;
}
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
GeckoAppShell.ensureCrashHandling();
GeckoAppShell.setApplicationContext(context);
GeckoThread.onResume();
GeckoThread.init(profile, args, null, false);
GeckoThread.launch();
if (DEBUG) {
Log.v(LOGTAG, "warmed up (launched)");
}
}
});
}
}

Просмотреть файл

@ -11,6 +11,9 @@ import android.support.customtabs.CustomTabsService;
import android.support.customtabs.CustomTabsSessionToken;
import android.util.Log;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.GeckoService;
import java.util.List;
/**
@ -18,6 +21,7 @@ import java.util.List;
*/
public class GeckoCustomTabsService extends CustomTabsService {
private static final String LOGTAG = "GeckoCustomTabsService";
private static final boolean DEBUG = false;
@Override
protected boolean updateVisuals(CustomTabsSessionToken sessionToken, Bundle bundle) {
@ -28,9 +32,12 @@ public class GeckoCustomTabsService extends CustomTabsService {
@Override
protected boolean warmup(long flags) {
Log.v(LOGTAG, "warmup()");
if (DEBUG) {
Log.v(LOGTAG, "warming up...");
}
GeckoService.startGecko(GeckoProfile.initFromArgs(this, null), null, getApplicationContext());
// Pretend warmup was successful
return true;
}