Bug 1755924 [wpt PR 32876] - Handle resumed blocks that get sliced by floats correctl...
[gecko.git] / widget / nsAppShellSingleton.h
bloba7d440bd53700cb6e0be4035386ec95616618041
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.
13 * The following functions are defined:
14 * nsAppShellInit
15 * nsAppShellShutdown
16 * nsAppShellConstructor
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.
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.
26 * The nsAppShellConstructor function is designed to be used as a factory
27 * method for the nsAppShell class.
30 #include "nsXULAppAPI.h"
32 static nsIAppShell* sAppShell;
34 static nsresult nsAppShellInit() {
35 NS_ASSERTION(!sAppShell, "already initialized");
37 sAppShell = new nsAppShell();
38 if (!sAppShell) return NS_ERROR_OUT_OF_MEMORY;
39 NS_ADDREF(sAppShell);
41 nsresult rv = static_cast<nsAppShell*>(sAppShell)->Init();
42 // If we somehow failed to initialize the appshell, it's extremely likely
43 // that we are sufficiently hosed that continuing on is just going to lead
44 // to bad things later. By crashing early here, the crash report will
45 // potentially contain a little more insight into what's going wrong than
46 // if we waited for a crash further down the line. See also bug 1545381.
47 MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
49 return NS_OK;
52 static void nsAppShellShutdown() { NS_RELEASE(sAppShell); }
54 nsresult nsAppShellConstructor(nsISupports* outer, const nsIID& iid,
55 void** result) {
56 NS_ENSURE_TRUE(!outer, NS_ERROR_NO_AGGREGATION);
57 NS_ENSURE_TRUE(sAppShell, NS_ERROR_NOT_INITIALIZED);
59 return sAppShell->QueryInterface(iid, result);
62 #endif // nsAppShellSingleton_h__