Bug 366417: Set up scriptloader in the nsDocument ctor to ensure that the blocker-count stays in sync with the notification depth. r/sr=bz

This commit is contained in:
jonas%sicking.cc 2007-05-30 20:43:42 +00:00
Родитель 79439823e9
Коммит 48fa25294c
11 изменённых файлов: 37 добавлений и 65 удалений

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

@ -530,7 +530,7 @@ public:
/**
* Get the script loader for this document
*/
virtual nsScriptLoader* GetScriptLoader() = 0;
virtual nsScriptLoader* ScriptLoader() = 0;
//----------------------------------------------------------------------

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

@ -205,8 +205,7 @@ nsContentSink::Init(nsIDocument* aDoc,
new nsScriptLoaderObserverProxy(this);
NS_ENSURE_TRUE(proxy, NS_ERROR_OUT_OF_MEMORY);
mScriptLoader = mDocument->GetScriptLoader();
NS_ENSURE_TRUE(mScriptLoader, NS_ERROR_FAILURE);
mScriptLoader = mDocument->ScriptLoader();
mScriptLoader->AddObserver(proxy);
mCSSLoader = aDoc->CSSLoader();

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

@ -1078,7 +1078,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END
nsresult
nsDocument::Init()
{
if (mBindingManager || mCSSLoader || mNodeInfoManager) {
if (mBindingManager || mCSSLoader || mNodeInfoManager || mScriptLoader) {
return NS_ERROR_ALREADY_INITIALIZED;
}
@ -1126,6 +1126,9 @@ nsDocument::Init()
NS_ASSERTION(GetOwnerDoc() == this, "Our nodeinfo is busted!");
mScriptLoader = new nsScriptLoader(this);
NS_ENSURE_TRUE(mScriptLoader, NS_ERROR_OUT_OF_MEMORY);
return NS_OK;
}
@ -2555,12 +2558,8 @@ nsDocument::GetInnerWindow()
}
nsScriptLoader*
nsDocument::GetScriptLoader()
nsDocument::ScriptLoader()
{
if (!mScriptLoader) {
mScriptLoader = new nsScriptLoader(this);
}
return mScriptLoader;
}

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

@ -451,7 +451,7 @@ public:
/**
* Get the script loader for this document
*/
virtual nsScriptLoader* GetScriptLoader();
virtual nsScriptLoader* ScriptLoader();
virtual void AddMutationObserver(nsIMutationObserver* aObserver);
virtual void RemoveMutationObserver(nsIMutationObserver* aMutationObserver);

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

@ -195,18 +195,16 @@ nsScriptElement::MaybeProcessScript()
}
nsresult scriptresult = NS_OK;
nsRefPtr<nsScriptLoader> loader = cont->GetOwnerDoc()->GetScriptLoader();
if (loader) {
mIsEvaluated = PR_TRUE;
scriptresult = loader->ProcessScriptElement(this);
nsRefPtr<nsScriptLoader> loader = cont->GetOwnerDoc()->ScriptLoader();
mIsEvaluated = PR_TRUE;
scriptresult = loader->ProcessScriptElement(this);
// The only error we don't ignore is NS_ERROR_HTMLPARSER_BLOCK
// However we don't want to override other success values
// (such as NS_CONTENT_SCRIPT_IS_EVENTHANDLER)
if (NS_FAILED(scriptresult) &&
scriptresult != NS_ERROR_HTMLPARSER_BLOCK) {
scriptresult = NS_OK;
}
// The only error we don't ignore is NS_ERROR_HTMLPARSER_BLOCK
// However we don't want to override other success values
// (such as NS_CONTENT_SCRIPT_IS_EVENTHANDLER)
if (NS_FAILED(scriptresult) &&
scriptresult != NS_ERROR_HTMLPARSER_BLOCK) {
scriptresult = NS_OK;
}
return scriptresult;

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

@ -775,11 +775,9 @@ nsGenericHTMLElement::SetInnerHTML(const nsAString& aInnerHTML)
PRBool scripts_enabled = PR_FALSE;
if (doc) {
loader = doc->GetScriptLoader();
if (loader) {
scripts_enabled = loader->GetEnabled();
loader->SetEnabled(PR_FALSE);
}
loader = doc->ScriptLoader();
scripts_enabled = loader->GetEnabled();
loader->SetEnabled(PR_FALSE);
}
nsCOMPtr<nsIDOMNode> thisNode(do_QueryInterface(NS_STATIC_CAST(nsIContent *,

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

@ -1852,10 +1852,7 @@ HTMLContentSink::DidBuildModel(void)
ScrollToRef();
nsScriptLoader *loader = mDocument->GetScriptLoader();
if (loader) {
loader->RemoveObserver(this);
}
mDocument->ScriptLoader()->RemoveObserver(this);
// Make sure we no longer respond to document mutations. We've flushed all
// our notifications out, so there's no need to do anything else here.

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

@ -327,10 +327,7 @@ nsXMLContentSink::DidBuildModel()
}
else {
// Kick off layout for non-XSLT transformed documents.
nsScriptLoader *loader = mDocument->GetScriptLoader();
if (loader) {
loader->RemoveObserver(this);
}
mDocument->ScriptLoader()->RemoveObserver(this);
if (mDocElement) {
// Notify document observers that all the content has been stuck
@ -405,10 +402,7 @@ nsXMLContentSink::OnTransformDone(nsresult aResult,
mDocument = aResultDocument;
}
nsScriptLoader *loader = originalDocument->GetScriptLoader();
if (loader) {
loader->RemoveObserver(this);
}
originalDocument->ScriptLoader()->RemoveObserver(this);
// Notify document observers that all the content has been stuck
// into the document.
@ -929,10 +923,7 @@ nsXMLContentSink::SetDocElement(PRInt32 aNameSpaceID,
// In this case, disable script execution, stylesheet
// loading, and auto XLinks since we plan to prettyprint.
mAllowAutoXLinks = PR_FALSE;
nsScriptLoader* scriptLoader = mDocument->GetScriptLoader();
if (scriptLoader) {
scriptLoader->SetEnabled(PR_FALSE);
}
mDocument->ScriptLoader()->SetEnabled(PR_FALSE);
if (mCSSLoader) {
mCSSLoader->SetEnabled(PR_FALSE);
}

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

@ -567,11 +567,8 @@ nsXMLDocument::StartDocumentLoad(const char* aCommand,
// We leave them disabled even in EndLoad(), and let anyone
// who puts the document on display to worry about enabling.
// scripts
nsScriptLoader *loader = GetScriptLoader();
if (loader) {
loader->SetEnabled(PR_FALSE); // Do not load/process scripts when loading as data
}
// Do not load/process scripts when loading as data
ScriptLoader()->SetEnabled(PR_FALSE);
// styles
CSSLoader()->SetEnabled(PR_FALSE); // Do not load/process styles when loading as data

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

@ -920,15 +920,13 @@ txMozillaXMLOutput::createResultDocument(const nsSubstring& aName, PRInt32 aNsID
}
// Set up script loader of the result document.
nsScriptLoader *loader = mDocument->GetScriptLoader();
if (loader) {
if (mNotifier) {
loader->AddObserver(mNotifier);
}
else {
// Don't load scripts, we can't notify the caller when they're loaded.
loader->SetEnabled(PR_FALSE);
}
nsScriptLoader *loader = mDocument->ScriptLoader();
if (mNotifier) {
loader->AddObserver(mNotifier);
}
else {
// Don't load scripts, we can't notify the caller when they're loaded.
loader->SetEnabled(PR_FALSE);
}
if (mNotifier) {
@ -1120,11 +1118,8 @@ txTransformNotifier::SignalTransformEnd(nsresult aResult)
nsCOMPtr<nsIDocument> doc = do_QueryInterface(mDocument);
if (doc) {
nsScriptLoader *scriptLoader = doc->GetScriptLoader();
if (scriptLoader) {
scriptLoader->RemoveObserver(this);
// XXX Maybe we want to cancel script loads if NS_FAILED(rv)?
}
doc->ScriptLoader()->RemoveObserver(this);
// XXX Maybe we want to cancel script loads if NS_FAILED(rv)?
if (NS_FAILED(aResult)) {
doc->CSSLoader()->Stop();

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

@ -138,10 +138,8 @@ nsScriptableUnescapeHTML::ParseFragment(const nsAString &aFragment,
nsRefPtr<nsScriptLoader> loader;
PRBool scripts_enabled = PR_FALSE;
if (document) {
loader = document->GetScriptLoader();
if (loader) {
scripts_enabled = loader->GetEnabled();
}
loader = document->ScriptLoader();
scripts_enabled = loader->GetEnabled();
}
if (scripts_enabled) {
loader->SetEnabled(PR_FALSE);