Bug 554911 - mozilla-runtime process hang and not closed properly after closing fennec UI. r=dougt
authorOleg Romashin <romaxa@gmail.com>
Tue, 30 Mar 2010 07:34:37 -0400
changeset 40008 2126aeac778bcd28e1f0d626abe33c40ca97ef49
parent 40007 3bbb3c3d3fa836fbf7464d7d601eaace49993107
child 40010 9d555c7ef1a444b8b4653a574f98f108d12a7f7a
push idunknown
push userunknown
push dateunknown
reviewersdougt
bugs554911
milestone1.9.3a4pre
Bug 554911 - mozilla-runtime process hang and not closed properly after closing fennec UI. r=dougt
dom/plugins/PluginModuleChild.cpp
toolkit/xre/Makefile.in
toolkit/xre/nsQAppInstance.cpp
toolkit/xre/nsQAppInstance.h
--- a/dom/plugins/PluginModuleChild.cpp
+++ b/dom/plugins/PluginModuleChild.cpp
@@ -33,17 +33,17 @@
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifdef MOZ_WIDGET_QT
-#include <QApplication>
+#include "nsQAppInstance.h"
 #endif
 
 #include "mozilla/plugins/PluginModuleChild.h"
 
 #ifdef MOZ_WIDGET_GTK2
 #include <gtk/gtk.h>
 #endif
 
@@ -63,19 +63,16 @@
 #include "PluginIdentifierChild.h"
 
 #include "nsNPAPIPlugin.h"
 
 using namespace mozilla::plugins;
 
 namespace {
 PluginModuleChild* gInstance = nsnull;
-#ifdef MOZ_WIDGET_QT
-static QApplication *gQApp = nsnull;
-#endif
 }
 
 
 PluginModuleChild::PluginModuleChild() :
     mLibrary(0),
     mShutdownFunc(0),
     mInitializeFunc(0)
 #if defined(OS_WIN) || defined(OS_MACOSX)
@@ -92,19 +89,17 @@ PluginModuleChild::PluginModuleChild() :
 
 PluginModuleChild::~PluginModuleChild()
 {
     NS_ASSERTION(gInstance == this, "Something terribly wrong here!");
     if (mLibrary) {
         PR_UnloadLibrary(mLibrary);
     }
 #ifdef MOZ_WIDGET_QT
-    if (gQApp)
-        delete gQApp;
-    gQApp = nsnull;
+    nsQAppInstance::Release();
 #endif
     gInstance = nsnull;
 }
 
 // static
 PluginModuleChild*
 PluginModuleChild::current()
 {
@@ -455,18 +450,17 @@ PluginModuleChild::InitGraphics()
 
     if (gtk_check_version(2,18,7) != NULL) { // older
         GtkPlugEmbeddedFn* embedded = &GTK_PLUG_CLASS(gtk_plug_class)->embedded;
         real_gtk_plug_embedded = *embedded;
         *embedded = wrap_gtk_plug_embedded;
     }
 
 #elif defined(MOZ_WIDGET_QT)
-    if (!qApp)
-        gQApp = new QApplication(0, NULL);
+    nsQAppInstance::AddRef();
 #else
     // may not be necessary on all platforms
 #endif
 #ifdef MOZ_X11
     // Do this after initializing GDK, or GDK will install its own handler.
     XRE_InstallX11ErrorHandler();
 #endif
 
--- a/toolkit/xre/Makefile.in
+++ b/toolkit/xre/Makefile.in
@@ -103,16 +103,18 @@ else
 ifeq ($(MOZ_WIDGET_TOOLKIT),beos)
 CPPSRCS += nsNativeAppSupportBeOS.cpp
 else
 ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
 CPPSRCS += nsNativeAppSupportUnix.cpp
 else
 ifeq ($(MOZ_WIDGET_TOOLKIT),qt)
 CPPSRCS += nsNativeAppSupportQt.cpp
+CPPSRCS += nsQAppInstance.cpp
+EXPORTS += nsQAppInstance.h
 else
 CPPSRCS += nsNativeAppSupportDefault.cpp
 endif
 endif
 endif
 endif
 endif
 endif
new file mode 100644
--- /dev/null
+++ b/toolkit/xre/nsQAppInstance.cpp
@@ -0,0 +1,66 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 et sw=2 tw=80: */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Corporation code.
+ *
+ * The Initial Developer of the Original Code is Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Oleg Romashin <romaxa@gmail.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#include "nsQAppInstance.h"
+#include <QApplication>
+
+// declared in nsAppRunner.cpp
+extern int    gArgc;
+extern char **gArgv;
+
+nsQAppInstance *nsQAppInstance::sQAppInstance = NULL;
+int nsQAppInstance::sQAppRefCount = 0;
+
+nsQAppInstance::nsQAppInstance(int gArgc, char** gArgv)
+  : QApplication(gArgc, gArgv)
+{
+}
+
+void nsQAppInstance::AddRef(void) {
+  if (qApp) return;
+  if (!sQAppInstance)
+    sQAppInstance = new nsQAppInstance(gArgc, gArgv);
+  sQAppRefCount++;
+}
+
+void nsQAppInstance::Release(void) {
+  if (sQAppInstance && !--sQAppRefCount) {
+    delete sQAppInstance;
+    sQAppInstance = NULL;
+  }
+}
new file mode 100644
--- /dev/null
+++ b/toolkit/xre/nsQAppInstance.h
@@ -0,0 +1,56 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 et sw=2 tw=80: */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Corporation code.
+ *
+ * The Initial Developer of the Original Code is Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Oleg Romashin <romaxa@gmail.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef nsQAppInstance_h
+#define nsQAppInstance_h
+
+#include <QApplication>
+
+class nsQAppInstance : public QApplication
+{
+public:
+  static void AddRef(void);
+  static void Release(void);
+
+private:
+  nsQAppInstance(int gArgc, char** gArgv);
+  static nsQAppInstance *sQAppInstance;
+  static int sQAppRefCount;
+};
+
+#endif /* nsQAppInstance_h */