Bug 1395828 (part 4) - Remove nsIParserService/nsParserService. r=mrbkap.

It a stateless wrapper around static methods in nsHTMLTags and nsHTMLElement,
and hence an unnecessary layer of indirection that just adds complexity and
slowness. This patch removes it, cutting almost 300 lines of code.

This requires making nsElementTable.h an exported header, to expose the
nsHTMLElement methods.

--HG--
extra : rebase_source : abbcb8e5001389affbf717092213b898673db07f
This commit is contained in:
Nicholas Nethercote 2017-09-05 20:19:06 +10:00
Родитель a444efbbd7
Коммит 2ef37710e7
21 изменённых файлов: 51 добавлений и 341 удалений

Просмотреть файл

@ -10,7 +10,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 {
@ -666,14 +666,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) {

Просмотреть файл

@ -15,7 +15,7 @@
#include "nsContentUtils.h"
#include "nsINode.h"
#include "nsCycleCollectionParticipant.h"
#include "nsIParserService.h"
#include "nsElementTable.h"
using mozilla::DebugOnly;
@ -407,10 +407,9 @@ nsContentIterator::InitInternal(nsINode* aStartContainer, uint32_t aStartOffset,
// case in order to address bug 1215798.
bool startIsContainer = true;
if (aStartContainer->IsHTMLElement()) {
if (nsIParserService* ps = nsContentUtils::GetParserService()) {
nsIAtom* name = aStartContainer->NodeInfo()->NameAtom();
ps->IsContainer(ps->HTMLAtomTagToId(name), startIsContainer);
}
nsIAtom* name = aStartContainer->NodeInfo()->NameAtom();
startIsContainer =
nsHTMLElement::IsContainer(nsHTMLTags::AtomTagToId(name));
}
if (!startIsData && (startIsContainer || aStartOffset)) {
mFirst = GetNextSibling(aStartContainer);
@ -471,10 +470,9 @@ nsContentIterator::InitInternal(nsINode* aStartContainer, uint32_t aStartOffset,
// include the end node in the range).
bool endIsContainer = true;
if (aEndContainer->IsHTMLElement()) {
if (nsIParserService* ps = nsContentUtils::GetParserService()) {
nsIAtom* name = aEndContainer->NodeInfo()->NameAtom();
ps->IsContainer(ps->HTMLAtomTagToId(name), endIsContainer);
}
nsIAtom* name = aEndContainer->NodeInfo()->NameAtom();
endIsContainer =
nsHTMLElement::IsContainer(nsHTMLTags::AtomTagToId(name));
}
if (!endIsData && !endIsContainer && !aEndOffset) {
mLast = PrevNode(aEndContainer);

Просмотреть файл

@ -109,6 +109,7 @@
#include "nsHtml5Module.h"
#include "nsHtml5StringParser.h"
#include "nsHTMLDocument.h"
#include "nsHTMLTags.h"
#include "nsIAddonPolicyService.h"
#include "nsIAnonymousContentCreator.h"
#include "nsIAsyncVerifyRedirectCallback.h"
@ -161,7 +162,6 @@
#include "nsIObserverService.h"
#include "nsIOfflineCacheUpdate.h"
#include "nsIParser.h"
#include "nsIParserService.h"
#include "nsIPermissionManager.h"
#include "nsIPluginHost.h"
#include "nsIRequest.h"
@ -252,7 +252,6 @@ nsIXPConnect *nsContentUtils::sXPConnect;
nsIScriptSecurityManager *nsContentUtils::sSecurityManager;
nsIPrincipal *nsContentUtils::sSystemPrincipal;
nsIPrincipal *nsContentUtils::sNullSubjectPrincipal;
nsIParserService *nsContentUtils::sParserService = nullptr;
nsNameSpaceManager *nsContentUtils::sNameSpaceManager;
nsIIOService *nsContentUtils::sIOService;
nsIUUIDGenerator *nsContentUtils::sUUIDGenerator;
@ -444,7 +443,6 @@ static const nsAttrValue::EnumTable kAutocompleteContactFieldHintTable[] = {
namespace {
static NS_DEFINE_CID(kParserServiceCID, NS_PARSERSERVICE_CID);
static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID);
static PLDHashTable* sEventListenerManagersHash;
@ -617,6 +615,8 @@ nsContentUtils::Init()
return NS_OK;
}
nsHTMLTags::AddRefTable();
sNameSpaceManager = nsNameSpaceManager::GetInstance();
NS_ENSURE_TRUE(sNameSpaceManager, NS_ERROR_OUT_OF_MEMORY);
@ -1569,27 +1569,6 @@ nsContentUtils::IsUserIdle(uint32_t aRequestedIdleTimeInMS, bool* aUserIsIdle)
return NS_OK;
}
/**
* Access a cached parser service. Don't addref. We need only one
* reference to it and this class has that one.
*/
/* static */
nsIParserService*
nsContentUtils::GetParserService()
{
// XXX: This isn't accessed from several threads, is it?
if (!sParserService) {
// Lock, recheck sCachedParserService and aquire if this should be
// safe for multiple threads.
nsresult rv = CallGetService(kParserServiceCID, &sParserService);
if (NS_FAILED(rv)) {
sParserService = nullptr;
}
}
return sParserService;
}
/**
* A helper function that parses a sandbox attribute (of an <iframe> or a CSP
* directive) and converts it to the set of flags used internally.
@ -2156,6 +2135,8 @@ nsContentUtils::Shutdown()
{
sInitialized = false;
nsHTMLTags::ReleaseTable();
NS_IF_RELEASE(sContentPolicyService);
sTriedToGetContentPolicy = false;
uint32_t i;
@ -2168,7 +2149,6 @@ nsContentUtils::Shutdown()
NS_IF_RELEASE(sSecurityManager);
NS_IF_RELEASE(sSystemPrincipal);
NS_IF_RELEASE(sNullSubjectPrincipal);
NS_IF_RELEASE(sParserService);
NS_IF_RELEASE(sIOService);
NS_IF_RELEASE(sUUIDGenerator);
NS_IF_RELEASE(sLineBreaker);

Просмотреть файл

@ -85,7 +85,6 @@ class nsIMessageBroadcaster;
class nsNameSpaceManager;
class nsIObserver;
class nsIParser;
class nsIParserService;
class nsIPluginTag;
class nsIPresShell;
class nsIPrincipal;
@ -612,8 +611,6 @@ public:
// element.
static bool InProlog(nsINode *aNode);
static nsIParserService* GetParserService();
static nsNameSpaceManager* NameSpaceManager()
{
return sNameSpaceManager;
@ -3247,8 +3244,6 @@ private:
static nsIPrincipal *sSystemPrincipal;
static nsIPrincipal *sNullSubjectPrincipal;
static nsIParserService *sParserService;
static nsNameSpaceManager *sNameSpaceManager;
static nsIIOService *sIOService;

Просмотреть файл

@ -124,7 +124,6 @@
#include "nsBidiUtils.h"
#include "nsIParserService.h"
#include "nsContentCreatorFunctions.h"
#include "nsIScriptContext.h"

Просмотреть файл

@ -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"
@ -1730,9 +1730,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)
@ -1740,11 +1737,8 @@ nsHTMLCopyEncoder::GetPromotedPoint(Endpoint aWhere, nsIDOMNode *aNode, int32_t
nsCOMPtr<nsIContent> 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;
}
}
@ -1813,9 +1807,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)
@ -1823,11 +1814,8 @@ nsHTMLCopyEncoder::GetPromotedPoint(Endpoint aWhere, nsIDOMNode *aNode, int32_t
nsCOMPtr<nsIContent> 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;
}
}

Просмотреть файл

@ -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"
@ -25,7 +26,6 @@
#include "nsNetUtil.h"
#include "nsEscape.h"
#include "nsCRT.h"
#include "nsIParserService.h"
#include "nsContentUtils.h"
#include "nsLWBrkCIID.h"
#include "nsIScriptElement.h"
@ -339,20 +339,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;
}
}

Просмотреть файл

@ -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"
@ -25,7 +26,6 @@
#include "nsNetUtil.h"
#include "nsEscape.h"
#include "nsCRT.h"
#include "nsIParserService.h"
#include "nsContentUtils.h"
#include "nsLWBrkCIID.h"
#include "nsIScriptElement.h"
@ -595,18 +595,8 @@ 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
@ -689,18 +679,8 @@ 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));
}

Просмотреть файл

@ -20,7 +20,7 @@
#include "nsIContentInlines.h"
#include "nsIDocument.h"
#include "nsIDocumentEncoder.h"
#include "nsIParserService.h"
#include "nsElementTable.h"
#include "nsNameSpaceManager.h"
#include "nsTextFragment.h"
#include "nsString.h"
@ -995,14 +995,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;
}

Просмотреть файл

@ -21,9 +21,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"
@ -3627,13 +3627,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<MSG_ILLEGAL_CONSTRUCTOR>();
return nullptr;

Просмотреть файл

@ -15,11 +15,11 @@
#include "nsCOMPtr.h"
#include "nsContentUtils.h"
#include "nsCopySupport.h"
#include "nsElementTable.h"
#include "nsFocusManager.h"
#include "nsFontMetrics.h"
#include "nsFrameSelection.h"
#include "nsIContentIterator.h"
#include "nsIParserService.h"
#include "nsIPresShell.h"
#include "nsISelection.h"
#include "nsIFrame.h"
@ -3039,10 +3039,9 @@ ContentEventHandler::GetStartOffset(const RawRange& aRawRange,
nsINode* startNode = aRawRange.GetStartContainer();
bool startIsContainer = true;
if (startNode->IsHTMLElement()) {
if (nsIParserService* ps = nsContentUtils::GetParserService()) {
nsIAtom* name = startNode->NodeInfo()->NameAtom();
ps->IsContainer(ps->HTMLAtomTagToId(name), startIsContainer);
}
nsIAtom* name = startNode->NodeInfo()->NameAtom();
startIsContainer =
nsHTMLElement::IsContainer(nsHTMLTags::AtomTagToId(name));
}
const NodePosition& startPos =
startIsContainer ?

Просмотреть файл

@ -14,6 +14,7 @@
#include "nsContentSink.h"
#include "nsCOMPtr.h"
#include "nsHTMLTags.h"
#include "nsReadableUtils.h"
#include "nsUnicharUtils.h"
#include "nsIHTMLContentSink.h"
@ -57,8 +58,6 @@
#include "nsIScriptGlobalObject.h"
#include "nsNameSpaceManager.h"
#include "nsIParserService.h"
#include "nsIStyleSheetLinkingElement.h"
#include "nsITimer.h"
#include "nsError.h"
@ -232,16 +231,12 @@ NS_NewHTMLElement(Element** aResult, already_AddRefed<mozilla::dom::NodeInfo>&&
RefPtr<mozilla::dom::NodeInfo> nodeInfo = aNodeInfo;
nsIParserService* parserService = nsContentUtils::GetParserService();
if (!parserService)
return NS_ERROR_OUT_OF_MEMORY;
nsIAtom *name = nodeInfo->NameAtom();
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);
// Per the Custom Element specification, unknown tags that are valid custom
// element names should be HTMLElement instead of HTMLUnknownElement.

Просмотреть файл

@ -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"

Просмотреть файл

@ -106,16 +106,12 @@
#include "prtime.h" // for PR_Now
class nsIOutputStream;
class nsIParserService;
class nsITransferable;
#ifdef DEBUG
#include "nsIDOMHTMLDocument.h" // for nsIDOMHTMLDocument
#endif
// Defined in nsEditorRegistration.cpp
extern nsIParserService *sParserService;
namespace mozilla {
using namespace dom;

Просмотреть файл

@ -59,13 +59,13 @@
#include "nsIWidget.h"
#include "nsIFrame.h"
#include "nsIParserService.h"
#include "mozilla/dom/Selection.h"
#include "mozilla/dom/DocumentFragment.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/Event.h"
#include "mozilla/dom/EventTarget.h"
#include "mozilla/dom/HTMLBodyElement.h"
#include "nsElementTable.h"
#include "nsTextFragment.h"
#include "nsContentList.h"
#include "mozilla/StyleSheet.h"
@ -700,8 +700,8 @@ HTMLEditor::NodeIsBlockStatic(const nsINode* aElement)
{
MOZ_ASSERT(aElement);
// Nodes we know we want to treat as block
// even though the parser says they're not:
// We want to treat these as block nodes even though nsHTMLElement says
// they're not.
if (aElement->IsAnyOfHTMLElements(nsGkAtoms::body,
nsGkAtoms::head,
nsGkAtoms::tbody,
@ -715,18 +715,8 @@ HTMLEditor::NodeIsBlockStatic(const nsINode* aElement)
return true;
}
bool isBlock;
#ifdef DEBUG
// XXX we can't use DebugOnly here because VC++ is stupid (bug 802884)
nsresult rv =
#endif
nsContentUtils::GetParserService()->
IsBlock(nsContentUtils::GetParserService()->HTMLAtomTagToId(
aElement->NodeInfo()->NameAtom()),
isBlock);
MOZ_ASSERT(rv == NS_OK);
return isBlock;
return nsHTMLElement::IsBlock(
nsHTMLTags::AtomTagToId(aElement->NodeInfo()->NameAtom()));
}
nsresult
@ -3446,17 +3436,15 @@ bool
HTMLEditor::TagCanContainTag(nsIAtom& aParentTag,
nsIAtom& aChildTag)
{
nsIParserService* parserService = nsContentUtils::GetParserService();
int32_t childTagEnum;
// XXX Should this handle #cdata-section too?
if (&aChildTag == nsGkAtoms::textTagName) {
childTagEnum = eHTMLTag_text;
} else {
childTagEnum = parserService->HTMLAtomTagToId(&aChildTag);
childTagEnum = nsHTMLTags::AtomTagToId(&aChildTag);
}
int32_t parentTagEnum = parserService->HTMLAtomTagToId(&aParentTag);
int32_t parentTagEnum = nsHTMLTags::AtomTagToId(&aParentTag);
return HTMLEditUtils::CanContain(parentTagEnum, childTagEnum);
}
@ -3470,8 +3458,7 @@ HTMLEditor::IsContainer(nsINode* aNode)
if (aNode->IsNodeOfType(nsINode::eTEXT)) {
tagEnum = eHTMLTag_text;
} else {
tagEnum =
nsContentUtils::GetParserService()->HTMLStringTagToId(aNode->NodeName());
tagEnum = nsHTMLTags::StringTagToId(aNode->NodeName());
}
return HTMLEditUtils::IsContainer(tagEnum);

Просмотреть файл

@ -18,6 +18,7 @@ XPIDL_SOURCES += [
XPIDL_MODULE = 'htmlparser'
EXPORTS += [
'nsElementTable.h',
'nsHTMLTagList.h',
'nsHTMLTags.h',
'nsIContentSink.h',
@ -25,7 +26,6 @@ EXPORTS += [
'nsIFragmentContentSink.h',
'nsIHTMLContentSink.h',
'nsIParser.h',
'nsIParserService.h',
'nsITokenizer.h',
'nsParserBase.h',
'nsParserCIID.h',
@ -43,7 +43,6 @@ UNIFIED_SOURCES += [
'nsParser.cpp',
'nsParserModule.cpp',
'nsParserMsgUtils.cpp',
'nsParserService.cpp',
'nsScanner.cpp',
'nsScannerString.cpp',
]

Просмотреть файл

@ -1,66 +0,0 @@
/* -*- Mode: C++; tab-width: 2; 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 nsIParserService_h__
#define nsIParserService_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsHTMLTags.h"
class nsIParser;
#define NS_PARSERSERVICE_CONTRACTID "@mozilla.org/parser/parser-service;1"
// {90a92e37-abd6-441b-9b39-4064d98e1ede}
#define NS_IPARSERSERVICE_IID \
{ 0x90a92e37, 0xabd6, 0x441b, { 0x9b, 0x39, 0x40, 0x64, 0xd9, 0x8e, 0x1e, 0xde } }
class nsIParserService : public nsISupports {
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IPARSERSERVICE_IID)
/**
* Looks up the nsHTMLTag enum value corresponding to the tag in aAtom. The
* lookup happens case insensitively.
*
* @param aAtom The tag to look up.
*
* @return int32_t The nsHTMLTag enum value corresponding to the tag in aAtom
* or eHTMLTag_userdefined if the tag does not correspond to
* any of the tag nsHTMLTag enum values.
*/
virtual int32_t HTMLAtomTagToId(nsIAtom* aAtom) const = 0;
/**
* Looks up the nsHTMLTag enum value corresponding to the tag in aAtom.
*
* @param aAtom The tag to look up.
*
* @return int32_t The nsHTMLTag enum value corresponding to the tag in aAtom
* or eHTMLTag_userdefined if the tag does not correspond to
* any of the tag nsHTMLTag enum values.
*/
virtual int32_t HTMLCaseSensitiveAtomTagToId(nsIAtom* aAtom) const = 0;
/**
* Looks up the nsHTMLTag enum value corresponding to the tag in aTag. The
* lookup happens case insensitively.
*
* @param aTag The tag to look up.
*
* @return int32_t The nsHTMLTag enum value corresponding to the tag in aTag
* or eHTMLTag_userdefined if the tag does not correspond to
* any of the tag nsHTMLTag enum values.
*/
virtual int32_t HTMLStringTagToId(const nsAString& aTag) const = 0;
NS_IMETHOD IsContainer(int32_t aId, bool& aIsContainer) const = 0;
NS_IMETHOD IsBlock(int32_t aId, bool& aIsBlock) const = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsIParserService, NS_IPARSERSERVICE_IID)
#endif // nsIParserService_h__

Просмотреть файл

@ -22,8 +22,4 @@
#define NS_EXPAT_DRIVER_CID \
{ 0xfff4fbe9, 0x528a, 0x4b37, { 0x81, 0x9d, 0xfc, 0x18, 0xf3, 0xa4, 0x1, 0xa7 } }
// {a6cf9112-15b3-11d2-932e-00805f8add32}
#define NS_PARSERSERVICE_CID \
{ 0xa6cf9112, 0x15b3, 0x11d2, { 0x93, 0x2e, 0x0, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } }
#endif

Просмотреть файл

@ -14,7 +14,6 @@
#include "nsHTMLTokenizer.h"
//#include "nsTextTokenizer.h"
#include "nsElementTable.h"
#include "nsParserService.h"
#include "nsSAXAttributes.h"
#include "nsSAXLocator.h"
#include "nsSAXXMLReader.h"
@ -31,7 +30,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsExpatDriver)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsParser)
NS_GENERIC_FACTORY_CONSTRUCTOR(CNavDTD)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsParserService)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSAXAttributes)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSAXXMLReader)
@ -41,7 +39,6 @@ NS_DEFINE_NAMED_CID(NS_EXPAT_DRIVER_CID);
#endif
NS_DEFINE_NAMED_CID(NS_PARSER_CID);
NS_DEFINE_NAMED_CID(NS_CNAVDTD_CID);
NS_DEFINE_NAMED_CID(NS_PARSERSERVICE_CID);
NS_DEFINE_NAMED_CID(NS_SAXATTRIBUTES_CID);
NS_DEFINE_NAMED_CID(NS_SAXXMLREADER_CID);
@ -51,14 +48,12 @@ static const mozilla::Module::CIDEntry kParserCIDs[] = {
#endif
{ &kNS_PARSER_CID, false, nullptr, nsParserConstructor },
{ &kNS_CNAVDTD_CID, false, nullptr, CNavDTDConstructor },
{ &kNS_PARSERSERVICE_CID, false, nullptr, nsParserServiceConstructor },
{ &kNS_SAXATTRIBUTES_CID, false, nullptr, nsSAXAttributesConstructor },
{ &kNS_SAXXMLREADER_CID, false, nullptr, nsSAXXMLReaderConstructor },
{ nullptr }
};
static const mozilla::Module::ContractIDEntry kParserContracts[] = {
{ NS_PARSERSERVICE_CONTRACTID, &kNS_PARSERSERVICE_CID },
{ NS_SAXATTRIBUTES_CONTRACTID, &kNS_SAXATTRIBUTES_CID },
{ NS_SAXXMLREADER_CONTRACTID, &kNS_SAXXMLREADER_CID },
{ nullptr }

Просмотреть файл

@ -1,56 +0,0 @@
/* -*- Mode: C++; tab-width: 2; 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/. */
#include "nsError.h"
#include "nsIAtom.h"
#include "nsParserService.h"
#include "nsElementTable.h"
#include "nsICategoryManager.h"
#include "nsCategoryManagerUtils.h"
nsParserService::nsParserService()
{
}
nsParserService::~nsParserService()
{
}
NS_IMPL_ISUPPORTS(nsParserService, nsIParserService)
int32_t
nsParserService::HTMLAtomTagToId(nsIAtom* aAtom) const
{
return nsHTMLTags::StringTagToId(nsDependentAtomString(aAtom));
}
int32_t
nsParserService::HTMLCaseSensitiveAtomTagToId(nsIAtom* aAtom) const
{
return nsHTMLTags::CaseSensitiveAtomTagToId(aAtom);
}
int32_t
nsParserService::HTMLStringTagToId(const nsAString& aTag) const
{
return nsHTMLTags::StringTagToId(aTag);
}
NS_IMETHODIMP
nsParserService::IsContainer(int32_t aId, bool& aIsContainer) const
{
aIsContainer = nsHTMLElement::IsContainer((eHTMLTags)aId);
return NS_OK;
}
NS_IMETHODIMP
nsParserService::IsBlock(int32_t aId, bool& aIsBlock) const
{
aIsBlock = nsHTMLElement::IsBlock((eHTMLTags)aId);
return NS_OK;
}

Просмотреть файл

@ -1,50 +0,0 @@
/* -*- Mode: C++; tab-width: 2; 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 NS_PARSERSERVICE_H__
#define NS_PARSERSERVICE_H__
#include "nsIParserService.h"
extern "C" int MOZ_XMLIsLetter(const char* ptr);
extern "C" int MOZ_XMLIsNCNameChar(const char* ptr);
/**
* Decodes an entity into the UTF-16 encoding of a Unicode character. If a ';'
* is found between `ptr` and `end` it will try to decode the entity and set
* `*next` to point to the character after the ;. The resulting UTF-16 code
* units will be written in `*result`, so if the entity is a valid numeric
* entity there needs to be space for at least two char16_t at the location
* `result` points to.
*
* @param ptr pointer to the ampersand.
* @param end pointer to the position after the last character of the
* string.
* @param next [out] will be set to the character after the ';' or null if
* the decoding was unsuccessful.
* @param result the buffer to write the resulting UTF-16 character in.
* @return the number of char16_t written to `*result`.
*/
extern "C" int MOZ_XMLTranslateEntity(const char* ptr, const char* end,
const char** next, char16_t* result);
class nsParserService : public nsIParserService {
virtual ~nsParserService();
public:
nsParserService();
NS_DECL_ISUPPORTS
int32_t HTMLAtomTagToId(nsIAtom* aAtom) const override;
int32_t HTMLCaseSensitiveAtomTagToId(nsIAtom* aAtom) const override;
int32_t HTMLStringTagToId(const nsAString& aTag) const override;
NS_IMETHOD IsContainer(int32_t aId, bool& aIsContainer) const override;
NS_IMETHOD IsBlock(int32_t aId, bool& aIsBlock) const override;
};
#endif