From d5dcf771dad3e30f0289f38144156c83954407a1 Mon Sep 17 00:00:00 2001 From: "rjc%netscape.com" Date: Wed, 12 Sep 2007 17:47:08 +0000 Subject: [PATCH] Fix bug # 20817: use default platform charset when reading in bookmarks until if/when we find a META charset tag that says to use something else. Review: ftang@netscape.com --- suite/browser/src/nsBookmarksService.cpp | 28 +++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/suite/browser/src/nsBookmarksService.cpp b/suite/browser/src/nsBookmarksService.cpp index 9fac47aa922..12db95e405e 100644 --- a/suite/browser/src/nsBookmarksService.cpp +++ b/suite/browser/src/nsBookmarksService.cpp @@ -89,6 +89,7 @@ #include "nsICharsetConverterManager.h" #include "nsICharsetAlias.h" +#include "nsIPlatformCharset.h" #ifdef DEBUG #ifdef XP_MAC @@ -114,6 +115,14 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); static NS_DEFINE_IID(kIIOServiceIID, NS_IIOSERVICE_IID); static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID); +#ifndef NS_IPLATFORMCHARSET_CID +// XXX this CID should be defined elsewhere +#define NS_IPLATFORMCHARSET_CID \ +{ 0x84b0f182, 0xc6c7, 0x11d2, {0xb3, 0xb0, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 }} +#endif + +static NS_DEFINE_CID(kPlatformCharsetCID, NS_IPLATFORMCHARSET_CID); + static NS_DEFINE_IID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); static NS_DEFINE_IID(kIStringBundleServiceIID, NS_ISTRINGBUNDLESERVICE_IID); @@ -392,6 +401,22 @@ BookmarkParser::Init(nsFileSpec *fileSpec, nsIRDFDataSource *aDataSource) mIEFavoritesRoot = nsnull; mFoundIEFavoritesRoot = PR_FALSE; + nsresult rv; + NS_WITH_SERVICE(nsIPlatformCharset, platformCharset, kPlatformCharsetCID, &rv); + if (NS_SUCCEEDED(rv) && (platformCharset)) + { + nsAutoString defaultCharset; + if (NS_SUCCEEDED(rv = platformCharset->GetCharset(kPlatformCharsetSel_4xBookmarkFile, defaultCharset))) + { + // found the default platform charset, now try and get a decoder from it to Unicode + NS_WITH_SERVICE(nsICharsetConverterManager, charsetConv, kCharsetConverterManagerCID, &rv); + if (NS_SUCCEEDED(rv) && (charsetConv)) + { + rv = charsetConv->GetUnicodeDecoder(&defaultCharset, getter_AddRefs(mUnicodeDecoder)); + } + } + } + if (fileSpec) { mContentsLen = fileSpec->GetFileSize(); @@ -877,7 +902,8 @@ BookmarkParser::ParseBookmark(const nsString &aLine, const nsCOMPtr= 0) { + while ((offset = url.Find(kEscape22)) >= 0) + { url.SetCharAt(' ',offset); url.Cut(offset + 1, sizeof(kEscape22) - 2); }