Bug 1382862 - Remove GeckoViewFragment; r=droeh
authorJim Chen <nchen@mozilla.com>
Tue, 25 Jul 2017 17:27:03 -0400
changeset 422098 cb3966784befbe11354b79598926681cd4088072
parent 422097 9e9270da4f55d22a25e51a07d411d7216687fb77
child 422099 6e59c41b3584fb692f0237701034cea162d5df8b
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdroeh
bugs1382862
milestone56.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 1382862 - Remove GeckoViewFragment; r=droeh GeckoViewFragment was more of a hack for GeckoApp-based custom tabs, and if we want to provide a fragment implementation for GeckoView, I think it'll look a lot different than today's GeckoViewFragment. So for now, I think it's best to revert the changes that added GeckoViewFragment, and that also simplifies GeckoView lifecycle management. MozReview-Commit-ID: 5WzIZ8TyBDV
mobile/android/app/src/main/res/layout/gecko_app.xml
mobile/android/base/moz.build
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoView.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoViewFragment.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/GeckoLayerClient.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/LayerView.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/NativePanZoomController.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/PanZoomController.java
--- a/mobile/android/app/src/main/res/layout/gecko_app.xml
+++ b/mobile/android/app/src/main/res/layout/gecko_app.xml
@@ -21,21 +21,20 @@
          android:background="@android:color/transparent">
 
         <RelativeLayout android:id="@+id/gecko_layout"
                         android:layout_width="match_parent"
                         android:layout_height="match_parent"
                         android:layout_below="@+id/tablet_tab_strip"
                         android:layout_above="@+id/find_in_page">
 
-            <fragment class="org.mozilla.gecko.GeckoViewFragment"
-                      android:id="@+id/layer_view"
-                      android:layout_width="match_parent"
-                      android:layout_height="match_parent"
-                      android:scrollbars="none"/>
+            <org.mozilla.gecko.GeckoView android:id="@+id/layer_view"
+                                         android:layout_width="match_parent"
+                                         android:layout_height="match_parent"
+                                         android:scrollbars="none"/>
 
             <AbsoluteLayout android:id="@+id/plugin_container"
                             android:background="@android:color/transparent"
                             android:layout_width="match_parent"
                             android:layout_height="match_parent"/>
 
             <org.mozilla.gecko.FormAssistPopup android:id="@+id/form_assist_popup"
                                                android:layout_width="match_parent"
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -378,17 +378,16 @@ gvjar.sources += [geckoview_source_dir +
     'GeckoInputConnection.java',
     'GeckoNetworkManager.java',
     'GeckoProfile.java',
     'GeckoProfileDirectories.java',
     'GeckoScreenOrientation.java',
     'GeckoSharedPrefs.java',
     'GeckoThread.java',
     'GeckoView.java',
-    'GeckoViewFragment.java',
     'GeckoViewHandler.java',
     'GeckoViewSettings.java',
     'gfx/BitmapUtils.java',
     'gfx/BufferedImage.java',
     'gfx/BufferedImageGLInfo.java',
     'gfx/DynamicToolbarAnimator.java',
     'gfx/FloatSize.java',
     'gfx/FullScreenState.java',
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoView.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoView.java
@@ -297,17 +297,16 @@ public class GeckoView extends LayerView
         mPermissionHandler.setListener(delegate, this);
     }
 
     private PromptDelegate mPromptDelegate;
     private InputConnectionListener mInputConnectionListener;
 
     private GeckoViewSettings mSettings;
 
