Bug 331117 - Layout module shold not shut down until all documents/windows have been released, r+sr=dbaron

This commit is contained in:
benjamin%smedbergs.us 2006-05-19 09:31:57 +00:00
Родитель afeadc35d3
Коммит 68537c76ad
7 изменённых файлов: 350 добавлений и 169 удалений

Просмотреть файл

@ -143,6 +143,8 @@ static NS_DEFINE_CID(kDOMEventGroupCID, NS_DOMEVENTGROUP_CID);
#include "nsIDOMXPathEvaluator.h"
#include "nsDOMCID.h"
#include "nsLayoutStatics.h"
#ifdef MOZ_LOGGING
// so we can get logging even in release builds
#define FORCE_PR_LOG 1
@ -707,6 +709,7 @@ nsDocument::nsDocument(const char* aContentType)
: nsIDocument(),
mVisible(PR_TRUE)
{
nsLayoutStatics::AddRef();
mContentType = aContentType;
#ifdef PR_LOGGING
@ -826,6 +829,7 @@ nsDocument::~nsDocument()
delete mHeaderData;
delete mBoxObjectTable;
nsLayoutStatics::Release();
}
NS_INTERFACE_MAP_BEGIN(nsDocument)

Просмотреть файл

@ -41,6 +41,11 @@
#include "nsIDOMEvent.h"
#include "nsIDOMEventListener.h"
// X.h defines KeyPress
#ifdef KeyPress
#undef KeyPress
#endif
/*
* Key pressed / released / typed listener interface.
*/

Просмотреть файл

@ -69,6 +69,7 @@
#include "nsIJVMManager.h"
#endif
#include "nsContentCID.h"
#include "nsLayoutStatics.h"
// Interfaces Needed
#include "nsIWidget.h"
@ -345,6 +346,8 @@ nsGlobalWindow::nsGlobalWindow(nsGlobalWindow *aOuterWindow)
, mSetOpenerWindowCalled(PR_FALSE)
#endif
{
nsLayoutStatics::AddRef();
// Initialize the PRCList (this).
PR_INIT_CLIST(this);
@ -463,6 +466,8 @@ nsGlobalWindow::~nsGlobalWindow()
CleanUp();
delete mPendingStorageEvents;
nsLayoutStatics::Release();
}
// static

Просмотреть файл

@ -111,11 +111,13 @@ CPPSRCS = \
nsLayoutModule.cpp \
nsContentHTTPStartup.cpp \
nsContentDLF.cpp \
nsLayoutStatics.cpp \
$(NULL)
EXPORTS = \
nsLayoutCID.h \
nsContentDLF.h \
nsLayoutStatics.h \
$(NULL)
SHARED_LIBRARY_LIBS = \

Просмотреть файл

