Don't block the parser on scripts we'll never execute. Bug 371743, r+sr=sicking

This commit is contained in:
bzbarsky@mit.edu 2007-04-11 13:18:11 -07:00
parent 076b7d4a14
commit 65e1a1fadf

View File

@ -252,16 +252,17 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
// disabled. // disabled.
// XXX is this different from the mDocument->IsScriptEnabled() call? // XXX is this different from the mDocument->IsScriptEnabled() call?
nsIScriptGlobalObject *globalObject = mDocument->GetScriptGlobalObject(); nsIScriptGlobalObject *globalObject = mDocument->GetScriptGlobalObject();
if (globalObject) 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 nsIScriptContext *context = globalObject->GetScriptContext(
// point in going on. nsIProgrammingLanguage::JAVASCRIPT);
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 // Default script language is whatever the root content specifies
@ -423,57 +424,55 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// After the security manager, the content-policy stuff gets a veto // After the security manager, the content-policy stuff gets a veto
if (globalObject) { PRInt16 shouldLoad = nsIContentPolicy::ACCEPT;
PRInt16 shouldLoad = nsIContentPolicy::ACCEPT; nsIURI *docURI = mDocument->GetDocumentURI();
nsIURI *docURI = mDocument->GetDocumentURI(); rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_SCRIPT,
rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_SCRIPT, scriptURI,
scriptURI, docURI,
docURI, aElement,
aElement, NS_LossyConvertUTF16toASCII(type),
NS_LossyConvertUTF16toASCII(type), nsnull, //extra
nsnull, //extra &shouldLoad,
&shouldLoad, nsContentUtils::GetContentPolicy());
nsContentUtils::GetContentPolicy()); if (NS_FAILED(rv) || NS_CP_REJECTED(shouldLoad)) {
if (NS_FAILED(rv) || NS_CP_REJECTED(shouldLoad)) { if (NS_FAILED(rv) || shouldLoad != nsIContentPolicy::REJECT_TYPE) {
if (NS_FAILED(rv) || shouldLoad != nsIContentPolicy::REJECT_TYPE) { return NS_ERROR_CONTENT_BLOCKED;
return NS_ERROR_CONTENT_BLOCKED;
}
return NS_ERROR_CONTENT_BLOCKED_SHOW_ALT;
} }
return NS_ERROR_CONTENT_BLOCKED_SHOW_ALT;
request->mURI = scriptURI;
request->mIsInline = PR_FALSE;
request->mLoading = PR_TRUE;
nsCOMPtr<nsILoadGroup> loadGroup = mDocument->GetDocumentLoadGroup();
nsCOMPtr<nsIStreamLoader> loader;
nsCOMPtr<nsPIDOMWindow> window(do_QueryInterface(globalObject));
nsIDocShell *docshell = window->GetDocShell();
nsCOMPtr<nsIInterfaceRequestor> prompter(do_QueryInterface(docshell));
nsCOMPtr<nsIChannel> channel;
rv = NS_NewChannel(getter_AddRefs(channel),
scriptURI, nsnull, loadGroup,
prompter, nsIRequest::LOAD_NORMAL);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIHttpChannel> 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);
} }
request->mURI = scriptURI;
request->mIsInline = PR_FALSE;
request->mLoading = PR_TRUE;
nsCOMPtr<nsILoadGroup> loadGroup = mDocument->GetDocumentLoadGroup();
nsCOMPtr<nsIStreamLoader> loader;
nsCOMPtr<nsPIDOMWindow> window(do_QueryInterface(globalObject));
nsIDocShell *docshell = window->GetDocShell();
nsCOMPtr<nsIInterfaceRequestor> prompter(do_QueryInterface(docshell));
nsCOMPtr<nsIChannel> channel;
rv = NS_NewChannel(getter_AddRefs(channel),
scriptURI, nsnull, loadGroup,
prompter, nsIRequest::LOAD_NORMAL);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIHttpChannel> 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 { } else {
request->mLoading = PR_FALSE; request->mLoading = PR_FALSE;
request->mIsInline = PR_TRUE; request->mIsInline = PR_TRUE;