Bug 1758813 [wpt PR 33142] - Implement RP sign out, a=testonly
[gecko.git] / layout / build / nsLayoutModule.cpp
blobd5811d18e45b014a0fa70f6697c91e650a04d0c8
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 "nsContentCID.h"
17 #include "nsContentDLF.h"
18 #include "nsContentPolicyUtils.h"
19 #include "nsDataDocumentContentPolicy.h"
20 #include "nsNoDataProtocolContentPolicy.h"
21 #include "nsDOMCID.h"
22 #include "nsFrameMessageManager.h"
23 #include "nsHTMLContentSerializer.h"
24 #include "nsHTMLParts.h"
25 #include "nsIContentSerializer.h"
26 #include "nsIContentViewer.h"
27 #include "nsPlainTextSerializer.h"
28 #include "nsXMLContentSerializer.h"
29 #include "nsXHTMLContentSerializer.h"
30 #include "nsIFrameTraversal.h"
31 #include "nsLayoutCID.h"
32 #include "nsFocusManager.h"
33 #include "ThirdPartyUtil.h"
34 #include "gfxPlatform.h"
35 #include "mozilla/gfx/gfxVars.h"
36 #include "mozilla/dom/quota/QuotaManagerService.h"
38 #include "nsIEventListenerService.h"
40 // view stuff
41 #include "nsContentCreatorFunctions.h"
43 #include "mozilla/dom/LocalStorageCommon.h"
44 #include "mozilla/dom/LocalStorageManager.h"
45 #include "mozilla/dom/LocalStorageManager2.h"
46 #include "mozilla/dom/SessionStorageManager.h"
48 #ifdef MOZ_WEBSPEECH
49 # include "mozilla/dom/nsSynthVoiceRegistry.h"
50 # include "mozilla/dom/OnlineSpeechRecognitionService.h"
51 #endif
53 #include "mozilla/dom/PushNotifier.h"
54 using mozilla::dom::PushNotifier;
55 #define PUSHNOTIFIER_CID \
56 { \
57 0x2fc2d3e3, 0x020f, 0x404e, { \
58 0xb0, 0x6a, 0x6e, 0xcf, 0x3e, 0xa2, 0x33, 0x4a \
59 } \
62 #include "nsScriptSecurityManager.h"
63 #include "nsNetCID.h"
64 #if defined(MOZ_WIDGET_ANDROID)
65 # include "nsHapticFeedback.h"
66 #endif
67 #include "nsParserUtils.h"
69 class nsIDocumentLoaderFactory;
71 #define PRODUCT_NAME "Gecko"
73 #include "inDeepTreeWalker.h"
75 static void Shutdown();
77 #include "mozilla/dom/nsContentSecurityManager.h"
79 using namespace mozilla;
80 using namespace mozilla::dom;
81 using namespace mozilla::net;
83 //-----------------------------------------------------------------------------
85 static bool gInitialized = false;
87 // Perform our one-time intialization for this module
89 void nsLayoutModuleInitialize() {
90 if (gInitialized) {
91 MOZ_CRASH("Recursive layout module initialization");
94 static_assert(sizeof(uintptr_t) == sizeof(void*),
95 "Eeek! You'll need to adjust the size of uintptr_t to the "
96 "size of a pointer on your platform.");
98 gInitialized = true;
100 if (NS_FAILED(xpcModuleCtor())) {
101 MOZ_CRASH("xpcModuleCtor failed");
104 if (NS_FAILED(nsLayoutStatics::Initialize())) {
105 Shutdown();
106 MOZ_CRASH("nsLayoutStatics::Initialize failed");
110 // Shutdown this module, releasing all of the module resources
112 // static
113 void Shutdown() {
114 MOZ_ASSERT(gInitialized, "module not initialized");
115 if (!gInitialized) return;
117 gInitialized = false;
119 nsLayoutStatics::Release();
122 nsresult NS_CreateFrameTraversal(nsIFrameTraversal** aResult);
124 already_AddRefed<nsIContentViewer> NS_NewContentViewer();
125 nsresult NS_NewContentDocumentLoaderFactory(nsIDocumentLoaderFactory** aResult);
126 nsresult NS_NewContentPolicy(nsIContentPolicy** aResult);
128 nsresult NS_NewEventListenerService(nsIEventListenerService** aResult);
129 nsresult NS_NewGlobalMessageManager(nsISupports** aResult);
130 nsresult NS_NewParentProcessMessageManager(nsISupports** aResult);
131 nsresult NS_NewChildProcessMessageManager(nsISupports** aResult);
133 #define MAKE_CTOR(ctor_, iface_, func_) \
134 nsresult ctor_(nsISupports* aOuter, REFNSIID aIID, void** aResult) { \
135 *aResult = nullptr; \
136 if (aOuter) return NS_ERROR_NO_AGGREGATION; \
137 iface_* inst; \
138 nsresult rv = func_(&inst); \
139 if (NS_SUCCEEDED(rv)) { \
140 rv = inst->QueryInterface(aIID, aResult); \
141 NS_RELEASE(inst); \
143 return rv; \
146 #define MAKE_GENERIC_CTOR(iface_, func_) \
147 NS_IMPL_COMPONENT_FACTORY(iface_) { \
148 nsCOMPtr<iface_> inst; \
149 if (NS_SUCCEEDED(func_(getter_AddRefs(inst)))) { \
150 return inst.forget(); \
152 return nullptr; \
155 #define MAKE_GENERIC_CTOR2(iface_, func_) \
156 NS_IMPL_COMPONENT_FACTORY(iface_) { return func_(); }
158 MAKE_GENERIC_CTOR(nsIFrameTraversal, NS_CreateFrameTraversal)
160 MAKE_GENERIC_CTOR2(nsIContentViewer, NS_NewContentViewer)
162 MAKE_CTOR(CreateXMLContentSerializer, nsIContentSerializer,
163 NS_NewXMLContentSerializer)
164 MAKE_CTOR(CreateHTMLContentSerializer, nsIContentSerializer,
165 NS_NewHTMLContentSerializer)
166 MAKE_CTOR(CreateXHTMLContentSerializer, nsIContentSerializer,
167 NS_NewXHTMLContentSerializer)
168 MAKE_CTOR(CreatePlainTextSerializer, nsIContentSerializer,
169 NS_NewPlainTextSerializer)
170 MAKE_CTOR(CreateContentPolicy, nsIContentPolicy, NS_NewContentPolicy)
172 MAKE_GENERIC_CTOR(nsIDocumentLoaderFactory, NS_NewContentDocumentLoaderFactory)
173 MAKE_GENERIC_CTOR(nsIEventListenerService, NS_NewEventListenerService)
174 MAKE_CTOR(CreateGlobalMessageManager, nsISupports, NS_NewGlobalMessageManager)
175 MAKE_CTOR(CreateParentMessageManager, nsISupports,
176 NS_NewParentProcessMessageManager)
177 MAKE_CTOR(CreateChildMessageManager, nsISupports,
178 NS_NewChildProcessMessageManager)
180 MAKE_GENERIC_CTOR(nsIFocusManager, NS_NewFocusManager)
182 // views are not refcounted, so this is the same as
183 // NS_GENERIC_FACTORY_CONSTRUCTOR without the NS_ADDREF/NS_RELEASE
184 #define NS_GENERIC_FACTORY_CONSTRUCTOR_NOREFS(_InstanceClass) \
185 static nsresult _InstanceClass##Constructor(nsISupports* aOuter, \
186 REFNSIID aIID, void** aResult) { \
187 nsresult rv; \
189 *aResult = nullptr; \
190 if (nullptr != aOuter) { \
191 rv = NS_ERROR_NO_AGGREGATION; \
192 return rv; \
195 _InstanceClass* inst = new _InstanceClass(); \
196 if (nullptr == inst) { \
197 rv = NS_ERROR_OUT_OF_MEMORY; \
198 return rv; \
200 rv = inst->QueryInterface(aIID, aResult); \
202 return rv; \
205 #ifdef ACCESSIBILITY
206 # include "xpcAccessibilityService.h"
208 MAKE_GENERIC_CTOR(nsIAccessibilityService, NS_GetAccessibilityService)
209 #endif
211 nsresult Construct_nsIScriptSecurityManager(nsISupports* aOuter, REFNSIID aIID,
212 void** aResult) {
213 if (!aResult) return NS_ERROR_NULL_POINTER;
214 *aResult = nullptr;
215 if (aOuter) return NS_ERROR_NO_AGGREGATION;
216 nsScriptSecurityManager* obj =
217 nsScriptSecurityManager::GetScriptSecurityManager();
218 if (!obj) return NS_ERROR_OUT_OF_MEMORY;
219 if (NS_FAILED(obj->QueryInterface(aIID, aResult))) return NS_ERROR_FAILURE;
220 return NS_OK;
223 nsresult LocalStorageManagerConstructor(nsISupports* aOuter, REFNSIID aIID,
224 void** aResult) {
225 if (NextGenLocalStorageEnabled()) {
226 RefPtr<LocalStorageManager2> manager = new LocalStorageManager2();
227 return manager->QueryInterface(aIID, aResult);
230 RefPtr<LocalStorageManager> manager = new LocalStorageManager();
231 return manager->QueryInterface(aIID, aResult);
234 nsresult SessionStorageManagerConstructor(nsISupports* aOuter, REFNSIID aIID,
235 void** aResult) {
236 RefPtr<SessionStorageManager> manager = new SessionStorageManager(nullptr);
237 return manager->QueryInterface(aIID, aResult);
240 static const mozilla::Module::CategoryEntry kLayoutCategories[] = {
241 // clang-format off
242 {nullptr}
243 // clang-format on
246 void nsLayoutModuleDtor() {
247 if (XRE_GetProcessType() == GeckoProcessType_GPU ||
248 XRE_GetProcessType() == GeckoProcessType_VR ||
249 XRE_GetProcessType() == GeckoProcessType_RDD) {
250 return;
253 Shutdown();
254 nsContentUtils::XPCOMShutdown();
256 // Layout depends heavily on gfx and imagelib, so we want to make sure that
257 // these modules are shut down after all the layout cleanup runs.
258 mozilla::image::ShutdownModule();
259 gfxPlatform::Shutdown();
260 gfx::gfxVars::Shutdown();
262 nsScriptSecurityManager::Shutdown();
263 xpcModuleDtor();
266 extern const mozilla::Module kLayoutModule = {mozilla::Module::kVersion,
267 nullptr,
268 nullptr,
269 kLayoutCategories,
270 nullptr,
271 nullptr,
272 nullptr};