More bug 461555 fixes to fix orange by making sure to remove deferred-scripts' onloadblocker when the parser is terminated. r/sr=mrbkap

This commit is contained in:
Jonas Sicking 2009-01-26 21:41:25 -08:00
parent 92e375760d
commit 41e86fb4e9
9 changed files with 37 additions and 23 deletions

View File

@ -353,8 +353,8 @@ nsContentSink::ScriptAvailable(nsresult aResult,
// using the DOM during loading, or if the script was inline and thus
// never blocked.
NS_ASSERTION(count == 0 ||
mScriptElements.IndexOf(aElement) == PRUint32(count - 1) ||
mScriptElements.IndexOf(aElement) == PRUint32(-1),
mScriptElements.IndexOf(aElement) == PRInt32(count - 1) ||
mScriptElements.IndexOf(aElement) == -1,
"script found at unexpected position");
// Check if this is the element we were waiting for
@ -1757,21 +1757,23 @@ nsContentSink::ContinueInterruptedParsingAsync()
}
PRBool
nsContentSink::ReadyToCallDidBuildModelImpl()
nsContentSink::ReadyToCallDidBuildModelImpl(PRBool aTerminated)
{
if (!mDidGetReadyToCallDidBuildModelCall) {
if (mDocument) {
if (mDocument && !aTerminated) {
mDocument->SetReadyStateInternal(nsIDocument::READYSTATE_INTERACTIVE);
}
if (mScriptLoader) {
mScriptLoader->EndDeferringScripts();
mScriptLoader->EndDeferringScripts(aTerminated);
}
}
mDidGetReadyToCallDidBuildModelCall = PR_TRUE;
return !mScriptLoader || !mScriptLoader->HasPendingOrCurrentScripts();
// If we're terminated we always want to call DidBuildModel.
return aTerminated || !mScriptLoader ||
!mScriptLoader->HasPendingOrCurrentScripts();
}
// URIs: action, href, src, longdesc, usemap, cite

View File

@ -138,7 +138,7 @@ class nsContentSink : public nsICSSLoaderObserver,
NS_HIDDEN_(nsresult) DidProcessATokenImpl(void);
NS_HIDDEN_(void) WillBuildModelImpl(void);
NS_HIDDEN_(void) DidBuildModelImpl(void);
NS_HIDDEN_(PRBool) ReadyToCallDidBuildModelImpl(void);
NS_HIDDEN_(PRBool) ReadyToCallDidBuildModelImpl(PRBool aTerminated);
NS_HIDDEN_(void) DropParserAndPerfHint(void);
void NotifyAppend(nsIContent* aContent, PRUint32 aStartIndex);

View File

@ -1013,7 +1013,7 @@ nsScriptLoader::ShouldExecuteScript(nsIDocument* aDocument,
}
void
nsScriptLoader::EndDeferringScripts()
nsScriptLoader::EndDeferringScripts(PRBool aKillDeferred)
{
if (mDeferEnabled) {
// Have to check because we apparently get EndDeferringScripts
@ -1022,7 +1022,12 @@ nsScriptLoader::EndDeferringScripts()
}
mDeferEnabled = PR_FALSE;
for (PRUint32 i = 0; i < (PRUint32)mRequests.Count(); ++i) {
mRequests[i]->mDefer = PR_FALSE;
if (aKillDeferred && mRequests[i]->mDefer) {
mRequests.RemoveObjectAt(i--);
}
else {
mRequests[i]->mDefer = PR_FALSE;
}
}
ProcessPendingRequests();

View File

@ -205,8 +205,11 @@ public:
*
* WARNING: This function will syncronously execute content scripts, so be
* prepared that the world might change around you.
*
* If aKillDeferred is PR_TRUE, deferred scripts won't be run, but instead
* removed.
*/
void EndDeferringScripts();
void EndDeferringScripts(PRBool aKillDeferred);
/**
* Returns the number of pending scripts, deferred or not.

View File

@ -185,7 +185,7 @@ public:
NS_IMETHOD WillParse(void);
NS_IMETHOD WillBuildModel(void);
NS_IMETHOD DidBuildModel(void);
virtual PRBool ReadyToCallDidBuildModel(void);
virtual PRBool ReadyToCallDidBuildModel(PRBool aTerminated);
NS_IMETHOD WillInterrupt(void);
NS_IMETHOD WillResume(void);
NS_IMETHOD SetParser(nsIParser* aParser);
@ -1839,9 +1839,9 @@ HTMLContentSink::DidBuildModel(void)
}
PRBool
HTMLContentSink::ReadyToCallDidBuildModel()
HTMLContentSink::ReadyToCallDidBuildModel(PRBool aTerminated)
{
return ReadyToCallDidBuildModelImpl();
return ReadyToCallDidBuildModelImpl(aTerminated);
}
NS_IMETHODIMP

View File

@ -384,9 +384,9 @@ nsXMLContentSink::DidBuildModel()
}
PRBool
nsXMLContentSink::ReadyToCallDidBuildModel()
nsXMLContentSink::ReadyToCallDidBuildModel(PRBool aTerminated)
{
return ReadyToCallDidBuildModelImpl();
return ReadyToCallDidBuildModelImpl(aTerminated);
}
NS_IMETHODIMP

View File

@ -93,7 +93,7 @@ public:
NS_IMETHOD WillParse(void);
NS_IMETHOD WillBuildModel(void);
NS_IMETHOD DidBuildModel(void);
virtual PRBool ReadyToCallDidBuildModel(void);
virtual PRBool ReadyToCallDidBuildModel(PRBool aTerminated);
NS_IMETHOD WillInterrupt(void);
NS_IMETHOD WillResume(void);
NS_IMETHOD SetParser(nsIParser* aParser);

View File

@ -90,9 +90,14 @@ public:
/**
* Thie method gets caller right before DidBuildModel is called.
* If false
* If false, the parser won't call DidBuildModel yet.
*
* If aTerminated is true, the parser has been terminated.
*/
virtual PRBool ReadyToCallDidBuildModel() { return PR_TRUE; };
virtual PRBool ReadyToCallDidBuildModel(PRBool aTerminated)
{
return PR_TRUE;
};
/**
* This method gets called when the parser gets i/o blocked,

View File

@ -1525,12 +1525,11 @@ nsParser::DidBuildModel(nsresult anErrorCode)
if (IsComplete()) {
if (mParserContext && !mParserContext->mPrevContext) {
// If mInternalState == NS_ERROR_HTMLPARSER_STOPPARSING then we got in
// here through Terminate() and so we always want to Call DidBuildModel
// on the DTD, even if the sink says 'no'.
// Let sink know if we're about to end load because we've been terminated.
// In that case we don't want it to run deferred scripts.
PRBool terminated = mInternalState == NS_ERROR_HTMLPARSER_STOPPARSING;
if (mParserContext->mDTD && mSink &&
(mInternalState == NS_ERROR_HTMLPARSER_STOPPARSING ||
mSink->ReadyToCallDidBuildModel())) {
mSink->ReadyToCallDidBuildModel(terminated)) {
result = mParserContext->mDTD->DidBuildModel(anErrorCode,PR_TRUE,this,mSink);
}