Bug 485579. Fix possible crash when closing tabs using cairo-qt. r=vlad, a=beltzner
authorTobias Hunger <tobias.hunger@gmail.com>
Fri, 27 Mar 2009 12:35:27 +0100
changeset 28944 fdecaf027ede916b818d6f11bcf38845f14f841b
parent 28943 7c80b01e757b9e308bdfa782b321501083c2df8a
child 28945 040cb204cd926d17b8be1062f48ac8665144cd96
push id7343
push userbzbarsky@mozilla.com
push dateFri, 05 Jun 2009 01:01:30 +0000
treeherderautoland@040cb204cd92 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvlad, beltzner
bugs485579
milestone1.9.2a1pre
Bug 485579. Fix possible crash when closing tabs using cairo-qt. r=vlad, a=beltzner
widget/src/qt/mozqwidget.cpp
widget/src/qt/mozqwidget.h
widget/src/qt/nsWindow.cpp
widget/src/qt/nsWindow.h
--- a/widget/src/qt/mozqwidget.cpp
+++ b/widget/src/qt/mozqwidget.cpp
@@ -5,16 +5,22 @@
 MozQWidget::MozQWidget(nsWindow *receiver, QWidget *parent,
                        const char *name, int f)
     : QWidget(parent, (Qt::WindowFlags)f),
       mReceiver(receiver)
 {
     setAttribute(Qt::WA_QuitOnClose, false);
 }
 
+MozQWidget::~MozQWidget()
+{
+    if (mReceiver)
+        mReceiver->QWidgetDestroyed();
+}
+
 bool MozQWidget::event(QEvent *e)
 {
     nsEventStatus status = nsEventStatus_eIgnore;
     bool handled = true;
 
     // always handle (delayed) delete requests triggered by
     // calling deleteLater() on this widget:
     if (e->type() == QEvent::DeferredDelete)
--- a/widget/src/qt/mozqwidget.h
+++ b/widget/src/qt/mozqwidget.h
@@ -9,16 +9,18 @@ class nsWindow;
 
 class MozQWidget : public QWidget
 {
     Q_OBJECT
 public:
     MozQWidget(nsWindow* receiver, QWidget *parent,
                const char *name, int f);
 
+    ~MozQWidget();
+
     /**
      * Mozilla helper.
      */
     void setModal(bool);
     bool SetCursor(nsCursor aCursor);
     void dropReceiver() { mReceiver = 0x0; };
     nsWindow* getReceiver() { return mReceiver; };
 
--- a/widget/src/qt/nsWindow.cpp
+++ b/widget/src/qt/nsWindow.cpp
@@ -104,16 +104,18 @@
 #include <qobject.h>
 #include <execinfo.h>
 #include <stdlib.h>
 
 #ifdef Q_WS_X11
 #include "qx11info_x11.h"
 #endif
 
+#include <QtCore/QDebug>
+
 #include <execinfo.h>
 
 #include "mozqwidget.h"
 
 /* For PrepareNativeWidget */
 static NS_DEFINE_IID(kDeviceContextCID, NS_DEVICE_CONTEXT_CID);
 
 // initialization static functions 
@@ -311,16 +313,17 @@ nsWindow::Destroy(void)
         mMozQWidget->dropReceiver();
 
         // Call deleteLater instead of delete; Qt still needs the object
         // to be valid even after sending it a Close event.  We could
         // also set WA_DeleteOnClose, but this gives us more control.
         mMozQWidget->deleteLater();
     }
 
+    mMozQWidget = nsnull;
     mDrawingArea = nsnull;
 
     OnDestroy();
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -1963,16 +1966,22 @@ nsWindow::ConvertBorderStyles(nsBorderSt
 #ifdef DEBUG
         printf("we don't handle eBorderStyle_close yet... please fix me\n");
 #endif
     }
 */
     return w;
 }
 
+void nsWindow::QWidgetDestroyed()
+{
+    mDrawingArea = nsnull;
+    mMozQWidget = nsnull;
+}
+
 NS_IMETHODIMP
 nsWindow::MakeFullScreen(PRBool aFullScreen)
 {
 /*
 #if GTK_CHECK_VERSION(2,2,0)
     if (aFullScreen)
         gdk_window_fullscreen (mDrawingArea->window);
     else
--- a/widget/src/qt/nsWindow.h
+++ b/widget/src/qt/nsWindow.h
@@ -203,16 +203,18 @@ public:
 
     //
     // utility methods
     //
 
     void               LoseFocus();
     qint32             ConvertBorderStyles(nsBorderStyle aStyle);
 
+    void               QWidgetDestroyed();
+
 
     /***** from CommonWidget *****/
 
     // event handling code
 
     void DispatchGotFocusEvent(void);
     void DispatchLostFocusEvent(void);
     void DispatchActivateEvent(void);