Bug 1514253 - Create PanZoomController immediately in GeckoSession r=geckoview-reviewers,droeh#geckoview-reviewers
authorJames Willcox <snorp@snorp.net>
Thu, 17 Jan 2019 14:17:50 +0000
changeset 511383 821f274155c761e7de874f1b0ca86d6f1492fe47
parent 511382 0a28f41635eb8f186ebbe27fff2a15626162d08d
child 511384 4a74ab74ff7a41cafaaa2829e166652680135c2f
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgeckoview-reviewers, droeh
bugs1514253
milestone66.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 1514253 - Create PanZoomController immediately in GeckoSession r=geckoview-reviewers,droeh#geckoview-reviewers Differential Revision: https://phabricator.services.mozilla.com/D14562
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
widget/android/nsWindow.cpp
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
@@ -102,17 +102,17 @@ public class GeckoSession implements Par
     private SessionFinder mFinder;
 
     private String mId = UUID.randomUUID().toString().replace("-", "");
     /* package */ String getId() { return mId; }
 
     private boolean mShouldPinOnScreen;
 
     // All fields are accessed on UI thread only.
-    private PanZoomController mNPZC;
+    private PanZoomController mPanZoomController = new PanZoomController(this);
     private OverscrollEdgeEffect mOverscroll;
     private DynamicToolbarAnimator mToolbar;
     private CompositorController mController;
 
     private boolean mAttachedCompositor;
     private boolean mCompositorReady;
     private Surface mSurface;
 
@@ -3653,23 +3653,17 @@ public class GeckoSession implements Par
      * Get the PanZoomController instance for this session.
      *
      * @return PanZoomController instance.
      */
     @UiThread
     public @NonNull PanZoomController getPanZoomController() {
         ThreadUtils.assertOnUiThread();
 
-        if (mNPZC == null) {
-            mNPZC = new PanZoomController(this);
-            if (mAttachedCompositor) {
-                mCompositor.attachNPZC(mNPZC);
-            }
-        }
-        return mNPZC;
+        return mPanZoomController;
     }
 
     /**
      * Get the OverscrollEdgeEffect instance for this session.
      *
      * @return OverscrollEdgeEffect instance.
      */
     @UiThread
@@ -4335,20 +4329,17 @@ public class GeckoSession implements Par
     }
 
     /* package */ void onCompositorAttached() {
         if (DEBUG) {
             ThreadUtils.assertOnUiThread();
         }
 
         mAttachedCompositor = true;
-
-        if (mNPZC != null) {
-            mCompositor.attachNPZC(mNPZC);
-        }
+        mCompositor.attachNPZC(mPanZoomController);
 
         if (mSurface != null) {
             // If we have a valid surface, create the compositor now that we're attached.
             // Leave mSurface alone because we'll need it later for onCompositorReady.
             onSurfaceChanged(mSurface, mOffsetX, mOffsetY, mWidth, mHeight);
         }
 
         mCompositor.sendToolbarAnimatorMessage(IS_COMPOSITOR_CONTROLLER_OPEN);
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -885,17 +885,24 @@ class nsWindow::LayerViewSupport final
  public:
   void AttachNPZC(jni::Object::Param aNPZC) {
     MOZ_ASSERT(NS_IsMainThread());
     if (!mWindow) {
       return;  // Already shut down.
     }
 
     MOZ_ASSERT(aNPZC);
-    MOZ_ASSERT(!mWindow->mNPZCSupport);
+
+    // We can have this situation if we get two GeckoViewSupport::Transfer()
+    // called before the first AttachNPZC() gets here. Just detach the current
+    // instance since that's what happens in GeckoViewSupport::Transfer() as
+    // well.
+    if (mWindow->mNPZCSupport) {
+      mWindow->mNPZCSupport.Detach(mWindow->mNPZCSupport->GetJavaNPZC());
+    }
 
     auto npzc = PanZoomController::LocalRef(
         jni::GetGeckoThreadEnv(), PanZoomController::Ref::From(aNPZC));
     mWindow->mNPZCSupport.Attach(npzc, mWindow, npzc);
 
     DispatchToUiThread("LayerViewSupport::AttachNPZC",
                        [npzc = PanZoomController::GlobalRef(npzc)] {
                          npzc->SetAttached(true);