Line data Source code
1 : /* This Source Code Form is subject to the terms of the Mozilla Public
2 : * License, v. 2.0. If a copy of the MPL was not distributed with this
3 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 :
5 : #include "base/basictypes.h"
6 :
7 : #include "nsLayoutStatics.h"
8 : #include "nscore.h"
9 :
10 : #include "DateTimeFormat.h"
11 : #include "nsAttrValue.h"
12 : #include "nsAutoCopyListener.h"
13 : #include "nsColorNames.h"
14 : #include "nsComputedDOMStyle.h"
15 : #include "nsContentDLF.h"
16 : #include "nsContentUtils.h"
17 : #include "nsCSSAnonBoxes.h"
18 : #include "mozilla/css/ErrorReporter.h"
19 : #include "nsCSSKeywords.h"
20 : #include "nsCSSParser.h"
21 : #include "nsCSSProps.h"
22 : #include "nsCSSPseudoClasses.h"
23 : #include "nsCSSPseudoElements.h"
24 : #include "nsCSSRendering.h"
25 : #include "nsGenericHTMLFrameElement.h"
26 : #include "mozilla/dom/Attr.h"
27 : #include "nsDOMClassInfo.h"
28 : #include "mozilla/EventListenerManager.h"
29 : #include "nsFrame.h"
30 : #include "nsGlobalWindow.h"
31 : #include "nsGkAtoms.h"
32 : #include "nsImageFrame.h"
33 : #include "nsLayoutStylesheetCache.h"
34 : #include "mozilla/RuleProcessorCache.h"
35 : #include "ContentPrincipal.h"
36 : #include "nsRange.h"
37 : #include "nsRegion.h"
38 : #include "nsRepeatService.h"
39 : #include "nsFloatManager.h"
40 : #include "nsSprocketLayout.h"
41 : #include "nsStackLayout.h"
42 : #include "nsStyleSet.h"
43 : #include "nsTextControlFrame.h"
44 : #include "nsXBLService.h"
45 : #include "txMozillaXSLTProcessor.h"
46 : #include "nsTreeSanitizer.h"
47 : #include "nsCellMap.h"
48 : #include "nsTextFrame.h"
49 : #include "nsCCUncollectableMarker.h"
50 : #include "nsTextFragment.h"
51 : #include "nsCSSRuleProcessor.h"
52 : #include "nsCORSListenerProxy.h"
53 : #include "nsHTMLDNSPrefetch.h"
54 : #include "nsHtml5Module.h"
55 : #include "nsHTMLTags.h"
56 : #include "nsIRDFContentSink.h" // for RDF atom initialization
57 : #include "mozilla/dom/FallbackEncoding.h"
58 : #include "nsFocusManager.h"
59 : #include "nsListControlFrame.h"
60 : #include "mozilla/dom/HTMLInputElement.h"
61 : #include "SVGElementFactory.h"
62 : #include "nsSVGUtils.h"
63 : #include "nsMathMLAtoms.h"
64 : #include "nsMathMLOperators.h"
65 : #include "Navigator.h"
66 : #include "StorageObserver.h"
67 : #include "CacheObserver.h"
68 : #include "DisplayItemClip.h"
69 : #include "ActiveLayerTracker.h"
70 : #include "CounterStyleManager.h"
71 : #include "FrameLayerBuilder.h"
72 : #include "AnimationCommon.h"
73 : #include "LayerAnimationInfo.h"
74 :
75 : #include "AudioChannelService.h"
76 : #include "mozilla/dom/PromiseDebugging.h"
77 : #include "mozilla/dom/WebCryptoThreadPool.h"
78 :
79 : #ifdef MOZ_XUL
80 : #include "nsXULPopupManager.h"
81 : #include "nsXULContentUtils.h"
82 : #include "nsXULPrototypeCache.h"
83 : #include "nsXULTooltipListener.h"
84 :
85 : #include "inDOMView.h"
86 :
87 : #include "nsMenuBarListener.h"
88 : #endif
89 :
90 : #include "nsTextServicesDocument.h"
91 :
92 : #ifdef MOZ_WEBSPEECH
93 : #include "nsSynthVoiceRegistry.h"
94 : #endif
95 :
96 : #ifdef MOZ_ANDROID_OMX
97 : #include "AndroidMediaPluginHost.h"
98 : #endif
99 :
100 : #include "CubebUtils.h"
101 : #include "Latency.h"
102 : #include "WebAudioUtils.h"
103 :
104 : #include "nsError.h"
105 :
106 : #include "nsJSEnvironment.h"
107 : #include "nsContentSink.h"
108 : #include "nsFrameMessageManager.h"
109 : #include "nsDOMMutationObserver.h"
110 : #include "nsHyphenationManager.h"
111 : #include "nsEditorSpellCheck.h"
112 : #include "nsWindowMemoryReporter.h"
113 : #include "mozilla/dom/ContentParent.h"
114 : #include "mozilla/ProcessPriorityManager.h"
115 : #include "nsPermissionManager.h"
116 : #include "nsCookieService.h"
117 : #include "nsApplicationCacheService.h"
118 : #include "mozilla/dom/CustomElementRegistry.h"
119 : #include "mozilla/dom/time/DateCacheCleaner.h"
120 : #include "mozilla/EventDispatcher.h"
121 : #include "mozilla/IMEStateManager.h"
122 : #include "mozilla/dom/HTMLVideoElement.h"
123 : #include "TouchManager.h"
124 : #include "MediaDecoder.h"
125 : #include "MediaPrefs.h"
126 : #include "mozilla/ServoBindings.h"
127 : #include "mozilla/StaticPresData.h"
128 : #include "mozilla/dom/WebIDLGlobalNameHash.h"
129 : #include "mozilla/dom/ipc/IPCBlobInputStreamStorage.h"
130 : #include "mozilla/dom/U2FTokenManager.h"
131 :
132 : using namespace mozilla;
133 : using namespace mozilla::net;
134 : using namespace mozilla::dom;
135 : using namespace mozilla::dom::ipc;
136 :
137 : nsrefcnt nsLayoutStatics::sLayoutStaticRefcnt = 0;
138 :
139 : nsresult
140 3 : nsLayoutStatics::Initialize()
141 : {
142 3 : NS_ASSERTION(sLayoutStaticRefcnt == 0,
143 : "nsLayoutStatics isn't zero!");
144 :
145 3 : sLayoutStaticRefcnt = 1;
146 : NS_LOG_ADDREF(&sLayoutStaticRefcnt, sLayoutStaticRefcnt,
147 3 : "nsLayoutStatics", 1);
148 :
149 : nsresult rv;
150 :
151 3 : ContentParent::StartUp();
152 :
153 : // Register all of our atoms once
154 3 : nsCSSAnonBoxes::AddRefAtoms();
155 3 : nsCSSPseudoClasses::AddRefAtoms();
156 3 : nsCSSPseudoElements::AddRefAtoms();
157 3 : nsCSSKeywords::AddRefTable();
158 3 : nsCSSProps::AddRefTable();
159 3 : nsColorNames::AddRefTable();
160 3 : nsGkAtoms::AddRefAtoms();
161 3 : nsTextServicesDocument::RegisterAtoms();
162 3 : nsHTMLTags::RegisterAtoms();
163 3 : nsRDFAtoms::RegisterAtoms();
164 :
165 3 : NS_SealStaticAtomTable();
166 :
167 3 : StartupJSEnvironment();
168 3 : rv = nsRegion::InitStatic();
169 3 : if (NS_FAILED(rv)) {
170 0 : NS_ERROR("Could not initialize nsRegion");
171 0 : return rv;
172 : }
173 :
174 3 : nsGlobalWindow::Init();
175 3 : Navigator::Init();
176 3 : nsXBLService::Init();
177 :
178 3 : rv = nsContentUtils::Init();
179 3 : if (NS_FAILED(rv)) {
180 0 : NS_ERROR("Could not initialize nsContentUtils");
181 0 : return rv;
182 : }
183 :
184 3 : rv = nsAttrValue::Init();
185 3 : if (NS_FAILED(rv)) {
186 0 : NS_ERROR("Could not initialize nsAttrValue");
187 0 : return rv;
188 : }
189 :
190 3 : rv = nsTextFragment::Init();
191 3 : if (NS_FAILED(rv)) {
192 0 : NS_ERROR("Could not initialize nsTextFragment");
193 0 : return rv;
194 : }
195 :
196 3 : nsCellMap::Init();
197 :
198 3 : StaticPresData::Init();
199 3 : nsCSSRendering::Init();
200 :
201 3 : rv = nsHTMLDNSPrefetch::Initialize();
202 3 : if (NS_FAILED(rv)) {
203 0 : NS_ERROR("Could not initialize HTML DNS prefetch");
204 0 : return rv;
205 : }
206 :
207 : #ifdef MOZ_XUL
208 3 : rv = nsXULContentUtils::Init();
209 3 : if (NS_FAILED(rv)) {
210 0 : NS_ERROR("Could not initialize nsXULContentUtils");
211 0 : return rv;
212 : }
213 :
214 : #endif
215 :
216 3 : nsMathMLOperators::AddRefTable();
217 :
218 : #ifdef DEBUG
219 3 : nsFrame::DisplayReflowStartup();
220 : #endif
221 3 : Attr::Initialize();
222 :
223 3 : rv = txMozillaXSLTProcessor::Startup();
224 3 : if (NS_FAILED(rv)) {
225 0 : NS_ERROR("Could not initialize txMozillaXSLTProcessor");
226 0 : return rv;
227 : }
228 :
229 3 : rv = StorageObserver::Init();
230 3 : if (NS_FAILED(rv)) {
231 0 : NS_ERROR("Could not initialize StorageObserver");
232 0 : return rv;
233 : }
234 :
235 3 : rv = nsCCUncollectableMarker::Init();
236 3 : if (NS_FAILED(rv)) {
237 0 : NS_ERROR("Could not initialize nsCCUncollectableMarker");
238 0 : return rv;
239 : }
240 :
241 3 : nsCSSParser::Startup();
242 3 : nsCSSRuleProcessor::Startup();
243 :
244 : #ifdef MOZ_XUL
245 3 : rv = nsXULPopupManager::Init();
246 3 : if (NS_FAILED(rv)) {
247 0 : NS_ERROR("Could not initialize nsXULPopupManager");
248 0 : return rv;
249 : }
250 : #endif
251 :
252 3 : rv = nsFocusManager::Init();
253 3 : if (NS_FAILED(rv)) {
254 0 : NS_ERROR("Could not initialize nsFocusManager");
255 0 : return rv;
256 : }
257 :
258 3 : AsyncLatencyLogger::InitializeStatics();
259 3 : MediaManager::StartupInit();
260 3 : CubebUtils::InitLibrary();
261 :
262 3 : nsContentSink::InitializeStatics();
263 3 : nsHtml5Module::InitializeStatics();
264 3 : mozilla::dom::FallbackEncoding::Initialize();
265 3 : nsLayoutUtils::Initialize();
266 3 : nsIPresShell::InitializeStatics();
267 3 : TouchManager::InitializeStatics();
268 3 : ContentPrincipal::InitializeStatics();
269 :
270 3 : nsCORSListenerProxy::Startup();
271 :
272 3 : nsWindowMemoryReporter::Init();
273 :
274 3 : SVGElementFactory::Init();
275 3 : nsSVGUtils::Init();
276 :
277 3 : ProcessPriorityManager::Init();
278 :
279 3 : nsPermissionManager::ClearOriginDataObserverInit();
280 3 : nsCookieService::AppClearDataObserverInit();
281 3 : nsApplicationCacheService::AppClearDataObserverInit();
282 :
283 3 : HTMLVideoElement::Init();
284 3 : nsGenericHTMLFrameElement::InitStatics();
285 :
286 : #ifdef MOZ_XUL
287 3 : nsMenuBarListener::InitializeStatics();
288 : #endif
289 :
290 3 : CacheObserver::Init();
291 :
292 3 : CounterStyleManager::InitializeBuiltinCounterStyles();
293 :
294 3 : IMEStateManager::Init();
295 :
296 3 : ServiceWorkerRegistrar::Initialize();
297 :
298 : #ifdef DEBUG
299 3 : nsStyleContext::Initialize();
300 3 : mozilla::LayerAnimationInfo::Initialize();
301 : #endif
302 :
303 3 : MediaDecoder::InitStatics();
304 :
305 3 : PromiseDebugging::Init();
306 :
307 3 : mozilla::dom::WebCryptoThreadPool::Initialize();
308 :
309 : #ifdef MOZ_STYLO
310 : InitializeServo();
311 : #endif
312 :
313 : #ifndef MOZ_WIDGET_ANDROID
314 : // On Android, we instantiate it when constructing AndroidBridge.
315 3 : MediaPrefs::GetSingleton();
316 : #endif
317 :
318 : // This must be initialized on the main-thread.
319 3 : mozilla::dom::IPCBlobInputStreamStorage::Initialize();
320 :
321 3 : mozilla::dom::U2FTokenManager::Initialize();
322 3 : return NS_OK;
323 : }
324 :
325 : void
326 0 : nsLayoutStatics::Shutdown()
327 : {
328 : // Don't need to shutdown nsWindowMemoryReporter, that will be done by the
329 : // memory reporter manager.
330 :
331 : #ifdef MOZ_STYLO
332 : ShutdownServo();
333 : URLExtraData::ReleaseDummy();
334 : #endif
335 :
336 0 : nsMessageManagerScriptExecutor::Shutdown();
337 0 : nsFocusManager::Shutdown();
338 : #ifdef MOZ_XUL
339 0 : nsXULPopupManager::Shutdown();
340 : #endif
341 0 : StorageObserver::Shutdown();
342 0 : txMozillaXSLTProcessor::Shutdown();
343 0 : Attr::Shutdown();
344 0 : EventListenerManager::Shutdown();
345 0 : IMEStateManager::Shutdown();
346 0 : nsCSSParser::Shutdown();
347 0 : nsCSSRuleProcessor::Shutdown();
348 0 : nsHTMLDNSPrefetch::Shutdown();
349 0 : nsCSSRendering::Shutdown();
350 0 : StaticPresData::Shutdown();
351 : #ifdef DEBUG
352 0 : nsFrame::DisplayReflowShutdown();
353 : #endif
354 0 : nsCellMap::Shutdown();
355 0 : ActiveLayerTracker::Shutdown();
356 :
357 : // Release all of our atoms
358 0 : nsColorNames::ReleaseTable();
359 0 : nsCSSProps::ReleaseTable();
360 0 : nsCSSKeywords::ReleaseTable();
361 0 : nsRepeatService::Shutdown();
362 0 : nsStackLayout::Shutdown();
363 0 : nsBox::Shutdown();
364 :
365 : #ifdef MOZ_XUL
366 0 : nsXULContentUtils::Finish();
367 0 : nsXULPrototypeCache::ReleaseGlobals();
368 0 : nsSprocketLayout::Shutdown();
369 : #endif
370 :
371 0 : SVGElementFactory::Shutdown();
372 0 : nsMathMLOperators::ReleaseTable();
373 :
374 0 : nsFloatManager::Shutdown();
375 0 : nsImageFrame::ReleaseGlobals();
376 :
377 0 : mozilla::css::ErrorReporter::ReleaseGlobals();
378 :
379 0 : nsTextFragment::Shutdown();
380 :
381 0 : nsAttrValue::Shutdown();
382 0 : nsContentUtils::Shutdown();
383 0 : nsLayoutStylesheetCache::Shutdown();
384 0 : RuleProcessorCache::Shutdown();
385 :
386 0 : ShutdownJSEnvironment();
387 0 : nsGlobalWindow::ShutDown();
388 0 : nsDOMClassInfo::ShutDown();
389 0 : WebIDLGlobalNameHash::Shutdown();
390 0 : nsListControlFrame::Shutdown();
391 0 : nsXBLService::Shutdown();
392 0 : nsAutoCopyListener::Shutdown();
393 0 : FrameLayerBuilder::Shutdown();
394 :
395 :
396 : #ifdef MOZ_ANDROID_OMX
397 : AndroidMediaPluginHost::Shutdown();
398 : #endif
399 :
400 0 : CubebUtils::ShutdownLibrary();
401 0 : AsyncLatencyLogger::ShutdownLogger();
402 0 : WebAudioUtils::Shutdown();
403 :
404 : #ifdef MOZ_WEBSPEECH
405 0 : nsSynthVoiceRegistry::Shutdown();
406 : #endif
407 :
408 0 : nsCORSListenerProxy::Shutdown();
409 :
410 0 : nsIPresShell::ReleaseStatics();
411 :
412 0 : TouchManager::ReleaseStatics();
413 :
414 0 : nsTreeSanitizer::ReleaseStatics();
415 :
416 0 : nsHtml5Module::ReleaseStatics();
417 :
418 0 : mozilla::dom::FallbackEncoding::Shutdown();
419 :
420 0 : nsRegion::ShutdownStatic();
421 :
422 0 : mozilla::EventDispatcher::Shutdown();
423 :
424 0 : HTMLInputElement::DestroyUploadLastDir();
425 :
426 0 : nsLayoutUtils::Shutdown();
427 :
428 0 : nsHyphenationManager::Shutdown();
429 0 : nsDOMMutationObserver::Shutdown();
430 :
431 0 : DateTimeFormat::Shutdown();
432 :
433 0 : ContentParent::ShutDown();
434 :
435 0 : DisplayItemClip::Shutdown();
436 :
437 0 : CustomElementRegistry::XPCOMShutdown();
438 :
439 0 : CacheObserver::Shutdown();
440 :
441 0 : PromiseDebugging::Shutdown();
442 0 : }
|