Bug 654106 - Avoid registering a script observer in the fragment parsing case. r=bzbarsky.

This commit is contained in:
Henri Sivonen 2011-05-04 09:35:14 +03:00
Родитель 222e1200db
Коммит 179c0852d6
4 изменённых файлов: 25 добавлений и 23 удалений

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

@ -287,25 +287,28 @@ nsContentSink::Init(nsIDocument* aDoc,
mDocumentURI = aURI;
mDocShell = do_QueryInterface(aContainer);
if (mDocShell) {
PRUint32 loadType = 0;
mDocShell->GetLoadType(&loadType);
mDocument->SetChangeScrollPosWhenScrollingToRef(
(loadType & nsIDocShell::LOAD_CMD_HISTORY) == 0);
mScriptLoader = mDocument->ScriptLoader();
if (!mFragmentMode) {
if (mDocShell) {
PRUint32 loadType = 0;
mDocShell->GetLoadType(&loadType);
mDocument->SetChangeScrollPosWhenScrollingToRef(
(loadType & nsIDocShell::LOAD_CMD_HISTORY) == 0);
}
// use this to avoid a circular reference sink->document->scriptloader->sink
nsCOMPtr<nsIScriptLoaderObserver> proxy =
new nsScriptLoaderObserverProxy(this);
NS_ENSURE_TRUE(proxy, NS_ERROR_OUT_OF_MEMORY);
mScriptLoader->AddObserver(proxy);
ProcessHTTPHeaders(aChannel);
}
// use this to avoid a circular reference sink->document->scriptloader->sink
nsCOMPtr<nsIScriptLoaderObserver> proxy =
new nsScriptLoaderObserverProxy(this);
NS_ENSURE_TRUE(proxy, NS_ERROR_OUT_OF_MEMORY);
mScriptLoader = mDocument->ScriptLoader();
mScriptLoader->AddObserver(proxy);
mCSSLoader = aDoc->CSSLoader();
ProcessHTTPHeaders(aChannel);
mNodeInfoManager = aDoc->NodeInfoManager();
mBackoffCount = sBackoffCount;
@ -315,10 +318,11 @@ nsContentSink::Init(nsIDocument* aDoc,
FavorPerformanceHint(!mDynamicLowerValue, 0);
}
mCanInterruptParser = sCanInterruptParser;
// prevent DropParserAndPerfHint from unblocking onload in the fragment
// case
mCanInterruptParser = !mFragmentMode && sCanInterruptParser;
return NS_OK;
}
NS_IMETHODIMP

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

@ -343,6 +343,8 @@ protected:
// shouldn't be performing any more content model notifications,
// since we're not longer updating our child counts.
PRUint8 mIsDocumentObserver : 1;
// True if this is a fragment parser
PRUint8 mFragmentMode : 1;
//
// -- Can interrupt parsing members --

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

@ -497,6 +497,8 @@ nsHtml5Parser::ParseHtml5Fragment(const nsAString& aSourceBuffer,
nsIURI* uri = doc->GetDocumentURI();
NS_ENSURE_TRUE(uri, NS_ERROR_NOT_AVAILABLE);
mExecutor->EnableFragmentMode(aPreventScriptExecution);
Initialize(doc, uri, nsnull, nsnull);
mExecutor->SetParser(this);
@ -516,8 +518,6 @@ nsHtml5Parser::ParseHtml5Fragment(const nsAString& aSourceBuffer,
}
#endif
mExecutor->EnableFragmentMode(aPreventScriptExecution);
NS_PRECONDITION(!mExecutor->HasStarted(),
"Tried to start parse without initializing the parser.");
mTreeBuilder->setScriptingEnabled(mExecutor->IsScriptEnabled());

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

@ -124,8 +124,6 @@ class nsHtml5TreeOpExecutor : public nsContentSink,
PRBool mCallContinueInterruptedParsingIfEnabled;
PRBool mFragmentMode;
PRBool mPreventScriptExecution;
public:
@ -241,8 +239,6 @@ class nsHtml5TreeOpExecutor : public nsContentSink,
*/
void EnableFragmentMode(PRBool aPreventScriptExecution) {
mFragmentMode = PR_TRUE;
mCanInterruptParser = PR_FALSE; // prevent DropParserAndPerfHint
// from unblocking onload
mPreventScriptExecution = aPreventScriptExecution;
}