Bug 1443283 - Prevent crash when a null or open GeckoSession is registered with GeckoView.setSession() r=jchen,esawin
authorRandall Barker <rbarker@mozilla.com>
Mon, 05 Mar 2018 12:41:34 -0800
changeset 407218 9a824b10df47
parent 407217 e27feda042d6
child 407219 4c664530b7e3
push id33596
push userncsoregi@mozilla.com
push date2018-03-09 00:18 +0000
treeherdermozilla-central@31a33fc61956 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjchen, esawin
bugs1443283
milestone60.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1443283 - Prevent crash when a null or open GeckoSession is registered with GeckoView.setSession() r=jchen,esawin MozReview-Commit-ID: HV7xoz7fr6k
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoView.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoView.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoView.java
@@ -187,28 +187,41 @@ public class GeckoView extends FrameLayo
      * @param color Cover color.
      */
     public void coverUntilFirstPaint(final int color) {
         if (mSurfaceView != null) {
             mSurfaceView.setBackgroundColor(color);
         }
     }
 
+    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() {
             @Override
             public void run() {
                 if (Build.VERSION.SDK_INT >= 16) {
                     GeckoView.this.postInvalidateOnAnimation();
                 } else {
@@ -227,18 +240,16 @@ public class GeckoView extends FrameLayo
         }
 
         session.getCompositorController().setFirstPaintCallback(new Runnable() {
             @Override
             public void run() {
                 coverUntilFirstPaint(Color.TRANSPARENT);
             }
         });
-
-        mSession = session;
     }
 
     public GeckoSession getSession() {
         return mSession;
     }
 
     public EventDispatcher getEventDispatcher() {
         return mSession.getEventDispatcher();
@@ -270,17 +281,19 @@ public class GeckoView extends FrameLayo
 
         super.onAttachedToWindow();
     }
 
     @Override
     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.
             return;
         }
 
         if (mSession != null && mSession.isOpen()) {
             mSession.close();