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.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "base/basictypes.h" |
michael@0 | 6 | |
michael@0 | 7 | #include "nsLayoutStatics.h" |
michael@0 | 8 | #include "nscore.h" |
michael@0 | 9 | |
michael@0 | 10 | #include "nsAttrValue.h" |
michael@0 | 11 | #include "nsAutoCopyListener.h" |
michael@0 | 12 | #include "nsColorNames.h" |
michael@0 | 13 | #include "nsComputedDOMStyle.h" |
michael@0 | 14 | #include "nsContentDLF.h" |
michael@0 | 15 | #include "nsContentUtils.h" |
michael@0 | 16 | #include "nsCSSAnonBoxes.h" |
michael@0 | 17 | #include "mozilla/css/ErrorReporter.h" |
michael@0 | 18 | #include "nsCSSKeywords.h" |
michael@0 | 19 | #include "nsCSSParser.h" |
michael@0 | 20 | #include "nsCSSProps.h" |
michael@0 | 21 | #include "nsCSSPseudoClasses.h" |
michael@0 | 22 | #include "nsCSSPseudoElements.h" |
michael@0 | 23 | #include "nsCSSRendering.h" |
michael@0 | 24 | #include "mozilla/dom/Attr.h" |
michael@0 | 25 | #include "nsDOMClassInfo.h" |
michael@0 | 26 | #include "nsEditorEventListener.h" |
michael@0 | 27 | #include "mozilla/EventListenerManager.h" |
michael@0 | 28 | #include "nsFrame.h" |
michael@0 | 29 | #include "nsGlobalWindow.h" |
michael@0 | 30 | #include "nsGkAtoms.h" |
michael@0 | 31 | #include "nsImageFrame.h" |
michael@0 | 32 | #include "nsLayoutStylesheetCache.h" |
michael@0 | 33 | #include "nsNodeInfo.h" |
michael@0 | 34 | #include "nsRange.h" |
michael@0 | 35 | #include "nsRegion.h" |
michael@0 | 36 | #include "nsRepeatService.h" |
michael@0 | 37 | #include "nsFloatManager.h" |
michael@0 | 38 | #include "nsSprocketLayout.h" |
michael@0 | 39 | #include "nsStackLayout.h" |
michael@0 | 40 | #include "nsStyleSet.h" |
michael@0 | 41 | #include "nsTextControlFrame.h" |
michael@0 | 42 | #include "nsXBLService.h" |
michael@0 | 43 | #include "txMozillaXSLTProcessor.h" |
michael@0 | 44 | #include "nsTreeSanitizer.h" |
michael@0 | 45 | #include "nsCellMap.h" |
michael@0 | 46 | #include "nsTextFrame.h" |
michael@0 | 47 | #include "nsCCUncollectableMarker.h" |
michael@0 | 48 | #include "nsTextFragment.h" |
michael@0 | 49 | #include "nsCSSRuleProcessor.h" |
michael@0 | 50 | #include "nsCrossSiteListenerProxy.h" |
michael@0 | 51 | #include "nsHTMLDNSPrefetch.h" |
michael@0 | 52 | #include "nsHtml5Module.h" |
michael@0 | 53 | #include "mozilla/dom/FallbackEncoding.h" |
michael@0 | 54 | #include "nsFocusManager.h" |
michael@0 | 55 | #include "nsListControlFrame.h" |
michael@0 | 56 | #include "mozilla/dom/HTMLInputElement.h" |
michael@0 | 57 | #include "SVGElementFactory.h" |
michael@0 | 58 | #include "nsSVGUtils.h" |
michael@0 | 59 | #include "nsMathMLAtoms.h" |
michael@0 | 60 | #include "nsMathMLOperators.h" |
michael@0 | 61 | #include "Navigator.h" |
michael@0 | 62 | #include "DOMStorageObserver.h" |
michael@0 | 63 | #include "CacheObserver.h" |
michael@0 | 64 | #include "DisplayItemClip.h" |
michael@0 | 65 | #include "ActiveLayerTracker.h" |
michael@0 | 66 | |
michael@0 | 67 | #include "AudioChannelService.h" |
michael@0 | 68 | |
michael@0 | 69 | #ifdef MOZ_XUL |
michael@0 | 70 | #include "nsXULPopupManager.h" |
michael@0 | 71 | #include "nsXULContentUtils.h" |
michael@0 | 72 | #include "nsXULPrototypeCache.h" |
michael@0 | 73 | #include "nsXULTooltipListener.h" |
michael@0 | 74 | |
michael@0 | 75 | #include "inDOMView.h" |
michael@0 | 76 | |
michael@0 | 77 | #include "nsMenuBarListener.h" |
michael@0 | 78 | #endif |
michael@0 | 79 | |
michael@0 | 80 | #include "nsHTMLEditor.h" |
michael@0 | 81 | #include "nsTextServicesDocument.h" |
michael@0 | 82 | |
michael@0 | 83 | #ifdef MOZ_WEBSPEECH |
michael@0 | 84 | #include "nsSynthVoiceRegistry.h" |
michael@0 | 85 | #endif |
michael@0 | 86 | |
michael@0 | 87 | #ifdef MOZ_MEDIA_PLUGINS |
michael@0 | 88 | #include "MediaPluginHost.h" |
michael@0 | 89 | #endif |
michael@0 | 90 | |
michael@0 | 91 | #ifdef MOZ_WMF |
michael@0 | 92 | #include "WMFDecoder.h" |
michael@0 | 93 | #endif |
michael@0 | 94 | |
michael@0 | 95 | #ifdef MOZ_GSTREAMER |
michael@0 | 96 | #include "GStreamerFormatHelper.h" |
michael@0 | 97 | #endif |
michael@0 | 98 | |
michael@0 | 99 | #ifdef MOZ_FFMPEG |
michael@0 | 100 | #include "FFmpegRuntimeLinker.h" |
michael@0 | 101 | #endif |
michael@0 | 102 | |
michael@0 | 103 | #include "AudioStream.h" |
michael@0 | 104 | #include "Latency.h" |
michael@0 | 105 | #include "WebAudioUtils.h" |
michael@0 | 106 | |
michael@0 | 107 | #ifdef MOZ_WIDGET_GONK |
michael@0 | 108 | #include "nsVolumeService.h" |
michael@0 | 109 | #include "SpeakerManagerService.h" |
michael@0 | 110 | using namespace mozilla::system; |
michael@0 | 111 | #endif |
michael@0 | 112 | |
michael@0 | 113 | #include "nsError.h" |
michael@0 | 114 | |
michael@0 | 115 | #include "nsJSEnvironment.h" |
michael@0 | 116 | #include "nsContentSink.h" |
michael@0 | 117 | #include "nsFrameMessageManager.h" |
michael@0 | 118 | #include "nsRefreshDriver.h" |
michael@0 | 119 | #include "nsDOMMutationObserver.h" |
michael@0 | 120 | #include "nsHyphenationManager.h" |
michael@0 | 121 | #include "nsEditorSpellCheck.h" |
michael@0 | 122 | #include "nsWindowMemoryReporter.h" |
michael@0 | 123 | #include "mozilla/dom/ContentParent.h" |
michael@0 | 124 | #include "mozilla/ProcessPriorityManager.h" |
michael@0 | 125 | #include "nsPermissionManager.h" |
michael@0 | 126 | #include "nsCookieService.h" |
michael@0 | 127 | #include "nsApplicationCacheService.h" |
michael@0 | 128 | #include "mozilla/dom/time/DateCacheCleaner.h" |
michael@0 | 129 | #include "mozilla/EventDispatcher.h" |
michael@0 | 130 | #include "mozilla/IMEStateManager.h" |
michael@0 | 131 | #include "nsDocument.h" |
michael@0 | 132 | #include "mozilla/dom/HTMLVideoElement.h" |
michael@0 | 133 | |
michael@0 | 134 | using namespace mozilla; |
michael@0 | 135 | using namespace mozilla::net; |
michael@0 | 136 | using namespace mozilla::dom; |
michael@0 | 137 | using namespace mozilla::dom::ipc; |
michael@0 | 138 | |
michael@0 | 139 | nsrefcnt nsLayoutStatics::sLayoutStaticRefcnt = 0; |
michael@0 | 140 | |
michael@0 | 141 | nsresult |
michael@0 | 142 | nsLayoutStatics::Initialize() |
michael@0 | 143 | { |
michael@0 | 144 | NS_ASSERTION(sLayoutStaticRefcnt == 0, |
michael@0 | 145 | "nsLayoutStatics isn't zero!"); |
michael@0 | 146 | |
michael@0 | 147 | sLayoutStaticRefcnt = 1; |
michael@0 | 148 | NS_LOG_ADDREF(&sLayoutStaticRefcnt, sLayoutStaticRefcnt, |
michael@0 | 149 | "nsLayoutStatics", 1); |
michael@0 | 150 | |
michael@0 | 151 | nsresult rv; |
michael@0 | 152 | |
michael@0 | 153 | ContentParent::StartUp(); |
michael@0 | 154 | |
michael@0 | 155 | // Register all of our atoms once |
michael@0 | 156 | nsCSSAnonBoxes::AddRefAtoms(); |
michael@0 | 157 | nsCSSPseudoClasses::AddRefAtoms(); |
michael@0 | 158 | nsCSSPseudoElements::AddRefAtoms(); |
michael@0 | 159 | nsCSSKeywords::AddRefTable(); |
michael@0 | 160 | nsCSSProps::AddRefTable(); |
michael@0 | 161 | nsColorNames::AddRefTable(); |
michael@0 | 162 | nsGkAtoms::AddRefAtoms(); |
michael@0 | 163 | |
michael@0 | 164 | StartupJSEnvironment(); |
michael@0 | 165 | rv = nsRegion::InitStatic(); |
michael@0 | 166 | if (NS_FAILED(rv)) { |
michael@0 | 167 | NS_ERROR("Could not initialize nsRegion"); |
michael@0 | 168 | return rv; |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | nsGlobalWindow::Init(); |
michael@0 | 172 | Navigator::Init(); |
michael@0 | 173 | nsXBLService::Init(); |
michael@0 | 174 | |
michael@0 | 175 | rv = nsContentUtils::Init(); |
michael@0 | 176 | if (NS_FAILED(rv)) { |
michael@0 | 177 | NS_ERROR("Could not initialize nsContentUtils"); |
michael@0 | 178 | return rv; |
michael@0 | 179 | } |
michael@0 | 180 | |
michael@0 | 181 | rv = nsAttrValue::Init(); |
michael@0 | 182 | if (NS_FAILED(rv)) { |
michael@0 | 183 | NS_ERROR("Could not initialize nsAttrValue"); |
michael@0 | 184 | return rv; |
michael@0 | 185 | } |
michael@0 | 186 | |
michael@0 | 187 | rv = nsTextFragment::Init(); |
michael@0 | 188 | if (NS_FAILED(rv)) { |
michael@0 | 189 | NS_ERROR("Could not initialize nsTextFragment"); |
michael@0 | 190 | return rv; |
michael@0 | 191 | } |
michael@0 | 192 | |
michael@0 | 193 | nsCellMap::Init(); |
michael@0 | 194 | |
michael@0 | 195 | nsCSSRendering::Init(); |
michael@0 | 196 | |
michael@0 | 197 | nsTextFrameTextRunCache::Init(); |
michael@0 | 198 | |
michael@0 | 199 | rv = nsHTMLDNSPrefetch::Initialize(); |
michael@0 | 200 | if (NS_FAILED(rv)) { |
michael@0 | 201 | NS_ERROR("Could not initialize HTML DNS prefetch"); |
michael@0 | 202 | return rv; |
michael@0 | 203 | } |
michael@0 | 204 | |
michael@0 | 205 | #ifdef MOZ_XUL |
michael@0 | 206 | rv = nsXULContentUtils::Init(); |
michael@0 | 207 | if (NS_FAILED(rv)) { |
michael@0 | 208 | NS_ERROR("Could not initialize nsXULContentUtils"); |
michael@0 | 209 | return rv; |
michael@0 | 210 | } |
michael@0 | 211 | |
michael@0 | 212 | #endif |
michael@0 | 213 | |
michael@0 | 214 | nsMathMLOperators::AddRefTable(); |
michael@0 | 215 | |
michael@0 | 216 | nsEditProperty::RegisterAtoms(); |
michael@0 | 217 | nsTextServicesDocument::RegisterAtoms(); |
michael@0 | 218 | |
michael@0 | 219 | #ifdef DEBUG |
michael@0 | 220 | nsFrame::DisplayReflowStartup(); |
michael@0 | 221 | #endif |
michael@0 | 222 | Attr::Initialize(); |
michael@0 | 223 | |
michael@0 | 224 | rv = txMozillaXSLTProcessor::Startup(); |
michael@0 | 225 | if (NS_FAILED(rv)) { |
michael@0 | 226 | NS_ERROR("Could not initialize txMozillaXSLTProcessor"); |
michael@0 | 227 | return rv; |
michael@0 | 228 | } |
michael@0 | 229 | |
michael@0 | 230 | rv = DOMStorageObserver::Init(); |
michael@0 | 231 | if (NS_FAILED(rv)) { |
michael@0 | 232 | NS_ERROR("Could not initialize DOMStorageObserver"); |
michael@0 | 233 | return rv; |
michael@0 | 234 | } |
michael@0 | 235 | |
michael@0 | 236 | rv = nsCCUncollectableMarker::Init(); |
michael@0 | 237 | if (NS_FAILED(rv)) { |
michael@0 | 238 | NS_ERROR("Could not initialize nsCCUncollectableMarker"); |
michael@0 | 239 | return rv; |
michael@0 | 240 | } |
michael@0 | 241 | |
michael@0 | 242 | rv = nsCSSRuleProcessor::Startup(); |
michael@0 | 243 | if (NS_FAILED(rv)) { |
michael@0 | 244 | NS_ERROR("Could not initialize nsCSSRuleProcessor"); |
michael@0 | 245 | return rv; |
michael@0 | 246 | } |
michael@0 | 247 | |
michael@0 | 248 | #ifdef MOZ_XUL |
michael@0 | 249 | rv = nsXULPopupManager::Init(); |
michael@0 | 250 | if (NS_FAILED(rv)) { |
michael@0 | 251 | NS_ERROR("Could not initialize nsXULPopupManager"); |
michael@0 | 252 | return rv; |
michael@0 | 253 | } |
michael@0 | 254 | #endif |
michael@0 | 255 | |
michael@0 | 256 | rv = nsFocusManager::Init(); |
michael@0 | 257 | if (NS_FAILED(rv)) { |
michael@0 | 258 | NS_ERROR("Could not initialize nsFocusManager"); |
michael@0 | 259 | return rv; |
michael@0 | 260 | } |
michael@0 | 261 | |
michael@0 | 262 | AsyncLatencyLogger::InitializeStatics(); |
michael@0 | 263 | AudioStream::InitLibrary(); |
michael@0 | 264 | |
michael@0 | 265 | nsContentSink::InitializeStatics(); |
michael@0 | 266 | nsHtml5Module::InitializeStatics(); |
michael@0 | 267 | mozilla::dom::FallbackEncoding::Initialize(); |
michael@0 | 268 | nsLayoutUtils::Initialize(); |
michael@0 | 269 | nsIPresShell::InitializeStatics(); |
michael@0 | 270 | nsRefreshDriver::InitializeStatics(); |
michael@0 | 271 | |
michael@0 | 272 | nsCORSListenerProxy::Startup(); |
michael@0 | 273 | |
michael@0 | 274 | NS_SealStaticAtomTable(); |
michael@0 | 275 | |
michael@0 | 276 | nsWindowMemoryReporter::Init(); |
michael@0 | 277 | |
michael@0 | 278 | SVGElementFactory::Init(); |
michael@0 | 279 | nsSVGUtils::Init(); |
michael@0 | 280 | |
michael@0 | 281 | ProcessPriorityManager::Init(); |
michael@0 | 282 | |
michael@0 | 283 | nsPermissionManager::AppClearDataObserverInit(); |
michael@0 | 284 | nsCookieService::AppClearDataObserverInit(); |
michael@0 | 285 | nsApplicationCacheService::AppClearDataObserverInit(); |
michael@0 | 286 | |
michael@0 | 287 | HTMLVideoElement::Init(); |
michael@0 | 288 | |
michael@0 | 289 | #ifdef MOZ_XUL |
michael@0 | 290 | nsMenuBarListener::InitializeStatics(); |
michael@0 | 291 | #endif |
michael@0 | 292 | |
michael@0 | 293 | CacheObserver::Init(); |
michael@0 | 294 | |
michael@0 | 295 | return NS_OK; |
michael@0 | 296 | } |
michael@0 | 297 | |
michael@0 | 298 | void |
michael@0 | 299 | nsLayoutStatics::Shutdown() |
michael@0 | 300 | { |
michael@0 | 301 | // Don't need to shutdown nsWindowMemoryReporter, that will be done by the |
michael@0 | 302 | // memory reporter manager. |
michael@0 | 303 | |
michael@0 | 304 | nsFrameScriptExecutor::Shutdown(); |
michael@0 | 305 | nsFocusManager::Shutdown(); |
michael@0 | 306 | #ifdef MOZ_XUL |
michael@0 | 307 | nsXULPopupManager::Shutdown(); |
michael@0 | 308 | #endif |
michael@0 | 309 | DOMStorageObserver::Shutdown(); |
michael@0 | 310 | txMozillaXSLTProcessor::Shutdown(); |
michael@0 | 311 | Attr::Shutdown(); |
michael@0 | 312 | EventListenerManager::Shutdown(); |
michael@0 | 313 | IMEStateManager::Shutdown(); |
michael@0 | 314 | nsComputedDOMStyle::Shutdown(); |
michael@0 | 315 | nsCSSParser::Shutdown(); |
michael@0 | 316 | nsCSSRuleProcessor::Shutdown(); |
michael@0 | 317 | nsTextFrameTextRunCache::Shutdown(); |
michael@0 | 318 | nsHTMLDNSPrefetch::Shutdown(); |
michael@0 | 319 | nsCSSRendering::Shutdown(); |
michael@0 | 320 | #ifdef DEBUG |
michael@0 | 321 | nsFrame::DisplayReflowShutdown(); |
michael@0 | 322 | #endif |
michael@0 | 323 | nsCellMap::Shutdown(); |
michael@0 | 324 | ActiveLayerTracker::Shutdown(); |
michael@0 | 325 | |
michael@0 | 326 | // Release all of our atoms |
michael@0 | 327 | nsColorNames::ReleaseTable(); |
michael@0 | 328 | nsCSSProps::ReleaseTable(); |
michael@0 | 329 | nsCSSKeywords::ReleaseTable(); |
michael@0 | 330 | nsRepeatService::Shutdown(); |
michael@0 | 331 | nsStackLayout::Shutdown(); |
michael@0 | 332 | nsBox::Shutdown(); |
michael@0 | 333 | |
michael@0 | 334 | #ifdef MOZ_XUL |
michael@0 | 335 | nsXULContentUtils::Finish(); |
michael@0 | 336 | nsXULPrototypeCache::ReleaseGlobals(); |
michael@0 | 337 | nsSprocketLayout::Shutdown(); |
michael@0 | 338 | #endif |
michael@0 | 339 | |
michael@0 | 340 | SVGElementFactory::Shutdown(); |
michael@0 | 341 | nsMathMLOperators::ReleaseTable(); |
michael@0 | 342 | |
michael@0 | 343 | nsFloatManager::Shutdown(); |
michael@0 | 344 | nsImageFrame::ReleaseGlobals(); |
michael@0 | 345 | |
michael@0 | 346 | mozilla::css::ErrorReporter::ReleaseGlobals(); |
michael@0 | 347 | |
michael@0 | 348 | nsTextFragment::Shutdown(); |
michael@0 | 349 | |
michael@0 | 350 | nsAttrValue::Shutdown(); |
michael@0 | 351 | nsContentUtils::Shutdown(); |
michael@0 | 352 | nsLayoutStylesheetCache::Shutdown(); |
michael@0 | 353 | |
michael@0 | 354 | ShutdownJSEnvironment(); |
michael@0 | 355 | nsGlobalWindow::ShutDown(); |
michael@0 | 356 | nsDOMClassInfo::ShutDown(); |
michael@0 | 357 | nsListControlFrame::Shutdown(); |
michael@0 | 358 | nsXBLService::Shutdown(); |
michael@0 | 359 | nsAutoCopyListener::Shutdown(); |
michael@0 | 360 | FrameLayerBuilder::Shutdown(); |
michael@0 | 361 | |
michael@0 | 362 | #ifdef MOZ_MEDIA_PLUGINS |
michael@0 | 363 | MediaPluginHost::Shutdown(); |
michael@0 | 364 | #endif |
michael@0 | 365 | |
michael@0 | 366 | #ifdef MOZ_GSTREAMER |
michael@0 | 367 | GStreamerFormatHelper::Shutdown(); |
michael@0 | 368 | #endif |
michael@0 | 369 | |
michael@0 | 370 | #ifdef MOZ_FFMPEG |
michael@0 | 371 | FFmpegRuntimeLinker::Unlink(); |
michael@0 | 372 | #endif |
michael@0 | 373 | |
michael@0 | 374 | AudioStream::ShutdownLibrary(); |
michael@0 | 375 | AsyncLatencyLogger::ShutdownLogger(); |
michael@0 | 376 | WebAudioUtils::Shutdown(); |
michael@0 | 377 | |
michael@0 | 378 | #ifdef MOZ_WMF |
michael@0 | 379 | WMFDecoder::UnloadDLLs(); |
michael@0 | 380 | #endif |
michael@0 | 381 | |
michael@0 | 382 | #ifdef MOZ_WIDGET_GONK |
michael@0 | 383 | nsVolumeService::Shutdown(); |
michael@0 | 384 | SpeakerManagerService::Shutdown(); |
michael@0 | 385 | #endif |
michael@0 | 386 | |
michael@0 | 387 | #ifdef MOZ_WEBSPEECH |
michael@0 | 388 | nsSynthVoiceRegistry::Shutdown(); |
michael@0 | 389 | #endif |
michael@0 | 390 | |
michael@0 | 391 | nsCORSListenerProxy::Shutdown(); |
michael@0 | 392 | |
michael@0 | 393 | nsIPresShell::ReleaseStatics(); |
michael@0 | 394 | |
michael@0 | 395 | nsTreeSanitizer::ReleaseStatics(); |
michael@0 | 396 | |
michael@0 | 397 | nsHtml5Module::ReleaseStatics(); |
michael@0 | 398 | |
michael@0 | 399 | mozilla::dom::FallbackEncoding::Shutdown(); |
michael@0 | 400 | |
michael@0 | 401 | nsRegion::ShutdownStatic(); |
michael@0 | 402 | |
michael@0 | 403 | mozilla::EventDispatcher::Shutdown(); |
michael@0 | 404 | |
michael@0 | 405 | HTMLInputElement::DestroyUploadLastDir(); |
michael@0 | 406 | |
michael@0 | 407 | nsLayoutUtils::Shutdown(); |
michael@0 | 408 | |
michael@0 | 409 | nsHyphenationManager::Shutdown(); |
michael@0 | 410 | nsDOMMutationObserver::Shutdown(); |
michael@0 | 411 | |
michael@0 | 412 | AudioChannelService::Shutdown(); |
michael@0 | 413 | |
michael@0 | 414 | ContentParent::ShutDown(); |
michael@0 | 415 | |
michael@0 | 416 | nsRefreshDriver::Shutdown(); |
michael@0 | 417 | |
michael@0 | 418 | DisplayItemClip::Shutdown(); |
michael@0 | 419 | |
michael@0 | 420 | nsDocument::XPCOMShutdown(); |
michael@0 | 421 | |
michael@0 | 422 | CacheObserver::Shutdown(); |
michael@0 | 423 | } |