Bug 1867190 - Add prefs for PHC probablities r=glandium
[gecko.git] / layout / build / nsLayoutModule.cpp
blob542785f156731a15a15381e61e6930d4f1977579
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 "nsIDocumentViewer.h"
27 #include "nsPlainTextSerializer.h"
28 #include "nsXMLContentSerializer.h"
29 #include "nsXHTMLContentSerializer.h"
30 #include "nsLayoutCID.h"
31 #include "nsFocusManager.h"
32 #include "ThirdPartyUtil.h"
33 #include "gfxPlatform.h"
34 #include "mozilla/gfx/gfxVars.h"
35 #include "mozilla/dom/quota/QuotaManagerService.h"
37 #include "nsIEventListenerService.h"
39 // view stuff
40 #include "nsContentCreatorFunctions.h"
42 #include "mozilla/dom/LocalStorageCommon.h"
43 #include "mozilla/dom/LocalStorageManager.h"
44 #include "mozilla/dom/LocalStorageManager2.h"
45 #include "mozilla/dom/SessionStorageManager.h"
47 #ifdef MOZ_WEBSPEECH
48 # include "mozilla/dom/nsSynthVoiceRegistry.h"
49 # include "mozilla/dom/OnlineSpeechRecognitionService.h"
50 #endif
52 #include "mozilla/dom/PushNotifier.h"
53 using mozilla::dom::PushNotifier;
54 #define PUSHNOTIFIER_CID \
55 { \
56 0x2fc2d3e3, 0x020f, 0x404e, { \
57 0xb0, 0x6a, 0x6e, 0xcf, 0x3e, 0xa2, 0x33, 0x4a \
58 } \
61 #include "nsScriptSecurityManager.h"
62 #include "nsNetCID.h"
63 #if defined(MOZ_WIDGET_ANDROID)
64 # include "nsHapticFeedback.h"
65 #endif
66 #include "nsParserUtils.h"
68 class nsIDocumentLoaderFactory;
70 #define PRODUCT_NAME "Gecko"
72 #include "inDeepTreeWalker.h"
74 static void Shutdown();
76 #include "mozilla/dom/nsContentSecurityManager.h"
78 using namespace mozilla;
79 using namespace mozilla::dom;
80 using namespace mozilla::net;
82 //-----------------------------------------------------------------------------
84 static bool gInitialized = false;
86 // Perform our one-time intialization for this module
88 void nsLayoutModuleInitialize() {
89 if (gInitialized) {
90 MOZ_CRASH("Recursive layout module initialization");
93 static_assert(sizeof(uintptr_t) == sizeof(void*),
94 "Eeek! You'll need to adjust the size of uintptr_t to the "
95 "size of a pointer on your platform.");
97 gInitialized = true;
99 if (NS_FAILED(xpcModuleCtor())) {
100 MOZ_CRASH("xpcModuleCtor failed");
103 if (NS_FAILED(nsLayoutStatics::Initialize())) {
104 Shutdown();
105 MOZ_CRASH("nsLayoutStatics::Initialize failed");
109 // Shutdown this module, releasing all of the module resources
111 // static
112 void Shutdown() {
113 MOZ_ASSERT(gInitialized, "module not initialized");
114 if (!gInitialized) 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) return NS_ERROR_NULL_POINTER;
202 *aResult = nullptr;
203 nsScriptSecurityManager* obj =
204 nsScriptSecurityManager::GetScriptSecurityManager();
205 if (!obj) return NS_ERROR_OUT_OF_MEMORY;
206 if (NS_FAILED(obj->QueryInterface(aIID, aResult))) return NS_ERROR_FAILURE;
207 return NS_OK;
210 nsresult LocalStorageManagerConstructor(REFNSIID aIID, void** aResult) {
211 if (NextGenLocalStorageEnabled()) {
212 RefPtr<LocalStorageManager2> manager = new LocalStorageManager2();
213 return manager->QueryInterface(aIID, aResult);
216 RefPtr<LocalStorageManager> manager = new LocalStorageManager();
217 return manager->QueryInterface(aIID, aResult);
220 nsresult SessionStorageManagerConstructor(REFNSIID aIID, void** aResult) {
221 RefPtr<SessionStorageManager> manager = new SessionStorageManager(nullptr);
222 return manager->QueryInterface(aIID, aResult);
225 void nsLayoutModuleDtor() {
226 if (XRE_GetProcessType() == GeckoProcessType_GPU ||
227 XRE_GetProcessType() == GeckoProcessType_VR ||
228 XRE_GetProcessType() == GeckoProcessType_RDD) {
229 return;
232 Shutdown();
233 nsContentUtils::XPCOMShutdown();
235 // Layout depends heavily on gfx and imagelib, so we want to make sure that
236 // these modules are shut down after all the layout cleanup runs.
237 mozilla::image::ShutdownModule();
238 gfxPlatform::Shutdown();
239 gfx::gfxVars::Shutdown();
241 nsScriptSecurityManager::Shutdown();
242 xpcModuleDtor();