mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 07:42:04 +00:00
Bug 1433968 - Use GeckoRuntime to launch Gecko in Fennec r=jchen
MozReview-Commit-ID: AUrvsFWDuhY
This commit is contained in:
parent
898decb011
commit
83a9f5c1e1
@ -123,7 +123,6 @@ public abstract class GeckoApp extends GeckoActivity
|
||||
public static final String ACTION_ALERT_CALLBACK = "org.mozilla.gecko.ALERT_CALLBACK";
|
||||
public static final String ACTION_HOMESCREEN_SHORTCUT = "org.mozilla.gecko.BOOKMARK";
|
||||
public static final String ACTION_WEBAPP = "org.mozilla.gecko.WEBAPP";
|
||||
public static final String ACTION_DEBUG = "org.mozilla.gecko.DEBUG";
|
||||
public static final String ACTION_LAUNCH_SETTINGS = "org.mozilla.gecko.SETTINGS";
|
||||
public static final String ACTION_LOAD = "org.mozilla.gecko.LOAD";
|
||||
public static final String ACTION_INIT_PW = "org.mozilla.gecko.INIT_PW";
|
||||
@ -998,6 +997,18 @@ public abstract class GeckoApp extends GeckoActivity
|
||||
return;
|
||||
}
|
||||
|
||||
// To prevent races, register startup events before launching the Gecko thread.
|
||||
EventDispatcher.getInstance().registerGeckoThreadListener(this,
|
||||
"Gecko:Ready",
|
||||
null);
|
||||
|
||||
EventDispatcher.getInstance().registerUiThreadListener(this,
|
||||
"Gecko:CorruptAPK",
|
||||
"Update:Check",
|
||||
"Update:Download",
|
||||
"Update:Install",
|
||||
null);
|
||||
|
||||
if (sAlreadyLoaded) {
|
||||
// This happens when the GeckoApp activity is destroyed by Android
|
||||
// without killing the entire application (see Bug 769269).
|
||||
@ -1005,15 +1016,14 @@ public abstract class GeckoApp extends GeckoActivity
|
||||
// also happen if we're not the first activity to run within a session.
|
||||
mIsRestoringActivity = true;
|
||||
Telemetry.addToHistogram("FENNEC_RESTORING_ACTIVITY", 1);
|
||||
|
||||
} else {
|
||||
final String action = intent.getAction();
|
||||
final String[] args = GeckoApplication.getDefaultGeckoArgs();
|
||||
final int flags = ACTION_DEBUG.equals(action) ? GeckoThread.FLAG_DEBUGGING : 0;
|
||||
|
||||
sAlreadyLoaded = true;
|
||||
GeckoThread.initMainProcess(/* profile */ null, args,
|
||||
intent.getExtras(), flags);
|
||||
if (GeckoApplication.getRuntime() == null) {
|
||||
GeckoApplication.createRuntime(this, intent);
|
||||
}
|
||||
|
||||
// Speculatively pre-fetch the profile in the background.
|
||||
ThreadUtils.postToBackgroundThread(new Runnable() {
|
||||
@ -1030,20 +1040,6 @@ public abstract class GeckoApp extends GeckoActivity
|
||||
}
|
||||
}
|
||||
|
||||
// To prevent races, register startup events before launching the Gecko thread.
|
||||
EventDispatcher.getInstance().registerGeckoThreadListener(this,
|
||||
"Gecko:Ready",
|
||||
null);
|
||||
|
||||
EventDispatcher.getInstance().registerUiThreadListener(this,
|
||||
"Gecko:CorruptAPK",
|
||||
"Update:Check",
|
||||
"Update:Download",
|
||||
"Update:Install",
|
||||
null);
|
||||
|
||||
GeckoThread.launch();
|
||||
|
||||
Bundle stateBundle = IntentUtils.getBundleExtraSafe(getIntent(), EXTRA_STATE_BUNDLE);
|
||||
if (stateBundle != null) {
|
||||
// Use the state bundle if it was given as an intent extra. This is
|
||||
@ -1081,7 +1077,7 @@ public abstract class GeckoApp extends GeckoActivity
|
||||
if (mLayerView.getSession() != null) {
|
||||
mLayerView.getSession().close();
|
||||
}
|
||||
mLayerView.setSession(session, GeckoRuntime.getDefault(this));
|
||||
mLayerView.setSession(session, GeckoApplication.getRuntime());
|
||||
mLayerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
|
||||
|
||||
getAppEventDispatcher().registerGeckoThreadListener(this,
|
||||
|
@ -13,10 +13,12 @@ import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Process;
|
||||
import android.os.SystemClock;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.text.TextUtils;
|
||||
@ -38,6 +40,7 @@ import org.mozilla.gecko.icons.Icons;
|
||||
import org.mozilla.gecko.lwt.LightweightTheme;
|
||||
import org.mozilla.gecko.mdns.MulticastDNSManager;
|
||||
import org.mozilla.gecko.media.AudioFocusAgent;
|
||||
import org.mozilla.gecko.mozglue.SafeIntent;
|
||||
import org.mozilla.gecko.notifications.NotificationClient;
|
||||
import org.mozilla.gecko.notifications.NotificationHelper;
|
||||
import org.mozilla.gecko.permissions.Permissions;
|
||||
@ -53,6 +56,8 @@ import org.mozilla.gecko.util.HardwareUtils;
|
||||
import org.mozilla.gecko.util.PRNGFixes;
|
||||
import org.mozilla.gecko.util.ShortcutUtils;
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
import org.mozilla.geckoview.GeckoRuntime;
|
||||
import org.mozilla.geckoview.GeckoRuntimeSettings;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
@ -65,6 +70,7 @@ import java.util.UUID;
|
||||
public class GeckoApplication extends Application
|
||||
implements HapticFeedbackDelegate {
|
||||
private static final String LOG_TAG = "GeckoApplication";
|
||||
public static final String ACTION_DEBUG = "org.mozilla.gecko.DEBUG";
|
||||
private static final String MEDIA_DECODING_PROCESS_CRASH = "MEDIA_DECODING_PROCESS_CRASH";
|
||||
|
||||
private boolean mInBackground;
|
||||
@ -113,7 +119,7 @@ public class GeckoApplication extends Application
|
||||
"startup (JavaScript) caches.");
|
||||
return new String[] { "-purgecaches" };
|
||||
}
|
||||
return null;
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
public static String getDefaultUAString() {
|
||||
@ -210,6 +216,50 @@ public class GeckoApplication extends Application
|
||||
mInBackground = false;
|
||||
}
|
||||
|
||||
private static GeckoRuntime sGeckoRuntime;
|
||||
public static GeckoRuntime getRuntime() {
|
||||
return sGeckoRuntime;
|
||||
}
|
||||
|
||||
public static GeckoRuntime ensureRuntime(@NonNull Context context) {
|
||||
if (sGeckoRuntime != null) {
|
||||
return sGeckoRuntime;
|
||||
}
|
||||
|
||||
return createRuntime(context, null);
|
||||
}
|
||||
|
||||
private static GeckoRuntimeSettings.Builder createSettingsBuilder() {
|
||||
return new GeckoRuntimeSettings.Builder()
|
||||
.javaCrashReportingEnabled(true)
|
||||
.nativeCrashReportingEnabled(true)
|
||||
.arguments(getDefaultGeckoArgs());
|
||||
}
|
||||
|
||||
public static GeckoRuntime createRuntime(@NonNull Context context,
|
||||
@Nullable SafeIntent intent) {
|
||||
if (sGeckoRuntime != null) {
|
||||
throw new IllegalStateException("Already have a GeckoRuntime!");
|
||||
}
|
||||
|
||||
if (context == null) {
|
||||
throw new IllegalArgumentException("Context must not be null");
|
||||
}
|
||||
|
||||
GeckoRuntimeSettings.Builder builder = createSettingsBuilder();
|
||||
if (intent != null) {
|
||||
builder.pauseForDebugger(ACTION_DEBUG.equals(intent.getAction()));
|
||||
|
||||
Bundle extras = intent.getExtras();
|
||||
if (extras != null) {
|
||||
builder.extras(extras);
|
||||
}
|
||||
}
|
||||
|
||||
sGeckoRuntime = GeckoRuntime.create(context, builder.build());
|
||||
return sGeckoRuntime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
Log.i(LOG_TAG, "zerdatime " + SystemClock.elapsedRealtime() +
|
||||
|
@ -18,6 +18,7 @@ import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.mozilla.gecko.mozglue.SafeIntent;
|
||||
import org.mozilla.gecko.util.BundleEventListener;
|
||||
import org.mozilla.gecko.util.GeckoBundle;
|
||||
import org.mozilla.gecko.util.EventCallback;
|
||||
@ -166,19 +167,22 @@ public class GeckoService extends Service {
|
||||
throw new IllegalArgumentException("Intent must specify profile.");
|
||||
}
|
||||
|
||||
if (!GeckoThread.initMainProcessWithProfile(
|
||||
profileName, profileDir != null ? new File(profileDir) : null,
|
||||
GeckoApplication.getDefaultGeckoArgs(), intent.getExtras())) {
|
||||
Log.w(LOGTAG, "Ignoring due to profile mismatch: " +
|
||||
profileName + " [" + profileDir + ']');
|
||||
|
||||
final GeckoProfile profile = GeckoThread.getActiveProfile();
|
||||
if (profile != null) {
|
||||
Log.w(LOGTAG, "Current profile is " + profile.getName() +
|
||||
" [" + profile.getDir().getAbsolutePath() + ']');
|
||||
}
|
||||
return false;
|
||||
if (GeckoApplication.getRuntime() != null) {
|
||||
// Gecko has already been initialized, make sure it's using the
|
||||
// expected profile.
|
||||
return GeckoThread.canUseProfile(profileName,
|
||||
profileDir != null ? new File(profileDir) : null);
|
||||
}
|
||||
|
||||
String args;
|
||||
if (profileDir != null) {
|
||||
args = "-profile " + profileDir;
|
||||
} else {
|
||||
args = "-P " + profileName;
|
||||
}
|
||||
|
||||
intent.putExtra(GeckoThread.EXTRA_ARGS, args);
|
||||
GeckoApplication.createRuntime(this, new SafeIntent(intent));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -192,8 +196,6 @@ public class GeckoService extends Service {
|
||||
return Service.START_NOT_STICKY;
|
||||
}
|
||||
|
||||
GeckoThread.launch();
|
||||
|
||||
switch (intent.getAction()) {
|
||||
case INTENT_ACTION_UPDATE_ADDONS:
|
||||
// Run the add-on update service. Because the service is automatically invoked
|
||||
|
@ -132,7 +132,7 @@ class VirtualPresentation extends CastPresentation {
|
||||
|
||||
// Create new GeckoView
|
||||
view = new GeckoView(getContext());
|
||||
view.setSession(session, GeckoRuntime.getDefault(getContext()));
|
||||
view.setSession(session, GeckoApplication.ensureRuntime(getContext()));
|
||||
view.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
|
||||
LayoutParams.MATCH_PARENT));
|
||||
|
||||
|
@ -37,6 +37,7 @@ import org.mozilla.gecko.Clipboard;
|
||||
import org.mozilla.gecko.DoorHangerPopup;
|
||||
import org.mozilla.gecko.EventDispatcher;
|
||||
import org.mozilla.gecko.FormAssistPopup;
|
||||
import org.mozilla.gecko.GeckoApplication;
|
||||
import org.mozilla.gecko.GeckoSharedPrefs;
|
||||
import org.mozilla.gecko.preferences.GeckoPreferences;
|
||||
import org.mozilla.gecko.R;
|
||||
@ -131,7 +132,7 @@ public class CustomTabsActivity extends AppCompatActivity
|
||||
mGeckoSession.setProgressDelegate(this);
|
||||
mGeckoSession.setContentDelegate(this);
|
||||
|
||||
mGeckoView.setSession(mGeckoSession, GeckoRuntime.getDefault(this));
|
||||
mGeckoView.setSession(mGeckoSession, GeckoApplication.ensureRuntime(this));
|
||||
|
||||
mPromptService = new PromptService(this, mGeckoView.getEventDispatcher());
|
||||
mDoorHangerPopup = new DoorHangerPopup(this, mGeckoView.getEventDispatcher());
|
||||
|
@ -26,6 +26,7 @@ import org.mozilla.gecko.AppConstants;
|
||||
import org.mozilla.gecko.BrowserApp;
|
||||
import org.mozilla.gecko.DoorHangerPopup;
|
||||
import org.mozilla.gecko.FormAssistPopup;
|
||||
import org.mozilla.gecko.GeckoApplication;
|
||||
import org.mozilla.gecko.GeckoScreenOrientation;
|
||||
import org.mozilla.gecko.GeckoSharedPrefs;
|
||||
import org.mozilla.gecko.preferences.GeckoPreferences;
|
||||
@ -97,7 +98,7 @@ public class WebAppActivity extends AppCompatActivity
|
||||
final GeckoSessionSettings settings = new GeckoSessionSettings();
|
||||
settings.setBoolean(GeckoSessionSettings.USE_MULTIPROCESS, false);
|
||||
mGeckoSession = new GeckoSession(settings);
|
||||
mGeckoView.setSession(mGeckoSession, GeckoRuntime.getDefault(this));
|
||||
mGeckoView.setSession(mGeckoSession, GeckoApplication.ensureRuntime(this));
|
||||
|
||||
mGeckoSession.setNavigationDelegate(this);
|
||||
mGeckoSession.setContentDelegate(this);
|
||||
|
@ -130,7 +130,7 @@ public class GeckoThread extends Thread {
|
||||
public static final int FLAG_ENABLE_NATIVE_CRASHREPORTER = 1 << 2; // Enable native crash reporting
|
||||
public static final int FLAG_ENABLE_JAVA_CRASHREPORTER = 1 << 3; // Enable java crash reporting
|
||||
|
||||
private static final String EXTRA_ARGS = "args";
|
||||
/* package */ static final String EXTRA_ARGS = "args";
|
||||
private static final String EXTRA_PREFS_FD = "prefsFd";
|
||||
private static final String EXTRA_IPC_FD = "ipcFd";
|
||||
private static final String EXTRA_CRASH_FD = "crashFd";
|
||||
|
Loading…
Reference in New Issue
Block a user