-    protected boolean mOnAttachedToWindowCalled;
     protected String mChromeUri;
     protected int mScreenId = 0; // default to the primary screen
 
     @WrapForJNI(dispatchTo = "proxy")
     protected static final class Window extends JNIObject {
         @WrapForJNI(skip = true)
         public final String chromeUri;
 
@@ -504,20 +503,16 @@ public class GeckoView extends LayerView
     protected void onRestoreInstanceState(final Parcelable state) {
         final StateBinder stateBinder = (StateBinder) state;
 
         if (stateBinder.window != null) {
             mWindow = stateBinder.window;
         }
         mStateSaved = false;
 
-        if (mOnAttachedToWindowCalled) {
-            reattachWindow();
-        }
-
         // We have to always call super.onRestoreInstanceState because View keeps
         // track of these calls and throws an exception when we don't call it.
         super.onRestoreInstanceState(stateBinder.superState);
     }
 
     /**
      * Return the URI of the underlying chrome window opened or to be opened, or null if
      * using the default GeckoView URI.
@@ -582,18 +577,16 @@ public class GeckoView extends LayerView
         if (mWindow == null) {
             // Open a new nsWindow if we didn't have one from before.
             openWindow();
         } else {
             reattachWindow();
         }
 
         super.onAttachedToWindow();
-
-        mOnAttachedToWindowCalled = true;
     }
 
     @Override
     public void onDetachedFromWindow() {
         super.onDetachedFromWindow();
         super.destroy();
 
         if (mStateSaved) {
@@ -605,18 +598,16 @@ public class GeckoView extends LayerView
             mWindow.close();
             mWindow.disposeNative();
         } else {
             GeckoThread.queueNativeCallUntil(GeckoThread.State.PROFILE_READY,
                     mWindow, "close");
             GeckoThread.queueNativeCallUntil(GeckoThread.State.PROFILE_READY,
                     mWindow, "disposeNative");
         }
-
-        mOnAttachedToWindowCalled = false;
     }
 
     @WrapForJNI public static final int LOAD_DEFAULT = 0;
     @WrapForJNI public static final int LOAD_NEW_TAB = 1;
     @WrapForJNI public static final int LOAD_SWITCH_TAB = 2;
 
     /**
     * Load the given URI.
deleted file mode 100644
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoViewFragment.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-package org.mozilla.gecko;
-
-import android.support.v4.app.Fragment;
-import android.os.Bundle;
-import android.os.Parcelable;
-import android.util.Log;
-import android.util.SparseArray;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-
-public class GeckoViewFragment extends android.support.v4.app.Fragment {
-    private static final String LOGTAG = "GeckoViewFragment";
-
-    private static Parcelable mSavedState = null;
-    private static GeckoViewFragment mLastUsed = null;
-    private GeckoView mGeckoView = null;
-
-    @Override
-    public void onCreate(Bundle savedInstanceState) {
-        setRetainInstance(true);
-        super.onCreate(savedInstanceState);
-    }
-
-    @Override
-    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
-        mGeckoView = new GeckoView(getContext());
-        return mGeckoView;
-    }
-
-    @Override
-    public void onResume() {
-        if (mSavedState != null && mLastUsed != this) {
-            // "Restore" the window from the previously used GeckoView to this GeckoView and attach it
-            mGeckoView.onRestoreInstanceState(mSavedState);
-            mSavedState = null;
-        }
-        super.onResume();
-    }
-
-    @Override
-    public void onPause() {
-        mSavedState = mGeckoView.onSaveInstanceState();
-        mLastUsed = this;
-        super.onPause();
-    }
-}
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/GeckoLayerClient.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/GeckoLayerClient.java
@@ -45,19 +45,19 @@ class GeckoLayerClient implements LayerV
      * 3) whenever reading multiple fields from mViewportMetrics without synchronization (i.e. in
      *    case 1 above) you should always first grab a local copy of the reference, and then use
      *    that because mViewportMetrics might get reassigned in between reading the different
      *    fields. */
     private volatile ImmutableViewportMetrics mViewportMetrics;
 
     private volatile boolean mGeckoIsReady;
 
-    /* package */ final PanZoomController mPanZoomController;
+    private final PanZoomController mPanZoomController;
     private final DynamicToolbarAnimator mToolbarAnimator;
-    /* package */ final LayerView mView;
+    private final LayerView mView;
 
     /* This flag is true from the time that browser.js detects a first-paint is about to start,
      * to the time that we receive the first-paint composite notification from the compositor.
      * Note that there is a small race condition with this; if there are two paints that both
      * have the first-paint flag set, and the second paint happens concurrently with the
      * composite for the first paint, then this flag may be set to true prematurely. Fixing this
      * is possible but risky; see https://bugzilla.mozilla.org/show_bug.cgi?id=797615#c751
      */
@@ -106,18 +106,17 @@ class GeckoLayerClient implements LayerV
         // Gecko being ready is one of the two conditions (along with having an available
         // surface) that cause us to create the compositor. So here, now that we know gecko
         // is ready, call updateCompositor() to see if we can actually do the creation.
         // This needs to run on the UI thread so that the surface validity can't change on
         // us while we're in the middle of creating the compositor.
         mView.post(new Runnable() {
             @Override
             public void run() {
-                mPanZoomController.attach();
-                mView.updateCompositor();
+                getView().updateCompositor();
             }
         });
     }
 
     public void destroy() {
         mPanZoomController.destroy();
         mGeckoIsReady = false;
     }
@@ -403,17 +402,17 @@ class GeckoLayerClient implements LayerV
             /*yPrecision*/ 0,
             /*deviceId*/ 0,
             /*edgeFlags*/ 0,
             /*source*/ source,
             /*flags*/ 0);
         mView.post(new Runnable() {
             @Override
             public void run() {
-                mView.dispatchTouchEvent(event);
+                getView().dispatchTouchEvent(event);
             }
         });
 
         // Forget about removed pointers
         if (eventType == MotionEvent.ACTION_POINTER_UP ||
             eventType == MotionEvent.ACTION_UP ||
             eventType == MotionEvent.ACTION_CANCEL ||
             eventType == MotionEvent.ACTION_HOVER_MOVE)
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/LayerView.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/LayerView.java
@@ -21,17 +21,16 @@ import android.content.Context;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.Color;
 import android.graphics.Matrix;
 import android.graphics.Point;
 import android.graphics.PointF;
 import android.graphics.Rect;
 import android.graphics.SurfaceTexture;
