From 4f88d7ef1ab617e0dceb7e56f4aa2478a46d7db3 Mon Sep 17 00:00:00 2001 From: "locka%iol.ie" Date: Thu, 11 Jul 2002 20:59:03 +0000 Subject: [PATCH] Support for error pages. b=28586 r=radha@netscape.com sr=rpotts@netscape.com a=asa@mozilla.org git-svn-id: svn://10.0.0.236/trunk@125030 18797224-902f-48f8-a5cc-f745e15eee43 --- .../mac/build_scripts/MozillaBuildList.pm | 2 + mozilla/docshell/Makefile.in | 2 +- mozilla/docshell/base/appstrings.properties | 8 +- mozilla/docshell/base/jar.mn | 1 - mozilla/docshell/base/nsDocShell.cpp | 240 +++++++++++++++--- mozilla/docshell/base/nsDocShell.h | 3 + mozilla/docshell/base/nsWebShell.cpp | 194 +++----------- mozilla/docshell/makefile.win | 2 +- mozilla/docshell/resources/Makefile.in | 30 +++ .../docshell/resources/content/Makefile.in | 30 +++ mozilla/docshell/resources/content/jar.mn | 3 + .../docshell/resources/content/makefile.win | 26 ++ .../docshell/resources/content/netError.js | 80 ++++++ .../docshell/resources/content/netError.xhtml | 78 ++++++ mozilla/docshell/resources/locale/Makefile.in | 30 +++ .../resources/locale/en-US/Makefile.in | 29 +++ .../docshell/resources/locale/en-US/jar.mn | 2 + .../resources/locale/en-US/makefile.win | 26 ++ .../resources/locale/en-US/netError.dtd | 35 +++ .../docshell/resources/locale/makefile.win | 26 ++ mozilla/docshell/resources/makefile.win | 26 ++ 21 files changed, 667 insertions(+), 206 deletions(-) create mode 100644 mozilla/docshell/resources/Makefile.in create mode 100644 mozilla/docshell/resources/content/Makefile.in create mode 100644 mozilla/docshell/resources/content/jar.mn create mode 100644 mozilla/docshell/resources/content/makefile.win create mode 100644 mozilla/docshell/resources/content/netError.js create mode 100644 mozilla/docshell/resources/content/netError.xhtml create mode 100644 mozilla/docshell/resources/locale/Makefile.in create mode 100644 mozilla/docshell/resources/locale/en-US/Makefile.in create mode 100644 mozilla/docshell/resources/locale/en-US/jar.mn create mode 100644 mozilla/docshell/resources/locale/en-US/makefile.win create mode 100644 mozilla/docshell/resources/locale/en-US/netError.dtd create mode 100644 mozilla/docshell/resources/locale/makefile.win create mode 100644 mozilla/docshell/resources/makefile.win diff --git a/mozilla/build/mac/build_scripts/MozillaBuildList.pm b/mozilla/build/mac/build_scripts/MozillaBuildList.pm index 9eaf47ab86a..0df9fbb7778 100644 --- a/mozilla/build/mac/build_scripts/MozillaBuildList.pm +++ b/mozilla/build/mac/build_scripts/MozillaBuildList.pm @@ -572,6 +572,8 @@ sub ProcessJarManifests() CreateJarFromManifest(":mozilla:caps:src:jar.mn", $chrome_dir, \%jars); CreateJarFromManifest(":mozilla:content:html:style:src:jar.mn", $chrome_dir, \%jars); CreateJarFromManifest(":mozilla:docshell:base:jar.mn", $chrome_dir, \%jars); + CreateJarFromManifest(":mozilla:docshell:resources:content:jar.mn", $chrome_dir, \%jars); + CreateJarFromManifest(":mozilla:docshell:resources:locale:en-US:jar.mn", $chrome_dir, \%jars); CreateJarFromManifest(":mozilla:editor:jar.mn", $chrome_dir, \%jars); CreateJarFromManifest(":mozilla:embedding:browser:chrome:jar.mn", $chrome_dir, \%jars); CreateJarFromManifest(":mozilla:embedding:browser:chrome:locale:en-US:jar.mn", $chrome_dir, \%jars); diff --git a/mozilla/docshell/Makefile.in b/mozilla/docshell/Makefile.in index b6ab27a87e8..eaf7028c20c 100644 --- a/mozilla/docshell/Makefile.in +++ b/mozilla/docshell/Makefile.in @@ -25,6 +25,6 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk -DIRS=base build +DIRS=base build resources include $(topsrcdir)/config/rules.mk diff --git a/mozilla/docshell/base/appstrings.properties b/mozilla/docshell/base/appstrings.properties index c3d4a07f92b..dd5ff6c2027 100644 --- a/mozilla/docshell/base/appstrings.properties +++ b/mozilla/docshell/base/appstrings.properties @@ -18,11 +18,11 @@ # Contributor(s): malformedURI=The URL is not valid and cannot be loaded. -fileNotFound=The file %s cannot be found. Please check the location and try again. -dnsNotFound=%s could not be found. Please check the name and try again. +fileNotFound=The file %S cannot be found. Please check the location and try again. +dnsNotFound=%S could not be found. Please check the name and try again. protocolNotFound=%S is not a registered protocol. -connectionFailure=The connection was refused when attempting to contact %s. -netTimeout=The operation timed out when attempting to contact %s. +connectionFailure=The connection was refused when attempting to contact %S. +netTimeout=The operation timed out when attempting to contact %S. redirectLoop=Redirection limit for this URL exceeded. Unable to load the requested page. repost=The page you are trying to view contains POSTDATA that has expired from cache. If you resend the data, any action the form carried out (such as a search or online purchase) will be repeated. To resend the data, click OK. Otherwise, click Cancel. repostConfirm=The page you are trying to view contains POSTDATA. If you resend the data, any action the form carried out (such as a search or online purchase) will be repeated. To resend the data, click OK. Otherwise, click Cancel. diff --git a/mozilla/docshell/base/jar.mn b/mozilla/docshell/base/jar.mn index 9f6e3b4b96a..3e4e0224318 100644 --- a/mozilla/docshell/base/jar.mn +++ b/mozilla/docshell/base/jar.mn @@ -1,3 +1,2 @@ en-US.jar: locale/en-US/global/appstrings.properties - diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index e6459de95ea..099b57f544a 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -81,6 +81,11 @@ #include "nsISHistoryListener.h" #include "nsIDirectoryListing.h" +// Pull in various NS_ERROR_* definitions +#include "nsIDNSService.h" +#include "nsISocketTransportService.h" +#include "nsISocketProvider.h" + // Editor-related #include "nsIEditingSession.h" @@ -109,6 +114,7 @@ #include "nsITextToSubURI.h" #include "prlog.h" +#include "prmem.h" #include "nsISelectionDisplay.h" @@ -209,6 +215,7 @@ nsDocShell::nsDocShell(): mUseExternalProtocolHandler(PR_FALSE), mDisallowPopupWindows(PR_FALSE), mIsBeingDestroyed(PR_FALSE), + mUseErrorPages(PR_FALSE), mParent(nsnull), mTreeOwner(nsnull), mChromeEventHandler(nsnull) @@ -1208,7 +1215,7 @@ nsDocShell::SetCurrentURI(nsIURI *aURI) { mCurrentURI = aURI; //This assignment addrefs PRBool isRoot = PR_FALSE; // Is this the root docshell - PRBool isSubFrame=PR_FALSE; // Is this a subframe navigation? + PRBool isSubFrame = PR_FALSE; // Is this a subframe navigation? if (!mLoadCookie) return NS_OK; @@ -1241,7 +1248,6 @@ nsDocShell::SetCurrentURI(nsIURI *aURI) return NS_OK; } - NS_ASSERTION(loader, "No document loader"); if (loader) { loader->FireOnLocationChange(webProgress, nsnull, aURI); @@ -2343,43 +2349,8 @@ nsDocShell::LoadURI(const PRUnichar * aURI, if (NS_ERROR_UNKNOWN_PROTOCOL == rv || NS_ERROR_MALFORMED_URI == rv) { - // we weren't able to find a protocol handler - nsCOMPtr prompter; - nsCOMPtr stringBundle; - GetPromptAndStringBundle(getter_AddRefs(prompter), - getter_AddRefs(stringBundle)); - - NS_ENSURE_TRUE(stringBundle, NS_ERROR_FAILURE); - - nsXPIDLString messageStr; - nsresult strerror; - - if (NS_ERROR_UNKNOWN_PROTOCOL == rv) { - const nsAutoString uriString(aURI); - PRInt32 colon = uriString.FindChar(':'); - // extract the scheme - nsAutoString scheme; - uriString.Left(scheme, colon); - - const PRUnichar* formatStrs[] = { scheme.get() }; - - strerror = - stringBundle->FormatStringFromName(NS_LITERAL_STRING("protocolNotFound").get(), - formatStrs, - 1, - getter_Copies(messageStr)); - } - else { - // NS_ERROR_MALFORMED_URI - strerror = - stringBundle->GetStringFromName(NS_LITERAL_STRING("malformedURI").get(), - getter_Copies(messageStr)); - } - - // now we have the string - NS_ENSURE_SUCCESS(strerror, NS_ERROR_FAILURE); - prompter->Alert(nsnull, messageStr); - } // end unknown protocol + DisplayLoadError(rv, uri, aURI); + } // end unknown protocol if (NS_FAILED(rv) || !uri) return NS_ERROR_FAILURE; @@ -2399,6 +2370,187 @@ nsDocShell::LoadURI(const PRUnichar * aURI, return rv; } +NS_IMETHODIMP +nsDocShell::DisplayLoadError(nsresult aError, nsIURI *aURI, const PRUnichar *aURL) +{ + // Get prompt and string bundle servcies + nsCOMPtr prompter; + nsCOMPtr stringBundle; + GetPromptAndStringBundle(getter_AddRefs(prompter), + getter_AddRefs(stringBundle)); + + NS_ENSURE_TRUE(stringBundle, NS_ERROR_FAILURE); + NS_ENSURE_TRUE(prompter, NS_ERROR_FAILURE); + + nsAutoString error; + const PRUint32 kMaxFormatStrArgs = 2; + nsAutoString formatStrs[kMaxFormatStrArgs]; + PRUint32 formatStrCount = 0; + nsresult rv = NS_OK; + + // Turn the error code into a human readable error message. + if (NS_ERROR_UNKNOWN_PROTOCOL == aError) { + NS_ENSURE_ARG_POINTER(aURL); + const nsAutoString uriString(aURL); + PRInt32 colon = uriString.FindChar(':'); + // extract the scheme + nsAutoString scheme; + uriString.Left(scheme, colon); + formatStrs[0].Assign(scheme.get()); + formatStrCount = 1; + error.Assign(NS_LITERAL_STRING("protocolNotFound")); + } + else if (NS_ERROR_FILE_NOT_FOUND == aError) { + NS_ENSURE_ARG_POINTER(aURI); + nsCAutoString spec; + aURI->GetPath(spec); + formatStrs[0].AssignWithConversion(spec.get()); + formatStrCount = 1; + error.Assign(NS_LITERAL_STRING("fileNotFound")); + } + else if (NS_ERROR_UNKNOWN_HOST == aError) { + NS_ENSURE_ARG_POINTER(aURI); + // Get the host + nsCAutoString host; + aURI->GetHost(host); + formatStrs[0].AssignWithConversion(host.get()); + formatStrCount = 1; + error.Assign(NS_LITERAL_STRING("dnsNotFound")); + } + else if(NS_ERROR_CONNECTION_REFUSED == aError) { + NS_ENSURE_ARG_POINTER(aURI); + // Build up the host:port string. + nsCAutoString hostport; + aURI->GetHostPort(hostport); + formatStrs[0].AssignWithConversion(hostport.get()); + formatStrCount = 1; + error.Assign(NS_LITERAL_STRING("connectionFailure")); + } + else if (NS_ERROR_NET_TIMEOUT == aError) { + NS_ENSURE_ARG_POINTER(aURI); + // Get the host + nsCAutoString host; + aURI->GetHost(host); + formatStrs[0].AssignWithConversion(host.get()); + formatStrCount = 1; + error.Assign(NS_LITERAL_STRING("netTimeout")); + } + else { + // Errors requiring simple formatting + switch (aError) { + case NS_ERROR_MALFORMED_URI: + // URI is malformed + error.Assign(NS_LITERAL_STRING("malformedURI")); + break; + case NS_ERROR_REDIRECT_LOOP: + // Doc failed to load because the server generated too many redirects + error.Assign(NS_LITERAL_STRING("redirectLoop")); + break; + case NS_ERROR_UNKNOWN_SOCKET_TYPE: + // Doc failed to load because PSM is not installed + error.Assign(NS_LITERAL_STRING("unknownSocketType")); + break; + case NS_ERROR_NET_RESET: + // Doc failed to load because the server kept reseting the connection + // before we could read any data from it + error.Assign(NS_LITERAL_STRING("netReset")); + break; + } + } + + // Test if the error should be displayed + if (error.IsEmpty()) { + return NS_OK; + } + + // Test if the error needs to be formatted + nsAutoString messageStr; + if (formatStrCount > 0) { + const PRUnichar *strs[kMaxFormatStrArgs]; + for (PRUint32 i = 0; i < formatStrCount; i++) { + strs[i] = formatStrs[i].get(); + } + nsXPIDLString str; + rv = stringBundle->FormatStringFromName( + error.get(), + strs, formatStrCount, getter_Copies(str)); + NS_ENSURE_SUCCESS(rv, rv); + messageStr.Assign(str.get()); + } + else + { + nsXPIDLString str; + rv = stringBundle->GetStringFromName( + error.get(), + getter_Copies(str)); + NS_ENSURE_SUCCESS(rv, rv); + messageStr.Assign(str.get()); + } + + // Display the error as a page or an alert prompt + NS_ENSURE_FALSE(messageStr.IsEmpty(), NS_ERROR_FAILURE); + if (mUseErrorPages) { + // Display an error page + LoadErrorPage(aURI, aURL, error.get(), messageStr.get()); + } + else + { + // Display a message box + prompter->Alert(nsnull, messageStr.get()); + } + + return NS_OK; +} + + +NS_IMETHODIMP +nsDocShell::LoadErrorPage(nsIURI *aURI, const PRUnichar *aURL, const PRUnichar *aErrorType, const PRUnichar *aDescription) +{ + nsAutoString url; + if (aURI) + { + nsCAutoString uri; + nsresult rv = aURI->GetSpec(uri); + NS_ENSURE_SUCCESS(rv, rv); + url.AssignWithConversion(uri.get()); + } + else if (aURL) + { + url.Assign(aURL); + } + else + { + return NS_ERROR_INVALID_POINTER; + } + + // Create a URL to pass all the error information through to the page. + + char *escapedUrl = nsEscape(NS_ConvertUCS2toUTF8(url.get()).get(), url_Path); + char *escapedError = nsEscape(NS_ConvertUCS2toUTF8(aErrorType).get(), url_Path); + char *escapedDescription = nsEscape(NS_ConvertUCS2toUTF8(aDescription).get(), url_Path); + + nsAutoString errorType(aErrorType); + nsAutoString errorPageUrl; + + errorPageUrl.Assign(NS_LITERAL_STRING("chrome://global/content/netError.xhtml?e=")); + errorPageUrl.AppendWithConversion(escapedError); + errorPageUrl.Append(NS_LITERAL_STRING("&u=")); + errorPageUrl.AppendWithConversion(escapedUrl); + errorPageUrl.Append(NS_LITERAL_STRING("&d=")); + errorPageUrl.AppendWithConversion(escapedDescription); + + PR_FREEIF(escapedDescription); + PR_FREEIF(escapedError); + PR_FREEIF(escapedUrl); + + return LoadURI(errorPageUrl.get(), // URI string + LOAD_FLAGS_BYPASS_HISTORY | LOAD_RELOAD_BYPASS_CACHE, + nsnull, + nsnull, + nsnull); +} + + NS_IMETHODIMP nsDocShell::Reload(PRUint32 aReloadFlags) { @@ -2413,7 +2565,6 @@ nsDocShell::Reload(PRUint32 aReloadFlags) type = LOAD_RELOAD_BYPASS_PROXY_AND_CACHE; else if (aReloadFlags & LOAD_FLAGS_CHARSET_CHANGE) type = LOAD_RELOAD_CHARSET_CHANGE; - // Send notifications to the HistoryListener if any, about the impending reload nsCOMPtr rootSH; rv = GetRootSessionHistory(getter_AddRefs(rootSH)); @@ -2665,7 +2816,9 @@ nsDocShell::InitWindow(nativeWindow parentNativeWindow, NS_IMETHODIMP nsDocShell::Create() { - mPrefs = do_GetService(NS_PREF_CONTRACTID); + nsresult rv = NS_ERROR_FAILURE; + mPrefs = do_GetService(NS_PREF_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); //GlobalHistory is now set in SetGlobalHistory // mGlobalHistory = do_GetService(NS_GLOBALHISTORY_CONTRACTID); @@ -2679,6 +2832,11 @@ nsDocShell::Create() // Check pref to see if we should prevent frameset spoofing mPrefs->GetBoolPref("browser.frame.validate_origin", &mValidateOrigin); + // Should we use XUL error pages instead of alerts if possible? + PRBool useErrorPages = PR_FALSE; + mPrefs->GetBoolPref("browser.xul.error_pages.enabled", &useErrorPages); + mUseErrorPages = useErrorPages; + return NS_OK; } diff --git a/mozilla/docshell/base/nsDocShell.h b/mozilla/docshell/base/nsDocShell.h index 6d515c46393..cf10e63b485 100644 --- a/mozilla/docshell/base/nsDocShell.h +++ b/mozilla/docshell/base/nsDocShell.h @@ -251,6 +251,8 @@ protected: NS_IMETHOD EnsureEditorData(); NS_IMETHOD EnsureFind(); NS_IMETHOD RefreshURIFromQueue(); + NS_IMETHOD DisplayLoadError(nsresult aError, nsIURI *aURI, const PRUnichar *aURL); + NS_IMETHOD LoadErrorPage(nsIURI *aURI, const PRUnichar *aURL, const PRUnichar *aPage, const PRUnichar *aDescription); static inline PRUint32 PRTimeToSeconds(PRTime t_usec) @@ -315,6 +317,7 @@ protected: PRPackedBool mFocusDocFirst; PRPackedBool mHasFocus; PRPackedBool mCreatingDocument; // (should be) debugging only + PRPackedBool mUseErrorPages; PRUint32 mAppType; PRInt32 mChildOffset; // Offset in the parent's child list. diff --git a/mozilla/docshell/base/nsWebShell.cpp b/mozilla/docshell/base/nsWebShell.cpp index 1b29fc7e680..c2f0bf2a1db 100644 --- a/mozilla/docshell/base/nsWebShell.cpp +++ b/mozilla/docshell/base/nsWebShell.cpp @@ -717,6 +717,15 @@ nsresult nsWebShell::EndPageLoad(nsIWebProgress *aProgress, nsCOMPtr kungFuDeathGrip(this); nsDocShell::EndPageLoad(aProgress, channel, aStatus); + // Test if this is the top frame or a subframe + PRBool isTopFrame = PR_TRUE; + nsCOMPtr targetParentTreeItem; + rv = GetSameTypeParent(getter_AddRefs(targetParentTreeItem)); + if (NS_SUCCEEDED(rv) && targetParentTreeItem) + { + isTopFrame = PR_FALSE; + } + // // If the page load failed, then deal with the error condition... // Errors are handled as follows: @@ -729,26 +738,7 @@ nsresult nsWebShell::EndPageLoad(nsIWebProgress *aProgress, if(url && NS_FAILED(aStatus)) { if (aStatus == NS_ERROR_FILE_NOT_FOUND) { - nsCOMPtr prompter; - nsCOMPtr stringBundle; - GetPromptAndStringBundle(getter_AddRefs(prompter), - getter_AddRefs(stringBundle)); - if (stringBundle && prompter) { - nsXPIDLString messageStr; - nsresult rv = stringBundle->GetStringFromName(NS_LITERAL_STRING("fileNotFound").get(), - getter_Copies(messageStr)); - - if (NS_SUCCEEDED(rv) && messageStr) { - nsCAutoString spec; - url->GetPath(spec); - - PRUnichar *msg = nsTextFormatter::smprintf(messageStr, spec.get()); - if (!msg) return NS_ERROR_OUT_OF_MEMORY; - - prompter->Alert(nsnull, msg); - nsTextFormatter::smprintf_free(msg); - } - } + DisplayLoadError(aStatus, url, nsnull); return NS_OK; } @@ -821,32 +811,28 @@ nsresult nsWebShell::EndPageLoad(nsIWebProgress *aProgress, if (aStatus == NS_ERROR_UNKNOWN_HOST || aStatus == NS_ERROR_NET_RESET) { - // Test if keyword lookup produced a new URI or not PRBool doCreateAlternate = PR_TRUE; - if (newURI) - { - PRBool sameURI = PR_FALSE; - url->Equals(newURI, &sameURI); - if (!sameURI) - { - // Keyword lookup made a new URI so no need to try an - // alternate one. - doCreateAlternate = PR_FALSE; - } - } - // Skip fixup for anything except a normal document load operation - if (mLoadType != LOAD_NORMAL) + + // Skip fixup for anything except a normal document load operation on + // the topframe. + + if (mLoadType != LOAD_NORMAL || !isTopFrame) { doCreateAlternate = PR_FALSE; } else { - // Skip fixup for frames & iframes - nsCOMPtr targetParentTreeItem; - rv = GetSameTypeParent(getter_AddRefs(targetParentTreeItem)); - if (NS_SUCCEEDED(rv) && targetParentTreeItem) + // Test if keyword lookup produced a new URI or not + if (newURI) { - doCreateAlternate = PR_FALSE; + PRBool sameURI = PR_FALSE; + url->Equals(newURI, &sameURI); + if (!sameURI) + { + // Keyword lookup made a new URI so no need to try an + // alternate one. + doCreateAlternate = PR_FALSE; + } } } if (doCreateAlternate) @@ -890,89 +876,19 @@ nsresult nsWebShell::EndPageLoad(nsIWebProgress *aProgress, // It is time to throw an error dialog box, and be done with it... // - // Doc failed to load because the host was not found. - if(aStatus == NS_ERROR_UNKNOWN_HOST) { - // throw a DNS failure dialog - nsCOMPtr prompter; - nsCOMPtr stringBundle; - - rv = GetPromptAndStringBundle(getter_AddRefs(prompter), - getter_AddRefs(stringBundle)); - if (!stringBundle) { - return rv; - } - - nsXPIDLString messageStr; - rv = stringBundle->GetStringFromName(NS_LITERAL_STRING("dnsNotFound").get(), - getter_Copies(messageStr)); - if (NS_FAILED(rv)) return rv; - - nsCAutoString host; - url->GetHost(host); - if (!host.IsEmpty()) { - PRUnichar *msg = nsTextFormatter::smprintf(messageStr, host.get()); - if (!msg) return NS_ERROR_OUT_OF_MEMORY; - - prompter->Alert(nsnull, msg); - nsTextFormatter::smprintf_free(msg); - } + // Errors to be shown only on top-level frames + if ((aStatus == NS_ERROR_UNKNOWN_HOST || + aStatus == NS_ERROR_CONNECTION_REFUSED) && + (isTopFrame || mUseErrorPages)) { + DisplayLoadError(aStatus, url, nsnull); } - // - // Doc failed to load because we couldn't connect to the server. - // throw a connection failure dialog - // - else if(aStatus == NS_ERROR_CONNECTION_REFUSED) { - nsCOMPtr prompter; - nsCOMPtr stringBundle; - - rv = GetPromptAndStringBundle(getter_AddRefs(prompter), - getter_AddRefs(stringBundle)); - if (!stringBundle) { - return rv; - } - - nsXPIDLString messageStr; - rv = stringBundle->GetStringFromName(NS_LITERAL_STRING("connectionFailure").get(), - getter_Copies(messageStr)); - if (NS_FAILED(rv)) return rv; - - // build up the host:port string. - nsCAutoString hostport; - url->GetHostPort(hostport); - - PRUnichar *msg = nsTextFormatter::smprintf(messageStr, hostport.get()); - if (!msg) return NS_ERROR_OUT_OF_MEMORY; - - prompter->Alert(nsnull, msg); - nsTextFormatter::smprintf_free(msg); + // Errors to be shown for any frame + else if (aStatus == NS_ERROR_NET_TIMEOUT || + aStatus == NS_ERROR_REDIRECT_LOOP || + aStatus == NS_ERROR_UNKNOWN_SOCKET_TYPE || + aStatus == NS_ERROR_NET_RESET) { + DisplayLoadError(aStatus, url, nsnull); } - // - // Doc failed to load because the socket function timed out. - // throw a timeout dialog - // - else if(aStatus == NS_ERROR_NET_TIMEOUT) { - nsCOMPtr prompter; - nsCOMPtr stringBundle; - - rv = GetPromptAndStringBundle(getter_AddRefs(prompter), - getter_AddRefs(stringBundle)); - if (!stringBundle) { - return rv; - } - - nsXPIDLString messageStr; - rv = stringBundle->GetStringFromName(NS_LITERAL_STRING("netTimeout").get(), - getter_Copies(messageStr)); - if (NS_FAILED(rv)) return rv; - - nsCAutoString host; - url->GetHost(host); - PRUnichar *msg = nsTextFormatter::smprintf(messageStr, host.get()); - if (!msg) return NS_ERROR_OUT_OF_MEMORY; - - prompter->Alert(nsnull, msg); - nsTextFormatter::smprintf_free(msg); - } // end NS_ERROR_NET_TIMEOUT else if (aStatus == NS_ERROR_DOCUMENT_NOT_CACHED) { /* A document that was requested to be fetched *only* from * the cache is not in cache. May be this is one of those @@ -1059,44 +975,6 @@ nsresult nsWebShell::EndPageLoad(nsIWebProgress *aProgress, } } } - else { - // - // handle errors that have simple messages w/ no arguments. - // - const char *errorStr = nsnull; - switch (aStatus) { - case NS_ERROR_REDIRECT_LOOP: - // Doc failed to load because the server generated too many redirects - errorStr = "redirectLoop"; - break; - case NS_ERROR_UNKNOWN_SOCKET_TYPE: - // Doc failed to load because PSM is not installed - errorStr = "unknownSocketType"; - break; - case NS_ERROR_NET_RESET: - // Doc failed to load because the server kept reseting the connection - // before we could read any data from it - errorStr = "netReset"; - break; - } - if (errorStr) { - nsCOMPtr prompter; - nsCOMPtr stringBundle; - - rv = GetPromptAndStringBundle(getter_AddRefs(prompter), - getter_AddRefs(stringBundle)); - if (!stringBundle) { - return rv; - } - - nsXPIDLString messageStr; - rv = stringBundle->GetStringFromName(NS_ConvertASCIItoUCS2(errorStr).get(), - getter_Copies(messageStr)); - if (NS_FAILED(rv)) return rv; - - prompter->Alert(nsnull, messageStr); - } - } } // if we have a host return NS_OK; diff --git a/mozilla/docshell/makefile.win b/mozilla/docshell/makefile.win index c4c04f8fcd2..af5605ac685 100644 --- a/mozilla/docshell/makefile.win +++ b/mozilla/docshell/makefile.win @@ -21,6 +21,6 @@ DEPTH=.. -DIRS=base build +DIRS=base build resources include <$(DEPTH)\config\rules.mak> diff --git a/mozilla/docshell/resources/Makefile.in b/mozilla/docshell/resources/Makefile.in new file mode 100644 index 00000000000..7f6333084a8 --- /dev/null +++ b/mozilla/docshell/resources/Makefile.in @@ -0,0 +1,30 @@ +# +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is the Mozilla browser. +# +# The Initial Developer of the Original Code is Netscape +# Communications, Inc. Portions created by Netscape are +# Copyright (C) 1999, Mozilla. All Rights Reserved. +# +# Contributor(s): +# Adam Lock + +DEPTH = ../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +DIRS=locale content + +include $(topsrcdir)/config/rules.mk diff --git a/mozilla/docshell/resources/content/Makefile.in b/mozilla/docshell/resources/content/Makefile.in new file mode 100644 index 00000000000..08ef0f3f1fc --- /dev/null +++ b/mozilla/docshell/resources/content/Makefile.in @@ -0,0 +1,30 @@ +# +# The contents of this file are subject to the Netscape Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/NPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): +# Adam Lock +# + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk +include $(topsrcdir)/config/rules.mk + diff --git a/mozilla/docshell/resources/content/jar.mn b/mozilla/docshell/resources/content/jar.mn new file mode 100644 index 00000000000..58fed605d4e --- /dev/null +++ b/mozilla/docshell/resources/content/jar.mn @@ -0,0 +1,3 @@ +toolkit.jar: + content/global/netError.xhtml + content/global/netError.js diff --git a/mozilla/docshell/resources/content/makefile.win b/mozilla/docshell/resources/content/makefile.win new file mode 100644 index 00000000000..c052917ad5b --- /dev/null +++ b/mozilla/docshell/resources/content/makefile.win @@ -0,0 +1,26 @@ +#!nmake +# +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 2001 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): +# Adam Lock + +DEPTH=..\..\.. + +include <$(DEPTH)\config\rules.mak> + diff --git a/mozilla/docshell/resources/content/netError.js b/mozilla/docshell/resources/content/netError.js new file mode 100644 index 00000000000..3d0b9ee45a0 --- /dev/null +++ b/mozilla/docshell/resources/content/netError.js @@ -0,0 +1,80 @@ +// Error url MUST be formatted like this: +// chrome://neterror.xhtml?e=error&u=url&d=desc + +function getErrorCode() +{ + url = document.location.href; + error = url.search(/e\=/); + duffUrl = url.search(/\&u\=/); + return unescape(url.slice(error + 2, duffUrl)); +} + +function getDuffUrl() +{ + url = document.location.href; + duffUrl = url.search(/u\=/); + desc = url.search(/\&d\=/); + return unescape(url.slice(duffUrl + 2, desc)); +} + +function getDescription() +{ + url = document.location.href; + desc = url.search(/d\=/); + return unescape(url.slice(desc + 2)); +} + +function retryThis() +{ + var duffUrl = getDuffUrl(); + document.location.href = duffUrl; +} + +function searchThis() +{ + searchForThis(getDuffUrl()); +} + +function searchForThis(url) +{ + document.location.href = "http://www.google.com/search?q=" + url; +} + +function fillIn() +{ + var err = getErrorCode(); + var duffUrl = getDuffUrl(); + var i; + + // Fill in the title + var titleText = "&" + err + ".title;"; + document.title = titleText; + +// document.getElementById("title").innerHTML = "

