Bug 1443283 - Prevent crash when a null or open GeckoSession is registered with GeckoView.setSession() r=jchen,esawin

MozReview-Commit-ID: HV7xoz7fr6k
This commit is contained in:
Randall Barker 2018-03-05 12:41:34 -08:00
Родитель 4d670d3ab3
Коммит a248afab67
1 изменённых файлов: 21 добавлений и 8 удалений

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

@ -192,18 +192,31 @@ public class GeckoView extends FrameLayout {
}
}
public GeckoSession releaseSession() {
if (mSession == null) {
return null;
}
GeckoSession session = mSession;
mSession.releaseDisplay(mDisplay.release());
mSession.getOverscrollEdgeEffect().setInvalidationCallback(null);
mSession.getCompositorController().setFirstPaintCallback(null);
mSession = null;
return session;
}
public void setSession(final GeckoSession session) {
if (mSession != null && mSession.isOpen()) {
throw new IllegalStateException("Current session is open");
}
if (mSession != null) {
mSession.releaseDisplay(mDisplay.release());
}
if (session != null) {
mDisplay.acquire(session.acquireDisplay());
releaseSession();
mSession = session;
if (mSession == null) {
return;
}
mDisplay.acquire(session.acquireDisplay());
final Context context = getContext();
session.getOverscrollEdgeEffect().setTheme(context);
session.getOverscrollEdgeEffect().setInvalidationCallback(new Runnable() {
@ -232,8 +245,6 @@ public class GeckoView extends FrameLayout {
coverUntilFirstPaint(Color.TRANSPARENT);
}
});
mSession = session;
}
public GeckoSession getSession() {
@ -275,7 +286,9 @@ public class GeckoView extends FrameLayout {
public void onDetachedFromWindow() {
super.onDetachedFromWindow();
mSession.getTextInputController().setView(this);
if (mSession != null) {
mSession.getTextInputController().setView(null);
}
if (mStateSaved) {
// If we saved state earlier, we don't want to close the window.