Skip to content

Commit

Permalink
Bug 1749935 - Remove GetDTD. r=hsivonen
Browse files Browse the repository at this point in the history
  • Loading branch information
petervanderbeken committed Feb 14, 2022
1 parent 470c69a commit d6a364b
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 74 deletions.
26 changes: 11 additions & 15 deletions dom/xslt/xslt/txMozillaStylesheetCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,15 @@ txStylesheetSink::OnDataAvailable(nsIRequest* aRequest,
nsIInputStream* aInputStream,
uint64_t aOffset, uint32_t aCount) {
if (!mCheckedForXML) {
nsCOMPtr<nsIDTD> dtd;
mParser->GetDTD(getter_AddRefs(dtd));
if (dtd) {
mCheckedForXML = true;
if (!(dtd->GetType() & NS_IPARSER_FLAG_XML)) {
nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
nsAutoString spec;
getSpec(channel, spec);
mCompiler->cancel(NS_ERROR_XSLT_WRONG_MIME_TYPE, nullptr, spec.get());

return NS_ERROR_XSLT_WRONG_MIME_TYPE;
}
Maybe<bool> isForXML = mParser->IsForParsingXML();
mCheckedForXML = isForXML.isSome();
if (mCheckedForXML && !isForXML.value()) {
nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
nsAutoString spec;
getSpec(channel, spec);
mCompiler->cancel(NS_ERROR_XSLT_WRONG_MIME_TYPE, nullptr, spec.get());

return NS_ERROR_XSLT_WRONG_MIME_TYPE;
}
}

Expand Down Expand Up @@ -281,9 +278,8 @@ txStylesheetSink::OnStopRequest(nsIRequest* aRequest, nsresult aStatusCode) {
// nsIHTMLContentSink.
result = NS_ERROR_XSLT_NETWORK_ERROR;
} else if (!mCheckedForXML) {
nsCOMPtr<nsIDTD> dtd;
mParser->GetDTD(getter_AddRefs(dtd));
if (dtd && !(dtd->GetType() & NS_IPARSER_FLAG_XML)) {
Maybe<bool> isForXML = mParser->IsForParsingXML();
if (isForXML.isSome() && !isForXML.value()) {
result = NS_ERROR_XSLT_WRONG_MIME_TYPE;
}
}
Expand Down
6 changes: 0 additions & 6 deletions parser/html/nsHtml5Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,6 @@ nsresult nsHtml5Parser::GetChannel(nsIChannel** aChannel) {
}
}

NS_IMETHODIMP
nsHtml5Parser::GetDTD(nsIDTD** aDTD) {
*aDTD = nullptr;
return NS_OK;
}

nsIStreamListener* nsHtml5Parser::GetStreamListener() {
return mStreamListener;
}
Expand Down
5 changes: 0 additions & 5 deletions parser/html/nsHtml5Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ class nsHtml5Parser final : public nsIParser, public nsSupportsWeakReference {
*/
nsresult GetChannel(nsIChannel** aChannel);

/**
* Return |this| for backwards compat.
*/
NS_IMETHOD GetDTD(nsIDTD** aDTD) override;

/**
* Get the stream parser for this parser
*/
Expand Down
3 changes: 0 additions & 3 deletions parser/htmlparser/CNavDTD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,3 @@ void CNavDTD::DidBuildModel() {}

NS_IMETHODIMP_(void)
CNavDTD::Terminate() {}

NS_IMETHODIMP_(int32_t)
CNavDTD::GetType() { return NS_IPARSER_FLAG_HTML; }
3 changes: 0 additions & 3 deletions parser/htmlparser/nsExpatDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1627,9 +1627,6 @@ nsExpatDriver::Terminate() {
mInternalState = NS_ERROR_HTMLPARSER_STOPPARSING;
}

NS_IMETHODIMP_(int32_t)
nsExpatDriver::GetType() { return NS_IPARSER_FLAG_XML; }

/*************************** Unused methods **********************************/

void nsExpatDriver::MaybeStopParser(nsresult aState) {
Expand Down
5 changes: 1 addition & 4 deletions parser/htmlparser/nsIDTD.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,12 @@ class nsIDTD : public nsISupports {
* @return
*/
NS_IMETHOD_(void) Terminate() = 0;

NS_IMETHOD_(int32_t) GetType() = 0;
};

NS_DEFINE_STATIC_IID_ACCESSOR(nsIDTD, NS_IDTD_IID)

#define NS_DECL_NSIDTD \
void DidBuildModel() override; \
NS_IMETHOD BuildModel(nsIContentSink* aSink) override; \
NS_IMETHOD_(void) Terminate() override; \
NS_IMETHOD_(int32_t) GetType() override;
NS_IMETHOD_(void) Terminate() override;
#endif /* nsIDTD_h___ */
15 changes: 0 additions & 15 deletions parser/htmlparser/nsIParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,6 @@ class nsIParser : public nsParserBase {
int32_t aSource,
bool aForceAutoDetection = false) = 0;

/**
* Get the DTD associated with this parser
* @update vidur 9/29/99
* @param aDTD out param that will contain the result
* @return NS_OK if successful, NS_ERROR_FAILURE for runtime error
*/
NS_IMETHOD GetDTD(nsIDTD** aDTD) = 0;

/**
* Get the nsIStreamListener for this parser
*/
Expand Down Expand Up @@ -191,11 +183,4 @@ class nsIParser : public nsParserBase {

NS_DEFINE_STATIC_IID_ACCESSOR(nsIParser, NS_IPARSER_IID)

/* ===========================================================*
Some useful constants...
* ===========================================================*/

#define NS_IPARSER_FLAG_XML 0x00000200
#define NS_IPARSER_FLAG_HTML 0x00000400

#endif
14 changes: 1 addition & 13 deletions parser/htmlparser/nsParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ nsresult nsParser::ResumeParse(bool allowIteration, bool aIsFinalChunk,
nsresult theTokenizerResult;
if (mFlags & NS_PARSER_FLAG_CAN_TOKENIZE) {
mParserContext->mScanner.Mark();
if (mDTD->GetType() == NS_IPARSER_FLAG_XML &&
if (mParserContext->mDocType == eXML &&
mParserContext->mParserCommand != eViewSource) {
nsExpatDriver* expat = static_cast<nsExpatDriver*>(mDTD.get());
theTokenizerResult =
Expand Down Expand Up @@ -1076,18 +1076,6 @@ nsresult nsParser::OnStopRequest(nsIRequest* request, nsresult status) {
return rv;
}

/**
* Get the DTD associated with this parser
*/
NS_IMETHODIMP
nsParser::GetDTD(nsIDTD** aDTD) {
if (mParserContext) {
NS_IF_ADDREF(*aDTD = mDTD);
}

return NS_OK;
}

/**
* Get this as nsIStreamListener
*/
Expand Down
19 changes: 11 additions & 8 deletions parser/htmlparser/nsParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "nsCOMArray.h"
#include "nsCycleCollectionParticipant.h"
#include "nsWeakReference.h"
#include "mozilla/Maybe.h"
#include "mozilla/UniquePtr.h"

class nsIDTD;
Expand Down Expand Up @@ -192,14 +193,6 @@ class nsParser final : public nsIParser,
// nsIStreamListener methods:
NS_DECL_NSISTREAMLISTENER

/**
* Get the DTD associated with this parser
* @update vidur 9/29/99
* @param aDTD out param that will contain the result
* @return NS_OK if successful, NS_ERROR_FAILURE for runtime error
*/
NS_IMETHOD GetDTD(nsIDTD** aDTD) override;

/**
* Get the nsIStreamListener for this parser
*/
Expand Down Expand Up @@ -256,6 +249,16 @@ class nsParser final : public nsIParser,
return !IsScriptExecuting() && !mProcessingNetworkData;
}

// Returns Nothing() if we haven't determined yet what the parser is being
// used for. Else returns whether this parser is used for parsing XML.
mozilla::Maybe<bool> IsForParsingXML() {
if (!mParserContext || mParserContext->mDTDMode == eDTDMode_autodetect) {
return mozilla::Nothing();
}

return mozilla::Some(mParserContext->mDocType == eXML);
}

protected:
void Initialize(bool aConstructor = false);
void Cleanup();
Expand Down
2 changes: 0 additions & 2 deletions parser/prototype/PrototypeDocumentParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ class PrototypeDocumentParser final : public nsIParser,
int32_t aSource,
bool aForceAutoDetection) override {}

NS_IMETHOD GetDTD(nsIDTD** aDTD) override { return NS_ERROR_NOT_IMPLEMENTED; }

virtual nsIStreamListener* GetStreamListener() override;

NS_IMETHOD ContinueInterruptedParsing() override {
Expand Down

0 comments on commit d6a364b

Please sign in to comment.