Bug 1442255 - 3. Use extras bundle to initialize Gecko in GeckoView; r=esawin
Use extras bundle to initialize Gecko in GeckoSession and
GeckoViewActivity.
MozReview-Commit-ID: 7dtaziVBDcg
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/TestRunnerActivity.java
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/TestRunnerActivity.java
@@ -96,22 +96,19 @@ public class TestRunnerActivity extends
session.openWindow(this);
return session;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- Intent intent = getIntent();
- GeckoLoader.setLastIntent(new SafeIntent(getIntent()));
-
- final String intentArgs = intent.getStringExtra("args");
- final String args = intentArgs != null ? "-purgecaches " + intentArgs : "-purgecaches";
- GeckoSession.preload(this, args, false /* no multiprocess, see below */);
+ final Intent intent = getIntent();
+ GeckoSession.preload(this, new String[] { "-purgecaches" },
+ intent.getExtras(), false /* no multiprocess, see below */);
// We can't use e10s because we get deadlocked when quickly creating and
// destroying sessions. Bug 1348361.
mSession = createSession();
// If we were passed a URI in the Intent, open it
final Uri uri = intent.getData();
if (uri != null) {
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
@@ -26,21 +26,23 @@ import org.mozilla.gecko.util.GeckoBundl
import org.mozilla.gecko.util.ThreadUtils;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.database.Cursor;
import android.net.Uri;
import android.os.Binder;
+import android.os.Bundle;
import android.os.IBinder;
import android.os.IInterface;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.SystemClock;
+import android.support.annotation.Nullable;
import android.support.annotation.NonNull;
import android.util.Log;
public class GeckoSession extends LayerSession
implements Parcelable {
private static final String LOGTAG = "GeckoSession";
private static final boolean DEBUG = false;
@@ -540,62 +542,73 @@ public class GeckoSession extends LayerS
}
};
/**
* Preload GeckoSession by starting Gecko in the background, if Gecko is not already running.
*
* @param context Activity or Application Context for starting GeckoSession.
*/
- public static void preload(final Context context) {
- preload(context, /* geckoArgs */ null, /* multiprocess */ false);
+ public static void preload(final @NonNull Context context) {
+ preload(context, /* geckoArgs */ null,
+ /* extras */ null, /* multiprocess */ false);
}
/**
* Preload GeckoSession by starting Gecko with the specified arguments in the background,
* if Gecko is not already running.
*
* @param context Activity or Application Context for starting GeckoSession.
* @param geckoArgs Arguments to be passed to Gecko, if Gecko is not already running.
* @param multiprocess True if child process in multiprocess mode should be preloaded.
*/
- public static void preload(final Context context, final String geckoArgs,
+ public static void preload(final @NonNull Context context,
+ final @Nullable String[] geckoArgs,
+ final @Nullable Bundle extras,
final boolean multiprocess) {
final Context appContext = context.getApplicationContext();
- if (GeckoAppShell.getApplicationContext() == null) {
+ if (!appContext.equals(GeckoAppShell.getApplicationContext())) {
GeckoAppShell.setApplicationContext(appContext);
}
+ if (GeckoThread.isLaunched()) {
+ return;
+ }
+
final int flags = multiprocess ? GeckoThread.FLAG_PRELOAD_CHILD : 0;
- if (GeckoThread.initMainProcess(/* profile */ null, geckoArgs, flags)) {
+ if (GeckoThread.initMainProcess(/* profile */ null, geckoArgs, extras, flags)) {
GeckoThread.launch();
}
}
public boolean isOpen() {
return mWindow != null;
}
/* package */ boolean isReady() {
return mNativeQueue.isReady();
}
- public void openWindow(final Context appContext) {
+ public void openWindow(final @Nullable Context appContext) {
ThreadUtils.assertOnUiThread();
if (isOpen()) {
throw new IllegalStateException("Session is open");
}
- if (!GeckoThread.isLaunched()) {
+ if (appContext != null) {
final boolean multiprocess =
mSettings.getBoolean(GeckoSessionSettings.USE_MULTIPROCESS);
- preload(appContext, /* geckoArgs */ null, multiprocess);
+ preload(appContext, /* geckoArgs */ null, /* extras */ null, multiprocess);
}
+ openWindow();
+ }
+
+ private void openWindow() {
final String chromeUri = mSettings.getString(GeckoSessionSettings.CHROME_URI);
final int screenId = mSettings.getInt(GeckoSessionSettings.SCREEN_ID);
final boolean isPrivate = mSettings.getBoolean(GeckoSessionSettings.USE_PRIVATE_MODE);
mWindow = new Window(mNativeQueue);
if (GeckoThread.isStateAtLeast(GeckoThread.State.PROFILE_READY)) {
Window.open(mWindow, mCompositor, mEventDispatcher,
--- a/mobile/android/geckoview_example/src/main/java/org/mozilla/geckoview_example/GeckoViewActivity.java
+++ b/mobile/android/geckoview_example/src/main/java/org/mozilla/geckoview_example/GeckoViewActivity.java
@@ -43,35 +43,28 @@ public class GeckoViewActivity extends A
private GeckoView mGeckoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i(LOGTAG, "zerdatime " + SystemClock.elapsedRealtime() +
" - application start");
- String geckoArgs = null;
- final String intentArgs = getIntent().getStringExtra("args");
+ final String[] geckoArgs;
if (BuildConfig.DEBUG) {
// In debug builds, we want to load JavaScript resources fresh with each build.
- geckoArgs = "-purgecaches";
- }
-
- if (!TextUtils.isEmpty(intentArgs)) {
- if (geckoArgs == null) {
- geckoArgs = intentArgs;
- } else {
- geckoArgs += " " + intentArgs;
- }
+ geckoArgs = new String[] { "-purgecaches" };
+ } else {
+ geckoArgs = null;
}
final boolean useMultiprocess = getIntent().getBooleanExtra(USE_MULTIPROCESS_EXTRA,
true);
- GeckoSession.preload(this, geckoArgs, useMultiprocess);
+ GeckoSession.preload(this, geckoArgs, getIntent().getExtras(), useMultiprocess);
setContentView(R.layout.geckoview_activity);
mGeckoView = (GeckoView) findViewById(R.id.gecko_view);
mGeckoSession = new GeckoSession();
mGeckoView.setSession(mGeckoSession);
mGeckoSession.setContentDelegate(new MyGeckoViewContent());