Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/layout/build/nsLayoutStatics.cpp
Line
Count
Source (jump to first uncovered line)
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/. */
6
7
#include "base/basictypes.h"
8
9
#include "nsLayoutStatics.h"
10
#include "nscore.h"
11
12
#include "DateTimeFormat.h"
13
#include "nsAttrValue.h"
14
#include "nsColorNames.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 "nsCSSKeywords.h"
21
#include "nsCSSProps.h"
22
#include "nsCSSPseudoElements.h"
23
#include "nsCSSRendering.h"
24
#include "nsGenericHTMLFrameElement.h"
25
#include "mozilla/dom/Attr.h"
26
#include "mozilla/EventListenerManager.h"
27
#include "nsFrame.h"
28
#include "nsGlobalWindow.h"
29
#include "nsGkAtoms.h"
30
#include "nsImageFrame.h"
31
#include "nsLayoutStylesheetCache.h"
32
#include "nsRange.h"
33
#include "nsRegion.h"
34
#include "nsRepeatService.h"
35
#include "nsFloatManager.h"
36
#include "nsSprocketLayout.h"
37
#include "nsStackLayout.h"
38
#include "nsTextControlFrame.h"
39
#include "nsXBLService.h"
40
#include "txMozillaXSLTProcessor.h"
41
#include "nsTreeSanitizer.h"
42
#include "nsCellMap.h"
43
#include "nsTextFrame.h"
44
#include "nsCCUncollectableMarker.h"
45
#include "nsTextFragment.h"
46
#include "nsMediaFeatures.h"
47
#include "nsCORSListenerProxy.h"
48
#include "nsHTMLDNSPrefetch.h"
49
#include "nsHtml5Module.h"
50
#include "nsHTMLTags.h"
51
#include "mozilla/dom/FallbackEncoding.h"
52
#include "nsFocusManager.h"
53
#include "nsListControlFrame.h"
54
#include "mozilla/dom/HTMLInputElement.h"
55
#include "SVGElementFactory.h"
56
#include "nsSVGUtils.h"
57
#include "nsMathMLAtoms.h"
58
#include "nsMathMLOperators.h"
59
#include "Navigator.h"
60
#include "StorageObserver.h"
61
#include "CacheObserver.h"
62
#include "DisplayItemClip.h"
63
#include "ActiveLayerTracker.h"
64
#include "FrameLayerBuilder.h"
65
#include "AnimationCommon.h"
66
#include "LayerAnimationInfo.h"
67
68
#include "AudioChannelService.h"
69
#include "mozilla/dom/PromiseDebugging.h"
70
#include "mozilla/dom/WebCryptoThreadPool.h"
71
72
#ifdef MOZ_XUL
73
#include "nsXULPopupManager.h"
74
#include "nsXULContentUtils.h"
75
#include "nsXULPrototypeCache.h"
76
#include "nsXULTooltipListener.h"
77
78
#include "nsMenuBarListener.h"
79
#endif
80
81
#include "CubebUtils.h"
82
#include "Latency.h"
83
#include "WebAudioUtils.h"
84
85
#include "nsError.h"
86
87
#include "nsJSEnvironment.h"
88
#include "nsContentSink.h"
89
#include "nsFrameMessageManager.h"
90
#include "nsDOMMutationObserver.h"
91
#include "nsHyphenationManager.h"
92
#include "nsWindowMemoryReporter.h"
93
#include "mozilla/dom/ContentParent.h"
94
#include "mozilla/ProcessPriorityManager.h"
95
#include "nsPermissionManager.h"
96
#include "nsCookieService.h"
97
#include "nsApplicationCacheService.h"
98
#include "mozilla/dom/CustomElementRegistry.h"
99
#include "mozilla/EventDispatcher.h"
100
#include "mozilla/IMEStateManager.h"
101
#include "mozilla/dom/HTMLVideoElement.h"
102
#include "TouchManager.h"
103
#include "DecoderDoctorLogger.h"
104
#include "MediaDecoder.h"
105
#include "mozilla/ClearSiteData.h"
106
#include "mozilla/ServoBindings.h"
107
#include "mozilla/StaticPresData.h"
108
#include "mozilla/dom/WebIDLGlobalNameHash.h"
109
#include "mozilla/dom/ipc/IPCBlobInputStreamStorage.h"
110
#include "mozilla/dom/U2FTokenManager.h"
111
#include "mozilla/dom/PointerEventHandler.h"
112
#include "mozilla/dom/BlobURLProtocolHandler.h"
113
#include "nsThreadManager.h"
114
115
using namespace mozilla;
116
using namespace mozilla::net;
117
using namespace mozilla::dom;
118
using namespace mozilla::dom::ipc;
119
120
nsrefcnt nsLayoutStatics::sLayoutStaticRefcnt = 0;
121
122
nsresult
123
nsLayoutStatics::Initialize()
124
3
{
125
3
  NS_ASSERTION(sLayoutStaticRefcnt == 0,
126
3
               "nsLayoutStatics isn't zero!");
127
3
128
3
  sLayoutStaticRefcnt = 1;
129
3
  NS_LOG_ADDREF(&sLayoutStaticRefcnt, sLayoutStaticRefcnt,
130
3
                "nsLayoutStatics", 1);
131
3
132
3
  nsresult rv;
133
3
134
3
  ContentParent::StartUp();
135
3
136
3
  nsCSSKeywords::AddRefTable();
137
3
  nsCSSProps::AddRefTable();
138
3
  nsColorNames::AddRefTable();
139
3
140
#ifdef DEBUG
141
  nsCSSPseudoElements::AssertAtoms();
142
  nsCSSAnonBoxes::AssertAtoms();
143
#endif
144
145
3
  StartupJSEnvironment();
146
3
  nsJSContext::EnsureStatics();
147
3
148
3
  nsGlobalWindowInner::Init();
149
3
  nsGlobalWindowOuter::Init();
150
3
  Navigator::Init();
151
3
  nsXBLService::Init();
152
3
153
3
  rv = nsContentUtils::Init();
154
3
  if (NS_FAILED(rv)) {
155
0
    NS_ERROR("Could not initialize nsContentUtils");
156
0
    return rv;
157
0
  }
158
3
159
3
  rv = nsAttrValue::Init();
160
3
  if (NS_FAILED(rv)) {
161
0
    NS_ERROR("Could not initialize nsAttrValue");
162
0
    return rv;
163
0
  }
164
3
165
3
  rv = nsTextFragment::Init();
166
3
  if (NS_FAILED(rv)) {
167
0
    NS_ERROR("Could not initialize nsTextFragment");
168
0
    return rv;
169
0
  }
170
3
171
3
  nsCellMap::Init();
172
3
173
3
  mozilla::SharedFontList::Initialize();
174
3
  StaticPresData::Init();
175
3
  nsCSSRendering::Init();
176
3
177
3
  rv = nsHTMLDNSPrefetch::Initialize();
178
3
  if (NS_FAILED(rv)) {
179
0
    NS_ERROR("Could not initialize HTML DNS prefetch");
180
0
    return rv;
181
0
  }
182
3
183
3
  nsMathMLOperators::AddRefTable();
184
3
185
#ifdef DEBUG
186
  nsFrame::DisplayReflowStartup();
187
#endif
188
  Attr::Initialize();
189
3
190
3
  rv = txMozillaXSLTProcessor::Startup();
191
3
  if (NS_FAILED(rv)) {
192
0
    NS_ERROR("Could not initialize txMozillaXSLTProcessor");
193
0
    return rv;
194
0
  }
195
3
196
3
  rv = StorageObserver::Init();
197
3
  if (NS_FAILED(rv)) {
198
0
    NS_ERROR("Could not initialize StorageObserver");
199
0
    return rv;
200
0
  }
201
3
202
3
  rv = nsCCUncollectableMarker::Init();
203
3
  if (NS_FAILED(rv)) {
204
0
    NS_ERROR("Could not initialize nsCCUncollectableMarker");
205
0
    return rv;
206
0
  }
207
3
208
3
#ifdef MOZ_XUL
209
3
  rv = nsXULPopupManager::Init();
210
3
  if (NS_FAILED(rv)) {
211
0
    NS_ERROR("Could not initialize nsXULPopupManager");
212
0
    return rv;
213
0
  }
214
3
#endif
215
3
216
3
  rv = nsFocusManager::Init();
217
3
  if (NS_FAILED(rv)) {
218
0
    NS_ERROR("Could not initialize nsFocusManager");
219
0
    return rv;
220
0
  }
221
3
222
3
  AsyncLatencyLogger::InitializeStatics();
223
3
  DecoderDoctorLogger::Init();
224
3
  MediaManager::StartupInit();
225
3
  CubebUtils::InitLibrary();
226
3
227
3
  nsContentSink::InitializeStatics();
228
3
  nsHtml5Module::InitializeStatics();
229
3
  mozilla::dom::FallbackEncoding::Initialize();
230
3
  nsLayoutUtils::Initialize();
231
3
  PointerEventHandler::InitializeStatics();
232
3
  TouchManager::InitializeStatics();
233
3
234
3
  nsCORSListenerProxy::Startup();
235
3
236
3
  nsWindowMemoryReporter::Init();
237
3
238
3
  SVGElementFactory::Init();
239
3
  nsSVGUtils::Init();
240
3
241
3
  ProcessPriorityManager::Init();
242
3
243
3
  nsPermissionManager::ClearOriginDataObserverInit();
244
3
  nsCookieService::AppClearDataObserverInit();
245
3
  nsApplicationCacheService::AppClearDataObserverInit();
246
3
247
3
  HTMLVideoElement::Init();
248
3
  nsGenericHTMLFrameElement::InitStatics();
249
3
250
3
#ifdef MOZ_XUL
251
3
  nsMenuBarListener::InitializeStatics();
252
3
#endif
253
3
254
3
  CacheObserver::Init();
255
3
256
3
  IMEStateManager::Init();
257
3
258
3
  ServiceWorkerRegistrar::Initialize();
259
3
260
#ifdef DEBUG
261
  mozilla::LayerAnimationInfo::Initialize();
262
#endif
263
264
3
  MediaDecoder::InitStatics();
265
3
266
3
  PromiseDebugging::Init();
267
3
268
3
  mozilla::dom::WebCryptoThreadPool::Initialize();
269
3
270
3
  if (XRE_IsParentProcess() || XRE_IsContentProcess()) {
271
3
    InitializeServo();
272
3
  }
273
3
274
3
  // This must be initialized on the main-thread.
275
3
  mozilla::dom::IPCBlobInputStreamStorage::Initialize();
276
3
277
3
  mozilla::dom::U2FTokenManager::Initialize();
278
3
279
3
  if (XRE_IsParentProcess()) {
280
3
    // On content process we initialize DOMPrefs when PContentChild is fully
281
3
    // initialized.
282
3
    mozilla::dom::DOMPrefs::Initialize();
283
3
  }
284
3
285
3
  nsThreadManager::InitializeShutdownObserver();
286
3
287
3
  ClearSiteData::Initialize();
288
3
289
3
  return NS_OK;
290
3
}
291
292
void
293
nsLayoutStatics::Shutdown()
294
0
{
295
0
  // Don't need to shutdown nsWindowMemoryReporter, that will be done by the
296
0
  // memory reporter manager.
297
0
298
0
  if (XRE_IsParentProcess() || XRE_IsContentProcess()) {
299
0
    ShutdownServo();
300
0
    URLExtraData::ReleaseDummy();
301
0
  }
302
0
303
0
  nsMessageManagerScriptExecutor::Shutdown();
304
0
  nsFocusManager::Shutdown();
305
0
#ifdef MOZ_XUL
306
0
  nsXULPopupManager::Shutdown();
307
0
#endif
308
0
  StorageObserver::Shutdown();
309
0
  txMozillaXSLTProcessor::Shutdown();
310
0
  Attr::Shutdown();
311
0
  EventListenerManager::Shutdown();
312
0
  IMEStateManager::Shutdown();
313
0
  nsMediaFeatures::Shutdown();
314
0
  nsHTMLDNSPrefetch::Shutdown();
315
0
  nsCSSRendering::Shutdown();
316
0
  StaticPresData::Shutdown();
317
#ifdef DEBUG
318
  nsFrame::DisplayReflowShutdown();
319
#endif
320
  nsCellMap::Shutdown();
321
0
  ActiveLayerTracker::Shutdown();
322
0
323
0
  // Release all of our atoms
324
0
  nsColorNames::ReleaseTable();
325
0
  nsCSSProps::ReleaseTable();
326
0
  nsCSSKeywords::ReleaseTable();
327
0
  nsRepeatService::Shutdown();
328
0
  nsStackLayout::Shutdown();
329
0
  nsBox::Shutdown();
330
0
331
0
#ifdef MOZ_XUL
332
0
  nsXULContentUtils::Finish();
333
0
  nsXULPrototypeCache::ReleaseGlobals();
334
0
  nsSprocketLayout::Shutdown();
335
0
#endif
336
0
337
0
  SVGElementFactory::Shutdown();
338
0
  nsMathMLOperators::ReleaseTable();
339
0
340
0
  nsFloatManager::Shutdown();
341
0
  nsImageFrame::ReleaseGlobals();
342
0
343
0
  mozilla::css::ErrorReporter::ReleaseGlobals();
344
0
345
0
  nsTextFragment::Shutdown();
346
0
347
0
  nsAttrValue::Shutdown();
348
0
  nsContentUtils::Shutdown();
349
0
  nsLayoutStylesheetCache::Shutdown();
350
0
351
0
  ShutdownJSEnvironment();
352
0
  nsGlobalWindowInner::ShutDown();
353
0
  nsGlobalWindowOuter::ShutDown();
354
0
  WebIDLGlobalNameHash::Shutdown();
355
0
  nsListControlFrame::Shutdown();
356
0
  nsXBLService::Shutdown();
357
0
  FrameLayerBuilder::Shutdown();
358
0
359
0
  CubebUtils::ShutdownLibrary();
360
0
  AsyncLatencyLogger::ShutdownLogger();
361
0
  WebAudioUtils::Shutdown();
362
0
363
0
  nsCORSListenerProxy::Shutdown();
364
0
365
0
  PointerEventHandler::ReleaseStatics();
366
0
367
0
  TouchManager::ReleaseStatics();
368
0
369
0
  nsTreeSanitizer::ReleaseStatics();
370
0
371
0
  nsHtml5Module::ReleaseStatics();
372
0
373
0
  mozilla::dom::FallbackEncoding::Shutdown();
374
0
375
0
  mozilla::EventDispatcher::Shutdown();
376
0
377
0
  HTMLInputElement::DestroyUploadLastDir();
378
0
379
0
  nsLayoutUtils::Shutdown();
380
0
  mozilla::SharedFontList::Shutdown();
381
0
382
0
  nsHyphenationManager::Shutdown();
383
0
  nsDOMMutationObserver::Shutdown();
384
0
385
0
  DateTimeFormat::Shutdown();
386
0
387
0
  ContentParent::ShutDown();
388
0
389
0
  DisplayItemClip::Shutdown();
390
0
391
0
  CacheObserver::Shutdown();
392
0
393
0
  PromiseDebugging::Shutdown();
394
0
395
0
  BlobURLProtocolHandler::RemoveDataEntries();
396
0
}