Bug 484121 (2/6) - Add nsIDTD::GetMode to eliminate heinous const_cast. r+sr=mrbkap

This commit is contained in:
Ben Newman 2009-06-23 14:22:16 -07:00
Родитель a56545afcb
Коммит 3295d504dd
28 изменённых файлов: 88 добавлений и 100 удалений

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

@ -355,8 +355,6 @@ public:
// nsIContentSink (superclass of nsIHTMLContentSink)
NS_IMETHOD WillParse() { return NS_OK; }
NS_IMETHOD WillBuildModel() { return NS_OK; }
NS_IMETHOD DidBuildModel() { return NS_OK; }
NS_IMETHOD WillInterrupt() { return NS_OK; }
NS_IMETHOD WillResume() { return NS_OK; }
NS_IMETHOD SetParser(nsIParser* aParser) { return NS_OK; }

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

@ -100,8 +100,6 @@ public:
// nsIContentSink
NS_IMETHOD WillParse(void) { return NS_OK; }
NS_IMETHOD WillBuildModel(void) { return NS_OK; }
NS_IMETHOD DidBuildModel(void) { return NS_OK; }
NS_IMETHOD WillInterrupt(void) { return NS_OK; }
NS_IMETHOD WillResume(void) { return NS_OK; }
NS_IMETHOD SetParser(nsIParser* aParser) { return NS_OK; }

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

@ -56,7 +56,6 @@
#include "nsIDocumentEncoder.h"
#include "nsTArray.h"
class nsPlainTextSerializer : public nsIContentSerializer,
public nsIHTMLContentSink,
public nsIHTMLToTextSink
@ -97,8 +96,6 @@ public:
// nsIContentSink
NS_IMETHOD WillParse(void) { return NS_OK; }
NS_IMETHOD WillBuildModel(void) { return NS_OK; }
NS_IMETHOD DidBuildModel(void) { return NS_OK; }
NS_IMETHOD WillInterrupt(void) { return NS_OK; }
NS_IMETHOD WillResume(void) { return NS_OK; }
NS_IMETHOD SetParser(nsIParser* aParser) { return NS_OK; }

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

