Backing out 8f9ff81ef3fa to try to fix orange.

This commit is contained in:
Peter Van der Beken 2009-03-24 10:43:42 +01:00
Родитель e8e85d2d88
Коммит ed2e3f411e
12 изменённых файлов: 120 добавлений и 115 удалений

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

@ -103,7 +103,8 @@ public:
* @return
*/
NS_IMETHOD DidBuildModel(nsresult anErrorCode, PRBool aNotifySink,
nsIParser* aParser) = 0;
nsIParser* aParser,
nsIContentSink* aSink) = 0;
/**
* Called by the parser after the parsing process has concluded
@ -111,7 +112,9 @@ public:
* @param anErrorCode - contains error code resulting from parse process
* @return
*/
NS_IMETHOD BuildModel(nsIParser* aParser, nsITokenizer* aTokenizer) = 0;
NS_IMETHOD BuildModel(nsIParser* aParser, nsITokenizer* aTokenizer,
nsITokenObserver* anObserver,
nsIContentSink* aSink) = 0;
/**
* Called during model building phase of parse process. Each token
@ -131,7 +134,7 @@ public:
* @update gess5/18/98
* @return ignored
*/
NS_IMETHOD WillResumeParse() = 0;
NS_IMETHOD WillResumeParse(nsIContentSink* aSink) = 0;
/**
* If the parse process gets interrupted, this method is called by
@ -139,7 +142,7 @@ public:
* @update gess5/18/98
* @return ignored
*/
NS_IMETHOD WillInterruptParse() = 0;
NS_IMETHOD WillInterruptParse(nsIContentSink* aSink) = 0;
/**
* This method is called to determine whether or not a tag of one
@ -175,22 +178,19 @@ public:
NS_IMETHOD_(void) Terminate() = 0;
NS_IMETHOD_(PRInt32) GetType() = 0;
NS_IMETHOD_(nsITokenizer*) CreateTokenizer() = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsIDTD, NS_IDTD_IID)
#define NS_DECL_NSIDTD \
NS_IMETHOD WillBuildModel( const CParserContext& aParserContext, nsITokenizer* aTokenizer, nsIContentSink* aSink);\
NS_IMETHOD DidBuildModel(nsresult anErrorCode, PRBool aNotifySink, nsIParser* aParser);\
NS_IMETHOD BuildModel(nsIParser* aParser, nsITokenizer* aTokenizer);\
NS_IMETHOD HandleToken(CToken* aToken, nsIParser* aParser);\
NS_IMETHOD WillResumeParse();\
NS_IMETHOD WillInterruptParse();\
NS_IMETHOD DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParser* aParser,nsIContentSink* aSink);\
NS_IMETHOD BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer,nsITokenObserver* anObserver,nsIContentSink* aSink);\
NS_IMETHOD HandleToken(CToken* aToken,nsIParser* aParser);\
NS_IMETHOD WillResumeParse(nsIContentSink* aSink = 0);\
NS_IMETHOD WillInterruptParse(nsIContentSink* aSink = 0);\
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_(nsITokenizer*) CreateTokenizer();
NS_IMETHOD_(PRInt32) GetType();
#endif /* nsIDTD_h___ */

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

