1 : /* ***** BEGIN LICENSE BLOCK *****
2 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 : *
4 : * The contents of this file are subject to the Mozilla Public License Version
5 : * 1.1 (the "License"); you may not use this file except in compliance with
6 : * the License. You may obtain a copy of the License at
7 : * http://www.mozilla.org/MPL/
8 : *
9 : * Software distributed under the License is distributed on an "AS IS" basis,
10 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 : * for the specific language governing rights and limitations under the
12 : * License.
13 : *
14 : * The Original Code is the Mozilla platform.
15 : *
16 : * The Initial Developer of the Original Code is
17 : * Benjamin Smedberg <benjamin@smedbergs.us>.
18 : *
19 : * Portions created by the Initial Developer are Copyright (C) 2006
20 : * the Mozilla Foundation <http://www.mozilla.org/>. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either the GNU General Public License Version 2 or later (the "GPL"), or
26 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #include "nsLayoutStatics.h"
39 : #include "nscore.h"
40 :
41 : #include "nsAttrValue.h"
42 : #include "nsAutoCopyListener.h"
43 : #include "nsColorNames.h"
44 : #include "nsComputedDOMStyle.h"
45 : #include "nsContentDLF.h"
46 : #include "nsContentUtils.h"
47 : #include "nsCSSAnonBoxes.h"
48 : #include "nsCSSFrameConstructor.h"
49 : #include "nsCSSKeywords.h"
50 : #include "nsCSSParser.h"
51 : #include "nsCSSProps.h"
52 : #include "nsCSSPseudoClasses.h"
53 : #include "nsCSSPseudoElements.h"
54 : #include "nsCSSRendering.h"
55 : #include "nsCSSScanner.h"
56 : #include "nsDOMAttribute.h"
57 : #include "nsDOMClassInfo.h"
58 : #include "nsEventListenerManager.h"
59 : #include "nsFrame.h"
60 : #include "nsGlobalWindow.h"
61 : #include "nsGkAtoms.h"
62 : #include "nsImageFrame.h"
63 : #include "nsLayoutStylesheetCache.h"
64 : #include "nsNodeInfo.h"
65 : #include "nsRange.h"
66 : #include "nsRegion.h"
67 : #include "nsRepeatService.h"
68 : #include "nsFloatManager.h"
69 : #include "nsSprocketLayout.h"
70 : #include "nsStackLayout.h"
71 : #include "nsStyleSet.h"
72 : #include "nsTextControlFrame.h"
73 : #include "nsXBLWindowKeyHandler.h"
74 : #include "txMozillaXSLTProcessor.h"
75 : #include "nsDOMStorage.h"
76 : #include "nsTreeSanitizer.h"
77 : #include "nsCellMap.h"
78 : #include "nsTextFrameTextRunCache.h"
79 : #include "nsCCUncollectableMarker.h"
80 : #include "nsTextFragment.h"
81 : #include "nsCSSRuleProcessor.h"
82 : #include "nsCrossSiteListenerProxy.h"
83 : #include "nsHTMLDNSPrefetch.h"
84 : #include "nsHtml5Module.h"
85 : #include "nsFocusManager.h"
86 : #include "nsFrameList.h"
87 : #include "nsListControlFrame.h"
88 : #include "nsHTMLInputElement.h"
89 : #include "nsSVGUtils.h"
90 : #include "nsMathMLAtoms.h"
91 : #include "nsMathMLOperators.h"
92 : #include "Navigator.h"
93 :
94 : #ifdef MOZ_XUL
95 : #include "nsXULPopupManager.h"
96 : #include "nsXULContentUtils.h"
97 : #include "nsXULElement.h"
98 : #include "nsXULPrototypeCache.h"
99 : #include "nsXULTooltipListener.h"
100 :
101 : #include "inDOMView.h"
102 : #endif
103 :
104 : #include "nsHTMLEditor.h"
105 : #include "nsTextServicesDocument.h"
106 :
107 : #ifdef MOZ_MEDIA
108 : #include "nsMediaDecoder.h"
109 : #include "nsHTMLMediaElement.h"
110 : #endif
111 :
112 : #ifdef MOZ_SYDNEYAUDIO
113 : #include "nsAudioStream.h"
114 : #endif
115 :
116 : #include "nsError.h"
117 :
118 : #include "nsCycleCollector.h"
119 : #include "nsJSEnvironment.h"
120 : #include "nsContentSink.h"
121 : #include "nsFrameMessageManager.h"
122 : #include "nsRefreshDriver.h"
123 :
124 : #include "nsHyphenationManager.h"
125 : #include "nsEditorSpellCheck.h"
126 : #include "nsWindowMemoryReporter.h"
127 :
128 : extern void NS_ShutdownChainItemPool();
129 :
130 : using namespace mozilla;
131 : using namespace mozilla::dom;
132 :
133 : nsrefcnt nsLayoutStatics::sLayoutStaticRefcnt = 0;
134 :
135 : nsresult
136 1404 : nsLayoutStatics::Initialize()
137 : {
138 1404 : NS_ASSERTION(sLayoutStaticRefcnt == 0,
139 : "nsLayoutStatics isn't zero!");
140 :
141 1404 : sLayoutStaticRefcnt = 1;
142 : NS_LOG_ADDREF(&sLayoutStaticRefcnt, sLayoutStaticRefcnt,
143 1404 : "nsLayoutStatics", 1);
144 :
145 : nsresult rv;
146 :
147 : // Register all of our atoms once
148 1404 : nsCSSAnonBoxes::AddRefAtoms();
149 1404 : nsCSSPseudoClasses::AddRefAtoms();
150 1404 : nsCSSPseudoElements::AddRefAtoms();
151 1404 : nsCSSKeywords::AddRefTable();
152 1404 : nsCSSProps::AddRefTable();
153 1404 : nsColorNames::AddRefTable();
154 1404 : nsGkAtoms::AddRefAtoms();
155 :
156 1404 : nsJSRuntime::Startup();
157 1404 : rv = nsRegion::InitStatic();
158 1404 : if (NS_FAILED(rv)) {
159 0 : NS_ERROR("Could not initialize nsRegion");
160 0 : return rv;
161 : }
162 :
163 1404 : nsGlobalWindow::Init();
164 1404 : Navigator::Init();
165 :
166 1404 : rv = nsContentUtils::Init();
167 1404 : if (NS_FAILED(rv)) {
168 0 : NS_ERROR("Could not initialize nsContentUtils");
169 0 : return rv;
170 : }
171 :
172 1404 : rv = nsAttrValue::Init();
173 1404 : if (NS_FAILED(rv)) {
174 0 : NS_ERROR("Could not initialize nsAttrValue");
175 0 : return rv;
176 : }
177 :
178 1404 : rv = nsTextFragment::Init();
179 1404 : if (NS_FAILED(rv)) {
180 0 : NS_ERROR("Could not initialize nsTextFragment");
181 0 : return rv;
182 : }
183 :
184 1404 : nsCellMap::Init();
185 :
186 1404 : nsCSSRendering::Init();
187 :
188 1404 : nsTextFrameTextRunCache::Init();
189 :
190 1404 : rv = nsHTMLDNSPrefetch::Initialize();
191 1404 : if (NS_FAILED(rv)) {
192 0 : NS_ERROR("Could not initialize HTML DNS prefetch");
193 0 : return rv;
194 : }
195 :
196 : #ifdef MOZ_XUL
197 1404 : rv = nsXULContentUtils::Init();
198 1404 : if (NS_FAILED(rv)) {
199 0 : NS_ERROR("Could not initialize nsXULContentUtils");
200 0 : return rv;
201 : }
202 :
203 1404 : inDOMView::InitAtoms();
204 :
205 : #endif
206 :
207 1404 : nsMathMLOperators::AddRefTable();
208 :
209 1404 : nsEditProperty::RegisterAtoms();
210 1404 : nsTextServicesDocument::RegisterAtoms();
211 :
212 : #ifdef DEBUG
213 1404 : nsFrame::DisplayReflowStartup();
214 : #endif
215 1404 : nsDOMAttribute::Initialize();
216 :
217 1404 : rv = txMozillaXSLTProcessor::Startup();
218 1404 : if (NS_FAILED(rv)) {
219 0 : NS_ERROR("Could not initialize txMozillaXSLTProcessor");
220 0 : return rv;
221 : }
222 :
223 1404 : rv = nsDOMStorageManager::Initialize();
224 1404 : if (NS_FAILED(rv)) {
225 0 : NS_ERROR("Could not initialize nsDOMStorageManager");
226 0 : return rv;
227 : }
228 :
229 1404 : rv = nsCCUncollectableMarker::Init();
230 1404 : if (NS_FAILED(rv)) {
231 0 : NS_ERROR("Could not initialize nsCCUncollectableMarker");
232 0 : return rv;
233 : }
234 :
235 1404 : rv = nsCSSRuleProcessor::Startup();
236 1404 : if (NS_FAILED(rv)) {
237 0 : NS_ERROR("Could not initialize nsCSSRuleProcessor");
238 0 : return rv;
239 : }
240 :
241 : #ifdef MOZ_XUL
242 1404 : rv = nsXULPopupManager::Init();
243 1404 : if (NS_FAILED(rv)) {
244 0 : NS_ERROR("Could not initialize nsXULPopupManager");
245 0 : return rv;
246 : }
247 : #endif
248 :
249 1404 : rv = nsFocusManager::Init();
250 1404 : if (NS_FAILED(rv)) {
251 0 : NS_ERROR("Could not initialize nsFocusManager");
252 0 : return rv;
253 : }
254 :
255 : #ifdef MOZ_SYDNEYAUDIO
256 1404 : nsAudioStream::InitLibrary();
257 : #endif
258 :
259 1404 : nsContentSink::InitializeStatics();
260 1404 : nsHtml5Module::InitializeStatics();
261 1404 : nsLayoutUtils::Initialize();
262 1404 : nsIPresShell::InitializeStatics();
263 1404 : nsRefreshDriver::InitializeStatics();
264 :
265 1404 : nsCORSListenerProxy::Startup();
266 :
267 1404 : nsFrameList::Init();
268 :
269 1404 : NS_SealStaticAtomTable();
270 :
271 1404 : nsWindowMemoryReporter::Init();
272 :
273 1404 : return NS_OK;
274 : }
275 :
276 : void
277 1403 : nsLayoutStatics::Shutdown()
278 : {
279 : // Don't need to shutdown nsWindowMemoryReporter, that will be done by the
280 : // memory reporter manager.
281 :
282 1403 : nsFrameScriptExecutor::Shutdown();
283 1403 : nsFocusManager::Shutdown();
284 : #ifdef MOZ_XUL
285 1403 : nsXULPopupManager::Shutdown();
286 : #endif
287 1403 : nsDOMStorageManager::Shutdown();
288 1403 : txMozillaXSLTProcessor::Shutdown();
289 1403 : nsDOMAttribute::Shutdown();
290 1403 : nsEventListenerManager::Shutdown();
291 1403 : nsComputedDOMStyle::Shutdown();
292 1403 : nsCSSParser::Shutdown();
293 1403 : nsCSSRuleProcessor::Shutdown();
294 1403 : nsTextFrameTextRunCache::Shutdown();
295 1403 : nsHTMLDNSPrefetch::Shutdown();
296 1403 : nsCSSRendering::Shutdown();
297 : #ifdef DEBUG
298 1403 : nsFrame::DisplayReflowShutdown();
299 : #endif
300 1403 : nsCellMap::Shutdown();
301 1403 : nsFrame::ShutdownLayerActivityTimer();
302 :
303 : // Release all of our atoms
304 1403 : nsColorNames::ReleaseTable();
305 1403 : nsCSSProps::ReleaseTable();
306 1403 : nsCSSKeywords::ReleaseTable();
307 1403 : nsRepeatService::Shutdown();
308 1403 : nsStackLayout::Shutdown();
309 1403 : nsBox::Shutdown();
310 :
311 : #ifdef MOZ_XUL
312 1403 : nsXULContentUtils::Finish();
313 1403 : nsXULElement::ReleaseGlobals();
314 1403 : nsXULPrototypeCache::ReleaseGlobals();
315 1403 : nsSprocketLayout::Shutdown();
316 : #endif
317 :
318 1403 : nsMathMLOperators::ReleaseTable();
319 :
320 1403 : nsCSSFrameConstructor::ReleaseGlobals();
321 1403 : nsFloatManager::Shutdown();
322 1403 : nsImageFrame::ReleaseGlobals();
323 :
324 1403 : nsCSSScanner::ReleaseGlobals();
325 :
326 1403 : nsTextFragment::Shutdown();
327 :
328 1403 : nsAttrValue::Shutdown();
329 1403 : nsContentUtils::Shutdown();
330 1403 : nsNodeInfo::ClearCache();
331 1403 : nsLayoutStylesheetCache::Shutdown();
332 1403 : NS_NameSpaceManagerShutdown();
333 :
334 1403 : nsJSRuntime::Shutdown();
335 1403 : nsGlobalWindow::ShutDown();
336 1403 : nsDOMClassInfo::ShutDown();
337 1403 : nsListControlFrame::Shutdown();
338 1403 : nsXBLWindowKeyHandler::ShutDown();
339 1403 : nsAutoCopyListener::Shutdown();
340 :
341 : #ifdef MOZ_SYDNEYAUDIO
342 1403 : nsAudioStream::ShutdownLibrary();
343 : #endif
344 :
345 1403 : nsCORSListenerProxy::Shutdown();
346 :
347 1403 : nsIPresShell::ReleaseStatics();
348 :
349 1403 : nsTreeSanitizer::ReleaseStatics();
350 :
351 1403 : nsHtml5Module::ReleaseStatics();
352 :
353 1403 : nsRegion::ShutdownStatic();
354 :
355 1403 : NS_ShutdownChainItemPool();
356 :
357 1403 : nsFrameList::Shutdown();
358 :
359 1403 : nsHTMLInputElement::DestroyUploadLastDir();
360 :
361 1403 : nsLayoutUtils::Shutdown();
362 :
363 1403 : nsHyphenationManager::Shutdown();
364 1403 : nsEditorSpellCheck::ShutDown();
365 1403 : }
|