@ -182,7 +182,7 @@ public:
// nsIContentSink
NS_IMETHOD WillParse(void);
NS_IMETHOD WillBuildModel(void);
NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode);
NS_IMETHOD DidBuildModel(void);
virtual PRBool ReadyToCallDidBuildModel(PRBool aTerminated);
NS_IMETHOD WillInterrupt(void);
@ -1742,28 +1742,21 @@ HTMLContentSink::WillParse(void)
}
NS_IMETHODIMP
HTMLContentSink::WillBuildModel(void)
HTMLContentSink::WillBuildModel(nsDTDMode aDTDMode)
{
WillBuildModelImpl();
if (mHTMLDocument) {
NS_ASSERTION(mParser, "no parser");
nsCompatibility mode = eCompatibility_NavQuirks;
if (mParser) {
nsDTDMode dtdMode = mParser->GetParseMode();
switch (dtdMode) {
case eDTDMode_full_standards:
mode = eCompatibility_FullStandards;
break;
case eDTDMode_almost_standards:
mode = eCompatibility_AlmostStandards;
break;
default:
mode = eCompatibility_NavQuirks;
break;
}
switch (aDTDMode) {
case eDTDMode_full_standards:
mode = eCompatibility_FullStandards;
break;
case eDTDMode_almost_standards:
mode = eCompatibility_AlmostStandards;
break;
default:
break;
}
mHTMLDocument->SetCompatibilityMode(mode);
}

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

@ -39,6 +39,7 @@
#include "nsCOMPtr.h"
#include "nsIServiceManager.h"
#include "nsIFragmentContentSink.h"
#include "nsIDTD.h"
#include "nsIHTMLContentSink.h"
#include "nsIParser.h"
#include "nsIParserService.h"
@ -88,7 +89,7 @@ public:
// nsIContentSink
NS_IMETHOD WillParse(void) { return NS_OK; }
NS_IMETHOD WillBuildModel(void);
NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode);
NS_IMETHOD DidBuildModel(void);
NS_IMETHOD WillInterrupt(void);
NS_IMETHOD WillResume(void);
@ -260,7 +261,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsHTMLFragmentContentSink)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMETHODIMP
nsHTMLFragmentContentSink::WillBuildModel(void)
nsHTMLFragmentContentSink::WillBuildModel(nsDTDMode)
{
if (mRoot) {
return NS_OK;

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

@ -93,9 +93,9 @@ NS_INTERFACE_MAP_END
// nsIContentSink
NS_IMETHODIMP
nsLoadSaveContentSink::WillBuildModel(void)
nsLoadSaveContentSink::WillBuildModel(nsDTDMode aDTDMode)
{
return mBaseSink->WillBuildModel();
return mBaseSink->WillBuildModel(aDTDMode);
}
NS_IMETHODIMP

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

@ -43,6 +43,7 @@
#include "nsIXMLContentSink.h"
#include "nsILoadSaveContentSink.h"
#include "nsCOMPtr.h"
#include "nsIDTD.h"
/**
* This class implements the core of the DOMBuilder for DOM3
@ -69,7 +70,7 @@ public:
NS_DECL_NSIEXPATSINK
// nsILoadSaveContentSink
NS_IMETHOD WillBuildModel(void);
NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode);
NS_IMETHOD DidBuildModel(void);
NS_IMETHOD WillInterrupt(void);
NS_IMETHOD WillResume(void);

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

@ -211,7 +211,7 @@ nsXMLContentSink::WillParse(void)
}
NS_IMETHODIMP
nsXMLContentSink::WillBuildModel(void)
nsXMLContentSink::WillBuildModel(nsDTDMode aDTDMode)
{
WillBuildModelImpl();

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

@ -46,6 +46,7 @@
#include "nsCOMPtr.h"
#include "nsCRT.h"
#include "nsCycleCollectionParticipant.h"
#include "nsIDTD.h"
class nsIDocument;
class nsIURI;
@ -91,7 +92,7 @@ public:
// nsIContentSink
NS_IMETHOD WillParse(void);
NS_IMETHOD WillBuildModel(void);
NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode);
NS_IMETHOD DidBuildModel(void);
virtual PRBool ReadyToCallDidBuildModel(PRBool aTerminated);
NS_IMETHOD WillInterrupt(void);

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

@ -42,6 +42,7 @@
#include "nsIXMLContentSink.h"
#include "nsContentSink.h"
#include "nsIExpatSink.h"
#include "nsIDTD.h"
#include "nsIParser.h"
#include "nsIDocument.h"
#include "nsIDOMDocumentFragment.h"
@ -93,7 +94,7 @@ public:
PRBool *_retval);
// nsIContentSink
NS_IMETHOD WillBuildModel(void);
NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode);
NS_IMETHOD DidBuildModel();
NS_IMETHOD SetDocumentCharset(nsACString& aCharset);
virtual nsISupports *GetTarget();
@ -190,7 +191,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsXMLFragmentContentSink,
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMETHODIMP
nsXMLFragmentContentSink::WillBuildModel(void)
nsXMLFragmentContentSink::WillBuildModel(nsDTDMode aDTDMode)
{
if (mRoot) {
return NS_OK;

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

@ -109,7 +109,6 @@ public:
// nsIContentSink
NS_IMETHOD WillParse(void) { return NS_OK; }
NS_IMETHOD WillBuildModel(void) { return NS_OK; }
NS_IMETHOD DidBuildModel();
NS_IMETHOD WillInterrupt(void) { return NS_OK; }
NS_IMETHOD WillResume(void) { return NS_OK; }

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

@ -257,7 +257,7 @@ NS_IMPL_ISUPPORTS3(XULContentSinkImpl,
// nsIContentSink interface
NS_IMETHODIMP
XULContentSinkImpl::WillBuildModel(void)
XULContentSinkImpl::WillBuildModel(nsDTDMode aDTDMode)
{
#if FIXME
if (! mParentContentSink) {

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

@ -48,6 +48,7 @@
#include "nsNodeInfoManager.h"
#include "nsWeakPtr.h"
#include "nsXULElement.h"
#include "nsIDTD.h"
class nsIDocument;
class nsIScriptSecurityManager;
@ -69,7 +70,7 @@ public:
// nsIContentSink
NS_IMETHOD WillParse(void) { return NS_OK; }
NS_IMETHOD WillBuildModel(void);
NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode);
NS_IMETHOD DidBuildModel(void);
NS_IMETHOD WillInterrupt(void);
NS_IMETHOD WillResume(void);

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

@ -52,12 +52,14 @@
#include "nsISupports.h"
#include "nsStringGlue.h"
#include "mozFlushType.h"
#include "nsIDTD.h"
class nsIParser;
// 5530ebaf-f9fd-44bf-b6b5-e46f3b67eb3d
#define NS_ICONTENT_SINK_IID \
{ 0x6fd3c94f, 0xaf81, 0x4792, \
{ 0xa3, 0xe4, 0x1f, 0xb9, 0x40, 0xb6, 0x9c, 0x3a } }
{ 0x5530ebaf, 0xf9fd, 0x44bf, \
{ 0xb6, 0xb5, 0xe4, 0x6f, 0x3b, 0x67, 0xeb, 0x3d } }
class nsIContentSink : public nsISupports {
public:
@ -76,17 +78,27 @@ public:
* This method gets called when the parser begins the process
* of building the content model via the content sink.
*
* Default implementation provided since the sink should have the option of
* doing nothing in response to this call.
*
* @update 5/7/98 gess
*/
NS_IMETHOD WillBuildModel(void)=0;
NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode) {
return NS_OK;
}
/**
* This method gets called when the parser concludes the process
* of building the content model via the content sink.
*
* Default implementation provided since the sink should have the option of
* doing nothing in response to this call.
*
* @update 5/7/98 gess
*/
NS_IMETHOD DidBuildModel()=0;
NS_IMETHOD DidBuildModel() {
return NS_OK;
}
/**
* Thie method gets caller right before DidBuildModel is called.

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

@ -178,6 +178,12 @@ public:
NS_IMETHOD_(void) Terminate() = 0;
NS_IMETHOD_(PRInt32) GetType() = 0;
/**
* Call this method after calling WillBuildModel to determine what mode the
* DTD actually is using, as it may differ from aParserContext.mDTDMode.
*/
NS_IMETHOD_(nsDTDMode) GetMode() const = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsIDTD, NS_IDTD_IID)
@ -192,5 +198,6 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIDTD, NS_IDTD_IID)
NS_IMETHOD_(PRBool) CanContain(PRInt32 aParent,PRInt32 aChild) const;\
NS_IMETHOD_(PRBool) IsContainer(PRInt32 aTag) const;\
NS_IMETHOD_(void) Terminate();\
NS_IMETHOD_(PRInt32) GetType();
NS_IMETHOD_(PRInt32) GetType();\
NS_IMETHOD_(nsDTDMode) GetMode() const;
#endif /* nsIDTD_h___ */

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

