diff --git a/content/build/nsContentModule.cpp b/content/build/nsContentModule.cpp index 7cb1828c428f..da04cde23ac5 100644 --- a/content/build/nsContentModule.cpp +++ b/content/build/nsContentModule.cpp @@ -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); diff --git a/content/xul/content/src/nsXULElement.cpp b/content/xul/content/src/nsXULElement.cpp index f22acf80e5fd..9ac49b0466e0 100644 --- a/content/xul/content/src/nsXULElement.cpp +++ b/content/xul/content/src/nsXULElement.cpp @@ -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 tag; PRInt32 dummy; - nsCOMPtr 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 tag; PRInt32 dummy; - nsCOMPtr 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 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; diff --git a/content/xul/content/src/nsXULElement.h b/content/xul/content/src/nsXULElement.h index 78713eaaf702..452c1a7d1d58 100644 --- a/content/xul/content/src/nsXULElement.h +++ b/content/xul/content/src/nsXULElement.h @@ -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; }; diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp index 1c1e5317ceb3..05aa557a4d9c 100644 --- a/layout/base/nsCSSFrameConstructor.cpp +++ b/layout/base/nsCSSFrameConstructor.cpp @@ -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 xblService = - do_GetService("@mozilla.org/xbl;1", &rv); - if (!xblService) - return rv; - PRBool resolveStyle; nsCOMPtr 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 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 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. diff --git a/layout/base/nsCSSFrameConstructor.h b/layout/base/nsCSSFrameConstructor.h index eb620f97a82c..26f1324e9e5e 100644 --- a/layout/base/nsCSSFrameConstructor.h +++ b/layout/base/nsCSSFrameConstructor.h @@ -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 mTempFrameTreeState; + + static nsIXBLService * gXBLService; }; #endif /* nsCSSFrameConstructor_h___ */ diff --git a/layout/build/nsLayoutModule.cpp b/layout/build/nsLayoutModule.cpp index eb0981dc4f51..c2402b73f3b3 100644 --- a/layout/build/nsLayoutModule.cpp +++ b/layout/build/nsLayoutModule.cpp @@ -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(); } diff --git a/layout/html/style/src/nsCSSFrameConstructor.cpp b/layout/html/style/src/nsCSSFrameConstructor.cpp index 1c1e5317ceb3..05aa557a4d9c 100644 --- a/layout/html/style/src/nsCSSFrameConstructor.cpp +++ b/layout/html/style/src/nsCSSFrameConstructor.cpp @@ -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 xblService = - do_GetService("@mozilla.org/xbl;1", &rv); - if (!xblService) - return rv; - PRBool resolveStyle; nsCOMPtr 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 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 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. diff --git a/layout/html/style/src/nsCSSFrameConstructor.h b/layout/html/style/src/nsCSSFrameConstructor.h index eb620f97a82c..26f1324e9e5e 100644 --- a/layout/html/style/src/nsCSSFrameConstructor.h +++ b/layout/html/style/src/nsCSSFrameConstructor.h @@ -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 mTempFrameTreeState; + + static nsIXBLService * gXBLService; }; #endif /* nsCSSFrameConstructor_h___ */