diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index 4d85902aeb7..1dd9538c123 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -734,11 +734,8 @@ nsHTMLDocument::StartAutodetection(nsIDocShell *aDocShell, nsAString& aCharset, rv_detect = adp->Init(wss, cdet, this, mParser, PromiseFlatString(aCharset).get(), aCommand); - // The current implementation for SetParserFilter needs to - // be changed to be more XPCOM friendly. See bug #40149 if (mParser) - nsCOMPtr oldFilter = - getter_AddRefs(mParser->SetParserFilter(cdetflt)); + mParser->SetParserFilter(cdetflt); } } } diff --git a/mozilla/htmlparser/public/nsIParser.h b/mozilla/htmlparser/public/nsIParser.h index 86e7ad8b160..8c8f33617b7 100644 --- a/mozilla/htmlparser/public/nsIParser.h +++ b/mozilla/htmlparser/public/nsIParser.h @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* ***** BEGIN LICENSE BLOCK ***** * Version: NPL 1.1/GPL 2.0/LGPL 2.1 * @@ -154,18 +154,17 @@ class nsIParser : public nsISupports { * Select given content sink into parser for parser output * @update gess5/11/98 * @param aSink is the new sink to be used by parser - * @return old sink, or NULL + * @return */ - virtual nsIContentSink* SetContentSink(nsIContentSink* aSink)=0; + NS_IMETHOD_(void) SetContentSink(nsIContentSink* aSink)=0; /** - * retrive the sink set into the parser + * retrieve the sink set into the parser * @update gess5/11/98 - * @param aSink is the new sink to be used by parser - * @return old sink, or NULL + * @return current sink */ - virtual nsIContentSink* GetContentSink(void)=0; + NS_IMETHOD_(nsIContentSink*) GetContentSink(void)=0; /** * Call this method once you've created a parser, and want to instruct it @@ -176,9 +175,9 @@ class nsIParser : public nsISupports { * @param aCommand -- ptrs to string that contains command * @return nada */ - virtual void GetCommand(nsString& aCommand)=0; - virtual void SetCommand(const char* aCommand)=0; - virtual void SetCommand(eParserCommands aParserCommand)=0; + NS_IMETHOD_(void) GetCommand(nsString& aCommand)=0; + NS_IMETHOD_(void) SetCommand(const char* aCommand)=0; + NS_IMETHOD_(void) SetCommand(eParserCommands aParserCommand)=0; /** * Call this method once you've created a parser, and want to instruct it @@ -189,10 +188,10 @@ class nsIParser : public nsISupports { * @param aCharsetSource- the soure of the chares * @return nada */ - virtual void SetDocumentCharset(const nsAString& aCharset, PRInt32 aSource)=0; - virtual void GetDocumentCharset(nsAString& oCharset, PRInt32& oSource)=0; + NS_IMETHOD_(void) SetDocumentCharset(const nsAString& aCharset, PRInt32 aSource)=0; + NS_IMETHOD_(void) GetDocumentCharset(nsAString& oCharset, PRInt32& oSource)=0; - virtual nsIParserFilter* SetParserFilter(nsIParserFilter* aFilter) = 0; + NS_IMETHOD_(void) SetParserFilter(nsIParserFilter* aFilter) = 0; /** * Get the channel associated with this parser @@ -217,32 +216,45 @@ class nsIParser : public nsISupports { ******************************************************************************************/ // Call this method to resume the parser from the blocked state.. - virtual nsresult ContinueParsing() =0; + NS_IMETHOD ContinueParsing() = 0; // Stops parsing temporarily. - virtual void BlockParser() =0; + NS_IMETHOD_(void) BlockParser() = 0; // Open up the parser for tokenization, building up content // model..etc. However, this method does not resume parsing // automatically. It's the callers' responsibility to restart // the parsing engine. - virtual void UnblockParser() =0; + NS_IMETHOD_(void) UnblockParser() = 0; - virtual PRBool IsParserEnabled() =0; - virtual PRBool IsComplete() =0; + NS_IMETHOD_(PRBool) IsParserEnabled() = 0; + NS_IMETHOD_(PRBool) IsComplete() = 0; - virtual nsresult Parse(nsIURI* aURL,nsIRequestObserver* aListener = nsnull,PRBool aEnableVerify=PR_FALSE, void* aKey=0,nsDTDMode aMode=eDTDMode_autodetect) = 0; - virtual nsresult Parse(nsIInputStream* aStream, const nsACString& aMimeType,PRBool aEnableVerify=PR_FALSE, void* aKey=0,nsDTDMode aMode=eDTDMode_autodetect) = 0; - virtual nsresult Parse(const nsAString& aSourceBuffer,void* aKey,const nsACString& aMimeType,PRBool aEnableVerify,PRBool aLastCall,nsDTDMode aMode=eDTDMode_autodetect) = 0; + NS_IMETHOD Parse(nsIURI* aURL, + nsIRequestObserver* aListener = nsnull, + PRBool aEnableVerify = PR_FALSE, + void* aKey = 0, + nsDTDMode aMode = eDTDMode_autodetect) = 0; + NS_IMETHOD Parse(nsIInputStream* aStream, + const nsACString& aMimeType, + PRBool aEnableVerify = PR_FALSE, + void* aKey = 0, + nsDTDMode aMode = eDTDMode_autodetect) = 0; + NS_IMETHOD Parse(const nsAString& aSourceBuffer, + void* aKey, + const nsACString& aMimeType, + PRBool aEnableVerify, + PRBool aLastCall, + nsDTDMode aMode = eDTDMode_autodetect) = 0; - virtual nsresult Terminate(void) = 0; + NS_IMETHOD Terminate(void) = 0; - virtual nsresult ParseFragment(const nsAString& aSourceBuffer, - void* aKey, - nsVoidArray& aTagStack, - PRUint32 anInsertPos, - const nsACString& aContentType, - nsDTDMode aMode=eDTDMode_autodetect) = 0; + NS_IMETHOD ParseFragment(const nsAString& aSourceBuffer, + void* aKey, + nsVoidArray& aTagStack, + PRUint32 anInsertPos, + const nsACString& aContentType, + nsDTDMode aMode = eDTDMode_autodetect) = 0; /** * This method gets called when the tokens have been consumed, and it's time @@ -250,7 +262,7 @@ class nsIParser : public nsISupports { * @update gess5/11/98 * @return error code -- 0 if model building went well . */ - virtual nsresult BuildModel(void)=0; + NS_IMETHOD BuildModel(void) = 0; /** @@ -259,7 +271,7 @@ class nsIParser : public nsISupports { * @update gess 6/9/98 * @return ptr to scanner */ - virtual nsDTDMode GetParseMode(void)=0; + NS_IMETHOD_(nsDTDMode) GetParseMode(void) = 0; /** * Call this method to cancel any pending parsing events. @@ -271,7 +283,7 @@ class nsIParser : public nsISupports { * @return NS_OK if succeeded else ERROR. */ - NS_IMETHOD CancelParsingEvents()=0; + NS_IMETHOD CancelParsingEvents() = 0; }; /* ===========================================================* diff --git a/mozilla/htmlparser/src/nsParser.cpp b/mozilla/htmlparser/src/nsParser.cpp index 83393be9b8f..e595484d3af 100644 --- a/mozilla/htmlparser/src/nsParser.cpp +++ b/mozilla/htmlparser/src/nsParser.cpp @@ -44,12 +44,10 @@ #include "nsIAtom.h" #include "nsParser.h" -#include "nsIContentSink.h" #include "nsString.h" #include "nsCRT.h" #include "nsScanner.h" #include "plstr.h" -#include "nsIParserFilter.h" #include "nsViewSourceHTML.h" #include "nsIStringStream.h" #include "nsIChannel.h" @@ -300,7 +298,7 @@ static PRBool gDumpContent=PR_FALSE; * @param * @return */ -nsParser::nsParser(nsITokenObserver* anObserver) { +nsParser::nsParser() { #ifdef NS_DEBUG if(!gDumpContent) { gDumpContent=(PR_GetEnv("PARSER_DUMP_CONTENT"))? PR_TRUE:PR_FALSE; @@ -308,11 +306,7 @@ nsParser::nsParser(nsITokenObserver* anObserver) { #endif mCharset.Assign(NS_LITERAL_STRING("ISO-8859-1")); - mParserFilter = 0; - mObserver = 0; - mSink=0; mParserContext=0; - mTokenObserver=anObserver; mStreamStatus=0; mCharsetSource=kCharsetUninitialized; mInternalState=NS_OK;; @@ -360,10 +354,6 @@ nsParser::~nsParser() { } #endif - NS_IF_RELEASE(mObserver); - NS_IF_RELEASE(mSink); - NS_IF_RELEASE(mParserFilter); - //don't forget to add code here to delete //what may be several contexts... delete mParserContext; @@ -443,20 +433,13 @@ nsParser::PostContinueEvent() * @param * @return */ -nsIParserFilter * nsParser::SetParserFilter(nsIParserFilter * aFilter) +NS_IMETHODIMP_(void) nsParser::SetParserFilter(nsIParserFilter * aFilter) { - nsIParserFilter* old=mParserFilter; - if(old) - NS_RELEASE(old); - if(aFilter) { - mParserFilter=aFilter; - NS_ADDREF(aFilter); - } - return old; + mParserFilter = aFilter; } -void nsParser::GetCommand(nsString& aCommand) +NS_IMETHODIMP_(void) nsParser::GetCommand(nsString& aCommand) { aCommand = mCommandStr; } @@ -467,10 +450,10 @@ void nsParser::GetCommand(nsString& aCommand) * this allows us to select a DTD which can do, say, view-source. * * @update gess 01/04/99 - * @param aContentSink -- ptr to content sink that will receive output - * @return ptr to previously set contentsink (usually null) + * @param aCommand the command string to set */ -void nsParser::SetCommand(const char* aCommand){ +NS_IMETHODIMP_(void) nsParser::SetCommand(const char* aCommand) +{ nsCAutoString theCommand(aCommand); if(theCommand.Equals(kViewSourceCommand)) mCommand=eViewSource; @@ -486,11 +469,11 @@ void nsParser::SetCommand(const char* aCommand){ * this allows us to select a DTD which can do, say, view-source. * * @update gess 01/04/99 - * @param aContentSink -- ptr to content sink that will receive output - * @return ptr to previously set contentsink (usually null) + * @param aParserCommand the command to set */ -void nsParser::SetCommand(eParserCommands aParserCommand){ - mCommand=aParserCommand; +NS_IMETHODIMP_(void) nsParser::SetCommand(eParserCommands aParserCommand) +{ + mCommand = aParserCommand; } @@ -499,11 +482,13 @@ void nsParser::SetCommand(eParserCommands aParserCommand){ * about what charset to load * * @update ftang 4/23/99 - * @param aCharset- the charest of a document - * @param aCharsetSource- the soure of the chares + * @param aCharset- the charset of a document + * @param aCharsetSource- the source of the charset * @return nada */ -void nsParser::SetDocumentCharset(const nsAString& aCharset, PRInt32 aCharsetSource){ +NS_IMETHODIMP_(void) +nsParser::SetDocumentCharset(const nsAString& aCharset, PRInt32 aCharsetSource) +{ mCharset = aCharset; mCharsetSource = aCharsetSource; if(mParserContext && mParserContext->mScanner) @@ -525,26 +510,23 @@ void nsParser::SetSinkCharset(nsAString& aCharset) * @param nsIContentSink interface for node receiver * @return */ -nsIContentSink* nsParser::SetContentSink(nsIContentSink* aSink) { - NS_PRECONDITION(0!=aSink,"sink cannot be null!"); - nsIContentSink* old=mSink; - - NS_IF_RELEASE(old); - if(aSink) { - mSink=aSink; - NS_ADDREF(aSink); +NS_IMETHODIMP_(void) nsParser::SetContentSink(nsIContentSink* aSink) +{ + NS_PRECONDITION(aSink,"sink cannot be null!"); + mSink = aSink; + + if (mSink) { mSink->SetParser(this); } - return old; } /** * retrive the sink set into the parser * @update gess5/11/98 - * @param aSink is the new sink to be used by parser - * @return old sink, or NULL + * @return current sink */ -nsIContentSink* nsParser::GetContentSink(void){ +NS_IMETHODIMP_(nsIContentSink*) nsParser::GetContentSink(void) +{ return mSink; } @@ -556,34 +538,23 @@ nsIContentSink* nsParser::GetContentSink(void){ * @param aDTD is the object to be registered. * @return nothing. */ -nsresult -nsParser::RegisterDTD(nsIDTD* aDTD){ +NS_IMETHODIMP +nsParser::RegisterDTD(nsIDTD* aDTD) +{ CSharedParserObjects* sharedObjects; nsresult rv = GetSharedObjects(&sharedObjects); NS_ENSURE_SUCCESS(rv, rv); return sharedObjects->RegisterDTD(aDTD); } -/** - * Retrieve scanner from topmost parsecontext - * - * @update gess 01/04/99 - * @return ptr to internal scanner - */ -nsScanner* nsParser::GetScanner(void){ - if(mParserContext) - return mParserContext->mScanner; - return 0; -} - - /** * Retrieve parsemode from topmost parser context * * @update gess 01/04/99 * @return parsemode */ -nsDTDMode nsParser::GetParseMode(void){ +NS_IMETHODIMP_(nsDTDMode) nsParser::GetParseMode(void) +{ if(mParserContext) return mParserContext->mDTDMode; NS_NOTREACHED("no parser context"); @@ -1207,7 +1178,8 @@ FindSuitableDTD(CParserContext& aParserContext, } NS_IMETHODIMP -nsParser::CancelParsingEvents() { +nsParser::CancelParsingEvents() +{ if (mFlags & NS_PARSER_FLAG_PENDING_CONTINUE_EVENT) { NS_ASSERTION(mEventQueue,"Event queue is null"); // Revoke all pending continue parsing events @@ -1334,7 +1306,8 @@ CParserContext* nsParser::PopContext() { * @param aState determines whether we parse/tokenize or just cache. * @return current state */ -void nsParser::SetUnusedInput(nsString& aBuffer) { +void nsParser::SetUnusedInput(nsString& aBuffer) +{ mUnusedInput=aBuffer; } @@ -1346,7 +1319,8 @@ void nsParser::SetUnusedInput(nsString& aBuffer) { * @update gess 7/4/99 * @return should return NS_OK once implemented */ -nsresult nsParser::Terminate(void){ +NS_IMETHODIMP nsParser::Terminate(void) +{ nsresult result = NS_OK; if (mParserContext && mParserContext->mDTD) { mParserContext->mDTD->Terminate(); @@ -1373,8 +1347,8 @@ nsresult nsParser::Terminate(void){ * @param aState determines whether we parse/tokenize or just cache. * @return current state */ -nsresult nsParser::ContinueParsing(){ - +NS_IMETHODIMP nsParser::ContinueParsing() +{ // If the stream has already finished, there's a good chance // that we might start closing things down when the parser // is reenabled. To make sure that we're not deleted across @@ -1401,7 +1375,8 @@ nsresult nsParser::ContinueParsing(){ * @update * @return */ -void nsParser::BlockParser() { +NS_IMETHODIMP_(void) nsParser::BlockParser() +{ mFlags &= ~NS_PARSER_FLAG_PARSER_ENABLED; MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: nsParser::BlockParser(), this=%p\n", this)); MOZ_TIMER_STOP(mParseTime); @@ -1416,7 +1391,8 @@ void nsParser::BlockParser() { * @update * @return */ -void nsParser::UnblockParser() { +NS_IMETHODIMP_(void) nsParser::UnblockParser() +{ mFlags |= NS_PARSER_FLAG_PARSER_ENABLED; MOZ_TIMER_DEBUGLOG(("Start: Parse Time: nsParser::UnblockParser(), this=%p\n", this)); MOZ_TIMER_START(mParseTime); @@ -1428,7 +1404,8 @@ void nsParser::UnblockParser() { * @update vidur 4/12/99 * @return current state */ -PRBool nsParser::IsParserEnabled() { +NS_IMETHODIMP_(PRBool) nsParser::IsParserEnabled() +{ return mFlags & NS_PARSER_FLAG_PARSER_ENABLED; } @@ -1438,7 +1415,8 @@ PRBool nsParser::IsParserEnabled() { * @update rickg 5/12/01 * @return complete state */ -PRBool nsParser::IsComplete() { +NS_IMETHODIMP_(PRBool) nsParser::IsComplete() +{ return !(mFlags & NS_PARSER_FLAG_PENDING_CONTINUE_EVENT); } @@ -1472,13 +1450,18 @@ void nsParser::SetCanInterrupt(PRBool aCanInterrupt) { * @param aFilename -- const char* containing file to be parsed. * @return error code -- 0 if ok, non-zero if error. */ -nsresult nsParser::Parse(nsIURI* aURL,nsIRequestObserver* aListener,PRBool aVerifyEnabled, void* aKey,nsDTDMode aMode) { +NS_IMETHODIMP +nsParser::Parse(nsIURI* aURL, + nsIRequestObserver* aListener, + PRBool aVerifyEnabled, + void* aKey, + nsDTDMode aMode) +{ NS_PRECONDITION(aURL, "Error: Null URL given"); nsresult result=kBadURL; mObserver = aListener; - NS_IF_ADDREF(mObserver); if (aVerifyEnabled) { mFlags |= NS_PARSER_FLAG_DTD_VERIFICATION; @@ -1518,7 +1501,13 @@ nsresult nsParser::Parse(nsIURI* aURL,nsIRequestObserver* aListener,PRBool aVeri * @param aStream is the i/o source * @return error code -- 0 if ok, non-zero if error. */ -nsresult nsParser::Parse(nsIInputStream* aStream,const nsACString& aMimeType,PRBool aVerifyEnabled, void* aKey,nsDTDMode aMode){ +NS_IMETHODIMP +nsParser::Parse(nsIInputStream* aStream, + const nsACString& aMimeType, + PRBool aVerifyEnabled, + void* aKey, + nsDTDMode aMode) +{ if (aVerifyEnabled) { mFlags |= NS_PARSER_FLAG_DTD_VERIFICATION; } @@ -1564,10 +1553,14 @@ nsresult nsParser::Parse(nsIInputStream* aStream,const nsACString& aMimeType,PRB * @param aMimeType tells us what type of content to expect in the given string * @return error code -- 0 if ok, non-zero if error. */ -nsresult nsParser::Parse(const nsAString& aSourceBuffer, void* aKey, - const nsACString& aMimeType, - PRBool aVerifyEnabled, PRBool aLastCall, - nsDTDMode aMode){ +NS_IMETHODIMP +nsParser::Parse(const nsAString& aSourceBuffer, + void* aKey, + const nsACString& aMimeType, + PRBool aVerifyEnabled, + PRBool aLastCall, + nsDTDMode aMode) +{ //NOTE: Make sure that updates to this method don't cause // bug #2361 to break again! @@ -1676,13 +1669,14 @@ nsresult nsParser::Parse(const nsAString& aSourceBuffer, void* aKey, * @param * @return */ -nsresult nsParser::ParseFragment(const nsAString& aSourceBuffer, - void* aKey, - nsVoidArray& aTagStack, - PRUint32 anInsertPos, - const nsACString& aMimeType, - nsDTDMode aMode){ - +NS_IMETHODIMP +nsParser::ParseFragment(const nsAString& aSourceBuffer, + void* aKey, + nsVoidArray& aTagStack, + PRUint32 anInsertPos, + const nsACString& aMimeType, + nsDTDMode aMode) +{ nsresult result = NS_OK; nsAutoString theContext; PRUint32 theCount = aTagStack.Count(); @@ -1901,7 +1895,7 @@ nsresult nsParser::BuildModel() { if (theRootDTD) { MOZ_TIMER_START(mDTDTime); - result = theRootDTD->BuildModel(this, theTokenizer, mTokenObserver, mSink); + result = theRootDTD->BuildModel(this, theTokenizer, nsnull, mSink); MOZ_TIMER_STOP(mDTDTime); } @@ -1951,7 +1945,7 @@ nsresult nsParser::OnStartRequest(nsIRequest *request, nsISupports* aContext) { "Parser's nsIStreamListener API was not setup " "correctly in constructor."); - if (nsnull != mObserver) { + if (mObserver) { mObserver->OnStartRequest(request, aContext); } mParserContext->mStreamListenerState = eOnStart; @@ -2454,7 +2448,7 @@ nsresult nsParser::OnStopRequest(nsIRequest *request, nsISupports* aContext, // XXX Should we wait to notify our observers as well if the // parser isn't yet enabled? - if (nsnull != mObserver) { + if (mObserver) { mObserver->OnStopRequest(request, aContext, status); } @@ -2591,15 +2585,6 @@ PRBool nsParser::DidTokenize(PRBool aIsFinalChunk){ if (NS_SUCCEEDED(rv) && theTokenizer) { result = theTokenizer->DidTokenize(aIsFinalChunk); - if(mTokenObserver) { - PRInt32 theCount=theTokenizer->GetCount(); - PRInt32 theIndex; - for(theIndex=0;theIndexGetTokenAt(theIndex))){ - //add code here to pull unwanted tokens out of the stack... - } - }//for - }//if } return result; } diff --git a/mozilla/htmlparser/src/nsParser.h b/mozilla/htmlparser/src/nsParser.h index d16b7aac6db..49c71c30a23 100644 --- a/mozilla/htmlparser/src/nsParser.h +++ b/mozilla/htmlparser/src/nsParser.h @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* ***** BEGIN LICENSE BLOCK ***** * Version: NPL 1.1/GPL 2.0/LGPL 2.1 * @@ -86,11 +86,11 @@ #include "nsDTDUtils.h" #include "nsTimer.h" #include "nsIEventQueue.h" +#include "nsIContentSink.h" +#include "nsIParserFilter.h" -class IContentSink; class nsIDTD; class nsScanner; -class nsIParserFilter; class nsIProgressEventSink; #ifdef XP_WIN @@ -113,7 +113,7 @@ class nsParser : public nsIParser, * default constructor * @update gess5/11/98 */ - nsParser(nsITokenObserver* anObserver=0); + nsParser(); /** @@ -128,7 +128,7 @@ class nsParser : public nsIParser, * @param aSink is the new sink to be used by parser * @return old sink, or NULL */ - virtual nsIContentSink* SetContentSink(nsIContentSink* aSink); + NS_IMETHOD_(void) SetContentSink(nsIContentSink* aSink); /** * retrive the sink set into the parser @@ -136,40 +136,40 @@ class nsParser : public nsIParser, * @param aSink is the new sink to be used by parser * @return old sink, or NULL */ - virtual nsIContentSink* GetContentSink(void); + NS_IMETHOD_(nsIContentSink*) GetContentSink(void); /** * Call this method once you've created a parser, and want to instruct it - * about the command which caused the parser to be constructed. For example, + * about the command which caused the parser to be constructed. For example, * this allows us to select a DTD which can do, say, view-source. * * @update gess 3/25/98 - * @param aContentSink -- ptr to content sink that will receive output - * @return ptr to previously set contentsink (usually null) + * @param aCommand -- ptrs to string that contains command + * @return nada */ - virtual void GetCommand(nsString& aCommand); - virtual void SetCommand(const char* aCommand); - virtual void SetCommand(eParserCommands aParserCommand); + NS_IMETHOD_(void) GetCommand(nsString& aCommand); + NS_IMETHOD_(void) SetCommand(const char* aCommand); + NS_IMETHOD_(void) SetCommand(eParserCommands aParserCommand); /** * Call this method once you've created a parser, and want to instruct it * about what charset to load * * @update ftang 4/23/99 - * @param aCharset- the charest of a document - * @param aCharsetSource- the soure of the chares + * @param aCharset- the charset of a document + * @param aCharsetSource- the source of the charset * @return nada */ - virtual void SetDocumentCharset(const nsAString& aCharset, PRInt32 aSource); + NS_IMETHOD_(void) SetDocumentCharset(const nsAString& aCharset, PRInt32 aSource); - void GetDocumentCharset(nsAString& aCharset, PRInt32& aSource) + NS_IMETHOD_(void) GetDocumentCharset(nsAString& aCharset, PRInt32& aSource) { aCharset = mCharset; aSource = mCharsetSource; } - virtual nsIParserFilter* SetParserFilter(nsIParserFilter* aFilter); + NS_IMETHOD_(void) SetParserFilter(nsIParserFilter* aFilter); NS_IMETHOD RegisterDTD(nsIDTD* aDTD); @@ -179,15 +179,7 @@ class nsParser : public nsIParser, * @update gess 6/9/98 * @return ptr to scanner */ - virtual nsDTDMode GetParseMode(void); - - /** - * Retrieve the scanner from the topmost parser context - * - * @update gess 6/9/98 - * @return ptr to scanner - */ - virtual nsScanner* GetScanner(void); + NS_IMETHOD_(nsDTDMode) GetParseMode(void); /** * Cause parser to parse input from given URL @@ -196,7 +188,11 @@ class nsParser : public nsIParser, * @param aListener is a listener to forward notifications to * @return TRUE if all went well -- FALSE otherwise */ - virtual nsresult Parse(nsIURI* aURL,nsIRequestObserver* aListener,PRBool aEnableVerify=PR_FALSE,void* aKey=0,nsDTDMode aMode=eDTDMode_autodetect); + NS_IMETHOD Parse(nsIURI* aURL, + nsIRequestObserver* aListener = nsnull, + PRBool aEnableVerify = PR_FALSE, + void* aKey = 0, + nsDTDMode aMode = eDTDMode_autodetect); /** * Cause parser to parse input from given stream @@ -204,7 +200,11 @@ class nsParser : public nsIParser, * @param aStream is the i/o source * @return TRUE if all went well -- FALSE otherwise */ - virtual nsresult Parse(nsIInputStream* aStream,const nsACString& aMimeType,PRBool aEnableVerify=PR_FALSE,void* aKey=0,nsDTDMode aMode=eDTDMode_autodetect); + NS_IMETHOD Parse(nsIInputStream* aStream, + const nsACString& aMimeType, + PRBool aEnableVerify = PR_FALSE, + void* aKey = 0, + nsDTDMode aMode = eDTDMode_autodetect); /** * @update gess5/11/98 @@ -212,16 +212,29 @@ class nsParser : public nsIParser, * @param appendTokens tells us whether we should insert tokens inline, or append them. * @return TRUE if all went well -- FALSE otherwise */ - virtual nsresult Parse(const nsAString& aSourceBuffer,void* aKey,const nsACString& aContentType,PRBool aEnableVerify=PR_FALSE,PRBool aLastCall=PR_FALSE,nsDTDMode aMode=eDTDMode_autodetect); + NS_IMETHOD Parse(const nsAString& aSourceBuffer, + void* aKey, + const nsACString& aContentType, + PRBool aEnableVerify, + PRBool aLastCall, + nsDTDMode aMode = eDTDMode_autodetect); - virtual nsresult ParseFragment(const nsAString& aSourceBuffer, - void* aKey, - nsVoidArray& aTagStack, - PRUint32 anInsertPos, - const nsACString& aContentType, - nsDTDMode aMode=eDTDMode_autodetect); + NS_IMETHOD ParseFragment(const nsAString& aSourceBuffer, + void* aKey, + nsVoidArray& aTagStack, + PRUint32 anInsertPos, + const nsACString& aContentType, + nsDTDMode aMode = eDTDMode_autodetect); + /** + * This method gets called when the tokens have been consumed, and it's time + * to build the model via the content sink. + * @update gess5/11/98 + * @return YES if model building went well -- NO otherwise. + */ + NS_IMETHOD BuildModel(void); + /** * Call this when you want control whether or not the parser will parse * and tokenize input (TRUE), or whether it just caches input to be @@ -231,10 +244,10 @@ class nsParser : public nsIParser, * @param aState determines whether we parse/tokenize or just cache. * @return current state */ - virtual nsresult ContinueParsing(); - virtual void BlockParser(); - virtual void UnblockParser(); - virtual nsresult Terminate(void); + NS_IMETHOD ContinueParsing(); + NS_IMETHOD_(void) BlockParser(); + NS_IMETHOD_(void) UnblockParser(); + NS_IMETHOD Terminate(void); /** * Call this to query whether the parser is enabled or not. @@ -242,7 +255,7 @@ class nsParser : public nsIParser, * @update vidur 4/12/99 * @return current state */ - virtual PRBool IsParserEnabled(); + NS_IMETHOD_(PRBool) IsParserEnabled(); /** * Call this to query whether the parser thinks it's done with parsing. @@ -250,7 +263,7 @@ class nsParser : public nsIParser, * @update rickg 5/12/01 * @return complete state */ - virtual PRBool IsComplete(); + NS_IMETHOD_(PRBool) IsComplete(); /** * This rather arcane method (hack) is used as a signal between the @@ -377,14 +390,6 @@ protected: * @return */ nsresult DidBuildModel(nsresult anErrorCode); - - /** - * This method gets called when the tokens have been consumed, and it's time - * to build the model via the content sink. - * @update gess5/11/98 - * @return YES if model building went well -- NO otherwise. - */ - virtual nsresult BuildModel(void); private: @@ -432,14 +437,13 @@ protected: //********************************************* - nsCOMPtr mEventQueue; - CParserContext* mParserContext; - nsIRequestObserver* mObserver; - nsIContentSink* mSink; + nsCOMPtr mEventQueue; + CParserContext* mParserContext; + nsCOMPtr mObserver; + nsCOMPtr mSink; - nsIParserFilter* mParserFilter; - nsITokenObserver* mTokenObserver; - nsTokenAllocator mTokenAllocator; + nsCOMPtr mParserFilter; + nsTokenAllocator mTokenAllocator; eParserCommands mCommand; nsresult mInternalState; diff --git a/mozilla/parser/htmlparser/public/nsIParser.h b/mozilla/parser/htmlparser/public/nsIParser.h index 86e7ad8b160..8c8f33617b7 100644 --- a/mozilla/parser/htmlparser/public/nsIParser.h +++ b/mozilla/parser/htmlparser/public/nsIParser.h @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* ***** BEGIN LICENSE BLOCK ***** * Version: NPL 1.1/GPL 2.0/LGPL 2.1 * @@ -154,18 +154,17 @@ class nsIParser : public nsISupports { * Select given content sink into parser for parser output * @update gess5/11/98 * @param aSink is the new sink to be used by parser - * @return old sink, or NULL + * @return */ - virtual nsIContentSink* SetContentSink(nsIContentSink* aSink)=0; + NS_IMETHOD_(void) SetContentSink(nsIContentSink* aSink)=0; /** - * retrive the sink set into the parser + * retrieve the sink set into the parser * @update gess5/11/98 - * @param aSink is the new sink to be used by parser - * @return old sink, or NULL + * @return current sink */ - virtual nsIContentSink* GetContentSink(void)=0; + NS_IMETHOD_(nsIContentSink*) GetContentSink(void)=0; /** * Call this method once you've created a parser, and want to instruct it @@ -176,9 +175,9 @@ class nsIParser : public nsISupports { * @param aCommand -- ptrs to string that contains command * @return nada */ - virtual void GetCommand(nsString& aCommand)=0; - virtual void SetCommand(const char* aCommand)=0; - virtual void SetCommand(eParserCommands aParserCommand)=0; + NS_IMETHOD_(void) GetCommand(nsString& aCommand)=0; + NS_IMETHOD_(void) SetCommand(const char* aCommand)=0; + NS_IMETHOD_(void) SetCommand(eParserCommands aParserCommand)=0; /** * Call this method once you've created a parser, and want to instruct it @@ -189,10 +188,10 @@ class nsIParser : public nsISupports { * @param aCharsetSource- the soure of the chares * @return nada */ - virtual void SetDocumentCharset(const nsAString& aCharset, PRInt32 aSource)=0; - virtual void GetDocumentCharset(nsAString& oCharset, PRInt32& oSource)=0; + NS_IMETHOD_(void) SetDocumentCharset(const nsAString& aCharset, PRInt32 aSource)=0; + NS_IMETHOD_(void) GetDocumentCharset(nsAString& oCharset, PRInt32& oSource)=0; - virtual nsIParserFilter* SetParserFilter(nsIParserFilter* aFilter) = 0; + NS_IMETHOD_(void) SetParserFilter(nsIParserFilter* aFilter) = 0; /** * Get the channel associated with this parser @@ -217,32 +216,45 @@ class nsIParser : public nsISupports { ******************************************************************************************/ // Call this method to resume the parser from the blocked state.. - virtual nsresult ContinueParsing() =0; + NS_IMETHOD ContinueParsing() = 0; // Stops parsing temporarily. - virtual void BlockParser() =0; + NS_IMETHOD_(void) BlockParser() = 0; // Open up the parser for tokenization, building up content // model..etc. However, this method does not resume parsing // automatically. It's the callers' responsibility to restart // the parsing engine. - virtual void UnblockParser() =0; + NS_IMETHOD_(void) UnblockParser() = 0; - virtual PRBool IsParserEnabled() =0; - virtual PRBool IsComplete() =0; + NS_IMETHOD_(PRBool) IsParserEnabled() = 0; + NS_IMETHOD_(PRBool) IsComplete() = 0; - virtual nsresult Parse(nsIURI* aURL,nsIRequestObserver* aListener = nsnull,PRBool aEnableVerify=PR_FALSE, void* aKey=0,nsDTDMode aMode=eDTDMode_autodetect) = 0; - virtual nsresult Parse(nsIInputStream* aStream, const nsACString& aMimeType,PRBool aEnableVerify=PR_FALSE, void* aKey=0,nsDTDMode aMode=eDTDMode_autodetect) = 0; - virtual nsresult Parse(const nsAString& aSourceBuffer,void* aKey,const nsACString& aMimeType,PRBool aEnableVerify,PRBool aLastCall,nsDTDMode aMode=eDTDMode_autodetect) = 0; + NS_IMETHOD Parse(nsIURI* aURL, + nsIRequestObserver* aListener = nsnull, + PRBool aEnableVerify = PR_FALSE, + void* aKey = 0, + nsDTDMode aMode = eDTDMode_autodetect) = 0; + NS_IMETHOD Parse(nsIInputStream* aStream, + const nsACString& aMimeType, + PRBool aEnableVerify = PR_FALSE, + void* aKey = 0, + nsDTDMode aMode = eDTDMode_autodetect) = 0; + NS_IMETHOD Parse(const nsAString& aSourceBuffer, + void* aKey, + const nsACString& aMimeType, + PRBool aEnableVerify, + PRBool aLastCall, + nsDTDMode aMode = eDTDMode_autodetect) = 0; - virtual nsresult Terminate(void) = 0; + NS_IMETHOD Terminate(void) = 0; - virtual nsresult ParseFragment(const nsAString& aSourceBuffer, - void* aKey, - nsVoidArray& aTagStack, - PRUint32 anInsertPos, - const nsACString& aContentType, - nsDTDMode aMode=eDTDMode_autodetect) = 0; + NS_IMETHOD ParseFragment(const nsAString& aSourceBuffer, + void* aKey, + nsVoidArray& aTagStack, + PRUint32 anInsertPos, + const nsACString& aContentType, + nsDTDMode aMode = eDTDMode_autodetect) = 0; /** * This method gets called when the tokens have been consumed, and it's time @@ -250,7 +262,7 @@ class nsIParser : public nsISupports { * @update gess5/11/98 * @return error code -- 0 if model building went well . */ - virtual nsresult BuildModel(void)=0; + NS_IMETHOD BuildModel(void) = 0; /** @@ -259,7 +271,7 @@ class nsIParser : public nsISupports { * @update gess 6/9/98 * @return ptr to scanner */ - virtual nsDTDMode GetParseMode(void)=0; + NS_IMETHOD_(nsDTDMode) GetParseMode(void) = 0; /** * Call this method to cancel any pending parsing events. @@ -271,7 +283,7 @@ class nsIParser : public nsISupports { * @return NS_OK if succeeded else ERROR. */ - NS_IMETHOD CancelParsingEvents()=0; + NS_IMETHOD CancelParsingEvents() = 0; }; /* ===========================================================* diff --git a/mozilla/parser/htmlparser/src/nsParser.cpp b/mozilla/parser/htmlparser/src/nsParser.cpp index 83393be9b8f..e595484d3af 100644 --- a/mozilla/parser/htmlparser/src/nsParser.cpp +++ b/mozilla/parser/htmlparser/src/nsParser.cpp @@ -44,12 +44,10 @@ #include "nsIAtom.h" #include "nsParser.h" -#include "nsIContentSink.h" #include "nsString.h" #include "nsCRT.h" #include "nsScanner.h" #include "plstr.h" -#include "nsIParserFilter.h" #include "nsViewSourceHTML.h" #include "nsIStringStream.h" #include "nsIChannel.h" @@ -300,7 +298,7 @@ static PRBool gDumpContent=PR_FALSE; * @param * @return */ -nsParser::nsParser(nsITokenObserver* anObserver) { +nsParser::nsParser() { #ifdef NS_DEBUG if(!gDumpContent) { gDumpContent=(PR_GetEnv("PARSER_DUMP_CONTENT"))? PR_TRUE:PR_FALSE; @@ -308,11 +306,7 @@ nsParser::nsParser(nsITokenObserver* anObserver) { #endif mCharset.Assign(NS_LITERAL_STRING("ISO-8859-1")); - mParserFilter = 0; - mObserver = 0; - mSink=0; mParserContext=0; - mTokenObserver=anObserver; mStreamStatus=0; mCharsetSource=kCharsetUninitialized; mInternalState=NS_OK;; @@ -360,10 +354,6 @@ nsParser::~nsParser() { } #endif - NS_IF_RELEASE(mObserver); - NS_IF_RELEASE(mSink); - NS_IF_RELEASE(mParserFilter); - //don't forget to add code here to delete //what may be several contexts... delete mParserContext; @@ -443,20 +433,13 @@ nsParser::PostContinueEvent() * @param * @return */ -nsIParserFilter * nsParser::SetParserFilter(nsIParserFilter * aFilter) +NS_IMETHODIMP_(void) nsParser::SetParserFilter(nsIParserFilter * aFilter) { - nsIParserFilter* old=mParserFilter; - if(old) - NS_RELEASE(old); - if(aFilter) { - mParserFilter=aFilter; - NS_ADDREF(aFilter); - } - return old; + mParserFilter = aFilter; } -void nsParser::GetCommand(nsString& aCommand) +NS_IMETHODIMP_(void) nsParser::GetCommand(nsString& aCommand) { aCommand = mCommandStr; } @@ -467,10 +450,10 @@ void nsParser::GetCommand(nsString& aCommand) * this allows us to select a DTD which can do, say, view-source. * * @update gess 01/04/99 - * @param aContentSink -- ptr to content sink that will receive output - * @return ptr to previously set contentsink (usually null) + * @param aCommand the command string to set */ -void nsParser::SetCommand(const char* aCommand){ +NS_IMETHODIMP_(void) nsParser::SetCommand(const char* aCommand) +{ nsCAutoString theCommand(aCommand); if(theCommand.Equals(kViewSourceCommand)) mCommand=eViewSource; @@ -486,11 +469,11 @@ void nsParser::SetCommand(const char* aCommand){ * this allows us to select a DTD which can do, say, view-source. * * @update gess 01/04/99 - * @param aContentSink -- ptr to content sink that will receive output - * @return ptr to previously set contentsink (usually null) + * @param aParserCommand the command to set */ -void nsParser::SetCommand(eParserCommands aParserCommand){ - mCommand=aParserCommand; +NS_IMETHODIMP_(void) nsParser::SetCommand(eParserCommands aParserCommand) +{ + mCommand = aParserCommand; } @@ -499,11 +482,13 @@ void nsParser::SetCommand(eParserCommands aParserCommand){ * about what charset to load * * @update ftang 4/23/99 - * @param aCharset- the charest of a document - * @param aCharsetSource- the soure of the chares + * @param aCharset- the charset of a document + * @param aCharsetSource- the source of the charset * @return nada */ -void nsParser::SetDocumentCharset(const nsAString& aCharset, PRInt32 aCharsetSource){ +NS_IMETHODIMP_(void) +nsParser::SetDocumentCharset(const nsAString& aCharset, PRInt32 aCharsetSource) +{ mCharset = aCharset; mCharsetSource = aCharsetSource; if(mParserContext && mParserContext->mScanner) @@ -525,26 +510,23 @@ void nsParser::SetSinkCharset(nsAString& aCharset) * @param nsIContentSink interface for node receiver * @return */ -nsIContentSink* nsParser::SetContentSink(nsIContentSink* aSink) { - NS_PRECONDITION(0!=aSink,"sink cannot be null!"); - nsIContentSink* old=mSink; - - NS_IF_RELEASE(old); - if(aSink) { - mSink=aSink; - NS_ADDREF(aSink); +NS_IMETHODIMP_(void) nsParser::SetContentSink(nsIContentSink* aSink) +{ + NS_PRECONDITION(aSink,"sink cannot be null!"); + mSink = aSink; + + if (mSink) { mSink->SetParser(this); } - return old; } /** * retrive the sink set into the parser * @update gess5/11/98 - * @param aSink is the new sink to be used by parser - * @return old sink, or NULL + * @return current sink */ -nsIContentSink* nsParser::GetContentSink(void){ +NS_IMETHODIMP_(nsIContentSink*) nsParser::GetContentSink(void) +{ return mSink; } @@ -556,34 +538,23 @@ nsIContentSink* nsParser::GetContentSink(void){ * @param aDTD is the object to be registered. * @return nothing. */ -nsresult -nsParser::RegisterDTD(nsIDTD* aDTD){ +NS_IMETHODIMP +nsParser::RegisterDTD(nsIDTD* aDTD) +{ CSharedParserObjects* sharedObjects; nsresult rv = GetSharedObjects(&sharedObjects); NS_ENSURE_SUCCESS(rv, rv); return sharedObjects->RegisterDTD(aDTD); } -/** - * Retrieve scanner from topmost parsecontext - * - * @update gess 01/04/99 - * @return ptr to internal scanner - */ -nsScanner* nsParser::GetScanner(void){ - if(mParserContext) - return mParserContext->mScanner; - return 0; -} - - /** * Retrieve parsemode from topmost parser context * * @update gess 01/04/99 * @return parsemode */ -nsDTDMode nsParser::GetParseMode(void){ +NS_IMETHODIMP_(nsDTDMode) nsParser::GetParseMode(void) +{ if(mParserContext) return mParserContext->mDTDMode; NS_NOTREACHED("no parser context"); @@ -1207,7 +1178,8 @@ FindSuitableDTD(CParserContext& aParserContext, } NS_IMETHODIMP -nsParser::CancelParsingEvents() { +nsParser::CancelParsingEvents() +{ if (mFlags & NS_PARSER_FLAG_PENDING_CONTINUE_EVENT) { NS_ASSERTION(mEventQueue,"Event queue is null"); // Revoke all pending continue parsing events @@ -1334,7 +1306,8 @@ CParserContext* nsParser::PopContext() { * @param aState determines whether we parse/tokenize or just cache. * @return current state */ -void nsParser::SetUnusedInput(nsString& aBuffer) { +void nsParser::SetUnusedInput(nsString& aBuffer) +{ mUnusedInput=aBuffer; } @@ -1346,7 +1319,8 @@ void nsParser::SetUnusedInput(nsString& aBuffer) { * @update gess 7/4/99 * @return should return NS_OK once implemented */ -nsresult nsParser::Terminate(void){ +NS_IMETHODIMP nsParser::Terminate(void) +{ nsresult result = NS_OK; if (mParserContext && mParserContext->mDTD) { mParserContext->mDTD->Terminate(); @@ -1373,8 +1347,8 @@ nsresult nsParser::Terminate(void){ * @param aState determines whether we parse/tokenize or just cache. * @return current state */ -nsresult nsParser::ContinueParsing(){ - +NS_IMETHODIMP nsParser::ContinueParsing() +{ // If the stream has already finished, there's a good chance // that we might start closing things down when the parser // is reenabled. To make sure that we're not deleted across @@ -1401,7 +1375,8 @@ nsresult nsParser::ContinueParsing(){ * @update * @return */ -void nsParser::BlockParser() { +NS_IMETHODIMP_(void) nsParser::BlockParser() +{ mFlags &= ~NS_PARSER_FLAG_PARSER_ENABLED; MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: nsParser::BlockParser(), this=%p\n", this)); MOZ_TIMER_STOP(mParseTime); @@ -1416,7 +1391,8 @@ void nsParser::BlockParser() { * @update * @return */ -void nsParser::UnblockParser() { +NS_IMETHODIMP_(void) nsParser::UnblockParser() +{ mFlags |= NS_PARSER_FLAG_PARSER_ENABLED; MOZ_TIMER_DEBUGLOG(("Start: Parse Time: nsParser::UnblockParser(), this=%p\n", this)); MOZ_TIMER_START(mParseTime); @@ -1428,7 +1404,8 @@ void nsParser::UnblockParser() { * @update vidur 4/12/99 * @return current state */ -PRBool nsParser::IsParserEnabled() { +NS_IMETHODIMP_(PRBool) nsParser::IsParserEnabled() +{ return mFlags & NS_PARSER_FLAG_PARSER_ENABLED; } @@ -1438,7 +1415,8 @@ PRBool nsParser::IsParserEnabled() { * @update rickg 5/12/01 * @return complete state */ -PRBool nsParser::IsComplete() { +NS_IMETHODIMP_(PRBool) nsParser::IsComplete() +{ return !(mFlags & NS_PARSER_FLAG_PENDING_CONTINUE_EVENT); } @@ -1472,13 +1450,18 @@ void nsParser::SetCanInterrupt(PRBool aCanInterrupt) { * @param aFilename -- const char* containing file to be parsed. * @return error code -- 0 if ok, non-zero if error. */ -nsresult nsParser::Parse(nsIURI* aURL,nsIRequestObserver* aListener,PRBool aVerifyEnabled, void* aKey,nsDTDMode aMode) { +NS_IMETHODIMP +nsParser::Parse(nsIURI* aURL, + nsIRequestObserver* aListener, + PRBool aVerifyEnabled, + void* aKey, + nsDTDMode aMode) +{ NS_PRECONDITION(aURL, "Error: Null URL given"); nsresult result=kBadURL; mObserver = aListener; - NS_IF_ADDREF(mObserver); if (aVerifyEnabled) { mFlags |= NS_PARSER_FLAG_DTD_VERIFICATION; @@ -1518,7 +1501,13 @@ nsresult nsParser::Parse(nsIURI* aURL,nsIRequestObserver* aListener,PRBool aVeri * @param aStream is the i/o source * @return error code -- 0 if ok, non-zero if error. */ -nsresult nsParser::Parse(nsIInputStream* aStream,const nsACString& aMimeType,PRBool aVerifyEnabled, void* aKey,nsDTDMode aMode){ +NS_IMETHODIMP +nsParser::Parse(nsIInputStream* aStream, + const nsACString& aMimeType, + PRBool aVerifyEnabled, + void* aKey, + nsDTDMode aMode) +{ if (aVerifyEnabled) { mFlags |= NS_PARSER_FLAG_DTD_VERIFICATION; } @@ -1564,10 +1553,14 @@ nsresult nsParser::Parse(nsIInputStream* aStream,const nsACString& aMimeType,PRB * @param aMimeType tells us what type of content to expect in the given string * @return error code -- 0 if ok, non-zero if error. */ -nsresult nsParser::Parse(const nsAString& aSourceBuffer, void* aKey, - const nsACString& aMimeType, - PRBool aVerifyEnabled, PRBool aLastCall, - nsDTDMode aMode){ +NS_IMETHODIMP +nsParser::Parse(const nsAString& aSourceBuffer, + void* aKey, + const nsACString& aMimeType, + PRBool aVerifyEnabled, + PRBool aLastCall, + nsDTDMode aMode) +{ //NOTE: Make sure that updates to this method don't cause // bug #2361 to break again! @@ -1676,13 +1669,14 @@ nsresult nsParser::Parse(const nsAString& aSourceBuffer, void* aKey, * @param * @return */ -nsresult nsParser::ParseFragment(const nsAString& aSourceBuffer, - void* aKey, - nsVoidArray& aTagStack, - PRUint32 anInsertPos, - const nsACString& aMimeType, - nsDTDMode aMode){ - +NS_IMETHODIMP +nsParser::ParseFragment(const nsAString& aSourceBuffer, + void* aKey, + nsVoidArray& aTagStack, + PRUint32 anInsertPos, + const nsACString& aMimeType, + nsDTDMode aMode) +{ nsresult result = NS_OK; nsAutoString theContext; PRUint32 theCount = aTagStack.Count(); @@ -1901,7 +1895,7 @@ nsresult nsParser::BuildModel() { if (theRootDTD) { MOZ_TIMER_START(mDTDTime); - result = theRootDTD->BuildModel(this, theTokenizer, mTokenObserver, mSink); + result = theRootDTD->BuildModel(this, theTokenizer, nsnull, mSink); MOZ_TIMER_STOP(mDTDTime); } @@ -1951,7 +1945,7 @@ nsresult nsParser::OnStartRequest(nsIRequest *request, nsISupports* aContext) { "Parser's nsIStreamListener API was not setup " "correctly in constructor."); - if (nsnull != mObserver) { + if (mObserver) { mObserver->OnStartRequest(request, aContext); } mParserContext->mStreamListenerState = eOnStart; @@ -2454,7 +2448,7 @@ nsresult nsParser::OnStopRequest(nsIRequest *request, nsISupports* aContext, // XXX Should we wait to notify our observers as well if the // parser isn't yet enabled? - if (nsnull != mObserver) { + if (mObserver) { mObserver->OnStopRequest(request, aContext, status); } @@ -2591,15 +2585,6 @@ PRBool nsParser::DidTokenize(PRBool aIsFinalChunk){ if (NS_SUCCEEDED(rv) && theTokenizer) { result = theTokenizer->DidTokenize(aIsFinalChunk); - if(mTokenObserver) { - PRInt32 theCount=theTokenizer->GetCount(); - PRInt32 theIndex; - for(theIndex=0;theIndexGetTokenAt(theIndex))){ - //add code here to pull unwanted tokens out of the stack... - } - }//for - }//if } return result; } diff --git a/mozilla/parser/htmlparser/src/nsParser.h b/mozilla/parser/htmlparser/src/nsParser.h index d16b7aac6db..49c71c30a23 100644 --- a/mozilla/parser/htmlparser/src/nsParser.h +++ b/mozilla/parser/htmlparser/src/nsParser.h @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* ***** BEGIN LICENSE BLOCK ***** * Version: NPL 1.1/GPL 2.0/LGPL 2.1 * @@ -86,11 +86,11 @@ #include "nsDTDUtils.h" #include "nsTimer.h" #include "nsIEventQueue.h" +#include "nsIContentSink.h" +#include "nsIParserFilter.h" -class IContentSink; class nsIDTD; class nsScanner; -class nsIParserFilter; class nsIProgressEventSink; #ifdef XP_WIN @@ -113,7 +113,7 @@ class nsParser : public nsIParser, * default constructor * @update gess5/11/98 */ - nsParser(nsITokenObserver* anObserver=0); + nsParser(); /** @@ -128,7 +128,7 @@ class nsParser : public nsIParser, * @param aSink is the new sink to be used by parser * @return old sink, or NULL */ - virtual nsIContentSink* SetContentSink(nsIContentSink* aSink); + NS_IMETHOD_(void) SetContentSink(nsIContentSink* aSink); /** * retrive the sink set into the parser @@ -136,40 +136,40 @@ class nsParser : public nsIParser, * @param aSink is the new sink to be used by parser * @return old sink, or NULL */ - virtual nsIContentSink* GetContentSink(void); + NS_IMETHOD_(nsIContentSink*) GetContentSink(void); /** * Call this method once you've created a parser, and want to instruct it - * about the command which caused the parser to be constructed. For example, + * about the command which caused the parser to be constructed. For example, * this allows us to select a DTD which can do, say, view-source. * * @update gess 3/25/98 - * @param aContentSink -- ptr to content sink that will receive output - * @return ptr to previously set contentsink (usually null) + * @param aCommand -- ptrs to string that contains command + * @return nada */ - virtual void GetCommand(nsString& aCommand); - virtual void SetCommand(const char* aCommand); - virtual void SetCommand(eParserCommands aParserCommand); + NS_IMETHOD_(void) GetCommand(nsString& aCommand); + NS_IMETHOD_(void) SetCommand(const char* aCommand); + NS_IMETHOD_(void) SetCommand(eParserCommands aParserCommand); /** * Call this method once you've created a parser, and want to instruct it * about what charset to load * * @update ftang 4/23/99 - * @param aCharset- the charest of a document - * @param aCharsetSource- the soure of the chares + * @param aCharset- the charset of a document + * @param aCharsetSource- the source of the charset * @return nada */ - virtual void SetDocumentCharset(const nsAString& aCharset, PRInt32 aSource); + NS_IMETHOD_(void) SetDocumentCharset(const nsAString& aCharset, PRInt32 aSource); - void GetDocumentCharset(nsAString& aCharset, PRInt32& aSource) + NS_IMETHOD_(void) GetDocumentCharset(nsAString& aCharset, PRInt32& aSource) { aCharset = mCharset; aSource = mCharsetSource; } - virtual nsIParserFilter* SetParserFilter(nsIParserFilter* aFilter); + NS_IMETHOD_(void) SetParserFilter(nsIParserFilter* aFilter); NS_IMETHOD RegisterDTD(nsIDTD* aDTD); @@ -179,15 +179,7 @@ class nsParser : public nsIParser, * @update gess 6/9/98 * @return ptr to scanner */ - virtual nsDTDMode GetParseMode(void); - - /** - * Retrieve the scanner from the topmost parser context - * - * @update gess 6/9/98 - * @return ptr to scanner - */ - virtual nsScanner* GetScanner(void); + NS_IMETHOD_(nsDTDMode) GetParseMode(void); /** * Cause parser to parse input from given URL @@ -196,7 +188,11 @@ class nsParser : public nsIParser, * @param aListener is a listener to forward notifications to * @return TRUE if all went well -- FALSE otherwise */ - virtual nsresult Parse(nsIURI* aURL,nsIRequestObserver* aListener,PRBool aEnableVerify=PR_FALSE,void* aKey=0,nsDTDMode aMode=eDTDMode_autodetect); + NS_IMETHOD Parse(nsIURI* aURL, + nsIRequestObserver* aListener = nsnull, + PRBool aEnableVerify = PR_FALSE, + void* aKey = 0, + nsDTDMode aMode = eDTDMode_autodetect); /** * Cause parser to parse input from given stream @@ -204,7 +200,11 @@ class nsParser : public nsIParser, * @param aStream is the i/o source * @return TRUE if all went well -- FALSE otherwise */ - virtual nsresult Parse(nsIInputStream* aStream,const nsACString& aMimeType,PRBool aEnableVerify=PR_FALSE,void* aKey=0,nsDTDMode aMode=eDTDMode_autodetect); + NS_IMETHOD Parse(nsIInputStream* aStream, + const nsACString& aMimeType, + PRBool aEnableVerify = PR_FALSE, + void* aKey = 0, + nsDTDMode aMode = eDTDMode_autodetect); /** * @update gess5/11/98 @@ -212,16 +212,29 @@ class nsParser : public nsIParser, * @param appendTokens tells us whether we should insert tokens inline, or append them. * @return TRUE if all went well -- FALSE otherwise */ - virtual nsresult Parse(const nsAString& aSourceBuffer,void* aKey,const nsACString& aContentType,PRBool aEnableVerify=PR_FALSE,PRBool aLastCall=PR_FALSE,nsDTDMode aMode=eDTDMode_autodetect); + NS_IMETHOD Parse(const nsAString& aSourceBuffer, + void* aKey, + const nsACString& aContentType, + PRBool aEnableVerify, + PRBool aLastCall, + nsDTDMode aMode = eDTDMode_autodetect); - virtual nsresult ParseFragment(const nsAString& aSourceBuffer, - void* aKey, - nsVoidArray& aTagStack, - PRUint32 anInsertPos, - const nsACString& aContentType, - nsDTDMode aMode=eDTDMode_autodetect); + NS_IMETHOD ParseFragment(const nsAString& aSourceBuffer, + void* aKey, + nsVoidArray& aTagStack, + PRUint32 anInsertPos, + const nsACString& aContentType, + nsDTDMode aMode = eDTDMode_autodetect); + /** + * This method gets called when the tokens have been consumed, and it's time + * to build the model via the content sink. + * @update gess5/11/98 + * @return YES if model building went well -- NO otherwise. + */ + NS_IMETHOD BuildModel(void); + /** * Call this when you want control whether or not the parser will parse * and tokenize input (TRUE), or whether it just caches input to be @@ -231,10 +244,10 @@ class nsParser : public nsIParser, * @param aState determines whether we parse/tokenize or just cache. * @return current state */ - virtual nsresult ContinueParsing(); - virtual void BlockParser(); - virtual void UnblockParser(); - virtual nsresult Terminate(void); + NS_IMETHOD ContinueParsing(); + NS_IMETHOD_(void) BlockParser(); + NS_IMETHOD_(void) UnblockParser(); + NS_IMETHOD Terminate(void); /** * Call this to query whether the parser is enabled or not. @@ -242,7 +255,7 @@ class nsParser : public nsIParser, * @update vidur 4/12/99 * @return current state */ - virtual PRBool IsParserEnabled(); + NS_IMETHOD_(PRBool) IsParserEnabled(); /** * Call this to query whether the parser thinks it's done with parsing. @@ -250,7 +263,7 @@ class nsParser : public nsIParser, * @update rickg 5/12/01 * @return complete state */ - virtual PRBool IsComplete(); + NS_IMETHOD_(PRBool) IsComplete(); /** * This rather arcane method (hack) is used as a signal between the @@ -377,14 +390,6 @@ protected: * @return */ nsresult DidBuildModel(nsresult anErrorCode); - - /** - * This method gets called when the tokens have been consumed, and it's time - * to build the model via the content sink. - * @update gess5/11/98 - * @return YES if model building went well -- NO otherwise. - */ - virtual nsresult BuildModel(void); private: @@ -432,14 +437,13 @@ protected: //********************************************* - nsCOMPtr mEventQueue; - CParserContext* mParserContext; - nsIRequestObserver* mObserver; - nsIContentSink* mSink; + nsCOMPtr mEventQueue; + CParserContext* mParserContext; + nsCOMPtr mObserver; + nsCOMPtr mSink; - nsIParserFilter* mParserFilter; - nsITokenObserver* mTokenObserver; - nsTokenAllocator mTokenAllocator; + nsCOMPtr mParserFilter; + nsTokenAllocator mTokenAllocator; eParserCommands mCommand; nsresult mInternalState;