Skip to content

Commit

Permalink
Bug 1749935 - Remove nsITokenizer. r=hsivonen
Browse files Browse the repository at this point in the history
  • Loading branch information
petervanderbeken committed Feb 14, 2022
1 parent d023f9c commit 6c6f720
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 208 deletions.
1 change: 0 additions & 1 deletion parser/html/nsHtml5Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "nsIParser.h"
#include "nsDeque.h"
#include "nsParserCIID.h"
#include "nsITokenizer.h"
#include "nsIContentSink.h"
#include "nsIRequest.h"
#include "nsIChannel.h"
Expand Down
20 changes: 0 additions & 20 deletions parser/htmlparser/CParserContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
#include "CParserContext.h"
#include "prenv.h"
#include "nsIHTMLContentSink.h"
#include "nsHTMLTokenizer.h"
#include "nsMimeTypes.h"
#include "nsHTMLTokenizer.h"

CParserContext::CParserContext(nsIURI* aURI, eParserCommands aCommand)
: mScanner(aURI),
Expand Down Expand Up @@ -60,21 +58,3 @@ void CParserContext::SetMimeType(const nsACString& aMimeType) {
mMimeType.EqualsLiteral(TEXT_RDF))
mDocType = eXML;
}

nsresult CParserContext::GetTokenizer(nsIDTD* aDTD, nsIContentSink* aSink,
nsITokenizer*& aTokenizer) {
nsresult result = NS_OK;
int32_t type = aDTD ? aDTD->GetType() : NS_IPARSER_FLAG_HTML;

if (!mTokenizer) {
if (type == NS_IPARSER_FLAG_HTML || mParserCommand == eViewSource) {
mTokenizer = new nsHTMLTokenizer;
} else if (type == NS_IPARSER_FLAG_XML) {
mTokenizer = do_QueryInterface(aDTD, &result);
}
}

aTokenizer = mTokenizer;

return result;
}
3 changes: 0 additions & 3 deletions parser/htmlparser/CParserContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,11 @@ class CParserContext {

~CParserContext();

nsresult GetTokenizer(nsIDTD* aDTD, nsIContentSink* aSink,
nsITokenizer*& aTokenizer);
void SetMimeType(const nsACString& aMimeType);

nsCOMPtr<nsIRequest>
mRequest; // provided by necko to differnciate different input streams
// why is mRequest strongly referenced? see bug 102376.
nsCOMPtr<nsITokenizer> mTokenizer;
nsScanner mScanner;

nsCString mMimeType;
Expand Down
2 changes: 0 additions & 2 deletions parser/htmlparser/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ EXPORTS += [
"nsIFragmentContentSink.h",
"nsIHTMLContentSink.h",
"nsIParser.h",
"nsITokenizer.h",
"nsParserBase.h",
"nsParserCIID.h",
"nsParserConstants.h",
Expand All @@ -39,7 +38,6 @@ UNIFIED_SOURCES += [
"nsElementTable.cpp",
"nsExpatDriver.cpp",
"nsHTMLTags.cpp",
"nsHTMLTokenizer.cpp",
"nsParser.cpp",
"nsParserModule.cpp",
"nsParserMsgUtils.cpp",
Expand Down
6 changes: 2 additions & 4 deletions parser/htmlparser/nsExpatDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,8 @@ static void GetLocalDTDURI(const nsCatalogData* aCatalogData, nsIURI* aDTD,
/***************************** END CATALOG UTILS *****************************/

NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsExpatDriver)
NS_INTERFACE_MAP_ENTRY(nsITokenizer)
NS_INTERFACE_MAP_ENTRY(nsIDTD)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDTD)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END

NS_IMPL_CYCLE_COLLECTING_ADDREF(nsExpatDriver)
Expand Down Expand Up @@ -1226,8 +1225,7 @@ void nsExpatDriver::ParseBuffer(const char16_t* aBuffer, uint32_t aLength,
}
}

NS_IMETHODIMP
nsExpatDriver::ConsumeToken(nsScanner& aScanner, bool aIsFinalChunk) {
nsresult nsExpatDriver::ResumeParse(nsScanner& aScanner, bool aIsFinalChunk) {
// We keep the scanner pointing to the position where Expat will start
// parsing.
nsScannerIterator currentExpatPosition;
Expand Down
10 changes: 5 additions & 5 deletions parser/htmlparser/nsExpatDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsIDTD.h"
#include "nsITokenizer.h"
#include "nsIInputStream.h"
#include "nsIParser.h"
#include "nsCycleCollectionParticipant.h"
Expand All @@ -28,19 +27,20 @@ template <typename, size_t>
class Array;
}

class nsExpatDriver : public nsIDTD, public nsITokenizer {
class nsExpatDriver : public nsIDTD {
virtual ~nsExpatDriver();

public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTING_ISUPPORTS_FINAL
NS_DECL_NSIDTD
NS_DECL_NSITOKENIZER
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsExpatDriver, nsIDTD)
NS_DECL_CYCLE_COLLECTION_CLASS(nsExpatDriver)

nsExpatDriver();

nsresult Initialize(nsIURI* aURI, nsIContentSink* aSink);

nsresult ResumeParse(nsScanner& aScanner, bool aIsFinalChunk);

int HandleExternalEntityRef(const char16_t* aOpenEntityNames,
const char16_t* aBase, const char16_t* aSystemId,
const char16_t* aPublicId);
Expand Down
50 changes: 0 additions & 50 deletions parser/htmlparser/nsHTMLTokenizer.cpp

This file was deleted.

32 changes: 0 additions & 32 deletions parser/htmlparser/nsHTMLTokenizer.h

This file was deleted.

42 changes: 0 additions & 42 deletions parser/htmlparser/nsITokenizer.h

This file was deleted.

64 changes: 16 additions & 48 deletions parser/htmlparser/nsParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "nsExpatDriver.h"
#include "nsIFragmentContentSink.h"
#include "nsStreamUtils.h"
#include "nsHTMLTokenizer.h"
#include "nsXPCOMCIDInternal.h"
#include "nsMimeTypes.h"
#include "nsCharsetSource.h"
Expand Down Expand Up @@ -333,10 +332,6 @@ nsresult nsParser::WillBuildModel() {
mDTD = new CNavDTD();
}

nsITokenizer* tokenizer;
nsresult rv = mParserContext->GetTokenizer(mDTD, mSink, tokenizer);
NS_ENSURE_SUCCESS(rv, rv);

return mSink->WillBuildModel(mParserContext->mDTDMode);
}

Expand Down Expand Up @@ -725,59 +720,32 @@ nsresult nsParser::ResumeParse(bool allowIteration, bool aIsFinalChunk,

// Only allow parsing to be interrupted in the subsequent call to
// build model.
nsITokenizer* theTokenizer = nullptr;
nsresult getTokenizerResult;
if (mParserContext) {
result = getTokenizerResult =
mParserContext->GetTokenizer(mDTD, mSink, theTokenizer);
} else {
getTokenizerResult = NS_ERROR_HTMLPARSER_BADTOKENIZER;
result = NS_OK;
}

nsresult theTokenizerResult;
if (mFlags & NS_PARSER_FLAG_CAN_TOKENIZE) {
if (NS_SUCCEEDED(getTokenizerResult)) {
theTokenizerResult = getTokenizerResult;

bool killSink = false;

while (NS_SUCCEEDED(theTokenizerResult)) {
mParserContext->mScanner.Mark();
theTokenizerResult = theTokenizer->ConsumeToken(
mParserContext->mScanner, aIsFinalChunk);
if (NS_FAILED(theTokenizerResult)) {
mParserContext->mScanner.RewindToMark();
if (NS_ERROR_HTMLPARSER_EOF == theTokenizerResult) {
break;
}
if (NS_ERROR_HTMLPARSER_STOPPARSING == theTokenizerResult) {
killSink = true;
theTokenizerResult = Terminate();
break;
}
mParserContext->mScanner.Mark();
if (mDTD->GetType() == NS_IPARSER_FLAG_XML &&
mParserContext->mParserCommand != eViewSource) {
nsExpatDriver* expat = static_cast<nsExpatDriver*>(mDTD.get());
theTokenizerResult =
expat->ResumeParse(mParserContext->mScanner, aIsFinalChunk);
if (NS_FAILED(theTokenizerResult)) {
mParserContext->mScanner.RewindToMark();
if (NS_ERROR_HTMLPARSER_STOPPARSING == theTokenizerResult) {
theTokenizerResult = Terminate();
mSink = nullptr;
}
}

if (killSink) {
mSink = nullptr;
}
} else {
theTokenizerResult = mInternalState =
NS_ERROR_HTMLPARSER_BADTOKENIZER;
// Nothing to do for non-XML. Note that this should only be
// about:blank at this point, we're also checking for view-source
// above, but that shouldn't end up here anymore.
theTokenizerResult = NS_ERROR_HTMLPARSER_EOF;
}
} else {
theTokenizerResult = NS_OK;
}

if (NS_SUCCEEDED(result)) {
if (mDTD) {
result = mDTD->BuildModel(mSink);
}
} else {
mInternalState = result = NS_ERROR_HTMLPARSER_BADTOKENIZER;
}

result = mDTD->BuildModel(mSink);
if (result == NS_ERROR_HTMLPARSER_INTERRUPTED && aIsFinalChunk) {
PostContinueEvent();
}
Expand Down
1 change: 0 additions & 1 deletion parser/htmlparser/nsParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
#include "nsDeque.h"
#include "CParserContext.h"
#include "nsParserCIID.h"
#include "nsITokenizer.h"
#include "nsHTMLTags.h"
#include "nsIContentSink.h"
#include "nsCOMArray.h"
Expand Down

0 comments on commit 6c6f720

Please sign in to comment.