bbb

"; + +// for (i = 0; i < t.childNodes.length; i++) +// { +// var n = t.childNodes.item(i); +// if (n.nodeType == Node.TEXT_NODE) +// { +// n.nodeValue = titleText; +// break; +// } +// } + + // Fill in the short description + var sd = document.getElementById("shortDesc"); + for (i = 0; i < sd.childNodes.length; i++) + { + var n = sd.childNodes.item(i); + if (n.nodeType == Node.TEXT_NODE) + { + n.nodeValue = getDescription(); + break; + } + } + + // Long description + var d = document.getElementById(err); + d.setAttribute("style", "display: block;"); +} diff --git a/mozilla/docshell/resources/content/netError.xhtml b/mozilla/docshell/resources/content/netError.xhtml new file mode 100644 index 00000000000..1e8dc3055e9 --- /dev/null +++ b/mozilla/docshell/resources/content/netError.xhtml @@ -0,0 +1,78 @@ + + + + %htmlDTD; + + %netErrorDTD; +]> + + + + + + + + + + + +
+

+
+ +

+ + + + + + + + + + +

&retry.label;

+

&search.label;

+ + + \ No newline at end of file diff --git a/mozilla/docshell/resources/locale/Makefile.in b/mozilla/docshell/resources/locale/Makefile.in new file mode 100644 index 00000000000..730d266a532 --- /dev/null +++ b/mozilla/docshell/resources/locale/Makefile.in @@ -0,0 +1,30 @@ +# +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is the Mozilla browser. +# +# The Initial Developer of the Original Code is Netscape +# Communications, Inc. Portions created by Netscape are +# Copyright (C) 1999, Mozilla. All Rights Reserved. +# +# Contributor(s): +# Adam Lock + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +DIRS=en-US + +include $(topsrcdir)/config/rules.mk diff --git a/mozilla/docshell/resources/locale/en-US/Makefile.in b/mozilla/docshell/resources/locale/en-US/Makefile.in new file mode 100644 index 00000000000..2aa07dd6e48 --- /dev/null +++ b/mozilla/docshell/resources/locale/en-US/Makefile.in @@ -0,0 +1,29 @@ +# +# The contents of this file are subject to the Netscape Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/NPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): +# Adam Lock + +DEPTH = ../../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk +include $(topsrcdir)/config/rules.mk + diff --git a/mozilla/docshell/resources/locale/en-US/jar.mn b/mozilla/docshell/resources/locale/en-US/jar.mn new file mode 100644 index 00000000000..e2336019506 --- /dev/null +++ b/mozilla/docshell/resources/locale/en-US/jar.mn @@ -0,0 +1,2 @@ +en-US.jar: + locale/en-US/global/netError.dtd diff --git a/mozilla/docshell/resources/locale/en-US/makefile.win b/mozilla/docshell/resources/locale/en-US/makefile.win new file mode 100644 index 00000000000..a0f04a5ac0d --- /dev/null +++ b/mozilla/docshell/resources/locale/en-US/makefile.win @@ -0,0 +1,26 @@ +#!nmake +# +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 2001 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): +# Adam Lock + +DEPTH=..\..\..\.. + +include <$(DEPTH)\config\rules.mak> + diff --git a/mozilla/docshell/resources/locale/en-US/netError.dtd b/mozilla/docshell/resources/locale/en-US/netError.dtd new file mode 100644 index 00000000000..6f768f6d38e --- /dev/null +++ b/mozilla/docshell/resources/locale/en-US/netError.dtd @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mozilla/docshell/resources/locale/makefile.win b/mozilla/docshell/resources/locale/makefile.win new file mode 100644 index 00000000000..e044a80f8d1 --- /dev/null +++ b/mozilla/docshell/resources/locale/makefile.win @@ -0,0 +1,26 @@ +#!nmake +# +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is the Mozilla browser. +# +# The Initial Developer of the Original Code is Netscape +# Communications, Inc. Portions created by Netscape are +# Copyright (C) 1999, Mozilla. All Rights Reserved. +# +# Contributor(s): +# Adam Lock + +DEPTH=..\..\.. + +DIRS=en-US + +include <$(DEPTH)\config\rules.mak> diff --git a/mozilla/docshell/resources/makefile.win b/mozilla/docshell/resources/makefile.win new file mode 100644 index 00000000000..50123b448ac --- /dev/null +++ b/mozilla/docshell/resources/makefile.win @@ -0,0 +1,26 @@ +#!nmake +# +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is the Mozilla browser. +# +# The Initial Developer of the Original Code is Netscape +# Communications, Inc. Portions created by Netscape are +# Copyright (C) 1999, Mozilla. All Rights Reserved. +# +# Contributor(s): +# Adam Lock + +DEPTH=..\.. + +DIRS=locale content + +include <$(DEPTH)\config\rules.mak>