From 55f8e6385816651d220fcf1945b29c980a26d32d Mon Sep 17 00:00:00 2001 From: "bzbarsky@mit.edu" Date: Wed, 11 Apr 2007 13:18:11 -0700 Subject: [PATCH] Don't block the parser on scripts we'll never execute. Bug 371743, r+sr=sicking --- content/base/src/nsScriptLoader.cpp | 115 ++++++++++++++-------------- 1 file changed, 57 insertions(+), 58 deletions(-) diff --git a/content/base/src/nsScriptLoader.cpp b/content/base/src/nsScriptLoader.cpp index 45d8129eb7ae..64060586d110 100644 --- a/content/base/src/nsScriptLoader.cpp +++ b/content/base/src/nsScriptLoader.cpp @@ -252,16 +252,17 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement) // disabled. // XXX is this different from the mDocument->IsScriptEnabled() call? nsIScriptGlobalObject *globalObject = mDocument->GetScriptGlobalObject(); - if (globalObject) - { - nsIScriptContext *context = globalObject->GetScriptContext( - nsIProgrammingLanguage::JAVASCRIPT); + if (!globalObject) { + return NS_ERROR_NOT_AVAILABLE; + } + + nsIScriptContext *context = globalObject->GetScriptContext( + nsIProgrammingLanguage::JAVASCRIPT); - // If scripts aren't enabled in the current context, there's no - // point in going on. - if (context && !context->GetScriptsEnabled()) { - return NS_ERROR_NOT_AVAILABLE; - } + // If scripts aren't enabled in the current context, there's no + // point in going on. + if (!context || !context->GetScriptsEnabled()) { + return NS_ERROR_NOT_AVAILABLE; } // Default script language is whatever the root content specifies @@ -423,57 +424,55 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement) NS_ENSURE_SUCCESS(rv, rv); // After the security manager, the content-policy stuff gets a veto - if (globalObject) { - PRInt16 shouldLoad = nsIContentPolicy::ACCEPT; - nsIURI *docURI = mDocument->GetDocumentURI(); - rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_SCRIPT, - scriptURI, - docURI, - aElement, - NS_LossyConvertUTF16toASCII(type), - nsnull, //extra - &shouldLoad, - nsContentUtils::GetContentPolicy()); - if (NS_FAILED(rv) || NS_CP_REJECTED(shouldLoad)) { - if (NS_FAILED(rv) || shouldLoad != nsIContentPolicy::REJECT_TYPE) { - return NS_ERROR_CONTENT_BLOCKED; - } - return NS_ERROR_CONTENT_BLOCKED_SHOW_ALT; + PRInt16 shouldLoad = nsIContentPolicy::ACCEPT; + nsIURI *docURI = mDocument->GetDocumentURI(); + rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_SCRIPT, + scriptURI, + docURI, + aElement, + NS_LossyConvertUTF16toASCII(type), + nsnull, //extra + &shouldLoad, + nsContentUtils::GetContentPolicy()); + if (NS_FAILED(rv) || NS_CP_REJECTED(shouldLoad)) { + if (NS_FAILED(rv) || shouldLoad != nsIContentPolicy::REJECT_TYPE) { + return NS_ERROR_CONTENT_BLOCKED; } - - request->mURI = scriptURI; - request->mIsInline = PR_FALSE; - request->mLoading = PR_TRUE; - - nsCOMPtr loadGroup = mDocument->GetDocumentLoadGroup(); - nsCOMPtr loader; - - nsCOMPtr window(do_QueryInterface(globalObject)); - nsIDocShell *docshell = window->GetDocShell(); - - nsCOMPtr prompter(do_QueryInterface(docshell)); - - nsCOMPtr channel; - rv = NS_NewChannel(getter_AddRefs(channel), - scriptURI, nsnull, loadGroup, - prompter, nsIRequest::LOAD_NORMAL); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr httpChannel(do_QueryInterface(channel)); - if (httpChannel) { - // HTTP content negotation has little value in this context. - httpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Accept"), - NS_LITERAL_CSTRING("*/*"), - PR_FALSE); - httpChannel->SetReferrer(mDocument->GetDocumentURI()); - } - - rv = NS_NewStreamLoader(getter_AddRefs(loader), this); - NS_ENSURE_SUCCESS(rv, rv); - - rv = channel->AsyncOpen(loader, request); - NS_ENSURE_SUCCESS(rv, rv); + return NS_ERROR_CONTENT_BLOCKED_SHOW_ALT; } + + request->mURI = scriptURI; + request->mIsInline = PR_FALSE; + request->mLoading = PR_TRUE; + + nsCOMPtr loadGroup = mDocument->GetDocumentLoadGroup(); + nsCOMPtr loader; + + nsCOMPtr window(do_QueryInterface(globalObject)); + nsIDocShell *docshell = window->GetDocShell(); + + nsCOMPtr prompter(do_QueryInterface(docshell)); + + nsCOMPtr channel; + rv = NS_NewChannel(getter_AddRefs(channel), + scriptURI, nsnull, loadGroup, + prompter, nsIRequest::LOAD_NORMAL); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr httpChannel(do_QueryInterface(channel)); + if (httpChannel) { + // HTTP content negotation has little value in this context. + httpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Accept"), + NS_LITERAL_CSTRING("*/*"), + PR_FALSE); + httpChannel->SetReferrer(mDocument->GetDocumentURI()); + } + + rv = NS_NewStreamLoader(getter_AddRefs(loader), this); + NS_ENSURE_SUCCESS(rv, rv); + + rv = channel->AsyncOpen(loader, request); + NS_ENSURE_SUCCESS(rv, rv); } else { request->mLoading = PR_FALSE; request->mIsInline = PR_TRUE;