@ -266,15 +266,6 @@ class nsIParser : public nsISupports {
*/
NS_IMETHOD BuildModel(void) = 0;
/**
* Retrieve the parse mode from the parser...
*
* @update gess 6/9/98
* @return ptr to scanner
*/
NS_IMETHOD_(nsDTDMode) GetParseMode(void) = 0;
/**
* Call this method to cancel any pending parsing events.
* Parsing events may be pending if all of the document's content

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

@ -209,7 +209,7 @@ CNavDTD::WillBuildModel(const CParserContext& aParserContext,
STOP_TIMER();
MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::WillBuildModel(), this=%p\n", this));
result = aSink->WillBuildModel();
result = aSink->WillBuildModel(GetMode());
MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::WillBuildModel(), this=%p\n", this));
START_TIMER();
@ -465,6 +465,12 @@ CNavDTD::GetType()
return NS_IPARSER_FLAG_HTML;
}
NS_IMETHODIMP_(nsDTDMode)
CNavDTD::GetMode() const
{
return mDTDMode;
}
/**
* Text and some tags require a body when they're added, this function returns
* true for those tags.

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

@ -1294,7 +1294,7 @@ nsExpatDriver::WillBuildModel(const CParserContext& aParserContext,
// XML must detect invalid character convertion
aParserContext.mScanner->OverrideReplacementCharacter(0xffff);
return aSink->WillBuildModel();
return aSink->WillBuildModel(GetMode());
}
NS_IMETHODIMP
@ -1367,6 +1367,12 @@ nsExpatDriver::GetType()
return NS_IPARSER_FLAG_XML;
}
NS_IMETHODIMP_(nsDTDMode)
nsExpatDriver::GetMode() const
{
return eDTDMode_full_standards;
}
/*************************** Unused methods **********************************/
NS_IMETHODIMP_(CToken*)

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

@ -70,7 +70,7 @@ NS_IMPL_ISUPPORTS1(nsHTMLTokenizer, nsITokenizer)
* @param aDocType The document type of the current document
* @param aCommand What we are trying to do (view-source, parse a fragment, etc.)
*/
nsHTMLTokenizer::nsHTMLTokenizer(PRInt32 aParseMode,
nsHTMLTokenizer::nsHTMLTokenizer(nsDTDMode aParseMode,
eParserDocType aDocType,
eParserCommands aCommand,
PRUint16 aFlags) :

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

@ -67,7 +67,7 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSITOKENIZER
nsHTMLTokenizer(PRInt32 aParseMode = eDTDMode_quirks,
nsHTMLTokenizer(nsDTDMode aParseMode = eDTDMode_quirks,
eParserDocType aDocType = eHTML_Quirks,
eParserCommands aCommand = eViewNormal,
PRUint16 aFlags = 0);

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

@ -99,14 +99,14 @@ nsLoggingSink::WillParse() {
}
NS_IMETHODIMP
nsLoggingSink::WillBuildModel() {
nsLoggingSink::WillBuildModel(nsDTDMode aDTDMode) {
WriteTabs(mOutput,++mLevel);
PR_fprintf(mOutput, "<begin>\n");
//proxy the call to the real sink if you have one.
if(mSink) {
mSink->WillBuildModel();
mSink->WillBuildModel(aDTDMode);
}
return NS_OK;

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

@ -61,7 +61,7 @@ public:
// nsIContentSink
NS_IMETHOD WillParse();
NS_IMETHOD WillBuildModel();
NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode);
NS_IMETHOD DidBuildModel();
NS_IMETHOD WillInterrupt();
NS_IMETHOD WillResume();

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

@ -1035,21 +1035,6 @@ nsParser::GetContentSink()
return mSink;
}
/**
* Retrieve parsemode from topmost parser context
*
* @return parsemode
*/
NS_IMETHODIMP_(nsDTDMode)
nsParser::GetParseMode()
{
if (mParserContext) {
return mParserContext->mDTDMode;
}
NS_NOTREACHED("no parser context");
return eDTDMode_unknown;
}
/**
* Determine what DTD mode (and thus what layout nsCompatibility mode)
* to use for this document based on the first chunk of data received

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

@ -180,14 +180,6 @@ class nsParser : public nsIParser,
NS_IMETHOD_(void) SetParserFilter(nsIParserFilter* aFilter);
/**
* Retrieve the scanner from the topmost parser context
*
* @update gess 6/9/98
* @return ptr to scanner
*/
NS_IMETHOD_(nsDTDMode) GetParseMode(void);
/**
* Cause parser to parse input from given URL
* @update gess5/11/98

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

@ -312,20 +312,9 @@ nsresult CViewSourceHTML::WillBuildModel(const CParserContext& aParserContext,
else mDocType=aParserContext.mDocType;
mLineNumber = 1;
// Munge the DTD mode so that the document will be in standards mode even if
// the original source was quirks. The CONST_CAST is evil, but the other
// options seem to be:
// 1) Change the WillBuildModel signature to take an nsIParser so that we can
// push a new parser context right here.
// 2) Make some assumptions about the exact class of mSink and get at the
// document that way.
// #1 doesn't seem worth it, and #2 is even more evil, since we plan to reset
// the DTD mode right back to what it was before, let's risk this.
CParserContext& parserContext = const_cast<CParserContext&>(aParserContext);
parserContext.mDTDMode = eDTDMode_full_standards;
result = mSink->WillBuildModel();
// And reset the DTD mode back to the right one
parserContext.mDTDMode = mDTDMode;
result = mSink->WillBuildModel(GetMode());
START_TIMER();
return result;
}
@ -611,6 +600,15 @@ CViewSourceHTML::GetType() {
return NS_IPARSER_FLAG_HTML;
}
NS_IMETHODIMP_(nsDTDMode)
CViewSourceHTML::GetMode() const
{
// Quirks mode needn't affect how the source is viewed, so parse the source
// view in full standards mode no matter what:
return eDTDMode_full_standards;
}
/**
*
* @update gess5/18/98

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

@ -89,7 +89,7 @@ nsSAXXMLReader::nsSAXXMLReader() : mIsAsyncParse(PR_FALSE)
// nsIContentSink
NS_IMETHODIMP
nsSAXXMLReader::WillBuildModel()
nsSAXXMLReader::WillBuildModel(nsDTDMode)
{
if (mContentHandler)
return mContentHandler->StartDocument();

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

@ -77,7 +77,7 @@ public:
return NS_OK;
}
NS_IMETHOD WillBuildModel();
NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode);
NS_IMETHOD DidBuildModel();
NS_IMETHOD SetParser(nsIParser* aParser);

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

@ -96,6 +96,7 @@
#include "nsIAtom.h"
#include "nsStaticAtom.h"
#include "nsIScriptError.h"
#include "nsIDTD.h"
////////////////////////////////////////////////////////////////////////
// XPCOM IIDs
@ -160,7 +161,7 @@ public:
// nsIContentSink
NS_IMETHOD WillParse(void);
NS_IMETHOD WillBuildModel(void);
NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode);
NS_IMETHOD DidBuildModel(void);
NS_IMETHOD WillInterrupt(void);
NS_IMETHOD WillResume(void);
@ -620,7 +621,7 @@ RDFContentSinkImpl::WillParse(void)
NS_IMETHODIMP
RDFContentSinkImpl::WillBuildModel(void)
RDFContentSinkImpl::WillBuildModel(nsDTDMode)
{
if (mDataSource) {
nsCOMPtr<nsIRDFXMLSink> sink = do_QueryInterface(mDataSource);