Bug 373614 - remove nsIXULContentSink interface, use the underlying class directly.r=smaug, sr=roc

This commit is contained in:
asqueella@gmail.com 2007-03-24 22:02:10 -07:00
parent b33b415350
commit b8c797ca40
5 changed files with 190 additions and 232 deletions

View File

@ -56,7 +56,6 @@ XPIDLSRCS += \
$(NULL)
EXPORTS = \
nsIXULContentSink.h \
nsIXULDocument.h \
nsIXULPrototypeCache.h \
$(NULL)

View File

@ -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__

View File

@ -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<nsNodeInfoManager> 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<nsIURI> mDocumentURL; // [OWNER]
nsRefPtr<nsXULPrototypeDocument> mPrototype; // [OWNER]
nsIParser* mParser; // [OWNER] We use regular pointer b/c of funky exports on nsIParser
nsCOMPtr<nsICSSLoader> mCSSLoader; // [OWNER]
nsCOMPtr<nsICSSParser> mCSSParser; // [OWNER]
nsCOMPtr<nsIScriptSecurityManager> 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 ****/

View File

@ -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 <waterson@netscape.com>
* David Hyatt <hyatt@netscape.com>
* Brendan Eich <brendan@mozilla.org>
* Mark Hammond <mhammond@skippinet.com.au>
*
* 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<nsNodeInfoManager> 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<nsIURI> mDocumentURL; // [OWNER]
nsRefPtr<nsXULPrototypeDocument> mPrototype; // [OWNER]
// We use regular pointer b/c of funky exports on nsIParser:
nsIParser* mParser; // [OWNER]
nsCOMPtr<nsICSSLoader> mCSSLoader; // [OWNER]
nsCOMPtr<nsICSSParser> mCSSParser; // [OWNER]
nsCOMPtr<nsIScriptSecurityManager> mSecMan;
};
#endif /* nsXULContentSink_h__ */

View File

@ -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<nsIXULContentSink> 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<XULContentSinkImpl> 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");