commit bf8e6315c253a54f3ff200515685df7d88df71b5
parent 077353d82bf76cd6d74199ef3716cfd85189a227
Author: Henri Sivonen <hsivonen@hsivonen.fi>
Date: Tue, 25 Nov 2025 09:50:21 +0000
Bug 563890 - Rename nsHTMLContentSink.cpp to HTMLElementFactory.cpp for consistency with SVG and MathML. r=dom-core,farre
Differential Revision: https://phabricator.services.mozilla.com/D273944
Diffstat:
9 files changed, 77 insertions(+), 124 deletions(-)
diff --git a/dom/base/nsIContent.h b/dom/base/nsIContent.h
@@ -407,7 +407,7 @@ class nsIContent : public nsINode {
* element (through createElement() or cloneNode() generally) then add a
* uint32_t aFromParser to the NS_NewXXX() constructor for your element and
* have the parser pass the appropriate flags. See HTMLInputElement.cpp and
- * nsHTMLContentSink::MakeContentObject().
+ * nsHtml5TreeBuilder::elementPopped().
*
* DO NOT USE THIS METHOD to get around the fact that it's hard to deal with
* attributes dynamically. If you make attributes affect your element from
@@ -429,7 +429,7 @@ class nsIContent : public nsINode {
* element (through createElement() or cloneNode() generally) then add a
* boolean aFromParser to the NS_NewXXX() constructor for your element and
* have the parser pass true. See HTMLInputElement.cpp and
- * nsHTMLContentSink::MakeContentObject().
+ * nsHtml5TreeBuilder::elementPopped().
*
* @param aHaveNotified Whether there has been a
* ContentInserted/ContentAppended notification for this content node
diff --git a/dom/html/HTMLElementFactory.cpp b/dom/html/HTMLElementFactory.cpp
@@ -0,0 +1,67 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* 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/. */
+
+#include "mozilla/Assertions.h"
+#include "mozilla/dom/CustomElementRegistry.h"
+#include "mozilla/dom/Element.h"
+#include "mozilla/dom/NodeInfo.h"
+#include "nsContentCreatorFunctions.h"
+#include "nsError.h"
+#include "nsGenericHTMLElement.h"
+#include "nsHTMLTags.h"
+#include "nsNodeInfoManager.h"
+
+using namespace mozilla;
+using namespace mozilla::dom;
+
+//----------------------------------------------------------------------
+
+nsGenericHTMLElement* NS_NewHTMLNOTUSEDElement(
+ already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
+ FromParser aFromParser) {
+ MOZ_ASSERT_UNREACHABLE("The element ctor should never be called");
+ return nullptr;
+}
+
+#define HTML_TAG(_tag, _classname, _interfacename) \
+ NS_NewHTML##_classname##Element,
+#define HTML_OTHER(_tag) NS_NewHTMLNOTUSEDElement,
+static const HTMLContentCreatorFunction sHTMLContentCreatorFunctions[] = {
+ NS_NewHTMLUnknownElement,
+#include "nsHTMLTagList.h"
+#undef HTML_TAG
+#undef HTML_OTHER
+ NS_NewHTMLUnknownElement};
+
+nsresult NS_NewHTMLElement(Element** aResult,
+ already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
+ FromParser aFromParser, nsAtom* aIsAtom,
+ mozilla::dom::CustomElementDefinition* aDefinition) {
+ RefPtr<mozilla::dom::NodeInfo> nodeInfo = aNodeInfo;
+
+ MOZ_ASSERT(
+ nodeInfo->NamespaceEquals(kNameSpaceID_XHTML),
+ "Trying to create HTML elements that don't have the XHTML namespace");
+
+ return nsContentUtils::NewXULOrHTMLElement(aResult, nodeInfo, aFromParser,
+ aIsAtom, aDefinition);
+}
+
+already_AddRefed<nsGenericHTMLElement> CreateHTMLElement(
+ uint32_t aNodeType, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
+ FromParser aFromParser) {
+ MOZ_ASSERT(aNodeType <= NS_HTML_TAG_MAX || aNodeType == eHTMLTag_userdefined,
+ "aNodeType is out of bounds");
+
+ HTMLContentCreatorFunction cb = sHTMLContentCreatorFunctions[aNodeType];
+
+ MOZ_ASSERT(cb != NS_NewHTMLNOTUSEDElement,
+ "Don't know how to construct tag element!");
+
+ RefPtr<nsGenericHTMLElement> result = cb(std::move(aNodeInfo), aFromParser);
+
+ return result.forget();
+}
diff --git a/dom/html/moz.build b/dom/html/moz.build
@@ -134,6 +134,7 @@ UNIFIED_SOURCES += [
"HTMLDivElement.cpp",
"HTMLDNSPrefetch.cpp",
"HTMLElement.cpp",
+ "HTMLElementFactory.cpp",
"HTMLEmbedElement.cpp",
"HTMLFieldSetElement.cpp",
"HTMLFontElement.cpp",
@@ -191,7 +192,6 @@ UNIFIED_SOURCES += [
"nsDOMStringMap.cpp",
"nsGenericHTMLElement.cpp",
"nsGenericHTMLFrameElement.cpp",
- "nsHTMLContentSink.cpp",
"nsHTMLDocument.cpp",
"nsIConstraintValidation.cpp",
"RadioNodeList.cpp",
diff --git a/dom/html/nsHTMLContentSink.cpp b/dom/html/nsHTMLContentSink.cpp
@@ -1,104 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* 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/. */
-
-/**
- * This file is near-OBSOLETE. It is used for about:blank only and for the
- * HTML element factory.
- * Don't bother adding new stuff in this file.
- */
-
-#include "mozAutoDocUpdate.h"
-#include "mozilla/Logging.h"
-#include "mozilla/dom/CustomElementRegistry.h"
-#include "mozilla/dom/Document.h"
-#include "mozilla/dom/Element.h"
-#include "mozilla/dom/MutationObservers.h"
-#include "mozilla/dom/NodeInfo.h"
-#include "mozilla/dom/ScriptLoader.h"
-#include "nsCOMPtr.h"
-#include "nsCRT.h"
-#include "nsContentCreatorFunctions.h"
-#include "nsContentPolicyUtils.h"
-#include "nsContentSink.h"
-#include "nsContentUtils.h"
-#include "nsDocElementCreatedNotificationRunner.h"
-#include "nsError.h"
-#include "nsEscape.h"
-#include "nsGenericHTMLElement.h"
-#include "nsGkAtoms.h"
-#include "nsHTMLDocument.h"
-#include "nsHTMLTags.h"
-#include "nsIChannel.h"
-#include "nsIContent.h"
-#include "nsIDocShell.h"
-#include "nsIHTMLContentSink.h"
-#include "nsIInterfaceRequestor.h"
-#include "nsIInterfaceRequestorUtils.h"
-#include "nsIScriptContext.h"
-#include "nsIScriptElement.h"
-#include "nsIScriptGlobalObject.h"
-#include "nsIURI.h"
-#include "nsNameSpaceManager.h"
-#include "nsNodeInfoManager.h"
-#include "nsReadableUtils.h"
-#include "nsStubDocumentObserver.h"
-#include "nsTArray.h"
-#include "nsTextNode.h"
-#include "nsUnicharUtils.h"
-#include "prtime.h"
-
-using namespace mozilla;
-using namespace mozilla::dom;
-
-//----------------------------------------------------------------------
-
-nsGenericHTMLElement* NS_NewHTMLNOTUSEDElement(
- already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
- FromParser aFromParser) {
- MOZ_ASSERT_UNREACHABLE("The element ctor should never be called");
- return nullptr;
-}
-
-#define HTML_TAG(_tag, _classname, _interfacename) \
- NS_NewHTML##_classname##Element,
-#define HTML_OTHER(_tag) NS_NewHTMLNOTUSEDElement,
-static const HTMLContentCreatorFunction sHTMLContentCreatorFunctions[] = {
- NS_NewHTMLUnknownElement,
-#include "nsHTMLTagList.h"
-#undef HTML_TAG
-#undef HTML_OTHER
- NS_NewHTMLUnknownElement};
-
-nsresult NS_NewHTMLElement(Element** aResult,
- already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
- FromParser aFromParser, nsAtom* aIsAtom,
- mozilla::dom::CustomElementDefinition* aDefinition) {
- RefPtr<mozilla::dom::NodeInfo> nodeInfo = aNodeInfo;
-
- NS_ASSERTION(
- nodeInfo->NamespaceEquals(kNameSpaceID_XHTML),
- "Trying to create HTML elements that don't have the XHTML namespace");
-
- return nsContentUtils::NewXULOrHTMLElement(aResult, nodeInfo, aFromParser,
- aIsAtom, aDefinition);
-}
-
-already_AddRefed<nsGenericHTMLElement> CreateHTMLElement(
- uint32_t aNodeType, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
- FromParser aFromParser) {
- NS_ASSERTION(
- aNodeType <= NS_HTML_TAG_MAX || aNodeType == eHTMLTag_userdefined,
- "aNodeType is out of bounds");
-
- HTMLContentCreatorFunction cb = sHTMLContentCreatorFunctions[aNodeType];
-
- NS_ASSERTION(cb != NS_NewHTMLNOTUSEDElement,
- "Don't know how to construct tag element!");
-
- RefPtr<nsGenericHTMLElement> result = cb(std::move(aNodeInfo), aFromParser);
-
- return result.forget();
-}
diff --git a/dom/xml/nsXMLContentSink.cpp b/dom/xml/nsXMLContentSink.cpp
@@ -68,10 +68,6 @@ using namespace mozilla::dom;
// 1) what's not allowed - We need to figure out which HTML tags
// (prefixed with a HTML namespace qualifier) are explicitly not
// allowed (if any).
-// 2) factoring code with nsHTMLContentSink - There's some amount of
-// common code between this and the HTML content sink. This will
-// increase as we support more and more HTML elements. How can code
-// from the code be factored?
nsresult NS_NewXMLContentSink(nsIXMLContentSink** aResult, Document* aDoc,
nsIURI* aURI, nsISupports* aContainer,
diff --git a/parser/html/nsHtml5TreeOpExecutor.cpp b/parser/html/nsHtml5TreeOpExecutor.cpp
@@ -186,9 +186,9 @@ nsHtml5TreeOpExecutor::DidBuildModel(bool aTerminated) {
}
});
- // This comes from nsXMLContentSink and nsHTMLContentSink
- // If this parser has been marked as broken, treat the end of parse as
- // forced termination.
+ // This comes from nsXMLContentSink and the old (now removed)
+ // nsHTMLContentSink. If this parser has been marked as broken, treat the end
+ // of parse as forced termination.
DidBuildModelImpl(aTerminated || NS_FAILED(IsBroken()));
bool destroying = true;
diff --git a/parser/htmlparser/nsHTMLTagList.h b/parser/htmlparser/nsHTMLTagList.h
@@ -27,7 +27,7 @@
The first argument to HTML_TAG is the tag name. The second argument is the
"creator" method of the form NS_New$TAGNAMEElement, that will be used by
- nsHTMLContentSink.cpp to create a content object for a tag of that
+ HTMLElementFactory.cpp to create a content object for a tag of that
type. Use NOTUSED, if the particular tag has a non-standard creator.
The third argument is the interface name specified for this element
in the HTML specification. It can be empty if the relevant interface name
@@ -188,7 +188,7 @@ HTML_HTMLELEMENT_TAG(wbr)
HTML_TAG(xmp, Pre, Pre)
/* These are not for tags. But they will be included in the nsHTMLTag
- enum anyway */
+ enum anyway, because they are used by HTMLEditUtils. */
HTML_OTHER(text)
HTML_OTHER(whitespace)
diff --git a/parser/htmlparser/nsHTMLTags.h b/parser/htmlparser/nsHTMLTags.h
@@ -20,7 +20,7 @@
These enum values are used as the index of array in various places.
If we change the structure of the enum by adding entries to it or removing
entries from it _directly_, not via nsHTMLTagList.h, don't forget to update
- dom/bindings/BindingUtils.cpp and dom/html/nsHTMLContentSink.cpp as well.
+ dom/bindings/BindingUtils.cpp and dom/html/HTMLElementFactory.cpp as well.
*/
#define HTML_TAG(_tag, _classname, _interfacename) eHTMLTag_##_tag,
#define HTML_OTHER(_tag) eHTMLTag_##_tag,
diff --git a/parser/htmlparser/nsParser.cpp b/parser/htmlparser/nsParser.cpp
@@ -76,13 +76,7 @@ when all of the document has been tokenized and there aren't any pending
nsParserContinueEvents. This can cause problems if the application assumes
that it can monitor the load requests to determine when the document load has
been completed. This is what happens in Mozilla. The document is considered
-completely loaded when all of the load requests have been satisfied. To delay
-the document load until all of the parsing has been completed the
-nsHTMLContentSink adds a dummy parser load request which is not removed until
-the nsHTMLContentSink's DidBuildModel is called. The CNavDTD will not call
-DidBuildModel until the final chunk of data has been passed to the parser
-through the OnDataAvailable and there aren't any pending
-nsParserContineEvents.
+completely loaded when all of the load requests have been satisfied.
Currently the parser is ignores requests to be interrupted during the
processing of script. This is because a document.write followed by JavaScript