From 69fdd9201c28013e8218ea927993e892d400b660 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Fri, 16 Sep 2005 19:27:27 +0000 Subject: [PATCH] Show a useful error message if a page claims to be compressed and isn't. Bug 184144, patch by Vidar Braut Haarr , r=darin, sr=bzbarsky git-svn-id: svn://10.0.0.236/trunk@180424 18797224-902f-48f8-a5cc-f745e15eee43 --- .../chrome/overrides/appstrings.properties | 1 + .../locales/en-US/chrome/overrides/netError.dtd | 7 +++++++ mozilla/docshell/base/nsDocShell.cpp | 4 ++++ mozilla/docshell/base/nsWebShell.cpp | 12 ++++++++---- .../locales/en-US/chrome/appstrings.properties | 1 + mozilla/dom/locales/en-US/chrome/netError.dtd | 3 +++ mozilla/netwerk/base/public/nsNetError.h | 6 ++++++ .../netwerk/protocol/http/src/nsHttpChannel.cpp | 14 +++++++++----- .../netwerk/protocol/http/src/nsHttpChannel.h | 2 +- .../converters/nsHTTPCompressConv.cpp | 17 +++++++++-------- 10 files changed, 49 insertions(+), 18 deletions(-) diff --git a/mozilla/browser/locales/en-US/chrome/overrides/appstrings.properties b/mozilla/browser/locales/en-US/chrome/overrides/appstrings.properties index a6ba073b067..1bc14fbfa55 100644 --- a/mozilla/browser/locales/en-US/chrome/overrides/appstrings.properties +++ b/mozilla/browser/locales/en-US/chrome/overrides/appstrings.properties @@ -51,6 +51,7 @@ isprinting=The document cannot change while Printing or in Print Preview. deniedPortAccess=This address uses a network port which is normally used for purposes other than Web browsing. Firefox has canceled the request for your protection. proxyResolveFailure=Firefox is configured to use a proxy server that can't be found. proxyConnectFailure=Firefox is configured to use a proxy server that is refusing connections. +contentEncodingError=The page you are trying to view cannot be shown because it uses an invalid or unsupported form of compression. Please contact the website owners to inform them of this problem. externalProtocolTitle=External Protocol Request externalProtocolPrompt=An external application must be launched to handle %1$S: links. Requested link:\n\n\n%2$S\nApplication: %3$S\n\n\nIf you were not expecting this request it may be an attempt to exploit a weakness in that other program. Cancel this request unless you are sure it is not malicious.\n #LOCALIZATION NOTE (externalProtocolUnknown): The following string is shown if the application name can't be determined diff --git a/mozilla/browser/locales/en-US/chrome/overrides/netError.dtd b/mozilla/browser/locales/en-US/chrome/overrides/netError.dtd index 31c9a167ecc..b9e46a89b29 100644 --- a/mozilla/browser/locales/en-US/chrome/overrides/netError.dtd +++ b/mozilla/browser/locales/en-US/chrome/overrides/netError.dtd @@ -59,6 +59,13 @@ "> + + +
  • Please contact the website owners to inform them of this problem.
  • + +"> + diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index c6a72a2647c..a3a73bc4b96 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -2945,6 +2945,10 @@ nsDocShell::DisplayLoadError(nsresult aError, nsIURI *aURI, // Proxy connection was refused. error.AssignLiteral("proxyConnectFailure"); break; + case NS_ERROR_INVALID_CONTENT_ENCODING: + // Bad Content Encoding. + error.AssignLiteral("contentEncodingError"); + break; } } diff --git a/mozilla/docshell/base/nsWebShell.cpp b/mozilla/docshell/base/nsWebShell.cpp index 575f3db9a2a..62822da570b 100644 --- a/mozilla/docshell/base/nsWebShell.cpp +++ b/mozilla/docshell/base/nsWebShell.cpp @@ -673,18 +673,22 @@ nsresult nsWebShell::EndPageLoad(nsIWebProgress *aProgress, // // If the page load failed, then deal with the error condition... // Errors are handled as follows: - // 1. Check to see if it a file not found error. + // 1. Check to see if it's a file not found error or bad content + // encoding error. // 2. Send the URI to a keyword server (if enabled) // 3. If the error was DNS failure, then add www and .com to the URI // (if appropriate). // 4. Throw an error dialog box... // - if(url && NS_FAILED(aStatus)) { - if (aStatus == NS_ERROR_FILE_NOT_FOUND) { + if (url && NS_FAILED(aStatus)) + { + if (aStatus == NS_ERROR_FILE_NOT_FOUND || + aStatus == NS_ERROR_INVALID_CONTENT_ENCODING) + { DisplayLoadError(aStatus, url, nsnull, channel); return NS_OK; - } + } if (sURIFixup) { diff --git a/mozilla/dom/locales/en-US/chrome/appstrings.properties b/mozilla/dom/locales/en-US/chrome/appstrings.properties index 32f80484f10..535f1b04e44 100644 --- a/mozilla/dom/locales/en-US/chrome/appstrings.properties +++ b/mozilla/dom/locales/en-US/chrome/appstrings.properties @@ -51,6 +51,7 @@ isprinting=The document cannot change while Printing or in Print Preview. deniedPortAccess=Access to the port number given has been disabled for security reasons. proxyResolveFailure=The proxy server you have configured could not be found. Please check your proxy settings and try again. proxyConnectFailure=The connection was refused when attempting to contact the proxy server you have configured. Please check your proxy settings and try again. +contentEncodingError=The page you are trying to view cannot be shown because it uses an invalid or unsupported form of compression. Please contact the website owners to inform them of this problem. externalProtocolTitle=External Protocol Request externalProtocolPrompt=An external application must be launched to handle %1$S: links. Requested link:\n\n\n%2$S\nApplication: %3$S\n\n\nIf you were not expecting this request it may be an attempt to exploit a weakness in that other program. Cancel this request unless you are sure it is not malicious.\n #LOCALIZATION NOTE (externalProtocolUnknown): The following string is shown if the application name can't be determined diff --git a/mozilla/dom/locales/en-US/chrome/netError.dtd b/mozilla/dom/locales/en-US/chrome/netError.dtd index 0f040880e24..6ac022ad977 100644 --- a/mozilla/dom/locales/en-US/chrome/netError.dtd +++ b/mozilla/dom/locales/en-US/chrome/netError.dtd @@ -27,6 +27,9 @@ The browser is operating in its offline mode and cannot connect to the requested item.

    "> + +The page you are trying to view cannot be shown because it uses an invalid or unsupported form of compression.

    "> + The network link was interrupted while negotiating a connection. Please try again.

    "> diff --git a/mozilla/netwerk/base/public/nsNetError.h b/mozilla/netwerk/base/public/nsNetError.h index 1987225442a..a3c79dd13b4 100644 --- a/mozilla/netwerk/base/public/nsNetError.h +++ b/mozilla/netwerk/base/public/nsNetError.h @@ -130,6 +130,12 @@ #define NS_ERROR_IN_PROGRESS \ NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 15) +/** + * The content encoding of the source document was incorrect, for example + * returning a plain HTML document advertised as Content-Encoding: gzip + */ +#define NS_ERROR_INVALID_CONTENT_ENCODING \ + NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 27) /****************************************************************************** * Connectivity error codes: diff --git a/mozilla/netwerk/protocol/http/src/nsHttpChannel.cpp b/mozilla/netwerk/protocol/http/src/nsHttpChannel.cpp index 358e05c3424..4f56c9ad464 100644 --- a/mozilla/netwerk/protocol/http/src/nsHttpChannel.cpp +++ b/mozilla/netwerk/protocol/http/src/nsHttpChannel.cpp @@ -674,17 +674,17 @@ nsHttpChannel::AddCookiesToRequest() mRequestHead.SetHeader(nsHttp::Cookie, cookie, PR_FALSE); } -void +nsresult nsHttpChannel::ApplyContentConversions() { if (!mResponseHead) - return; + return NS_OK; LOG(("nsHttpChannel::ApplyContentConversions [this=%x]\n", this)); if (!mApplyConversion) { LOG(("not applying conversion per mApplyConversion\n")); - return; + return NS_OK; } const char *val = mResponseHead->PeekHeader(nsHttp::Content_Encoding); @@ -708,7 +708,11 @@ nsHttpChannel::ApplyContentConversions() mListener = converter; } } + } else if (val != nsnull) { + return NS_ERROR_INVALID_CONTENT_ENCODING; } + + return NS_OK; } nsresult @@ -747,13 +751,13 @@ nsHttpChannel::CallOnStartRequest() if (mResponseHead) SetPropertyAsInt64(NS_CHANNEL_PROP_CONTENT_LENGTH, mResponseHead->ContentLength()); - + LOG((" calling mListener->OnStartRequest\n")); nsresult rv = mListener->OnStartRequest(this, mListenerContext); if (NS_FAILED(rv)) return rv; // install stream converter if required - ApplyContentConversions(); + rv = ApplyContentConversions(); return rv; } diff --git a/mozilla/netwerk/protocol/http/src/nsHttpChannel.h b/mozilla/netwerk/protocol/http/src/nsHttpChannel.h index 1145884fbc0..549a56908f8 100644 --- a/mozilla/netwerk/protocol/http/src/nsHttpChannel.h +++ b/mozilla/netwerk/protocol/http/src/nsHttpChannel.h @@ -151,7 +151,7 @@ private: nsresult AsyncAbort(nsresult status); nsresult SetupTransaction(); void AddCookiesToRequest(); - void ApplyContentConversions(); + nsresult ApplyContentConversions(); nsresult CallOnStartRequest(); nsresult ProcessResponse(); nsresult ProcessNormal(); diff --git a/mozilla/netwerk/streamconv/converters/nsHTTPCompressConv.cpp b/mozilla/netwerk/streamconv/converters/nsHTTPCompressConv.cpp index f40fd46f969..624f64a74e8 100644 --- a/mozilla/netwerk/streamconv/converters/nsHTTPCompressConv.cpp +++ b/mozilla/netwerk/streamconv/converters/nsHTTPCompressConv.cpp @@ -46,6 +46,7 @@ #include "nsReadableUtils.h" #include "nsIByteArrayInputStream.h" #include "nsIStringStream.h" +#include "nsNetError.h" static NS_METHOD DiscardSegments(nsIInputStream *input, @@ -141,7 +142,7 @@ nsHTTPCompressConv::OnDataAvailable(nsIRequest* request, PRUint32 aSourceOffset, PRUint32 aCount) { - nsresult rv = NS_ERROR_FAILURE; + nsresult rv = NS_ERROR_INVALID_CONTENT_ENCODING; PRUint32 streamLen = aCount; if (streamLen == 0) @@ -272,7 +273,7 @@ nsHTTPCompressConv::OnDataAvailable(nsIRequest* request, // stop an endless loop caused by non-deflate data being labelled as deflate if (mDummyStreamInitialised) { NS_ERROR("endless loop detected"); - return NS_ERROR_FAILURE; + return NS_ERROR_INVALID_CONTENT_ENCODING; } mDummyStreamInitialised = PR_TRUE; // reset stream pointers to our original data @@ -280,7 +281,7 @@ nsHTTPCompressConv::OnDataAvailable(nsIRequest* request, d_stream.avail_in = (uInt)streamLen; } else - return NS_ERROR_FAILURE; + return NS_ERROR_INVALID_CONTENT_ENCODING; } /* for */ } else @@ -339,7 +340,7 @@ nsHTTPCompressConv::OnDataAvailable(nsIRequest* request, break; } else - return NS_ERROR_FAILURE; + return NS_ERROR_INVALID_CONTENT_ENCODING; } /* for */ } /* gzip */ break; @@ -421,19 +422,19 @@ nsHTTPCompressConv::check_header(nsIInputStream *iStr, PRUint32 streamLen, nsres if (mSkipCount == 0 && ((unsigned)c & 0377) != gz_magic[0]) { - *rs = NS_ERROR_FAILURE; + *rs = NS_ERROR_INVALID_CONTENT_ENCODING; return 0; } if (mSkipCount == 1 && ((unsigned)c & 0377) != gz_magic[1]) { - *rs = NS_ERROR_FAILURE; + *rs = NS_ERROR_INVALID_CONTENT_ENCODING; return 0; } if (mSkipCount == 2 && ((unsigned)c & 0377) != Z_DEFLATED) { - *rs = NS_ERROR_FAILURE; + *rs = NS_ERROR_INVALID_CONTENT_ENCODING; return 0; } @@ -443,7 +444,7 @@ nsHTTPCompressConv::check_header(nsIInputStream *iStr, PRUint32 streamLen, nsres mFlags = (unsigned) c & 0377; if (mFlags & RESERVED) { - *rs = NS_ERROR_FAILURE; + *rs = NS_ERROR_INVALID_CONTENT_ENCODING; return 0; } hMode = GZIP_OS;