Fix issues with ScriptAvailable() not firing for some scripts. Bug 214081, r+sr=jst

This commit is contained in:
bzbarsky%mit.edu 2003-07-31 01:28:16 +00:00
Родитель 140c6a5314
Коммит db19c4b681
4 изменённых файлов: 8 добавлений и 32 удалений

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

@ -324,20 +324,8 @@ nsScriptLoader::ProcessScriptElement(nsIDOMHTMLScriptElement *aElement,
aObserver); aObserver);
} }
// See if script evaluation is enabled.
PRBool scriptsEnabled = PR_TRUE;
nsCOMPtr<nsIScriptGlobalObject> globalObject;
mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject));
if (globalObject)
{
nsCOMPtr<nsIScriptContext> context;
if (NS_SUCCEEDED(globalObject->GetContext(getter_AddRefs(context)))
&& context)
context->GetScriptsEnabled(&scriptsEnabled);
}
// If scripts aren't enabled there's no point in going on. // If scripts aren't enabled there's no point in going on.
if (!scriptsEnabled) { if (!mDocument->IsScriptEnabled()) {
return FireErrorNotification(NS_ERROR_NOT_AVAILABLE, aElement, aObserver); return FireErrorNotification(NS_ERROR_NOT_AVAILABLE, aElement, aObserver);
} }
@ -421,6 +409,8 @@ nsScriptLoader::ProcessScriptElement(nsIDOMHTMLScriptElement *aElement,
return FireErrorNotification(rv, aElement, aObserver); return FireErrorNotification(rv, aElement, aObserver);
} }
nsCOMPtr<nsIScriptGlobalObject> globalObject;
mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject));
// After the security manager, the content-policy stuff gets a veto // After the security manager, the content-policy stuff gets a veto
if (globalObject) { if (globalObject) {
nsCOMPtr<nsIDOMWindow> domWin(do_QueryInterface(globalObject)); nsCOMPtr<nsIDOMWindow> domWin(do_QueryInterface(globalObject));

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

@ -645,8 +645,7 @@ nsHTMLScriptElement::GetLineNumber(PRUint32* aLineNumber)
void void
nsHTMLScriptElement::MaybeProcessScript() nsHTMLScriptElement::MaybeProcessScript()
{ {
if (mIsEvaluated || mEvaluating || !mDocument || !mParent || if (mIsEvaluated || mEvaluating || !mDocument || !mParent) {
!mDocument->IsScriptEnabled()) {
return; return;
} }

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

@ -5518,7 +5518,7 @@ HTMLContentSink::ScriptAvailable(nsresult aResult,
// Mark the current script as loaded // Mark the current script as loaded
mNeedToBlockParser = PR_FALSE; mNeedToBlockParser = PR_FALSE;
if (NS_SUCCEEDED(aResult)) { if (NS_SUCCEEDED(aResult) && aResult != NS_CONTENT_SCRIPT_IS_EVENTHANDLER) {
PreEvaluateScript(); PreEvaluateScript();
} else { } else {
mScriptElements->RemoveElementAt(count - 1); mScriptElements->RemoveElementAt(count - 1);
@ -5602,17 +5602,6 @@ HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode)
return rv; return rv;
} }
// Determine whether the script is really an event handler.
// Event handler scripts are NOT immediately evaluated.
nsCOMPtr<nsIDOMHTMLScriptElement> scriptElement = do_QueryInterface(element);
PRBool bIsEventHandler = PR_FALSE;
nsAutoString forString;
scriptElement->GetHtmlFor(forString);
if (!forString.IsEmpty()) {
bIsEventHandler = PR_TRUE;
}
nsCOMPtr<nsIDTD> dtd; nsCOMPtr<nsIDTD> dtd;
mParser->GetDTD(getter_AddRefs(dtd)); mParser->GetDTD(getter_AddRefs(dtd));
NS_ENSURE_TRUE(dtd, NS_ERROR_FAILURE); NS_ENSURE_TRUE(dtd, NS_ERROR_FAILURE);
@ -5660,11 +5649,9 @@ HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode)
// Assume that we're going to block the parser with a script load. // Assume that we're going to block the parser with a script load.
// If it's an inline script, we'll be told otherwise in the call // If it's an inline script, we'll be told otherwise in the call
// to our ScriptAvailable method. // to our ScriptAvailable method.
// mNeedToBlockParser = PR_TRUE;
// However, if this script is an event handler, then DO NOT block the
// parser because it will NOT be executed now.
mNeedToBlockParser = !bIsEventHandler;
nsCOMPtr<nsIDOMHTMLScriptElement> scriptElement = do_QueryInterface(element);
mScriptElements->AppendElement(scriptElement); mScriptElements->AppendElement(scriptElement);
} }

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

@ -1445,7 +1445,7 @@ nsXMLContentSink::ScriptAvailable(nsresult aResult,
// Mark the current script as loaded // Mark the current script as loaded
mNeedToBlockParser = PR_FALSE; mNeedToBlockParser = PR_FALSE;
if (NS_FAILED(aResult)) { if (NS_FAILED(aResult) || aResult == NS_CONTENT_SCRIPT_IS_EVENTHANDLER) {
mScriptElements.RemoveObjectAt(count-1); mScriptElements.RemoveObjectAt(count-1);
if(mParser && aWasPending){ if(mParser && aWasPending){