Bug 1413698 - 1. Separate out attach() from open() in GeckoView.Window; r?snorp draft
authorJim Chen <nchen@mozilla.com>
Thu, 02 Nov 2017 13:09:14 -0400
changeset 692159 5ca236a0c23e91e7309c177933849cac7810c378
parent 692089 40a14ca1cf04499f398e4cb8ba359b39eae4e216
child 692160 67d691f30f5538b65f23cc24be89cf17c49d0741
push id87420
push userbmo:nchen@mozilla.com
push dateThu, 02 Nov 2017 17:09:33 +0000
reviewerssnorp
bugs1413698
milestone58.0a1
Bug 1413698 - 1. Separate out attach() from open() in GeckoView.Window; r?snorp Right now, `GeckoView.Window.open()` consists of opening a new Gecko nsWindow and attaching it to the opening GeckoView. This patch separates the attaching step into an `Window.attach()` function that was renamed from `Window.reattach()`. Going forward, `Window.open()` and `Window.close()` will correspond to opening and closing a session, which `Window.attach()` will corrspond to attaching a display to a session. MozReview-Commit-ID: 94Un74pwizY
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoEditable.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoView.java
widget/android/GeneratedJNINatives.h
widget/android/GeneratedJNIWrappers.cpp
widget/android/GeneratedJNIWrappers.h
widget/android/nsWindow.cpp
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoEditable.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoEditable.java
@@ -593,33 +593,31 @@ final class GeckoEditable extends IGecko
                 Log.d(LOGTAG, "sending: " + event);
             }
             onKeyEvent(mFocusedChild, event, event.getAction(),
                        /* metaState */ 0, /* isSynthesizedImeKey */ true);
         }
     }
 
     @WrapForJNI(calledFrom = "gecko")
-    private GeckoEditable(final GeckoView v) {
+    private GeckoEditable() {
         if (DEBUG) {
             // Called by nsWindow.
             ThreadUtils.assertOnGeckoThread();
         }
 
         mText = new AsyncText();
         mActions = new ConcurrentLinkedQueue<Action>();
 
         final Class<?>[] PROXY_INTERFACES = { Editable.class };
         mProxy = (Editable)Proxy.newProxyInstance(
                 Editable.class.getClassLoader(),
                 PROXY_INTERFACES, this);
 
         mIcRunHandler = mIcPostHandler = ThreadUtils.getUiHandler();
-
-        onViewChange(v);
     }
 
     @WrapForJNI(calledFrom = "gecko")
     private void setDefaultEditableChild(final IGeckoEditableChild child) {
         mDefaultChild = child;
     }
 
     @WrapForJNI(calledFrom = "gecko")
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoView.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoView.java
@@ -70,17 +70,17 @@ public class GeckoView extends LayerView
 
         @Override
         public boolean isAtLeast(final NativeQueue.State other) {
             return (other instanceof State) &&
                    mRank >= ((State) other).mRank;
         }
     }
 
