Bug 1749935 - Create nsParser directly instead of with a CID. r=hsivonen

Differential Revision: https://phabricator.services.mozilla.com/D135896
This commit is contained in:
Peter Van der Beken 2022-02-14 13:03:51 +00:00
parent 6c6f7200a6
commit 15b814ccd7
21 changed files with 32 additions and 108 deletions

View File

@ -561,6 +561,7 @@ LOCAL_INCLUDES += [
"/layout/xul",
"/netwerk/base",
"/netwerk/url-classifier",
"/parser/htmlparser",
"/security/manager/ssl",
"/widget",
"/xpcom/ds",

View File

@ -299,7 +299,6 @@
#include "nsIObjectLoadingContent.h"
#include "nsIObserver.h"
#include "nsIObserverService.h"
#include "nsIParser.h"
#include "nsIParserUtils.h"
#include "nsIPermissionManager.h"
#include "nsIPluginTag.h"
@ -346,7 +345,7 @@
#include "nsNodeInfoManager.h"
#include "nsPIDOMWindow.h"
#include "nsPIDOMWindowInlines.h"
#include "nsParserCIID.h"
#include "nsParser.h"
#include "nsParserConstants.h"
#include "nsPluginHost.h"
#include "nsPoint.h"
@ -452,7 +451,7 @@ nsContentUtils::UserInteractionObserver*
nsContentUtils::sUserInteractionObserver = nullptr;
nsHtml5StringParser* nsContentUtils::sHTMLFragmentParser = nullptr;
nsIParser* nsContentUtils::sXMLFragmentParser = nullptr;
nsParser* nsContentUtils::sXMLFragmentParser = nullptr;
nsIFragmentContentSink* nsContentUtils::sXMLFragmentSink = nullptr;
bool nsContentUtils::sFragmentParsingActive = false;
@ -591,8 +590,6 @@ static const nsAttrValue::EnumTable kAutocompleteContactFieldHintTable[] = {
namespace {
static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID);
static PLDHashTable* sEventListenerManagersHash;
// A global hashtable to for keeping the arena alive for cross docGroup node
@ -5177,7 +5174,7 @@ nsresult nsContentUtils::ParseFragmentXML(const nsAString& aSourceBuffer,
mozilla::AutoRestore<bool> guard(nsContentUtils::sFragmentParsingActive);
nsContentUtils::sFragmentParsingActive = true;
if (!sXMLFragmentParser) {
nsCOMPtr<nsIParser> parser = do_CreateInstance(kCParserCID);
RefPtr<nsParser> parser = new nsParser();
parser.forget(&sXMLFragmentParser);
// sXMLFragmentParser now owns the parser
}

View File

@ -94,7 +94,6 @@ class nsIInterfaceRequestor;
class nsILoadGroup;
class nsILoadInfo;
class nsIObserver;
class nsIParser;
class nsIPluginTag;
class nsIPrincipal;
class nsIReferrerInfo;
@ -112,6 +111,7 @@ class nsIURI;
class nsIWidget;
class nsIXPConnect;
class nsNodeInfoManager;
class nsParser;
class nsPIWindowRoot;
class nsPresContext;
class nsStringBuffer;
@ -3404,7 +3404,7 @@ class nsContentUtils {
static UserInteractionObserver* sUserInteractionObserver;
static nsHtml5StringParser* sHTMLFragmentParser;
static nsIParser* sXMLFragmentParser;
static nsParser* sXMLFragmentParser;
static nsIFragmentContentSink* sXMLFragmentSink;
/**

View File

@ -250,6 +250,7 @@ LOCAL_INCLUDES += [
"/layout/tables",
"/layout/xul",
"/netwerk/base",
"/parser/htmlparser",
]
FINAL_LIBRARY = "xul"

View File

@ -40,7 +40,6 @@
#include "nsAttrName.h"
#include "nsNetCID.h"
#include "nsParserCIID.h"
#include "mozilla/parser/PrototypeDocumentParser.h"
#include "mozilla/dom/PrototypeDocumentContentSink.h"
#include "nsNameSpaceManager.h"
@ -73,6 +72,7 @@
#include "nsIRequest.h"
#include "nsHtml5TreeOpExecutor.h"
#include "nsHtml5Parser.h"
#include "nsParser.h"
#include "nsSandboxFlags.h"
#include "mozilla/dom/HTMLBodyElement.h"
#include "mozilla/dom/HTMLDocumentBinding.h"
@ -95,8 +95,6 @@ using namespace mozilla::dom;
//#define DEBUG_charset
static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID);
// ==================================================================
// =
// ==================================================================
@ -385,8 +383,7 @@ nsresult nsHTMLDocument::StartDocumentLoad(
aChannel->GetOriginalURI(getter_AddRefs(originalURI));
mParser = new mozilla::parser::PrototypeDocumentParser(originalURI, this);
} else {
mParser = do_CreateInstance(kCParserCID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
mParser = new nsParser();
}
// Look for the parent document. Note that at this point we don't have our

View File

@ -5,7 +5,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/XMLDocument.h"
#include "nsParserCIID.h"
#include "nsCharsetSource.h"
#include "nsIXMLContentSink.h"
#include "nsPresContext.h"
@ -32,6 +31,7 @@
#include "nsIConsoleService.h"
#include "nsIScriptError.h"
#include "nsHTMLDocument.h"
#include "nsParser.h"
#include "mozilla/BasicEvents.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/Encoding.h"
@ -258,10 +258,7 @@ nsresult XMLDocument::StartDocumentLoad(
rv = aChannel->GetURI(getter_AddRefs(aUrl));
if (NS_FAILED(rv)) return rv;
static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID);
mParser = do_CreateInstance(kCParserCID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
mParser = new nsParser();
nsCOMPtr<nsIXMLContentSink> sink;

View File

@ -43,6 +43,7 @@ LOCAL_INCLUDES += [
"/dom/xslt/base",
"/dom/xul",
"/layout/style",
"/parser/htmlparser",
]
RESOURCE_FILES.dtd += [

View File

@ -55,6 +55,7 @@ LOCAL_INCLUDES += [
"../xpath",
"/dom/base",
"/js/xpconnect/src",
"/parser/htmlparser",
]
FINAL_LIBRARY = "xul"

View File

@ -8,7 +8,7 @@
#include "nsIExpatSink.h"
#include "nsIInterfaceRequestor.h"
#include "nsILoadGroup.h"
#include "nsIParser.h"
#include "nsParser.h"
#include "nsCharsetSource.h"
#include "nsIRequestObserver.h"
#include "nsContentPolicyUtils.h"
@ -21,7 +21,6 @@
#include "nsIXMLContentSink.h"
#include "nsMimeTypes.h"
#include "nsNetUtil.h"
#include "nsParserCIID.h"
#include "nsGkAtoms.h"
#include "txLog.h"
#include "txMozillaXSLTProcessor.h"
@ -42,8 +41,6 @@ using namespace mozilla;
using mozilla::dom::Document;
using mozilla::dom::ReferrerPolicy;
static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID);
static void getSpec(nsIChannel* aChannel, nsAString& aSpec) {
if (!aChannel) {
return;
@ -65,7 +62,7 @@ class txStylesheetSink final : public nsIXMLContentSink,
public nsIStreamListener,
public nsIInterfaceRequestor {
public:
txStylesheetSink(txStylesheetCompiler* aCompiler, nsIParser* aParser);
txStylesheetSink(txStylesheetCompiler* aCompiler, nsParser* aParser);
NS_DECL_ISUPPORTS
NS_DECL_NSIEXPATSINK
@ -87,7 +84,7 @@ class txStylesheetSink final : public nsIXMLContentSink,
private:
RefPtr<txStylesheetCompiler> mCompiler;
nsCOMPtr<nsIStreamListener> mListener;
nsCOMPtr<nsIParser> mParser;
RefPtr<nsParser> mParser;
bool mCheckedForXML;
protected:
@ -98,10 +95,11 @@ class txStylesheetSink final : public nsIXMLContentSink,
};
txStylesheetSink::txStylesheetSink(txStylesheetCompiler* aCompiler,
nsIParser* aParser)
: mCompiler(aCompiler), mParser(aParser), mCheckedForXML(false) {
mListener = do_QueryInterface(aParser);
}
nsParser* aParser)
: mCompiler(aCompiler),
mListener(aParser),
mParser(aParser),
mCheckedForXML(false) {}
NS_IMPL_ISUPPORTS(txStylesheetSink, nsIXMLContentSink, nsIContentSink,
nsIExpatSink, nsIStreamListener, nsIRequestObserver,
@ -239,7 +237,7 @@ txStylesheetSink::OnStartRequest(nsIRequest* aRequest) {
encoding = UTF_8_ENCODING;
}
mParser->SetDocumentCharset(WrapNotNull(encoding), charsetSource);
mParser->SetDocumentCharset(WrapNotNull(encoding), charsetSource, false);
nsAutoCString contentType;
channel->GetContentType(contentType);
@ -256,7 +254,8 @@ txStylesheetSink::OnStartRequest(nsIRequest* aRequest) {
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIStreamListener> converter;
rv = serv->AsyncConvertData(UNKNOWN_CONTENT_TYPE, "*/*", mListener,
mParser, getter_AddRefs(converter));
NS_ISUPPORTS_CAST(nsIParser*, mParser),
getter_AddRefs(converter));
if (NS_SUCCEEDED(rv)) {
mListener = converter;
}
@ -420,9 +419,7 @@ nsresult txCompileObserver::startLoad(nsIURI* aUri,
}
}
nsCOMPtr<nsIParser> parser = do_CreateInstance(kCParserCID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<nsParser> parser = new nsParser();
RefPtr<txStylesheetSink> sink = new txStylesheetSink(aCompiler, parser);
channel->SetNotificationCallbacks(sink);

View File

@ -9,7 +9,6 @@
#include "mozilla/UniquePtr.h"
#include "nsIParser.h"
#include "nsDeque.h"
#include "nsParserCIID.h"
#include "nsIContentSink.h"
#include "nsIRequest.h"
#include "nsIChannel.h"

View File

@ -25,7 +25,6 @@
#include "nsIParser.h"
#include "nsNetCID.h"
#include "nsNetUtil.h"
#include "nsParserCIID.h"
#include "nsString.h"
#include "nsTreeSanitizer.h"
#include "nsXPCOM.h"

View File

@ -1,21 +0,0 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.
Headers = [
'nsHTMLTags.h',
]
InitFunc = 'nsParserInitialize'
UnloadFunc = 'nsHTMLTags::ReleaseTable'
Classes = [
{
'cid': '{2ce606b0-bee6-11d1-aad9-00805f8a3e14}',
'contract_ids': [],
'type': 'nsParser',
'headers': ['/parser/htmlparser/nsParser.h'],
},
]

View File

@ -26,7 +26,6 @@ EXPORTS += [
"nsIHTMLContentSink.h",
"nsIParser.h",
"nsParserBase.h",
"nsParserCIID.h",
"nsParserConstants.h",
"nsRLBoxExpatDriver.h",
"nsScannerString.h",
@ -39,16 +38,11 @@ UNIFIED_SOURCES += [
"nsExpatDriver.cpp",
"nsHTMLTags.cpp",
"nsParser.cpp",
"nsParserModule.cpp",
"nsParserMsgUtils.cpp",
"nsScanner.cpp",
"nsScannerString.cpp",
]
XPCOM_MANIFESTS += [
"components.conf",
]
include("/ipc/chromium/chromium-config.mozbuild")
FINAL_LIBRARY = "xul"

View File

@ -6,7 +6,6 @@
#include "nsExpatDriver.h"
#include "mozilla/fallible.h"
#include "nsCOMPtr.h"
#include "nsParserCIID.h"
#include "CParserContext.h"
#include "nsIExpatSink.h"
#include "nsIContentSink.h"

View File

@ -5,6 +5,7 @@
#include "nsHTMLTags.h"
#include "nsCRT.h"
#include "nsElementTable.h"
#include "nsReadableUtils.h"
#include "nsString.h"
#include "nsUnicharUtils.h"
@ -72,6 +73,9 @@ nsresult nsHTMLTags::AddRefTable(void) {
}
MOZ_ASSERT(maxTagNameLength == NS_HTMLTAG_NAME_MAX_LENGTH);
CheckElementTable();
TestTagTable();
#endif
}

View File

@ -16,7 +16,6 @@
#include "prenv.h"
#include "prlock.h"
#include "prcvar.h"
#include "nsParserCIID.h"
#include "nsReadableUtils.h"
#include "nsCOMPtr.h"
#include "nsExpatDriver.h"

View File

@ -44,7 +44,6 @@
#include "nsIParser.h"
#include "nsDeque.h"
#include "CParserContext.h"
#include "nsParserCIID.h"
#include "nsHTMLTags.h"
#include "nsIContentSink.h"
#include "nsCOMArray.h"
@ -308,6 +307,4 @@ class nsParser final : public nsIParser,
bool mIsAboutBlank;
};
nsresult nsParserInitialize();
#endif

View File

@ -1,17 +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 nsParserCIID_h__
#define nsParserCIID_h__
// {2ce606b0-bee6-11d1-aad9-00805f8a3e14}
#define NS_PARSER_CID \
{ \
0x2ce606b0, 0xbee6, 0x11d1, { \
0xaa, 0xd9, 0x0, 0x80, 0x5f, 0x8a, 0x3e, 0x14 \
} \
}
#endif

View File

@ -1,18 +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 "nsHTMLTags.h"
nsresult nsParserInitialize() {
nsresult rv = nsHTMLTags::AddRefTable();
NS_ENSURE_SUCCESS(rv, rv);
#ifdef DEBUG
CheckElementTable();
nsHTMLTags::TestTagTable();
#endif
return rv;
}

View File

@ -8,17 +8,15 @@
#include "nsXULPrototypeCache.h"
#include "nsXULContentSink.h"
#include "nsParserCIID.h"
#include "mozilla/Encoding.h"
#include "nsCharsetSource.h"
#include "nsParser.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/URL.h"
#include "mozilla/dom/PrototypeDocumentContentSink.h"
using namespace mozilla::dom;
static NS_DEFINE_CID(kParserCID, NS_PARSER_CID);
namespace mozilla {
namespace parser {
@ -197,9 +195,7 @@ nsresult PrototypeDocumentParser::PrepareToLoadPrototype(
NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to initialize datasource sink");
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIParser> parser = do_CreateInstance(kParserCID, &rv);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create parser");
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIParser> parser = new nsParser();
parser->SetCommand(eViewNormal);

View File

@ -19,5 +19,6 @@ UNIFIED_SOURCES += [
FINAL_LIBRARY = "xul"
LOCAL_INCLUDES += [
"../htmlparser",
"/dom/xul",
]