Bug 1285572 - Save nsPIDOMWindowOuter in GeckoViewSupport; r=snorp
authorJim Chen <nchen@mozilla.com>
Wed, 20 Jul 2016 21:43:34 -0400
changeset 346007 a2608d51d577c86d8092f8856cc8cd3363b2443f
parent 346006 56b6362b516e71447964b615b7c1fb8f9889f590
child 346008 00a117d3c5fc29fb17bc81e3f8ca9df5563fbd8e
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1285572
milestone50.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 1285572 - Save nsPIDOMWindowOuter in GeckoViewSupport; r=snorp Keep a pointer to nsPIDOMWindowOuter in GeckoViewSupport so that GeckoView native method implementations can access the DOM window. This also lets us simplify GeckoViewSupport::Close by calling nsPIDOMWindowOuter::ForceClose directly.
widget/android/nsWindow.cpp
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -226,16 +226,19 @@ public:
     ~GeckoViewSupport();
 
     using Base::DisposeNative;
     using EditableBase::DisposeNative;
 
     /**
      * GeckoView methods
      */
+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 aGLController,
                      jni::String::Param aChromeURI,
                      int32_t aWidth, int32_t aHeight);
 
@@ -1118,17 +1121,17 @@ nsWindow::GeckoViewSupport::Open(const j
                                  int32_t aWidth, int32_t aHeight)
 {
     MOZ_ASSERT(NS_IsMainThread());
 
     PROFILER_LABEL("nsWindow", "GeckoViewSupport::Open",
                    js::ProfileEntry::Category::OTHER);
 
     nsCOMPtr<nsIWindowWatcher> ww = do_GetService(NS_WINDOWWATCHER_CONTRACTID);
-    MOZ_ASSERT(ww);
+    MOZ_RELEASE_ASSERT(ww);
 
     nsAdoptingCString url;
     if (aChromeURI) {
         url = aChromeURI->ToCString();
     } else {
         url = Preferences::GetCString("toolkit.defaultChromeURI");
         if (!url) {
             url = NS_LITERAL_CSTRING("chrome://browser/content/browser.xul");
@@ -1149,63 +1152,58 @@ nsWindow::GeckoViewSupport::Open(const j
     {
         args->AppendElement(widthArg);
         args->AppendElement(heightArg);
     }
 
     nsCOMPtr<mozIDOMWindowProxy> domWindow;
     ww->OpenWindow(nullptr, url, nullptr, "chrome,dialog=0,resizable",
                    args, getter_AddRefs(domWindow));
-    MOZ_ASSERT(domWindow);
-
-    nsCOMPtr<nsIWidget> widget =
-        WidgetUtils::DOMWindowToWidget(nsPIDOMWindowOuter::From(domWindow));
+    MOZ_RELEASE_ASSERT(domWindow);
+
+    nsCOMPtr<nsPIDOMWindowOuter> pdomWindow =
+            nsPIDOMWindowOuter::From(domWindow);
+    nsCOMPtr<nsIWidget> widget = WidgetUtils::DOMWindowToWidget(pdomWindow);
     MOZ_ASSERT(widget);
 
     const auto window = static_cast<nsWindow*>(widget.get());
 
     // Attach a new GeckoView support object to the new window.
     window->mGeckoViewSupport  = mozilla::MakeUnique<GeckoViewSupport>(
             window, GeckoView::Window::LocalRef(aCls.Env(), aWindow), aView);
 
+    window->mGeckoViewSupport->mDOMWindow = pdomWindow;
+
     // Attach the GLController to the new window.
     window->mGLControllerSupport = mozilla::MakeUnique<GLControllerSupport>(
             window, GLController::LocalRef(
             aCls.Env(), GLController::Ref::From(aGLController)));
 
     gGeckoViewWindow = window;
 
     if (window->mWidgetListener) {
         nsCOMPtr<nsIXULWindow> xulWindow(
                 window->mWidgetListener->GetXULWindow());
         if (xulWindow) {
-            // Out window is not intrinsically sized, so tell nsXULWindow to
+            // Our window is not intrinsically sized, so tell nsXULWindow to
             // not set a size for us.
             xulWindow->SetIntrinsicallySized(false);
         }
     }
 }
 
 void
 nsWindow::GeckoViewSupport::Close()
 {
-    nsIWidgetListener* const widgetListener = window.mWidgetListener;
-
-    if (!widgetListener) {
+    if (!mDOMWindow) {
         return;
     }
 
-    nsCOMPtr<nsIXULWindow> xulWindow(widgetListener->GetXULWindow());
-    // GeckoView-created top-level windows should be a XUL window.
-    MOZ_ASSERT(xulWindow);
-
-    nsCOMPtr<nsIBaseWindow> baseWindow(do_QueryInterface(xulWindow));
-    MOZ_ASSERT(baseWindow);
-
-    baseWindow->Destroy();
+    mDOMWindow->ForceClose();
+    mDOMWindow = nullptr;
 }
 
 void
 nsWindow::GeckoViewSupport::Reattach(GeckoView::Param aView)
 {
     // Associate our previous GeckoEditable with the new GeckoView.
     mEditable->OnViewChange(aView);
 }