nsLayoutStatics.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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. #include "base/basictypes.h"
  5. #include "nsLayoutStatics.h"
  6. #include "nscore.h"
  7. #include "nsAttrValue.h"
  8. #include "nsAutoCopyListener.h"
  9. #include "nsColorNames.h"
  10. #include "nsComputedDOMStyle.h"
  11. #include "nsContentDLF.h"
  12. #include "nsContentUtils.h"
  13. #include "nsCSSAnonBoxes.h"
  14. #include "mozilla/css/ErrorReporter.h"
  15. #include "nsCSSKeywords.h"
  16. #include "nsCSSParser.h"
  17. #include "nsCSSProps.h"
  18. #include "nsCSSPseudoClasses.h"
  19. #include "nsCSSPseudoElements.h"
  20. #include "nsCSSRendering.h"
  21. #include "mozilla/dom/Attr.h"
  22. #include "nsDOMClassInfo.h"
  23. #include "mozilla/EventListenerManager.h"
  24. #include "nsFrame.h"
  25. #include "nsGlobalWindow.h"
  26. #include "nsGkAtoms.h"
  27. #include "nsImageFrame.h"
  28. #include "nsLayoutStylesheetCache.h"
  29. #include "mozilla/RuleProcessorCache.h"
  30. #include "nsPrincipal.h"
  31. #include "nsRange.h"
  32. #include "nsRegion.h"
  33. #include "nsRepeatService.h"
  34. #include "nsFloatManager.h"
  35. #include "nsSprocketLayout.h"
  36. #include "nsStackLayout.h"
  37. #include "nsStyleSet.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 "nsCSSRuleProcessor.h"
  47. #include "nsCORSListenerProxy.h"
  48. #include "nsHTMLDNSPrefetch.h"
  49. #include "nsHtml5Atoms.h"
  50. #include "nsHtml5Module.h"
  51. #include "nsHTMLTags.h"
  52. #include "nsIRDFContentSink.h" // for RDF atom initialization
  53. #include "mozilla/dom/FallbackEncoding.h"
  54. #include "nsFocusManager.h"
  55. #include "nsListControlFrame.h"
  56. #include "mozilla/dom/HTMLInputElement.h"
  57. #include "SVGElementFactory.h"
  58. #include "nsSVGUtils.h"
  59. #include "nsMathMLAtoms.h"
  60. #include "nsMathMLOperators.h"
  61. #include "Navigator.h"
  62. #include "DOMStorageObserver.h"
  63. #include "CacheObserver.h"
  64. #include "DisplayItemClip.h"
  65. #include "ActiveLayerTracker.h"
  66. #include "CounterStyleManager.h"
  67. #include "FrameLayerBuilder.h"
  68. #include "AnimationCommon.h"
  69. #include "LayerAnimationInfo.h"
  70. #include "AudioChannelService.h"
  71. #include "mozilla/dom/PromiseDebugging.h"
  72. #include "mozilla/dom/WebCryptoThreadPool.h"
  73. #ifdef MOZ_XUL
  74. #include "nsXULPopupManager.h"
  75. #include "nsXULContentUtils.h"
  76. #include "nsXULPrototypeCache.h"
  77. #include "nsXULTooltipListener.h"
  78. #include "inDOMView.h"
  79. #include "nsMenuBarListener.h"
  80. #endif
  81. #include "nsTextServicesDocument.h"
  82. #ifdef MOZ_WEBSPEECH
  83. #include "nsSynthVoiceRegistry.h"
  84. #endif
  85. #include "CubebUtils.h"
  86. #include "Latency.h"
  87. #include "WebAudioUtils.h"
  88. #include "nsError.h"
  89. #include "nsJSEnvironment.h"
  90. #include "nsContentSink.h"
  91. #include "nsFrameMessageManager.h"
  92. #include "nsDOMMutationObserver.h"
  93. #include "nsHyphenationManager.h"
  94. #include "nsEditorSpellCheck.h"
  95. #include "nsWindowMemoryReporter.h"
  96. #include "mozilla/dom/ContentParent.h"
  97. #include "mozilla/ProcessPriorityManager.h"
  98. #include "nsPermissionManager.h"
  99. #include "nsCookieService.h"
  100. #include "nsApplicationCacheService.h"
  101. #include "mozilla/dom/CustomElementRegistry.h"
  102. #include "mozilla/dom/time/DateCacheCleaner.h"
  103. #include "mozilla/dom/workers/ServiceWorkerManager.h"
  104. #include "mozilla/EventDispatcher.h"
  105. #include "mozilla/IMEStateManager.h"
  106. #include "mozilla/dom/HTMLVideoElement.h"
  107. #include "TouchManager.h"
  108. #include "MediaDecoder.h"
  109. #include "MediaManager.h"
  110. #include "MediaPrefs.h"
  111. #include "mozilla/ServoBindings.h"
  112. #include "mozilla/StaticPresData.h"
  113. #include "mozilla/dom/WebIDLGlobalNameHash.h"
  114. #ifdef MOZ_WIDGET_GTK
  115. #include "nsNativeMenuAtoms.h"
  116. #endif
  117. using namespace mozilla;
  118. using namespace mozilla::net;
  119. using namespace mozilla::dom;
  120. using namespace mozilla::dom::ipc;
  121. nsrefcnt nsLayoutStatics::sLayoutStaticRefcnt = 0;
  122. nsresult
  123. nsLayoutStatics::Initialize()
  124. {
  125. NS_ASSERTION(sLayoutStaticRefcnt == 0,
  126. "nsLayoutStatics isn't zero!");
  127. sLayoutStaticRefcnt = 1;
  128. NS_LOG_ADDREF(&sLayoutStaticRefcnt, sLayoutStaticRefcnt,
  129. "nsLayoutStatics", 1);
  130. nsresult rv;
  131. ContentParent::StartUp();
  132. // Register all of our atoms once
  133. nsCSSAnonBoxes::AddRefAtoms();
  134. nsCSSPseudoClasses::AddRefAtoms();
  135. nsCSSPseudoElements::AddRefAtoms();
  136. nsCSSKeywords::AddRefTable();
  137. nsCSSProps::AddRefAtoms();
  138. nsCSSProps::AddRefTable();
  139. nsColorNames::AddRefTable();
  140. nsGkAtoms::AddRefAtoms();
  141. nsHtml5Atoms::AddRefAtoms();
  142. nsTextServicesDocument::RegisterAtoms();
  143. nsHTMLTags::RegisterAtoms();
  144. nsRDFAtoms::RegisterAtoms();
  145. #ifdef MOZ_WIDGET_GTK
  146. nsNativeMenuAtoms::RegisterAtoms();
  147. #endif
  148. NS_SealStaticAtomTable();
  149. StartupJSEnvironment();
  150. rv = nsRegion::InitStatic();
  151. if (NS_FAILED(rv)) {
  152. NS_ERROR("Could not initialize nsRegion");
  153. return rv;
  154. }
  155. nsGlobalWindow::Init();
  156. Navigator::Init();
  157. nsXBLService::Init();
  158. rv = nsContentUtils::Init();
  159. if (NS_FAILED(rv)) {
  160. NS_ERROR("Could not initialize nsContentUtils");
  161. return rv;
  162. }
  163. rv = nsAttrValue::Init();
  164. if (NS_FAILED(rv)) {
  165. NS_ERROR("Could not initialize nsAttrValue");
  166. return rv;
  167. }
  168. rv = nsTextFragment::Init();
  169. if (NS_FAILED(rv)) {
  170. NS_ERROR("Could not initialize nsTextFragment");
  171. return rv;
  172. }
  173. nsCellMap::Init();
  174. StaticPresData::Init();
  175. nsCSSRendering::Init();
  176. rv = nsHTMLDNSPrefetch::Initialize();
  177. if (NS_FAILED(rv)) {
  178. NS_ERROR("Could not initialize HTML DNS prefetch");
  179. return rv;
  180. }
  181. #ifdef MOZ_XUL
  182. rv = nsXULContentUtils::Init();
  183. if (NS_FAILED(rv)) {
  184. NS_ERROR("Could not initialize nsXULContentUtils");
  185. return rv;
  186. }
  187. #endif
  188. nsMathMLOperators::AddRefTable();
  189. #ifdef DEBUG
  190. nsFrame::DisplayReflowStartup();
  191. #endif
  192. Attr::Initialize();
  193. rv = txMozillaXSLTProcessor::Startup();
  194. if (NS_FAILED(rv)) {
  195. NS_ERROR("Could not initialize txMozillaXSLTProcessor");
  196. return rv;
  197. }
  198. rv = DOMStorageObserver::Init();
  199. if (NS_FAILED(rv)) {
  200. NS_ERROR("Could not initialize DOMStorageObserver");
  201. return rv;
  202. }
  203. rv = nsCCUncollectableMarker::Init();
  204. if (NS_FAILED(rv)) {
  205. NS_ERROR("Could not initialize nsCCUncollectableMarker");
  206. return rv;
  207. }
  208. nsCSSParser::Startup();
  209. nsCSSRuleProcessor::Startup();
  210. #ifdef MOZ_XUL
  211. rv = nsXULPopupManager::Init();
  212. if (NS_FAILED(rv)) {
  213. NS_ERROR("Could not initialize nsXULPopupManager");
  214. return rv;
  215. }
  216. #endif
  217. rv = nsFocusManager::Init();
  218. if (NS_FAILED(rv)) {
  219. NS_ERROR("Could not initialize nsFocusManager");
  220. return rv;
  221. }
  222. AsyncLatencyLogger::InitializeStatics();
  223. MediaManager::StartupInit();
  224. CubebUtils::InitLibrary();
  225. nsContentSink::InitializeStatics();
  226. nsHtml5Module::InitializeStatics();
  227. mozilla::dom::FallbackEncoding::Initialize();
  228. nsLayoutUtils::Initialize();
  229. nsIPresShell::InitializeStatics();
  230. TouchManager::InitializeStatics();
  231. nsPrincipal::InitializeStatics();
  232. nsCORSListenerProxy::Startup();
  233. nsWindowMemoryReporter::Init();
  234. SVGElementFactory::Init();
  235. nsSVGUtils::Init();
  236. ProcessPriorityManager::Init();
  237. #ifdef MOZ_PERMISSIONS
  238. nsPermissionManager::ClearOriginDataObserverInit();
  239. #endif
  240. nsCookieService::AppClearDataObserverInit();
  241. nsApplicationCacheService::AppClearDataObserverInit();
  242. HTMLVideoElement::Init();
  243. #ifdef MOZ_XUL
  244. nsMenuBarListener::InitializeStatics();
  245. #endif
  246. CacheObserver::Init();
  247. CounterStyleManager::InitializeBuiltinCounterStyles();
  248. IMEStateManager::Init();
  249. ServiceWorkerRegistrar::Initialize();
  250. #ifdef DEBUG
  251. nsStyleContext::Initialize();
  252. mozilla::LayerAnimationInfo::Initialize();
  253. #endif
  254. MediaDecoder::InitStatics();
  255. PromiseDebugging::Init();
  256. mozilla::dom::WebCryptoThreadPool::Initialize();
  257. // NB: We initialize servo in nsAppRunner.cpp, because we need to do it after
  258. // creating the hidden DOM window to support some current stylo hacks. We
  259. // should move initialization back here once those go away.
  260. MediaPrefs::GetSingleton();
  261. return NS_OK;
  262. }
  263. void
  264. nsLayoutStatics::Shutdown()
  265. {
  266. // Don't need to shutdown nsWindowMemoryReporter, that will be done by the
  267. // memory reporter manager.
  268. nsMessageManagerScriptExecutor::Shutdown();
  269. nsFocusManager::Shutdown();
  270. #ifdef MOZ_XUL
  271. nsXULPopupManager::Shutdown();
  272. #endif
  273. DOMStorageObserver::Shutdown();
  274. txMozillaXSLTProcessor::Shutdown();
  275. Attr::Shutdown();
  276. EventListenerManager::Shutdown();
  277. IMEStateManager::Shutdown();
  278. nsCSSParser::Shutdown();
  279. nsCSSRuleProcessor::Shutdown();
  280. nsHTMLDNSPrefetch::Shutdown();
  281. nsCSSRendering::Shutdown();
  282. StaticPresData::Shutdown();
  283. #ifdef DEBUG
  284. nsFrame::DisplayReflowShutdown();
  285. #endif
  286. nsCellMap::Shutdown();
  287. ActiveLayerTracker::Shutdown();
  288. // Release all of our atoms
  289. nsColorNames::ReleaseTable();
  290. nsCSSProps::ReleaseTable();
  291. nsCSSKeywords::ReleaseTable();
  292. nsRepeatService::Shutdown();
  293. nsStackLayout::Shutdown();
  294. nsBox::Shutdown();
  295. #ifdef MOZ_XUL
  296. nsXULContentUtils::Finish();
  297. nsXULPrototypeCache::ReleaseGlobals();
  298. nsSprocketLayout::Shutdown();
  299. #endif
  300. SVGElementFactory::Shutdown();
  301. nsMathMLOperators::ReleaseTable();
  302. nsFloatManager::Shutdown();
  303. nsImageFrame::ReleaseGlobals();
  304. mozilla::css::ErrorReporter::ReleaseGlobals();
  305. nsTextFragment::Shutdown();
  306. nsAttrValue::Shutdown();
  307. nsContentUtils::Shutdown();
  308. nsLayoutStylesheetCache::Shutdown();
  309. RuleProcessorCache::Shutdown();
  310. ShutdownJSEnvironment();
  311. nsGlobalWindow::ShutDown();
  312. nsDOMClassInfo::ShutDown();
  313. WebIDLGlobalNameHash::Shutdown();
  314. nsListControlFrame::Shutdown();
  315. nsXBLService::Shutdown();
  316. nsAutoCopyListener::Shutdown();
  317. FrameLayerBuilder::Shutdown();
  318. CubebUtils::ShutdownLibrary();
  319. AsyncLatencyLogger::ShutdownLogger();
  320. WebAudioUtils::Shutdown();
  321. #ifdef MOZ_WEBSPEECH
  322. nsSynthVoiceRegistry::Shutdown();
  323. #endif
  324. nsCORSListenerProxy::Shutdown();
  325. nsIPresShell::ReleaseStatics();
  326. TouchManager::ReleaseStatics();
  327. nsTreeSanitizer::ReleaseStatics();
  328. nsHtml5Module::ReleaseStatics();
  329. mozilla::dom::FallbackEncoding::Shutdown();
  330. nsRegion::ShutdownStatic();
  331. mozilla::EventDispatcher::Shutdown();
  332. HTMLInputElement::DestroyUploadLastDir();
  333. nsLayoutUtils::Shutdown();
  334. nsHyphenationManager::Shutdown();
  335. nsDOMMutationObserver::Shutdown();
  336. ContentParent::ShutDown();
  337. DisplayItemClip::Shutdown();
  338. CacheObserver::Shutdown();
  339. PromiseDebugging::Shutdown();
  340. }