Bug 1542009 - Don't create a GeckoSession if there isn't one. r=geckoview-reviewers,esawin,snorp
authorAgi Sferro <agi@mozilla.com>
Mon, 15 Apr 2019 17:14:46 +0000
changeset 469541 82ec6a86a2bce943561551381576e79ecf517a43
parent 469540 f057b78337e7442427b3379537c67d5761f2bf39
child 469542 c860fa255272b3539cfee29f7c55a1d0c57da8d4
push id112801
push userccoroiu@mozilla.com
push dateMon, 15 Apr 2019 21:40:09 +0000
treeherdermozilla-inbound@afb20612c0e5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgeckoview-reviewers, esawin, snorp
bugs1542009
milestone68.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 1542009 - Don't create a GeckoSession if there isn't one. r=geckoview-reviewers,esawin,snorp This fixes a problem where Gecko would call Vsync even when the browser does not have a surface attached to. This can be triggered by attaching a GeckoView without a session and then attaching a GeckoSession to the view. This causes GeckoView to create two Windows, one of which never gets put in the background causing Gecko to think the browser is still visible. The GeckoSession should be cleaned up by the GC but this may take a long time. To avoid this footgun we just don't create a GeckoSession when there isn't one already attached to the GeckoView, logging a warning in case the embedder is confused by the blank screen. Differential Revision: https://phabricator.services.mozilla.com/D27366
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoView.java
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/doc-files/CHANGELOG.md
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoView.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoView.java
@@ -27,16 +27,17 @@ import android.os.Handler;
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.support.annotation.AnyThread;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.annotation.UiThread;
 import android.util.AttributeSet;
 import android.util.DisplayMetrics;
+import android.util.Log;
 import android.util.SparseArray;
 import android.util.TypedValue;
 import android.view.KeyEvent;
 import android.view.MotionEvent;
 import android.view.SurfaceHolder;
 import android.view.SurfaceView;
 import android.view.View;
 import android.view.ViewGroup;
@@ -259,16 +260,19 @@ public class GeckoView extends FrameLayo
         }
     }
 
     /**
      * Unsets the current session from this instance and returns it, if any. You must call
      * this before {@link #setSession(GeckoSession)} if there is already an open session
      * set for this instance.
      *
+     * Note: this method does not close the session and the session remains active. The
+     * caller is responsible for calling {@link GeckoSession#close()} when appropriate.
+     *
      * @return The {@link GeckoSession} that was set for this instance. May be null.
      */
     @UiThread
     public @Nullable GeckoSession releaseSession() {
         ThreadUtils.assertOnUiThread();
 
         if (mSession == null) {
             return null;
@@ -422,17 +426,18 @@ public class GeckoView extends FrameLayo
     public @NonNull DynamicToolbarAnimator getDynamicToolbarAnimator() {
         ThreadUtils.assertOnUiThread();
         return mSession.getDynamicToolbarAnimator();
     }
 
     @Override
     public void onAttachedToWindow() {
         if (mSession == null) {
-            setSession(new GeckoSession(), GeckoRuntime.getDefault(getContext()));
+            Log.w(LOGTAG, "No GeckoSession attached to this GeckoView instance. Call setSession to attach a GeckoSession to this instance.");
+            return;
         }
 
         if (!mSession.isOpen()) {
             mSession.open(mRuntime);
         }
         mRuntime.orientationChanged();
 
         super.onAttachedToWindow();
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/doc-files/CHANGELOG.md
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/doc-files/CHANGELOG.md
@@ -55,16 +55,19 @@ exclude: true
 [68.11]: ../ContentBlocking.html#AT_FINGERPRINTING
 
 - Added `HistoryItem` and `HistoryList` interfaces and `onHistoryStateChange` to 
   [`HistoryDelegate`][68.12] and added `gotoHistoryIndex` to [`GeckoSession`][68.13].
 
 [68.12]: ../GeckoSession.HistoryDelegate.html
 [68.13]: ../GeckoSession.html
 
+- [`GeckoView`][65.5] will not create a [`GeckoSession`][65.9] anymore when
+  attached to a window without a session.
+
 ## v67
 - Added [`setAutomaticFontSizeAdjustment`][67.2] to
   [`GeckoRuntimeSettings`][67.3] for automatically adjusting font size settings
   depending on the OS-level font size setting.
 
 [67.2]: ../GeckoRuntimeSettings.html#setAutomaticFontSizeAdjustment-boolean-
 [67.3]: ../GeckoRuntimeSettings.html