bug# 96469 caching xbl service r=jag, sr=waterson, a=asa

This commit is contained in:
dp%netscape.com 2001-08-23 20:07:10 +00:00
parent a59e06aac8
commit f4baa95a45
8 changed files with 60 additions and 37 deletions

View File

@ -104,6 +104,7 @@ class nsIDocumentLoaderFactory;
#include "nsIXULSortService.h"
#include "nsXULAtoms.h"
#include "nsXULContentUtils.h"
#include "nsXULElement.h"
#endif
// jst says, ``we need this to avoid holding on to XPConnect past its
@ -203,6 +204,7 @@ Shutdown(nsIModule* aSelf)
#ifdef MOZ_XUL
nsXULContentUtils::Finish();
nsXULAtoms::ReleaseAtoms();
nsXULElement::ReleaseGlobals();
#endif
NS_IF_RELEASE(nsContentDLF::gUAStyleSheet);

View File

@ -147,6 +147,9 @@
class nsIWebShell;
// Global object maintenance
nsIXBLService * nsXULElement::gXBLService = nsnull;
// XXX This is sure to change. Copied from mozilla/layout/xul/content/src/nsXULAtoms.cpp
#define XUL_NAMESPACE_URI "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
static const char kXULNameSpaceURI[] = XUL_NAMESPACE_URI;
@ -753,8 +756,7 @@ nsXULElement::QueryInterface(REFNSIID iid, void** result)
(NodeInfo()->NamespaceEquals(kNameSpaceID_XUL))){
nsCOMPtr<nsIAtom> tag;
PRInt32 dummy;
nsCOMPtr<nsIXBLService> xblService =
do_GetService("@mozilla.org/xbl;1", &rv);
nsIXBLService *xblService = GetXBLService();
xblService->ResolveTag(NS_STATIC_CAST(nsIStyledContent*, this), &dummy, getter_AddRefs(tag));
if (tag.get() == nsXULAtoms::tree) {
// We delegate XULTreeElement APIs to an aggregate object
@ -780,8 +782,7 @@ nsXULElement::QueryInterface(REFNSIID iid, void** result)
nsCOMPtr<nsIAtom> tag;
PRInt32 dummy;
nsCOMPtr<nsIXBLService> xblService =
do_GetService("@mozilla.org/xbl;1", &rv);
nsIXBLService *xblService = GetXBLService();
xblService->ResolveTag(NS_STATIC_CAST(nsIStyledContent*, this), &dummy, getter_AddRefs(tag));
if (tag.get() == nsXULAtoms::tree) {
inst = nsContentUtils::
@ -2079,7 +2080,7 @@ nsXULElement::GetScriptObject(nsIScriptContext* aContext, void** aScriptObject)
if (! mScriptObject) {
// Use the XBL service to get the `base' tag, which'll be how
// we determine what kind of script object to cook up.
nsCOMPtr<nsIXBLService> xblService = do_GetService("@mozilla.org/xbl;1", &rv);
nsIXBLService *xblService = GetXBLService();
NS_ASSERTION(xblService != nsnull, "couldn't get XBL service");
if (! xblService)
return NS_ERROR_UNEXPECTED;

View File

@ -36,7 +36,7 @@
// XXX because nsIEventListenerManager has broken includes
#include "nslayout.h"
#include "nsIDOMEvent.h"
#include "nsIServiceManager.h"
#include "nsHTMLValue.h"
#include "nsIAtom.h"
#include "nsINodeInfo.h"
@ -61,12 +61,12 @@
#include "nsXULAttributes.h"
#include "nsIChromeEventHandler.h"
#include "nsXULAttributeValue.h"
#include "nsIXBLService.h"
class nsISizeOfHandler;
class nsIDocument;
class nsIRDFService;
class nsIXBLService;
class nsISupportsArray;
class nsIXULContentUtils;
class nsIXULPrototypeDocument;
@ -331,6 +331,13 @@ class nsXULElement : public nsIXULContent,
public nsIChromeEventHandler
{
public:
static nsIXBLService* GetXBLService() {
if (!gXBLService)
CallGetService("@mozilla.org/xbl;1", &gXBLService);
return gXBLService;
}
static void ReleaseGlobals() { NS_IF_RELEASE(gXBLService); }
protected:
// pseudo-constants
static nsrefcnt gRefCnt;
@ -552,6 +559,8 @@ protected:
nsIRDFResource* OwnedResource() const { return mSlots ? mSlots->mOwnedResource.get() : nsnull; }
nsXULAttributes* Attributes() const { return mSlots ? mSlots->mAttributes : nsnull; }
nsXULAggregateElement* InnerXULElement() const { return mSlots ? mSlots->mInnerXULElement : nsnull; }
static nsIXBLService *gXBLService;
};

View File

@ -115,7 +115,6 @@ static NS_DEFINE_CID(kAttributeContentCID, NS_ATTRIBUTECONTENT_CID);
#include "nsIScrollableFrame.h"
#include "nsIServiceManager.h"
#include "nsIXBLService.h"
#include "nsIStyleRuleSupplier.h"
@ -157,6 +156,9 @@ NS_NewPolylineFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame);
#include "nsINodeInfo.h"
#include "prenv.h"
// Global object maintenance
nsIXBLService * nsCSSFrameConstructor::gXBLService = nsnull;
#ifdef DEBUG
// Set the environment variable GECKO_FRAMECTOR_DEBUG_FLAGS to one or
// more of the following flags (comma separated) for handy debug
@ -3452,14 +3454,11 @@ nsCSSFrameConstructor::ConstructDocElementFrame(nsIPresShell* aPresShell,
if (!display->mBinding.IsEmpty()) {
// Get the XBL loader.
nsresult rv;
nsCOMPtr<nsIXBLService> xblService =
do_GetService("@mozilla.org/xbl;1", &rv);
if (!xblService)
return rv;
PRBool resolveStyle;
nsCOMPtr<nsIXBLBinding> binding;
rv = xblService->LoadBindings(aDocElement, display->mBinding, PR_FALSE, getter_AddRefs(binding), &resolveStyle);
if (!gXBLService)
return NS_ERROR_FAILURE;
rv = gXBLService->LoadBindings(aDocElement, display->mBinding, PR_FALSE, getter_AddRefs(binding), &resolveStyle);
if (NS_FAILED(rv))
return NS_OK; // Binding will load asynchronously.
@ -7297,14 +7296,11 @@ nsCSSFrameConstructor::ConstructFrameInternal( nsIPresShell* aPresShe
if (!display->mBinding.IsEmpty()) {
// Get the XBL loader.
nsresult rv;
nsCOMPtr<nsIXBLService> xblService =
do_GetService("@mozilla.org/xbl;1", &rv);
if (!xblService)
return rv;
// Load the bindings.
PRBool resolveStyle;
rv = xblService->LoadBindings(aContent, display->mBinding, PR_FALSE, getter_AddRefs(binding), &resolveStyle);
if (!gXBLService)
return NS_ERROR_FAILURE;
rv = gXBLService->LoadBindings(aContent, display->mBinding, PR_FALSE, getter_AddRefs(binding), &resolveStyle);
if (NS_FAILED(rv))
return NS_OK;
@ -7316,7 +7312,7 @@ nsCSSFrameConstructor::ConstructFrameInternal( nsIPresShell* aPresShe
nsCOMPtr<nsIAtom> baseTag;
PRInt32 nameSpaceID;
xblService->ResolveTag(aContent, &nameSpaceID, getter_AddRefs(baseTag));
gXBLService->ResolveTag(aContent, &nameSpaceID, getter_AddRefs(baseTag));
if (baseTag.get() != aTag || aNameSpaceID != nameSpaceID) {
// Construct the frame using the XBL base tag.

View File

@ -29,6 +29,8 @@
#include "nsCOMPtr.h"
#include "nsIStyleContext.h"
#include "nsILayoutHistoryState.h"
#include "nsIXBLService.h"
#include "nsIServiceManager.h"
class nsIDocument;
struct nsFrameItems;
@ -43,13 +45,16 @@ class nsVoidArray;
class nsIFrameManager;
class nsFrameConstructorState;
class nsIDOMHTMLSelectElement;
class nsIXBLService;
class nsCSSFrameConstructor : public nsIStyleFrameConstruction, public nsICSSFrameConstructor {
public:
nsCSSFrameConstructor(void);
virtual ~nsCSSFrameConstructor(void);
// Maintain global objects - gXBLService
static nsresult InitGlobals() { return CallGetService("@mozilla.org/xbl;1", &gXBLService); }
static void ReleaseGlobals() { NS_IF_RELEASE(gXBLService); }
private:
// These are not supported and are not implemented!
nsCSSFrameConstructor(const nsCSSFrameConstructor& aCopy);
@ -950,6 +955,8 @@ protected:
PRBool mHasGfxScrollbars;
nsCOMPtr<nsILayoutHistoryState> mTempFrameTreeState;
static nsIXBLService * gXBLService;
};
#endif /* nsCSSFrameConstructor_h___ */

View File

@ -43,6 +43,7 @@
#include "nsCSSProps.h" // to addref/release table
#include "nsCSSAtoms.h" // to addref/release table
#include "nsColorNames.h" // to addref/release table
#include "nsCSSFrameConstructor.h"
#ifdef INCLUDE_XUL
#include "nsXULAtoms.h"
@ -99,6 +100,8 @@ Initialize(nsIModule* self)
nsSVGAtoms::AddRefAtoms();
#endif
nsCSSFrameConstructor::InitGlobals();
return nsTextTransformer::Initialize();
}
@ -142,6 +145,8 @@ Shutdown(nsIModule* self)
nsSVGAtoms::ReleaseAtoms();
#endif
nsCSSFrameConstructor::ReleaseGlobals();
nsTextTransformer::Shutdown();
}

View File

@ -115,7 +115,6 @@ static NS_DEFINE_CID(kAttributeContentCID, NS_ATTRIBUTECONTENT_CID);
#include "nsIScrollableFrame.h"
#include "nsIServiceManager.h"
#include "nsIXBLService.h"
#include "nsIStyleRuleSupplier.h"
@ -157,6 +156,9 @@ NS_NewPolylineFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame);
#include "nsINodeInfo.h"
#include "prenv.h"
// Global object maintenance
nsIXBLService * nsCSSFrameConstructor::gXBLService = nsnull;
#ifdef DEBUG
// Set the environment variable GECKO_FRAMECTOR_DEBUG_FLAGS to one or
// more of the following flags (comma separated) for handy debug
@ -3452,14 +3454,11 @@ nsCSSFrameConstructor::ConstructDocElementFrame(nsIPresShell* aPresShell,
if (!display->mBinding.IsEmpty()) {
// Get the XBL loader.
nsresult rv;
nsCOMPtr<nsIXBLService> xblService =
do_GetService("@mozilla.org/xbl;1", &rv);
if (!xblService)
return rv;
PRBool resolveStyle;
nsCOMPtr<nsIXBLBinding> binding;
rv = xblService->LoadBindings(aDocElement, display->mBinding, PR_FALSE, getter_AddRefs(binding), &resolveStyle);
if (!gXBLService)
return NS_ERROR_FAILURE;
rv = gXBLService->LoadBindings(aDocElement, display->mBinding, PR_FALSE, getter_AddRefs(binding), &resolveStyle);
if (NS_FAILED(rv))
return NS_OK; // Binding will load asynchronously.
@ -7297,14 +7296,11 @@ nsCSSFrameConstructor::ConstructFrameInternal( nsIPresShell* aPresShe
if (!display->mBinding.IsEmpty()) {
// Get the XBL loader.
nsresult rv;
nsCOMPtr<nsIXBLService> xblService =
do_GetService("@mozilla.org/xbl;1", &rv);
if (!xblService)
return rv;
// Load the bindings.
PRBool resolveStyle;
rv = xblService->LoadBindings(aContent, display->mBinding, PR_FALSE, getter_AddRefs(binding), &resolveStyle);
if (!gXBLService)
return NS_ERROR_FAILURE;
rv = gXBLService->LoadBindings(aContent, display->mBinding, PR_FALSE, getter_AddRefs(binding), &resolveStyle);
if (NS_FAILED(rv))
return NS_OK;
@ -7316,7 +7312,7 @@ nsCSSFrameConstructor::ConstructFrameInternal( nsIPresShell* aPresShe
nsCOMPtr<nsIAtom> baseTag;
PRInt32 nameSpaceID;
xblService->ResolveTag(aContent, &nameSpaceID, getter_AddRefs(baseTag));
gXBLService->ResolveTag(aContent, &nameSpaceID, getter_AddRefs(baseTag));
if (baseTag.get() != aTag || aNameSpaceID != nameSpaceID) {
// Construct the frame using the XBL base tag.

View File

@ -29,6 +29,8 @@
#include "nsCOMPtr.h"
#include "nsIStyleContext.h"
#include "nsILayoutHistoryState.h"
#include "nsIXBLService.h"
#include "nsIServiceManager.h"
class nsIDocument;
struct nsFrameItems;
@ -43,13 +45,16 @@ class nsVoidArray;
class nsIFrameManager;
class nsFrameConstructorState;
class nsIDOMHTMLSelectElement;
class nsIXBLService;
class nsCSSFrameConstructor : public nsIStyleFrameConstruction, public nsICSSFrameConstructor {
public:
nsCSSFrameConstructor(void);
virtual ~nsCSSFrameConstructor(void);
// Maintain global objects - gXBLService
static nsresult InitGlobals() { return CallGetService("@mozilla.org/xbl;1", &gXBLService); }
static void ReleaseGlobals() { NS_IF_RELEASE(gXBLService); }
private:
// These are not supported and are not implemented!
nsCSSFrameConstructor(const nsCSSFrameConstructor& aCopy);
@ -950,6 +955,8 @@ protected:
PRBool mHasGfxScrollbars;
nsCOMPtr<nsILayoutHistoryState> mTempFrameTreeState;
static nsIXBLService * gXBLService;
};
#endif /* nsCSSFrameConstructor_h___ */