Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef nsAppShellSingleton_h__ |
michael@0 | 7 | #define nsAppShellSingleton_h__ |
michael@0 | 8 | |
michael@0 | 9 | /** |
michael@0 | 10 | * This file is designed to be included into the file that provides the |
michael@0 | 11 | * nsIModule implementation for a particular widget toolkit. |
michael@0 | 12 | * |
michael@0 | 13 | * The following functions are defined: |
michael@0 | 14 | * nsAppShellInit |
michael@0 | 15 | * nsAppShellShutdown |
michael@0 | 16 | * nsAppShellConstructor |
michael@0 | 17 | * |
michael@0 | 18 | * The nsAppShellInit function is designed to be used as a module constructor. |
michael@0 | 19 | * If you already have a module constructor, then call nsAppShellInit from your |
michael@0 | 20 | * module constructor. |
michael@0 | 21 | * |
michael@0 | 22 | * The nsAppShellShutdown function is designed to be used as a module |
michael@0 | 23 | * destructor. If you already have a module destructor, then call |
michael@0 | 24 | * nsAppShellShutdown from your module destructor. |
michael@0 | 25 | * |
michael@0 | 26 | * The nsAppShellConstructor function is designed to be used as a factory |
michael@0 | 27 | * method for the nsAppShell class. |
michael@0 | 28 | */ |
michael@0 | 29 | |
michael@0 | 30 | #include "nsXULAppAPI.h" |
michael@0 | 31 | #if defined(MOZ_METRO) && defined(XP_WIN) |
michael@0 | 32 | #include "winrt/MetroAppShell.h" |
michael@0 | 33 | #endif |
michael@0 | 34 | |
michael@0 | 35 | static nsIAppShell *sAppShell; |
michael@0 | 36 | |
michael@0 | 37 | static nsresult |
michael@0 | 38 | nsAppShellInit() |
michael@0 | 39 | { |
michael@0 | 40 | NS_ASSERTION(!sAppShell, "already initialized"); |
michael@0 | 41 | |
michael@0 | 42 | #if !defined(MOZ_METRO) || !defined(XP_WIN) |
michael@0 | 43 | sAppShell = new nsAppShell(); |
michael@0 | 44 | #else |
michael@0 | 45 | if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro) { |
michael@0 | 46 | sAppShell = new MetroAppShell(); |
michael@0 | 47 | } else { |
michael@0 | 48 | sAppShell = new nsAppShell(); |
michael@0 | 49 | } |
michael@0 | 50 | #endif |
michael@0 | 51 | if (!sAppShell) |
michael@0 | 52 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 53 | NS_ADDREF(sAppShell); |
michael@0 | 54 | |
michael@0 | 55 | nsresult rv; |
michael@0 | 56 | #if !defined(MOZ_METRO) || !defined(XP_WIN) |
michael@0 | 57 | rv = static_cast<nsAppShell*>(sAppShell)->Init(); |
michael@0 | 58 | #else |
michael@0 | 59 | if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro) { |
michael@0 | 60 | rv = static_cast<MetroAppShell*>(sAppShell)->Init(); |
michael@0 | 61 | } else { |
michael@0 | 62 | rv = static_cast<nsAppShell*>(sAppShell)->Init(); |
michael@0 | 63 | } |
michael@0 | 64 | #endif |
michael@0 | 65 | if (NS_FAILED(rv)) { |
michael@0 | 66 | NS_RELEASE(sAppShell); |
michael@0 | 67 | return rv; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | return NS_OK; |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | static void |
michael@0 | 74 | nsAppShellShutdown() |
michael@0 | 75 | { |
michael@0 | 76 | NS_RELEASE(sAppShell); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | static nsresult |
michael@0 | 80 | nsAppShellConstructor(nsISupports *outer, const nsIID &iid, void **result) |
michael@0 | 81 | { |
michael@0 | 82 | NS_ENSURE_TRUE(!outer, NS_ERROR_NO_AGGREGATION); |
michael@0 | 83 | NS_ENSURE_TRUE(sAppShell, NS_ERROR_NOT_INITIALIZED); |
michael@0 | 84 | |
michael@0 | 85 | return sAppShell->QueryInterface(iid, result); |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | #endif // nsAppShellSingleton_h__ |