@ -56,6 +56,14 @@ class nsTokenAllocator;
#define NS_ITOKENIZER_IID \
{0xe4238ddc, 0x9eb6, 0x11d2, {0xba, 0xa5, 0x0, 0x10, 0x4b, 0x98, 0x3f, 0xd4 }}
/**
* This interface is used as a callback to objects interested
* in observing the token stream created from the parse process.
*/
class nsITokenObserver {
public:
virtual PRBool operator()(CToken* aToken)=0;
};
/***************************************************************
Notes:

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

@ -253,7 +253,9 @@ CNavDTD::WillBuildModel(const CParserContext& aParserContext,
nsresult
CNavDTD::BuildModel(nsIParser* aParser,
nsITokenizer* aTokenizer)
nsITokenizer* aTokenizer,
nsITokenObserver* anObserver,
nsIContentSink* aSink)
{
NS_PRECONDITION(mBodyContext != nsnull,
"Create a context before calling build model");
@ -361,7 +363,8 @@ CNavDTD::BuildModel(nsIParser* aParser,
nsresult
CNavDTD::BuildNeglectedTarget(eHTMLTags aTarget,
eHTMLTokenTypes aType,
nsIParser* aParser)
nsIParser* aParser,
nsIContentSink* aSink)
{
NS_ASSERTION(mTokenizer, "tokenizer is null! unable to build target.");
NS_ASSERTION(mTokenAllocator, "unable to create tokens without an allocator.");
@ -372,15 +375,16 @@ CNavDTD::BuildNeglectedTarget(eHTMLTags aTarget,
CToken* target = mTokenAllocator->CreateTokenOfType(aType, aTarget);
NS_ENSURE_TRUE(target, NS_ERROR_OUT_OF_MEMORY);
mTokenizer->PushTokenFront(target);
return BuildModel(aParser, mTokenizer);
return BuildModel(aParser, mTokenizer, 0, aSink);
}
nsresult
CNavDTD::DidBuildModel(nsresult anErrorCode,
PRBool aNotifySink,
nsIParser* aParser)
nsIParser* aParser,
nsIContentSink* aSink)
{
if (!mSink) {
if (!aSink) {
return NS_OK;
}
@ -393,7 +397,7 @@ CNavDTD::DidBuildModel(nsresult anErrorCode,
// Also note: We ignore the return value of BuildNeglectedTarget, we
// can't reasonably respond to errors (or requests to block) at this
// point in the parsing process.
BuildNeglectedTarget(eHTMLTag_body, eToken_start, aParser);
BuildNeglectedTarget(eHTMLTag_body, eToken_start, aParser, aSink);
}
if (mFlags & NS_DTD_FLAG_MISPLACED_CONTENT) {
// Looks like the misplaced contents are not processed yet.
@ -431,7 +435,7 @@ CNavDTD::DidBuildModel(nsresult anErrorCode,
result = CloseContainersTo(mBodyContext->Last(), PR_FALSE);
if (NS_FAILED(result)) {
//No matter what, you need to call did build model.
mSink->DidBuildModel();
aSink->DidBuildModel();
return result;
}
}
@ -456,7 +460,7 @@ CNavDTD::DidBuildModel(nsresult anErrorCode,
}
// No matter what, you need to call did build model.
return mSink->DidBuildModel();
return aSink->DidBuildModel();
}
NS_IMETHODIMP_(void)
@ -472,12 +476,6 @@ CNavDTD::GetType()
return NS_IPARSER_FLAG_HTML;
}
NS_IMETHODIMP_(nsITokenizer*)
CNavDTD::CreateTokenizer()
{
return new nsHTMLTokenizer(mDTDMode, mDocType, mParserCommand, mSink);
}
/**
* Text and some tags require a body when they're added, this function returns
* true for those tags.
@ -3154,12 +3152,12 @@ CNavDTD::CreateContextStackFor(eHTMLTags aParent, eHTMLTags aChild)
}
nsresult
CNavDTD::WillResumeParse()
CNavDTD::WillResumeParse(nsIContentSink* aSink)
{
STOP_TIMER();
MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::WillResumeParse(), this=%p\n", this));
nsresult result = mSink ? mSink->WillResume() : NS_OK;
nsresult result = aSink ? aSink->WillResume() : NS_OK;
MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::WillResumeParse(), this=%p\n", this));
START_TIMER();
@ -3168,12 +3166,12 @@ CNavDTD::WillResumeParse()
}
nsresult
CNavDTD::WillInterruptParse()
CNavDTD::WillInterruptParse(nsIContentSink* aSink)
{
STOP_TIMER();
MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::WillInterruptParse(), this=%p\n", this));
nsresult result = mSink ? mSink->WillInterrupt() : NS_OK;
nsresult result = aSink ? aSink->WillInterrupt() : NS_OK;
MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::WillInterruptParse(), this=%p\n", this));
START_TIMER();

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

@ -296,7 +296,7 @@ private:
nsresult HandleProcessingInstructionToken(CToken* aToken);
nsresult HandleDocTypeDeclToken(CToken* aToken);
nsresult BuildNeglectedTarget(eHTMLTags aTarget, eHTMLTokenTypes aType,
nsIParser* aParser);
nsIParser* aParser, nsIContentSink* aSink);
nsresult OpenHTML(const nsCParserNode *aNode);
nsresult OpenBody(const nsCParserNode *aNode);

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

@ -95,11 +95,51 @@ CParserContext::SetMimeType(const nsACString& aMimeType)
}
nsresult
CParserContext::GetTokenizer(nsIDTD* aDTD, nsITokenizer*& aTokenizer)
CParserContext::GetTokenizer(nsIDTD* aDTD,
nsIContentSink* aSink,
nsITokenizer*& aTokenizer)
{
if (!mTokenizer)
mTokenizer = aDTD->CreateTokenizer();
return (aTokenizer = mTokenizer)
? NS_OK
: NS_ERROR_OUT_OF_MEMORY;
nsresult result = NS_OK;
PRInt32 type = aDTD ? aDTD->GetType() : NS_IPARSER_FLAG_HTML;
if (!mTokenizer) {
if (type == NS_IPARSER_FLAG_HTML || mParserCommand == eViewSource) {
nsCOMPtr<nsIHTMLContentSink> theSink = do_QueryInterface(aSink);
PRUint16 theFlags = 0;
if (theSink) {
// XXX This code is repeated both here and in CNavDTD. Can the two
// callsites be combined?
PRBool enabled;
theSink->IsEnabled(eHTMLTag_frameset, &enabled);
if(enabled) {
theFlags |= NS_IPARSER_FLAG_FRAMES_ENABLED;
}
theSink->IsEnabled(eHTMLTag_script, &enabled);
if(enabled) {
theFlags |= NS_IPARSER_FLAG_SCRIPT_ENABLED;
}
}
mTokenizer = new nsHTMLTokenizer(mDTDMode, mDocType,
mParserCommand, theFlags);
if (!mTokenizer) {
return NS_ERROR_OUT_OF_MEMORY;
}
// Make sure the new tokenizer has all of the necessary information.
// XXX this might not be necessary.
if (mPrevContext) {
mTokenizer->CopyState(mPrevContext->mTokenizer);
}
}
else if (type == NS_IPARSER_FLAG_XML) {
mTokenizer = do_QueryInterface(aDTD, &result);
}
}
aTokenizer = mTokenizer;
return result;
}

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

@ -73,7 +73,9 @@ public:
~CParserContext();
nsresult GetTokenizer(nsIDTD* aDTD, nsITokenizer*& aTokenizer);
nsresult GetTokenizer(nsIDTD* aDTD,
nsIContentSink* aSink,
nsITokenizer*& aTokenizer);
void SetMimeType(const nsACString& aMimeType);
nsCOMPtr<nsIRequest> mRequest; // provided by necko to differnciate different input streams

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

@ -803,12 +803,10 @@ nsExpatDriver::OpenInputStreamFromExternalDTD(const PRUnichar* aFPIStr,
localURI.swap(uri);
}
nsCOMPtr<nsIContentSink> sink = do_QueryInterface(mSink);
nsCOMPtr<nsIDocument> doc;
NS_ASSERTION(mSink == nsCOMPtr<nsIExpatSink>(do_QueryInterface(mOriginalSink)),
"In nsExpatDriver::OpenInputStreamFromExternalDTD: "
"mOriginalSink not the same object as mSink?");
if (mOriginalSink)
doc = do_QueryInterface(mOriginalSink->GetTarget());
if (sink)
doc = do_QueryInterface(sink->GetTarget());
PRInt16 shouldLoad = nsIContentPolicy::ACCEPT;
rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_DTD,
uri,
@ -1234,8 +1232,6 @@ nsExpatDriver::WillBuildModel(const CParserContext& aParserContext,
return mInternalState;
}
mOriginalSink = aSink;
static const XML_Memory_Handling_Suite memsuite =
{
(void *(*)(size_t))PR_Malloc,
@ -1303,7 +1299,9 @@ nsExpatDriver::WillBuildModel(const CParserContext& aParserContext,
NS_IMETHODIMP
nsExpatDriver::BuildModel(nsIParser* aParser,
nsITokenizer* aTokenizer)
nsITokenizer* aTokenizer,
nsITokenObserver* anObserver,
nsIContentSink* aSink)
{
return mInternalState;
}
@ -1311,19 +1309,17 @@ nsExpatDriver::BuildModel(nsIParser* aParser,
NS_IMETHODIMP
nsExpatDriver::DidBuildModel(nsresult anErrorCode,
PRBool aNotifySink,
nsIParser* aParser)
nsIParser* aParser,
nsIContentSink* aSink)
{
NS_ASSERTION(mSink == nsCOMPtr<nsIExpatSink>(do_QueryInterface(mOriginalSink)),
"In nsExpatDriver::DidBuildModel: mOriginalSink not the same object as mSink?");
// Check for mOriginalSink is intentional. This would make sure
// Check for mSink is intentional. This would make sure
// that DidBuildModel() is called only once on the sink.
nsresult result = NS_OK;
if (mOriginalSink) {
result = mOriginalSink->DidBuildModel();
mOriginalSink = nsnull;
if (mSink) {
result = aSink->DidBuildModel();
mSink = nsnull;
}
mSink = nsnull;
mExtendedSink = nsnull;
return result;
@ -1338,19 +1334,15 @@ nsExpatDriver::WillTokenize(PRBool aIsFinalChunk,
}
NS_IMETHODIMP
nsExpatDriver::WillResumeParse()
nsExpatDriver::WillResumeParse(nsIContentSink* aSink)
{
NS_ASSERTION(mSink == nsCOMPtr<nsIExpatSink>(do_QueryInterface(mOriginalSink)),
"In nsExpatDriver::WillResumeParse: mOriginalSink not the same object as mSink?");
return mOriginalSink ? mOriginalSink->WillResume() : NS_OK;
return aSink ? aSink->WillResume() : NS_OK;
}
NS_IMETHODIMP
nsExpatDriver::WillInterruptParse()
nsExpatDriver::WillInterruptParse(nsIContentSink* aSink)
{
NS_ASSERTION(mSink == nsCOMPtr<nsIExpatSink>(do_QueryInterface(mOriginalSink)),
"In nsExpatDriver::WillInterruptParse: mOriginalSink not the same object as mSink?");
return mOriginalSink ? mOriginalSink->WillInterrupt() : NS_OK;
return aSink ? aSink->WillInterrupt() : NS_OK;
}
NS_IMETHODIMP
@ -1375,12 +1367,6 @@ nsExpatDriver::GetType()
return NS_IPARSER_FLAG_XML;
}
NS_IMETHODIMP_(nsITokenizer*)
nsExpatDriver::CreateTokenizer()
{
return static_cast<nsITokenizer*>(this);
}
/*************************** Unused methods **********************************/
NS_IMETHODIMP_(CToken*)

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

