Skip to content

Commit

Permalink
Bug 1749935 - Remove nsIDTD::WillBuildModel. r=hsivonen
Browse files Browse the repository at this point in the history
  • Loading branch information
petervanderbeken committed Feb 14, 2022
1 parent bbfc56b commit 2e0cd03
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 30 deletions.
6 changes: 0 additions & 6 deletions parser/htmlparser/CNavDTD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ CNavDTD::CNavDTD() {}

CNavDTD::~CNavDTD() {}

NS_IMETHODIMP
CNavDTD::WillBuildModel(const CParserContext& aParserContext,
nsIContentSink* aSink) {
return NS_OK;
}

NS_IMETHODIMP
CNavDTD::BuildModel(nsIContentSink* aSink) {
// NB: It is important to throw STOPPARSING if the sink is the wrong type in
Expand Down
6 changes: 2 additions & 4 deletions parser/htmlparser/nsExpatDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1503,9 +1503,7 @@ RLBoxExpatSandboxData::~RLBoxExpatSandboxData() {
MOZ_COUNT_DTOR(RLBoxExpatSandboxData);
}

NS_IMETHODIMP
nsExpatDriver::WillBuildModel(const CParserContext& aParserContext,
nsIContentSink* aSink) {
nsresult nsExpatDriver::Initialize(nsIURI* aURI, nsIContentSink* aSink) {
mSink = do_QueryInterface(aSink);
if (!mSink) {
NS_ERROR("nsExpatDriver didn't get an nsIExpatSink");
Expand Down Expand Up @@ -1576,7 +1574,7 @@ nsExpatDriver::WillBuildModel(const CParserContext& aParserContext,
XML_PARAM_ENTITY_PARSING_ALWAYS);
#endif

auto baseURI = GetExpatBaseURI(aParserContext.mScanner.GetURI());
auto baseURI = GetExpatBaseURI(aURI);
auto uri =
TransferBuffer<XML_Char>(Sandbox(), &baseURI[0], ArrayLength(baseURI));
RLBOX_EXPAT_MCALL(MOZ_XML_SetBase, *uri);
Expand Down
2 changes: 2 additions & 0 deletions parser/htmlparser/nsExpatDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class nsExpatDriver : public nsIDTD, public nsITokenizer {

nsExpatDriver();

nsresult Initialize(nsIURI* aURI, nsIContentSink* aSink);

int HandleExternalEntityRef(const char16_t* aOpenEntityNames,
const char16_t* aBase, const char16_t* aSystemId,
const char16_t* aPublicId);
Expand Down
13 changes: 4 additions & 9 deletions parser/htmlparser/nsIDTD.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ class nsIDTD : public nsISupports {
public:
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
*/
Expand Down Expand Up @@ -86,11 +83,9 @@ class nsIDTD : public nsISupports {

NS_DEFINE_STATIC_IID_ACCESSOR(nsIDTD, NS_IDTD_IID)

#define NS_DECL_NSIDTD \
NS_IMETHOD WillBuildModel(const CParserContext& aParserContext, \
nsIContentSink* aSink) override; \
void DidBuildModel() override; \
NS_IMETHOD BuildModel(nsIContentSink* aSink) override; \
NS_IMETHOD_(void) Terminate() override; \
#define NS_DECL_NSIDTD \
void DidBuildModel() override; \
NS_IMETHOD BuildModel(nsIContentSink* aSink) override; \
NS_IMETHOD_(void) Terminate() override; \
NS_IMETHOD_(int32_t) GetType() override;
#endif /* nsIDTD_h___ */
17 changes: 6 additions & 11 deletions parser/htmlparser/nsParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,11 @@ nsresult nsParser::WillBuildModel() {
// Now see if we're parsing XML or HTML (which, as far as we're concerned,
// simply means "not XML").
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 {
mDTD = new CNavDTD();
}
Expand All @@ -333,16 +337,7 @@ nsresult nsParser::WillBuildModel() {
nsresult rv = mParserContext->GetTokenizer(mDTD, mSink, tokenizer);
NS_ENSURE_SUCCESS(rv, rv);

rv = mDTD->WillBuildModel(*mParserContext, mSink);
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;
return mSink->WillBuildModel(mParserContext->mDTDMode);
}

/**
Expand Down

0 comments on commit 2e0cd03

Please sign in to comment.