From b8c797ca400763576b9cfd46ddcc01ea619fe353 Mon Sep 17 00:00:00 2001 From: "asqueella@gmail.com" Date: Sat, 24 Mar 2007 22:02:10 -0700 Subject: [PATCH] Bug 373614 - remove nsIXULContentSink interface, use the underlying class directly.r=smaug, sr=roc --- content/xul/document/public/Makefile.in | 1 - .../xul/document/public/nsIXULContentSink.h | 70 ------- content/xul/document/src/nsXULContentSink.cpp | 161 +--------------- content/xul/document/src/nsXULContentSink.h | 181 ++++++++++++++++++ content/xul/document/src/nsXULDocument.cpp | 9 +- 5 files changed, 190 insertions(+), 232 deletions(-) delete mode 100644 content/xul/document/public/nsIXULContentSink.h create mode 100644 content/xul/document/src/nsXULContentSink.h diff --git a/content/xul/document/public/Makefile.in b/content/xul/document/public/Makefile.in index 97a67be883b..cb46aebd811 100644 --- a/content/xul/document/public/Makefile.in +++ b/content/xul/document/public/Makefile.in @@ -56,7 +56,6 @@ XPIDLSRCS += \ $(NULL) EXPORTS = \ - nsIXULContentSink.h \ nsIXULDocument.h \ nsIXULPrototypeCache.h \ $(NULL) diff --git a/content/xul/document/public/nsIXULContentSink.h b/content/xul/document/public/nsIXULContentSink.h deleted file mode 100644 index 0c710cc3cb5..00000000000 --- a/content/xul/document/public/nsIXULContentSink.h +++ /dev/null @@ -1,70 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** 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 Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of 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 nsIXULContentSink_h__ -#define nsIXULContentSink_h__ - -#include "nsIXMLContentSink.h" - -class nsIDocument; -class nsXULPrototypeDocument; - -// {26b87c63-1b6b-46af-b685-11bbf39aa84a} -#define NS_IXULCONTENTSINK_IID \ -{ 0x26b87c63, 0x1b6b, 0x46af, \ - { 0xb6, 0x85, 0x11, 0xbb, 0xf3, 0x9a, 0xa8, 0x4a } } - -class nsIXULContentSink : public nsIXMLContentSink -{ -public: - NS_DECLARE_STATIC_IID_ACCESSOR(NS_IXULCONTENTSINK_IID) - - /** - * Initialize the content sink, giving it an nsIDocument object - * with which to communicate with the outside world, and an - * nsXULPrototypeDocument to build. - */ - NS_IMETHOD Init(nsIDocument* aDocument, nsXULPrototypeDocument* aPrototype) = 0; -}; - -NS_DEFINE_STATIC_IID_ACCESSOR(nsIXULContentSink, NS_IXULCONTENTSINK_IID) - -nsresult -NS_NewXULContentSink(nsIXULContentSink** aResult); - -#endif // nsIXULContentSink_h__ diff --git a/content/xul/document/src/nsXULContentSink.cpp b/content/xul/document/src/nsXULContentSink.cpp index da1598ac9d9..f227990e409 100644 --- a/content/xul/document/src/nsXULContentSink.cpp +++ b/content/xul/document/src/nsXULContentSink.cpp @@ -47,6 +47,7 @@ * see http://developer.mozilla.org/en/docs/XUL */ +#include "nsXULContentSink.h" #include "nsCOMPtr.h" #include "nsForwardReference.h" #include "nsICSSLoader.h" @@ -70,17 +71,13 @@ #include "nsIServiceManager.h" #include "nsIURL.h" #include "nsIViewManager.h" -#include "nsIXULContentSink.h" #include "nsIXULDocument.h" -#include "nsIXULPrototypeCache.h" #include "nsIScriptSecurityManager.h" #include "nsLayoutCID.h" #include "nsNetUtil.h" #include "nsRDFCID.h" #include "nsParserUtils.h" #include "nsIMIMEHeaderParam.h" -#include "nsVoidArray.h" -#include "nsWeakPtr.h" #include "nsXPIDLString.h" #include "nsReadableUtils.h" #include "nsXULElement.h" @@ -93,10 +90,8 @@ #include "nsIObjectInputStream.h" // XXXbe temporary #include "nsXULDocument.h" // XXXbe temporary -#include "nsIExpatSink.h" #include "nsUnicharUtils.h" #include "nsGkAtoms.h" -#include "nsNodeInfoManager.h" #include "nsContentUtils.h" #include "nsAttrName.h" #include "nsXMLContentSink.h" @@ -111,123 +106,6 @@ static NS_DEFINE_CID(kXULPrototypeCacheCID, NS_XULPROTOTYPECACHE_CID); //---------------------------------------------------------------------- -class XULContentSinkImpl : public nsIXULContentSink, - public nsIExpatSink -{ -public: - XULContentSinkImpl(nsresult& aRV); - virtual ~XULContentSinkImpl(); - - // nsISupports - NS_DECL_ISUPPORTS - NS_DECL_NSIEXPATSINK - - // nsIContentSink - NS_IMETHOD WillTokenize(void) { return NS_OK; } - NS_IMETHOD WillBuildModel(void); - NS_IMETHOD DidBuildModel(void); - NS_IMETHOD WillInterrupt(void); - NS_IMETHOD WillResume(void); - NS_IMETHOD SetParser(nsIParser* aParser); - virtual void FlushPendingNotifications(mozFlushType aType) { } - NS_IMETHOD SetDocumentCharset(nsACString& aCharset); - virtual nsISupports *GetTarget(); - - // nsIXULContentSink - NS_IMETHOD Init(nsIDocument* aDocument, nsXULPrototypeDocument* aPrototype); - -protected: - // pseudo-constants - PRUnichar* mText; - PRInt32 mTextLength; - PRInt32 mTextSize; - PRBool mConstrainSize; - - nsresult AddAttributes(const PRUnichar** aAttributes, - const PRUint32 aAttrLen, - nsXULPrototypeElement* aElement); - - nsresult OpenRoot(const PRUnichar** aAttributes, - const PRUint32 aAttrLen, - nsINodeInfo *aNodeInfo); - - nsresult OpenTag(const PRUnichar** aAttributes, - const PRUint32 aAttrLen, - const PRUint32 aLineNumber, - nsINodeInfo *aNodeInfo); - - nsresult OpenScript(const PRUnichar** aAttributes, - const PRUint32 aLineNumber); - - static PRBool IsDataInBuffer(PRUnichar* aBuffer, PRInt32 aLength); - - nsresult SetElementScriptType(nsXULPrototypeElement* element, - const PRUnichar** aAttributes, - const PRUint32 aAttrLen); - - // Text management - nsresult FlushText(PRBool aCreateTextNode = PR_TRUE); - nsresult AddText(const PRUnichar* aText, PRInt32 aLength); - - - nsRefPtr mNodeInfoManager; - - - nsresult NormalizeAttributeString(const PRUnichar *aExpatName, - nsAttrName &aName); - nsresult CreateElement(nsINodeInfo *aNodeInfo, nsXULPrototypeElement** aResult); - - - public: - enum State { eInProlog, eInDocumentElement, eInScript, eInEpilog }; - protected: - - State mState; - - // content stack management - class ContextStack { - protected: - struct Entry { - nsXULPrototypeNode* mNode; - // a LOT of nodes have children; preallocate for 8 - nsAutoVoidArray mChildren; - State mState; - Entry* mNext; - }; - - Entry* mTop; - PRInt32 mDepth; - - public: - ContextStack(); - ~ContextStack(); - - PRInt32 Depth() { return mDepth; } - - nsresult Push(nsXULPrototypeNode* aNode, State aState); - nsresult Pop(State* aState); - - nsresult GetTopNode(nsXULPrototypeNode** aNode); - nsresult GetTopChildren(nsVoidArray** aChildren); - nsresult GetTopNodeScriptType(PRUint32 *aScriptType); - }; - - friend class ContextStack; - ContextStack mContextStack; - - nsWeakPtr mDocument; // [OWNER] - nsCOMPtr mDocumentURL; // [OWNER] - - nsRefPtr mPrototype; // [OWNER] - nsIParser* mParser; // [OWNER] We use regular pointer b/c of funky exports on nsIParser - - nsCOMPtr mCSSLoader; // [OWNER] - nsCOMPtr mCSSParser; // [OWNER] - nsCOMPtr mSecMan; -}; - -//---------------------------------------------------------------------- - XULContentSinkImpl::ContextStack::ContextStack() : mTop(nsnull), mDepth(0) { @@ -332,7 +210,7 @@ XULContentSinkImpl::ContextStack::GetTopNodeScriptType(PRUint32 *aScriptType) //---------------------------------------------------------------------- -XULContentSinkImpl::XULContentSinkImpl(nsresult& rv) +XULContentSinkImpl::XULContentSinkImpl() : mText(nsnull), mTextLength(0), mTextSize(0), @@ -345,8 +223,6 @@ XULContentSinkImpl::XULContentSinkImpl(nsresult& rv) if (! gLog) gLog = PR_NewLogModule("nsXULContentSink"); #endif - - rv = NS_OK; } @@ -385,8 +261,7 @@ XULContentSinkImpl::~XULContentSinkImpl() //---------------------------------------------------------------------- // nsISupports interface -NS_IMPL_ISUPPORTS4(XULContentSinkImpl, - nsIXULContentSink, +NS_IMPL_ISUPPORTS3(XULContentSinkImpl, nsIXMLContentSink, nsIContentSink, nsIExpatSink) @@ -465,12 +340,10 @@ XULContentSinkImpl::GetTarget() } //---------------------------------------------------------------------- -// -// nsIXULContentSink interface -// -NS_IMETHODIMP -XULContentSinkImpl::Init(nsIDocument* aDocument, nsXULPrototypeDocument* aPrototype) +nsresult +XULContentSinkImpl::Init(nsIDocument* aDocument, + nsXULPrototypeDocument* aPrototype) { NS_PRECONDITION(aDocument != nsnull, "null ptr"); if (! aDocument) @@ -631,28 +504,6 @@ XULContentSinkImpl::CreateElement(nsINodeInfo *aNodeInfo, return NS_OK; } -nsresult -NS_NewXULContentSink(nsIXULContentSink** aResult) -{ - NS_PRECONDITION(aResult != nsnull, "null ptr"); - if (! aResult) - return NS_ERROR_NULL_POINTER; - - nsresult rv; - XULContentSinkImpl* sink = new XULContentSinkImpl(rv); - if (! sink) - return NS_ERROR_OUT_OF_MEMORY; - - if (NS_FAILED(rv)) { - delete sink; - return rv; - } - - NS_ADDREF(sink); - *aResult = sink; - return NS_OK; -} - /**** BEGIN NEW APIs ****/ diff --git a/content/xul/document/src/nsXULContentSink.h b/content/xul/document/src/nsXULContentSink.h new file mode 100644 index 00000000000..9506969d432 --- /dev/null +++ b/content/xul/document/src/nsXULContentSink.h @@ -0,0 +1,181 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** 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 Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Chris Waterson + * David Hyatt + * Brendan Eich + * Mark Hammond + * + * Alternatively, the contents of this file may be used under the terms of + * either of 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 nsXULContentSink_h__ +#define nsXULContentSink_h__ + +#include "nsIExpatSink.h" +#include "nsIXMLContentSink.h" +#include "nsAutoPtr.h" +#include "nsNodeInfoManager.h" +#include "nsVoidArray.h" +#include "nsWeakPtr.h" + +class nsICSSLoader; +class nsICSSParser; +class nsIDocument; +class nsIScriptSecurityManager; +class nsAttrName; +class nsXULPrototypeDocument; +class nsXULPrototypeElement; +class nsXULPrototypeNode; + +class XULContentSinkImpl : public nsIXMLContentSink, + public nsIExpatSink +{ +public: + XULContentSinkImpl(); + virtual ~XULContentSinkImpl(); + + // nsISupports + NS_DECL_ISUPPORTS + NS_DECL_NSIEXPATSINK + + // nsIContentSink + NS_IMETHOD WillTokenize(void) { return NS_OK; } + NS_IMETHOD WillBuildModel(void); + NS_IMETHOD DidBuildModel(void); + NS_IMETHOD WillInterrupt(void); + NS_IMETHOD WillResume(void); + NS_IMETHOD SetParser(nsIParser* aParser); + virtual void FlushPendingNotifications(mozFlushType aType) { } + NS_IMETHOD SetDocumentCharset(nsACString& aCharset); + virtual nsISupports *GetTarget(); + + /** + * Initialize the content sink, giving it an nsIDocument object + * with which to communicate with the outside world, and an + * nsXULPrototypeDocument to build. + */ + nsresult Init(nsIDocument* aDocument, nsXULPrototypeDocument* aPrototype); + +protected: + // pseudo-constants + PRUnichar* mText; + PRInt32 mTextLength; + PRInt32 mTextSize; + PRBool mConstrainSize; + + nsresult AddAttributes(const PRUnichar** aAttributes, + const PRUint32 aAttrLen, + nsXULPrototypeElement* aElement); + + nsresult OpenRoot(const PRUnichar** aAttributes, + const PRUint32 aAttrLen, + nsINodeInfo *aNodeInfo); + + nsresult OpenTag(const PRUnichar** aAttributes, + const PRUint32 aAttrLen, + const PRUint32 aLineNumber, + nsINodeInfo *aNodeInfo); + + nsresult OpenScript(const PRUnichar** aAttributes, + const PRUint32 aLineNumber); + + static PRBool IsDataInBuffer(PRUnichar* aBuffer, PRInt32 aLength); + + nsresult SetElementScriptType(nsXULPrototypeElement* element, + const PRUnichar** aAttributes, + const PRUint32 aAttrLen); + + // Text management + nsresult FlushText(PRBool aCreateTextNode = PR_TRUE); + nsresult AddText(const PRUnichar* aText, PRInt32 aLength); + + + nsRefPtr mNodeInfoManager; + + nsresult NormalizeAttributeString(const PRUnichar *aExpatName, + nsAttrName &aName); + nsresult CreateElement(nsINodeInfo *aNodeInfo, + nsXULPrototypeElement** aResult); + + + public: + enum State { eInProlog, eInDocumentElement, eInScript, eInEpilog }; + protected: + + State mState; + + // content stack management + class ContextStack { + protected: + struct Entry { + nsXULPrototypeNode* mNode; + // a LOT of nodes have children; preallocate for 8 + nsAutoVoidArray mChildren; + State mState; + Entry* mNext; + }; + + Entry* mTop; + PRInt32 mDepth; + + public: + ContextStack(); + ~ContextStack(); + + PRInt32 Depth() { return mDepth; } + + nsresult Push(nsXULPrototypeNode* aNode, State aState); + nsresult Pop(State* aState); + + nsresult GetTopNode(nsXULPrototypeNode** aNode); + nsresult GetTopChildren(nsVoidArray** aChildren); + nsresult GetTopNodeScriptType(PRUint32 *aScriptType); + }; + + friend class ContextStack; + ContextStack mContextStack; + + nsWeakPtr mDocument; // [OWNER] + nsCOMPtr mDocumentURL; // [OWNER] + + nsRefPtr mPrototype; // [OWNER] + + // We use regular pointer b/c of funky exports on nsIParser: + nsIParser* mParser; // [OWNER] + nsCOMPtr mCSSLoader; // [OWNER] + nsCOMPtr mCSSParser; // [OWNER] + nsCOMPtr mSecMan; +}; + +#endif /* nsXULContentSink_h__ */ diff --git a/content/xul/document/src/nsXULDocument.cpp b/content/xul/document/src/nsXULDocument.cpp index bd772225a1d..b1da8e6f796 100644 --- a/content/xul/document/src/nsXULDocument.cpp +++ b/content/xul/document/src/nsXULDocument.cpp @@ -84,10 +84,9 @@ #include "nsIDocShell.h" #include "nsGkAtoms.h" #include "nsXMLContentSink.h" -#include "nsIXULContentSink.h" +#include "nsXULContentSink.h" #include "nsXULContentUtils.h" #include "nsIXULOverlayProvider.h" -#include "nsIXULPrototypeCache.h" #include "nsNetUtil.h" #include "nsParserUtils.h" #include "nsParserCIID.h" @@ -2123,10 +2122,8 @@ nsXULDocument::PrepareToLoadPrototype(nsIURI* aURI, const char* aCommand, // Create a XUL content sink, a parser, and kick off a load for // the overlay. - nsCOMPtr sink; - rv = NS_NewXULContentSink(getter_AddRefs(sink)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create XUL content sink"); - if (NS_FAILED(rv)) return rv; + nsRefPtr sink = new XULContentSinkImpl(); + if (!sink) return NS_ERROR_OUT_OF_MEMORY; rv = sink->Init(this, mCurrentPrototype); NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to initialize datasource sink");