Bug 1944416: Restore individual tabs from closed groups in closed windows r=dao,sessi...
[gecko.git] / layout / build / nsLayoutStatics.cpp
blob547656d343e7dcb6b482f4a42064539c533231c3
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 "base/basictypes.h"
9 #include "nsLayoutStatics.h"
10 #include "nscore.h"
12 #include "mozilla/intl/AppDateTimeFormat.h"
13 #include "mozilla/dom/ServiceWorkerRegistrar.h"
14 #include "nsAttrValue.h"
15 #include "nsComputedDOMStyle.h"
16 #include "nsContentDLF.h"
17 #include "nsContentUtils.h"
18 #include "nsCSSAnonBoxes.h"
19 #include "mozilla/css/ErrorReporter.h"
20 #include "nsCSSProps.h"
21 #include "nsCSSPseudoElements.h"
22 #include "nsCSSRendering.h"
23 #include "nsGenericHTMLFrameElement.h"
24 #include "mozilla/dom/Attr.h"
25 #include "mozilla/dom/PopupBlocker.h"
26 #include "nsIFrame.h"
27 #include "nsFrameState.h"
28 #include "nsGlobalWindowInner.h"
29 #include "nsGlobalWindowOuter.h"
30 #include "nsGkAtoms.h"
31 #include "nsImageFrame.h"
32 #include "mozilla/GlobalStyleSheetCache.h"
33 #include "nsRegion.h"
34 #include "nsRepeatService.h"
35 #include "nsFloatManager.h"
36 #include "nsTextControlFrame.h"
37 #include "txMozillaXSLTProcessor.h"
38 #include "nsTreeSanitizer.h"
39 #include "nsCellMap.h"
40 #include "nsTextFrame.h"
41 #include "nsCCUncollectableMarker.h"
42 #include "nsTextFragment.h"
43 #include "nsCORSListenerProxy.h"
44 #include "nsHtml5Module.h"
45 #include "nsHTMLTags.h"
46 #include "nsFocusManager.h"
47 #include "mozilla/dom/HTMLDNSPrefetch.h"
48 #include "mozilla/dom/HTMLInputElement.h"
49 #include "mozilla/dom/SVGElementFactory.h"
50 #include "nsMathMLAtoms.h"
51 #include "nsMathMLOperators.h"
52 #include "Navigator.h"
53 #include "StorageObserver.h"
54 #include "CacheObserver.h"
55 #include "DisplayItemClip.h"
56 #include "HitTestInfo.h"
57 #include "ActiveLayerTracker.h"
58 #include "AnimationCommon.h"
59 #include "LayerAnimationInfo.h"
61 #include "AudioChannelService.h"
62 #include "mozilla/dom/PromiseDebugging.h"
63 #include "mozilla/dom/nsMixedContentBlocker.h"
65 #include "nsXULPopupManager.h"
66 #include "nsXULContentUtils.h"
67 #include "nsXULPrototypeCache.h"
68 #include "nsXULTooltipListener.h"
70 #include "mozilla/dom/UIDirectionManager.h"
72 #include "CubebUtils.h"
73 #include "WebAudioUtils.h"
75 #include "nsError.h"
77 #include "nsJSEnvironment.h"
78 #include "nsContentSink.h"
79 #include "nsFrameMessageManager.h"
80 #include "nsDOMMutationObserver.h"
81 #include "nsHyphenationManager.h"
82 #include "nsWindowMemoryReporter.h"
83 #include "mozilla/dom/ContentParent.h"
84 #include "mozilla/ProcessPriorityManager.h"
85 #include "mozilla/PermissionManager.h"
86 #include "mozilla/dom/CustomElementRegistry.h"
87 #include "mozilla/EventDispatcher.h"
88 #include "mozilla/IMEStateManager.h"
89 #ifndef MOZ_WIDGET_ANDROID
90 # include "mozilla/Viaduct.h"
91 #endif
92 #include "mozilla/dom/HTMLVideoElement.h"
93 #include "ThirdPartyUtil.h"
94 #include "TouchManager.h"
95 #include "DecoderDoctorLogger.h"
96 #include "MediaDecoder.h"
97 #include "mozilla/ClearSiteData.h"
98 #include "mozilla/EditorController.h"
99 #include "mozilla/HTMLEditorController.h"
100 #include "mozilla/ServoBindings.h"
101 #include "mozilla/StaticPresData.h"
102 #include "mozilla/dom/AbstractRange.h"
103 #include "mozilla/dom/Document.h"
104 #include "mozilla/dom/WebIDLGlobalNameHash.h"
105 #include "mozilla/dom/PointerEventHandler.h"
106 #include "mozilla/dom/RemoteWorkerService.h"
107 #include "mozilla/dom/BlobURLProtocolHandler.h"
108 #include "mozilla/dom/ReportingHeader.h"
109 #include "mozilla/dom/BrowserParent.h"
110 #include "mozilla/dom/MIDIPlatformService.h"
111 #include "mozilla/dom/quota/ActorsParent.h"
112 #include "mozilla/dom/quota/StringifyUtils.h"
113 #include "mozilla/dom/localstorage/ActorsParent.h"
114 #include "mozilla/net/UrlClassifierFeatureFactory.h"
115 #include "mozilla/RemoteLazyInputStreamStorage.h"
116 #include "nsLayoutUtils.h"
117 #include "nsThreadManager.h"
118 #include "mozilla/css/ImageLoader.h"
119 #include "gfxUserFontSet.h"
120 #include "RestoreTabContentObserver.h"
121 #include "mozilla/intl/LineBreakCache.h"
123 #include "nsRLBoxExpatDriver.h"
124 #include "RLBoxWOFF2Types.h"
126 using namespace mozilla;
127 using namespace mozilla::net;
128 using namespace mozilla::dom;
129 using namespace mozilla::dom::ipc;
130 using namespace mozilla::dom::quota;
132 nsrefcnt nsLayoutStatics::sLayoutStaticRefcnt = 0;
134 nsresult nsLayoutStatics::Initialize() {
135 NS_ASSERTION(sLayoutStaticRefcnt == 0, "nsLayoutStatics isn't zero!");
137 sLayoutStaticRefcnt = 1;
138 NS_LOG_ADDREF(&sLayoutStaticRefcnt, sLayoutStaticRefcnt, "nsLayoutStatics",
141 nsresult rv;
143 ContentParent::StartUp();
145 nsCSSProps::Init();
147 #ifdef DEBUG
148 nsCSSPseudoElements::AssertAtoms();
149 nsCSSAnonBoxes::AssertAtoms();
150 DebugVerifyFrameStateBits();
151 #endif
153 StartupJSEnvironment();
155 nsGlobalWindowInner::Init();
156 nsGlobalWindowOuter::Init();
158 rv = nsContentUtils::Init();
159 if (NS_FAILED(rv)) {
160 NS_ERROR("Could not initialize nsContentUtils");
161 return rv;
164 nsAttrValue::Init();
166 rv = nsTextFragment::Init();
167 if (NS_FAILED(rv)) {
168 NS_ERROR("Could not initialize nsTextFragment");
169 return rv;
172 nsCellMap::Init();
174 StaticPresData::Init();
175 nsCSSRendering::Init();
176 css::ImageLoader::Init();
178 rv = HTMLDNSPrefetch::Initialize();
179 if (NS_FAILED(rv)) {
180 NS_ERROR("Could not initialize HTML DNS prefetch");
181 return rv;
184 nsMathMLOperators::AddRefTable();
186 Attr::Initialize();
188 PopupBlocker::Initialize();
190 rv = txMozillaXSLTProcessor::Startup();
191 if (NS_FAILED(rv)) {
192 NS_ERROR("Could not initialize txMozillaXSLTProcessor");
193 return rv;
196 rv = StorageObserver::Init();
197 if (NS_FAILED(rv)) {
198 NS_ERROR("Could not initialize StorageObserver");
199 return rv;
202 rv = nsCCUncollectableMarker::Init();
203 if (NS_FAILED(rv)) {
204 NS_ERROR("Could not initialize nsCCUncollectableMarker");
205 return rv;
208 rv = nsXULPopupManager::Init();
209 if (NS_FAILED(rv)) {
210 NS_ERROR("Could not initialize nsXULPopupManager");
211 return rv;
214 rv = nsFocusManager::Init();
215 if (NS_FAILED(rv)) {
216 NS_ERROR("Could not initialize nsFocusManager");
217 return rv;
220 DecoderDoctorLogger::Init();
221 CubebUtils::InitLibrary();
223 nsHtml5Module::InitializeStatics();
224 nsLayoutUtils::Initialize();
225 PointerEventHandler::InitializeStatics();
226 TouchManager::InitializeStatics();
228 nsWindowMemoryReporter::Init();
230 SVGElementFactory::Init();
232 ProcessPriorityManager::Init();
234 UIDirectionManager::Initialize();
236 CacheObserver::Init();
238 IMEStateManager::Init();
240 ServiceWorkerRegistrar::Initialize();
242 MediaDecoder::InitStatics();
244 PromiseDebugging::Init();
246 if (XRE_IsParentProcess() || XRE_IsContentProcess()) {
247 InitializeServo();
250 // This must be initialized on the main-thread.
251 mozilla::RemoteLazyInputStreamStorage::Initialize();
253 if (XRE_IsParentProcess()) {
254 // On content process we initialize these components when PContentChild is
255 // fully initialized.
256 mozilla::dom::RemoteWorkerService::InitializeParent();
259 ClearSiteData::Initialize();
261 // Reporting API.
262 ReportingHeader::Initialize();
264 InitializeScopedLogExtraInfo();
266 Stringifyable::InitTLS();
268 if (XRE_IsParentProcess()) {
269 InitializeQuotaManager();
270 InitializeLocalStorage();
273 ThirdPartyUtil::Startup();
275 RestoreTabContentObserver::Initialize();
277 mozilla::intl::LineBreakCache::Initialize();
279 RLBoxExpatSandboxPool::Initialize();
281 RLBoxWOFF2SandboxPool::Initalize();
283 if (XRE_IsParentProcess()) {
284 MIDIPlatformService::InitStatics();
287 #ifndef MOZ_WIDGET_ANDROID
288 if (XRE_IsParentProcess()) {
289 InitializeViaduct();
291 #endif
293 return NS_OK;
296 void nsLayoutStatics::Shutdown() {
297 // Don't need to shutdown nsWindowMemoryReporter, that will be done by the
298 // memory reporter manager.
300 if (XRE_IsParentProcess() || XRE_IsContentProcess()) {
301 ShutdownServo();
304 mozilla::dom::AbstractRange::Shutdown();
305 Document::Shutdown();
306 nsMessageManagerScriptExecutor::Shutdown();
307 nsFocusManager::Shutdown();
308 nsXULPopupManager::Shutdown();
309 UIDirectionManager::Shutdown();
310 StorageObserver::Shutdown();
311 txMozillaXSLTProcessor::Shutdown();
312 Attr::Shutdown();
313 PopupBlocker::Shutdown();
314 IMEStateManager::Shutdown();
315 EditorController::Shutdown();
316 HTMLEditorController::Shutdown();
317 HTMLDNSPrefetch::Shutdown();
318 nsCSSRendering::Shutdown();
319 StaticPresData::Shutdown();
320 nsCellMap::Shutdown();
321 ActiveLayerTracker::Shutdown();
323 // Release all of our atoms
324 nsRepeatService::Shutdown();
326 nsXULContentUtils::Finish();
327 nsXULPrototypeCache::ReleaseGlobals();
329 SVGElementFactory::Shutdown();
330 nsMathMLOperators::ReleaseTable();
332 nsFloatManager::Shutdown();
333 nsImageFrame::ReleaseGlobals();
335 mozilla::css::ErrorReporter::ReleaseGlobals();
337 nsTextFragment::Shutdown();
339 nsAttrValue::Shutdown();
340 nsContentUtils::Shutdown();
341 nsMixedContentBlocker::Shutdown();
342 GlobalStyleSheetCache::Shutdown();
344 ShutdownJSEnvironment();
345 nsGlobalWindowInner::ShutDown();
346 nsGlobalWindowOuter::ShutDown();
348 CubebUtils::ShutdownLibrary();
349 WebAudioUtils::Shutdown();
351 nsCORSListenerProxy::Shutdown();
353 PointerEventHandler::ReleaseStatics();
355 TouchManager::ReleaseStatics();
357 nsTreeSanitizer::ReleaseStatics();
359 nsHtml5Module::ReleaseStatics();
361 mozilla::EventDispatcher::Shutdown();
363 HTMLInputElement::DestroyUploadLastDir();
365 nsLayoutUtils::Shutdown();
367 nsHyphenationManager::Shutdown();
368 nsDOMMutationObserver::Shutdown();
370 mozilla::intl::AppDateTimeFormat::Shutdown();
372 ContentParent::ShutDown();
374 DisplayItemClip::Shutdown();
375 HitTestInfo::Shutdown();
377 CacheObserver::Shutdown();
379 PromiseDebugging::Shutdown();
381 BlobURLProtocolHandler::RemoveDataEntries();
383 css::ImageLoader::Shutdown();
385 mozilla::net::UrlClassifierFeatureFactory::Shutdown();
387 RestoreTabContentObserver::Shutdown();
389 mozilla::intl::LineBreakCache::Shutdown();