Bug 1944416: Restore individual tabs from closed groups in closed windows r=dao,sessi...
[gecko.git] / layout / build / nsLayoutModule.cpp
blobd2bf86d899fac1a0945c7a998bd80f1976f397e8
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsLayoutModule.h"
9 #include "base/basictypes.h"
11 #include "XPCModule.h"
12 #include "mozilla/Components.h"
13 #include "mozilla/ModuleUtils.h"
14 #include "nsImageModule.h"
15 #include "nsLayoutStatics.h"
16 #include "nsContentDLF.h"
17 #include "nsContentPolicyUtils.h"
18 #include "nsDataDocumentContentPolicy.h"
19 #include "nsNoDataProtocolContentPolicy.h"
20 #include "nsDOMCID.h"
21 #include "nsFrameMessageManager.h"
22 #include "nsHTMLContentSerializer.h"
23 #include "nsHTMLParts.h"
24 #include "nsIContentSerializer.h"
25 #include "nsIDocumentViewer.h"
26 #include "nsPlainTextSerializer.h"
27 #include "nsXMLContentSerializer.h"
28 #include "nsXHTMLContentSerializer.h"
29 #include "nsFocusManager.h"
30 #include "ThirdPartyUtil.h"
31 #include "gfxPlatform.h"
32 #include "mozilla/gfx/gfxVars.h"
33 #include "mozilla/dom/quota/QuotaManagerService.h"
35 #include "nsIEventListenerService.h"
37 // view stuff
38 #include "nsContentCreatorFunctions.h"
40 #include "mozilla/dom/LocalStorageCommon.h"
41 #include "mozilla/dom/LocalStorageManager.h"
42 #include "mozilla/dom/LocalStorageManager2.h"
43 #include "mozilla/dom/SessionStorageManager.h"
45 #ifdef MOZ_WEBSPEECH
46 # include "mozilla/dom/nsSynthVoiceRegistry.h"
47 # include "mozilla/dom/OnlineSpeechRecognitionService.h"
48 #endif
50 #include "mozilla/dom/PushNotifier.h"
51 using mozilla::dom::PushNotifier;
52 #define PUSHNOTIFIER_CID \
53 { \
54 0x2fc2d3e3, 0x020f, 0x404e, { \
55 0xb0, 0x6a, 0x6e, 0xcf, 0x3e, 0xa2, 0x33, 0x4a \
56 } \
59 #include "nsScriptSecurityManager.h"
60 #include "nsNetCID.h"
61 #if defined(MOZ_WIDGET_ANDROID)
62 # include "nsHapticFeedback.h"
63 #endif
64 #include "nsParserUtils.h"
66 class nsIDocumentLoaderFactory;
68 #define PRODUCT_NAME "Gecko"
70 #include "inDeepTreeWalker.h"
72 static void Shutdown();
74 #include "mozilla/dom/nsContentSecurityManager.h"
76 using namespace mozilla;
77 using namespace mozilla::dom;
78 using namespace mozilla::net;
80 //-----------------------------------------------------------------------------
82 static bool gInitialized = false;
84 // Perform our one-time intialization for this module
86 void nsLayoutModuleInitialize() {
87 if (gInitialized) {
88 MOZ_CRASH("Recursive layout module initialization");
91 static_assert(sizeof(uintptr_t) == sizeof(void*),
92 "Eeek! You'll need to adjust the size of uintptr_t to the "
93 "size of a pointer on your platform.");
95 gInitialized = true;
97 if (NS_FAILED(xpcModuleCtor())) {
98 MOZ_CRASH("xpcModuleCtor failed");
101 if (NS_FAILED(nsLayoutStatics::Initialize())) {
102 Shutdown();
103 MOZ_CRASH("nsLayoutStatics::Initialize failed");
107 // Shutdown this module, releasing all of the module resources
109 // static
110 void Shutdown() {
111 MOZ_ASSERT(gInitialized, "module not initialized");
112 if (!gInitialized) {
113 return;
116 gInitialized = false;
118 nsLayoutStatics::Release();
121 already_AddRefed<nsIDocumentViewer> NS_NewDocumentViewer();
122 nsresult NS_NewContentDocumentLoaderFactory(nsIDocumentLoaderFactory** aResult);
123 nsresult NS_NewContentPolicy(nsIContentPolicy** aResult);
125 nsresult NS_NewEventListenerService(nsIEventListenerService** aResult);
126 nsresult NS_NewGlobalMessageManager(nsISupports** aResult);
127 nsresult NS_NewParentProcessMessageManager(nsISupports** aResult);
128 nsresult NS_NewChildProcessMessageManager(nsISupports** aResult);
130 #define MAKE_CTOR(ctor_, iface_, func_) \
131 nsresult ctor_(REFNSIID aIID, void** aResult) { \
132 *aResult = nullptr; \
133 iface_* inst; \
134 nsresult rv = func_(&inst); \
135 if (NS_SUCCEEDED(rv)) { \
136 rv = inst->QueryInterface(aIID, aResult); \
137 NS_RELEASE(inst); \
139 return rv; \
142 #define MAKE_GENERIC_CTOR(iface_, func_) \
143 NS_IMPL_COMPONENT_FACTORY(iface_) { \
144 nsCOMPtr<iface_> inst; \
145 if (NS_SUCCEEDED(func_(getter_AddRefs(inst)))) { \
146 return inst.forget(); \
148 return nullptr; \
151 #define MAKE_GENERIC_CTOR2(iface_, func_) \
152 NS_IMPL_COMPONENT_FACTORY(iface_) { return func_(); }
154 MAKE_GENERIC_CTOR2(nsIDocumentViewer, NS_NewDocumentViewer)
156 MAKE_CTOR(CreateXMLContentSerializer, nsIContentSerializer,
157 NS_NewXMLContentSerializer)
158 MAKE_CTOR(CreateHTMLContentSerializer, nsIContentSerializer,
159 NS_NewHTMLContentSerializer)
160 MAKE_CTOR(CreateXHTMLContentSerializer, nsIContentSerializer,
161 NS_NewXHTMLContentSerializer)
162 MAKE_CTOR(CreatePlainTextSerializer, nsIContentSerializer,
163 NS_NewPlainTextSerializer)
164 MAKE_CTOR(CreateContentPolicy, nsIContentPolicy, NS_NewContentPolicy)
166 MAKE_GENERIC_CTOR(nsIDocumentLoaderFactory, NS_NewContentDocumentLoaderFactory)
167 MAKE_GENERIC_CTOR(nsIEventListenerService, NS_NewEventListenerService)
168 MAKE_CTOR(CreateGlobalMessageManager, nsISupports, NS_NewGlobalMessageManager)
169 MAKE_CTOR(CreateParentMessageManager, nsISupports,
170 NS_NewParentProcessMessageManager)
171 MAKE_CTOR(CreateChildMessageManager, nsISupports,
172 NS_NewChildProcessMessageManager)
174 MAKE_GENERIC_CTOR(nsIFocusManager, NS_NewFocusManager)
176 // views are not refcounted, so this is the same as
177 // NS_GENERIC_FACTORY_CONSTRUCTOR without the NS_ADDREF/NS_RELEASE
178 #define NS_GENERIC_FACTORY_CONSTRUCTOR_NOREFS(_InstanceClass) \
179 static nsresult _InstanceClass##Constructor(REFNSIID aIID, void** aResult) { \
180 nsresult rv; \
182 *aResult = nullptr; \
184 _InstanceClass* inst = new _InstanceClass(); \
185 if (nullptr == inst) { \
186 rv = NS_ERROR_OUT_OF_MEMORY; \
187 return rv; \
189 rv = inst->QueryInterface(aIID, aResult); \
191 return rv; \
194 #ifdef ACCESSIBILITY
195 # include "xpcAccessibilityService.h"
197 MAKE_GENERIC_CTOR(nsIAccessibilityService, NS_GetAccessibilityService)
198 #endif
200 nsresult Construct_nsIScriptSecurityManager(REFNSIID aIID, void** aResult) {
201 if (!aResult) {
202 return NS_ERROR_NULL_POINTER;
204 *aResult = nullptr;
205 nsScriptSecurityManager* obj =
206 nsScriptSecurityManager::GetScriptSecurityManager();
207 if (!obj) {
208 return NS_ERROR_OUT_OF_MEMORY;
210 if (NS_FAILED(obj->QueryInterface(aIID, aResult))) {
211 return NS_ERROR_FAILURE;
213 return NS_OK;
216 nsresult LocalStorageManagerConstructor(REFNSIID aIID, void** aResult) {
217 if (NextGenLocalStorageEnabled()) {
218 auto manager = MakeRefPtr<LocalStorageManager2>();
219 return manager->QueryInterface(aIID, aResult);
222 auto manager = MakeRefPtr<LocalStorageManager>();
223 return manager->QueryInterface(aIID, aResult);
226 nsresult SessionStorageManagerConstructor(REFNSIID aIID, void** aResult) {
227 auto manager = MakeRefPtr<SessionStorageManager>(nullptr);
228 return manager->QueryInterface(aIID, aResult);
231 void nsLayoutModuleDtor() {
232 if (XRE_GetProcessType() == GeckoProcessType_GPU ||
233 XRE_GetProcessType() == GeckoProcessType_VR ||
234 XRE_GetProcessType() == GeckoProcessType_RDD) {
235 return;
238 Shutdown();
239 nsContentUtils::XPCOMShutdown();
241 // Layout depends heavily on gfx and imagelib, so we want to make sure that
242 // these modules are shut down after all the layout cleanup runs.
243 mozilla::image::ShutdownModule();
244 gfxPlatform::Shutdown();
245 gfx::gfxVars::Shutdown();
247 nsScriptSecurityManager::Shutdown();
248 xpcModuleDtor();