backing out bug 393246 for final to resolve bug 432836, a=schrep

This commit is contained in:
mconnor@steelgryphon.com 2008-05-09 17:53:37 -07:00
Родитель a863361e54
Коммит 8dd327f60e
2 изменённых файлов: 57 добавлений и 2 удалений

Просмотреть файл

@ -46,6 +46,7 @@
#include "nsIPrefService.h"
#include "nsIPrefLocalizedString.h"
#include "nsIPlatformCharset.h"
#include "nsILocalFile.h"
#include "nsIURIFixup.h"
@ -231,6 +232,17 @@ nsDefaultURIFixup::CreateFixupURI(const nsACString& aStringURI, PRUint32 aFixupF
#endif
}
// For these protocols, use system charset instead of the default UTF-8,
// if the URI is non ASCII.
PRBool bAsciiURI = IsASCII(uriString);
PRBool bUseNonDefaultCharsetForURI =
!bAsciiURI &&
(scheme.IsEmpty() ||
scheme.LowerCaseEqualsLiteral("http") ||
scheme.LowerCaseEqualsLiteral("https") ||
scheme.LowerCaseEqualsLiteral("ftp") ||
scheme.LowerCaseEqualsLiteral("file"));
// Now we need to check whether "scheme" is something we don't
// really know about.
nsCOMPtr<nsIProtocolHandler> ourHandler, extHandler;
@ -240,7 +252,8 @@ nsDefaultURIFixup::CreateFixupURI(const nsACString& aStringURI, PRUint32 aFixupF
if (ourHandler != extHandler || !PossiblyHostPortUrl(uriString)) {
// Just try to create an URL out of it
rv = NS_NewURI(aURI, uriString, nsnull);
rv = NS_NewURI(aURI, uriString,
bUseNonDefaultCharsetForURI ? GetCharsetForUrlBar() : nsnull);
if (!*aURI && rv != NS_ERROR_MALFORMED_URI) {
return rv;
@ -310,9 +323,13 @@ nsDefaultURIFixup::CreateFixupURI(const nsACString& aStringURI, PRUint32 aFixupF
uriString.Assign(NS_LITERAL_CSTRING("ftp://") + uriString);
else
uriString.Assign(NS_LITERAL_CSTRING("http://") + uriString);
// For ftp & http, we want to use system charset.
if (!bAsciiURI)
bUseNonDefaultCharsetForURI = PR_TRUE;
} // end if checkprotocol
rv = NS_NewURI(aURI, uriString, nsnull);
rv = NS_NewURI(aURI, uriString, bUseNonDefaultCharsetForURI ? GetCharsetForUrlBar() : nsnull);
// Did the caller want us to try an alternative URI?
// If so, attempt to fixup http://foo into http://www.foo.com
@ -739,6 +756,41 @@ PRBool nsDefaultURIFixup::PossiblyByteExpandedFileName(const nsAString& aIn)
return PR_FALSE;
}
const char * nsDefaultURIFixup::GetFileSystemCharset()
{
if (mFsCharset.IsEmpty())
{
nsresult rv;
nsCAutoString charset;
nsCOMPtr<nsIPlatformCharset> plat(do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv));
if (NS_SUCCEEDED(rv))
rv = plat->GetCharset(kPlatformCharsetSel_FileName, charset);
if (charset.IsEmpty())
mFsCharset.AssignLiteral("ISO-8859-1");
else
mFsCharset.Assign(charset);
}
return mFsCharset.get();
}
const char * nsDefaultURIFixup::GetCharsetForUrlBar()
{
const char *charset = GetFileSystemCharset();
#ifdef XP_MAC
// check for "x-mac-" prefix
if ((strlen(charset) >= 6) && charset[0] == 'x' && charset[2] == 'm')
{
if (!strcmp("x-mac-roman", charset))
return "ISO-8859-1";
// we can do more x-mac-xxxx mapping here
// or somewhere in intl code like nsIPlatformCharset.
}
#endif
return charset;
}
nsresult nsDefaultURIFixup::KeywordURIFixup(const nsACString & aURIString,
nsIURI** aURI)
{

Просмотреть файл

@ -68,8 +68,11 @@ private:
PRBool PossiblyHostPortUrl(const nsACString& aUrl);
PRBool MakeAlternateURI(nsIURI *aURI);
PRBool IsLikelyFTP(const nsCString& aHostSpec);
const char * GetFileSystemCharset();
const char * GetCharsetForUrlBar();
nsCOMPtr<nsIPrefBranch> mPrefBranch;
nsCAutoString mFsCharset;
};
#endif