-import android.os.Parcelable;
 import android.support.v4.util.SimpleArrayMap;
 import android.util.AttributeSet;
 import android.util.Log;
 import android.view.KeyEvent;
 import android.view.MotionEvent;
 import android.view.SurfaceHolder;
 import android.view.SurfaceView;
 import android.view.TextureView;
@@ -60,17 +59,16 @@ public class LayerView extends FrameLayo
     private Listener mListener;
 
     /* This should only be modified on the Java UI thread. */
     private final Overscroll mOverscroll;
 
     private boolean mServerSurfaceValid;
     private int mWidth, mHeight;
 
-    private boolean onAttachedToWindowCalled;
     private int mDefaultClearColor = Color.WHITE;
     /* package */ GetPixelsResult mGetPixelsResult;
     private final List<DrawListener> mDrawListeners;
 
     /* This is written by the Gecko thread and the UI thread, and read by the UI thread. */
     /* package */ volatile boolean mCompositorCreated;
     /* package */ volatile boolean mCompositorControllerOpen;
 
@@ -416,24 +414,16 @@ public class LayerView extends FrameLayo
         }
         if (mPanZoomController != null && mPanZoomController.onMotionEvent(event)) {
             return true;
         }
         return false;
     }
 
     @Override
-    protected void onRestoreInstanceState(final Parcelable state) {
-        if (onAttachedToWindowCalled) {
-            attachCompositor();
-        }
-        super.onRestoreInstanceState(state);
-    }
-
-    @Override
     protected void onAttachedToWindow() {
         super.onAttachedToWindow();
 
         // We are adding descendants to this LayerView, but we don't want the
         // descendants to affect the way LayerView retains its focus.
         setDescendantFocusability(FOCUS_BLOCK_DESCENDANTS);
 
         // This check should not be done before the view is attached to a window
@@ -459,25 +449,16 @@ public class LayerView extends FrameLayo
             mSurfaceView.setBackgroundColor(Color.WHITE);
             addView(mSurfaceView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
 
             SurfaceHolder holder = mSurfaceView.getHolder();
             holder.addCallback(new SurfaceListener());
         }
 
         attachCompositor();
-
-        onAttachedToWindowCalled = true;
-    }
-
-    @Override
-    protected void onDetachedFromWindow() {
-        super.onDetachedFromWindow();
-
-        onAttachedToWindowCalled = false;
     }
 
     // Don't expose GeckoLayerClient to things outside this package; only expose it as an Object
     GeckoLayerClient getLayerClient() { return mLayerClient; }
 
     /* package */ boolean isGeckoReady() {
         return mLayerClient.isGeckoReady();
     }
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/NativePanZoomController.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/NativePanZoomController.java
@@ -134,17 +134,16 @@ class NativePanZoomController extends JN
         final float y = coords.y;
 
         return handleMouseEvent(event.getActionMasked(), event.getEventTime(), event.getMetaState(), x, y, event.getButtonState());
     }
 
 
     NativePanZoomController(View view) {
         mView = (LayerView) view;
-        mDestroyed = true;
 
         String[] prefs = { "ui.scrolling.negate_wheel_scroll" };
         mPrefsObserver = new PrefsHelper.PrefHandlerBase() {
             @Override public void prefValue(String pref, boolean value) {
                 if (pref.equals("ui.scrolling.negate_wheel_scroll")) {
                     mNegateWheelScroll = value;
                 }
             }
@@ -201,21 +200,16 @@ class NativePanZoomController extends JN
         }
         if (mDestroyed || !mView.isGeckoReady()) {
             return;
         }
         mDestroyed = true;
         disposeNative();
     }
 
-    @Override
-    public void attach() {
-        mDestroyed = false;
-    }
-
     @WrapForJNI(calledFrom = "ui", dispatchTo = "gecko_priority") @Override // JNIObject
     protected native void disposeNative();
 
     @Override
     public void setOverscrollHandler(final Overscroll handler) {
         mOverscroll = handler;
     }
 
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/PanZoomController.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/gfx/PanZoomController.java
@@ -18,17 +18,16 @@ public interface PanZoomController {
 
     static class Factory {
         static PanZoomController create(View view) {
             return new NativePanZoomController(view);
         }
     }
 
     public void destroy();
-    public void attach();
 
     public boolean onTouchEvent(MotionEvent event);
     public boolean onMotionEvent(MotionEvent event);
 
     public void setOverscrollHandler(final Overscroll controller);
 
     public void setIsLongpressEnabled(boolean isLongpressEnabled);
 }