@ -35,33 +35,21 @@
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsXBLAtoms.h" // to addref/release table
#include "nsCSSPseudoElements.h" // to addref/release table
#include "nsCSSPseudoClasses.h" // to addref/release table
#include "nsCSSAnonBoxes.h" // to addref/release table
#include "nsCSSKeywords.h" // to addref/release table
#include "nsCSSProps.h" // to addref/release table
#include "nsColorNames.h" // to addref/release table
#include "nsLayoutStatics.h"
#include "nsContentCID.h"
#include "nsContentHTTPStartup.h"
#include "nsContentDLF.h"
#include "nsContentPolicyUtils.h"
#include "nsContentUtils.h"
#include "nsDataDocumentContentPolicy.h"
#include "nsLayoutStylesheetCache.h"
#include "nsDOMCID.h"
#include "nsCSSOMFactory.h"
#include "nsInspectorCSSUtils.h"
#include "nsEventListenerManager.h"
#include "nsGenericElement.h"
#include "nsHTMLAtoms.h"
#include "nsHTMLAtoms.h"
#include "nsHTMLContentSerializer.h"
#include "nsHTMLParts.h"
#include "nsGenericHTMLElement.h"
#include "nsICSSLoader.h"
#include "nsICSSParser.h"
#include "nsCSSScanner.h"
#include "nsICSSStyleSheet.h"
#include "nsICategoryManager.h"
#include "nsIComponentManager.h"
@ -98,38 +86,23 @@
#include "nsISelection.h"
#include "nsIXBLService.h"
#include "nsICaret.h"
#include "nsJSEnvironment.h"
#include "nsLayoutAtoms.h"
#include "nsPlainTextSerializer.h"
#include "mozSanitizingSerializer.h"
#include "nsRange.h"
#include "nsComputedDOMStyle.h"
#include "nsXMLContentSerializer.h"
#include "nsRuleNode.h"
#include "nsWyciwygProtocolHandler.h"
#include "nsContentAreaDragDrop.h"
#include "nsContentList.h"
#include "nsISyncLoadDOMService.h"
#include "nsCSSFrameConstructor.h"
#include "nsRepeatService.h"
#include "nsSprocketLayout.h"
#include "nsStackLayout.h"
#include "nsBox.h"
#include "nsSpaceManager.h"
#include "nsTextTransformer.h"
#include "nsIFrameTraversal.h"
#ifndef MOZ_CAIRO_GFX
#include "nsISelectionImageService.h"
#endif
#include "nsCSSLoader.h"
#include "nsXULAtoms.h"
#include "nsLayoutCID.h"
#include "nsStyleSet.h"
#include "nsImageFrame.h"
#include "nsILanguageAtomService.h"
#include "nsTextControlFrame.h"
#include "nsStyleSheetService.h"
#include "nsNodeInfo.h"
// Transformiix stuff
#include "nsXPathEvaluator.h"
@ -147,21 +120,15 @@
#include "nsViewsCID.h"
#include "nsViewManager.h"
#include "nsContentCreatorFunctions.h"
#include "nsFrame.h"
#include "nsXBLWindowKeyHandler.h"
// DOM includes
#include "nsDOMException.h"
#include "nsGlobalWindowCommands.h"
#include "nsIControllerCommandTable.h"
#include "nsJSProtocolHandler.h"
#include "nsGlobalWindow.h"
#include "nsDOMClassInfo.h"
#include "nsScriptNameSpaceManager.h"
#include "nsIControllerContext.h"
#include "nsDOMScriptObjectFactory.h"
#include "nsAutoCopyListener.h"
#include "nsDOMAttribute.h"
#include "nsDOMStorage.h"
#include "nsHTMLCanvasFrame.h"
@ -191,14 +158,13 @@ class nsIDocumentLoaderFactory;
static NS_DEFINE_CID(kWindowCommandTableCID, NS_WINDOWCOMMANDTABLE_CID);
#ifdef MOZ_XUL
#include "nsIBoxObject.h"
#include "nsIXULDocument.h"
#include "nsIXULPopupListener.h"
#include "nsIXULPrototypeCache.h"
#include "nsIXULPrototypeDocument.h"
#include "nsIXULPrototypeDocument.h"
#include "nsIXULSortService.h"
#include "nsXULContentUtils.h"
#include "nsXULElement.h"
NS_IMETHODIMP
NS_NewXULContentBuilder(nsISupports* aOuter, REFNSIID aIID, void** aResult);
@ -210,20 +176,13 @@ NS_NewXULTreeBuilder(nsISupports* aOuter, REFNSIID aIID, void** aResult);
PR_STATIC_CALLBACK(nsresult) Initialize(nsIModule* aSelf);
static void Shutdown();
#ifdef MOZ_MATHML
#include "nsMathMLAtoms.h"
#include "nsMathMLOperators.h"
#endif
#ifdef MOZ_XTF
#include "nsIXTFService.h"
#include "nsIXMLContentBuilder.h"
#endif
#ifdef MOZ_SVG
#include "nsSVGAtoms.h"
#include "nsISVGRenderer.h"
#include "nsSVGUtils.h"
#endif
// Transformiix
@ -289,79 +248,11 @@ Initialize(nsIModule* aSelf)
gInitialized = PR_TRUE;
nsJSEnvironment::Startup();
nsresult rv = nsContentUtils::Init();
nsresult rv = nsLayoutStatics::Initialize();
if (NS_FAILED(rv)) {
NS_ERROR("Could not initialize nsContentUtils");
Shutdown();
return rv;
}
rv = nsAttrValue::Init();
if (NS_FAILED(rv)) {
NS_ERROR("Could not initialize nsAttrValue");
Shutdown();
return rv;
}
rv = nsTextFragment::Init();
if (NS_FAILED(rv)) {
NS_ERROR("Could not initialize nsAttrValue");
Shutdown();
return rv;
}
// Register all of our atoms once
nsCSSAnonBoxes::AddRefAtoms();
nsCSSPseudoClasses::AddRefAtoms();
nsCSSPseudoElements::AddRefAtoms();
nsCSSKeywords::AddRefTable();
nsCSSProps::AddRefTable();
nsColorNames::AddRefTable();
nsGkAtoms::AddRefAtoms();
#ifdef MOZ_XUL
rv = nsXULContentUtils::Init();
if (NS_FAILED(rv)) {
NS_ERROR("Could not initialize nsXULContentUtils");
Shutdown();
return rv;
}
#endif
#ifdef MOZ_MATHML
nsMathMLOperators::AddRefTable();
#endif
#ifdef MOZ_SVG
if (nsSVGUtils::SVGEnabled())
nsContentDLF::RegisterSVG();
#endif
#ifdef DEBUG
nsFrame::DisplayReflowStartup();
#endif
rv = nsTextTransformer::Initialize();
if (NS_FAILED(rv)) {
NS_ERROR("Could not initialize nsTextTransformer");
Shutdown();
return rv;
}
nsDOMAttribute::Initialize();
if (!txXSLTProcessor::init()) {
Shutdown();
return NS_ERROR_OUT_OF_MEMORY;
}
// Add our shutdown observer.
nsCOMPtr<nsIObserverService> observerService =
@ -396,62 +287,7 @@ Shutdown()
gInitialized = PR_FALSE;
nsNodeInfo::ClearCache();
txXSLTProcessor::shutdown();
nsDOMAttribute::Shutdown();
nsRange::Shutdown();
nsDOMEventRTTearoff::Shutdown();
nsEventListenerManager::Shutdown();
nsContentList::Shutdown();
nsComputedDOMStyle::Shutdown();
CSSLoaderImpl::Shutdown();
#ifdef DEBUG
nsFrame::DisplayReflowShutdown();
#endif
// Release all of our atoms
nsColorNames::ReleaseTable();
nsCSSProps::ReleaseTable();
nsCSSKeywords::ReleaseTable();
nsRepeatService::Shutdown();
nsStackLayout::Shutdown();
nsBox::Shutdown();
#ifdef MOZ_XUL
nsXULContentUtils::Finish();
nsXULElement::ReleaseGlobals();
nsXULPrototypeElement::ReleaseGlobals();
nsXULPrototypeScript::ReleaseGlobals();
nsSprocketLayout::Shutdown();
#endif
#ifdef MOZ_MATHML
nsMathMLOperators::ReleaseTable();
#endif
nsCSSFrameConstructor::ReleaseGlobals();
nsTextTransformer::Shutdown();
nsSpaceManager::Shutdown();
nsImageFrame::ReleaseGlobals();
nsCSSScanner::ReleaseGlobals();
NS_IF_RELEASE(nsContentDLF::gUAStyleSheet);
NS_IF_RELEASE(nsRuleNode::gLangService);
nsGenericHTMLElement::Shutdown();
nsTextFragment::Shutdown();
nsAttrValue::Shutdown();
nsContentUtils::Shutdown();
nsLayoutStylesheetCache::Shutdown();
NS_NameSpaceManagerShutdown();
nsStyleSet::FreeGlobals();
nsGlobalWindow::ShutDown();
nsDOMClassInfo::ShutDown();
nsTextControlFrame::ShutDown();
nsXBLWindowKeyHandler::ShutDown();
nsAutoCopyListener::Shutdown();
nsLayoutStatics::Release();
}
#ifdef NS_DEBUG