@ -41,7 +41,6 @@
#include "expat_config.h"
#include "expat.h"
#include "nsCOMPtr.h"
#include "nsAutoPtr.h"
#include "nsString.h"
#include "nsIDTD.h"
#include "nsITokenizer.h"
@ -157,13 +156,8 @@ private:
// The length of the data in Expat's buffer (in number of PRUnichars).
PRUint32 mExpatBuffered;
// These sinks all refer the same conceptual object. mOriginalSink is
// identical with the nsIContentSink* passed to WillBuildModel, and exists
// only to avoid QI-ing back to nsIContentSink*.
nsCOMPtr<nsIContentSink> mOriginalSink;
nsCOMPtr<nsIExpatSink> mSink;
nsCOMPtr<nsIExtendedExpatSink> mExtendedSink;
const nsCatalogData* mCatalogData; // weak
nsString mURISpec;
};

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

@ -73,19 +73,9 @@ NS_IMPL_ISUPPORTS1(nsHTMLTokenizer, nsITokenizer)
nsHTMLTokenizer::nsHTMLTokenizer(PRInt32 aParseMode,
eParserDocType aDocType,
eParserCommands aCommand,
nsIHTMLContentSink* aSink)
: nsITokenizer(), mTokenDeque(0), mFlags(0)
PRUint16 aFlags) :
nsITokenizer(), mTokenDeque(0), mFlags(aFlags)
{
if (aSink) {
PRBool enabled;
aSink->IsEnabled(eHTMLTag_frameset, &enabled);
if (enabled)
mFlags |= NS_IPARSER_FLAG_FRAMES_ENABLED;
aSink->IsEnabled(eHTMLTag_script, &enabled);
if (enabled)
mFlags |= NS_IPARSER_FLAG_SCRIPT_ENABLED;
}
if (aParseMode == eDTDMode_full_standards ||
aParseMode == eDTDMode_almost_standards) {
mFlags |= NS_IPARSER_FLAG_STRICT_MODE;

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

@ -70,7 +70,7 @@ public:
nsHTMLTokenizer(PRInt32 aParseMode = eDTDMode_quirks,
eParserDocType aDocType = eHTML_Quirks,
eParserCommands aCommand = eViewNormal,
nsIHTMLContentSink* aSink = 0);
PRUint16 aFlags = 0);
virtual ~nsHTMLTokenizer();
protected:

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

@ -1508,7 +1508,7 @@ nsParser::WillBuildModel(nsString& aFilename)
NS_ENSURE_TRUE(mDTD, NS_ERROR_OUT_OF_MEMORY);
nsITokenizer* tokenizer;
nsresult rv = mParserContext->GetTokenizer(mDTD, tokenizer);
nsresult rv = mParserContext->GetTokenizer(mDTD, mSink, tokenizer);
NS_ENSURE_SUCCESS(rv, rv);
return mDTD->WillBuildModel(*mParserContext, tokenizer, mSink);
@ -1531,7 +1531,7 @@ nsParser::DidBuildModel(nsresult anErrorCode)
PRBool terminated = mInternalState == NS_ERROR_HTMLPARSER_STOPPARSING;
if (mDTD && mSink &&
mSink->ReadyToCallDidBuildModel(terminated)) {
result = mDTD->DidBuildModel(anErrorCode,PR_TRUE,this);
result = mDTD->DidBuildModel(anErrorCode,PR_TRUE,this,mSink);
}
//Ref. to bug 61462.
@ -2227,7 +2227,7 @@ nsParser::ResumeParse(PRBool allowIteration, PRBool aIsFinalChunk,
}
if (mDTD) {
mDTD->WillResumeParse();
mDTD->WillResumeParse(mSink);
PRBool theIterationIsOk = PR_TRUE;
while (result == NS_OK && theIterationIsOk) {
@ -2265,7 +2265,7 @@ nsParser::ResumeParse(PRBool allowIteration, PRBool aIsFinalChunk,
// (and cache any data coming in) until the parser is re-enabled.
if (NS_ERROR_HTMLPARSER_BLOCK == result) {
if (mDTD) {
mDTD->WillInterruptParse();
mDTD->WillInterruptParse(mSink);
}
if (mFlags & NS_PARSER_FLAG_PARSER_ENABLED) {
@ -2332,7 +2332,7 @@ nsParser::ResumeParse(PRBool allowIteration, PRBool aIsFinalChunk,
result == NS_ERROR_HTMLPARSER_INTERRUPTED) {
result = (result == NS_ERROR_HTMLPARSER_INTERRUPTED) ? NS_OK : result;
if (mDTD) {
mDTD->WillInterruptParse();
mDTD->WillInterruptParse(mSink);
}
}
}
@ -2358,13 +2358,13 @@ nsParser::BuildModel()
nsresult result = NS_OK;
if (mParserContext) {
result = mParserContext->GetTokenizer(mDTD, theTokenizer);
result = mParserContext->GetTokenizer(mDTD, mSink, theTokenizer);
}
if (NS_SUCCEEDED(result)) {
if (mDTD) {
MOZ_TIMER_START(mDTDTime);
result = mDTD->BuildModel(this, theTokenizer);
result = mDTD->BuildModel(this, theTokenizer, nsnull, mSink);
MOZ_TIMER_STOP(mDTDTime);
}
} else {
@ -2981,7 +2981,7 @@ nsParser::WillTokenize(PRBool aIsFinalChunk)
}
nsITokenizer* theTokenizer;
nsresult result = mParserContext->GetTokenizer(mDTD, theTokenizer);
nsresult result = mParserContext->GetTokenizer(mDTD, mSink, theTokenizer);
NS_ENSURE_SUCCESS(result, PR_FALSE);
return NS_SUCCEEDED(theTokenizer->WillTokenize(aIsFinalChunk,
&mTokenAllocator));
@ -2999,7 +2999,7 @@ nsresult nsParser::Tokenize(PRBool aIsFinalChunk)
nsresult result = NS_ERROR_NOT_AVAILABLE;
if (mParserContext) {
result = mParserContext->GetTokenizer(mDTD, theTokenizer);
result = mParserContext->GetTokenizer(mDTD, mSink, theTokenizer);
}
if (NS_SUCCEEDED(result)) {
@ -3074,7 +3074,7 @@ nsParser::DidTokenize(PRBool aIsFinalChunk)
}
nsITokenizer* theTokenizer;
nsresult rv = mParserContext->GetTokenizer(mDTD, theTokenizer);
nsresult rv = mParserContext->GetTokenizer(mDTD, mSink, theTokenizer);
NS_ENSURE_SUCCESS(rv, PR_FALSE);
rv = theTokenizer->DidTokenize(aIsFinalChunk);

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

@ -338,9 +338,7 @@ nsresult CViewSourceHTML::WillBuildModel(const CParserContext& aParserContext,
* @param aFilename is the name of the file being parsed.
* @return error code (almost always 0)
*/
NS_IMETHODIMP CViewSourceHTML::BuildModel(nsIParser* aParser,
nsITokenizer* aTokenizer)
{
NS_IMETHODIMP CViewSourceHTML::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer,nsITokenObserver* anObserver,nsIContentSink* aSink) {
nsresult result=NS_OK;
if(aTokenizer && aParser) {
@ -549,10 +547,7 @@ void CViewSourceHTML::AddAttrToNode(nsCParserStartNode& aNode,
* @param
* @return
*/
NS_IMETHODIMP CViewSourceHTML::DidBuildModel(nsresult anErrorCode,
PRBool aNotifySink,
nsIParser* aParser)
{
NS_IMETHODIMP CViewSourceHTML::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParser* aParser,nsIContentSink* aSink){
nsresult result= NS_OK;
//ADD CODE HERE TO CLOSE OPEN CONTAINERS...
@ -616,20 +611,13 @@ CViewSourceHTML::GetType() {
return NS_IPARSER_FLAG_HTML;
}
NS_IMETHODIMP_(nsITokenizer*)
CViewSourceHTML::CreateTokenizer()
{
return new nsHTMLTokenizer(mDTDMode, mDocType, mParserCommand, mSink);
}
/**
*
* @update gess5/18/98
* @param
* @return
*/
NS_IMETHODIMP CViewSourceHTML::WillResumeParse()
{
NS_IMETHODIMP CViewSourceHTML::WillResumeParse(nsIContentSink* aSink){
nsresult result = NS_OK;
if(mSink) {
result = mSink->WillResume();
@ -643,8 +631,7 @@ NS_IMETHODIMP CViewSourceHTML::WillResumeParse()
* @param
* @return
*/
NS_IMETHODIMP CViewSourceHTML::WillInterruptParse()
{
NS_IMETHODIMP CViewSourceHTML::WillInterruptParse(nsIContentSink* aSink){
nsresult result = NS_OK;
if(mSink) {
result = mSink->WillInterrupt();