Bug 1749935 - Remove nsIDTD::WillBuildModel. r=hsivonen

Differential Revision: https://phabricator.services.mozilla.com/D135883
This commit is contained in:
Peter Van der Beken 2022-02-14 13:03:49 +00:00
parent bbfc56b73d
commit 2e0cd032d6
5 changed files with 14 additions and 30 deletions

View File

@ -16,12 +16,6 @@ CNavDTD::CNavDTD() {}
CNavDTD::~CNavDTD() {} CNavDTD::~CNavDTD() {}
NS_IMETHODIMP
CNavDTD::WillBuildModel(const CParserContext& aParserContext,
nsIContentSink* aSink) {
return NS_OK;
}
NS_IMETHODIMP NS_IMETHODIMP
CNavDTD::BuildModel(nsIContentSink* aSink) { CNavDTD::BuildModel(nsIContentSink* aSink) {
// NB: It is important to throw STOPPARSING if the sink is the wrong type in // NB: It is important to throw STOPPARSING if the sink is the wrong type in

View File

@ -1503,9 +1503,7 @@ RLBoxExpatSandboxData::~RLBoxExpatSandboxData() {
MOZ_COUNT_DTOR(RLBoxExpatSandboxData); MOZ_COUNT_DTOR(RLBoxExpatSandboxData);
} }
NS_IMETHODIMP nsresult nsExpatDriver::Initialize(nsIURI* aURI, nsIContentSink* aSink) {
nsExpatDriver::WillBuildModel(const CParserContext& aParserContext,
nsIContentSink* aSink) {
mSink = do_QueryInterface(aSink); mSink = do_QueryInterface(aSink);
if (!mSink) { if (!mSink) {
NS_ERROR("nsExpatDriver didn't get an nsIExpatSink"); NS_ERROR("nsExpatDriver didn't get an nsIExpatSink");
@ -1576,7 +1574,7 @@ nsExpatDriver::WillBuildModel(const CParserContext& aParserContext,
XML_PARAM_ENTITY_PARSING_ALWAYS); XML_PARAM_ENTITY_PARSING_ALWAYS);
#endif #endif
auto baseURI = GetExpatBaseURI(aParserContext.mScanner.GetURI()); auto baseURI = GetExpatBaseURI(aURI);
auto uri = auto uri =
TransferBuffer<XML_Char>(Sandbox(), &baseURI[0], ArrayLength(baseURI)); TransferBuffer<XML_Char>(Sandbox(), &baseURI[0], ArrayLength(baseURI));
RLBOX_EXPAT_MCALL(MOZ_XML_SetBase, *uri); RLBOX_EXPAT_MCALL(MOZ_XML_SetBase, *uri);

View File

@ -39,6 +39,8 @@ class nsExpatDriver : public nsIDTD, public nsITokenizer {
nsExpatDriver(); nsExpatDriver();
nsresult Initialize(nsIURI* aURI, nsIContentSink* aSink);
int HandleExternalEntityRef(const char16_t* aOpenEntityNames, int HandleExternalEntityRef(const char16_t* aOpenEntityNames,
const char16_t* aBase, const char16_t* aSystemId, const char16_t* aBase, const char16_t* aSystemId,
const char16_t* aPublicId); const char16_t* aPublicId);

View File

@ -49,9 +49,6 @@ class nsIDTD : public nsISupports {
public: public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDTD_IID) NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDTD_IID)
NS_IMETHOD WillBuildModel(const CParserContext& aParserContext,
nsIContentSink* aSink) = 0;
/** /**
* Called by the parser after the parsing process has concluded * Called by the parser after the parsing process has concluded
*/ */
@ -86,11 +83,9 @@ class nsIDTD : public nsISupports {
NS_DEFINE_STATIC_IID_ACCESSOR(nsIDTD, NS_IDTD_IID) NS_DEFINE_STATIC_IID_ACCESSOR(nsIDTD, NS_IDTD_IID)
#define NS_DECL_NSIDTD \ #define NS_DECL_NSIDTD \
NS_IMETHOD WillBuildModel(const CParserContext& aParserContext, \ void DidBuildModel() override; \
nsIContentSink* aSink) override; \ NS_IMETHOD BuildModel(nsIContentSink* aSink) override; \
void DidBuildModel() override; \ NS_IMETHOD_(void) Terminate() override; \
NS_IMETHOD BuildModel(nsIContentSink* aSink) override; \
NS_IMETHOD_(void) Terminate() override; \
NS_IMETHOD_(int32_t) GetType() override; NS_IMETHOD_(int32_t) GetType() override;
#endif /* nsIDTD_h___ */ #endif /* nsIDTD_h___ */

View File

@ -324,7 +324,11 @@ nsresult nsParser::WillBuildModel() {
// Now see if we're parsing XML or HTML (which, as far as we're concerned, // Now see if we're parsing XML or HTML (which, as far as we're concerned,
// simply means "not XML"). // simply means "not XML").
if (mParserContext->mDocType == eXML) { if (mParserContext->mDocType == eXML) {
mDTD = new nsExpatDriver(); RefPtr<nsExpatDriver> expat = new nsExpatDriver();
nsresult rv = expat->Initialize(mParserContext->mScanner.GetURI(), mSink);
NS_ENSURE_SUCCESS(rv, rv);
mDTD = expat.forget();
} else { } else {
mDTD = new CNavDTD(); mDTD = new CNavDTD();
} }
@ -333,16 +337,7 @@ nsresult nsParser::WillBuildModel() {
nsresult rv = mParserContext->GetTokenizer(mDTD, mSink, tokenizer); nsresult rv = mParserContext->GetTokenizer(mDTD, mSink, tokenizer);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
rv = mDTD->WillBuildModel(*mParserContext, mSink); return mSink->WillBuildModel(mParserContext->mDTDMode);
nsresult sinkResult = mSink->WillBuildModel(mParserContext->mDTDMode);
// nsIDTD::WillBuildModel used to be responsible for calling
// nsIContentSink::WillBuildModel, but that obligation isn't expressible
// in the nsIDTD interface itself, so it's sounder and simpler to give that
// responsibility back to the parser. The former behavior of the DTD was to
// NS_ENSURE_SUCCESS the sink WillBuildModel call, so if the sink returns
// failure we should use sinkResult instead of rv, to preserve the old error
// handling behavior of the DTD:
return NS_FAILED(sinkResult) ? sinkResult : rv;
} }
/** /**