widget/xpwidgets/nsAppShellSingleton.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/xpwidgets/nsAppShellSingleton.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,88 @@
     1.4 +/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsAppShellSingleton_h__
    1.10 +#define nsAppShellSingleton_h__
    1.11 +
    1.12 +/**
    1.13 + * This file is designed to be included into the file that provides the
    1.14 + * nsIModule implementation for a particular widget toolkit.
    1.15 + *
    1.16 + * The following functions are defined:
    1.17 + *   nsAppShellInit
    1.18 + *   nsAppShellShutdown
    1.19 + *   nsAppShellConstructor
    1.20 + *
    1.21 + * The nsAppShellInit function is designed to be used as a module constructor.
    1.22 + * If you already have a module constructor, then call nsAppShellInit from your
    1.23 + * module constructor.
    1.24 + *
    1.25 + * The nsAppShellShutdown function is designed to be used as a module
    1.26 + * destructor.  If you already have a module destructor, then call
    1.27 + * nsAppShellShutdown from your module destructor.
    1.28 + *
    1.29 + * The nsAppShellConstructor function is designed to be used as a factory
    1.30 + * method for the nsAppShell class.
    1.31 + */
    1.32 +
    1.33 +#include "nsXULAppAPI.h"
    1.34 +#if defined(MOZ_METRO) && defined(XP_WIN)
    1.35 +#include "winrt/MetroAppShell.h"
    1.36 +#endif
    1.37 +
    1.38 +static nsIAppShell *sAppShell;
    1.39 +
    1.40 +static nsresult
    1.41 +nsAppShellInit()
    1.42 +{
    1.43 +  NS_ASSERTION(!sAppShell, "already initialized");
    1.44 +
    1.45 +#if !defined(MOZ_METRO) || !defined(XP_WIN)
    1.46 +  sAppShell = new nsAppShell();
    1.47 +#else
    1.48 +  if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro) {
    1.49 +    sAppShell = new MetroAppShell();
    1.50 +  } else {
    1.51 +    sAppShell = new nsAppShell();
    1.52 +  }
    1.53 +#endif
    1.54 +  if (!sAppShell)
    1.55 +    return NS_ERROR_OUT_OF_MEMORY;
    1.56 +  NS_ADDREF(sAppShell);
    1.57 +
    1.58 +  nsresult rv;
    1.59 +#if !defined(MOZ_METRO) || !defined(XP_WIN)
    1.60 +  rv = static_cast<nsAppShell*>(sAppShell)->Init();
    1.61 +#else
    1.62 +  if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro) {
    1.63 +    rv = static_cast<MetroAppShell*>(sAppShell)->Init();
    1.64 +  } else {
    1.65 +    rv = static_cast<nsAppShell*>(sAppShell)->Init();
    1.66 +  }
    1.67 +#endif
    1.68 +  if (NS_FAILED(rv)) {
    1.69 +    NS_RELEASE(sAppShell);
    1.70 +    return rv;
    1.71 +  }
    1.72 +
    1.73 +  return NS_OK;
    1.74 +}
    1.75 +
    1.76 +static void
    1.77 +nsAppShellShutdown()
    1.78 +{
    1.79 +  NS_RELEASE(sAppShell);
    1.80 +}
    1.81 +
    1.82 +static nsresult
    1.83 +nsAppShellConstructor(nsISupports *outer, const nsIID &iid, void **result)
    1.84 +{
    1.85 +  NS_ENSURE_TRUE(!outer, NS_ERROR_NO_AGGREGATION);
    1.86 +  NS_ENSURE_TRUE(sAppShell, NS_ERROR_NOT_INITIALIZED);
    1.87 +
    1.88 +  return sAppShell->QueryInterface(iid, result);
    1.89 +}
    1.90 +
    1.91 +#endif  // nsAppShellSingleton_h__

mercurial