Просмотреть файл

@ -0,0 +1,265 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Mozilla platform.
*
* The Initial Developer of the Original Code is
* Benjamin Smedberg <benjamin@smedbergs.us>.
*
* Portions created by the Initial Developer are Copyright (C) 2006
* the Mozilla Foundation <http://www.mozilla.org/>. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsLayoutStatics.h"
#include "nscore.h"
#include "nsAttrValue.h"
#include "nsAutoCopyListener.h"
#include "nsColorNames.h"
#include "nsComputedDOMStyle.h"
#include "nsContentDLF.h"
#include "nsContentUtils.h"
#include "nsCSSAnonBoxes.h"
#include "nsCSSFrameConstructor.h"
#include "nsCSSKeywords.h"
#include "nsCSSLoader.h"
#include "nsCSSProps.h"
#include "nsCSSPseudoClasses.h"
#include "nsCSSPseudoElements.h"
#include "nsCSSScanner.h"
#include "nsICSSStyleSheet.h"
#include "nsDOMAttribute.h"
#include "nsDOMClassInfo.h"
#include "nsEventListenerManager.h"
#include "nsFrame.h"
#include "nsGenericElement.h" // for nsDOMEventRTTearoff
#include "nsGenericHTMLElement.h"
#include "nsGlobalWindow.h"
#include "nsHTMLAtoms.h"
#include "nsImageFrame.h"
#include "nsJSEnvironment.h"
#include "nsLayoutAtoms.h"
#include "nsLayoutStylesheetCache.h"
#include "nsNodeInfo.h"
#include "nsRange.h"
#include "nsRepeatService.h"
#include "nsSpaceManager.h"
#include "nsSprocketLayout.h"
#include "nsStackLayout.h"
#include "nsStyleSet.h"
#include "nsTextControlFrame.h"
#include "nsTextTransformer.h"
#include "nsXBLAtoms.h"
#include "nsXBLWindowKeyHandler.h"
#include "txXSLTProcessor.h"
#ifdef MOZ_XUL
#include "nsXULContentUtils.h"
#include "nsXULElement.h"
#endif
#ifdef MOZ_MATHML
#include "nsMathMLAtoms.h"
#include "nsMathMLOperators.h"
#endif
#ifdef MOZ_SVG
#include "nsSVGAtoms.h"
#include "nsSVGUtils.h"
#endif
#include "nsError.h"
#include "nsTraceRefcnt.h"
static nsrefcnt sLayoutStaticRefcnt;
nsresult
nsLayoutStatics::Initialize()
{
#ifdef NS_BUILD_REFCNT_LOGGING
NS_LogCtor(&sLayoutStaticRefcnt, "nsLayoutStatics", 1);
#endif
NS_ASSERTION(sLayoutStaticRefcnt == 0,
"nsLayoutStatics isn't zero!");
sLayoutStaticRefcnt = 1;
NS_LOG_ADDREF(&sLayoutStaticRefcnt, sLayoutStaticRefcnt,
"nsLayoutStatics", 0);
nsresult rv;
nsJSEnvironment::Startup();
rv = nsContentUtils::Init();
if (NS_FAILED(rv)) {
NS_ERROR("Could not initialize nsContentUtils");
return rv;
}
rv = nsAttrValue::Init();
if (NS_FAILED(rv)) {
NS_ERROR("Could not initialize nsAttrValue");
return rv;
}
rv = nsTextFragment::Init();
if (NS_FAILED(rv)) {
NS_ERROR("Could not initialize nsTextFragment");
return rv;
}
// Register all of our atoms once
nsCSSAnonBoxes::AddRefAtoms();
nsCSSPseudoClasses::AddRefAtoms();
nsCSSPseudoElements::AddRefAtoms();
nsCSSKeywords::AddRefTable();
nsCSSProps::AddRefTable();
nsColorNames::AddRefTable();
nsGkAtoms::AddRefAtoms();
#ifdef MOZ_XUL
rv = nsXULContentUtils::Init();
if (NS_FAILED(rv)) {
NS_ERROR("Could not initialize nsXULContentUtils");
return rv;
}
#endif
#ifdef MOZ_MATHML
nsMathMLOperators::AddRefTable();
#endif
#ifdef MOZ_SVG
if (nsSVGUtils::SVGEnabled())
nsContentDLF::RegisterSVG();
#endif
#ifdef DEBUG
nsFrame::DisplayReflowStartup();
#endif
rv = nsTextTransformer::Initialize();
if (NS_FAILED(rv)) {
NS_ERROR("Could not initialize nsTextTransformer");
return rv;
}
nsDOMAttribute::Initialize();
if (!txXSLTProcessor::init()) {
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
void
nsLayoutStatics::Shutdown()
{
#ifdef NS_BUILD_REFCNT_LOGGING
NS_LogDtor(&sLayoutStaticRefcnt, "nsLayoutStatics", 1);
#endif
nsNodeInfo::ClearCache();
txXSLTProcessor::shutdown();
nsDOMAttribute::Shutdown();
nsRange::Shutdown();
nsDOMEventRTTearoff::Shutdown();
nsEventListenerManager::Shutdown();
nsContentList::Shutdown();
nsComputedDOMStyle::Shutdown();
CSSLoaderImpl::Shutdown();
#ifdef DEBUG
nsFrame::DisplayReflowShutdown();
#endif
// Release all of our atoms
nsColorNames::ReleaseTable();
nsCSSProps::ReleaseTable();
nsCSSKeywords::ReleaseTable();
nsRepeatService::Shutdown();
nsStackLayout::Shutdown();
nsBox::Shutdown();
#ifdef MOZ_XUL
nsXULContentUtils::Finish();
nsXULElement::ReleaseGlobals();
nsXULPrototypeElement::ReleaseGlobals();
nsXULPrototypeScript::ReleaseGlobals();
nsSprocketLayout::Shutdown();
#endif
#ifdef MOZ_MATHML
nsMathMLOperators::ReleaseTable();
#endif
nsCSSFrameConstructor::ReleaseGlobals();
nsTextTransformer::Shutdown();
nsSpaceManager::Shutdown();
nsImageFrame::ReleaseGlobals();
nsCSSScanner::ReleaseGlobals();
NS_IF_RELEASE(nsContentDLF::gUAStyleSheet);
NS_IF_RELEASE(nsRuleNode::gLangService);
nsGenericHTMLElement::Shutdown();
nsTextFragment::Shutdown();
nsAttrValue::Shutdown();
nsContentUtils::Shutdown();
nsLayoutStylesheetCache::Shutdown();
NS_NameSpaceManagerShutdown();
nsStyleSet::FreeGlobals();
nsGlobalWindow::ShutDown();
nsDOMClassInfo::ShutDown();
nsTextControlFrame::ShutDown();
nsXBLWindowKeyHandler::ShutDown();
nsAutoCopyListener::Shutdown();
}
void
nsLayoutStatics::AddRef()
{
NS_ASSERTION(sLayoutStaticRefcnt,
"nsLayoutStatics already dropped to zero!");
++sLayoutStaticRefcnt;
NS_LOG_ADDREF(&sLayoutStaticRefcnt, sLayoutStaticRefcnt,
"nsLayoutStatics", 1);
}
void
nsLayoutStatics::Release()
{
--sLayoutStaticRefcnt;
NS_LOG_RELEASE(&sLayoutStaticRefcnt, sLayoutStaticRefcnt,
"nsLayoutStatics");
if (!sLayoutStaticRefcnt)
Shutdown();
}

Просмотреть файл

@ -0,0 +1,64 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Mozilla platform.
*
* The Initial Developer of the Original Code is
* Benjamin Smedberg <benjamin@smedbergs.us>.
*
* Portions created by the Initial Developer are Copyright (C) 2006
* the Mozilla Foundation <http://www.mozilla.org/>. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsLayoutStatics_h__
#define nsLayoutStatics_h__
#include "nscore.h"
// This isn't really a class, it's a namespace for static methods.
// Documents and other objects can hold a reference to the layout static
// objects so that they last past the xpcom-shutdown notification.
class nsLayoutStatics
{
public:
// Called by the layout module constructor. This call performs an AddRef()
// internally.
static nsresult Initialize();
static void AddRef();
static void Release();
private:
// not to be called!
nsLayoutStatics();
static void Shutdown();
};
#endif // nsLayoutStatics_h__