From 905aa04b9818beef19d41fd17cbf50d710032570 Mon Sep 17 00:00:00 2001 From: "kaie%kuix.de" Date: Sun, 18 Feb 2007 04:24:05 +0000 Subject: [PATCH] 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 git-svn-id: svn://10.0.0.236/trunk@220499 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/docshell/base/nsDocShell.cpp | 30 +++++++++++++++++-- mozilla/docshell/base/nsWebShell.cpp | 3 +- .../docshell/resources/content/netError.xhtml | 2 ++ .../netwerk/base/src/nsSocketTransport2.cpp | 16 ++++++++-- 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index 7af02967e27..075092ceeaf 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -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 securityInfo; + nsCOMPtr 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 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(); diff --git a/mozilla/docshell/base/nsWebShell.cpp b/mozilla/docshell/base/nsWebShell.cpp index 409bd76d074..9812201bf3e 100644 --- a/mozilla/docshell/base/nsWebShell.cpp +++ b/mozilla/docshell/base/nsWebShell.cpp @@ -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) { diff --git a/mozilla/docshell/resources/content/netError.xhtml b/mozilla/docshell/resources/content/netError.xhtml index 11a821ad8e4..09abcd5ae01 100644 --- a/mozilla/docshell/resources/content/netError.xhtml +++ b/mozilla/docshell/resources/content/netError.xhtml @@ -167,6 +167,7 @@

&proxyResolveFailure.title;

&proxyConnectFailure.title;

&contentEncodingError.title;

+

&nssFailure.title;

&generic.longDesc;
@@ -185,6 +186,7 @@
&proxyResolveFailure.longDesc;
&proxyConnectFailure.longDesc;
&contentEncodingError.longDesc;
+
&nssFailure.longDesc;
diff --git a/mozilla/netwerk/base/src/nsSocketTransport2.cpp b/mozilla/netwerk/base/src/nsSocketTransport2.cpp index 0bd9941289f..dfbd9e37af8 100644 --- a/mozilla/netwerk/base/src/nsSocketTransport2.cpp +++ b/mozilla/netwerk/base/src/nsSocketTransport2.cpp @@ -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 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;