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