Bug 484121 (5/6) - Avoid needlessly passing nsIContentSink parameters to nsIDTD methods. r+sr=mrbkap

This commit is contained in:
Ben Newman 2009-06-23 14:22:17 -07:00
parent d0673daedb
commit 15437233b4
11 changed files with 62 additions and 69 deletions

View File

@ -103,8 +103,7 @@ public:
* @return
*/
NS_IMETHOD DidBuildModel(nsresult anErrorCode,
nsIParser* aParser,
nsIContentSink* aSink) = 0;
nsIParser* aParser) = 0;
/**
* Called by the parser after the parsing process has concluded
@ -112,21 +111,7 @@ public:
* @param anErrorCode - contains error code resulting from parse process
* @return
*/
NS_IMETHOD BuildModel(nsIParser* aParser, nsITokenizer* aTokenizer,
nsITokenObserver* anObserver,
nsIContentSink* aSink) = 0;
/**
* Called during model building phase of parse process. Each token
* created during the parse phase is stored in a deque (in the
* parser) and are passed to this method so that the DTD can
* process the token. Ultimately, the DTD will transform given
* token into calls onto a contentsink.
* @update gess 3/25/98
* @param aToken -- token object to be put into content model
* @return error code (usually 0)
*/
NS_IMETHOD HandleToken(CToken* aToken,nsIParser* aParser) = 0;
NS_IMETHOD BuildModel(nsIParser* aParser, nsITokenizer* aTokenizer) = 0;
/**
* This method is called to determine whether or not a tag of one
@ -174,9 +159,8 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIDTD, NS_IDTD_IID)
#define NS_DECL_NSIDTD \
NS_IMETHOD WillBuildModel( const CParserContext& aParserContext, nsITokenizer* aTokenizer, nsIContentSink* aSink);\
NS_IMETHOD DidBuildModel(nsresult anErrorCode,nsIParser* aParser,nsIContentSink* aSink);\
NS_IMETHOD BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer,nsITokenObserver* anObserver,nsIContentSink* aSink);\
NS_IMETHOD HandleToken(CToken* aToken,nsIParser* aParser);\
NS_IMETHOD DidBuildModel(nsresult anErrorCode,nsIParser* aParser);\
NS_IMETHOD BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer);\
NS_IMETHOD_(PRBool) CanContain(PRInt32 aParent,PRInt32 aChild) const;\
NS_IMETHOD_(PRBool) IsContainer(PRInt32 aTag) const;\
NS_IMETHOD_(void) Terminate();\

View File

@ -56,14 +56,6 @@ class nsTokenAllocator;
#define NS_ITOKENIZER_IID \
{0xe4238ddc, 0x9eb6, 0x11d2, {0xba, 0xa5, 0x0, 0x10, 0x4b, 0x98, 0x3f, 0xd4 }}
/**
* This interface is used as a callback to objects interested
* in observing the token stream created from the parse process.
*/
class nsITokenObserver {
public:
virtual PRBool operator()(CToken* aToken)=0;
};
/***************************************************************
Notes:

View File

@ -188,7 +188,7 @@ CNavDTD::~CNavDTD()
#endif
}
nsresult
NS_IMETHODIMP
CNavDTD::WillBuildModel(const CParserContext& aParserContext,
nsITokenizer* aTokenizer,
nsIContentSink* aSink)
@ -233,11 +233,9 @@ CNavDTD::WillBuildModel(const CParserContext& aParserContext,
return result;
}
nsresult
NS_IMETHODIMP
CNavDTD::BuildModel(nsIParser* aParser,
nsITokenizer* aTokenizer,
nsITokenObserver* anObserver,
nsIContentSink* aSink)
nsITokenizer* aTokenizer)
{
NS_PRECONDITION(mBodyContext != nsnull,
"Create a context before calling build model");
@ -345,8 +343,7 @@ CNavDTD::BuildModel(nsIParser* aParser,
nsresult
CNavDTD::BuildNeglectedTarget(eHTMLTags aTarget,
eHTMLTokenTypes aType,
nsIParser* aParser,
nsIContentSink* aSink)
nsIParser* aParser)
{
NS_ASSERTION(mTokenizer, "tokenizer is null! unable to build target.");
NS_ASSERTION(mTokenAllocator, "unable to create tokens without an allocator.");
@ -357,15 +354,14 @@ CNavDTD::BuildNeglectedTarget(eHTMLTags aTarget,
CToken* target = mTokenAllocator->CreateTokenOfType(aType, aTarget);
NS_ENSURE_TRUE(target, NS_ERROR_OUT_OF_MEMORY);
mTokenizer->PushTokenFront(target);
return BuildModel(aParser, mTokenizer, 0, aSink);
return BuildModel(aParser, mTokenizer);
}
nsresult
NS_IMETHODIMP
CNavDTD::DidBuildModel(nsresult anErrorCode,
nsIParser* aParser,
nsIContentSink* aSink)
nsIParser* aParser)
{
if (!aSink) {
if (!mSink) {
return NS_OK;
}
@ -378,7 +374,7 @@ CNavDTD::DidBuildModel(nsresult anErrorCode,
// Also note: We ignore the return value of BuildNeglectedTarget, we
// can't reasonably respond to errors (or requests to block) at this
// point in the parsing process.
BuildNeglectedTarget(eHTMLTag_body, eToken_start, aParser, aSink);
BuildNeglectedTarget(eHTMLTag_body, eToken_start, aParser);
}
if (mFlags & NS_DTD_FLAG_MISPLACED_CONTENT) {
// Looks like the misplaced contents are not processed yet.
@ -2126,7 +2122,7 @@ CNavDTD::CollectAttributes(nsIParserNode *aNode, eHTMLTags aTag, PRInt32 aCount)
* @param aChild -- tag enum of child container
* @return PR_TRUE if parent can contain child
*/
PRBool
NS_IMETHODIMP_(PRBool)
CNavDTD::CanContain(PRInt32 aParent, PRInt32 aChild) const
{
PRBool result = gHTMLElements[aParent].CanContain((eHTMLTags)aChild, mDTDMode);
@ -2305,7 +2301,7 @@ CNavDTD::CanOmit(eHTMLTags aParent, eHTMLTags aChild, PRInt32& aParentContains)
* @param aTag -- tag to test as a container
* @return PR_TRUE if given tag can contain other tags
*/
PRBool
NS_IMETHODIMP_(PRBool)
CNavDTD::IsContainer(PRInt32 aTag) const
{
return nsHTMLElement::IsContainer((eHTMLTags)aTag);

View File

@ -258,6 +258,8 @@ private:
*/
PRInt32 LastOf(eHTMLTags aTagSet[], PRInt32 aCount) const;
nsresult HandleToken(CToken* aToken, nsIParser* aParser);
/**
* This method gets called when a start token has been
* encountered in the parse process. If the current container
@ -295,7 +297,7 @@ private:
nsresult HandleProcessingInstructionToken(CToken* aToken);
nsresult HandleDocTypeDeclToken(CToken* aToken);
nsresult BuildNeglectedTarget(eHTMLTags aTarget, eHTMLTokenTypes aType,
nsIParser* aParser, nsIContentSink* aSink);
nsIParser* aParser);
nsresult OpenHTML(const nsCParserNode *aNode);
nsresult OpenBody(const nsCParserNode *aNode);

View File

@ -803,10 +803,12 @@ nsExpatDriver::OpenInputStreamFromExternalDTD(const PRUnichar* aFPIStr,
localURI.swap(uri);
}
nsCOMPtr<nsIContentSink> sink = do_QueryInterface(mSink);
nsCOMPtr<nsIDocument> doc;
if (sink)
doc = do_QueryInterface(sink->GetTarget());
NS_ASSERTION(mSink == nsCOMPtr<nsIExpatSink>(do_QueryInterface(mOriginalSink)),
"In nsExpatDriver::OpenInputStreamFromExternalDTD: "
"mOriginalSink not the same object as mSink?");
if (mOriginalSink)
doc = do_QueryInterface(mOriginalSink->GetTarget());
PRInt16 shouldLoad = nsIContentPolicy::ACCEPT;
rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_DTD,
uri,
@ -1232,6 +1234,8 @@ nsExpatDriver::WillBuildModel(const CParserContext& aParserContext,
return mInternalState;
}
mOriginalSink = aSink;
static const XML_Memory_Handling_Suite memsuite =
{
(void *(*)(size_t))PR_Malloc,
@ -1299,20 +1303,16 @@ nsExpatDriver::WillBuildModel(const CParserContext& aParserContext,
NS_IMETHODIMP
nsExpatDriver::BuildModel(nsIParser* aParser,
nsITokenizer* aTokenizer,
nsITokenObserver* anObserver,
nsIContentSink* aSink)
nsITokenizer* aTokenizer)
{
return mInternalState;
}
NS_IMETHODIMP
nsExpatDriver::DidBuildModel(nsresult anErrorCode,
nsIParser* aParser,
nsIContentSink* aSink)
nsIParser* aParser)
{
// Check for mSink is intentional. This would make sure
// that DidBuildModel() is called only once on the sink.
mOriginalSink = nsnull;
mSink = nsnull;
mExtendedSink = nsnull;
return NS_OK;
@ -1409,7 +1409,7 @@ nsExpatDriver::CopyState(nsITokenizer* aTokenizer)
return NS_OK;
}
NS_IMETHODIMP
nsresult
nsExpatDriver::HandleToken(CToken* aToken,nsIParser* aParser)
{
return NS_OK;

View File

@ -99,6 +99,8 @@ public:
const PRUnichar* aNotationName);
private:
nsresult HandleToken(CToken* aToken, nsIParser* aParser);
// Load up an external stream to get external entity information
nsresult OpenInputStreamFromExternalDTD(const PRUnichar* aFPIStr,
const PRUnichar* aURLStr,
@ -156,8 +158,13 @@ private:
// The length of the data in Expat's buffer (in number of PRUnichars).
PRUint32 mExpatBuffered;
// These sinks all refer the same conceptual object. mOriginalSink is
// identical with the nsIContentSink* passed to WillBuildModel, and exists
// only to avoid QI-ing back to nsIContentSink*.
nsCOMPtr<nsIContentSink> mOriginalSink;
nsCOMPtr<nsIExpatSink> mSink;
nsCOMPtr<nsIExtendedExpatSink> mExtendedSink;
const nsCatalogData* mCatalogData; // weak
nsString mURISpec;
};

View File

@ -73,8 +73,8 @@ NS_IMPL_ISUPPORTS1(nsHTMLTokenizer, nsITokenizer)
nsHTMLTokenizer::nsHTMLTokenizer(nsDTDMode aParseMode,
eParserDocType aDocType,
eParserCommands aCommand,
PRUint16 aFlags) :
nsITokenizer(), mTokenDeque(0), mFlags(aFlags)
PRUint32 aFlags)
: mTokenDeque(0), mFlags(aFlags)
{
if (aParseMode == eDTDMode_full_standards ||
aParseMode == eDTDMode_almost_standards) {

View File

@ -70,7 +70,7 @@ public:
nsHTMLTokenizer(nsDTDMode aParseMode = eDTDMode_quirks,
eParserDocType aDocType = eHTML_Quirks,
eParserCommands aCommand = eViewNormal,
PRUint16 aFlags = 0);
PRUint32 aFlags = 0);
virtual ~nsHTMLTokenizer();
static PRUint32 GetFlags(const nsIContentSink* aSink);

View File

@ -1605,7 +1605,7 @@ nsParser::DidBuildModel(nsresult anErrorCode)
PRBool terminated = mInternalState == NS_ERROR_HTMLPARSER_STOPPARSING;
if (mDTD && mSink &&
mSink->ReadyToCallDidBuildModel(terminated)) {
nsresult dtdResult = mDTD->DidBuildModel(anErrorCode,this,mSink),
nsresult dtdResult = mDTD->DidBuildModel(anErrorCode,this),
sinkResult = mSink->DidBuildModel();
// nsIDTD::DidBuildModel used to be responsible for calling
// nsIContentSink::DidBuildModel, but that obligation isn't expressible
@ -2429,7 +2429,7 @@ nsParser::BuildModel()
if (NS_SUCCEEDED(result)) {
if (mDTD) {
MOZ_TIMER_START(mDTDTime);
result = mDTD->BuildModel(this, theTokenizer, nsnull, mSink);
result = mDTD->BuildModel(this, theTokenizer);
MOZ_TIMER_STOP(mDTDTime);
}
} else {

View File

@ -261,10 +261,11 @@ CViewSourceHTML::~CViewSourceHTML(){
* @param aSink
* @return error code (almost always 0)
*/
nsresult CViewSourceHTML::WillBuildModel(const CParserContext& aParserContext,
nsITokenizer* aTokenizer,
nsIContentSink* aSink){
NS_IMETHODIMP
CViewSourceHTML::WillBuildModel(const CParserContext& aParserContext,
nsITokenizer* aTokenizer,
nsIContentSink* aSink)
{
nsresult result=NS_OK;
#ifdef RAPTOR_PERF_METRICS
@ -326,7 +327,9 @@ nsresult CViewSourceHTML::WillBuildModel(const CParserContext& aParserContext,
* @param aFilename is the name of the file being parsed.
* @return error code (almost always 0)
*/
NS_IMETHODIMP CViewSourceHTML::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer,nsITokenObserver* anObserver,nsIContentSink* aSink) {
NS_IMETHODIMP CViewSourceHTML::BuildModel(nsIParser* aParser,
nsITokenizer* aTokenizer)
{
nsresult result=NS_OK;
if(aTokenizer && aParser) {
@ -535,7 +538,9 @@ void CViewSourceHTML::AddAttrToNode(nsCParserStartNode& aNode,
* @param
* @return
*/
NS_IMETHODIMP CViewSourceHTML::DidBuildModel(nsresult anErrorCode,nsIParser* aParser,nsIContentSink* aSink){
NS_IMETHODIMP CViewSourceHTML::DidBuildModel(nsresult anErrorCode,
nsIParser* aParser)
{
nsresult result= NS_OK;
//ADD CODE HERE TO CLOSE OPEN CONTAINERS...
@ -626,7 +631,9 @@ void CViewSourceHTML::SetVerification(PRBool aEnabled)
* @param aChild -- int tag of child container
* @return PR_TRUE if parent can contain child
*/
PRBool CViewSourceHTML::CanContain(PRInt32 aParent,PRInt32 aChild) const{
NS_IMETHODIMP_(PRBool)
CViewSourceHTML::CanContain(PRInt32 aParent, PRInt32 aChild) const
{
PRBool result=PR_TRUE;
return result;
}
@ -639,7 +646,9 @@ PRBool CViewSourceHTML::CanContain(PRInt32 aParent,PRInt32 aChild) const{
* @param aTag -- tag to test for containership
* @return PR_TRUE if given tag can contain other tags
*/
PRBool CViewSourceHTML::IsContainer(PRInt32 aTag) const{
NS_IMETHODIMP_(PRBool)
CViewSourceHTML::IsContainer(PRInt32 aTag) const
{
PRBool result=PR_TRUE;
return result;
}
@ -827,7 +836,8 @@ nsresult CViewSourceHTML::WriteTag(PRInt32 aTagType,const nsSubstring & aText,PR
* @param aToken -- token object to be put into content model
* @return 0 if all is well; non-zero is an error
*/
NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken,nsIParser* aParser)
nsresult
CViewSourceHTML::HandleToken(CToken* aToken,nsIParser* aParser)
{
nsresult result=NS_OK;
CHTMLToken* theToken= (CHTMLToken*)(aToken);

View File

@ -95,6 +95,8 @@ public:
virtual void SetVerification(PRBool aEnable);
private:
nsresult HandleToken(CToken* aToken, nsIParser* aParser);
nsresult WriteTag(PRInt32 tagType,
const nsSubstring &aText,
PRInt32 attrCount,