-    private final NativeQueue mNativeQueue =
+    /* package */ final NativeQueue mNativeQueue =
         new NativeQueue(State.INITIAL, State.READY);
 
     private final EventDispatcher mEventDispatcher =
         new EventDispatcher(mNativeQueue);
 
     private final GeckoViewHandler<ContentListener> mContentHandler =
         new GeckoViewHandler<ContentListener>(
             "GeckoViewContent", this,
@@ -305,52 +305,51 @@ public class GeckoView extends LayerView
     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;
 
         @WrapForJNI(skip = true)
-        /* package */ NativeQueue mNativeQueue;
+        private NativeQueue mNativeQueue;
 
         @WrapForJNI(skip = true)
-        /* package */ Window(final String chromeUri, final NativeQueue queue) {
+        /* package */ Window(final String chromeUri) {
             this.chromeUri = chromeUri;
-            mNativeQueue = queue;
         }
 
-        static native void open(Window instance, GeckoView view,
-                                Object compositor, EventDispatcher dispatcher,
-                                String chromeUri, GeckoBundle settings,
+        static native void open(Window instance, EventDispatcher dispatcher,
+                                GeckoBundle settings, String chromeUri,
                                 int screenId, boolean privateMode);
 
         @Override protected native void disposeNative();
 
         native void close();
 
-        native void reattach(GeckoView view, Object compositor,
-                             EventDispatcher dispatcher);
+        native void attach(GeckoView view, Object compositor,
+                           EventDispatcher dispatcher);
 
         @WrapForJNI(calledFrom = "gecko")
         private synchronized void setState(final State newState) {
             if (mNativeQueue.getState() != State.READY &&
                 newState == State.READY) {
                 Log.i(LOGTAG, "zerdatime " + SystemClock.elapsedRealtime() +
                       " - chrome startup finished");
             }
             mNativeQueue.setState(newState);
         }
 
         @WrapForJNI(calledFrom = "gecko")
-        private synchronized void onReattach(final GeckoView view) {
+        private synchronized void onAttach(final GeckoView view) {
             if (view.mNativeQueue == mNativeQueue) {
                 return;
+            } else if (mNativeQueue != null) {
+                view.mNativeQueue.setState(mNativeQueue.getState());
             }
-            view.mNativeQueue.setState(mNativeQueue.getState());
             mNativeQueue = view.mNativeQueue;
         }
     }
 
     // Object to hold onto our nsWindow connection when GeckoView gets destroyed.
     private static class StateBinder extends Binder implements Parcelable {
         public final Parcelable superState;
         public final Window window;
@@ -536,56 +535,55 @@ public class GeckoView extends LayerView
     public void setChromeUri(final String uri) {
         if (mWindow != null) {
             throw new IllegalStateException("Already opened chrome window");
         }
         mChromeUri = uri;
     }
 
     protected void openWindow() {
-        mWindow = new Window(mChromeUri, mNativeQueue);
+        mWindow = new Window(mChromeUri);
 
         if (GeckoThread.isStateAtLeast(GeckoThread.State.PROFILE_READY)) {
-            Window.open(mWindow, this, getCompositor(), mEventDispatcher,
-                        mChromeUri, mSettings.asBundle(), mScreenId,
+            Window.open(mWindow, mEventDispatcher, mSettings.asBundle(),
+                        mChromeUri, mScreenId,
                         mSettings.getBoolean(GeckoViewSettings.USE_PRIVATE_MODE));
         } else {
             GeckoThread.queueNativeCallUntil(
                 GeckoThread.State.PROFILE_READY,
-                Window.class, "open", mWindow,
-                GeckoView.class, this,
-                Object.class, getCompositor(),
+                Window.class, "open",
+                Window.class, mWindow,
                 EventDispatcher.class, mEventDispatcher,
+                GeckoBundle.class, mSettings.asBundle(),
                 String.class, mChromeUri,
-                GeckoBundle.class, mSettings.asBundle(),
                 mScreenId, mSettings.getBoolean(GeckoViewSettings.USE_PRIVATE_MODE));
         }
     }
 
-    protected void reattachWindow() {
+    protected void attachView() {
         if (GeckoThread.isStateAtLeast(GeckoThread.State.PROFILE_READY)) {
-            mWindow.reattach(this, getCompositor(), mEventDispatcher);
+            mWindow.attach(this, getCompositor(), mEventDispatcher);
         } else {
             GeckoThread.queueNativeCallUntil(GeckoThread.State.PROFILE_READY,
-                    mWindow, "reattach", GeckoView.class, this,
+                    mWindow, "attach", GeckoView.class, this,
                     Object.class, getCompositor(), EventDispatcher.class, mEventDispatcher);
         }
     }
 
     @Override
     public void onAttachedToWindow() {
         final DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
 
         if (mWindow == null) {
             // Open a new nsWindow if we didn't have one from before.
             openWindow();
-        } else {
-            reattachWindow();
         }
 
+        attachView();
+
         super.onAttachedToWindow();
     }
 
     @Override
     public void onDetachedFromWindow() {
         super.onDetachedFromWindow();
         super.destroy();
 
--- a/widget/android/GeneratedJNINatives.h
+++ b/widget/android/GeneratedJNINatives.h
@@ -262,31 +262,31 @@ class GeckoView::Window::Natives : publi
 {
 public:
     static const JNINativeMethod methods[4];
 };
 
 template<class Impl>
 const JNINativeMethod GeckoView::Window::Natives<Impl>::methods[] = {
 
+    mozilla::jni::MakeNativeMethod<GeckoView::Window::Attach_t>(
+            mozilla::jni::NativeStub<GeckoView::Window::Attach_t, Impl>
+            ::template Wrap<&Impl::Attach>),
+
     mozilla::jni::MakeNativeMethod<GeckoView::Window::Close_t>(
             mozilla::jni::NativeStub<GeckoView::Window::Close_t, Impl>
             ::template Wrap<&Impl::Close>),
 
     mozilla::jni::MakeNativeMethod<GeckoView::Window::DisposeNative_t>(
             mozilla::jni::NativeStub<GeckoView::Window::DisposeNative_t, Impl>
             ::template Wrap<&Impl::DisposeNative>),
 
     mozilla::jni::MakeNativeMethod<GeckoView::Window::Open_t>(
             mozilla::jni::NativeStub<GeckoView::Window::Open_t, Impl>
-            ::template Wrap<&Impl::Open>),
-
-    mozilla::jni::MakeNativeMethod<GeckoView::Window::Reattach_t>(
-            mozilla::jni::NativeStub<GeckoView::Window::Reattach_t, Impl>
-            ::template Wrap<&Impl::Reattach>)
+            ::template Wrap<&Impl::Open>)
 };
 
 template<class Impl>
 class PrefsHelper::Natives : public mozilla::jni::NativeImpl<PrefsHelper, Impl>
 {
 public:
     static const JNINativeMethod methods[4];
 };
--- a/widget/android/GeneratedJNIWrappers.cpp
+++ b/widget/android/GeneratedJNIWrappers.cpp
@@ -645,19 +645,19 @@ constexpr char GeckoBatteryManager::OnBa
 constexpr char GeckoBatteryManager::OnBatteryChange_t::signature[];
 
 const char GeckoEditable::name[] =
         "org/mozilla/gecko/GeckoEditable";
 
 constexpr char GeckoEditable::New_t::name[];
 constexpr char GeckoEditable::New_t::signature[];
 
-auto GeckoEditable::New(mozilla::jni::Object::Param a0) -> GeckoEditable::LocalRef
+auto GeckoEditable::New() -> GeckoEditable::LocalRef
 {
-    return mozilla::jni::Constructor<New_t>::Call(GeckoEditable::Context(), nullptr, a0);
+    return mozilla::jni::Constructor<New_t>::Call(GeckoEditable::Context(), nullptr);
 }
 
 constexpr char GeckoEditable::OnViewChange_t::name[];
 constexpr char GeckoEditable::OnViewChange_t::signature[];
 
 auto GeckoEditable::OnViewChange(mozilla::jni::Object::Param a0) const -> void
 {
     return mozilla::jni::Method<OnViewChange_t>::Call(GeckoEditable::mCtx, nullptr, a0);
@@ -970,36 +970,36 @@ constexpr char GeckoView::State::READY_t
 auto GeckoView::State::READY() -> State::LocalRef
 {
     return mozilla::jni::Field<READY_t>::Get(State::Context(), nullptr);
 }
 
 const char GeckoView::Window::name[] =
         "org/mozilla/gecko/GeckoView$Window";
 
+constexpr char GeckoView::Window::Attach_t::name[];
+constexpr char GeckoView::Window::Attach_t::signature[];
+
 constexpr char GeckoView::Window::Close_t::name[];
 constexpr char GeckoView::Window::Close_t::signature[];
 
 constexpr char GeckoView::Window::DisposeNative_t::name[];
 constexpr char GeckoView::Window::DisposeNative_t::signature[];
 
-constexpr char GeckoView::Window::OnReattach_t::name[];
-constexpr char GeckoView::Window::OnReattach_t::signature[];
-
-auto GeckoView::Window::OnReattach(GeckoView::Param a0) const -> void
+constexpr char GeckoView::Window::OnAttach_t::name[];
+constexpr char GeckoView::Window::OnAttach_t::signature[];
+
+auto GeckoView::Window::OnAttach(GeckoView::Param a0) const -> void
 {
-    return mozilla::jni::Method<OnReattach_t>::Call(Window::mCtx, nullptr, a0);
+    return mozilla::jni::Method<OnAttach_t>::Call(Window::mCtx, nullptr, a0);
 }
 
 constexpr char GeckoView::Window::Open_t::name[];
 constexpr char GeckoView::Window::Open_t::signature[];
 
-constexpr char GeckoView::Window::Reattach_t::name[];
-constexpr char GeckoView::Window::Reattach_t::signature[];
-
 constexpr char GeckoView::Window::SetState_t::name[];
 constexpr char GeckoView::Window::SetState_t::signature[];
 
 auto GeckoView::Window::SetState(mozilla::jni::Object::Param a0) const -> void
 {
     return mozilla::jni::Method<SetState_t>::Call(Window::mCtx, nullptr, a0);
 }
 
--- a/widget/android/GeneratedJNIWrappers.h
+++ b/widget/android/GeneratedJNIWrappers.h
@@ -1841,31 +1841,30 @@ public:
     static const char name[];
 
     explicit GeckoEditable(const Context& ctx) : ObjectBase<GeckoEditable>(ctx) {}
 
     struct New_t {
         typedef GeckoEditable Owner;
         typedef GeckoEditable::LocalRef ReturnType;
         typedef GeckoEditable::Param SetterType;
-        typedef mozilla::jni::Args<
-                mozilla::jni::Object::Param> Args;
+        typedef mozilla::jni::Args<> Args;
         static constexpr char name[] = "<init>";
         static constexpr char signature[] =
-                "(Lorg/mozilla/gecko/GeckoView;)V";
+                "()V";
         static const bool isStatic = false;
         static const mozilla::jni::ExceptionMode exceptionMode =
                 mozilla::jni::ExceptionMode::ABORT;
         static const mozilla::jni::CallingThread callingThread =
                 mozilla::jni::CallingThread::GECKO;
         static const mozilla::jni::DispatchTarget dispatchTarget =
                 mozilla::jni::DispatchTarget::CURRENT;
     };
 
-    static auto New(mozilla::jni::Object::Param) -> GeckoEditable::LocalRef;
+    static auto New() -> GeckoEditable::LocalRef;
 
     struct OnViewChange_t {
         typedef GeckoEditable Owner;
         typedef void ReturnType;
         typedef void SetterType;
         typedef mozilla::jni::Args<
                 mozilla::jni::Object::Param> Args;
         static constexpr char name[] = "onViewChange";
@@ -2895,16 +2894,36 @@ public:
 
 class GeckoView::Window : public mozilla::jni::ObjectBase<Window>
 {
 public:
     static const char name[];
 
     explicit Window(const Context& ctx) : ObjectBase<Window>(ctx) {}
 
+    struct Attach_t {
+        typedef Window Owner;
+        typedef void ReturnType;
+        typedef void SetterType;
+        typedef mozilla::jni::Args<
+                GeckoView::Param,
+                mozilla::jni::Object::Param,
+                mozilla::jni::Object::Param> Args;
+        static constexpr char name[] = "attach";
+        static constexpr char signature[] =
+                "(Lorg/mozilla/gecko/GeckoView;Ljava/lang/Object;Lorg/mozilla/gecko/EventDispatcher;)V";
+        static const bool isStatic = false;
+        static const mozilla::jni::ExceptionMode exceptionMode =
+                mozilla::jni::ExceptionMode::ABORT;
+        static const mozilla::jni::CallingThread callingThread =
+                mozilla::jni::CallingThread::ANY;
+        static const mozilla::jni::DispatchTarget dispatchTarget =
+                mozilla::jni::DispatchTarget::PROXY;
+    };
+
     struct Close_t {
         typedef Window Owner;
         typedef void ReturnType;
         typedef void SetterType;
         typedef mozilla::jni::Args<> Args;
         static constexpr char name[] = "close";
         static constexpr char signature[] =
                 "()V";
@@ -2929,73 +2948,51 @@ public:
         static const mozilla::jni::ExceptionMode exceptionMode =
                 mozilla::jni::ExceptionMode::ABORT;
         static const mozilla::jni::CallingThread callingThread =
                 mozilla::jni::CallingThread::ANY;
         static const mozilla::jni::DispatchTarget dispatchTarget =
                 mozilla::jni::DispatchTarget::PROXY;
     };
 
-    struct OnReattach_t {
+    struct OnAttach_t {
         typedef Window Owner;
         typedef void ReturnType;
         typedef void SetterType;
         typedef mozilla::jni::Args<
                 GeckoView::Param> Args;
-        static constexpr char name[] = "onReattach";
+        static constexpr char name[] = "onAttach";
         static constexpr char signature[] =
                 "(Lorg/mozilla/gecko/GeckoView;)V";
         static const bool isStatic = false;
         static const mozilla::jni::ExceptionMode exceptionMode =
                 mozilla::jni::ExceptionMode::ABORT;
         static const mozilla::jni::CallingThread callingThread =
                 mozilla::jni::CallingThread::GECKO;
         static const mozilla::jni::DispatchTarget dispatchTarget =
                 mozilla::jni::DispatchTarget::CURRENT;
     };
 
-    auto OnReattach(GeckoView::Param) const -> void;
+    auto OnAttach(GeckoView::Param) const -> void;
 
     struct Open_t {
         typedef Window Owner;
         typedef void ReturnType;
         typedef void SetterType;
         typedef mozilla::jni::Args<
                 Window::Param,
-                GeckoView::Param,
                 mozilla::jni::Object::Param,
                 mozilla::jni::Object::Param,
                 mozilla::jni::String::Param,
-                mozilla::jni::Object::Param,
                 int32_t,
                 bool> Args;
         static constexpr char name[] = "open";
         static constexpr char signature[] =
-                "(Lorg/mozilla/gecko/GeckoView$Window;Lorg/mozilla/gecko/GeckoView;Ljava/lang/Object;Lorg/mozilla/gecko/EventDispatcher;Ljava/lang/String;Lorg/mozilla/gecko/util/GeckoBundle;IZ)V";
-        static const bool isStatic = true;
-        static const mozilla::jni::ExceptionMode exceptionMode =
-                mozilla::jni::ExceptionMode::ABORT;
-        static const mozilla::jni::CallingThread callingThread =
-                mozilla::jni::CallingThread::ANY;
-        static const mozilla::jni::DispatchTarget dispatchTarget =
-                mozilla::jni::DispatchTarget::PROXY;
-    };
-
-    struct Reattach_t {
-        typedef Window Owner;
-        typedef void ReturnType;
-        typedef void SetterType;
-        typedef mozilla::jni::Args<
-                GeckoView::Param,
-                mozilla::jni::Object::Param,
-                mozilla::jni::Object::Param> Args;
-        static constexpr char name[] = "reattach";
-        static constexpr char signature[] =
-                "(Lorg/mozilla/gecko/GeckoView;Ljava/lang/Object;Lorg/mozilla/gecko/EventDispatcher;)V";
-        static const bool isStatic = false;
+                "(Lorg/mozilla/gecko/GeckoView$Window;Lorg/mozilla/gecko/EventDispatcher;Lorg/mozilla/gecko/util/GeckoBundle;Ljava/lang/String;IZ)V";
+        static const bool isStatic = true;
         static const mozilla::jni::ExceptionMode exceptionMode =
                 mozilla::jni::ExceptionMode::ABORT;
         static const mozilla::jni::CallingThread callingThread =
                 mozilla::jni::CallingThread::ANY;
         static const mozilla::jni::DispatchTarget dispatchTarget =
                 mozilla::jni::DispatchTarget::PROXY;
     };
 
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -274,30 +274,29 @@ public:
      */
 private:
     nsCOMPtr<nsPIDOMWindowOuter> mDOMWindow;
 
 public:
     // Create and attach a window.
     static void Open(const jni::Class::LocalRef& aCls,
                      GeckoView::Window::Param aWindow,
-                     GeckoView::Param aView, jni::Object::Param aCompositor,
                      jni::Object::Param aDispatcher,
+                     jni::Object::Param aSettings,
                      jni::String::Param aChromeURI,
-                     jni::Object::Param aSettings,
                      int32_t aScreenId,
                      bool aPrivateMode);
 
     // Close and destroy the nsWindow.
     void Close();
 
     // Reattach this nsWindow to a new GeckoView.
-    void Reattach(const GeckoView::Window::LocalRef& inst,
-                  GeckoView::Param aView, jni::Object::Param aCompositor,
-                  jni::Object::Param aDispatcher);
+    void Attach(const GeckoView::Window::LocalRef& inst,
+                GeckoView::Param aView, jni::Object::Param aCompositor,
+                jni::Object::Param aDispatcher);
 
     void EnableEventDispatcher();
 };
 
 /**
  * NativePanZoomController handles its native calls on the UI thread, so make
  * it separate from GeckoViewSupport.
  */
@@ -1258,21 +1257,19 @@ nsWindow::GeckoViewSupport::~GeckoViewSu
     if (window.mLayerViewSupport) {
         window.mLayerViewSupport.Detach();
     }
 }
 
 /* static */ void
 nsWindow::GeckoViewSupport::Open(const jni::Class::LocalRef& aCls,
                                  GeckoView::Window::Param aWindow,
-                                 GeckoView::Param aView,
-                                 jni::Object::Param aCompositor,
                                  jni::Object::Param aDispatcher,
+                                 jni::Object::Param aSettings,
                                  jni::String::Param aChromeURI,
-                                 jni::Object::Param aSettings,
                                  int32_t aScreenId,
                                  bool aPrivateMode)
 {
     MOZ_ASSERT(NS_IsMainThread());
 
     AUTO_PROFILER_LABEL("nsWindow::GeckoViewSupport::Open", OTHER);
 
     nsCOMPtr<nsIWindowWatcher> ww = do_GetService(NS_WINDOWWATCHER_CONTRACTID);
@@ -1314,27 +1311,22 @@ nsWindow::GeckoViewSupport::Open(const j
 
     // Attach a new GeckoView support object to the new window.
     window->mGeckoViewSupport = mozilla::MakeUnique<GeckoViewSupport>(
         window, (GeckoView::Window::LocalRef(aCls.Env(), aWindow)));
 
     window->mGeckoViewSupport->mDOMWindow = pdomWindow;
 
     // Attach a new GeckoEditable support object to the new window.
-    auto editable = GeckoEditable::New(aView);
+    auto editable = GeckoEditable::New();
     auto editableChild = GeckoEditableChild::New(editable);
     editable->SetDefaultEditableChild(editableChild);
     window->mEditable = editable;
     window->mEditableSupport.Attach(editableChild, window, editableChild);
 
-    // Attach the Compositor to the new window.
-    auto compositor = LayerView::Compositor::LocalRef(
-            aCls.Env(), LayerView::Compositor::Ref::From(aCompositor));
-    window->mLayerViewSupport.Attach(compositor, window, compositor);
-
     // Attach again using the new window.
     androidView->mEventDispatcher->Attach(
             java::EventDispatcher::Ref::From(aDispatcher), pdomWindow);
     window->mAndroidView = androidView;
 
     if (window->mWidgetListener) {
         nsCOMPtr<nsIXULWindow> xulWindow(
                 window->mWidgetListener->GetXULWindow());
@@ -1358,44 +1350,45 @@ nsWindow::GeckoViewSupport::Close()
     }
 
     mDOMWindow->ForceClose();
     mDOMWindow = nullptr;
     mGeckoViewWindow = nullptr;
 }
 
 void
-nsWindow::GeckoViewSupport::Reattach(const GeckoView::Window::LocalRef& inst,
-                                     GeckoView::Param aView,
-                                     jni::Object::Param aCompositor,
-                                     jni::Object::Param aDispatcher)
+nsWindow::GeckoViewSupport::Attach(const GeckoView::Window::LocalRef& inst,
+                                   GeckoView::Param aView,
+                                   jni::Object::Param aCompositor,
+                                   jni::Object::Param aDispatcher)
 {
     // Associate our previous GeckoEditable with the new GeckoView.
     MOZ_ASSERT(window.mEditable);
     window.mEditable->OnViewChange(aView);
 
     // mNPZCSupport might have already been detached through the Java side calling
     // NativePanZoomController.destroy().
     if (window.mNPZCSupport) {
         window.mNPZCSupport.Detach();
     }
 
-    MOZ_ASSERT(window.mLayerViewSupport);
-    window.mLayerViewSupport.Detach();
+    if (window.mLayerViewSupport) {
+        window.mLayerViewSupport.Detach();
+    }
 
     auto compositor = LayerView::Compositor::LocalRef(
             inst.Env(), LayerView::Compositor::Ref::From(aCompositor));
     window.mLayerViewSupport.Attach(compositor, &window, compositor);
     compositor->Reattach();
 
     MOZ_ASSERT(window.mAndroidView);
     window.mAndroidView->mEventDispatcher->Attach(
             java::EventDispatcher::Ref::From(aDispatcher), mDOMWindow);
 
-    mGeckoViewWindow->OnReattach(aView);
+    mGeckoViewWindow->OnAttach(aView);
 }
 
 void
 nsWindow::InitNatives()
 {
     nsWindow::GeckoViewSupport::Base::Init();
     nsWindow::LayerViewSupport::Init();
     nsWindow::NPZCSupport::Init();