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 469529 82ec6a86a2bc
parent 469528 f057b78337e7
child 469530 c860fa255272
push id35873
push userccoroiu@mozilla.com
push dateMon, 15 Apr 2019 21:36:26 +0000
treeherdermozilla-central@b8f49a14c458 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgeckoview-reviewers, esawin, snorp
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
--- 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.
     public @Nullable GeckoSession releaseSession() {
         if (mSession == null) {
             return null;
@@ -422,17 +426,18 @@ public class GeckoView extends FrameLayo
     public @NonNull DynamicToolbarAnimator getDynamicToolbarAnimator() {
         return mSession.getDynamicToolbarAnimator();
     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()) {
--- 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