From 61e46a6d58a58e249f1982d903780bf5bccb8f6b Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 17 Apr 2020 06:24:43 -0400 Subject: Issue #1375 - Stop largely using the parser service This is based on Bug 1395828 * Add nsHTMLElement::IsBlock() * Rename nsHTMLTags methods * Remove AssertParserServiceIsCorrect() * Remove most uses of nsIParserService/nsParserService --- dom/base/CustomElementRegistry.cpp | 10 ++-------- dom/base/nsContentUtils.cpp | 5 +++++ dom/base/nsDocument.cpp | 1 - dom/base/nsDocumentEncoder.cpp | 22 +++++----------------- dom/base/nsHTMLContentSerializer.cpp | 22 ++++++++-------------- dom/base/nsXHTMLContentSerializer.cpp | 28 +++------------------------- dom/base/nsXMLContentSerializer.cpp | 13 ++++--------- dom/bindings/BindingUtils.cpp | 10 ++-------- dom/html/nsHTMLContentSink.cpp | 9 ++------- dom/xul/XULDocument.cpp | 1 - 10 files changed, 31 insertions(+), 90 deletions(-) (limited to 'dom') diff --git a/dom/base/CustomElementRegistry.cpp b/dom/base/CustomElementRegistry.cpp index 99452df65..e4d4c0670 100644 --- a/dom/base/CustomElementRegistry.cpp +++ b/dom/base/CustomElementRegistry.cpp @@ -11,7 +11,7 @@ #include "mozilla/dom/HTMLElementBinding.h" #include "mozilla/dom/WebComponentsBinding.h" #include "mozilla/dom/DocGroup.h" -#include "nsIParserService.h" +#include "nsHTMLTags.h" #include "jsapi.h" namespace mozilla { @@ -588,14 +588,8 @@ CustomElementRegistry::Define(const nsAString& aName, return; } - nsIParserService* ps = nsContentUtils::GetParserService(); - if (!ps) { - aRv.Throw(NS_ERROR_UNEXPECTED); - return; - } - // bgsound and multicol are unknown html element. - int32_t tag = ps->HTMLCaseSensitiveAtomTagToId(extendsAtom); + int32_t tag = nsHTMLTags::CaseSensitiveAtomTagToId(extendsAtom); if (tag == eHTMLTag_userdefined || tag == eHTMLTag_bgsound || tag == eHTMLTag_multicol) { diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index f4828b162..a68f5ef87 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -102,6 +102,7 @@ #include "nsHostObjectProtocolHandler.h" #include "nsHtml5Module.h" #include "nsHtml5StringParser.h" +#include "nsHTMLTags.h" #include "nsIAddonPolicyService.h" #include "nsIAnonymousContentCreator.h" #include "nsIAsyncVerifyRedirectCallback.h" @@ -501,6 +502,8 @@ nsContentUtils::Init() return NS_OK; } + nsHTMLTags::AddRefTable(); + sNameSpaceManager = nsNameSpaceManager::GetInstance(); NS_ENSURE_TRUE(sNameSpaceManager, NS_ERROR_OUT_OF_MEMORY); @@ -1927,6 +1930,8 @@ nsContentUtils::Shutdown() { sInitialized = false; + nsHTMLTags::ReleaseTable(); + NS_IF_RELEASE(sContentPolicyService); sTriedToGetContentPolicy = false; uint32_t i; diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 130580fad..87d860c6a 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -116,7 +116,6 @@ #include "nsBidiUtils.h" -#include "nsIParserService.h" #include "nsContentCreatorFunctions.h" #include "nsIScriptContext.h" diff --git a/dom/base/nsDocumentEncoder.cpp b/dom/base/nsDocumentEncoder.cpp index de41a7331..2f5c3dc0a 100644 --- a/dom/base/nsDocumentEncoder.cpp +++ b/dom/base/nsDocumentEncoder.cpp @@ -32,7 +32,6 @@ #include "nsIDOMDocument.h" #include "nsGkAtoms.h" #include "nsIContent.h" -#include "nsIParserService.h" #include "nsIScriptContext.h" #include "nsIScriptGlobalObject.h" #include "nsIScriptSecurityManager.h" @@ -40,6 +39,7 @@ #include "nsISelectionPrivate.h" #include "nsITransferable.h" // for kUnicodeMime #include "nsContentUtils.h" +#include "nsElementTable.h" #include "nsNodeUtils.h" #include "nsUnicharUtils.h" #include "nsReadableUtils.h" @@ -1741,9 +1741,6 @@ nsHTMLCopyEncoder::GetPromotedPoint(Endpoint aWhere, nsIDOMNode *aNode, int32_t rv = GetNodeLocation(node, address_of(parent), &offset); NS_ENSURE_SUCCESS(rv, rv); if (offset == -1) return NS_OK; // we hit generated content; STOP - nsIParserService *parserService = nsContentUtils::GetParserService(); - if (!parserService) - return NS_ERROR_OUT_OF_MEMORY; while ((IsFirstNode(node)) && (!IsRoot(parent)) && (parent != common)) { if (bResetPromotion) @@ -1751,11 +1748,8 @@ nsHTMLCopyEncoder::GetPromotedPoint(Endpoint aWhere, nsIDOMNode *aNode, int32_t nsCOMPtr content = do_QueryInterface(parent); if (content && content->IsHTMLElement()) { - bool isBlock = false; - parserService->IsBlock(parserService->HTMLAtomTagToId( - content->NodeInfo()->NameAtom()), isBlock); - if (isBlock) - { + if (nsHTMLElement::IsBlock(nsHTMLTags::AtomTagToId( + content->NodeInfo()->NameAtom()))) { bResetPromotion = false; } } @@ -1824,9 +1818,6 @@ nsHTMLCopyEncoder::GetPromotedPoint(Endpoint aWhere, nsIDOMNode *aNode, int32_t rv = GetNodeLocation(node, address_of(parent), &offset); NS_ENSURE_SUCCESS(rv, rv); if (offset == -1) return NS_OK; // we hit generated content; STOP - nsIParserService *parserService = nsContentUtils::GetParserService(); - if (!parserService) - return NS_ERROR_OUT_OF_MEMORY; while ((IsLastNode(node)) && (!IsRoot(parent)) && (parent != common)) { if (bResetPromotion) @@ -1834,11 +1825,8 @@ nsHTMLCopyEncoder::GetPromotedPoint(Endpoint aWhere, nsIDOMNode *aNode, int32_t nsCOMPtr content = do_QueryInterface(parent); if (content && content->IsHTMLElement()) { - bool isBlock = false; - parserService->IsBlock(parserService->HTMLAtomTagToId( - content->NodeInfo()->NameAtom()), isBlock); - if (isBlock) - { + if (nsHTMLElement::IsBlock(nsHTMLTags::AtomTagToId( + content->NodeInfo()->NameAtom()))) { bResetPromotion = false; } } diff --git a/dom/base/nsHTMLContentSerializer.cpp b/dom/base/nsHTMLContentSerializer.cpp index c135c4cf8..ea9c5a66f 100644 --- a/dom/base/nsHTMLContentSerializer.cpp +++ b/dom/base/nsHTMLContentSerializer.cpp @@ -15,6 +15,7 @@ #include "nsIDOMElement.h" #include "nsIContent.h" #include "nsIDocument.h" +#include "nsElementTable.h" #include "nsNameSpaceManager.h" #include "nsString.h" #include "nsUnicharUtils.h" @@ -347,20 +348,13 @@ nsHTMLContentSerializer::AppendElementEnd(Element* aElement, } if (ns == kNameSpaceID_XHTML) { - nsIParserService* parserService = nsContentUtils::GetParserService(); - - if (parserService) { - bool isContainer; - - parserService-> - IsContainer(parserService->HTMLCaseSensitiveAtomTagToId(name), - isContainer); - if (!isContainer) { - // Keep this in sync with the cleanup at the end of this method. - MOZ_ASSERT(name != nsGkAtoms::body); - MaybeLeaveFromPreContent(content); - return NS_OK; - } + bool isContainer = + nsHTMLElement::IsContainer(nsHTMLTags::CaseSensitiveAtomTagToId(name)); + if (!isContainer) { + // Keep this in sync with the cleanup at the end of this method. + MOZ_ASSERT(name != nsGkAtoms::body); + MaybeLeaveFromPreContent(content); + return NS_OK; } } diff --git a/dom/base/nsXHTMLContentSerializer.cpp b/dom/base/nsXHTMLContentSerializer.cpp index 0a39ef663..aa330364b 100755 --- a/dom/base/nsXHTMLContentSerializer.cpp +++ b/dom/base/nsXHTMLContentSerializer.cpp @@ -15,6 +15,7 @@ #include "nsIDOMElement.h" #include "nsIContent.h" #include "nsIDocument.h" +#include "nsElementTable.h" #include "nsNameSpaceManager.h" #include "nsString.h" #include "nsUnicharUtils.h" @@ -27,7 +28,6 @@ #include "nsEscape.h" #include "nsITextToSubURI.h" #include "nsCRT.h" -#include "nsIParserService.h" #include "nsContentUtils.h" #include "nsLWBrkCIID.h" #include "nsIScriptElement.h" @@ -667,18 +667,7 @@ nsXHTMLContentSerializer::LineBreakBeforeOpen(int32_t aNamespaceID, nsIAtom* aNa aName == nsGkAtoms::html) { return true; } - else { - nsIParserService* parserService = nsContentUtils::GetParserService(); - - if (parserService) { - bool res; - parserService-> - IsBlock(parserService->HTMLCaseSensitiveAtomTagToId(aName), res); - return res; - } - } - - return mAddSpace; + return nsHTMLElement::IsBlock(nsHTMLTags::CaseSensitiveAtomTagToId(aName)); } bool @@ -761,18 +750,7 @@ nsXHTMLContentSerializer::LineBreakAfterClose(int32_t aNamespaceID, nsIAtom* aNa (aName == nsGkAtoms::div)) { return true; } - else { - nsIParserService* parserService = nsContentUtils::GetParserService(); - - if (parserService) { - bool res; - parserService-> - IsBlock(parserService->HTMLCaseSensitiveAtomTagToId(aName), res); - return res; - } - } - - return false; + return nsHTMLElement::IsBlock(nsHTMLTags::CaseSensitiveAtomTagToId(aName)); } diff --git a/dom/base/nsXMLContentSerializer.cpp b/dom/base/nsXMLContentSerializer.cpp index f12bb8fdc..71a675e11 100644 --- a/dom/base/nsXMLContentSerializer.cpp +++ b/dom/base/nsXMLContentSerializer.cpp @@ -19,7 +19,7 @@ #include "nsIContent.h" #include "nsIDocument.h" #include "nsIDocumentEncoder.h" -#include "nsIParserService.h" +#include "nsElementTable.h" #include "nsNameSpaceManager.h" #include "nsTextFragment.h" #include "nsString.h" @@ -994,14 +994,9 @@ ElementNeedsSeparateEndTag(Element* aElement, Element* aOriginalElement) // HTML container tags should have a separate end tag even if empty, per spec. // See // https://w3c.github.io/DOM-Parsing/#dfn-concept-xml-serialization-algorithm - bool isHTMLContainer = true; // Default in case we get no parser service. - nsIParserService* parserService = nsContentUtils::GetParserService(); - if (parserService) { - nsIAtom* localName = aElement->NodeInfo()->NameAtom(); - parserService->IsContainer( - parserService->HTMLCaseSensitiveAtomTagToId(localName), - isHTMLContainer); - } + nsIAtom* localName = aElement->NodeInfo()->NameAtom(); + bool isHTMLContainer = + nsHTMLElement::IsContainer(nsHTMLTags::CaseSensitiveAtomTagToId(localName)); return isHTMLContainer; } diff --git a/dom/bindings/BindingUtils.cpp b/dom/bindings/BindingUtils.cpp index f76f14d95..51274f1af 100644 --- a/dom/bindings/BindingUtils.cpp +++ b/dom/bindings/BindingUtils.cpp @@ -23,9 +23,9 @@ #include "nsContentCreatorFunctions.h" #include "nsContentUtils.h" #include "nsGlobalWindow.h" +#include "nsHTMLTags.h" #include "nsIDocShell.h" #include "nsIDOMGlobalPropertyInitializer.h" -#include "nsIParserService.h" #include "nsIPermissionManager.h" #include "nsIPrincipal.h" #include "nsIXPConnect.h" @@ -3493,13 +3493,7 @@ CreateHTMLElement(const GlobalObject& aGlobal, const JS::CallArgs& aCallArgs, // Step 5. // If the definition is for a customized built-in element, the localName // should be defined in the specification. - nsIParserService* parserService = nsContentUtils::GetParserService(); - if (!parserService) { - aRv.Throw(NS_ERROR_UNEXPECTED); - return nullptr; - } - - tag = parserService->HTMLCaseSensitiveAtomTagToId(definition->mLocalName); + tag = nsHTMLTags::CaseSensitiveAtomTagToId(definition->mLocalName); if (tag == eHTMLTag_userdefined) { aRv.ThrowTypeError(); return nullptr; diff --git a/dom/html/nsHTMLContentSink.cpp b/dom/html/nsHTMLContentSink.cpp index 1fe5d2a86..1c390a53e 100644 --- a/dom/html/nsHTMLContentSink.cpp +++ b/dom/html/nsHTMLContentSink.cpp @@ -14,6 +14,7 @@ #include "nsContentSink.h" #include "nsCOMPtr.h" +#include "nsHTMLTags.h" #include "nsReadableUtils.h" #include "nsUnicharUtils.h" #include "nsIHTMLContentSink.h" @@ -59,8 +60,6 @@ #include "nsIScriptGlobalObject.h" #include "nsNameSpaceManager.h" -#include "nsIParserService.h" - #include "nsIStyleSheetLinkingElement.h" #include "nsITimer.h" #include "nsError.h" @@ -262,10 +261,6 @@ NS_NewHTMLElement(Element** aResult, already_AddRefed&& RefPtr nodeInfo = aNodeInfo; - nsIParserService* parserService = nsContentUtils::GetParserService(); - if (!parserService) - return NS_ERROR_OUT_OF_MEMORY; - nsIAtom *name = nodeInfo->NameAtom(); RefPtr tagAtom = nodeInfo->NameAtom(); RefPtr typeAtom = aIs ? NS_Atomize(*aIs) : tagAtom; @@ -273,7 +268,7 @@ NS_NewHTMLElement(Element** aResult, already_AddRefed&& NS_ASSERTION(nodeInfo->NamespaceEquals(kNameSpaceID_XHTML), "Trying to HTML elements that don't have the XHTML namespace"); - int32_t tag = parserService->HTMLCaseSensitiveAtomTagToId(name); + int32_t tag = nsHTMLTags::CaseSensitiveAtomTagToId(name); bool isCustomElementName = (tag == eHTMLTag_userdefined && nsContentUtils::IsCustomElementName(name)); diff --git a/dom/xul/XULDocument.cpp b/dom/xul/XULDocument.cpp index 1dcb55aee..929efc1af 100644 --- a/dom/xul/XULDocument.cpp +++ b/dom/xul/XULDocument.cpp @@ -66,7 +66,6 @@ #include "nsContentUtils.h" #include "nsIParser.h" #include "nsCharsetSource.h" -#include "nsIParserService.h" #include "mozilla/StyleSheetInlines.h" #include "mozilla/css/Loader.h" #include "nsIScriptError.h" -- cgit v1.2.3