commit 8cfad39176be94c2534ada4abc8c693998f48026
parent 56352b8ad81410c10bc445521dc9629acf062189
Author: Henri Sivonen <hsivonen@hsivonen.fi>
Date: Tue, 25 Nov 2025 14:41:48 +0000
Bug 2002189 - Remove nsIDTD. r=dom-core,edgar,smaug
Differential Revision: https://phabricator.services.mozilla.com/D273975
Diffstat:
20 files changed, 47 insertions(+), 132 deletions(-)
diff --git a/dom/prototype/PrototypeDocumentContentSink.h b/dom/prototype/PrototypeDocumentContentSink.h
@@ -17,7 +17,6 @@
#include "nsCycleCollectionParticipant.h"
#include "nsICSSLoaderObserver.h"
#include "nsIContentSink.h"
-#include "nsIDTD.h"
#include "nsIScriptContext.h"
#include "nsIStreamLoader.h"
#include "nsTArray.h"
diff --git a/dom/xml/nsXMLContentSink.cpp b/dom/xml/nsXMLContentSink.cpp
@@ -147,7 +147,7 @@ NS_IMETHODIMP
nsXMLContentSink::WillParse(void) { return WillParseImpl(); }
NS_IMETHODIMP
-nsXMLContentSink::WillBuildModel(nsDTDMode aDTDMode) {
+nsXMLContentSink::WillBuildModel() {
WillBuildModelImpl();
// Notify document that the load is beginning
diff --git a/dom/xml/nsXMLContentSink.h b/dom/xml/nsXMLContentSink.h
@@ -13,7 +13,6 @@
#include "nsCRT.h"
#include "nsContentSink.h"
#include "nsCycleCollectionParticipant.h"
-#include "nsIDTD.h"
#include "nsIDocumentTransformer.h"
#include "nsIExpatSink.h"
#include "nsIXMLContentSink.h"
@@ -59,7 +58,7 @@ class nsXMLContentSink : public nsContentSink,
// nsIContentSink
NS_IMETHOD WillParse(void) override;
- NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode) override;
+ NS_IMETHOD WillBuildModel() override;
NS_IMETHOD DidBuildModel(bool aTerminated) override;
NS_IMETHOD WillInterrupt(void) override;
void WillResume() override;
diff --git a/dom/xml/nsXMLFragmentContentSink.cpp b/dom/xml/nsXMLFragmentContentSink.cpp
@@ -18,7 +18,6 @@
#include "nsGkAtoms.h"
#include "nsHashKeys.h"
#include "nsIContent.h"
-#include "nsIDTD.h"
#include "nsIDocShell.h"
#include "nsIExpatSink.h"
#include "nsIFragmentContentSink.h"
@@ -55,7 +54,7 @@ class nsXMLFragmentContentSink : public nsXMLContentSink,
bool* aRetval) override;
// nsIContentSink
- NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode) override;
+ NS_IMETHOD WillBuildModel() override;
NS_IMETHOD DidBuildModel(bool aTerminated) override;
virtual void SetDocumentCharset(NotNull<const Encoding*> aEncoding) override;
virtual nsISupports* GetTarget() override;
@@ -135,7 +134,7 @@ NS_IMPL_CYCLE_COLLECTION_INHERITED(nsXMLFragmentContentSink, nsXMLContentSink,
mTargetDocument, mRoot)
NS_IMETHODIMP
-nsXMLFragmentContentSink::WillBuildModel(nsDTDMode aDTDMode) {
+nsXMLFragmentContentSink::WillBuildModel() {
if (mRoot) {
return NS_OK;
}
diff --git a/dom/xul/nsXULContentSink.h b/dom/xul/nsXULContentSink.h
@@ -7,7 +7,6 @@
#define nsXULContentSink_h__
#include "mozilla/WeakPtr.h"
-#include "nsIDTD.h"
#include "nsIExpatSink.h"
#include "nsIWeakReferenceUtils.h"
#include "nsIXMLContentSink.h"
diff --git a/parser/html/nsHtml5StreamParser.cpp b/parser/html/nsHtml5StreamParser.cpp
@@ -46,7 +46,6 @@
#include "nsIChannel.h"
#include "nsIContentSink.h"
#include "nsID.h"
-#include "nsIDTD.h"
#include "nsIDocShell.h"
#include "nsIHttpChannel.h"
#include "nsIInputStream.h"
diff --git a/parser/html/nsHtml5TreeOpExecutor.cpp b/parser/html/nsHtml5TreeOpExecutor.cpp
@@ -158,7 +158,8 @@ nsHtml5TreeOpExecutor::WillParse() {
return NS_ERROR_NOT_IMPLEMENTED;
}
-nsresult nsHtml5TreeOpExecutor::WillBuildModel() {
+NS_IMETHODIMP
+nsHtml5TreeOpExecutor::WillBuildModel() {
mDocument->AddObserver(this);
WillBuildModelImpl();
GetDocument()->BeginLoad();
diff --git a/parser/html/nsHtml5TreeOpExecutor.h b/parser/html/nsHtml5TreeOpExecutor.h
@@ -111,10 +111,7 @@ class nsHtml5TreeOpExecutor final
*/
NS_IMETHOD WillParse() override;
- NS_IMETHOD WillBuildModel(nsDTDMode /* unused */) override {
- return WillBuildModel();
- }
- nsresult WillBuildModel();
+ NS_IMETHOD WillBuildModel() override;
/**
* Emits EOF.
diff --git a/parser/html/nsHtml5TreeOperation.cpp b/parser/html/nsHtml5TreeOperation.cpp
@@ -32,7 +32,6 @@
#include "nsHtml5HtmlAttributes.h"
#include "nsHtml5SVGLoadDispatcher.h"
#include "nsHtml5TreeBuilder.h"
-#include "nsIDTD.h"
#include "nsIFormControl.h"
#include "nsIMutationObserver.h"
#include "nsINode.h"
diff --git a/parser/html/nsParserUtils.cpp b/parser/html/nsParserUtils.cpp
@@ -16,7 +16,6 @@
#include "nsHtml5Module.h"
#include "nsIContent.h"
#include "nsIContentSink.h"
-#include "nsIDTD.h"
#include "mozilla/dom/Document.h"
#include "nsIDocumentEncoder.h"
#include "nsIFragmentContentSink.h"
diff --git a/parser/htmlparser/CParserContext.cpp b/parser/htmlparser/CParserContext.cpp
@@ -14,7 +14,6 @@ CParserContext::CParserContext(nsIURI* aURI, eParserCommands aCommand)
mDTDMode(eDTDMode_autodetect),
mDocType(eUnknown),
mStreamListenerState(eNone),
- mContextType(eCTURL),
mParserCommand(aCommand),
mMultipart(true),
mCopyUnused(false) {
@@ -28,7 +27,6 @@ CParserContext::CParserContext(const nsAString& aBuffer,
mDTDMode(eDTDMode_full_standards),
mDocType(eXML),
mStreamListenerState(aLastBuffer ? eOnStop : eOnDataAvail),
- mContextType(eCTString),
mParserCommand(aCommand),
mMultipart(!aLastBuffer),
mCopyUnused(aLastBuffer) {
diff --git a/parser/htmlparser/CParserContext.h b/parser/htmlparser/CParserContext.h
@@ -13,7 +13,6 @@
#define __CParserContext
#include "nsIParser.h"
-#include "nsIDTD.h"
#include "nsIRequest.h"
#include "nsScanner.h"
#include "nsString.h"
@@ -26,10 +25,23 @@ class nsITokenizer;
* data in a parsercontext. Hey, that what it's for!
*/
+/**
+ * Legacy enum kept around for now to accommodate fragment vs. not fragment
+ * paths in nsParser.
+ */
+enum eAutoDetectResult {
+ eUnknownDetect,
+ ePrimaryDetect,
+};
+
+/**
+ * Legacy enum kept around for now to accommodate fragment vs. not fragment
+ * paths in nsParser.
+ */
+enum nsDTDMode { eDTDMode_full_standards, eDTDMode_autodetect };
+
class CParserContext {
public:
- enum eContextType { eCTURL, eCTString };
-
CParserContext(nsIURI* aURI, eParserCommands aCommand);
CParserContext(const nsAString& aBuffer, eParserCommands aCommand,
bool aLastBuffer);
@@ -48,7 +60,6 @@ class CParserContext {
eParserDocType mDocType;
eStreamState mStreamListenerState;
- eContextType mContextType;
eAutoDetectResult mAutoDetectStatus = eUnknownDetect;
eParserCommands mParserCommand;
diff --git a/parser/htmlparser/moz.build b/parser/htmlparser/moz.build
@@ -21,7 +21,6 @@ EXPORTS += [
"nsHTMLTagList.h",
"nsHTMLTags.h",
"nsIContentSink.h",
- "nsIDTD.h",
"nsIFragmentContentSink.h",
"nsIParser.h",
"nsParserBase.h",
diff --git a/parser/htmlparser/nsExpatDriver.cpp b/parser/htmlparser/nsExpatDriver.cpp
@@ -357,7 +357,6 @@ static void GetLocalDTDURI(const nsCatalogData* aCatalogData, nsIURI* aDTD,
/***************************** END CATALOG UTILS *****************************/
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsExpatDriver)
- NS_INTERFACE_MAP_ENTRY(nsIDTD)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
@@ -1656,8 +1655,7 @@ nsresult nsExpatDriver::Initialize(nsIURI* aURI, nsIContentSink* aSink) {
return mInternalState;
}
-NS_IMETHODIMP
-nsExpatDriver::BuildModel(nsIContentSink* aSink) { return mInternalState; }
+nsresult nsExpatDriver::BuildModel() { return mInternalState; }
void nsExpatDriver::DidBuildModel() {
if (!mInParser) {
@@ -1671,8 +1669,7 @@ void nsExpatDriver::DidBuildModel() {
mSink = nullptr;
}
-NS_IMETHODIMP_(void)
-nsExpatDriver::Terminate() {
+void nsExpatDriver::Terminate() {
// XXX - not sure what happens to the unparsed data.
if (mExpatParser) {
RLBOX_EXPAT_MCALL(MOZ_XML_StopParser, XML_FALSE);
diff --git a/parser/htmlparser/nsExpatDriver.h b/parser/htmlparser/nsExpatDriver.h
@@ -10,7 +10,6 @@
#include "moz_expat.h"
#include "nsCOMPtr.h"
#include "nsString.h"
-#include "nsIDTD.h"
#include "nsIInputStream.h"
#include "nsIParser.h"
#include "nsCycleCollectionParticipant.h"
@@ -28,18 +27,21 @@ template <typename, size_t>
class Array;
}
-class nsExpatDriver : public nsIDTD {
+class nsExpatDriver : public nsISupports {
virtual ~nsExpatDriver();
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS_FINAL
- NS_DECL_NSIDTD
NS_DECL_CYCLE_COLLECTION_CLASS(nsExpatDriver)
nsExpatDriver();
nsresult Initialize(nsIURI* aURI, nsIContentSink* aSink);
+ void DidBuildModel();
+ nsresult BuildModel();
+ void Terminate();
+
nsresult ResumeParse(nsScanner& aScanner, bool aIsFinalChunk);
int HandleExternalEntityRef(const char16_t* aOpenEntityNames,
diff --git a/parser/htmlparser/nsIContentSink.h b/parser/htmlparser/nsIContentSink.h
@@ -21,7 +21,6 @@
#include "nsString.h"
#include "mozilla/FlushType.h"
#include "mozilla/NotNull.h"
-#include "nsIDTD.h"
class nsParserBase;
namespace mozilla {
@@ -57,7 +56,7 @@ class nsIContentSink : public nsISupports {
*
* @update 5/7/98 gess
*/
- NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode) { return NS_OK; }
+ NS_IMETHOD WillBuildModel() { return NS_OK; }
/**
* This method gets called when the parser concludes the process
diff --git a/parser/htmlparser/nsIDTD.h b/parser/htmlparser/nsIDTD.h
@@ -1,82 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef nsIDTD_h___
-#define nsIDTD_h___
-
-/**
- * MODULE NOTES:
- * @update gess 7/20/98
- *
- * This interface defines standard interface for DTD's. Note that this
- * isn't HTML specific. DTD's have several functions within the parser
- * system:
- * 1) To coordinate the consumption of an input stream via the
- * parser
- * 2) To serve as proxy to represent the containment rules of the
- * underlying document
- * 3) To offer autodetection services to the parser (mainly for doc
- * conversion)
- * */
-
-#include "nsISupports.h"
-#include "nsString.h"
-
-#define NS_IDTD_IID \
- {0x3de05873, 0xefa7, 0x410d, {0xa4, 0x61, 0x80, 0x33, 0xaf, 0xd9, 0xe3, 0x26}}
-
-enum eAutoDetectResult {
- eUnknownDetect,
- ePrimaryDetect,
-};
-
-enum nsDTDMode {
- eDTDMode_quirks, // pre 4.0 versions
- eDTDMode_full_standards,
- eDTDMode_autodetect
-};
-
-class nsIContentSink;
-class CParserContext;
-
-class nsIDTD : public nsISupports {
- public:
- NS_INLINE_DECL_STATIC_IID(NS_IDTD_IID)
-
- /**
- * Called by the parser after the parsing process has concluded
- */
- virtual void DidBuildModel() = 0;
-
- /**
- * Called (possibly repeatedly) by the parser to parse tokens and construct
- * the document model via the sink provided to WillBuildModel.
- *
- * @param aCountLines - informs the DTD whether to count newlines
- * (not wanted, e.g., when handling document.write)
- * @param aCharsetPtr - address of an nsCString containing the charset
- * that the DTD should use (pointer in case the DTD
- * opts to ignore this parameter)
- */
- NS_IMETHOD BuildModel(nsIContentSink* aSink) = 0;
-
- /**
- * Use this id you want to stop the building content model
- * --------------[ Sets DTD to STOP mode ]----------------
- * It's recommended to use this method in accordance with
- * the parser's terminate() method.
- *
- * @update harishd 07/22/99
- * @param
- * @return
- */
- NS_IMETHOD_(void) Terminate() = 0;
-};
-
-#define NS_DECL_NSIDTD \
- void DidBuildModel() override; \
- NS_IMETHOD BuildModel(nsIContentSink* aSink) override; \
- NS_IMETHOD_(void) Terminate() override;
-#endif /* nsIDTD_h___ */
diff --git a/parser/htmlparser/nsIParser.h b/parser/htmlparser/nsIParser.h
@@ -19,7 +19,6 @@
#include "nsISupports.h"
#include "nsIStreamListener.h"
-#include "nsIDTD.h"
#include "nsString.h"
#include "nsTArray.h"
#include "nsAtom.h"
diff --git a/parser/htmlparser/nsParser.cpp b/parser/htmlparser/nsParser.cpp
@@ -126,13 +126,13 @@ void nsParser::Cleanup() {
NS_IMPL_CYCLE_COLLECTION_CLASS(nsParser)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsParser)
- NS_IMPL_CYCLE_COLLECTION_UNLINK(mDTD)
+ NS_IMPL_CYCLE_COLLECTION_UNLINK(mExpatDriver)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSink)
NS_IMPL_CYCLE_COLLECTION_UNLINK_WEAK_REFERENCE
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsParser)
- NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDTD)
+ NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mExpatDriver)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSink)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
@@ -286,9 +286,9 @@ nsresult nsParser::WillBuildModel() {
nsresult rv = expat->Initialize(mParserContext->mScanner.GetURI(), mSink);
NS_ENSURE_SUCCESS(rv, rv);
- mDTD = expat.forget();
+ mExpatDriver = expat.forget();
- return mSink->WillBuildModel(mParserContext->mDTDMode);
+ return mSink->WillBuildModel();
}
/**
@@ -299,8 +299,8 @@ void nsParser::DidBuildModel() {
// Let sink know if we're about to end load because we've been terminated.
// In that case we don't want it to run deferred scripts.
bool terminated = mInternalState == NS_ERROR_HTMLPARSER_STOPPARSING;
- if (mDTD && mSink) {
- mDTD->DidBuildModel();
+ if (mExpatDriver && mSink) {
+ mExpatDriver->DidBuildModel();
mSink->DidBuildModel(terminated);
}
@@ -339,8 +339,8 @@ nsParser::Terminate(void) {
mFlags &= ~NS_PARSER_FLAG_PENDING_CONTINUE_EVENT;
}
- if (mDTD) {
- mDTD->Terminate();
+ if (mExpatDriver) {
+ mExpatDriver->Terminate();
DidBuildModel();
} else if (mSink) {
// We have no parser context or no DTD yet (so we got terminated before we
@@ -684,7 +684,7 @@ nsresult nsParser::ResumeParse(bool allowIteration, bool aIsFinalChunk,
return result;
}
- if (mDTD) {
+ if (mExpatDriver) {
mSink->WillResume();
bool theIterationIsOk = true;
@@ -705,9 +705,8 @@ nsresult nsParser::ResumeParse(bool allowIteration, bool aIsFinalChunk,
mParserContext->mScanner.Mark();
if (mParserContext->mDocType == eXML &&
mParserContext->mParserCommand != eViewSource) {
- nsExpatDriver* expat = static_cast<nsExpatDriver*>(mDTD.get());
- theTokenizerResult =
- expat->ResumeParse(mParserContext->mScanner, aIsFinalChunk);
+ theTokenizerResult = mExpatDriver->ResumeParse(
+ mParserContext->mScanner, aIsFinalChunk);
if (NS_FAILED(theTokenizerResult)) {
mParserContext->mScanner.RewindToMark();
if (NS_ERROR_HTMLPARSER_STOPPARSING == theTokenizerResult) {
@@ -725,7 +724,7 @@ nsresult nsParser::ResumeParse(bool allowIteration, bool aIsFinalChunk,
theTokenizerResult = NS_OK;
}
- result = mDTD->BuildModel(mSink);
+ result = mExpatDriver->BuildModel();
if (result == NS_ERROR_HTMLPARSER_INTERRUPTED && aIsFinalChunk) {
PostContinueEvent();
}
@@ -795,7 +794,7 @@ nsresult nsParser::OnStartRequest(nsIRequest* request) {
mParserContext->mAutoDetectStatus = eUnknownDetect;
mParserContext->mRequest = request;
- mDTD = nullptr;
+ mExpatDriver = nullptr;
nsresult rv;
nsAutoCString contentType;
diff --git a/parser/htmlparser/nsParser.h b/parser/htmlparser/nsParser.h
@@ -52,7 +52,7 @@
#include "mozilla/Maybe.h"
#include "mozilla/UniquePtr.h"
-class nsIDTD;
+class nsExpatDriver;
class nsIRunnable;
#ifdef _MSC_VER
@@ -296,7 +296,9 @@ class nsParser final : public nsIParser,
//*********************************************
mozilla::UniquePtr<CParserContext> mParserContext;
- nsCOMPtr<nsIDTD> mDTD;
+ // mExpatDriver probably should be UniquePtr, but not changing
+ // for now due to cycle collection.
+ RefPtr<nsExpatDriver> mExpatDriver;
nsCOMPtr<nsIContentSink> mSink;
nsIRunnable* mContinueEvent; // weak ref