michael@0: /* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsAppShellSingleton_h__ michael@0: #define nsAppShellSingleton_h__ michael@0: michael@0: /** michael@0: * This file is designed to be included into the file that provides the michael@0: * nsIModule implementation for a particular widget toolkit. michael@0: * michael@0: * The following functions are defined: michael@0: * nsAppShellInit michael@0: * nsAppShellShutdown michael@0: * nsAppShellConstructor michael@0: * michael@0: * The nsAppShellInit function is designed to be used as a module constructor. michael@0: * If you already have a module constructor, then call nsAppShellInit from your michael@0: * module constructor. michael@0: * michael@0: * The nsAppShellShutdown function is designed to be used as a module michael@0: * destructor. If you already have a module destructor, then call michael@0: * nsAppShellShutdown from your module destructor. michael@0: * michael@0: * The nsAppShellConstructor function is designed to be used as a factory michael@0: * method for the nsAppShell class. michael@0: */ michael@0: michael@0: #include "nsXULAppAPI.h" michael@0: #if defined(MOZ_METRO) && defined(XP_WIN) michael@0: #include "winrt/MetroAppShell.h" michael@0: #endif michael@0: michael@0: static nsIAppShell *sAppShell; michael@0: michael@0: static nsresult michael@0: nsAppShellInit() michael@0: { michael@0: NS_ASSERTION(!sAppShell, "already initialized"); michael@0: michael@0: #if !defined(MOZ_METRO) || !defined(XP_WIN) michael@0: sAppShell = new nsAppShell(); michael@0: #else michael@0: if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro) { michael@0: sAppShell = new MetroAppShell(); michael@0: } else { michael@0: sAppShell = new nsAppShell(); michael@0: } michael@0: #endif michael@0: if (!sAppShell) michael@0: return NS_ERROR_OUT_OF_MEMORY; michael@0: NS_ADDREF(sAppShell); michael@0: michael@0: nsresult rv; michael@0: #if !defined(MOZ_METRO) || !defined(XP_WIN) michael@0: rv = static_cast(sAppShell)->Init(); michael@0: #else michael@0: if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro) { michael@0: rv = static_cast(sAppShell)->Init(); michael@0: } else { michael@0: rv = static_cast(sAppShell)->Init(); michael@0: } michael@0: #endif michael@0: if (NS_FAILED(rv)) { michael@0: NS_RELEASE(sAppShell); michael@0: return rv; michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: static void michael@0: nsAppShellShutdown() michael@0: { michael@0: NS_RELEASE(sAppShell); michael@0: } michael@0: michael@0: static nsresult michael@0: nsAppShellConstructor(nsISupports *outer, const nsIID &iid, void **result) michael@0: { michael@0: NS_ENSURE_TRUE(!outer, NS_ERROR_NO_AGGREGATION); michael@0: NS_ENSURE_TRUE(sAppShell, NS_ERROR_NOT_INITIALIZED); michael@0: michael@0: return sAppShell->QueryInterface(iid, result); michael@0: } michael@0: michael@0: #endif // nsAppShellSingleton_h__