Bug 107491, improve SSL error messages

Patch v9 - docshell and netwerk portions
Second and final checkin of this patch, enabling the new SSL error page
r/sr=biesi
This commit is contained in:
kaie%kuix.de 2007-02-18 04:24:05 +00:00
parent 892404e42f
commit 5af3e3656c
4 changed files with 46 additions and 5 deletions

View File

@ -136,6 +136,8 @@
#include "nsIPromptFactory.h"
#include "nsIObserver.h"
#include "nsINestedURI.h"
#include "nsITransportSecurityInfo.h"
#include "nsINSSErrorsService.h"
// Editor-related
#include "nsIEditingSession.h"
@ -2818,6 +2820,7 @@ nsDocShell::DisplayLoadError(nsresult aError, nsIURI *aURI,
nsAutoString formatStrs[kMaxFormatStrArgs];
PRUint32 formatStrCount = 0;
nsresult rv = NS_OK;
nsAutoString messageStr;
// Turn the error code into a human readable error message.
if (NS_ERROR_UNKNOWN_PROTOCOL == aError) {
@ -2892,6 +2895,27 @@ nsDocShell::DisplayLoadError(nsresult aError, nsIURI *aURI,
formatStrCount = 1;
error.AssignLiteral("netTimeout");
}
else if (NS_ERROR_GET_MODULE(aError) == NS_ERROR_MODULE_SECURITY) {
nsCOMPtr<nsISupports> securityInfo;
nsCOMPtr<nsITransportSecurityInfo> tsi;
if (aFailedChannel)
aFailedChannel->GetSecurityInfo(getter_AddRefs(securityInfo));
tsi = do_QueryInterface(securityInfo);
if (tsi) {
// Usually we should have aFailedChannel and get a detailed message
tsi->GetErrorMessage(getter_Copies(messageStr));
}
else {
// No channel, let's obtain the generic error message
nsCOMPtr<nsINSSErrorsService> nsserr =
do_GetService(NS_NSS_ERRORS_SERVICE_CONTRACTID);
if (nsserr) {
nsserr->GetErrorMessage(aError, messageStr);
}
}
if (!messageStr.IsEmpty())
error.AssignLiteral("nssFailure");
}
else {
// Errors requiring simple formatting
switch (aError) {
@ -2946,8 +2970,10 @@ nsDocShell::DisplayLoadError(nsresult aError, nsIURI *aURI,
}
// Test if the error needs to be formatted
nsAutoString messageStr;
if (formatStrCount > 0) {
if (!messageStr.IsEmpty()) {
// already obtained message
}
else if (formatStrCount > 0) {
const PRUnichar *strs[kMaxFormatStrArgs];
for (PRUint32 i = 0; i < formatStrCount; i++) {
strs[i] = formatStrs[i].get();

View File

@ -1174,7 +1174,8 @@ nsresult nsWebShell::EndPageLoad(nsIWebProgress *aProgress,
aStatus == NS_ERROR_REDIRECT_LOOP ||
aStatus == NS_ERROR_UNKNOWN_SOCKET_TYPE ||
aStatus == NS_ERROR_NET_INTERRUPT ||
aStatus == NS_ERROR_NET_RESET) {
aStatus == NS_ERROR_NET_RESET ||
NS_ERROR_GET_MODULE(aStatus) == NS_ERROR_MODULE_SECURITY) {
DisplayLoadError(aStatus, url, nsnull, channel);
}
else if (aStatus == NS_ERROR_DOCUMENT_NOT_CACHED) {

View File

@ -167,6 +167,7 @@
<h1 id="et_proxyResolveFailure">&proxyResolveFailure.title;</h1>
<h1 id="et_proxyConnectFailure">&proxyConnectFailure.title;</h1>
<h1 id="et_contentEncodingError">&contentEncodingError.title;</h1>
<h1 id="et_nssFailure">&nssFailure.title;</h1>
</div>
<div id="errorDescriptionsContainer">
<div id="ed_generic">&generic.longDesc;</div>
@ -185,6 +186,7 @@
<div id="ed_proxyResolveFailure">&proxyResolveFailure.longDesc;</div>
<div id="ed_proxyConnectFailure">&proxyConnectFailure.longDesc;</div>
<div id="ed_contentEncodingError">&contentEncodingError.longDesc;</div>
<div id="ed_nssFailure">&nssFailure.longDesc;</div>
</div>
</div>

View File

@ -66,6 +66,7 @@
#include "nsISocketProviderService.h"
#include "nsISocketProvider.h"
#include "nsISSLSocketControl.h"
#include "nsINSSErrorsService.h"
#include "nsIPipe.h"
#include "nsIProgrammingLanguage.h"
@ -149,7 +150,7 @@ static PRErrorCode RandomizeConnectError(PRErrorCode code)
static nsresult
ErrorAccordingToNSPR(PRErrorCode errorCode)
{
nsresult rv;
nsresult rv = NS_ERROR_FAILURE;
switch (errorCode) {
case PR_WOULD_BLOCK_ERROR:
rv = NS_BASE_STREAM_WOULD_BLOCK;
@ -176,7 +177,18 @@ ErrorAccordingToNSPR(PRErrorCode errorCode)
rv = NS_ERROR_NET_TIMEOUT;
break;
default:
rv = NS_ERROR_FAILURE;
{
nsCOMPtr<nsINSSErrorsService> nsserr =
do_GetService(NS_NSS_ERRORS_SERVICE_CONTRACTID);
if (nsserr) {
nsresult nssXPCOMCode;
nsresult conversionStatus =
nsserr->GetXPCOMFromNSSError(errorCode, &nssXPCOMCode);
if (NS_SUCCEEDED(conversionStatus))
rv = nssXPCOMCode;
}
}
}
LOG(("ErrorAccordingToNSPR [in=%d out=%x]\n", errorCode, rv));
return rv;