Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
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/. */
5 #include "base/basictypes.h"
7 #include "nsLayoutStatics.h"
8 #include "nscore.h"
10 #include "nsAttrValue.h"
11 #include "nsAutoCopyListener.h"
12 #include "nsColorNames.h"
13 #include "nsComputedDOMStyle.h"
14 #include "nsContentDLF.h"
15 #include "nsContentUtils.h"
16 #include "nsCSSAnonBoxes.h"
17 #include "mozilla/css/ErrorReporter.h"
18 #include "nsCSSKeywords.h"
19 #include "nsCSSParser.h"
20 #include "nsCSSProps.h"
21 #include "nsCSSPseudoClasses.h"
22 #include "nsCSSPseudoElements.h"
23 #include "nsCSSRendering.h"
24 #include "mozilla/dom/Attr.h"
25 #include "nsDOMClassInfo.h"
26 #include "nsEditorEventListener.h"
27 #include "mozilla/EventListenerManager.h"
28 #include "nsFrame.h"
29 #include "nsGlobalWindow.h"
30 #include "nsGkAtoms.h"
31 #include "nsImageFrame.h"
32 #include "nsLayoutStylesheetCache.h"
33 #include "nsNodeInfo.h"
34 #include "nsRange.h"
35 #include "nsRegion.h"
36 #include "nsRepeatService.h"
37 #include "nsFloatManager.h"
38 #include "nsSprocketLayout.h"
39 #include "nsStackLayout.h"
40 #include "nsStyleSet.h"
41 #include "nsTextControlFrame.h"
42 #include "nsXBLService.h"
43 #include "txMozillaXSLTProcessor.h"
44 #include "nsTreeSanitizer.h"
45 #include "nsCellMap.h"
46 #include "nsTextFrame.h"
47 #include "nsCCUncollectableMarker.h"
48 #include "nsTextFragment.h"
49 #include "nsCSSRuleProcessor.h"
50 #include "nsCrossSiteListenerProxy.h"
51 #include "nsHTMLDNSPrefetch.h"
52 #include "nsHtml5Module.h"
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"
67 #include "AudioChannelService.h"
69 #ifdef MOZ_XUL
70 #include "nsXULPopupManager.h"
71 #include "nsXULContentUtils.h"
72 #include "nsXULPrototypeCache.h"
73 #include "nsXULTooltipListener.h"
75 #include "inDOMView.h"
77 #include "nsMenuBarListener.h"
78 #endif
80 #include "nsHTMLEditor.h"
81 #include "nsTextServicesDocument.h"
83 #ifdef MOZ_WEBSPEECH
84 #include "nsSynthVoiceRegistry.h"
85 #endif
87 #ifdef MOZ_MEDIA_PLUGINS
88 #include "MediaPluginHost.h"
89 #endif
91 #ifdef MOZ_WMF
92 #include "WMFDecoder.h"
93 #endif
95 #ifdef MOZ_GSTREAMER
96 #include "GStreamerFormatHelper.h"
97 #endif
99 #ifdef MOZ_FFMPEG
100 #include "FFmpegRuntimeLinker.h"
101 #endif
103 #include "AudioStream.h"
104 #include "Latency.h"
105 #include "WebAudioUtils.h"
107 #ifdef MOZ_WIDGET_GONK
108 #include "nsVolumeService.h"
109 #include "SpeakerManagerService.h"
110 using namespace mozilla::system;
111 #endif
113 #include "nsError.h"
115 #include "nsJSEnvironment.h"
116 #include "nsContentSink.h"
117 #include "nsFrameMessageManager.h"
118 #include "nsRefreshDriver.h"
119 #include "nsDOMMutationObserver.h"
120 #include "nsHyphenationManager.h"
121 #include "nsEditorSpellCheck.h"
122 #include "nsWindowMemoryReporter.h"
123 #include "mozilla/dom/ContentParent.h"
124 #include "mozilla/ProcessPriorityManager.h"
125 #include "nsPermissionManager.h"
126 #include "nsCookieService.h"
127 #include "nsApplicationCacheService.h"
128 #include "mozilla/dom/time/DateCacheCleaner.h"
129 #include "mozilla/EventDispatcher.h"
130 #include "mozilla/IMEStateManager.h"
131 #include "nsDocument.h"
132 #include "mozilla/dom/HTMLVideoElement.h"
134 using namespace mozilla;
135 using namespace mozilla::net;
136 using namespace mozilla::dom;
137 using namespace mozilla::dom::ipc;
139 nsrefcnt nsLayoutStatics::sLayoutStaticRefcnt = 0;
141 nsresult
142 nsLayoutStatics::Initialize()
143 {
144 NS_ASSERTION(sLayoutStaticRefcnt == 0,
145 "nsLayoutStatics isn't zero!");
147 sLayoutStaticRefcnt = 1;
148 NS_LOG_ADDREF(&sLayoutStaticRefcnt, sLayoutStaticRefcnt,
149 "nsLayoutStatics", 1);
151 nsresult rv;
153 ContentParent::StartUp();
155 // Register all of our atoms once
156 nsCSSAnonBoxes::AddRefAtoms();
157 nsCSSPseudoClasses::AddRefAtoms();
158 nsCSSPseudoElements::AddRefAtoms();
159 nsCSSKeywords::AddRefTable();
160 nsCSSProps::AddRefTable();
161 nsColorNames::AddRefTable();
162 nsGkAtoms::AddRefAtoms();
164 StartupJSEnvironment();
165 rv = nsRegion::InitStatic();
166 if (NS_FAILED(rv)) {
167 NS_ERROR("Could not initialize nsRegion");
168 return rv;
169 }
171 nsGlobalWindow::Init();
172 Navigator::Init();
173 nsXBLService::Init();
175 rv = nsContentUtils::Init();
176 if (NS_FAILED(rv)) {
177 NS_ERROR("Could not initialize nsContentUtils");
178 return rv;
179 }
181 rv = nsAttrValue::Init();
182 if (NS_FAILED(rv)) {
183 NS_ERROR("Could not initialize nsAttrValue");
184 return rv;
185 }
187 rv = nsTextFragment::Init();
188 if (NS_FAILED(rv)) {
189 NS_ERROR("Could not initialize nsTextFragment");
190 return rv;
191 }
193 nsCellMap::Init();
195 nsCSSRendering::Init();
197 nsTextFrameTextRunCache::Init();
199 rv = nsHTMLDNSPrefetch::Initialize();
200 if (NS_FAILED(rv)) {
201 NS_ERROR("Could not initialize HTML DNS prefetch");
202 return rv;
203 }
205 #ifdef MOZ_XUL
206 rv = nsXULContentUtils::Init();
207 if (NS_FAILED(rv)) {
208 NS_ERROR("Could not initialize nsXULContentUtils");
209 return rv;
210 }
212 #endif
214 nsMathMLOperators::AddRefTable();
216 nsEditProperty::RegisterAtoms();
217 nsTextServicesDocument::RegisterAtoms();
219 #ifdef DEBUG
220 nsFrame::DisplayReflowStartup();
221 #endif
222 Attr::Initialize();
224 rv = txMozillaXSLTProcessor::Startup();
225 if (NS_FAILED(rv)) {
226 NS_ERROR("Could not initialize txMozillaXSLTProcessor");
227 return rv;
228 }
230 rv = DOMStorageObserver::Init();
231 if (NS_FAILED(rv)) {
232 NS_ERROR("Could not initialize DOMStorageObserver");
233 return rv;
234 }
236 rv = nsCCUncollectableMarker::Init();
237 if (NS_FAILED(rv)) {
238 NS_ERROR("Could not initialize nsCCUncollectableMarker");
239 return rv;
240 }
242 rv = nsCSSRuleProcessor::Startup();
243 if (NS_FAILED(rv)) {
244 NS_ERROR("Could not initialize nsCSSRuleProcessor");
245 return rv;
246 }
248 #ifdef MOZ_XUL
249 rv = nsXULPopupManager::Init();
250 if (NS_FAILED(rv)) {
251 NS_ERROR("Could not initialize nsXULPopupManager");
252 return rv;
253 }
254 #endif
256 rv = nsFocusManager::Init();
257 if (NS_FAILED(rv)) {
258 NS_ERROR("Could not initialize nsFocusManager");
259 return rv;
260 }
262 AsyncLatencyLogger::InitializeStatics();
263 AudioStream::InitLibrary();
265 nsContentSink::InitializeStatics();
266 nsHtml5Module::InitializeStatics();
267 mozilla::dom::FallbackEncoding::Initialize();
268 nsLayoutUtils::Initialize();
269 nsIPresShell::InitializeStatics();
270 nsRefreshDriver::InitializeStatics();
272 nsCORSListenerProxy::Startup();
274 NS_SealStaticAtomTable();
276 nsWindowMemoryReporter::Init();
278 SVGElementFactory::Init();
279 nsSVGUtils::Init();
281 ProcessPriorityManager::Init();
283 nsPermissionManager::AppClearDataObserverInit();
284 nsCookieService::AppClearDataObserverInit();
285 nsApplicationCacheService::AppClearDataObserverInit();
287 HTMLVideoElement::Init();
289 #ifdef MOZ_XUL
290 nsMenuBarListener::InitializeStatics();
291 #endif
293 CacheObserver::Init();
295 return NS_OK;
296 }
298 void
299 nsLayoutStatics::Shutdown()
300 {
301 // Don't need to shutdown nsWindowMemoryReporter, that will be done by the
302 // memory reporter manager.
304 nsFrameScriptExecutor::Shutdown();
305 nsFocusManager::Shutdown();
306 #ifdef MOZ_XUL
307 nsXULPopupManager::Shutdown();
308 #endif
309 DOMStorageObserver::Shutdown();
310 txMozillaXSLTProcessor::Shutdown();
311 Attr::Shutdown();
312 EventListenerManager::Shutdown();
313 IMEStateManager::Shutdown();
314 nsComputedDOMStyle::Shutdown();
315 nsCSSParser::Shutdown();
316 nsCSSRuleProcessor::Shutdown();
317 nsTextFrameTextRunCache::Shutdown();
318 nsHTMLDNSPrefetch::Shutdown();
319 nsCSSRendering::Shutdown();
320 #ifdef DEBUG
321 nsFrame::DisplayReflowShutdown();
322 #endif
323 nsCellMap::Shutdown();
324 ActiveLayerTracker::Shutdown();
326 // Release all of our atoms
327 nsColorNames::ReleaseTable();
328 nsCSSProps::ReleaseTable();
329 nsCSSKeywords::ReleaseTable();
330 nsRepeatService::Shutdown();
331 nsStackLayout::Shutdown();
332 nsBox::Shutdown();
334 #ifdef MOZ_XUL
335 nsXULContentUtils::Finish();
336 nsXULPrototypeCache::ReleaseGlobals();
337 nsSprocketLayout::Shutdown();
338 #endif
340 SVGElementFactory::Shutdown();
341 nsMathMLOperators::ReleaseTable();
343 nsFloatManager::Shutdown();
344 nsImageFrame::ReleaseGlobals();
346 mozilla::css::ErrorReporter::ReleaseGlobals();
348 nsTextFragment::Shutdown();
350 nsAttrValue::Shutdown();
351 nsContentUtils::Shutdown();
352 nsLayoutStylesheetCache::Shutdown();
354 ShutdownJSEnvironment();
355 nsGlobalWindow::ShutDown();
356 nsDOMClassInfo::ShutDown();
357 nsListControlFrame::Shutdown();
358 nsXBLService::Shutdown();
359 nsAutoCopyListener::Shutdown();
360 FrameLayerBuilder::Shutdown();
362 #ifdef MOZ_MEDIA_PLUGINS
363 MediaPluginHost::Shutdown();
364 #endif
366 #ifdef MOZ_GSTREAMER
367 GStreamerFormatHelper::Shutdown();
368 #endif
370 #ifdef MOZ_FFMPEG
371 FFmpegRuntimeLinker::Unlink();
372 #endif
374 AudioStream::ShutdownLibrary();
375 AsyncLatencyLogger::ShutdownLogger();
376 WebAudioUtils::Shutdown();
378 #ifdef MOZ_WMF
379 WMFDecoder::UnloadDLLs();
380 #endif
382 #ifdef MOZ_WIDGET_GONK
383 nsVolumeService::Shutdown();
384 SpeakerManagerService::Shutdown();
385 #endif
387 #ifdef MOZ_WEBSPEECH
388 nsSynthVoiceRegistry::Shutdown();
389 #endif
391 nsCORSListenerProxy::Shutdown();
393 nsIPresShell::ReleaseStatics();
395 nsTreeSanitizer::ReleaseStatics();
397 nsHtml5Module::ReleaseStatics();
399 mozilla::dom::FallbackEncoding::Shutdown();
401 nsRegion::ShutdownStatic();
403 mozilla::EventDispatcher::Shutdown();
405 HTMLInputElement::DestroyUploadLastDir();
407 nsLayoutUtils::Shutdown();
409 nsHyphenationManager::Shutdown();
410 nsDOMMutationObserver::Shutdown();
412 AudioChannelService::Shutdown();
414 ContentParent::ShutDown();
416 nsRefreshDriver::Shutdown();
418 DisplayItemClip::Shutdown();
420 nsDocument::XPCOMShutdown();
422 CacheObserver::Shutdown();
423 }