Bug 1441982 - Only allow an unopened GeckoSession as a response to onNewSession() r=jchen
This is a little clearer than the current semantics and explicitly allows reusing an
existing GeckoSession instance (as long as it's not yet open).
MozReview-Commit-ID: 8e8gvOEjYze
--- 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
@@ -88,17 +88,16 @@ public class TestRunnerActivity extends
// We can't use e10s because we get deadlocked when quickly creating and
// destroying sessions. Bug 1348361.
settings.setBoolean(GeckoSessionSettings.USE_MULTIPROCESS, false);
}
final GeckoSession session = new GeckoSession(settings);
session.setNavigationDelegate(mNavigationDelegate);
- session.openWindow(this);
return session;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
@@ -106,16 +105,17 @@ public class TestRunnerActivity extends
final String intentArgs = intent.getStringExtra("args");
final String args = intentArgs != null ? "-purgecaches " + intentArgs : "-purgecaches";
GeckoSession.preload(this, args, false /* no multiprocess, see below */);
// We can't use e10s because we get deadlocked when quickly creating and
// destroying sessions. Bug 1348361.
mSession = createSession();
+ mSession.openWindow(this);
// If we were passed a URI in the Intent, open it
final Uri uri = intent.getData();
if (uri != null) {
mSession.loadUri(uri);
}
mView = new GeckoView(this);
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
@@ -146,21 +146,27 @@ public class GeckoSession extends LayerS
delegate.onLoadUri(GeckoSession.this, uri, where);
callback.sendSuccess(result);
} else if ("GeckoView:OnNewSession".equals(event)) {
final String uri = message.getString("uri");
delegate.onNewSession(GeckoSession.this, uri,
new Response<GeckoSession>() {
@Override
public void respond(GeckoSession session) {
- if (session != null && session.isOpen() && session.isReady()) {
- throw new IllegalArgumentException("Must use a new GeckoSession instance");
+ if (session == null) {
+ callback.sendSuccess(null);
+ return;
}
- callback.sendSuccess(session != null ? session.getId() : null);
+ if (session.isOpen()) {
+ throw new IllegalArgumentException("Must use an unopened GeckoSession instance");
+ }
+
+ session.openWindow(null);
+ callback.sendSuccess(session.getId());
}
});
}
}
};
private final GeckoSessionHandler<ProgressDelegate> mProgressHandler =
new GeckoSessionHandler<ProgressDelegate>(