widget/xpwidgets/nsAppShellSingleton.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial