From b371b618cb55ed225b23222a94818d12308ff3a6 Mon Sep 17 00:00:00 2001 From: Oleg Romashin Date: Tue, 30 Mar 2010 07:34:37 -0400 Subject: [PATCH] Bug 554911 - mozilla-runtime process hang and not closed properly after closing fennec UI. r=dougt --HG-- extra : rebase_source : 5490b2acfe1980e372b7918cf36e8e771b2a0747 --- dom/plugins/PluginModuleChild.cpp | 12 ++---- toolkit/xre/Makefile.in | 2 + toolkit/xre/nsQAppInstance.cpp | 66 +++++++++++++++++++++++++++++++ toolkit/xre/nsQAppInstance.h | 56 ++++++++++++++++++++++++++ 4 files changed, 127 insertions(+), 9 deletions(-) create mode 100644 toolkit/xre/nsQAppInstance.cpp create mode 100644 toolkit/xre/nsQAppInstance.h diff --git a/dom/plugins/PluginModuleChild.cpp b/dom/plugins/PluginModuleChild.cpp index eb146cd2dcf..4732de2e039 100644 --- a/dom/plugins/PluginModuleChild.cpp +++ b/dom/plugins/PluginModuleChild.cpp @@ -38,7 +38,7 @@ * ***** END LICENSE BLOCK ***** */ #ifdef MOZ_WIDGET_QT -#include +#include "nsQAppInstance.h" #endif #include "mozilla/plugins/PluginModuleChild.h" @@ -68,9 +68,6 @@ using namespace mozilla::plugins; namespace { PluginModuleChild* gInstance = nsnull; -#ifdef MOZ_WIDGET_QT -static QApplication *gQApp = nsnull; -#endif } @@ -97,9 +94,7 @@ PluginModuleChild::~PluginModuleChild() PR_UnloadLibrary(mLibrary); } #ifdef MOZ_WIDGET_QT - if (gQApp) - delete gQApp; - gQApp = nsnull; + nsQAppInstance::Release(); #endif gInstance = nsnull; } @@ -460,8 +455,7 @@ PluginModuleChild::InitGraphics() } #elif defined(MOZ_WIDGET_QT) - if (!qApp) - gQApp = new QApplication(0, NULL); + nsQAppInstance::AddRef(); #else // may not be necessary on all platforms #endif diff --git a/toolkit/xre/Makefile.in b/toolkit/xre/Makefile.in index b1e0d8c3c22..058067ed058 100644 --- a/toolkit/xre/Makefile.in +++ b/toolkit/xre/Makefile.in @@ -108,6 +108,8 @@ CPPSRCS += nsNativeAppSupportUnix.cpp else ifeq ($(MOZ_WIDGET_TOOLKIT),qt) CPPSRCS += nsNativeAppSupportQt.cpp +CPPSRCS += nsQAppInstance.cpp +EXPORTS += nsQAppInstance.h else CPPSRCS += nsNativeAppSupportDefault.cpp endif diff --git a/toolkit/xre/nsQAppInstance.cpp b/toolkit/xre/nsQAppInstance.cpp new file mode 100644 index 00000000000..8bf15e0ad2e --- /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 + * + * 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 + +// 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; + } +} diff --git a/toolkit/xre/nsQAppInstance.h b/toolkit/xre/nsQAppInstance.h new file mode 100644 index 00000000000..fde12b00b62 --- /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 + * + * 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 + +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 */